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

cleanup: update _alloc_image_component function

Return allocated volume directly instead of 1/0.
This commit is contained in:
Zdenek Kabelac 2014-09-12 11:48:41 +02:00
parent 126463ad1f
commit 76c3c94bd2

View File

@ -349,30 +349,17 @@ static char *_generate_raid_name(struct logical_volume *lv,
* Create an LV of specified type. Set visible after creation. * Create an LV of specified type. Set visible after creation.
* This function does not make metadata changes. * This function does not make metadata changes.
*/ */
static int _alloc_image_component(struct logical_volume *lv, static struct logical_volume *_alloc_image_component(struct logical_volume *lv,
const char *alt_base_name, const char *alt_base_name,
struct alloc_handle *ah, uint32_t first_area, struct alloc_handle *ah, uint32_t first_area,
uint64_t type, struct logical_volume **new_lv) uint64_t type)
{ {
uint64_t status; uint64_t status;
size_t len = strlen(lv->name) + 32; char img_name[NAME_LEN];
char img_name[len]; const char *type_suffix;
const char *base_name = (alt_base_name) ? alt_base_name : lv->name;
struct logical_volume *tmp_lv; struct logical_volume *tmp_lv;
const struct segment_type *segtype; const struct segment_type *segtype;
if (type == RAID_META) {
if (dm_snprintf(img_name, len, "%s_rmeta_%%d", base_name) < 0)
return_0;
} else if (type == RAID_IMAGE) {
if (dm_snprintf(img_name, len, "%s_rimage_%%d", base_name) < 0)
return_0;
} else {
log_error(INTERNAL_ERROR
"Bad type provided to _alloc_raid_component");
return 0;
}
if (!ah) { if (!ah) {
log_error(INTERNAL_ERROR log_error(INTERNAL_ERROR
"Stand-alone %s area allocation not implemented", "Stand-alone %s area allocation not implemented",
@ -380,6 +367,23 @@ static int _alloc_image_component(struct logical_volume *lv,
return 0; return 0;
} }
switch (type) {
case RAID_META:
type_suffix = "rmeta";
break;
case RAID_IMAGE:
type_suffix = "rimage";
break;
default:
log_error(INTERNAL_ERROR
"Bad type provided to _alloc_raid_component.");
return 0;
}
if (dm_snprintf(img_name, sizeof(img_name), "%s_%s_%%d",
(alt_base_name) ? : lv->name, type_suffix) < 0)
return_0;
status = LVM_READ | LVM_WRITE | LV_REBUILD | type; status = LVM_READ | LVM_WRITE | LV_REBUILD | type;
if (!(tmp_lv = lv_create_empty(img_name, NULL, status, ALLOC_INHERIT, lv->vg))) { if (!(tmp_lv = lv_create_empty(img_name, NULL, status, ALLOC_INHERIT, lv->vg))) {
log_error("Failed to allocate new raid component, %s.", img_name); log_error("Failed to allocate new raid component, %s.", img_name);
@ -395,8 +399,8 @@ static int _alloc_image_component(struct logical_volume *lv,
} }
lv_set_visible(tmp_lv); lv_set_visible(tmp_lv);
*new_lv = tmp_lv;
return 1; return tmp_lv;
} }
static int _alloc_image_components(struct logical_volume *lv, static int _alloc_image_components(struct logical_volume *lv,
@ -411,7 +415,6 @@ static int _alloc_image_components(struct logical_volume *lv,
const struct segment_type *segtype; const struct segment_type *segtype;
struct alloc_handle *ah; struct alloc_handle *ah;
struct dm_list *parallel_areas; struct dm_list *parallel_areas;
struct logical_volume *tmp_lv;
struct lv_list *lvl_array; struct lv_list *lvl_array;
if (!(lvl_array = dm_pool_alloc(lv->vg->vgmem, if (!(lvl_array = dm_pool_alloc(lv->vg->vgmem,
@ -455,16 +458,16 @@ static int _alloc_image_components(struct logical_volume *lv,
* allocated areas. Thus, the metadata areas are pulled * allocated areas. Thus, the metadata areas are pulled
* from 's + count'. * from 's + count'.
*/ */
if (!_alloc_image_component(lv, NULL, ah, s + count, if (!(lvl_array[s + count].lv =
RAID_META, &tmp_lv)) _alloc_image_component(lv, NULL, ah, s + count, RAID_META)))
return_0; return_0;
lvl_array[s + count].lv = tmp_lv;
dm_list_add(new_meta_lvs, &(lvl_array[s + count].list)); dm_list_add(new_meta_lvs, &(lvl_array[s + count].list));
if (!_alloc_image_component(lv, NULL, ah, s, if (!(lvl_array[s].lv =
RAID_IMAGE, &tmp_lv)) _alloc_image_component(lv, NULL, ah, s, RAID_IMAGE)))
return_0; return_0;
lvl_array[s].lv = tmp_lv;
dm_list_add(new_data_lvs, &(lvl_array[s].list)); dm_list_add(new_data_lvs, &(lvl_array[s].list));
} }
@ -514,8 +517,7 @@ static int _alloc_rmeta_for_lv(struct logical_volume *data_lv,
&allocatable_pvs, data_lv->alloc, 0, NULL))) &allocatable_pvs, data_lv->alloc, 0, NULL)))
return_0; return_0;
if (!_alloc_image_component(data_lv, base_name, ah, 0, if (!(*meta_lv = _alloc_image_component(data_lv, base_name, ah, 0, RAID_META)))
RAID_META, meta_lv))
return_0; return_0;
alloc_destroy(ah); alloc_destroy(ah);