diff options
author | David Teigland <teigland@redhat.com> | 2022-02-22 15:03:11 -0600 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2022-02-24 15:37:53 -0600 |
commit | 07338325e552bb692f2422f42750e70c9d31152c (patch) | |
tree | 46016e2027141fa85b7e5aae58c1ce6c14bb41b3 /lib/label/label.c | |
parent | ac1f4bbbfd4c5f1387c3e0607f7d556409e7a4b4 (diff) | |
download | lvm2-dev-dct-devs3.tar.gz |
devices: fix name handlingdev-dct-devs3
- Fix cases where incorrect device paths were left
on the dev->aliases list. Leaving incorrect paths
on dev->aliases could result in using the wrong device.
- Fix a widespread incorrect assumption that dev_name()
always returns a valid path (or NULL). dev_name()
returns "[unknown]" when there are no paths to a
device, and is mainly meant to be used in messages.
- Check for valid dev paths in cases that want to use
the from dev_name() for things other than a message.
Diffstat (limited to 'lib/label/label.c')
-rw-r--r-- | lib/label/label.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/label/label.c b/lib/label/label.c index fe2bc8fec..ffb393891 100644 --- a/lib/label/label.c +++ b/lib/label/label.c @@ -1130,11 +1130,12 @@ int label_scan_vg_online(struct cmd_context *cmd, const char *vgname, * sure to find the device. */ if (try_dev_scan) { + log_debug("Repeat dev cache scan to translate devnos."); dev_cache_scan(cmd); dm_list_iterate_items(po, &pvs_online) { if (po->dev) continue; - if (!(po->dev = dev_cache_get_by_devt(cmd, po->devno, NULL, NULL))) { + if (!(po->dev = dev_cache_get_by_devt(cmd, po->devno))) { log_error("No device found for %d:%d PVID %s", (int)MAJOR(po->devno), (int)MINOR(po->devno), po->pvid); goto bad; @@ -1722,7 +1723,7 @@ void label_scan_invalidate_lv(struct cmd_context *cmd, struct logical_volume *lv if (lv_info(cmd, lv, 0, &lvinfo, 0, 0) && lvinfo.exists) { /* FIXME: Still unclear what is it supposed to find */ devt = MKDEV(lvinfo.major, lvinfo.minor); - if ((dev = dev_cache_get_by_devt(cmd, devt, NULL, NULL))) + if ((dev = dev_cache_get_by_devt(cmd, devt))) label_scan_invalidate(dev); } } @@ -1736,13 +1737,19 @@ void label_scan_invalidate_lvs(struct cmd_context *cmd, struct dm_list *lvs) struct lv_list *lvl; dev_t devt; + /* + * FIXME: this is all unnecessary unless there are PVs stacked on LVs, + * so we can skip all of this if scan_lvs=0. + */ + log_debug("invalidating devs for any pvs on lvs"); + if (get_device_list(NULL, &devs, &devs_features)) { if (devs_features & DM_DEVICE_LIST_HAS_UUID) { dm_list_iterate_items(dm_dev, devs) if (dm_dev->uuid && strncmp(dm_dev->uuid, UUID_PREFIX, sizeof(UUID_PREFIX) - 1) == 0) { devt = MKDEV(dm_dev->major, dm_dev->minor); - if ((dev = dev_cache_get_by_devt(cmd, devt, NULL, NULL))) + if ((dev = dev_cache_get_by_devt(cmd, devt))) label_scan_invalidate(dev); } /* ATM no further caching for any lvconvert command @@ -1879,10 +1886,24 @@ int label_scan_open_rw(struct device *dev) int label_scan_reopen_rw(struct device *dev) { + const char *name; int flags = 0; int prev_fd = dev->bcache_fd; int fd; + if (dm_list_empty(&dev->aliases)) { + log_error("Cannot reopen rw device %d:%d with no valid paths di %d fd %d.", + (int)MAJOR(dev->dev), (int)MINOR(dev->dev), dev->bcache_di, dev->bcache_fd); + return 0; + } + + name = dev_name(dev); + if (!name || name[0] != '/') { + log_error("Cannot reopen rw device %d:%d with no valid name di %d fd %d.", + (int)MAJOR(dev->dev), (int)MINOR(dev->dev), dev->bcache_di, dev->bcache_fd); + return 0; + } + if (!(dev->flags & DEV_IN_BCACHE)) { if ((dev->bcache_fd != -1) || (dev->bcache_di != -1)) { /* shouldn't happen */ @@ -1912,7 +1933,7 @@ int label_scan_reopen_rw(struct device *dev) flags |= O_NOATIME; flags |= O_RDWR; - fd = open(dev_name(dev), flags, 0777); + fd = open(name, flags, 0777); if (fd < 0) { log_error("Failed to open rw %s errno %d di %d fd %d.", dev_name(dev), errno, dev->bcache_di, dev->bcache_fd); |