diff options
author | David Teigland <teigland@redhat.com> | 2022-09-15 09:45:21 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2022-10-10 11:47:29 -0500 |
commit | 13c63f0cfa22a0bc89b8d528b8e2301c49fc7b0d (patch) | |
tree | fc9a073c93518b499f1210db30590407f3203b54 /lib/device | |
parent | c4e6d675de5b0df5a711971b7828933f07b0efd0 (diff) | |
download | lvm2-13c63f0cfa22a0bc89b8d528b8e2301c49fc7b0d.tar.gz |
lvmdevices: use deviceidtype option strictly
Only use the device id type specified by --deviceidtype,
and fail if that type is not available for the device.
Diffstat (limited to 'lib/device')
-rw-r--r-- | lib/device/device_id.c | 15 | ||||
-rw-r--r-- | lib/device/device_id.h | 2 |
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/device/device_id.c b/lib/device/device_id.c index 6383f69fb..252654861 100644 --- a/lib/device/device_id.c +++ b/lib/device/device_id.c @@ -1140,7 +1140,7 @@ struct dev_use *get_du_for_device_id(struct cmd_context *cmd, uint16_t idtype, c * . add or update entry in cmd->use_devices */ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_arg, - const char *idtype_arg, const char *id_arg) + const char *idtype_arg, const char *id_arg, int use_idtype_only) { char pvid[ID_LEN+1] = { 0 }; uint16_t idtype = 0; @@ -1194,9 +1194,13 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_ */ if (idtype_arg) { - if (!(idtype = idtype_from_str(idtype_arg))) + if (!(idtype = idtype_from_str(idtype_arg))) { + if (use_idtype_only) { + log_error("The specified --deviceidtype %s is unknown.", idtype_arg); + return 0; + } log_warn("WARNING: ignoring unknown device_id type %s.", idtype_arg); - else { + } else { if (id_arg) { if ((idname = strdup(id_arg))) goto id_done; @@ -1206,6 +1210,11 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_ if ((idname = device_id_system_read(cmd, dev, idtype))) goto id_done; + if (use_idtype_only) { + log_error("The specified --deviceidtype %s is not available for %s.", idtype_arg, dev_name(dev)); + return 0; + } + log_warn("WARNING: ignoring deviceidtype %s which is not available for device.", idtype_arg); idtype = 0; } diff --git a/lib/device/device_id.h b/lib/device/device_id.h index 6962925df..700176bb5 100644 --- a/lib/device/device_id.h +++ b/lib/device/device_id.h @@ -28,7 +28,7 @@ int device_ids_use_devname(struct cmd_context *cmd); int device_ids_read(struct cmd_context *cmd); int device_ids_write(struct cmd_context *cmd); int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid, - const char *idtype_arg, const char *id_arg); + const char *idtype_arg, const char *id_arg, int use_idtype_only); void device_id_pvremove(struct cmd_context *cmd, struct device *dev); void device_ids_match(struct cmd_context *cmd); int device_ids_match_dev(struct cmd_context *cmd, struct device *dev); |