From fa11ef6846a07a3131991cf4abfe130fc488920c Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Tue, 15 Oct 2024 13:31:21 +0200 Subject: [PATCH] metadata: look for LV by name with find_lv Avoid getting dm_list reference when looking for logical_volume*. --- lib/locking/lvmlockd.c | 12 ++++++------ lib/metadata/raid_manip.c | 6 ++---- lib/report/report.c | 9 ++++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/locking/lvmlockd.c b/lib/locking/lvmlockd.c index f01816494..72fa808e7 100644 --- a/lib/locking/lvmlockd.c +++ b/lib/locking/lvmlockd.c @@ -3266,7 +3266,7 @@ int lockd_init_lv(struct cmd_context *cmd, struct volume_group *vg, struct logic } else if (seg_is_thin(lp)) { if ((seg_is_thin_volume(lp) && !lp->create_pool) || (!seg_is_thin_volume(lp) && lp->origin_name)) { - struct lv_list *lvl; + struct logical_volume *thin_pool_lv; /* * Creating a new thin lv or snapshot. These lvs do not get @@ -3275,11 +3275,11 @@ int lockd_init_lv(struct cmd_context *cmd, struct volume_group *vg, struct logic */ log_debug("lockd_init_lv thin %s locking thin pool", display_lvname(lv)); - if (!(lvl = find_lv_in_vg(vg, lp->pool_name))) { + if (!(thin_pool_lv = find_lv(vg, lp->pool_name))) { log_error("Failed to find thin pool %s/%s", vg->name, lp->pool_name); return 0; } - if (!lockd_lv(cmd, lvl->lv, "ex", 0)) { + if (!lockd_lv(cmd, thin_pool_lv, "ex", 0)) { log_error("Failed to lock thin pool %s/%s", vg->name, lp->pool_name); return 0; } @@ -3308,7 +3308,7 @@ int lockd_init_lv(struct cmd_context *cmd, struct volume_group *vg, struct logic } } else if (seg_is_vdo(lp)) { - struct lv_list *lvl; + struct logical_volume *vdo_pool_lv; /* * A vdo lv is being created in a vdo pool. The vdo lv does @@ -3316,12 +3316,12 @@ int lockd_init_lv(struct cmd_context *cmd, struct volume_group *vg, struct logic * the vdo pool needs to be locked to create a vdo lv in it. */ - if (!(lvl = find_lv_in_vg(vg, lp->pool_name))) { + if (!(vdo_pool_lv = find_lv(vg, lp->pool_name))) { log_error("Failed to find vdo pool %s/%s", vg->name, lp->pool_name); return 0; } - if (!lockd_lv(cmd, lvl->lv, "ex", LDLV_PERSISTENT)) { + if (!lockd_lv(cmd, vdo_pool_lv, "ex", LDLV_PERSISTENT)) { log_error("Failed to lock vdo pool %s/%s", vg->name, lp->pool_name); return 0; } diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c index af461250a..856d8340d 100644 --- a/lib/metadata/raid_manip.c +++ b/lib/metadata/raid_manip.c @@ -3579,7 +3579,6 @@ int lv_raid_merge(struct logical_volume *image_lv) { uint32_t s; char *p, *lv_name; - struct lv_list *lvl; struct logical_volume *lv; struct logical_volume *meta_lv = NULL; struct lv_segment *seg; @@ -3601,17 +3600,16 @@ int lv_raid_merge(struct logical_volume *image_lv) } *p = '\0'; /* lv_name is now that of top-level RAID */ - if (!(lvl = find_lv_in_vg(vg, lv_name))) { + if (!(lv = find_lv(vg, lv_name))) { log_error("Unable to find containing RAID array for %s.", display_lvname(image_lv)); return 0; } /* Ensure primary LV is not active elsewhere. */ - if (!lockd_lv(vg->cmd, lvl->lv, "ex", 0)) + if (!lockd_lv(vg->cmd, lv, "ex", 0)) return_0; - lv = lvl->lv; seg = first_seg(lv); for (s = 0; s < seg->area_count; ++s) if (seg_lv(seg, s) == image_lv) diff --git a/lib/report/report.c b/lib/report/report.c index a6e478787..9ec596fbc 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -2622,13 +2622,12 @@ static struct logical_volume *_lv_for_raid_image_seg(const struct lv_segment *se p = strchr(p + 5, '_'); if (p) { - struct lv_list *lvl; + struct logical_volume *lv; *p = '\0'; - if ((lvl = find_lv_in_vg(seg->lv->vg, lv_name)) && - seg_is_reshapable_raid(first_seg(lvl->lv))) - return lvl->lv; - + if ((lv = find_lv(seg->lv->vg, lv_name)) && + seg_is_reshapable_raid(first_seg(lv))) + return lv; } } }