mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-18 10:04:20 +03:00
thin: refactor parsing
This commit is contained in:
parent
7467c0156b
commit
1a11388c44
@ -81,30 +81,18 @@ static int _thin_pool_add_message(struct lv_segment *seg,
|
|||||||
static int _thin_pool_text_import(struct lv_segment *seg,
|
static int _thin_pool_text_import(struct lv_segment *seg,
|
||||||
const struct dm_config_node *sn)
|
const struct dm_config_node *sn)
|
||||||
{
|
{
|
||||||
const char *lv_name;
|
const char *lv_name, *meta_name;
|
||||||
struct logical_volume *pool_data_lv, *pool_metadata_lv;
|
struct logical_volume *pool_data_lv, *pool_metadata_lv;
|
||||||
const char *discards_str = NULL;
|
const char *discards_str = NULL;
|
||||||
uint32_t zero = 0;
|
uint32_t zero = 0;
|
||||||
uint32_t crop = 0;
|
uint32_t crop = UINT32_MAX;
|
||||||
|
|
||||||
if (!dm_config_get_str(sn, "metadata", &lv_name))
|
if (!dm_config_get_str(sn, "metadata", &meta_name))
|
||||||
return SEG_LOG_ERROR("Metadata must be a string in");
|
return SEG_LOG_ERROR("Metadata must be a string in");
|
||||||
|
|
||||||
if (!(pool_metadata_lv = find_lv(seg->lv->vg, lv_name)))
|
|
||||||
return SEG_LOG_ERROR("Unknown metadata %s in", lv_name);
|
|
||||||
|
|
||||||
if (!dm_config_get_str(sn, "pool", &lv_name))
|
if (!dm_config_get_str(sn, "pool", &lv_name))
|
||||||
return SEG_LOG_ERROR("Pool must be a string in");
|
return SEG_LOG_ERROR("Pool must be a string in");
|
||||||
|
|
||||||
if (!(pool_data_lv = find_lv(seg->lv->vg, lv_name)))
|
|
||||||
return SEG_LOG_ERROR("Unknown pool %s in", lv_name);
|
|
||||||
|
|
||||||
if (!attach_pool_data_lv(seg, pool_data_lv))
|
|
||||||
return_0;
|
|
||||||
|
|
||||||
if (!attach_pool_metadata_lv(seg, pool_metadata_lv))
|
|
||||||
return_0;
|
|
||||||
|
|
||||||
if (!dm_config_get_uint64(sn, "transaction_id", &seg->transaction_id))
|
if (!dm_config_get_uint64(sn, "transaction_id", &seg->transaction_id))
|
||||||
return SEG_LOG_ERROR("Could not read transaction_id for");
|
return SEG_LOG_ERROR("Could not read transaction_id for");
|
||||||
|
|
||||||
@ -115,6 +103,21 @@ static int _thin_pool_text_import(struct lv_segment *seg,
|
|||||||
!dm_config_get_str(sn, "discards", &discards_str))
|
!dm_config_get_str(sn, "discards", &discards_str))
|
||||||
return SEG_LOG_ERROR("Could not read discards for");
|
return SEG_LOG_ERROR("Could not read discards for");
|
||||||
|
|
||||||
|
if (dm_config_has_node(sn, "zero_new_blocks") &&
|
||||||
|
!dm_config_get_uint32(sn, "zero_new_blocks", &zero))
|
||||||
|
return SEG_LOG_ERROR("Could not read zero_new_blocks for");
|
||||||
|
|
||||||
|
if (dm_config_has_node(sn, "crop_metadata")) {
|
||||||
|
if (!dm_config_get_uint32(sn, "crop_metadata", &crop))
|
||||||
|
return SEG_LOG_ERROR("Could not read crop_metadata for");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(pool_data_lv = find_lv(seg->lv->vg, lv_name)))
|
||||||
|
return SEG_LOG_ERROR("Unknown pool %s in", lv_name);
|
||||||
|
|
||||||
|
if (!(pool_metadata_lv = find_lv(seg->lv->vg, meta_name)))
|
||||||
|
return SEG_LOG_ERROR("Unknown metadata %s in", lv_name);
|
||||||
|
|
||||||
if (!discards_str)
|
if (!discards_str)
|
||||||
seg->discards = THIN_DISCARDS_IGNORE;
|
seg->discards = THIN_DISCARDS_IGNORE;
|
||||||
else if (!set_pool_discards(&seg->discards, discards_str))
|
else if (!set_pool_discards(&seg->discards, discards_str))
|
||||||
@ -123,21 +126,21 @@ static int _thin_pool_text_import(struct lv_segment *seg,
|
|||||||
if ((seg->chunk_size < DM_THIN_MIN_DATA_BLOCK_SIZE) ||
|
if ((seg->chunk_size < DM_THIN_MIN_DATA_BLOCK_SIZE) ||
|
||||||
(seg->chunk_size > DM_THIN_MAX_DATA_BLOCK_SIZE))
|
(seg->chunk_size > DM_THIN_MAX_DATA_BLOCK_SIZE))
|
||||||
return SEG_LOG_ERROR("Unsupported value %u for chunk_size",
|
return SEG_LOG_ERROR("Unsupported value %u for chunk_size",
|
||||||
seg->device_id);
|
seg->chunk_size);
|
||||||
|
|
||||||
if (dm_config_has_node(sn, "zero_new_blocks") &&
|
if (crop != UINT32_MAX) {
|
||||||
!dm_config_get_uint32(sn, "zero_new_blocks", &zero))
|
|
||||||
return SEG_LOG_ERROR("Could not read zero_new_blocks for");
|
|
||||||
|
|
||||||
seg->zero_new_blocks = (zero) ? THIN_ZERO_YES : THIN_ZERO_NO;
|
|
||||||
|
|
||||||
if (dm_config_has_node(sn, "crop_metadata")) {
|
|
||||||
if (!dm_config_get_uint32(sn, "crop_metadata", &crop))
|
|
||||||
return SEG_LOG_ERROR("Could not read crop_metadata for");
|
|
||||||
seg->crop_metadata = (crop) ? THIN_CROP_METADATA_YES : THIN_CROP_METADATA_NO;
|
seg->crop_metadata = (crop) ? THIN_CROP_METADATA_YES : THIN_CROP_METADATA_NO;
|
||||||
seg->lv->status |= LV_CROP_METADATA;
|
seg->lv->status |= LV_CROP_METADATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
seg->zero_new_blocks = (zero) ? THIN_ZERO_YES : THIN_ZERO_NO;
|
||||||
|
|
||||||
|
if (!attach_pool_data_lv(seg, pool_data_lv))
|
||||||
|
return_0;
|
||||||
|
|
||||||
|
if (!attach_pool_metadata_lv(seg, pool_metadata_lv))
|
||||||
|
return_0;
|
||||||
|
|
||||||
/* Read messages */
|
/* Read messages */
|
||||||
for (; sn; sn = sn->sib)
|
for (; sn; sn = sn->sib)
|
||||||
if (!(sn->v) && !_thin_pool_add_message(seg, sn->key, sn->child))
|
if (!(sn->v) && !_thin_pool_add_message(seg, sn->key, sn->child))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user