1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

thin_pool: code refactoring

Move common code into thin_pool_set_params()
(just like we use  cache_set_params).
This commit is contained in:
Zdenek Kabelac 2023-12-07 18:07:56 +01:00
parent f3f7f5db89
commit a176184b7d
4 changed files with 50 additions and 22 deletions

View File

@ -9486,18 +9486,16 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
first_seg(lv)->min_recovery_rate = lp->min_recovery_rate;
first_seg(lv)->max_recovery_rate = lp->max_recovery_rate;
} else if (lv_is_thin_pool(lv)) {
first_seg(lv)->chunk_size = lp->chunk_size;
first_seg(lv)->zero_new_blocks = lp->zero_new_blocks;
first_seg(lv)->discards = lp->discards;
if ((first_seg(lv)->crop_metadata = lp->crop_metadata) == THIN_CROP_METADATA_NO)
lv->status |= LV_CROP_METADATA;
if (!recalculate_pool_chunk_size_with_dev_hints(lv, seg_lv(first_seg(lv), 0),
lp->thin_chunk_size_calc_policy)) {
if (!thin_pool_set_params(first_seg(lv),
lp->error_when_full,
lp->crop_metadata,
lp->thin_chunk_size_calc_policy,
lp->chunk_size,
lp->discards,
lp->zero_new_blocks)) {
stack;
goto revert_new_lv;
}
if (lp->error_when_full)
lv->status |= LV_ERROR_WHEN_FULL;
} else if (pool_lv && lv_is_virtual(lv) && /* not yet thin LV */
(seg = first_seg(lv)) &&
seg_is_thin(seg)) { /* going to be a thin volume */

View File

@ -909,6 +909,13 @@ int update_thin_pool_params(struct cmd_context *cmd,
thin_crop_metadata_t *crop_metadata,
int *chunk_size_calc_method, uint32_t *chunk_size,
thin_discards_t *discards, thin_zero_t *zero_new_blocks);
int thin_pool_set_params(struct lv_segment *seg,
int error_when_full,
thin_crop_metadata_t crop_metadata,
int thin_chunk_size_calc_policy,
uint32_t chunk_size,
thin_discards_t discards,
thin_zero_t zero_new_blocks);
struct lv_status_thin_pool {
struct dm_pool *mem;

View File

@ -775,6 +775,32 @@ thin_crop_metadata_t get_thin_pool_crop_metadata(struct cmd_context *cmd,
return crop;
}
int thin_pool_set_params(struct lv_segment *seg,
int error_when_full,
thin_crop_metadata_t crop_metadata,
int thin_chunk_size_calc_policy,
uint32_t chunk_size,
thin_discards_t discards,
thin_zero_t zero_new_blocks)
{
if (!recalculate_pool_chunk_size_with_dev_hints(seg->lv, seg_lv(seg, 0),
thin_chunk_size_calc_policy))
return_0;
if (error_when_full)
seg->lv->status |= LV_ERROR_WHEN_FULL;
if ((seg->crop_metadata = crop_metadata) == THIN_CROP_METADATA_NO)
seg->lv->status |= LV_CROP_METADATA;
seg->chunk_size = chunk_size;
seg->discards = discards;
seg->zero_new_blocks = zero_new_blocks;
seg->transaction_id = 0;
return 1;
}
int update_thin_pool_params(struct cmd_context *cmd,
struct profile *profile,
uint32_t extent_size,

View File

@ -3423,23 +3423,20 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
if (!cache_set_params(seg, chunk_size, cache_metadata_format, cache_mode, policy_name, policy_settings))
goto_bad;
} else {
seg->transaction_id = 0;
seg->crop_metadata = crop_metadata;
seg->chunk_size = chunk_size;
seg->discards = discards;
seg->zero_new_blocks = zero_new_blocks;
if (crop_metadata == THIN_CROP_METADATA_NO)
pool_lv->status |= LV_CROP_METADATA;
if (!recalculate_pool_chunk_size_with_dev_hints(pool_lv, data_lv, chunk_calc))
goto_bad;
/* Error when full */
if (arg_is_set(cmd, errorwhenfull_ARG))
error_when_full = arg_uint_value(cmd, errorwhenfull_ARG, 0);
error_when_full = arg_int_value(cmd, errorwhenfull_ARG, 0);
else
error_when_full = find_config_tree_bool(cmd, activation_error_when_full_CFG, vg->profile);
if (error_when_full)
pool_lv->status |= LV_ERROR_WHEN_FULL;
if (!thin_pool_set_params(seg,
error_when_full,
crop_metadata,
chunk_calc,
chunk_size,
discards,
zero_new_blocks))
goto_bad;
if (to_thin) {
if (!thin_pool_prepare_metadata(metadata_lv, seg->chunk_size,