zdev: Implement internal device attributes

This change adds base infrastructure for implementing internal device
attributes. In the context of the zdev tools, an internal device
attribute is a new type of device attribute with the following
characteristics:

  - Can be set and removed like normal device attributes
  - Affects zdev-internal handling only
  - Does not correspond to an actual device attribute, that is
    it has no representation in SysFS
  - Can not be set in the active configuration
  - Name starts with "zdev:" to prevent conflicts with actual
    device attributes

Values for internal device attributes are stored in udev rules alongside
the normal persistent configuration of a device. They are encoded as
udev environment variables. Note that they have no further effect on
udev processing.

Signed-off-by: Peter Oberparleiter <oberpar@linux.vnet.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Peter Oberparleiter
2017-09-01 11:05:58 +02:00
committed by Jan Höppner
parent 3c5644ccfd
commit c0392efa39
12 changed files with 220 additions and 8 deletions

View File

@@ -16,6 +16,7 @@
#include "attrib.h"
#include "device.h"
#include "devtype.h"
#include "internal.h"
#include "misc.h"
#include "namespace.h"
#include "setting.h"
@@ -221,6 +222,9 @@ static exit_code_t apply_setting(struct device *dev, config_t config,
goto err_activeonly_forceable;
if (!force && SCOPE_AUTOCONF(config) && a->activeonly)
goto err_activeonly_forceable;
/* Check for internal. */
if (config == config_active && a->internal)
goto err_int_noactive;
/* Check for multiple values. */
if (!force && !a->multi && strlist_find(processed, key))
goto err_multi_forceable;
@@ -230,6 +234,9 @@ static exit_code_t apply_setting(struct device *dev, config_t config,
goto err_unknown;
if (!force)
goto err_unknown_forceable;
/* Check for internal. */
if (config == config_active && internal_by_name(key))
goto err_int_noactive;
}
strlist_add(processed, "%s", key);
@@ -294,6 +301,11 @@ err_activeonly_forceable:
delayed_forceable("Attribute '%s' should only be changed in the active "
"config\n", a->name);
return EXIT_INVALID_SETTING;
err_int_noactive:
delayed_err("Internal attribute '%s' cannot be set in the active config\n",
key);
return EXIT_INVALID_SETTING;
}
/* Apply device settings from strlist to device. */
@@ -542,6 +554,9 @@ exit_code_t device_write_active_settings(struct device *dev)
s = p->ptr;
if (!s->modified || s->removed)
continue;
if ((s->attrib && s->attrib->internal) ||
internal_by_name(s->name))
continue;
path = subtype_get_active_attrib_path(st, dev, s->name);
if (!path) {