master - raid: destroy allocation handle on error path
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=08914ed7c1df18...
Commit: 08914ed7c1df18dc2a16c6f896ae388ac5e7c299
Parent: 76c3c94bd2a2ac4d3e255541da515cae8e823621
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Sep 12 11:37:01 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Sep 12 13:51:30 2014 +0200
raid: destroy allocation handle on error path
Don't leak ah memory pool on error path.
---
WHATS_NEW | 1 +
lib/metadata/raid_manip.c | 14 +++++++++-----
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index ebbc76f..f127d7d 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.112 -
=====================================
+ Don't leak alloc_handle on raid target error path.
Properly validate raid leg names.
Archive metadata before starting their modification in raid target.
Add missing vg_revert in suspend_lv() error path in raid target.
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index b670058..58bc09b 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -459,15 +459,17 @@ static int _alloc_image_components(struct logical_volume *lv,
* from 's + count'.
*/
if (!(lvl_array[s + count].lv =
- _alloc_image_component(lv, NULL, ah, s + count, RAID_META)))
+ _alloc_image_component(lv, NULL, ah, s + count, RAID_META))) {
+ alloc_destroy(ah);
return_0;
-
+ }
dm_list_add(new_meta_lvs, &(lvl_array[s + count].list));
if (!(lvl_array[s].lv =
- _alloc_image_component(lv, NULL, ah, s, RAID_IMAGE)))
+ _alloc_image_component(lv, NULL, ah, s, RAID_IMAGE))) {
+ alloc_destroy(ah);
return_0;
-
+ }
dm_list_add(new_data_lvs, &(lvl_array[s].list));
}
@@ -517,8 +519,10 @@ static int _alloc_rmeta_for_lv(struct logical_volume *data_lv,
&allocatable_pvs, data_lv->alloc, 0, NULL)))
return_0;
- if (!(*meta_lv = _alloc_image_component(data_lv, base_name, ah, 0, RAID_META)))
+ if (!(*meta_lv = _alloc_image_component(data_lv, base_name, ah, 0, RAID_META))) {
+ alloc_destroy(ah);
return_0;
+ }
alloc_destroy(ah);
9 years
master - cleanup: update _alloc_image_component function
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=76c3c94bd2a2ac...
Commit: 76c3c94bd2a2ac4d3e255541da515cae8e823621
Parent: 126463ad1fd653f76d5cd112e02d5214e0433587
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Sep 12 11:48:41 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Sep 12 13:51:30 2014 +0200
cleanup: update _alloc_image_component function
Return allocated volume directly instead of 1/0.
---
lib/metadata/raid_manip.c | 60 +++++++++++++++++++++++---------------------
1 files changed, 31 insertions(+), 29 deletions(-)
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index 2369f5f..b670058 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -349,37 +349,41 @@ static char *_generate_raid_name(struct logical_volume *lv,
* Create an LV of specified type. Set visible after creation.
* This function does not make metadata changes.
*/
-static int _alloc_image_component(struct logical_volume *lv,
- const char *alt_base_name,
- struct alloc_handle *ah, uint32_t first_area,
- uint64_t type, struct logical_volume **new_lv)
+static struct logical_volume *_alloc_image_component(struct logical_volume *lv,
+ const char *alt_base_name,
+ struct alloc_handle *ah, uint32_t first_area,
+ uint64_t type)
{
uint64_t status;
- size_t len = strlen(lv->name) + 32;
- char img_name[len];
- const char *base_name = (alt_base_name) ? alt_base_name : lv->name;
+ char img_name[NAME_LEN];
+ const char *type_suffix;
struct logical_volume *tmp_lv;
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 {
+ if (!ah) {
log_error(INTERNAL_ERROR
- "Bad type provided to _alloc_raid_component");
+ "Stand-alone %s area allocation not implemented",
+ (type == RAID_META) ? "metadata" : "data");
return 0;
}
- if (!ah) {
+ switch (type) {
+ case RAID_META:
+ type_suffix = "rmeta";
+ break;
+ case RAID_IMAGE:
+ type_suffix = "rimage";
+ break;
+ default:
log_error(INTERNAL_ERROR
- "Stand-alone %s area allocation not implemented",
- (type == RAID_META) ? "metadata" : "data");
+ "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;
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);
@@ -395,8 +399,8 @@ static int _alloc_image_component(struct logical_volume *lv,
}
lv_set_visible(tmp_lv);
- *new_lv = tmp_lv;
- return 1;
+
+ return tmp_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;
struct alloc_handle *ah;
struct dm_list *parallel_areas;
- struct logical_volume *tmp_lv;
struct lv_list *lvl_array;
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
* from 's + count'.
*/
- if (!_alloc_image_component(lv, NULL, ah, s + count,
- RAID_META, &tmp_lv))
+ if (!(lvl_array[s + count].lv =
+ _alloc_image_component(lv, NULL, ah, s + count, RAID_META)))
return_0;
- lvl_array[s + count].lv = tmp_lv;
+
dm_list_add(new_meta_lvs, &(lvl_array[s + count].list));
- if (!_alloc_image_component(lv, NULL, ah, s,
- RAID_IMAGE, &tmp_lv))
+ if (!(lvl_array[s].lv =
+ _alloc_image_component(lv, NULL, ah, s, RAID_IMAGE)))
return_0;
- lvl_array[s].lv = tmp_lv;
+
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)))
return_0;
- if (!_alloc_image_component(data_lv, base_name, ah, 0,
- RAID_META, meta_lv))
+ if (!(*meta_lv = _alloc_image_component(data_lv, base_name, ah, 0, RAID_META)))
return_0;
alloc_destroy(ah);
9 years
master - cleanup: plain code reindent
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=126463ad1fd653...
Commit: 126463ad1fd653f76d5cd112e02d5214e0433587
Parent: ad376e9e00eaa453e7d8ba1ffdc763345ec49d0e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Sep 11 20:08:56 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Sep 12 13:51:30 2014 +0200
cleanup: plain code reindent
Just simple reindent and brace changes.
---
lib/metadata/raid_manip.c | 119 ++++++++++++++++++++++-----------------------
1 files changed, 58 insertions(+), 61 deletions(-)
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index d0740e8..2369f5f 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2011-2014 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -26,10 +26,9 @@ static int _lv_is_raid_with_tracking(const struct logical_volume *lv,
struct logical_volume **tracking)
{
uint32_t s;
- struct lv_segment *seg;
+ const struct lv_segment *seg = first_seg(lv);
*tracking = NULL;
- seg = first_seg(lv);
if (!(lv->status & RAID))
return 0;
@@ -39,7 +38,6 @@ static int _lv_is_raid_with_tracking(const struct logical_volume *lv,
!(seg_lv(seg, s)->status & LVM_WRITE))
*tracking = seg_lv(seg, s);
-
return *tracking ? 1 : 0;
}
@@ -130,11 +128,8 @@ static int _raid_remove_top_layer(struct logical_volume *lv,
return 0;
}
- lvl_array = dm_pool_alloc(lv->vg->vgmem, 2 * sizeof(*lvl));
- if (!lvl_array) {
- log_error("Memory allocation failed.");
- return 0;
- }
+ if (!(lvl_array = dm_pool_alloc(lv->vg->vgmem, 2 * sizeof(*lvl))))
+ return_0;
/* Add last metadata area to removal_list */
lvl_array[0].lv = seg_metalv(seg, 0);
@@ -154,6 +149,7 @@ static int _raid_remove_top_layer(struct logical_volume *lv,
return_0;
lv->status &= ~(MIRRORED | RAID);
+
return 1;
}
@@ -385,9 +381,8 @@ static int _alloc_image_component(struct logical_volume *lv,
}
status = LVM_READ | LVM_WRITE | LV_REBUILD | type;
- tmp_lv = lv_create_empty(img_name, NULL, status, ALLOC_INHERIT, lv->vg);
- if (!tmp_lv) {
- log_error("Failed to allocate new raid component, %s", img_name);
+ 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);
return 0;
}
@@ -419,9 +414,8 @@ static int _alloc_image_components(struct logical_volume *lv,
struct logical_volume *tmp_lv;
struct lv_list *lvl_array;
- lvl_array = dm_pool_alloc(lv->vg->vgmem,
- sizeof(*lvl_array) * count * 2);
- if (!lvl_array)
+ if (!(lvl_array = dm_pool_alloc(lv->vg->vgmem,
+ sizeof(*lvl_array) * count * 2)))
return_0;
if (!(parallel_areas = build_parallel_areas_from_lv(lv, 0, 1)))
@@ -454,7 +448,7 @@ static int _alloc_image_components(struct logical_volume *lv,
lv->alloc, 0, parallel_areas)))
return_0;
- for (s = 0; s < count; s++) {
+ for (s = 0; s < count; ++s) {
/*
* The allocation areas are grouped together. First
* come the rimage allocated areas, then come the metadata
@@ -473,7 +467,9 @@ static int _alloc_image_components(struct logical_volume *lv,
lvl_array[s].lv = tmp_lv;
dm_list_add(new_data_lvs, &(lvl_array[s].list));
}
+
alloc_destroy(ah);
+
return 1;
}
@@ -523,6 +519,7 @@ static int _alloc_rmeta_for_lv(struct logical_volume *data_lv,
return_0;
alloc_destroy(ah);
+
return 1;
}
@@ -736,13 +733,14 @@ to be left for these sub-lvs.
fail:
/* Cleanly remove newly-allocated LVs that failed insertion attempt */
-
dm_list_iterate_items(lvl, &meta_lvs)
if (!lv_remove(lvl->lv))
return_0;
+
dm_list_iterate_items(lvl, &data_lvs)
if (!lv_remove(lvl->lv))
return_0;
+
return 0;
}
@@ -841,9 +839,8 @@ static int _raid_extract_images(struct logical_volume *lv, uint32_t new_count,
return 0;
}
- lvl_array = dm_pool_alloc(lv->vg->vgmem,
- sizeof(*lvl_array) * extract * 2);
- if (!lvl_array)
+ if (!(lvl_array = dm_pool_alloc(lv->vg->vgmem,
+ sizeof(*lvl_array) * extract * 2)))
return_0;
if (!(error_segtype = get_segtype_from_string(lv->vg->cmd, "error")))
@@ -1096,14 +1093,14 @@ int lv_raid_split(struct logical_volume *lv, const char *split_name,
"while tracking changes for %s",
lv->name, tracking->name);
return 0;
- } else {
- /* Ensure we only split the tracking image */
- dm_list_init(&tracking_pvs);
- splittable_pvs = &tracking_pvs;
- if (!get_pv_list_for_lv(tracking->vg->cmd->mem,
- tracking, splittable_pvs))
- return_0;
}
+
+ /* Ensure we only split the tracking image */
+ dm_list_init(&tracking_pvs);
+ splittable_pvs = &tracking_pvs;
+ if (!get_pv_list_for_lv(tracking->vg->cmd->mem,
+ tracking, splittable_pvs))
+ return_0;
}
if (!_raid_extract_images(lv, new_count, splittable_pvs, 1,
@@ -1152,6 +1149,7 @@ int lv_raid_split(struct logical_volume *lv, const char *split_name,
*/
if (!activate_lv_excl_local(cmd, lvl->lv))
return_0;
+
dm_list_iterate_items(lvl, &removal_list)
if (!activate_lv_excl_local(cmd, lvl->lv))
return_0;
@@ -1217,7 +1215,7 @@ int lv_raid_split_and_track(struct logical_volume *lv,
return 0;
}
- for (s = seg->area_count - 1; s >= 0; s--) {
+ for (s = seg->area_count - 1; s >= 0; --s) {
if (!lv_is_on_pvs(seg_lv(seg, s), splittable_pvs))
continue;
lv_set_visible(seg_lv(seg, s));
@@ -1277,13 +1275,13 @@ int lv_raid_merge(struct logical_volume *image_lv)
vg->name, image_lv->name);
return 0;
}
+
lv = lvl->lv;
seg = first_seg(lv);
- for (s = 0; s < seg->area_count; s++) {
- if (seg_lv(seg, s) == image_lv) {
+ for (s = 0; s < seg->area_count; ++s)
+ if (seg_lv(seg, s) == image_lv)
meta_lv = seg_metalv(seg, s);
- }
- }
+
if (!meta_lv)
return_0;
@@ -1327,10 +1325,9 @@ static int _convert_mirror_to_raid1(struct logical_volume *lv,
return 0;
}
- meta_areas = dm_pool_zalloc(lv->vg->vgmem,
- lv_mirror_count(lv) * sizeof(*meta_areas));
- if (!meta_areas) {
- log_error("Failed to allocate memory");
+ if (!(meta_areas = dm_pool_zalloc(lv->vg->vgmem,
+ lv_mirror_count(lv) * sizeof(*meta_areas)))) {
+ log_error("Failed to allocate meta areas memory.");
return 0;
}
@@ -1821,29 +1818,29 @@ static int _partial_raid_lv_is_redundant(struct logical_volume *lv)
uint32_t failed_components = 0;
if (!strcmp(raid_seg->segtype->name, "raid10")) {
- /* FIXME: We only support 2-way mirrors in RAID10 currently */
+ /* FIXME: We only support 2-way mirrors in RAID10 currently */
copies = 2;
- for (i = 0; i < raid_seg->area_count * copies; i++) {
- s = i % raid_seg->area_count;
+ for (i = 0; i < raid_seg->area_count * copies; i++) {
+ s = i % raid_seg->area_count;
- if (!(i % copies))
- rebuilds_per_group = 0;
+ if (!(i % copies))
+ rebuilds_per_group = 0;
- if ((seg_lv(raid_seg, s)->status & PARTIAL_LV) ||
- (seg_metalv(raid_seg, s)->status & PARTIAL_LV) ||
- lv_is_virtual(seg_lv(raid_seg, s)) ||
- lv_is_virtual(seg_metalv(raid_seg, s)))
- rebuilds_per_group++;
+ if ((seg_lv(raid_seg, s)->status & PARTIAL_LV) ||
+ (seg_metalv(raid_seg, s)->status & PARTIAL_LV) ||
+ lv_is_virtual(seg_lv(raid_seg, s)) ||
+ lv_is_virtual(seg_metalv(raid_seg, s)))
+ rebuilds_per_group++;
- if (rebuilds_per_group >= copies) {
- log_verbose("An entire mirror group has failed in %s",
+ if (rebuilds_per_group >= copies) {
+ log_verbose("An entire mirror group has failed in %s.",
display_lvname(lv));
- return 0; /* Insufficient redundancy to activate */
+ return 0; /* Insufficient redundancy to activate */
}
- }
+ }
return 1; /* Redundant */
- }
+ }
for (s = 0; s < raid_seg->area_count; s++) {
if ((seg_lv(raid_seg, s)->status & PARTIAL_LV) ||
@@ -1853,18 +1850,18 @@ static int _partial_raid_lv_is_redundant(struct logical_volume *lv)
failed_components++;
}
- if (failed_components == raid_seg->area_count) {
- log_verbose("All components of raid LV %s have failed",
+ if (failed_components == raid_seg->area_count) {
+ log_verbose("All components of raid LV %s have failed.",
display_lvname(lv));
- return 0; /* Insufficient redundancy to activate */
- } else if (raid_seg->segtype->parity_devs &&
- (failed_components > raid_seg->segtype->parity_devs)) {
- log_verbose("More than %u components from %s %s have failed",
+ return 0; /* Insufficient redundancy to activate */
+ } else if (raid_seg->segtype->parity_devs &&
+ (failed_components > raid_seg->segtype->parity_devs)) {
+ log_verbose("More than %u components from %s %s have failed.",
raid_seg->segtype->parity_devs,
- raid_seg->segtype->ops->name(raid_seg),
- display_lvname(lv));
- return 0; /* Insufficient redundancy to activate */
- }
+ raid_seg->segtype->ops->name(raid_seg),
+ display_lvname(lv));
+ return 0; /* Insufficient redundancy to activate */
+ }
return 1;
}
9 years
master - debug: add missing stack trace on error path
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ad376e9e00eaa4...
Commit: ad376e9e00eaa453e7d8ba1ffdc763345ec49d0e
Parent: c10c16cc3531cf613152675b732a50b1339e62c9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Sep 11 20:11:44 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Sep 12 13:51:29 2014 +0200
debug: add missing stack trace on error path
---
lib/metadata/raid_manip.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index 6edd56d..d0740e8 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -1238,7 +1238,7 @@ int lv_raid_split_and_track(struct logical_volume *lv,
/* Activate the split (and tracking) LV */
if (!_activate_sublv_preserving_excl(lv, seg_lv(seg, s)))
- return 0;
+ return_0;
log_print_unless_silent("Use 'lvconvert --merge %s/%s' to merge back into %s",
lv->vg->name, seg_lv(seg, s)->name, lv->name);
@@ -1907,7 +1907,7 @@ int partial_raid_lv_supports_degraded_activation(struct logical_volume *lv)
int not_capable = 0;
if (!_lv_may_be_activated_in_degraded_mode(lv, ¬_capable) || not_capable)
- return 0;
+ return_0;
if (!for_each_sub_lv(lv, _lv_may_be_activated_in_degraded_mode, ¬_capable)) {
log_error(INTERNAL_ERROR "for_each_sub_lv failure.");
9 years
master - raid: use _generate_raid_name
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c10c16cc3531cf...
Commit: c10c16cc3531cf613152675b732a50b1339e62c9
Parent: 2db0312455260cda6f45ee8d3814a00f3f297af0
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Sep 12 11:39:48 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Sep 12 13:51:29 2014 +0200
raid: use _generate_raid_name
Use new function to get implicit name validation
(so we do not exit with internal error on metadata validation).
---
WHATS_NEW | 1 +
lib/metadata/raid_manip.c | 56 ++++++++-------------------------------------
2 files changed, 11 insertions(+), 46 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index a84ef4b..ebbc76f 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.112 -
=====================================
+ Properly validate raid leg names.
Archive metadata before starting their modification in raid target.
Add missing vg_revert in suspend_lv() error path in raid target.
Add missing backup of lvm2 metadata after some raid modifications.
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index bff6e59..6edd56d 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -590,21 +590,14 @@ static int _raid_add_images(struct logical_volume *lv,
* commits the LVM metadata before clearing the LVs.
*/
if (seg_is_linear(seg)) {
- char *name;
- size_t len;
struct dm_list *l;
struct lv_list *lvl_tmp;
dm_list_iterate(l, &data_lvs) {
if (l == dm_list_last(&data_lvs)) {
lvl = dm_list_item(l, struct lv_list);
- len = strlen(lv->name) + sizeof("_rimage_XXX");
- if (!(name = dm_pool_alloc(lv->vg->vgmem, len))) {
- log_error("Failed to allocate rimage name.");
- return 0;
- }
- sprintf(name, "%s_rimage_%u", lv->name, count);
- lvl->lv->name = name;
+ if (!(lvl->lv->name = _generate_raid_name(lv, "rimage", count)))
+ return_0;
continue;
}
lvl = dm_list_item(l, struct lv_list);
@@ -778,9 +771,6 @@ static int _extract_image_components(struct lv_segment *seg, uint32_t idx,
struct logical_volume **extracted_rmeta,
struct logical_volume **extracted_rimage)
{
- int len;
- char *tmp_name;
- struct volume_group *vg = seg->lv->vg;
struct logical_volume *data_lv = seg_lv(seg, idx);
struct logical_volume *meta_lv = seg_metalv(seg, idx);
@@ -800,19 +790,11 @@ static int _extract_image_components(struct lv_segment *seg, uint32_t idx,
seg_type(seg, idx) = AREA_UNASSIGNED;
seg_metatype(seg, idx) = AREA_UNASSIGNED;
- len = strlen(meta_lv->name) + strlen("_extracted") + 1;
- tmp_name = dm_pool_alloc(vg->vgmem, len);
- if (!tmp_name)
+ if (!(data_lv->name = _generate_raid_name(data_lv, "_extracted", -1)))
return_0;
- sprintf(tmp_name, "%s_extracted", meta_lv->name);
- meta_lv->name = tmp_name;
- len = strlen(data_lv->name) + strlen("_extracted") + 1;
- tmp_name = dm_pool_alloc(vg->vgmem, len);
- if (!tmp_name)
+ if (!(meta_lv->name = _generate_raid_name(meta_lv, "_extracted", -1)))
return_0;
- sprintf(tmp_name, "%s_extracted", data_lv->name);
- data_lv->name = tmp_name;
*extracted_rmeta = meta_lv;
*extracted_rimage = data_lv;
@@ -1335,6 +1317,7 @@ static int _convert_mirror_to_raid1(struct logical_volume *lv,
struct lv_list lvl_array[seg->area_count], *lvl;
struct dm_list meta_lvs;
struct lv_segment_area *meta_areas;
+ char *new_name;
dm_list_init(&meta_lvs);
@@ -1399,18 +1382,9 @@ static int _convert_mirror_to_raid1(struct logical_volume *lv,
s++;
}
- for (s = 0; s < seg->area_count; s++) {
- char *new_name;
-
- new_name = dm_pool_zalloc(lv->vg->vgmem,
- strlen(lv->name) +
- strlen("_rimage_XXn"));
- if (!new_name) {
- log_error("Failed to rename mirror images");
- return 0;
- }
-
- sprintf(new_name, "%s_rimage_%u", lv->name, s);
+ for (s = 0; s < seg->area_count; ++s) {
+ if (!(new_name = _generate_raid_name(seg_lv(seg, s), "rimage", s)))
+ return_0;
log_debug_metadata("Renaming %s to %s", seg_lv(seg, s)->name, new_name);
seg_lv(seg, s)->name = new_name;
seg_lv(seg, s)->status &= ~MIRROR_IMAGE;
@@ -1737,12 +1711,7 @@ try_again:
lvl = dm_list_item(dm_list_first(&new_meta_lvs),
struct lv_list);
dm_list_del(&lvl->list);
- tmp_names[s] = dm_pool_alloc(lv->vg->vgmem,
- strlen(lvl->lv->name) + 1);
- if (!tmp_names[s])
- return_0;
- if (dm_snprintf(tmp_names[s], strlen(lvl->lv->name) + 1,
- "%s_rmeta_%u", lv->name, s) < 0)
+ if (!(tmp_names[s] = _generate_raid_name(lv, "rmeta", s)))
return_0;
if (!set_lv_segment_area_lv(raid_seg, s, lvl->lv, 0,
lvl->lv->status)) {
@@ -1756,12 +1725,7 @@ try_again:
lvl = dm_list_item(dm_list_first(&new_data_lvs),
struct lv_list);
dm_list_del(&lvl->list);
- tmp_names[sd] = dm_pool_alloc(lv->vg->vgmem,
- strlen(lvl->lv->name) + 1);
- if (!tmp_names[sd])
- return_0;
- if (dm_snprintf(tmp_names[sd], strlen(lvl->lv->name) + 1,
- "%s_rimage_%u", lv->name, s) < 0)
+ if (!(tmp_names[sd] = _generate_raid_name(lv, "rimage", s)))
return_0;
if (!set_lv_segment_area_lv(raid_seg, s, lvl->lv, 0,
lvl->lv->status)) {
9 years
master - raid: add function for name creation
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=2db0312455260c...
Commit: 2db0312455260cda6f45ee8d3814a00f3f297af0
Parent: 40b7b107b186e1680db05dcb05230b978852d010
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Sep 12 11:30:00 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Sep 12 13:51:29 2014 +0200
raid: add function for name creation
Add name for construction and validation of raid subvolume
name with a given suffix.
TODO: check if reusable for mirrors as well.
---
lib/metadata/raid_manip.c | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index b7ba464..bff6e59 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -320,6 +320,35 @@ static int _shift_and_rename_image_components(struct lv_segment *seg)
return 1;
}
+/* Generate raid subvolume name and validate it */
+static char *_generate_raid_name(struct logical_volume *lv,
+ const char *suffix, int count)
+{
+ const char *format = (count >= 0) ? "%s_%s_%u" : "%s_%s";
+ size_t len = strlen(lv->name) + strlen(suffix) + ((count >= 0) ? 5 : 2);
+ char *name;
+
+ if (!(name = dm_pool_alloc(lv->vg->vgmem, len))) {
+ log_error("Failed to allocate new name.");
+ return NULL;
+ }
+
+ if (dm_snprintf(name, len, format, lv->name, suffix, count) < 0)
+ return_NULL;
+
+ if (!validate_name(name)) {
+ log_error("New logical volume name \"%s\" is not valid.", name);
+ return NULL;
+ }
+
+ if (find_lv_in_vg(lv->vg, name)) {
+ log_error("Logical volume %s already exists in volume group %s.",
+ name, lv->vg->name);
+ return NULL;
+ }
+
+ return name;
+}
/*
* Create an LV of specified type. Set visible after creation.
* This function does not make metadata changes.
9 years
master - raid: check result of get_segtype_from_string
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=40b7b107b186e1...
Commit: 40b7b107b186e1680db05dcb05230b978852d010
Parent: 08bde75093665001e7b30a7491c5bb9a53383d56
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Sep 12 11:48:51 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Sep 12 13:45:50 2014 +0200
raid: check result of get_segtype_from_string
Error here is rather highly unpexpected for these types, but
stay consistent with rest of the code and don't use unchecked value.
---
lib/metadata/raid_manip.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index 4bfe9c9..b7ba464 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -362,7 +362,9 @@ static int _alloc_image_component(struct logical_volume *lv,
return 0;
}
- segtype = get_segtype_from_string(lv->vg->cmd, "striped");
+ if (!(segtype = get_segtype_from_string(lv->vg->cmd, "striped")))
+ return_0;
+
if (!lv_add_segment(ah, first_area, 1, tmp_lv, segtype, 0, status, 0)) {
log_error("Failed to add segment to LV, %s", img_name);
return 0;
@@ -833,7 +835,8 @@ static int _raid_extract_images(struct logical_volume *lv, uint32_t new_count,
if (!lvl_array)
return_0;
- error_segtype = get_segtype_from_string(lv->vg->cmd, "error");
+ if (!(error_segtype = get_segtype_from_string(lv->vg->cmd, "error")))
+ return_0;
/*
* We make two passes over the devices.
9 years
master - raid: add missing archive call
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=08bde750936650...
Commit: 08bde75093665001e7b30a7491c5bb9a53383d56
Parent: 569184a3bb124f94bc79c1a1d042f686270e7864
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Sep 12 11:30:38 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Sep 12 13:45:49 2014 +0200
raid: add missing archive call
Before starting to update raid metadata, archive existing unmodified one.
---
WHATS_NEW | 1 +
lib/metadata/raid_manip.c | 15 +++++++++++++++
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index f65d7fb..a84ef4b 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.112 -
=====================================
+ Archive metadata before starting their modification in raid target.
Add missing vg_revert in suspend_lv() error path in raid target.
Add missing backup of lvm2 metadata after some raid modifications.
Use vg memory pool for extent allocation.
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index 989244c..4bfe9c9 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -520,6 +520,9 @@ static int _raid_add_images(struct logical_volume *lv,
return 0;
}
+ if (!archive(lv->vg))
+ return_0;
+
dm_list_init(&meta_lvs); /* For image addition */
dm_list_init(&data_lvs); /* For image addition */
@@ -909,6 +912,9 @@ static int _raid_remove_images(struct logical_volume *lv,
struct dm_list removal_list;
struct lv_list *lvl;
+ if (!archive(lv->vg))
+ return_0;
+
dm_list_init(&removal_list);
if (!_raid_extract_images(lv, new_count, pvs, 1,
@@ -1313,6 +1319,9 @@ static int _convert_mirror_to_raid1(struct logical_volume *lv,
return 0;
}
+ if (!archive(lv->vg))
+ return_0;
+
for (s = 0; s < seg->area_count; s++) {
log_debug_metadata("Allocating new metadata LV for %s",
seg_lv(seg, s)->name);
@@ -1543,6 +1552,9 @@ int lv_raid_replace(struct logical_volume *lv,
return 0;
}
+ if (!archive(lv->vg))
+ return_0;
+
/*
* How many sub-LVs are being removed?
*/
@@ -1767,6 +1779,9 @@ int lv_raid_remove_missing(struct logical_volume *lv)
return 0;
}
+ if (!archive(lv->vg))
+ return_0;
+
log_debug("Attempting to remove missing devices from %s LV, %s",
seg->segtype->ops->name(seg), lv->name);
9 years
master - raid: add missing vg_revert
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=569184a3bb124f...
Commit: 569184a3bb124f94bc79c1a1d042f686270e7864
Parent: dd1fa0e808918b51a690e26de8a8cfff6c307854
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Sep 11 19:58:28 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Sep 12 13:45:14 2014 +0200
raid: add missing vg_revert
After failing vg_write() and suspend_lv() there was missing vg_revert() call.
---
WHATS_NEW | 1 +
lib/metadata/raid_manip.c | 2 ++
2 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index be549b8..f65d7fb 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.112 -
=====================================
+ Add missing vg_revert in suspend_lv() error path in raid target.
Add missing backup of lvm2 metadata after some raid modifications.
Use vg memory pool for extent allocation.
Add allocation/physical_extent_size config option for default PE size of VGs.
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index 91cc0dd..989244c 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -938,6 +938,7 @@ static int _raid_remove_images(struct logical_volume *lv,
if (!suspend_lv(lv->vg->cmd, lv)) {
log_error("Failed to suspend %s/%s before committing changes",
lv->vg->name, lv->name);
+ vg_revert(lv->vg);
return 0;
}
@@ -1113,6 +1114,7 @@ int lv_raid_split(struct logical_volume *lv, const char *split_name,
if (!suspend_lv(cmd, lv)) {
log_error("Failed to suspend %s/%s before committing changes",
lv->vg->name, lv->name);
+ vg_revert(lv->vg);
return 0;
}
9 years
master - raid: add missing backups
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=dd1fa0e808918b...
Commit: dd1fa0e808918b51a690e26de8a8cfff6c307854
Parent: 15ba2afdc2d70ee21c2599f0d51a413f0a7afa9b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Sep 11 19:05:40 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Sep 12 13:42:57 2014 +0200
raid: add missing backups
Add backup() calls that were missing after successful update
of metadata.
---
WHATS_NEW | 2 ++
lib/metadata/raid_manip.c | 17 ++++++++++++-----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 983bc1a..be549b8 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,7 @@
Version 2.02.112 -
=====================================
+ Add missing backup of lvm2 metadata after some raid modifications.
+ Use vg memory pool for extent allocation.
Add allocation/physical_extent_size config option for default PE size of VGs.
Introduce common code to modify metadate and reload updated LV.
Fix rename of active snapshot volume in cluster.
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index d39dbc8..91cc0dd 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -13,6 +13,7 @@
*/
#include "lib.h"
+#include "archiver.h"
#include "metadata.h"
#include "toolcontext.h"
#include "segtype.h"
@@ -695,11 +696,13 @@ to be left for these sub-lvs.
rebuild_flag_cleared = 1;
}
}
- if (rebuild_flag_cleared &&
- (!vg_write(lv->vg) || !vg_commit(lv->vg))) {
- log_error("Failed to clear REBUILD flag for %s/%s components",
- lv->vg->name, lv->name);
- return 0;
+ if (rebuild_flag_cleared) {
+ if (!vg_write(lv->vg) || !vg_commit(lv->vg)) {
+ log_error("Failed to clear REBUILD flag for %s/%s components",
+ lv->vg->name, lv->name);
+ return 0;
+ }
+ backup(lv->vg);
}
return 1;
@@ -978,6 +981,8 @@ static int _raid_remove_images(struct logical_volume *lv,
return_0;
}
+ backup(lv->vg);
+
return 1;
}
@@ -1149,6 +1154,8 @@ int lv_raid_split(struct logical_volume *lv, const char *split_name,
if (!vg_write(lv->vg) || !vg_commit(lv->vg))
return_0;
+ backup(lv->vg);
+
return 1;
}
9 years