|
|
38b7b2 |
From 591b5f006fca7e06bfbf0d5512da3ae5b0f6bbdd Mon Sep 17 00:00:00 2001
|
|
|
38b7b2 |
From: David Teigland <teigland@redhat.com>
|
|
|
38b7b2 |
Date: Tue, 22 Feb 2022 15:03:11 -0600
|
|
|
38b7b2 |
Subject: [PATCH 38/54] devices: fix dev_name assumptions
|
|
|
38b7b2 |
|
|
|
38b7b2 |
dev_name(dev) returns "[unknown]" if there are no names
|
|
|
38b7b2 |
on dev->aliases. It's meant mainly for log messages.
|
|
|
38b7b2 |
|
|
|
38b7b2 |
Many places assume a valid path name is returned, and
|
|
|
38b7b2 |
use it directly. A caller that wants to use the path
|
|
|
38b7b2 |
from dev_name() must first check if the dev has any
|
|
|
38b7b2 |
paths with dm_list_empty(&dev->aliases).
|
|
|
38b7b2 |
---
|
|
|
38b7b2 |
lib/activate/dev_manager.c | 9 ++++++++-
|
|
|
38b7b2 |
lib/device/dev-type.c | 3 +++
|
|
|
38b7b2 |
lib/device/device_id.c | 13 +++++++++++--
|
|
|
38b7b2 |
lib/label/hints.c | 2 ++
|
|
|
38b7b2 |
lib/label/label.c | 16 +++++++++++++++-
|
|
|
38b7b2 |
lib/locking/lvmlockd.c | 4 ++++
|
|
|
38b7b2 |
lib/metadata/mirror.c | 17 +++++++++++++----
|
|
|
38b7b2 |
lib/metadata/pv_list.c | 5 +++++
|
|
|
38b7b2 |
lib/metadata/vg.c | 5 +++++
|
|
|
38b7b2 |
test/shell/losetup-partscan.sh | 2 ++
|
|
|
38b7b2 |
10 files changed, 68 insertions(+), 8 deletions(-)
|
|
|
38b7b2 |
|
|
|
38b7b2 |
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
|
|
|
38b7b2 |
index a73a556b2..284254d68 100644
|
|
|
38b7b2 |
--- a/lib/activate/dev_manager.c
|
|
|
38b7b2 |
+++ b/lib/activate/dev_manager.c
|
|
|
38b7b2 |
@@ -2875,6 +2875,10 @@ int add_areas_line(struct dev_manager *dm, struct lv_segment *seg,
|
|
|
38b7b2 |
|
|
|
38b7b2 |
/* FIXME Avoid repeating identical stat in dm_tree_node_add_target_area */
|
|
|
38b7b2 |
for (s = start_area; s < areas; s++) {
|
|
|
38b7b2 |
+
|
|
|
38b7b2 |
+ /* FIXME: dev_name() does not return NULL! It needs to check if dm_list_empty(&dev->aliases)
|
|
|
38b7b2 |
+ but this knot of logic is too complex to pull apart without careful deconstruction. */
|
|
|
38b7b2 |
+
|
|
|
38b7b2 |
if ((seg_type(seg, s) == AREA_PV &&
|
|
|
38b7b2 |
(!seg_pvseg(seg, s) || !seg_pv(seg, s) || !seg_dev(seg, s) ||
|
|
|
38b7b2 |
!(name = dev_name(seg_dev(seg, s))) || !*name ||
|
|
|
38b7b2 |
@@ -2893,7 +2897,10 @@ int add_areas_line(struct dev_manager *dm, struct lv_segment *seg,
|
|
|
38b7b2 |
return_0;
|
|
|
38b7b2 |
num_error_areas++;
|
|
|
38b7b2 |
} else if (seg_type(seg, s) == AREA_PV) {
|
|
|
38b7b2 |
- if (!dm_tree_node_add_target_area(node, dev_name(seg_dev(seg, s)), NULL,
|
|
|
38b7b2 |
+ struct device *dev = seg_dev(seg, s);
|
|
|
38b7b2 |
+ name = dm_list_empty(&dev->aliases) ? NULL : dev_name(dev);
|
|
|
38b7b2 |
+
|
|
|
38b7b2 |
+ if (!dm_tree_node_add_target_area(node, name, NULL,
|
|
|
38b7b2 |
(seg_pv(seg, s)->pe_start + (extent_size * seg_pe(seg, s)))))
|
|
|
38b7b2 |
return_0;
|
|
|
38b7b2 |
num_existing_areas++;
|
|
|
38b7b2 |
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
|
|
|
38b7b2 |
index 0e77a009d..c67a86fa3 100644
|
|
|
38b7b2 |
--- a/lib/device/dev-type.c
|
|
|
38b7b2 |
+++ b/lib/device/dev-type.c
|
|
|
38b7b2 |
@@ -966,6 +966,9 @@ static int _wipe_known_signatures_with_blkid(struct device *dev, const char *nam
|
|
|
38b7b2 |
|
|
|
38b7b2 |
/* TODO: Should we check for valid dev - _dev_is_valid(dev)? */
|
|
|
38b7b2 |
|
|
|
38b7b2 |
+ if (dm_list_empty(&dev->aliases))
|
|
|
38b7b2 |
+ goto_out;
|
|
|
38b7b2 |
+
|
|
|
38b7b2 |
if (!(probe = blkid_new_probe_from_filename(dev_name(dev)))) {
|
|
|
38b7b2 |
log_error("Failed to create a new blkid probe for device %s.", dev_name(dev));
|
|
|
38b7b2 |
goto out;
|
|
|
38b7b2 |
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
|
|
|
38b7b2 |
index bcb2e6bcf..82db6e4a5 100644
|
|
|
38b7b2 |
--- a/lib/device/device_id.c
|
|
|
38b7b2 |
+++ b/lib/device/device_id.c
|
|
|
38b7b2 |
@@ -347,6 +347,8 @@ const char *device_id_system_read(struct cmd_context *cmd, struct device *dev, u
|
|
|
38b7b2 |
}
|
|
|
38b7b2 |
|
|
|
38b7b2 |
else if (idtype == DEV_ID_TYPE_DEVNAME) {
|
|
|
38b7b2 |
+ if (dm_list_empty(&dev->aliases))
|
|
|
38b7b2 |
+ goto_bad;
|
|
|
38b7b2 |
if (!(idname = strdup(dev_name(dev))))
|
|
|
38b7b2 |
goto_bad;
|
|
|
38b7b2 |
return idname;
|
|
|
38b7b2 |
@@ -940,6 +942,10 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_
|
|
|
38b7b2 |
if (!dev_get_partition_number(dev, &part))
|
|
|
38b7b2 |
return_0;
|
|
|
38b7b2 |
|
|
|
38b7b2 |
+ /* Ensure valid dev_name(dev) below. */
|
|
|
38b7b2 |
+ if (dm_list_empty(&dev->aliases))
|
|
|
38b7b2 |
+ return_0;
|
|
|
38b7b2 |
+
|
|
|
38b7b2 |
/*
|
|
|
38b7b2 |
* When enable_devices_file=0 and pending_devices_file=1 we let
|
|
|
38b7b2 |
* pvcreate/vgcreate add new du's to cmd->use_devices. These du's may
|
|
|
38b7b2 |
@@ -1820,6 +1826,9 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
|
|
|
38b7b2 |
if (dev->flags & DEV_SCAN_NOT_READ)
|
|
|
38b7b2 |
continue;
|
|
|
38b7b2 |
|
|
|
38b7b2 |
+ if (dm_list_empty(&dev->aliases))
|
|
|
38b7b2 |
+ continue;
|
|
|
38b7b2 |
+
|
|
|
38b7b2 |
if (!cmd->filter->passes_filter(cmd, cmd->filter, dev, "persistent")) {
|
|
|
38b7b2 |
log_warn("Devices file %s is excluded by filter: %s.",
|
|
|
38b7b2 |
dev_name(dev), dev_filtered_reason(dev));
|
|
|
38b7b2 |
@@ -2197,14 +2206,14 @@ void device_ids_find_renamed_devs(struct cmd_context *cmd, struct dm_list *dev_l
|
|
|
38b7b2 |
dm_list_iterate_items(dil, &search_pvids) {
|
|
|
38b7b2 |
char *dup_devname1, *dup_devname2, *dup_devname3;
|
|
|
38b7b2 |
|
|
|
38b7b2 |
- if (!dil->dev) {
|
|
|
38b7b2 |
+ if (!dil->dev || dm_list_empty(&dil->dev->aliases)) {
|
|
|
38b7b2 |
not_found++;
|
|
|
38b7b2 |
continue;
|
|
|
38b7b2 |
}
|
|
|
38b7b2 |
- found++;
|
|
|
38b7b2 |
|
|
|
38b7b2 |
dev = dil->dev;
|
|
|
38b7b2 |
devname = dev_name(dev);
|
|
|
38b7b2 |
+ found++;
|
|
|
38b7b2 |
|
|
|
38b7b2 |
if (!(du = get_du_for_pvid(cmd, dil->pvid))) {
|
|
|
38b7b2 |
/* shouldn't happen */
|
|
|
38b7b2 |
diff --git a/lib/label/hints.c b/lib/label/hints.c
|
|
|
38b7b2 |
index 95d5d77b8..2a7b3dca7 100644
|
|
|
38b7b2 |
--- a/lib/label/hints.c
|
|
|
38b7b2 |
+++ b/lib/label/hints.c
|
|
|
38b7b2 |
@@ -498,6 +498,8 @@ int validate_hints(struct cmd_context *cmd, struct dm_list *hints)
|
|
|
38b7b2 |
if (!(iter = dev_iter_create(NULL, 0)))
|
|
|
38b7b2 |
return 0;
|
|
|
38b7b2 |
while ((dev = dev_iter_get(cmd, iter))) {
|
|
|
38b7b2 |
+ if (dm_list_empty(&dev->aliases))
|
|
|
38b7b2 |
+ continue;
|
|
|
38b7b2 |
if (!(hint = _find_hint_name(hints, dev_name(dev))))
|
|
|
38b7b2 |
continue;
|
|
|
38b7b2 |
|
|
|
38b7b2 |
diff --git a/lib/label/label.c b/lib/label/label.c
|
|
|
38b7b2 |
index ffe925254..cf707f7a3 100644
|
|
|
38b7b2 |
--- a/lib/label/label.c
|
|
|
38b7b2 |
+++ b/lib/label/label.c
|
|
|
38b7b2 |
@@ -1565,10 +1565,24 @@ int label_scan_open_rw(struct device *dev)
|
|
|
38b7b2 |
|
|
|
38b7b2 |
int label_scan_reopen_rw(struct device *dev)
|
|
|
38b7b2 |
{
|
|
|
38b7b2 |
+ const char *name;
|
|
|
38b7b2 |
int flags = 0;
|
|
|
38b7b2 |
int prev_fd = dev->bcache_fd;
|
|
|
38b7b2 |
int fd;
|
|
|
38b7b2 |
|
|
|
38b7b2 |
+ if (dm_list_empty(&dev->aliases)) {
|
|
|
38b7b2 |
+ log_error("Cannot reopen rw device %d:%d with no valid paths di %d fd %d.",
|
|
|
38b7b2 |
+ (int)MAJOR(dev->dev), (int)MINOR(dev->dev), dev->bcache_di, dev->bcache_fd);
|
|
|
38b7b2 |
+ return 0;
|
|
|
38b7b2 |
+ }
|
|
|
38b7b2 |
+
|
|
|
38b7b2 |
+ name = dev_name(dev);
|
|
|
38b7b2 |
+ if (!name || name[0] != '/') {
|
|
|
38b7b2 |
+ log_error("Cannot reopen rw device %d:%d with no valid name di %d fd %d.",
|
|
|
38b7b2 |
+ (int)MAJOR(dev->dev), (int)MINOR(dev->dev), dev->bcache_di, dev->bcache_fd);
|
|
|
38b7b2 |
+ return 0;
|
|
|
38b7b2 |
+ }
|
|
|
38b7b2 |
+
|
|
|
38b7b2 |
if (!(dev->flags & DEV_IN_BCACHE)) {
|
|
|
38b7b2 |
if ((dev->bcache_fd != -1) || (dev->bcache_di != -1)) {
|
|
|
38b7b2 |
/* shouldn't happen */
|
|
|
38b7b2 |
@@ -1598,7 +1612,7 @@ int label_scan_reopen_rw(struct device *dev)
|
|
|
38b7b2 |
flags |= O_NOATIME;
|
|
|
38b7b2 |
flags |= O_RDWR;
|
|
|
38b7b2 |
|
|
|
38b7b2 |
- fd = open(dev_name(dev), flags, 0777);
|
|
|
38b7b2 |
+ fd = open(name, flags, 0777);
|
|
|
38b7b2 |
if (fd < 0) {
|
|
|
38b7b2 |
log_error("Failed to open rw %s errno %d di %d fd %d.",
|
|
|
38b7b2 |
dev_name(dev), errno, dev->bcache_di, dev->bcache_fd);
|
|
|
38b7b2 |
diff --git a/lib/locking/lvmlockd.c b/lib/locking/lvmlockd.c
|
|
|
38b7b2 |
index b598df3d6..60c80f1b1 100644
|
|
|
38b7b2 |
--- a/lib/locking/lvmlockd.c
|
|
|
38b7b2 |
+++ b/lib/locking/lvmlockd.c
|
|
|
38b7b2 |
@@ -272,6 +272,8 @@ static void _lockd_retrive_vg_pv_list(struct volume_group *vg,
|
|
|
38b7b2 |
|
|
|
38b7b2 |
i = 0;
|
|
|
38b7b2 |
dm_list_iterate_items(pvl, &vg->pvs) {
|
|
|
38b7b2 |
+ if (!pvl->pv->dev || dm_list_empty(&pvl->pv->dev->aliases))
|
|
|
38b7b2 |
+ continue;
|
|
|
38b7b2 |
lock_pvs->path[i] = strdup(pv_dev_name(pvl->pv));
|
|
|
38b7b2 |
if (!lock_pvs->path[i]) {
|
|
|
38b7b2 |
log_error("Fail to allocate PV path for VG %s", vg->name);
|
|
|
38b7b2 |
@@ -341,6 +343,8 @@ static void _lockd_retrive_lv_pv_list(struct volume_group *vg,
|
|
|
38b7b2 |
|
|
|
38b7b2 |
dm_list_iterate_items(pvl, &vg->pvs) {
|
|
|
38b7b2 |
if (lv_is_on_pv(lv, pvl->pv)) {
|
|
|
38b7b2 |
+ if (!pvl->pv->dev || dm_list_empty(&pvl->pv->dev->aliases))
|
|
|
38b7b2 |
+ continue;
|
|
|
38b7b2 |
lock_pvs->path[i] = strdup(pv_dev_name(pvl->pv));
|
|
|
38b7b2 |
if (!lock_pvs->path[i]) {
|
|
|
38b7b2 |
log_error("Fail to allocate PV path for LV %s/%s",
|
|
|
38b7b2 |
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
|
|
|
38b7b2 |
index e2bf191a1..46da57948 100644
|
|
|
38b7b2 |
--- a/lib/metadata/mirror.c
|
|
|
38b7b2 |
+++ b/lib/metadata/mirror.c
|
|
|
38b7b2 |
@@ -1231,14 +1231,23 @@ int remove_mirrors_from_segments(struct logical_volume *lv,
|
|
|
38b7b2 |
const char *get_pvmove_pvname_from_lv_mirr(const struct logical_volume *lv_mirr)
|
|
|
38b7b2 |
{
|
|
|
38b7b2 |
struct lv_segment *seg;
|
|
|
38b7b2 |
+ struct device *dev;
|
|
|
38b7b2 |
|
|
|
38b7b2 |
dm_list_iterate_items(seg, &lv_mirr->segments) {
|
|
|
38b7b2 |
if (!seg_is_mirrored(seg))
|
|
|
38b7b2 |
continue;
|
|
|
38b7b2 |
- if (seg_type(seg, 0) == AREA_PV)
|
|
|
38b7b2 |
- return dev_name(seg_dev(seg, 0));
|
|
|
38b7b2 |
- if (seg_type(seg, 0) == AREA_LV)
|
|
|
38b7b2 |
- return dev_name(seg_dev(first_seg(seg_lv(seg, 0)), 0));
|
|
|
38b7b2 |
+ if (seg_type(seg, 0) == AREA_PV) {
|
|
|
38b7b2 |
+ dev = seg_dev(seg, 0);
|
|
|
38b7b2 |
+ if (!dev || dm_list_empty(&dev->aliases))
|
|
|
38b7b2 |
+ return NULL;
|
|
|
38b7b2 |
+ return dev_name(dev);
|
|
|
38b7b2 |
+ }
|
|
|
38b7b2 |
+ if (seg_type(seg, 0) == AREA_LV) {
|
|
|
38b7b2 |
+ dev = seg_dev(first_seg(seg_lv(seg, 0)), 0);
|
|
|
38b7b2 |
+ if (!dev || dm_list_empty(&dev->aliases))
|
|
|
38b7b2 |
+ return NULL;
|
|
|
38b7b2 |
+ return dev_name(dev);
|
|
|
38b7b2 |
+ }
|
|
|
38b7b2 |
}
|
|
|
38b7b2 |
|
|
|
38b7b2 |
return NULL;
|
|
|
38b7b2 |
diff --git a/lib/metadata/pv_list.c b/lib/metadata/pv_list.c
|
|
|
38b7b2 |
index 813e8e525..fc3667db0 100644
|
|
|
38b7b2 |
--- a/lib/metadata/pv_list.c
|
|
|
38b7b2 |
+++ b/lib/metadata/pv_list.c
|
|
|
38b7b2 |
@@ -152,6 +152,11 @@ static int _create_pv_entry(struct dm_pool *mem, struct pv_list *pvl,
|
|
|
38b7b2 |
struct pv_list *new_pvl = NULL, *pvl2;
|
|
|
38b7b2 |
struct dm_list *pe_ranges;
|
|
|
38b7b2 |
|
|
|
38b7b2 |
+ if (!pvl->pv->dev || dm_list_empty(&pvl->pv->dev->aliases)) {
|
|
|
38b7b2 |
+ log_error("Failed to create PV entry for missing device.");
|
|
|
38b7b2 |
+ return 0;
|
|
|
38b7b2 |
+ }
|
|
|
38b7b2 |
+
|
|
|
38b7b2 |
pvname = pv_dev_name(pvl->pv);
|
|
|
38b7b2 |
if (allocatable_only && !(pvl->pv->status & ALLOCATABLE_PV)) {
|
|
|
38b7b2 |
log_warn("WARNING: Physical volume %s not allocatable.", pvname);
|
|
|
38b7b2 |
diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c
|
|
|
38b7b2 |
index 85482552a..adc954bab 100644
|
|
|
38b7b2 |
--- a/lib/metadata/vg.c
|
|
|
38b7b2 |
+++ b/lib/metadata/vg.c
|
|
|
38b7b2 |
@@ -679,6 +679,11 @@ int vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
|
|
|
38b7b2 |
return r;
|
|
|
38b7b2 |
}
|
|
|
38b7b2 |
|
|
|
38b7b2 |
+ if (!pv->dev || dm_list_empty(&pv->dev->aliases)) {
|
|
|
38b7b2 |
+ log_error("No device found for PV.");
|
|
|
38b7b2 |
+ return r;
|
|
|
38b7b2 |
+ }
|
|
|
38b7b2 |
+
|
|
|
38b7b2 |
log_debug("vgreduce_single VG %s PV %s", vg->name, pv_dev_name(pv));
|
|
|
38b7b2 |
|
|
|
38b7b2 |
if (pv_pe_alloc_count(pv)) {
|
|
|
38b7b2 |
diff --git a/test/shell/losetup-partscan.sh b/test/shell/losetup-partscan.sh
|
|
|
38b7b2 |
index 99f552ad1..670568945 100644
|
|
|
38b7b2 |
--- a/test/shell/losetup-partscan.sh
|
|
|
38b7b2 |
+++ b/test/shell/losetup-partscan.sh
|
|
|
38b7b2 |
@@ -33,6 +33,8 @@ aux udev_wait
|
|
|
38b7b2 |
ls -la "${LOOP}"*
|
|
|
38b7b2 |
test -e "${LOOP}p1"
|
|
|
38b7b2 |
|
|
|
38b7b2 |
+aux lvmconf 'devices/scan = "/dev"'
|
|
|
38b7b2 |
+
|
|
|
38b7b2 |
aux extend_filter "a|$LOOP|"
|
|
|
38b7b2 |
aux extend_devices "$LOOP"
|
|
|
38b7b2 |
|
|
|
38b7b2 |
--
|
|
|
38b7b2 |
2.34.3
|
|
|
38b7b2 |
|