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

metadata: add get_or_create_glv and get_or_create_glvl

The get_or_create_glv is helper function that retrieves any existing
generic_logical_volume wrapper for the LV. If the wrapper does not exist
yet, it's created.

The get_org_create_glvl is the same as get_or_create_glv but it creates
the glv_list wrapper in addition so it can be added to a list.
This commit is contained in:
Peter Rajnoha 2016-03-01 15:19:23 +01:00
parent e573eca554
commit 937f72b168
2 changed files with 39 additions and 0 deletions

View File

@ -5307,6 +5307,42 @@ char *generate_lv_name(struct volume_group *vg, const char *format,
return buffer;
}
struct generic_logical_volume *get_or_create_glv(struct dm_pool*mem, struct logical_volume *lv, int *glv_created)
{
struct generic_logical_volume *glv;
if (!(glv = lv->this_glv)) {
if (!(glv = dm_pool_zalloc(mem, sizeof(struct generic_logical_volume)))) {
log_error("Failed to allocate generic logical volume structure.");
return NULL;
}
glv->live = lv;
lv->this_glv = glv;
if (glv_created)
*glv_created = 1;
} else if (glv_created)
*glv_created = 0;
return glv;
}
struct glv_list *get_or_create_glvl(struct dm_pool *mem, struct logical_volume *lv, int *glv_created)
{
struct glv_list *glvl;
if (!(glvl = dm_pool_zalloc(mem, sizeof(struct glv_list)))) {
log_error("Failed to allocate generic logical volume list item.");
return NULL;
}
if (!(glvl->glv = get_or_create_glv(mem, lv, glv_created))) {
dm_pool_free(mem, glvl);
return_NULL;
}
return glvl;
}
struct logical_volume *alloc_lv(struct dm_pool *mem)
{
struct logical_volume *lv;

View File

@ -1238,6 +1238,9 @@ dm_percent_t copy_percent(const struct logical_volume *lv_mirr);
char *generate_lv_name(struct volume_group *vg, const char *format,
char *buffer, size_t len);
struct generic_logical_volume *get_or_create_glv(struct dm_pool *mem, struct logical_volume *lv, int *glv_created);
struct glv_list *get_or_create_glvl(struct dm_pool *mem, struct logical_volume *lv, int *glv_created);
/*
* Begin skeleton for external LVM library
*/