1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

metadata: look for LV by name with find_lv

Avoid getting dm_list reference when looking for logical_volume*.
This commit is contained in:
Zdenek Kabelac 2024-10-15 13:31:21 +02:00
parent 1755ceb17c
commit fa11ef6846
3 changed files with 12 additions and 15 deletions

View File

@ -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;
}

View File

@ -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)

View File

@ -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;
}
}
}