1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-30 17:18:21 +03:00

pool: code refactoring

Move pool related manipulation code to pool_manip.c.
This commit is contained in:
Zdenek Kabelac 2023-12-08 14:10:39 +01:00
parent a176184b7d
commit c496f80379
3 changed files with 33 additions and 31 deletions

View File

@ -937,6 +937,8 @@ struct logical_volume *alloc_pool_metadata(struct logical_volume *pool_lv,
uint32_t stripes, uint32_t stripe_size, uint32_t stripes, uint32_t stripe_size,
uint32_t extents, alloc_policy_t alloc, uint32_t extents, alloc_policy_t alloc,
struct dm_list *pvh); struct dm_list *pvh);
int add_metadata_to_pool(struct lv_segment *pool_seg,
struct logical_volume *metadata_lv);
int handle_pool_metadata_spare(struct volume_group *vg, uint32_t extents, int handle_pool_metadata_spare(struct volume_group *vg, uint32_t extents,
struct dm_list *pvh, int poolmetadataspare); struct dm_list *pvh, int poolmetadataspare);
int vg_set_pool_metadata_spare(struct logical_volume *lv); int vg_set_pool_metadata_spare(struct logical_volume *lv);

View File

@ -642,6 +642,36 @@ struct logical_volume *alloc_pool_metadata(struct logical_volume *pool_lv,
return metadata_lv; return metadata_lv;
} }
int add_metadata_to_pool(struct lv_segment *pool_seg,
struct logical_volume *metadata_lv)
{
struct cmd_context *cmd = metadata_lv->vg->cmd;
char name[NAME_LEN]; /* generated sub lv name */
if (!deactivate_lv(cmd, metadata_lv)) {
log_error("Aborting. Failed to deactivate metadata lv. "
"Manual intervention required.");
return 0;
}
if ((dm_snprintf(name, sizeof(name), "%s%s", pool_seg->lv->name,
seg_is_thin_pool(pool_seg) ? "_tmeta" : "_cmeta") < 0)) {
log_error("Failed to create internal lv names, %s name is too long.",
pool_seg->lv->name);
return 0;
}
/* Rename LVs to the pool _[ct]meta LV naming scheme. */
if ((strcmp(metadata_lv->name, name) != 0) &&
!lv_rename_update(cmd, metadata_lv, name, 0))
return_0;
if (!attach_pool_metadata_lv(pool_seg, metadata_lv))
return_0;
return 1;
}
static struct logical_volume *_alloc_pool_metadata_spare(struct volume_group *vg, static struct logical_volume *_alloc_pool_metadata_spare(struct volume_group *vg,
uint32_t extents, uint32_t extents,
struct dm_list *pvh) struct dm_list *pvh)

View File

@ -3018,36 +3018,6 @@ static struct logical_volume *_lvconvert_insert_thin_layer(struct logical_volume
return pool_lv; return pool_lv;
} }
static int _lvconvert_attach_metadata_to_pool(struct lv_segment *pool_seg,
struct logical_volume *metadata_lv)
{
struct cmd_context *cmd = metadata_lv->vg->cmd;
char name[NAME_LEN]; /* generated sub lv name */
if (!deactivate_lv(cmd, metadata_lv)) {
log_error("Aborting. Failed to deactivate metadata lv. "
"Manual intervention required.");
return 0;
}
if ((dm_snprintf(name, sizeof(name), "%s%s", pool_seg->lv->name,
seg_is_thin_pool(pool_seg) ? "_tmeta" : "_cmeta") < 0)) {
log_error("Failed to create internal lv names, %s name is too long.",
pool_seg->lv->name);
return 0;
}
/* Rename LVs to the pool _[ct]meta LV naming scheme. */
if ((strcmp(metadata_lv->name, name) != 0) &&
!lv_rename_update(cmd, metadata_lv, name, 0))
return_0;
if (!attach_pool_metadata_lv(pool_seg, metadata_lv))
return_0;
return 1;
}
/* /*
* Create a new pool LV, using the lv arg as the data sub LV. * Create a new pool LV, using the lv arg as the data sub LV.
* The metadata sub LV is either a new LV created here, or an * The metadata sub LV is either a new LV created here, or an
@ -3448,7 +3418,7 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
} }
} }
if (!_lvconvert_attach_metadata_to_pool(seg, metadata_lv)) if (!add_metadata_to_pool(seg, metadata_lv))
goto_bad; goto_bad;
/* /*