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

vg: add radix_tree for lv uuids

When searching for committed LV by uuid, this search can
be expensive for commands like 'vgremove' - so for
this part introduce  'lv_uuids' radix_tree that is
build with first access to lv_committed().
This commit is contained in:
Zdenek Kabelac 2024-10-26 22:37:00 +02:00
parent 61252f535f
commit 13aea49489
3 changed files with 19 additions and 0 deletions

View File

@ -1667,6 +1667,10 @@ struct logical_volume *find_lv_in_vg_by_lvid(const struct volume_group *vg,
if (memcmp(&lvid->id[0], &vg->id, ID_LEN))
return NULL; /* Check VG does not match */
if (vg->lv_uuids)
return radix_tree_lookup_ptr(vg->lv_uuids, &lvid->id[1],
sizeof(lvid->id[1]));
dm_list_iterate_items(lvl, &vg->lvs)
if (!memcmp(&lvid->id[1], &lvl->lv->lvid.id[1], sizeof(lvid->id[1])))
return lvl->lv; /* LV uuid match */
@ -4344,6 +4348,7 @@ const struct logical_volume *lv_committed(const struct logical_volume *lv)
{
struct volume_group *vg;
const struct logical_volume *found_lv;
struct lv_list *lvl;
if (!lv)
return NULL;
@ -4353,6 +4358,16 @@ const struct logical_volume *lv_committed(const struct logical_volume *lv)
vg = lv->vg->vg_committed;
if (!vg->lv_uuids &&
(vg->lv_uuids = radix_tree_create(NULL, NULL)))
dm_list_iterate_items(lvl, &vg->lvs) {
if (!radix_tree_insert_ptr(vg->lv_uuids,
&lvl->lv->lvid.id[1],
sizeof(lvl->lv->lvid.id[1]),
lvl->lv))
return NULL;
}
if (!(found_lv = find_lv_in_vg_by_lvid(vg, &lv->lvid))) {
log_error(INTERNAL_ERROR "LV %s (UUID %s) not found in committed metadata.",
display_lvname(lv), lv->lvid.s);

View File

@ -81,6 +81,9 @@ static void _free_vg(struct volume_group *vg)
if (vg->lv_names)
radix_tree_destroy(vg->lv_names);
if (vg->lv_uuids)
radix_tree_destroy(vg->lv_uuids);
if (vg->pv_names)
radix_tree_destroy(vg->pv_names);

View File

@ -65,6 +65,7 @@ struct volume_group {
uint64_t status;
struct radix_tree *lv_names; /* maintained tree for LV names within VG */
struct radix_tree *lv_uuids; /* LV uuid (when searching committed metadata) */
struct radix_tree *pv_names; /* PV names used for metadata import */
struct id id;