main - pvs_online: include devname in pvid files
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=73b4602f219767850a2834c6b15bdb5e6d636870 Commit: 73b4602f219767850a2834c6b15bdb5e6d636870 Parent: 024ce50f06feff2dae53dce83398911bef071a6e Author: David Teigland <[email protected]> AuthorDate: Mon Nov 8 16:02:48 2021 -0600 Committer: David Teigland <[email protected]> CommitterDate: Tue Nov 9 11:26:26 2021 -0600
pvs_online: include devname in pvid files
Include the device name in the /run/lvm/pvs_online/pvid files. Commands using the pvid file can use the devname to more quickly find the correct device, vs finding the device using the major:minor number. If the devname in the pvid file is missing or incorrect, fall back to using the devno.
--- lib/device/dev-cache.c | 50 ++++++++++++++++++ lib/device/dev-cache.h | 1 + lib/device/online.c | 138 +++++++++++++++++++++++++++++++++++++------------ lib/device/online.h | 3 +- lib/label/label.c | 18 ++----- tools/pvscan.c | 41 +++++++-------- 6 files changed, 182 insertions(+), 69 deletions(-)
lib/device/dev-cache.c +50 -0
@@ -2241,3 +2241,53 @@ int setup_devno_in_dev_cache(struct cmd_context *cmd, dev_t devno)return setup_devname_in_dev_cache (cmd, devname); } +struct device *setup_dev_in_dev_cache (struct cmd_context *cmd,dev_t devno,const char *devname) +{ +struct device *dev; +struct stat buf; +int major = (int )MAJOR (devno); +int minor = (int )MINOR (devno); + +if (devname) { +if (stat (devname, &buf) <0 ) { +log_error ("Cannot access device %s for %d:%d." , devname, major, minor); +if (!(devname =_get_devname_from_devno (cmd, devno))) { +log_error ("No device name found from %d:%d." , major, minor); + return_NULL; + } +if (stat (devname, &buf) <0 ) { +log_error ("Cannot access device %s from %d:%d." , devname, major, minor); + return_NULL; + } + } + }else { +if (!(devname =_get_devname_from_devno (cmd, devno))) { +log_error ("No device name found from %d:%d." , major, minor); + return_NULL; + } +if (stat (devname, &buf) <0 ) { +log_error ("Cannot access device %s from %d:%d." , devname, major, minor); + return_NULL; + } + } + +if (!S_ISBLK (buf.st_mode)) { +log_error ("Invaild device type %s." , devname); + return_NULL; + } + +if (devno && (buf.st_rdev != devno)) { +log_warn ("Found %s devno %d:%d expected %d:%d." , devname, + (int )MAJOR (buf.st_rdev), (int )MINOR (buf.st_rdev), major, minor); + } + +if (!_insert_dev (devname, buf.st_rdev)) + return_NULL; + +if (!(dev = (struct device *)dm_hash_lookup (_cache.names, devname))) { +log_error ("Device lookup failed for %d:%d %s" , major, minor, devname); + return_NULL; + } + +return dev; +}
lib/device/dev-cache.h +1 -0
@@ -82,5 +82,6 @@ int setup_device(struct cmd_context *cmd, const char *devname);int setup_devices_for_online_autoactivation (struct cmd_context *cmd);int setup_devname_in_dev_cache (struct cmd_context *cmd,const char *devname);int setup_devno_in_dev_cache (struct cmd_context *cmd,dev_t devno); +struct device *setup_dev_in_dev_cache (struct cmd_context *cmd,dev_t devno,const char *devname);#endif
lib/device/online.c +106 -32
248 lines not on this page · raw message
lib/device/online.h +2 -1
@@ -21,6 +21,7 @@ struct pv_online {dev_t devno;char pvid[ID_LEN +1 ];char vgname[NAME_LEN ]; +char devname[NAME_LEN ]; };/*
@@ -44,7 +45,7 @@ do \ log_error("pvscan[%d] " fmt, getpid(), ##args); \while (0 ) -int online_pvid_file_read(char *path, int *major, int *minor, char *vgname); +int online_pvid_file_read(char *path, int *major, int *minor, char *vgname, char *devname);int online_vg_file_create (struct cmd_context *cmd,const char *vgname);void online_vg_file_remove (const char *vgname);int online_pvid_file_create (struct cmd_context *cmd,struct device *dev,const char *vgname);
lib/label/label.c +5 -13
@@ -1073,26 +1073,18 @@ int label_scan_vg_online(struct cmd_context *cmd, const char *vgname, }/* -* For each po devno add a struct dev to dev-cache. This is a faster +* For each po add a struct dev to dev-cache. This is a faster * alternative to the usual dev_cache_scan() which looks at all * devices. If this optimization fails, then fall back to the usual * dev_cache_scan(). */ dm_list_iterate_items(po, &pvs_online) { -if (!setup_devno_in_dev_cache (cmd, po->devno)) { -log_debug ("No device set up for quick mapping of %d:%d PVID %s" , - (int )MAJOR (po->devno), (int )MINOR (po->devno), po->pvid); +if (!(po->dev =setup_dev_in_dev_cache (cmd, po->devno, po->devname[0 ] ? po->devname :NULL ))) { +log_debug ("No device found for quick mapping of online PV %d:%d %s PVID %s" , + (int )MAJOR (po->devno), (int )MINOR (po->devno), po->devname, po->pvid); try_dev_scan =1 ; -break ; - } - -if (!(po->dev =dev_cache_get_by_devt (cmd, po->devno,NULL ,NULL ))) { -log_debug ("No device found for quick mapping of %d:%d PVID %s" , - (int )MAJOR (po->devno), (int )MINOR (po->devno), po->pvid); - try_dev_scan =1 ; -break ; +continue ; } -if (!(devl =dm_pool_zalloc (cmd->mem,sizeof (*devl)))) goto_bad;
tools/pvscan.c +18 -23
92 lines not on this page · raw message