File s390-tools-sles15sp2-01-zdev-Introduce-read-only-attributes.patch of Package s390-tools.17983
Subject: [PATCH] [FEAT SAN1810] zdev: Introduce read-only attributes
From: Fedor Loshakov <loshakov@linux.ibm.com>
Summary: zdev: report FC Endpoint Security of zfcp devices
Description: Report FC Endpoint Security of zfcp devices, which
includes:
1. Add support to report Fibre Channel (FC)
Endpoint Security related information for zfcp-host
and zfcp-lun devices.
2. Format and print HBA FC Endpoint Security trace
records
Upstream-ID: c063273b145c1f182968f318c04d3d8ea4dc0d9f
Problem-ID: SAN1810
Upstream-Description:
zdev: Introduce read-only attributes
Add support for defining read-only attributes in the chzdev/lszdev
tools. These attributes can be used to provide online documentation
for specific attributes via the --help-attribute and --list-attributes
tool functions.
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Reviewed-by: Jens Remus <jremus@linux.ibm.com>
Reviewed-by: Fedor Loshakov <loshakov@linux.ibm.com>
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Signed-off-by: Fedor Loshakov <loshakov@linux.ibm.com>
---
zdev/include/attrib.h | 4 +++-
zdev/src/device.c | 9 ++++++++-
zdev/src/export.c | 4 +++-
zdev/src/table_attribs.c | 14 +++++++++-----
4 files changed, 23 insertions(+), 8 deletions(-)
--- a/zdev/include/attrib.h
+++ b/zdev/include/attrib.h
@@ -1,7 +1,7 @@
/*
* zdev - Modify and display the persistent configuration of devices
*
- * Copyright IBM Corp. 2016, 2017
+ * Copyright IBM Corp. 2016, 2019
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
@@ -181,6 +181,7 @@ struct value_map {
* @activeonly: This attribute should only be changed in the active config
* @unstable: The value read is not the last value written
* @writeonly: This attribute cannot be read from
+ * @readonly: This attribute cannot be written to
* @rewrite: Writing the same value multiple times has side-effects
* @mandatory: This attribute cannot be removed from a configured device
* @newline: There must be a newline when writing to this attribute
@@ -211,6 +212,7 @@ struct attrib {
unsigned int activeonly :1;
unsigned int unstable :1;
unsigned int writeonly :1;
+ unsigned int readonly :1;
unsigned int rewrite :1;
unsigned int mandatory :1;
unsigned int newline :1;
--- a/zdev/src/device.c
+++ b/zdev/src/device.c
@@ -215,6 +215,9 @@ static exit_code_t apply_setting(struct
/* Check for known attribute. */
a = subtype_find_dev_attrib(st, key);
if (a) {
+ /* Check for read-only attribute. */
+ if (a->readonly)
+ goto err_readonly;
/* Check for acceptable value of known attribute. */
if (!force && !attrib_check_value(a, value))
goto err_invalid_forceable;
@@ -307,6 +310,10 @@ err_int_noactive:
delayed_err("Internal attribute '%s' cannot be set in the active config\n",
key);
return EXIT_INVALID_SETTING;
+
+err_readonly:
+ delayed_err("Cannot modify read-only attribute: %s\n", key);
+ return EXIT_INVALID_SETTING;
}
/* Apply device settings from strlist to device. */
@@ -521,7 +528,7 @@ void device_read_active_settings(struct
a = attrib_find(st->dev_attribs, name);
s = setting_list_apply_actual(dev->active.settings, a, name,
value);
- if (link || (scope == scope_all &&
+ if ((a && a->readonly) || link || (scope == scope_all &&
util_path_is_readonly_file("%s", path)))
s->readonly = 1;
if (link)
--- a/zdev/src/export.c
+++ b/zdev/src/export.c
@@ -1,7 +1,7 @@
/*
* zdev - Modify and display the persistent configuration of devices
*
- * Copyright IBM Corp. 2016, 2017
+ * Copyright IBM Corp. 2016, 2019
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
@@ -71,6 +71,8 @@ static bool is_exportable(struct setting
if (!a)
return true;
+ if (a->readonly)
+ return false;
if (a->mandatory)
return true;
if (SCOPE_ACTIVE(config)) {
--- a/zdev/src/table_attribs.c
+++ b/zdev/src/table_attribs.c
@@ -1,7 +1,7 @@
/*
* zdev - Modify and display the persistent configuration of devices
*
- * Copyright IBM Corp. 2016, 2017
+ * Copyright IBM Corp. 2016, 2019
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
@@ -186,13 +186,15 @@ static void table_attribs_show_details_o
indent(j, "The default value is '%s'.\n", a->defval);
}
- printf("\n");
- indent(i, "ACCEPTED VALUES\n");
- attrib_print_acceptable(a, j);
+ if (!a->readonly) {
+ printf("\n");
+ indent(i, "ACCEPTED VALUES\n");
+ attrib_print_acceptable(a, j);
+ }
if (!(a->multi || a->activeonly || a->unstable || a->writeonly ||
a->rewrite || a->mandatory || a->newline || a->activerem ||
- a->nounload || a->check))
+ a->nounload || a->check || a->readonly))
return;
printf("\n");
@@ -211,6 +213,8 @@ static void table_attribs_show_details_o
}
if (a->writeonly)
indent(j, "- You cannot read this attribute\n");
+ if (a->readonly)
+ indent(j, "- You cannot write to this attribute\n");
if (a->rewrite) {
indent(j, "- Setting the same value multiple times may have "
"additional effects\n");