|
|
4aaf76 |
lib/device/device_id.c | 32 ++++++++++++++----------
|
|
|
4aaf76 |
man/lvmdevices.8_des | 68 +++++++++++++++++++++++++++++++++++++++-----------
|
|
|
4aaf76 |
tools/args.h | 5 ++++
|
|
|
4aaf76 |
tools/command-lines.in | 1 +
|
|
|
4aaf76 |
tools/lvmdevices.c | 7 ++++--
|
|
|
4aaf76 |
5 files changed, 84 insertions(+), 29 deletions(-)
|
|
|
4aaf76 |
|
|
|
4aaf76 |
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
|
|
|
4aaf76 |
index 1b98487..f158e4f 100644
|
|
|
4aaf76 |
--- a/lib/device/device_id.c
|
|
|
4aaf76 |
+++ b/lib/device/device_id.c
|
|
|
4aaf76 |
@@ -931,6 +931,7 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_
|
|
|
4aaf76 |
/*
|
|
|
4aaf76 |
* Choose the device_id type for the device being added.
|
|
|
4aaf76 |
*
|
|
|
4aaf76 |
+ * 0. use an idtype specified by the user
|
|
|
4aaf76 |
* 1. use an idtype specific to a special/virtual device type
|
|
|
4aaf76 |
* e.g. loop, mpath, crypt, lvmlv, md, etc.
|
|
|
4aaf76 |
* 2. use an idtype specified by user option.
|
|
|
4aaf76 |
@@ -939,6 +940,24 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_
|
|
|
4aaf76 |
* 5. use devname as the last resort.
|
|
|
4aaf76 |
*/
|
|
|
4aaf76 |
|
|
|
4aaf76 |
+ if (idtype_arg) {
|
|
|
4aaf76 |
+ if (!(idtype = idtype_from_str(idtype_arg)))
|
|
|
4aaf76 |
+ log_warn("WARNING: ignoring unknown device_id type %s.", idtype_arg);
|
|
|
4aaf76 |
+ else {
|
|
|
4aaf76 |
+ if (id_arg) {
|
|
|
4aaf76 |
+ if ((idname = strdup(id_arg)))
|
|
|
4aaf76 |
+ goto id_done;
|
|
|
4aaf76 |
+ log_warn("WARNING: ignoring device_id name %s.", id_arg);
|
|
|
4aaf76 |
+ }
|
|
|
4aaf76 |
+
|
|
|
4aaf76 |
+ if ((idname = device_id_system_read(cmd, dev, idtype)))
|
|
|
4aaf76 |
+ goto id_done;
|
|
|
4aaf76 |
+
|
|
|
4aaf76 |
+ log_warn("WARNING: ignoring deviceidtype %s which is not available for device.", idtype_arg);
|
|
|
4aaf76 |
+ idtype = 0;
|
|
|
4aaf76 |
+ }
|
|
|
4aaf76 |
+ }
|
|
|
4aaf76 |
+
|
|
|
4aaf76 |
if (MAJOR(dev->dev) == cmd->dev_types->device_mapper_major) {
|
|
|
4aaf76 |
if (_dev_has_mpath_uuid(cmd, dev, &idname)) {
|
|
|
4aaf76 |
idtype = DEV_ID_TYPE_MPATH_UUID;
|
|
|
4aaf76 |
@@ -972,19 +991,6 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_
|
|
|
4aaf76 |
log_warn("Missing support for DRBD idtype");
|
|
|
4aaf76 |
}
|
|
|
4aaf76 |
|
|
|
4aaf76 |
- if (idtype_arg) {
|
|
|
4aaf76 |
- if (!(idtype = idtype_from_str(idtype_arg)))
|
|
|
4aaf76 |
- log_warn("WARNING: ignoring unknown device_id type %s.", idtype_arg);
|
|
|
4aaf76 |
- else {
|
|
|
4aaf76 |
- if (id_arg) {
|
|
|
4aaf76 |
- if (!(idname = strdup(id_arg)))
|
|
|
4aaf76 |
- stack;
|
|
|
4aaf76 |
- goto id_done;
|
|
|
4aaf76 |
- }
|
|
|
4aaf76 |
- goto id_name;
|
|
|
4aaf76 |
- }
|
|
|
4aaf76 |
- }
|
|
|
4aaf76 |
-
|
|
|
4aaf76 |
/*
|
|
|
4aaf76 |
* No device-specific, existing, or user-specified idtypes,
|
|
|
4aaf76 |
* so use first available of sys_wwid / sys_serial / devname.
|
|
|
4aaf76 |
diff --git a/man/lvmdevices.8_des b/man/lvmdevices.8_des
|
|
|
4aaf76 |
index 015aa11..2335456 100644
|
|
|
4aaf76 |
--- a/man/lvmdevices.8_des
|
|
|
4aaf76 |
+++ b/man/lvmdevices.8_des
|
|
|
4aaf76 |
@@ -9,18 +9,18 @@ remove it from the devices file with lvmdevices --deldev. The
|
|
|
4aaf76 |
vgimportdevices(8) command adds all PVs from a VG to the devices file,
|
|
|
4aaf76 |
and updates the VG metadata to include device IDs of the PVs.
|
|
|
4aaf76 |
.P
|
|
|
4aaf76 |
-Commands adding new devices to the devices file necessarily look outside
|
|
|
4aaf76 |
-the existing devices file to find the devices to add. pvcreate, vgcreate,
|
|
|
4aaf76 |
-and vgextend also look outside the devices file to create new PVs and add
|
|
|
4aaf76 |
-them to the devices file.
|
|
|
4aaf76 |
+Commands that add new devices to the devices file necessarily look outside
|
|
|
4aaf76 |
+the existing devices file to find the devices being added. pvcreate,
|
|
|
4aaf76 |
+vgcreate, and vgextend also look outside the devices file to create new
|
|
|
4aaf76 |
+PVs and add those PVs to the devices file.
|
|
|
4aaf76 |
.P
|
|
|
4aaf76 |
LVM records devices in the devices file using hardware-specific IDs, such
|
|
|
4aaf76 |
as the WWID, and attempts to use subsystem-specific IDs for virtual device
|
|
|
4aaf76 |
-types (which also aim to be as unique and stable as possible.)
|
|
|
4aaf76 |
-These device IDs are also written in the VG metadata. When no hardware or
|
|
|
4aaf76 |
+types (which also aim to be as unique and stable as possible.) These
|
|
|
4aaf76 |
+device IDs are also written in the VG metadata. When no hardware or
|
|
|
4aaf76 |
virtual ID is available, lvm falls back using the unstable device name as
|
|
|
4aaf76 |
-the device ID. When devnames are used, lvm performs extra scanning to
|
|
|
4aaf76 |
-find devices if their devname changes, e.g. after reboot.
|
|
|
4aaf76 |
+the device ID. When devnames are used as IDs, lvm performs extra scanning
|
|
|
4aaf76 |
+to find devices if their devname changes, e.g. after reboot.
|
|
|
4aaf76 |
.P
|
|
|
4aaf76 |
When proper device IDs are used, an lvm command will not look at devices
|
|
|
4aaf76 |
outside the devices file, but when devnames are used as a fallback, lvm
|
|
|
4aaf76 |
@@ -34,12 +34,13 @@ overriding the devices file. The listed devices act as a sort of devices
|
|
|
4aaf76 |
file in terms of limiting which devices lvm will see and use. Devices
|
|
|
4aaf76 |
that are not listed will appear to be missing to the lvm command.
|
|
|
4aaf76 |
.P
|
|
|
4aaf76 |
-Multiple devices files can be kept in \fI#DEFAULT_SYS_DIR#/devices\fP, which allows lvm
|
|
|
4aaf76 |
-to be used with different sets of devices, e.g. system devices do not need
|
|
|
4aaf76 |
-to be exposed to a specific application, and the application can use lvm on
|
|
|
4aaf76 |
-its own devices that are not exposed to the system. The option
|
|
|
4aaf76 |
---devicesfile <filename> is used to select the devices file to use with the
|
|
|
4aaf76 |
-command. Without the option set, the default system devices file is used.
|
|
|
4aaf76 |
+Multiple devices files can be kept \fI#DEFAULT_SYS_DIR#/devices\fP, which
|
|
|
4aaf76 |
+allows lvm to be used with different sets of devices. For example, system
|
|
|
4aaf76 |
+devices do not need to be exposed to a specific application, and the
|
|
|
4aaf76 |
+application can use lvm on its own devices that are not exposed to the
|
|
|
4aaf76 |
+system. The option --devicesfile <filename> is used to select the devices
|
|
|
4aaf76 |
+file to use with the command. Without the option set, the default system
|
|
|
4aaf76 |
+devices file is used.
|
|
|
4aaf76 |
.P
|
|
|
4aaf76 |
Setting --devicesfile "" causes lvm to not use a devices file.
|
|
|
4aaf76 |
.P
|
|
|
4aaf76 |
@@ -59,3 +60,42 @@ if it does not yet exist.
|
|
|
4aaf76 |
.P
|
|
|
4aaf76 |
It is recommended to use lvm commands to make changes to the devices file to
|
|
|
4aaf76 |
ensure proper updates.
|
|
|
4aaf76 |
+.P
|
|
|
4aaf76 |
+The device ID and device ID type are included in the VG metadata and can
|
|
|
4aaf76 |
+be reported with pvs -o deviceid,deviceidtype. (Note that the lvmdevices
|
|
|
4aaf76 |
+command does not update VG metadata, but subsequent lvm commands modifying
|
|
|
4aaf76 |
+the metadata will include the device ID.)
|
|
|
4aaf76 |
+.P
|
|
|
4aaf76 |
+Possible device ID types are:
|
|
|
4aaf76 |
+.br
|
|
|
4aaf76 |
+.IP \[bu] 2
|
|
|
4aaf76 |
+.B sys_wwid
|
|
|
4aaf76 |
+uses the wwid reported by sysfs. This is the first choice for non-virtual
|
|
|
4aaf76 |
+devices.
|
|
|
4aaf76 |
+.IP \[bu] 2
|
|
|
4aaf76 |
+.B sys_serial
|
|
|
4aaf76 |
+uses the serial number reported by sysfs. This is the second choice for
|
|
|
4aaf76 |
+non-virtual devices.
|
|
|
4aaf76 |
+.IP \[bu] 2
|
|
|
4aaf76 |
+.B mpath_uuid
|
|
|
4aaf76 |
+is used for dm multipath devices, reported by sysfs.
|
|
|
4aaf76 |
+.IP \[bu] 2
|
|
|
4aaf76 |
+.B crypt_uuid
|
|
|
4aaf76 |
+is used for dm crypt devices, reported by sysfs.
|
|
|
4aaf76 |
+.IP \[bu] 2
|
|
|
4aaf76 |
+.B md_uuid
|
|
|
4aaf76 |
+is used for md devices, reported by sysfs.
|
|
|
4aaf76 |
+.B lvmlv_uuid
|
|
|
4aaf76 |
+is used if a PV is placed on top of an lvm LV, reported by sysfs.
|
|
|
4aaf76 |
+.IP \[bu] 2
|
|
|
4aaf76 |
+.B loop_file
|
|
|
4aaf76 |
+is used for loop devices, the backing file name repored by sysfs.
|
|
|
4aaf76 |
+.IP \[bu] 2
|
|
|
4aaf76 |
+.B devname
|
|
|
4aaf76 |
+the device name is used if no other type applies.
|
|
|
4aaf76 |
+.P
|
|
|
4aaf76 |
+
|
|
|
4aaf76 |
+The default choice for device ID type can be overriden using lvmdevices
|
|
|
4aaf76 |
+--addev --deviceidtype <type>. If the specified type is available for the
|
|
|
4aaf76 |
+device it will be used, otherwise the device will be added using the type
|
|
|
4aaf76 |
+that would otherwise be chosen.
|
|
|
4aaf76 |
diff --git a/tools/args.h b/tools/args.h
|
|
|
4aaf76 |
index 741c82b..d4f23f8 100644
|
|
|
4aaf76 |
--- a/tools/args.h
|
|
|
4aaf76 |
+++ b/tools/args.h
|
|
|
4aaf76 |
@@ -228,6 +228,11 @@ arg(detachprofile_ARG, '\0', "detachprofile", 0, 0, 0,
|
|
|
4aaf76 |
"Detaches a metadata profile from a VG or LV.\n"
|
|
|
4aaf76 |
"See \\fBlvm.conf\\fP(5) for more information about profiles.\n")
|
|
|
4aaf76 |
|
|
|
4aaf76 |
+arg(deviceidtype_ARG, '\0', "deviceidtype", string_VAL, 0, 0,
|
|
|
4aaf76 |
+ "The type of device ID to use for the device.\n"
|
|
|
4aaf76 |
+ "If the specified type is available for the device,\n"
|
|
|
4aaf76 |
+ "then it will override the default type that lvm would use.\n")
|
|
|
4aaf76 |
+
|
|
|
4aaf76 |
arg(devices_ARG, '\0', "devices", pv_VAL, ARG_GROUPABLE, 0,
|
|
|
4aaf76 |
"Devices that the command can use. This option can be repeated\n"
|
|
|
4aaf76 |
"or accepts a comma separated list of devices. This overrides\n"
|
|
|
4aaf76 |
diff --git a/tools/command-lines.in b/tools/command-lines.in
|
|
|
4aaf76 |
index 67c37ff..8607305 100644
|
|
|
4aaf76 |
--- a/tools/command-lines.in
|
|
|
4aaf76 |
+++ b/tools/command-lines.in
|
|
|
4aaf76 |
@@ -1430,6 +1430,7 @@ ID: lvmdevices_update
|
|
|
4aaf76 |
DESC: Update the devices file to fix incorrect values.
|
|
|
4aaf76 |
|
|
|
4aaf76 |
lvmdevices --adddev PV
|
|
|
4aaf76 |
+OO: --deviceidtype String
|
|
|
4aaf76 |
ID: lvmdevices_edit
|
|
|
4aaf76 |
DESC: Add a device to the devices file.
|
|
|
4aaf76 |
|
|
|
4aaf76 |
diff --git a/tools/lvmdevices.c b/tools/lvmdevices.c
|
|
|
4aaf76 |
index 6b3e056..3448bdd 100644
|
|
|
4aaf76 |
--- a/tools/lvmdevices.c
|
|
|
4aaf76 |
+++ b/tools/lvmdevices.c
|
|
|
4aaf76 |
@@ -265,6 +265,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
|
|
|
4aaf76 |
|
|
|
4aaf76 |
if (arg_is_set(cmd, adddev_ARG)) {
|
|
|
4aaf76 |
const char *devname;
|
|
|
4aaf76 |
+ const char *deviceidtype;
|
|
|
4aaf76 |
|
|
|
4aaf76 |
if (!(devname = arg_str_value(cmd, adddev_ARG, NULL)))
|
|
|
4aaf76 |
goto_bad;
|
|
|
4aaf76 |
@@ -311,8 +312,10 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
|
|
|
4aaf76 |
dev_name(dev), dev_filtered_reason(dev));
|
|
|
4aaf76 |
}
|
|
|
4aaf76 |
|
|
|
4aaf76 |
- /* allow deviceidtype_ARG/deviceid_ARG ? */
|
|
|
4aaf76 |
- if (!device_id_add(cmd, dev, dev->pvid, NULL, NULL))
|
|
|
4aaf76 |
+ /* also allow deviceid_ARG ? */
|
|
|
4aaf76 |
+ deviceidtype = arg_str_value(cmd, deviceidtype_ARG, NULL);
|
|
|
4aaf76 |
+
|
|
|
4aaf76 |
+ if (!device_id_add(cmd, dev, dev->pvid, deviceidtype, NULL))
|
|
|
4aaf76 |
goto_bad;
|
|
|
4aaf76 |
if (!device_ids_write(cmd))
|
|
|
4aaf76 |
goto_bad;
|