Skip to contentSkip to conversation

main - lvmdevices: add deviceidtype option

PATCH David Teigland 1 participant 1 message Jun 11, 2021

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=440d6ae79fb4df92c7992d3c1689ba4f2d242d6a
Commit:        440d6ae79fb4df92c7992d3c1689ba4f2d242d6a
Parent:        8331321070899507b904d8a0ec78b413c826ae32
Author:        David Teigland <[email protected]>
AuthorDate:    Tue Jun 8 14:49:34 2021 -0500
Committer:     David Teigland <[email protected]>
CommitterDate: Fri Jun 11 13:27:18 2021 -0500

lvmdevices: add deviceidtype option

When adding a device to the devices file with --adddev, lvm by default chooses the best device ID type for the new device. The new --deviceidtype option allows the user to override the built in preference. This is useful if there's a problem with the default type, or if a secondary type is preferrable.

If the specified deviceidtype does not produce a device ID, then lvm falls back to the preference it would otherwise use.

---
 lib/device/device_id.c | 32 ++++++++++++++----------
 man/lvmdevices.8_des   | 68 +++++++++++++++++++++++++++++++++++++++-----------
 tools/args.h           |  5 ++++
 tools/command-lines.in |  1 +
 tools/lvmdevices.c     |  7 ++++--
 5 files changed, 84 insertions(+), 29 deletions(-)
lib/device/device_id.c +19 -13
index 1b98487ab..f158e4f06 100644
@@ -931,6 +931,7 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_
 	/*
 	 * Choose the device_id type for the device being added.
 	 *
+	 * 0. use an idtype specified by the user
 	 * 1. use an idtype specific to a special/virtual device type
 	 *    e.g. loop, mpath, crypt, lvmlv, md, etc.
 	 * 2. use an idtype specified by user option.
@@ -939,6 +940,24 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_
 	 * 5. use devname as the last resort.
 	 */
 
+	if (idtype_arg) {
+		if (!(idtype = idtype_from_str(idtype_arg)))
+			log_warn("WARNING: ignoring unknown device_id type %s.", idtype_arg);
+		else {
+			if (id_arg) {
+				if ((idname = strdup(id_arg)))
+					goto id_done;
+				log_warn("WARNING: ignoring device_id name %s.", id_arg);
+			}
+
+			if ((idname = device_id_system_read(cmd, dev, idtype)))
+				goto id_done;
+
+			log_warn("WARNING: ignoring deviceidtype %s which is not available for device.", idtype_arg);
+			idtype = 0;
+		}
+	}
+
 	if (MAJOR(dev->dev) == cmd->dev_types->device_mapper_major) {
 		if (_dev_has_mpath_uuid(cmd, dev, &idname)) {
 			idtype = DEV_ID_TYPE_MPATH_UUID;
@@ -972,19 +991,6 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_
 		log_warn("Missing support for DRBD idtype");
 	}
 
-	if (idtype_arg) {
-		if (!(idtype = idtype_from_str(idtype_arg)))
-			log_warn("WARNING: ignoring unknown device_id type %s.", idtype_arg);
-		else {
-			if (id_arg) {
-				if (!(idname = strdup(id_arg)))
-					stack;
-				goto id_done;
-			}
-			goto id_name;
-		}
-	}
-
 	/*
 	 * No device-specific, existing, or user-specified idtypes,
 	 * so use first available of sys_wwid / sys_serial / devname.
man/lvmdevices.8_des +54 -14

87 lines not on this page · raw message

tools/args.h +5 -0
index 741c82b9f..d4f23f849 100644
@@ -228,6 +228,11 @@ arg(detachprofile_ARG, '\0', "detachprofile", 0, 0, 0,
     "Detaches a metadata profile from a VG or LV.\n"
     "See \\fBlvm.conf\\fP(5) for more information about profiles.\n")
 
+arg(deviceidtype_ARG, '\0', "deviceidtype", string_VAL, 0, 0,
+    "The type of device ID to use for the device.\n"
+    "If the specified type is available for the device,\n"
+    "then it will override the default type that lvm would use.\n")
+
 arg(devices_ARG, '\0', "devices", pv_VAL, ARG_GROUPABLE, 0,
     "Devices that the command can use. This option can be repeated\n"
     "or accepts a comma separated list of devices. This overrides\n"
tools/command-lines.in +1 -0
index 67c37ffd0..8607305cb 100644
@@ -1430,6 +1430,7 @@ ID: lvmdevices_update
 DESC: Update the devices file to fix incorrect values.
 
 lvmdevices --adddev PV
+OO: --deviceidtype String
 ID: lvmdevices_edit
 DESC: Add a device to the devices file.
 
tools/lvmdevices.c +5 -2
index 6b3e05683..3448bdd14 100644
@@ -265,6 +265,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
 
 	if (arg_is_set(cmd, adddev_ARG)) {
 		const char *devname;
+		const char *deviceidtype;
 
 		if (!(devname = arg_str_value(cmd, adddev_ARG, NULL)))
 			goto_bad;
@@ -311,8 +312,10 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
 				 dev_name(dev), dev_filtered_reason(dev));
 		}
 
-		/* allow deviceidtype_ARG/deviceid_ARG ? */
-		if (!device_id_add(cmd, dev, dev->pvid, NULL, NULL))
+		/* also allow deviceid_ARG ? */
+		deviceidtype = arg_str_value(cmd, deviceidtype_ARG, NULL);
+
+		if (!device_id_add(cmd, dev, dev->pvid, deviceidtype, NULL))
 			goto_bad;
 		if (!device_ids_write(cmd))
 			goto_bad;