diff options
author | David Teigland <teigland@redhat.com> | 2022-02-22 15:03:11 -0600 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2022-02-24 17:22:04 -0600 |
commit | 4eb04c8c05e52776891f62863375ceacf866de77 (patch) | |
tree | 46016e2027141fa85b7e5aae58c1ce6c14bb41b3 /lib/label | |
parent | 00c3069872ab488f66f14c8c2727bd080affc05e (diff) | |
download | lvm2-4eb04c8c05e52776891f62863375ceacf866de77.tar.gz |
devices: fix dev_name assumptions
dev_name(dev) returns "[unknown]" if there are no names
on dev->aliases. It's meant mainly for log messages.
Many places assume a valid path name is returned, and
use it directly. A caller that wants to use the path
from dev_name() must first check if the dev has any
paths with dm_list_empty(&dev->aliases).
Diffstat (limited to 'lib/label')
-rw-r--r-- | lib/label/hints.c | 2 | ||||
-rw-r--r-- | lib/label/label.c | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/label/hints.c b/lib/label/hints.c index 35ae7f5cc..edce6f517 100644 --- a/lib/label/hints.c +++ b/lib/label/hints.c @@ -500,6 +500,8 @@ int validate_hints(struct cmd_context *cmd, struct dm_list *hints) if (!(iter = dev_iter_create(NULL, 0))) return 0; while ((dev = dev_iter_get(cmd, iter))) { + if (dm_list_empty(&dev->aliases)) + continue; if (!(hint = _find_hint_name(hints, dev_name(dev)))) continue; diff --git a/lib/label/label.c b/lib/label/label.c index 66d6e7db7..ffb393891 100644 --- a/lib/label/label.c +++ b/lib/label/label.c @@ -1130,6 +1130,7 @@ 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) @@ -1736,6 +1737,12 @@ 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) @@ -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); |