main - device_id: handle duplicate serial numbers
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=761b922178c8522fd9abb207ba31bd27f9fa9dc4 Commit: 761b922178c8522fd9abb207ba31bd27f9fa9dc4 Parent: bdab36cf3f059e597371bb504646f4dfb7a89f50 Author: David Teigland <[email protected]> AuthorDate: Mon Oct 31 16:14:01 2022 -0500 Committer: David Teigland <[email protected]> CommitterDate: Mon Nov 7 08:56:02 2022 -0600
device_id: handle duplicate serial numbers
Handle multiple devices using the same serial number as their device id. After matching devices to devices file entries, if there is a discrepency between the ondisk PVID and the devices file PVID, then rematch devices to devices file entries using PVID, looking at all disks on the system with the same serial number.
--- lib/cache/lvmcache.c | 16 + lib/commands/toolcontext.h | 1 + lib/device/device.h | 5 + lib/device/device_id.c | 377 +++++++++++++++++++ lib/device/device_id.h | 1 + test/shell/devicesfile-serial.sh | 777 +++++++++++++++++++++++++++++++++++++++ tools/lvmdevices.c | 10 +- 7 files changed, 1185 insertions(+), 2 deletions(-)
lib/cache/lvmcache.c +16 -0
@@ -1634,6 +1634,22 @@ int lvmcache_label_scan(struct cmd_context *cmd)if (!label_scan (cmd)) return_0; +/* +* device_ids_validate() found devices using a sys_serial device id +* which had a PVID on disk that did not match the PVID in the devices +* file. Serial numbers may not always be unique, so any device with +* the same serial number is found and searched for the correct PVID. +* If the PVID is found on a device that has not been scanned, then +* it needs to be scanned so it can be used. +*/ +if (!dm_list_empty (&cmd->device_ids_check_serial)) { +struct dm_list scan_devs; +dm_list_init (&scan_devs); +device_ids_check_serial (cmd, &scan_devs,NULL ,0 ); +if (!dm_list_empty (&scan_devs)) +label_scan_devs (cmd, cmd->filter, &scan_devs); + } +/* * When devnames are used as device ids (which is dispreferred), * changing/unstable devnames can lead to entries in the devices file
lib/commands/toolcontext.h +1 -0
@@ -215,6 +215,7 @@ struct cmd_context {struct dm_list use_devices;/* struct dev_use for each entry in devices file */ const char *md_component_checks;const char *search_for_devnames;/* config file setting */ +struct dm_list device_ids_check_serial;const char *devicesfile;/* from --devicesfile option */ struct dm_list deviceslist;/* from --devices option, struct dm_str_list */
lib/device/device.h +5 -0
@@ -118,6 +118,11 @@ struct dev_use {char *pvid; }; +struct dev_use_list { +struct dm_list list; +struct dev_use *du; +}; +/* * All devices in LVM will be represented by one of these. * pointer comparisons are valid.
lib/device/device_id.c +377 -0
413 lines not on this page · raw message
lib/device/device_id.h +1 -0
@@ -35,6 +35,7 @@ int device_ids_match_dev(struct cmd_context *cmd, struct device *dev);void device_ids_match_device_list (struct cmd_context *cmd);void device_ids_validate (struct cmd_context *cmd,struct dm_list *scanned_devs,int *device_ids_invalid,int noupdate);int device_ids_version_unchanged (struct cmd_context *cmd); +void device_ids_check_serial (struct cmd_context *cmd,struct dm_list *scan_devs,int *update_needed,int noupdate);void device_ids_find_renamed_devs (struct cmd_context *cmd,struct dm_list *dev_list,int *search_count,int noupdate);const char *device_id_system_read (struct cmd_context *cmd,struct device *dev,uint16_t idtype);void device_id_update_vg_uuid (struct cmd_context *cmd,struct volume_group *vg,struct id *old_vg_id);
test/shell/devicesfile-serial.sh new file +777 -0
777 lines not on this page · raw message
tools/lvmdevices.c +8 -2
@@ -124,6 +124,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv) {struct dm_list search_pvids;struct dm_list found_devs; +struct dm_list scan_devs;struct device_id_list *dil;struct device_list *devl;struct device *dev;
@@ -132,6 +133,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)dm_list_init (&search_pvids);dm_list_init (&found_devs); +dm_list_init (&scan_devs);if (!setup_devices_file (cmd))return ECMD_FAILED ;
@@ -186,6 +188,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)int update_set =arg_is_set (cmd, update_ARG);int search_count =0 ;int update_needed =0 ; +int serial_update_needed =0 ;int invalid =0 ;unlink_searched_devnames (cmd);
@@ -273,6 +276,9 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv) } } +if (!dm_list_empty (&cmd->device_ids_check_serial)) +device_ids_check_serial (cmd, &scan_devs, &serial_update_needed,1 ); +/* * Find and fix any devname entries that have moved to a * renamed device.
@@ -288,7 +294,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv) }if (arg_is_set (cmd, update_ARG)) { -if (update_needed || !dm_list_empty (&found_devs)) { +if (update_needed || serial_update_needed || !dm_list_empty (&found_devs)) {if (!device_ids_write (cmd)) goto_bad;log_print ("Updated devices file to version %s" ,devices_file_version ());
@@ -301,7 +307,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)* needs updates, i.e. running --update would make * changes. */ -if (update_needed) { +if (update_needed || serial_update_needed) {log_error ("Updates needed for devices file." ); goto bad; }