mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
metadata: use radix_tree for find_lv_in_vg
Since there is a group of commands that need to access 'lv_list' while still need to search for LV by its name, make the whole struct lv_list a member of logical_volume structure. This makes it easy to return also 'lv_list' this list this LV within VG. Also the patch should not use more memory, since we were allocating lv_list for each LV anyway when linkin LV to VG. Since find_lv_by_name() is now using radix_tree(), use the same 'search for /' in LV in name for both find_lv() & find_lv_in_vg(). TODO: Possibly refactor code and use only dm_list instead of lv_list and dereference LV with container_of() (thus saving pointer within struct logical_volume) - but we use 'lv_list' currently in many places...
This commit is contained in:
parent
0e5beb92c5
commit
db0f1b799f
@ -21,7 +21,14 @@ union lvid;
|
||||
struct lv_segment;
|
||||
enum activation_change;
|
||||
|
||||
struct lv_list {
|
||||
struct dm_list list;
|
||||
struct logical_volume *lv;
|
||||
};
|
||||
|
||||
struct logical_volume {
|
||||
/* NOTE: lvid must be the first structure member as it's used for
|
||||
* offsetof() calculation in report.c with columns.h */
|
||||
union lvid lvid;
|
||||
const char *name;
|
||||
|
||||
@ -41,6 +48,7 @@ struct logical_volume {
|
||||
struct dm_list snapshot_segs;
|
||||
struct lv_segment *snapshot;
|
||||
|
||||
struct lv_list lvl;
|
||||
struct dm_list segments;
|
||||
struct dm_list tags;
|
||||
struct dm_list segs_using_this_lv;
|
||||
|
@ -573,11 +573,6 @@ struct pv_list {
|
||||
struct dm_list *pe_ranges; /* Ranges of PEs e.g. for allocation */
|
||||
};
|
||||
|
||||
struct lv_list {
|
||||
struct dm_list list;
|
||||
struct logical_volume *lv;
|
||||
};
|
||||
|
||||
struct glv_list {
|
||||
struct dm_list list;
|
||||
struct generic_logical_volume *glv;
|
||||
|
@ -1637,6 +1637,7 @@ struct pv_list *find_pv_in_vg_by_uuid(const struct volume_group *vg,
|
||||
struct lv_list *find_lv_in_vg(const struct volume_group *vg,
|
||||
const char *lv_name)
|
||||
{
|
||||
struct logical_volume *lv;
|
||||
struct lv_list *lvl;
|
||||
const char *ptr;
|
||||
|
||||
@ -1646,6 +1647,11 @@ struct lv_list *find_lv_in_vg(const struct volume_group *vg,
|
||||
else
|
||||
ptr = lv_name;
|
||||
|
||||
if (vg->lv_names) {
|
||||
lv = radix_tree_lookup_ptr(vg->lv_names, ptr, strlen(ptr));
|
||||
return (lv) ? &lv->lvl : NULL;
|
||||
}
|
||||
|
||||
dm_list_iterate_items(lvl, &vg->lvs)
|
||||
if (!strcmp(lvl->lv->name, ptr))
|
||||
return lvl;
|
||||
@ -1671,12 +1677,8 @@ struct logical_volume *find_lv_in_vg_by_lvid(const struct volume_group *vg,
|
||||
struct logical_volume *find_lv(const struct volume_group *vg,
|
||||
const char *lv_name)
|
||||
{
|
||||
if (!vg->lv_names) {
|
||||
struct lv_list *lvl = find_lv_in_vg(vg, lv_name);
|
||||
return lvl ? lvl->lv : NULL;
|
||||
}
|
||||
|
||||
return radix_tree_lookup_ptr(vg->lv_names, lv_name, strlen(lv_name));
|
||||
struct lv_list *lvl = find_lv_in_vg(vg, lv_name);
|
||||
return lvl ? lvl->lv : NULL;
|
||||
}
|
||||
|
||||
struct generic_logical_volume *find_historical_glv(const struct volume_group *vg,
|
||||
|
@ -116,9 +116,7 @@ int link_lv_to_vg(struct volume_group *vg, struct logical_volume *lv)
|
||||
if (vg_max_lv_reached(vg))
|
||||
stack;
|
||||
|
||||
if (!(lvl = dm_pool_zalloc(vg->vgmem, sizeof(*lvl))))
|
||||
return_0;
|
||||
|
||||
lvl = &lv->lvl;
|
||||
lvl->lv = lv;
|
||||
lv->vg = vg;
|
||||
dm_list_add(&vg->lvs, &lvl->list);
|
||||
|
Loading…
Reference in New Issue
Block a user