master - WHATS_NEW: New segment type raid5_n
by Heinz Mauelshagen
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=96f331fe052972...
Commit: 96f331fe05297259274c04ac7fbd7d99eb911c77
Parent: 7e92535d475da7403f2ec8eeb2c5af6209fa2ba8
Author: Heinz Mauelshagen <heinzm(a)redhat.com>
AuthorDate: Fri Feb 3 23:41:48 2017 +0100
Committer: Heinz Mauelshagen <heinzm(a)redhat.com>
CommitterDate: Fri Feb 3 23:41:48 2017 +0100
WHATS_NEW: New segment type raid5_n
---
WHATS_NEW | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 94411ae..95a24ba 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.169 -
=====================================
+ Support raid5_n segment type and conversions from/to it.
Support new internal command _dmeventd_thin_command.
Introduce new dmeventd/thin_command configurable setting.
Use new default units 'r' for displaying sizes.
7 years, 2 months
master - lvconvert: add segtype raid5_n and conversions to/from it
by Heinz Mauelshagen
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7e92535d475da7...
Commit: 7e92535d475da7403f2ec8eeb2c5af6209fa2ba8
Parent: 60ddd05f163cbf53670e5c8deabfc384168eae0f
Author: Heinz Mauelshagen <heinzm(a)redhat.com>
AuthorDate: Fri Feb 3 22:16:00 2017 +0100
Committer: Heinz Mauelshagen <heinzm(a)redhat.com>
CommitterDate: Fri Feb 3 22:16:35 2017 +0100
lvconvert: add segtype raid5_n and conversions to/from it
Change:
- missed a return_0
- use lvseg_name() rather than my own function
Related: rhbz1366296
---
lib/metadata/raid_manip.c | 13 ++-----------
1 files changed, 2 insertions(+), 11 deletions(-)
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index f845164..3543a69 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -2227,7 +2227,7 @@ static int _convert_raid1_to_mirror(struct logical_volume *lv,
log_debug_metadata("Changing image count to %u on %s.",
new_image_count, display_lvname(lv));
if (!_lv_raid_change_image_count(lv, new_image_count, allocate_pvs, removal_lvs, 0, 0))
- return 0;
+ return_0;
}
/* Remove rmeta LVs */
@@ -2703,15 +2703,6 @@ static const char *_get_segtype_alias(const struct segment_type *segtype)
return "";
}
-/* Return "linear" for striped segtype with 1 area instead of "striped" */
-static const char *_get_segtype_name(const struct segment_type *segtype, unsigned new_image_count)
-{
- if (!segtype || (segtype_is_striped(segtype) && new_image_count == 1))
- return "linear";
-
- return segtype->name;
-}
-
static int _log_possible_conversion_types(const struct logical_volume *lv, const struct segment_type *new_segtype)
{
unsigned possible_conversions = 0;
@@ -2732,7 +2723,7 @@ static int _log_possible_conversion_types(const struct logical_volume *lv, const
log_error("Converting %s from %s%s%s%s is "
"directly possible to the following layout%s:",
- display_lvname(lv), _get_segtype_name(seg->segtype, seg->area_count),
+ display_lvname(lv), lvseg_name(seg),
*alias ? " (same as " : "", alias, *alias ? ")" : "",
possible_conversions > 1 ? "s" : "");
7 years, 2 months
master - lvconvert: add segtype raid5_n and conversions to/from it
by Heinz Mauelshagen
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=60ddd05f163cbf...
Commit: 60ddd05f163cbf53670e5c8deabfc384168eae0f
Parent: 875ce04c61fb40436bf4d6308356c800d08c1f7e
Author: Heinz Mauelshagen <heinzm(a)redhat.com>
AuthorDate: Fri Feb 3 20:39:40 2017 +0100
Committer: Heinz Mauelshagen <heinzm(a)redhat.com>
CommitterDate: Fri Feb 3 20:40:26 2017 +0100
lvconvert: add segtype raid5_n and conversions to/from it
Add:
- support for segment type raid5_n (striped raid with dedicated last parity SubLVs)
- conversion support from striped/raid0/raid0_meta/raid4 to/from raid5_n
- related tests to lvconvert-raid-takeover.sh
Related: rhbz1366296
---
lib/metadata/merge.c | 7 +-
lib/metadata/raid_manip.c | 252 +++++++++++++++++++++++----------
lib/raid/raid.c | 15 +-
libdm/libdm-deptree.c | 7 +-
test/shell/lvconvert-raid-takeover.sh | 63 ++++++++-
5 files changed, 259 insertions(+), 85 deletions(-)
diff --git a/lib/metadata/merge.c b/lib/metadata/merge.c
index 59c0885..dbd91db 100644
--- a/lib/metadata/merge.c
+++ b/lib/metadata/merge.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
- * Copyright (C) 2004-2016 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2017 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -148,7 +148,8 @@ static void _check_raid1_seg(struct lv_segment *seg, int *error_count)
static void _check_raid45610_seg(struct lv_segment *seg, int *error_count)
{
/* Checks applying to any raid4/5/6/10 */
- if (!seg->meta_areas)
+ /* Allow raid4 + raid5_n to get activated w/o metadata (mandatory during conversion between them) */
+ if (!(seg_is_raid4(seg) || seg_is_raid5_n(seg)) && !seg->meta_areas)
raid_seg_error("no meta areas");
if (!seg->stripe_size)
raid_seg_error("zero stripe size");
@@ -610,7 +611,7 @@ int check_lv_segments(struct logical_volume *lv, int complete_vg)
continue;
if (lv == seg_lv(seg, s))
seg_found++;
- if (seg_is_raid_with_meta(seg) && (lv == seg_metalv(seg, s)))
+ if (seg->meta_areas && seg_is_raid_with_meta(seg) && (lv == seg_metalv(seg, s)))
seg_found++;
}
if (seg_is_replicator_dev(seg)) {
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index 8c88280..f845164 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011-2014 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2011-2017 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -2175,6 +2175,7 @@ static int _convert_mirror_to_raid1(struct logical_volume *lv,
lv->status &= ~MIRROR;
lv->status &= ~MIRRORED;
lv->status |= RAID;
+ seg->status |= RAID;
if (!lv_update_and_reload(lv))
return_0;
@@ -2567,44 +2568,22 @@ static struct possible_takeover_reshape_type _possible_takeover_reshape_types[]
.possible_types = SEG_RAID0|SEG_RAID0_META,
.current_areas = 1,
.options = ALLOW_STRIPE_SIZE },
- { .current_types = SEG_STRIPED_TARGET, /* striped -> raid0*, i.e. seg->area_count > 1 */
- .possible_types = SEG_RAID0|SEG_RAID0_META,
- .current_areas = ~0U,
- .options = ALLOW_NONE },
- { .current_types = SEG_STRIPED_TARGET, /* striped -> raid4 , i.e. seg->area_count > 1 */
- .possible_types = SEG_RAID4,
- .current_areas = ~0U,
- .options = ALLOW_NONE }, /* FIXME: ALLOW_REGION_SIZE */
+
/* raid0* -> */
{ .current_types = SEG_RAID0|SEG_RAID0_META, /* seg->area_count = 1 */
.possible_types = SEG_RAID1,
.current_areas = 1,
.options = ALLOW_NONE }, /* FIXME: ALLOW_REGION_SIZE */
- { .current_types = SEG_RAID0|SEG_RAID0_META, /* raid0* -> striped, i.e. seg->area_count > 1 */
- .possible_types = SEG_STRIPED_TARGET,
- .current_areas = ~0U,
- .options = ALLOW_NONE },
- { .current_types = SEG_RAID0|SEG_RAID0_META, /* raid0* -> raid0*, i.e. seg->area_count > 1 */
- .possible_types = SEG_RAID0_META|SEG_RAID0,
- .current_areas = ~0U,
- .options = ALLOW_NONE },
- { .current_types = SEG_RAID0|SEG_RAID0_META, /* raid0* -> raid4, i.e. seg->area_count > 1 */
- .possible_types = SEG_RAID4,
- .current_areas = ~0U,
- .options = ALLOW_NONE }, /* FIXME: ALLOW_REGION_SIZE */
- /* raid4 -> -> */
- { .current_types = SEG_RAID4, /* raid4 ->striped/raid0*, i.e. seg->area_count > 1 */
- .possible_types = SEG_STRIPED_TARGET|SEG_RAID0|SEG_RAID0_META,
- .current_areas = ~0U,
- .options = ALLOW_NONE },
- /* raid1 -> mirror */
- { .current_types = SEG_RAID1,
- .possible_types = SEG_MIRROR,
+
+ /* striped,raid0*,raid4,raid5_n <-> striped,raid0*,raid4,raid5_n */
+ { .current_types = SEG_STRIPED_TARGET|SEG_RAID0|SEG_RAID0_META|SEG_RAID4|SEG_RAID5_N,
+ .possible_types = SEG_STRIPED_TARGET|SEG_RAID0|SEG_RAID0_META|SEG_RAID4|SEG_RAID5_N,
.current_areas = ~0U,
.options = ALLOW_NONE }, /* FIXME: ALLOW_REGION_SIZE */
- /* mirror -> raid1 with arbitrary number of legs */
- { .current_types = SEG_MIRROR,
- .possible_types = SEG_RAID1,
+
+ /* mirror <-> raid1 with arbitrary number of legs */
+ { .current_types = SEG_MIRROR|SEG_RAID1,
+ .possible_types = SEG_MIRROR|SEG_RAID1,
.current_areas = ~0U,
.options = ALLOW_NONE }, /* FIXME: ALLOW_REGION_SIZE */
@@ -2724,6 +2703,15 @@ static const char *_get_segtype_alias(const struct segment_type *segtype)
return "";
}
+/* Return "linear" for striped segtype with 1 area instead of "striped" */
+static const char *_get_segtype_name(const struct segment_type *segtype, unsigned new_image_count)
+{
+ if (!segtype || (segtype_is_striped(segtype) && new_image_count == 1))
+ return "linear";
+
+ return segtype->name;
+}
+
static int _log_possible_conversion_types(const struct logical_volume *lv, const struct segment_type *new_segtype)
{
unsigned possible_conversions = 0;
@@ -2744,7 +2732,7 @@ static int _log_possible_conversion_types(const struct logical_volume *lv, const
log_error("Converting %s from %s%s%s%s is "
"directly possible to the following layout%s:",
- display_lvname(lv), lvseg_name(seg),
+ display_lvname(lv), _get_segtype_name(seg->segtype, seg->area_count),
*alias ? " (same as " : "", alias, *alias ? ")" : "",
possible_conversions > 1 ? "s" : "");
@@ -2911,6 +2899,8 @@ static int _raid1_to_mirrored_wrapper(TAKEOVER_FN_ARGS)
* parity device to lv segment area 0 and thus changing MD
* array roles, detach the MetaLVs and reload as raid0 in
* order to wipe them then reattach and set back to raid0_meta.
+ *
+ * Same applies to raid4 <-> raid5.
*/
static int _clear_meta_lvs(struct logical_volume *lv)
{
@@ -2920,16 +2910,18 @@ static int _clear_meta_lvs(struct logical_volume *lv)
const struct segment_type *tmp_segtype;
struct dm_list meta_lvs;
struct lv_list *lvl_array, *lvl;
+ int is_raid4_or_5N = seg_is_raid4(seg) || seg_is_raid5_n(seg);
- /* Reject non-raid0_meta segment types cautiously */
- if (!seg_is_raid0_meta(seg) ||
- !seg->meta_areas)
+ /* Reject non-raid0_meta/raid4/raid5_n segment types cautiously */
+ if (!seg->meta_areas ||
+ (!seg_is_raid0_meta(seg) && !is_raid4_or_5N))
return_0;
if (!(lvl_array = dm_pool_alloc(lv->vg->vgmem, seg->area_count * sizeof(*lvl_array))))
return_0;
dm_list_init(&meta_lvs);
+ tmp_segtype = seg->segtype;
tmp_areas = seg->meta_areas;
/* Extract all MetaLVs listing them on @meta_lvs */
@@ -2940,10 +2932,12 @@ static int _clear_meta_lvs(struct logical_volume *lv)
/* Memorize meta areas and segtype to set again after initializing. */
seg->meta_areas = NULL;
- tmp_segtype = seg->segtype;
- if (!(seg->segtype = get_segtype_from_flag(lv->vg->cmd, SEG_RAID0)) ||
- !lv_update_and_reload(lv))
+ if (seg_is_raid0_meta(seg) &&
+ !(seg->segtype = get_segtype_from_flag(lv->vg->cmd, SEG_RAID0)))
+ return_0;
+
+ if (!lv_update_and_reload(lv))
return_0;
/* Note: detached rmeta are NOT renamed */
@@ -3066,7 +3060,7 @@ static void _shift_area_lvs(struct lv_segment *seg, uint32_t s1, uint32_t s2)
*/
static int _shift_parity_dev(struct lv_segment *seg)
{
- if (seg_is_raid0_meta(seg))
+ if (seg_is_raid0_meta(seg) || seg_is_raid5_n(seg))
_shift_area_lvs(seg, seg->area_count - 1, 0);
else if (seg_is_raid4(seg))
_shift_area_lvs(seg, 0, seg->area_count - 1);
@@ -3082,10 +3076,13 @@ static int _raid456_to_raid0_or_striped_wrapper(TAKEOVER_FN_ARGS)
int rename_sublvs = 0;
struct lv_segment *seg = first_seg(lv);
struct dm_list removal_lvs;
+ uint32_t region_size = seg->region_size;
dm_list_init(&removal_lvs);
- if (!seg_is_raid4(seg) && !seg_is_raid5_n(seg) && !seg_is_raid6_n_6(seg)) {
+ if (!seg_is_raid4(seg) &&
+ !seg_is_raid5_n(seg) &&
+ !seg_is_raid6_n_6(seg)) {
log_error("LV %s has to be of type raid4/raid5_n/raid6_n_6 to allow for this conversion.",
display_lvname(lv));
return 0;
@@ -3098,7 +3095,7 @@ static int _raid456_to_raid0_or_striped_wrapper(TAKEOVER_FN_ARGS)
if (!yes && yes_no_prompt("Are you sure you want to convert \"%s\" LV %s to \"%s\" "
"type losing all resilience? [y/n]: ",
lvseg_name(seg), display_lvname(lv), new_segtype->name) == 'n') {
- log_error("Logical volume %s NOT converted to \"%s\".",
+ log_error("Logical volume %s NOT converted to \"%s\"",
display_lvname(lv), new_segtype->name);
return 0;
}
@@ -3122,22 +3119,23 @@ static int _raid456_to_raid0_or_striped_wrapper(TAKEOVER_FN_ARGS)
if (segtype_is_any_raid0(new_segtype) &&
!(rename_sublvs = _rename_area_lvs(lv, "_"))) {
- log_error("Failed to rename %s LV %s MetaLVs.",
- lvseg_name(seg), display_lvname(lv));
+ log_error("Failed to rename %s LV %s MetaLVs.", lvseg_name(seg), display_lvname(lv));
return 0;
}
-
}
/* Remove meta and data LVs requested */
if (!_lv_raid_change_image_count(lv, new_image_count, allocate_pvs, &removal_lvs, 0, 0))
return 0;
- if (!(seg->segtype = get_segtype_from_flag(lv->vg->cmd, SEG_RAID0_META)))
- return_0;
+ /* FIXME Hard-coded raid4/5/6 to striped/raid0 */
+ if (segtype_is_striped_target(new_segtype) || segtype_is_any_raid0(new_segtype)) {
+ seg->area_len = seg->extents_copied = seg->area_len / seg->area_count;
+ if (!(seg->segtype = get_segtype_from_flag(lv->vg->cmd, SEG_RAID0_META)))
+ return_0;
- /* FIXME Hard-coded raid4 to raid0 */
- seg->area_len = seg->extents_copied = seg->area_len / seg->area_count;
+ region_size = 0;
+ }
if (segtype_is_striped_target(new_segtype)) {
if (!_convert_raid0_to_striped(lv, 0, &removal_lvs))
@@ -3146,15 +3144,15 @@ static int _raid456_to_raid0_or_striped_wrapper(TAKEOVER_FN_ARGS)
!_raid0_add_or_remove_metadata_lvs(lv, 0 /* update_and_reload */, allocate_pvs, &removal_lvs))
return_0;
- seg->region_size = 0;
+ seg->region_size = region_size;
+ seg->segtype = new_segtype;
if (!_lv_update_reload_fns_reset_eliminate_lvs(lv, &removal_lvs))
return_0;
if (rename_sublvs) {
if (!_rename_area_lvs(lv, NULL)) {
- log_error("Failed to rename %s LV %s MetaLVs.",
- lvseg_name(seg), display_lvname(lv));
+ log_error("Failed to rename %s LV %s MetaLVs.", lvseg_name(seg), display_lvname(lv));
return 0;
}
if (!lv_update_and_reload(lv))
@@ -3164,6 +3162,79 @@ static int _raid456_to_raid0_or_striped_wrapper(TAKEOVER_FN_ARGS)
return 1;
}
+/*
+ * raid4 <-> raid5_n helper
+ *
+ * On conversions between raid4 and raid5_n, the parity SubLVs need
+ * to be switched between beginning and end of the segment areas.
+ *
+ * The metadata devices reflect the previous positions within the RaidLV,
+ * thus need to be cleared in order to allow the kernel to start the new
+ * mapping and recreate metadata with the proper new position stored.
+ */
+static int _raid45_to_raid54_wrapper(TAKEOVER_FN_ARGS)
+{
+ struct lv_segment *seg = first_seg(lv);
+ struct dm_list removal_lvs;
+ uint32_t region_size = seg->region_size;
+
+ dm_list_init(&removal_lvs);
+
+ if (!(seg_is_raid4(seg) && segtype_is_raid5_n(new_segtype)) &&
+ !(seg_is_raid5_n(seg) && segtype_is_raid4(new_segtype))) {
+ log_error("LV %s has to be of type raid4 or raid5_n to allow for this conversion.",
+ display_lvname(lv));
+ return 0;
+ }
+
+
+ /* Necessary when convering to raid0/striped w/o redundancy? */
+ if (!_raid_in_sync(lv)) {
+ log_error("Unable to convert %s while it is not in-sync.",
+ display_lvname(lv));
+ return 0;
+ }
+
+ log_debug_metadata("Converting LV %s from %s to %s.", display_lvname(lv),
+ (seg_is_raid4(seg) ? SEG_TYPE_NAME_RAID4 : SEG_TYPE_NAME_RAID5_N),
+ (seg_is_raid4(seg) ? SEG_TYPE_NAME_RAID5_N : SEG_TYPE_NAME_RAID4));
+
+ /* Archive metadata */
+ if (!archive(lv->vg))
+ return_0;
+
+ if (!_rename_area_lvs(lv, "_")) {
+ log_error("Failed to rename %s LV %s MetaLVs.", lvseg_name(seg), display_lvname(lv));
+ return 0;
+ }
+
+ if (!_clear_meta_lvs(lv))
+ return_0;
+
+ /* Shift parity SubLV pair "PDD..." <-> "DD...P" on raid4 <-> raid5_n conversion */
+ if( !_shift_parity_dev(seg))
+ return 0;
+
+ /* Don't resync */
+ init_mirror_in_sync(1);
+ seg->region_size = new_region_size ?: region_size;
+ seg->segtype = new_segtype;
+
+ if (!_lv_update_reload_fns_reset_eliminate_lvs(lv, &removal_lvs))
+ return_0;
+
+ init_mirror_in_sync(0);
+
+ if (!_rename_area_lvs(lv, NULL)) {
+ log_error("Failed to rename %s LV %s MetaLVs.", lvseg_name(seg), display_lvname(lv));
+ return 0;
+ }
+ if (!lv_update_and_reload(lv))
+ return_0;
+
+ return 1;
+}
+
static int _striped_to_raid0_wrapper(struct logical_volume *lv,
const struct segment_type *new_segtype,
uint32_t new_stripes,
@@ -3188,14 +3259,31 @@ static int _striped_to_raid0_wrapper(struct logical_volume *lv,
/* Helper: striped/raid0* -> raid4/5/6/10 */
static int _striped_or_raid0_to_raid45610_wrapper(TAKEOVER_FN_ARGS)
{
+ uint32_t extents_copied, region_size, seg_len, stripe_size;
struct lv_segment *seg = first_seg(lv);
struct dm_list removal_lvs;
dm_list_init(&removal_lvs);
+ if (!seg_is_striped_target(seg) &&
+ !seg_is_any_raid0(seg) &&
+ !seg_is_raid4(seg) &&
+ !seg_is_any_raid5(seg)) {
+ log_error("Can't convert %s LV %s.", lvseg_name(seg), display_lvname(lv));
+ return 0;
+ }
+
if (seg_is_raid10(seg))
return _takeover_unsupported_yet(lv, new_stripes, new_segtype);
+ if (!segtype_is_raid4(new_segtype) &&
+ !segtype_is_raid5_n(new_segtype) &&
+ !segtype_is_raid6_n_6(new_segtype)) {
+ /* Can't convert to e.g. raid10_offset */
+ log_error("Can't convert %s to %s.", display_lvname(lv), new_segtype->name);
+ return 0;
+ }
+
if (new_data_copies > new_image_count) {
log_error("N number of data_copies \"--mirrors N-1\" may not be larger than number of stripes.");
return 0;
@@ -3206,8 +3294,9 @@ static int _striped_or_raid0_to_raid45610_wrapper(TAKEOVER_FN_ARGS)
return 0;
}
- /* FIXME: restricted to raid4 for the time being... */
- if (!segtype_is_raid4(new_segtype)) {
+ /* FIXME: restricted to raid4 and raid5_n for the time being... */
+ if (!segtype_is_raid4(new_segtype) &&
+ !segtype_is_raid5_n(new_segtype)) {
/* Can't convert striped/raid0* to e.g. raid10_offset */
log_error("Can't convert %s to %s.", display_lvname(lv), new_segtype->name);
return 0;
@@ -3219,7 +3308,7 @@ static int _striped_or_raid0_to_raid45610_wrapper(TAKEOVER_FN_ARGS)
/* This helper can be used to convert from striped/raid0* -> raid10 too */
if (seg_is_striped_target(seg)) {
- log_debug_metadata("Converting LV %s from %s to %s",
+ log_debug_metadata("Converting LV %s from %s to %s.",
display_lvname(lv), SEG_TYPE_NAME_STRIPED, SEG_TYPE_NAME_RAID0);
if (!(seg = _convert_striped_to_raid0(lv, 1 /* alloc_metadata_devs */, 0 /* update_and_reload */, allocate_pvs)))
return_0;
@@ -3229,18 +3318,32 @@ static int _striped_or_raid0_to_raid45610_wrapper(TAKEOVER_FN_ARGS)
if (seg_is_raid0(seg)) {
log_debug_metadata("Adding metadata LVs to %s.", display_lvname(lv));
if (!_raid0_add_or_remove_metadata_lvs(lv, 1 /* update_and_reload */, allocate_pvs, NULL))
- return_0;
- /* raid0_meta -> raid4 needs clearing of MetaLVs in order to avoid raid disk role cahnge issues in the kernel */
+ return 0;
+ /* raid0_meta -> raid4 needs clearing of MetaLVs in order to avoid raid disk role change issues in the kernel */
} else if (segtype_is_raid4(new_segtype) &&
!_clear_meta_lvs(lv))
return_0;
+
/* Add the additional component LV pairs */
log_debug_metadata("Adding %" PRIu32 " component LV pair(s) to %s.",
new_image_count - lv_raid_image_count(lv),
display_lvname(lv));
+ extents_copied = seg->extents_copied;
+ region_size = seg->region_size;
+ seg_len = seg->len;
+ stripe_size = seg->stripe_size;
+
+ if (seg_is_raid4(seg) || seg_is_any_raid5(seg)) {
+ if (!(seg->segtype = get_segtype_from_flag(lv->vg->cmd, SEG_RAID0_META)))
+ return_0;
+ seg->area_len = seg_lv(seg, 0)->le_count;
+ lv->le_count = seg->len = seg->area_len * seg->area_count;
+ seg->extents_copied = seg->region_size = 0;
+ }
+
if (!_lv_raid_change_image_count(lv, new_image_count, allocate_pvs, NULL, 0, 1))
- return_0;
+ return 0;
if (segtype_is_raid4(new_segtype) &&
(!_shift_parity_dev(seg) ||
@@ -3250,9 +3353,12 @@ static int _striped_or_raid0_to_raid45610_wrapper(TAKEOVER_FN_ARGS)
}
seg->segtype = new_segtype;
- seg->region_size = new_region_size;
- /* FIXME Hard-coded raid0 to raid4 */
- seg->area_len = seg->len;
+ seg->region_size = new_region_size ?: region_size;
+
+ /* FIXME Hard-coded raid0 to raid4/5/6 */
+ seg->stripe_size = stripe_size;
+ lv->le_count = seg->len = seg->area_len = seg_len;
+ seg->extents_copied = extents_copied;
_check_and_adjust_region_size(lv);
@@ -3262,7 +3368,7 @@ static int _striped_or_raid0_to_raid45610_wrapper(TAKEOVER_FN_ARGS)
return_0;
if (segtype_is_raid4(new_segtype)) {
- /* We had to rename SubLVs because of collision free sgifting, rename back... */
+ /* We had to rename SubLVs because of collision free shifting, rename back... */
if (!_rename_area_lvs(lv, NULL))
return_0;
if (!lv_update_and_reload(lv))
@@ -3352,7 +3458,9 @@ static int _takeover_from_raid0_to_raid10(TAKEOVER_FN_ARGS)
static int _takeover_from_raid0_to_raid45(TAKEOVER_FN_ARGS)
{
- return _striped_or_raid0_to_raid45610_wrapper(lv, new_segtype, yes, force, first_seg(lv)->area_count + 1, 1 /* data_copies */, 0, 0, new_region_size, allocate_pvs);
+ return _striped_or_raid0_to_raid45610_wrapper(lv, new_segtype, yes, force,
+ first_seg(lv)->area_count + 1 /* new_image_count */,
+ 2 /* data_copies */, 0, 0, new_region_size, allocate_pvs);
}
static int _takeover_from_raid0_to_raid6(TAKEOVER_FN_ARGS)
@@ -3398,7 +3506,9 @@ static int _takeover_from_raid0_meta_to_raid10(TAKEOVER_FN_ARGS)
static int _takeover_from_raid0_meta_to_raid45(TAKEOVER_FN_ARGS)
{
- return _striped_or_raid0_to_raid45610_wrapper(lv, new_segtype, yes, force, first_seg(lv)->area_count + 1, 1 /* data_copies */, 0, 0, new_region_size, allocate_pvs);
+ return _striped_or_raid0_to_raid45610_wrapper(lv, new_segtype, yes, force,
+ first_seg(lv)->area_count + 1 /* new_image_count */,
+ 2 /* data_copies */, 0, 0, new_region_size, allocate_pvs);
}
static int _takeover_from_raid0_meta_to_raid6(TAKEOVER_FN_ARGS)
@@ -3481,7 +3591,7 @@ static int _takeover_from_raid45_to_raid1(TAKEOVER_FN_ARGS)
static int _takeover_from_raid45_to_raid54(TAKEOVER_FN_ARGS)
{
- return _takeover_unsupported_yet(lv, new_stripes, new_segtype);
+ return _raid45_to_raid54_wrapper(lv, new_segtype, yes, force, first_seg(lv)->area_count, 2 /* data_copies */, 0, 0, 0, allocate_pvs);
}
static int _takeover_from_raid45_to_raid6(TAKEOVER_FN_ARGS)
@@ -3679,14 +3789,10 @@ static int _set_convenient_raid456_segtype_to(const struct lv_segment *seg_from,
return 0;
}
- /* Got to do check for raid5 -> raid6 ... */
- } else if (seg_is_any_raid5(seg_from) &&
- segtype_is_any_raid6(*segtype)) {
- log_error("Conversion not supported.");
- return 0;
-
/* ... and raid6 -> raid5 */
- } else if (seg_is_any_raid6(seg_from) &&
+ } else if ((seg_is_raid6_zr(seg_from) ||
+ seg_is_raid6_nr(seg_from) ||
+ seg_is_raid6_nc(seg_from)) &&
segtype_is_any_raid5(*segtype)) {
log_error("Conversion not supported.");
return 0;
@@ -3927,7 +4033,7 @@ static int _lv_raid_rebuild_or_replace(struct logical_volume *lv,
const char *action_str = rebuild ? "rebuild" : "replace";
if (seg_is_any_raid0(raid_seg)) {
- log_error("Can't replace any devices in %s LV %s",
+ log_error("Can't replace any devices in %s LV %s.",
lvseg_name(raid_seg), display_lvname(lv));
return 0;
}
diff --git a/lib/raid/raid.c b/lib/raid/raid.c
index 1e562ff..7dfafef 100644
--- a/lib/raid/raid.c
+++ b/lib/raid/raid.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011-2016 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2011-2017 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -87,13 +87,13 @@ static int _raid_text_import_areas(struct lv_segment *seg,
}
/* Metadata device comes first. */
- if (!seg_is_raid0(seg)) {
- if (!(lv = find_lv(seg->lv->vg, cv->v.str))) {
- log_error("Couldn't find volume '%s' for segment '%s'.",
- cv->v.str ? : "NULL", seg_name);
- return 0;
- }
+ if (!(lv = find_lv(seg->lv->vg, cv->v.str))) {
+ log_error("Couldn't find volume '%s' for segment '%s'.",
+ cv->v.str ? : "NULL", seg_name);
+ return 0;
+ }
+ if (strstr(lv->name, "_rmeta_")) {
if (!set_lv_segment_area_lv(seg, s, lv, 0, RAID_META))
return_0;
cv = cv->next;
@@ -537,6 +537,7 @@ static const struct raid_type {
{ SEG_TYPE_NAME_RAID10, 0, SEG_RAID10 | SEG_AREAS_MIRRORED },
{ SEG_TYPE_NAME_RAID4, 1, SEG_RAID4 },
{ SEG_TYPE_NAME_RAID5, 1, SEG_RAID5 },
+ { SEG_TYPE_NAME_RAID5_N, 1, SEG_RAID5_N },
{ SEG_TYPE_NAME_RAID5_LA, 1, SEG_RAID5_LA },
{ SEG_TYPE_NAME_RAID5_LS, 1, SEG_RAID5_LS },
{ SEG_TYPE_NAME_RAID5_RA, 1, SEG_RAID5_RA },
diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c
index c5226a7..8a32320 100644
--- a/libdm/libdm-deptree.c
+++ b/libdm/libdm-deptree.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2016 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2005-2017 Red Hat, Inc. All rights reserved.
*
* This file is part of the device-mapper userspace tools.
*
@@ -47,6 +47,7 @@ enum {
SEG_RAID1,
SEG_RAID10,
SEG_RAID4,
+ SEG_RAID5_N,
SEG_RAID5_LA,
SEG_RAID5_RA,
SEG_RAID5_LS,
@@ -81,6 +82,7 @@ static const struct {
{ SEG_RAID1, "raid1"},
{ SEG_RAID10, "raid10"},
{ SEG_RAID4, "raid4"},
+ { SEG_RAID5_N, "raid5_n"},
{ SEG_RAID5_LA, "raid5_la"},
{ SEG_RAID5_RA, "raid5_ra"},
{ SEG_RAID5_LS, "raid5_ls"},
@@ -2140,6 +2142,7 @@ static int _emit_areas_line(struct dm_task *dmt __attribute__((unused)),
case SEG_RAID1:
case SEG_RAID10:
case SEG_RAID4:
+ case SEG_RAID5_N:
case SEG_RAID5_LA:
case SEG_RAID5_RA:
case SEG_RAID5_LS:
@@ -2588,6 +2591,7 @@ static int _emit_segment_line(struct dm_task *dmt, uint32_t major,
case SEG_RAID1:
case SEG_RAID10:
case SEG_RAID4:
+ case SEG_RAID5_N:
case SEG_RAID5_LA:
case SEG_RAID5_RA:
case SEG_RAID5_LS:
@@ -3869,6 +3873,7 @@ int dm_tree_node_add_null_area(struct dm_tree_node *node, uint64_t offset)
case SEG_RAID0_META:
case SEG_RAID1:
case SEG_RAID4:
+ case SEG_RAID5_N:
case SEG_RAID5_LA:
case SEG_RAID5_RA:
case SEG_RAID5_LS:
diff --git a/test/shell/lvconvert-raid-takeover.sh b/test/shell/lvconvert-raid-takeover.sh
index c1cb1aa..0b7d326 100644
--- a/test/shell/lvconvert-raid-takeover.sh
+++ b/test/shell/lvconvert-raid-takeover.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# Copyright (C) 2016 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2016,2017 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
@@ -120,6 +120,7 @@ check lv_field $vg/$lv4 segtype "striped"
check lv_field $vg/$lv4 stripes 3
fsck -fn /dev/mapper/$vg-$lv4
+
# Convert striped -> raid4
lvconvert -y --ty raid4 $vg/$lv1
check lv_field $vg/$lv1 segtype "raid4"
@@ -128,6 +129,37 @@ fsck -fn /dev/mapper/$vg-$lv1
aux wait_for_sync $vg $lv1
fsck -fn /dev/mapper/$vg-$lv1
+# Convert raid4 -> raid5_n
+lvconvert -y --ty raid5_n $vg/$lv1
+check lv_field $vg/$lv1 segtype "raid5_n"
+check lv_field $vg/$lv1 stripes 4
+fsck -fn /dev/mapper/$vg-$lv1
+aux wait_for_sync $vg $lv1
+fsck -fn /dev/mapper/$vg-$lv1
+
+# Convert raid5 -> striped
+lvconvert -y --ty striped $vg/$lv1
+check lv_field $vg/$lv1 segtype "striped"
+check lv_field $vg/$lv1 stripes 3
+fsck -fn /dev/mapper/$vg-$lv1
+
+# Convert striped -> raid5_n
+lvconvert -y --ty raid5_n $vg/$lv1
+check lv_field $vg/$lv1 segtype "raid5_n"
+check lv_field $vg/$lv1 stripes 4
+fsck -fn /dev/mapper/$vg-$lv1
+aux wait_for_sync $vg $lv1
+fsck -fn /dev/mapper/$vg-$lv1
+
+# Convert raid5_n -> raid4
+lvconvert -y --ty raid4 $vg/$lv1
+check lv_field $vg/$lv1 segtype "raid4"
+check lv_field $vg/$lv1 stripes 4
+fsck -fn /dev/mapper/$vg-$lv1
+aux wait_for_sync $vg $lv1
+fsck -fn /dev/mapper/$vg-$lv1
+
+
# Convert raid0 -> raid4
lvconvert -y --ty raid4 $vg/$lv2
check lv_field $vg/$lv2 segtype "raid4"
@@ -136,6 +168,35 @@ fsck -fn /dev/mapper/$vg-$lv2
aux wait_for_sync $vg $lv2
fsck -fn /dev/mapper/$vg-$lv2
+# Convert raid4 -> raid0
+lvconvert -y --ty raid0 $vg/$lv2
+check lv_field $vg/$lv2 segtype "raid0"
+check lv_field $vg/$lv2 stripes 3
+fsck -fn /dev/mapper/$vg-$lv2
+
+# Convert raid0 -> raid5_n
+lvconvert -y --ty raid5_n $vg/$lv2
+check lv_field $vg/$lv2 segtype "raid5_n"
+check lv_field $vg/$lv2 stripes 4
+fsck -fn /dev/mapper/$vg-$lv2
+aux wait_for_sync $vg $lv2
+fsck -fn /dev/mapper/$vg-$lv2
+
+# Convert raid5_n -> raid0_meta
+lvconvert -y --ty raid0_meta $vg/$lv2
+check lv_field $vg/$lv2 segtype "raid0_meta"
+check lv_field $vg/$lv2 stripes 3
+fsck -fn /dev/mapper/$vg-$lv2
+
+# Convert raid0_meta -> raid5_n
+lvconvert -y --ty raid5_n $vg/$lv2
+check lv_field $vg/$lv2 segtype "raid5_n"
+check lv_field $vg/$lv2 stripes 4
+fsck -fn /dev/mapper/$vg-$lv2
+aux wait_for_sync $vg $lv2
+fsck -fn /dev/mapper/$vg-$lv2
+
+
# Convert raid4 -> raid0_meta
lvconvert -y --ty raid0_meta $vg/$lv1
check lv_field $vg/$lv1 segtype "raid0_meta"
7 years, 2 months
master - lvmdbusd: cmdhandler.py, remove duplicate code
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=875ce04c61fb40...
Commit: 875ce04c61fb40436bf4d6308356c800d08c1f7e
Parent: 3eccbb4b4713f0d79831e7c146851bff820c94bb
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Feb 1 19:05:41 2017 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Wed Feb 1 19:05:41 2017 -0600
lvmdbusd: cmdhandler.py, remove duplicate code
Move similar code to common functions, less is more!
---
daemons/lvmdbusd/cmdhandler.py | 16 +++++++---------
1 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/daemons/lvmdbusd/cmdhandler.py b/daemons/lvmdbusd/cmdhandler.py
index f1591aa..31b7c5c 100644
--- a/daemons/lvmdbusd/cmdhandler.py
+++ b/daemons/lvmdbusd/cmdhandler.py
@@ -295,7 +295,7 @@ def vg_lv_snapshot(vg_name, snapshot_options, name, size_bytes):
return call(cmd)
-def vg_lv_create_linear(vg_name, create_options, name, size_bytes, thin_pool):
+def _vg_lv_create_common_cmd(create_options, size_bytes, thin_pool):
cmd = ['lvcreate']
cmd.extend(options_to_cli_args(create_options))
@@ -303,20 +303,18 @@ def vg_lv_create_linear(vg_name, create_options, name, size_bytes, thin_pool):
cmd.extend(['--size', str(size_bytes) + 'B'])
else:
cmd.extend(['--thin', '--size', str(size_bytes) + 'B'])
+ return cmd
+
+
+def vg_lv_create_linear(vg_name, create_options, name, size_bytes, thin_pool):
+ cmd = _vg_lv_create_common_cmd(create_options, size_bytes, thin_pool)
cmd.extend(['--name', name, vg_name])
return call(cmd)
def vg_lv_create_striped(vg_name, create_options, name, size_bytes,
num_stripes, stripe_size_kb, thin_pool):
- cmd = ['lvcreate']
- cmd.extend(options_to_cli_args(create_options))
-
- if not thin_pool:
- cmd.extend(['--size', str(size_bytes) + 'B'])
- else:
- cmd.extend(['--thin', '--size', str(size_bytes) + 'B'])
-
+ cmd = _vg_lv_create_common_cmd(create_options, size_bytes, thin_pool)
cmd.extend(['--stripes', str(num_stripes)])
if stripe_size_kb != 0:
7 years, 2 months
master - lvmdbusd: manager.py, remove duplicate code
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3eccbb4b4713f0...
Commit: 3eccbb4b4713f0d79831e7c146851bff820c94bb
Parent: 945842fa680d6c967b64362fe8b2ce6c3334a52d
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Feb 1 18:57:01 2017 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Wed Feb 1 18:57:01 2017 -0600
lvmdbusd: manager.py, remove duplicate code
Move similar code to common functions, less is more!
---
daemons/lvmdbusd/manager.py | 42 ++++++++++++++++--------------------------
1 files changed, 16 insertions(+), 26 deletions(-)
diff --git a/daemons/lvmdbusd/manager.py b/daemons/lvmdbusd/manager.py
index 3f6f09b..41bb22a 100644
--- a/daemons/lvmdbusd/manager.py
+++ b/daemons/lvmdbusd/manager.py
@@ -31,6 +31,16 @@ class Manager(AutomatedProperties):
return dbus.String('1.0.0')
@staticmethod
+ def handle_execute(rc, out, err):
+ if rc == 0:
+ cfg.load()
+ else:
+ # Need to work on error handling, need consistent
+ raise dbus.exceptions.DBusException(
+ MANAGER_INTERFACE,
+ 'Exit code %s, stderr = %s' % (str(rc), err))
+
+ @staticmethod
def _pv_create(device, create_options):
# Check to see if we are already trying to create a PV for an existing
@@ -41,15 +51,8 @@ class Manager(AutomatedProperties):
MANAGER_INTERFACE, "PV Already exists!")
rc, out, err = cmdhandler.pv_create(create_options, [device])
- if rc == 0:
- cfg.load()
- created_pv = cfg.om.get_object_path_by_lvm_id(device)
- else:
- raise dbus.exceptions.DBusException(
- MANAGER_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
-
- return created_pv
+ Manager.handle_execute(rc, out, err)
+ return cfg.om.get_object_path_by_lvm_id(device)
@dbus.service.method(
dbus_interface=MANAGER_INTERFACE,
@@ -76,14 +79,8 @@ class Manager(AutomatedProperties):
MANAGER_INTERFACE, 'object path = %s not found' % p)
rc, out, err = cmdhandler.vg_create(create_options, pv_devices, name)
-
- if rc == 0:
- cfg.load()
- return cfg.om.get_object_path_by_lvm_id(name)
- else:
- raise dbus.exceptions.DBusException(
- MANAGER_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
+ Manager.handle_execute(rc, out, err)
+ return cfg.om.get_object_path_by_lvm_id(name)
@dbus.service.method(
dbus_interface=MANAGER_INTERFACE,
@@ -200,15 +197,8 @@ class Manager(AutomatedProperties):
activate, cache, device_path,
major_minor, scan_options)
- if rc == 0:
- # This could potentially change the state quite a bit, so lets
- # update everything to be safe
- cfg.load()
- return '/'
- else:
- raise dbus.exceptions.DBusException(
- MANAGER_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
+ Manager.handle_execute(rc, out, err)
+ return '/'
@dbus.service.method(
dbus_interface=MANAGER_INTERFACE,
7 years, 2 months
master - lvmdbusd: lvmdb.py, remove duplicate code
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=945842fa680d6c...
Commit: 945842fa680d6c967b64362fe8b2ce6c3334a52d
Parent: 681d69c70ae70dffa9d21bfd82e1e9821371ee82
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Feb 1 18:56:39 2017 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Wed Feb 1 18:56:39 2017 -0600
lvmdbusd: lvmdb.py, remove duplicate code
Move similar code to common functions, less is more!
---
daemons/lvmdbusd/lvmdb.py | 39 ++++++++++++++++-----------------------
1 files changed, 16 insertions(+), 23 deletions(-)
diff --git a/daemons/lvmdbusd/lvmdb.py b/daemons/lvmdbusd/lvmdb.py
index 9529e03..974e7d7 100755
--- a/daemons/lvmdbusd/lvmdb.py
+++ b/daemons/lvmdbusd/lvmdb.py
@@ -69,18 +69,7 @@ class DataStore(object):
table[key] = record
@staticmethod
- def _parse_pvs(_pvs):
- pvs = sorted(_pvs, key=lambda pk: pk['pv_name'])
-
- c_pvs = OrderedDict()
- c_lookup = {}
- c_pvs_in_vgs = {}
-
- for p in pvs:
- DataStore._insert_record(
- c_pvs, p['pv_uuid'], p,
- ['pvseg_start', 'pvseg_size', 'segtype'])
-
+ def _pvs_parse_common(c_pvs, c_pvs_in_vgs, c_lookup):
for p in c_pvs.values():
# Capture which PVs are associated with which VG
if p['vg_uuid'] not in c_pvs_in_vgs:
@@ -93,6 +82,20 @@ class DataStore(object):
# Lookup for translating between /dev/<name> and pv uuid
c_lookup[p['pv_name']] = p['pv_uuid']
+ @staticmethod
+ def _parse_pvs(_pvs):
+ pvs = sorted(_pvs, key=lambda pk: pk['pv_name'])
+
+ c_pvs = OrderedDict()
+ c_lookup = {}
+ c_pvs_in_vgs = {}
+
+ for p in pvs:
+ DataStore._insert_record(
+ c_pvs, p['pv_uuid'], p,
+ ['pvseg_start', 'pvseg_size', 'segtype'])
+
+ DataStore._pvs_parse_common(c_pvs, c_pvs_in_vgs, c_lookup)
return c_pvs, c_lookup, c_pvs_in_vgs
@staticmethod
@@ -132,17 +135,7 @@ class DataStore(object):
i['pvseg_size'] = i['pv_pe_count']
i['segtype'] = 'free'
- for p in c_pvs.values():
- # Capture which PVs are associated with which VG
- if p['vg_uuid'] not in c_pvs_in_vgs:
- c_pvs_in_vgs[p['vg_uuid']] = []
-
- if p['vg_name']:
- c_pvs_in_vgs[p['vg_uuid']].append(
- (p['pv_name'], p['pv_uuid']))
-
- # Lookup for translating between /dev/<name> and pv uuid
- c_lookup[p['pv_name']] = p['pv_uuid']
+ DataStore._pvs_parse_common(c_pvs, c_pvs_in_vgs, c_lookup)
return c_pvs, c_lookup, c_pvs_in_vgs
7 years, 2 months
master - lvmdbusd: pv.py, remove duplicate code
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=681d69c70ae70d...
Commit: 681d69c70ae70dffa9d21bfd82e1e9821371ee82
Parent: a010cede6e69fcb9301d0b1f4e282a2b04d15430
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Feb 1 16:51:00 2017 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Wed Feb 1 16:51:00 2017 -0600
lvmdbusd: pv.py, remove duplicate code
Move similar code to common functions, less is more!
---
daemons/lvmdbusd/pv.py | 65 ++++++++++++++++++-----------------------------
1 files changed, 25 insertions(+), 40 deletions(-)
diff --git a/daemons/lvmdbusd/pv.py b/daemons/lvmdbusd/pv.py
index 95047d1..fe32143 100644
--- a/daemons/lvmdbusd/pv.py
+++ b/daemons/lvmdbusd/pv.py
@@ -135,23 +135,30 @@ class Pv(AutomatedProperties):
def _remove(pv_uuid, pv_name, remove_options):
# Remove the PV, if successful then remove from the model
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(pv_uuid, pv_name)
+ Pv.validate_dbus_object(pv_uuid, pv_name)
+ rc, out, err = cmdhandler.pv_remove(pv_name, remove_options)
+ Pv.handle_execute(rc, out, err)
+ return '/'
- if dbo:
- rc, out, err = cmdhandler.pv_remove(pv_name, remove_options)
- if rc == 0:
- cfg.load()
- else:
- # Need to work on error handling, need consistent
- raise dbus.exceptions.DBusException(
- PV_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
+ @staticmethod
+ def handle_execute(rc, out, err):
+ if rc == 0:
+ cfg.load()
else:
+ # Need to work on error handling, need consistent
+ raise dbus.exceptions.DBusException(
+ PV_INTERFACE,
+ 'Exit code %s, stderr = %s' % (str(rc), err))
+
+ @staticmethod
+ def validate_dbus_object(pv_uuid, pv_name):
+ dbo = cfg.om.get_object_by_uuid_lvm_id(pv_uuid, pv_name)
+ if not dbo:
raise dbus.exceptions.DBusException(
PV_INTERFACE,
'PV with uuid %s and name %s not present!' %
(pv_uuid, pv_name))
- return '/'
+ return dbo
@dbus.service.method(
dbus_interface=PV_INTERFACE,
@@ -168,22 +175,11 @@ class Pv(AutomatedProperties):
@staticmethod
def _resize(pv_uuid, pv_name, new_size_bytes, resize_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(pv_uuid, pv_name)
+ Pv.validate_dbus_object(pv_uuid, pv_name)
- if dbo:
- rc, out, err = cmdhandler.pv_resize(pv_name, new_size_bytes,
+ rc, out, err = cmdhandler.pv_resize(pv_name, new_size_bytes,
resize_options)
- if rc == 0:
- cfg.load()
- else:
- raise dbus.exceptions.DBusException(
- PV_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- PV_INTERFACE,
- 'PV with uuid %s and name %s not present!' %
- (pv_uuid, pv_name))
+ Pv.handle_execute(rc, out, err)
return '/'
@dbus.service.method(
@@ -201,21 +197,10 @@ class Pv(AutomatedProperties):
@staticmethod
def _allocation_enabled(pv_uuid, pv_name, yes_no, allocation_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(pv_uuid, pv_name)
-
- if dbo:
- rc, out, err = cmdhandler.pv_allocatable(
- pv_name, yes_no, allocation_options)
- if rc == 0:
- cfg.load()
- else:
- raise dbus.exceptions.DBusException(
- PV_INTERFACE, 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- PV_INTERFACE,
- 'PV with uuid %s and name %s not present!' %
- (pv_uuid, pv_name))
+ Pv.validate_dbus_object(pv_uuid, pv_name)
+ rc, out, err = cmdhandler.pv_allocatable(
+ pv_name, yes_no, allocation_options)
+ Pv.handle_execute(rc, out, err)
return '/'
@dbus.service.method(
7 years, 2 months
master - lvmdbusd: vg.py, remove duplicate code
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a010cede6e69fc...
Commit: a010cede6e69fcb9301d0b1f4e282a2b04d15430
Parent: 83a19075861d86d7800e395f4c30f90dabc11692
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Feb 1 16:37:03 2017 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Wed Feb 1 16:37:03 2017 -0600
lvmdbusd: vg.py, remove duplicate code
Move similar code to common functions, less is more!
---
daemons/lvmdbusd/vg.py | 418 +++++++++++++++---------------------------------
1 files changed, 128 insertions(+), 290 deletions(-)
diff --git a/daemons/lvmdbusd/vg.py b/daemons/lvmdbusd/vg.py
index 9b1df4e..c00084d 100644
--- a/daemons/lvmdbusd/vg.py
+++ b/daemons/lvmdbusd/vg.py
@@ -145,29 +145,35 @@ class Vg(AutomatedProperties):
@staticmethod
def fetch_new_lv(vg_name, lv_name):
- cfg.load()
return cfg.om.get_object_path_by_lvm_id("%s/%s" % (vg_name, lv_name))
@staticmethod
- def _rename(uuid, vg_name, new_name, rename_options):
- # Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
-
- if dbo:
- rc, out, err = cmdhandler.vg_rename(vg_name, new_name,
- rename_options)
- if rc == 0:
- cfg.load()
- else:
- # Need to work on error handling, need consistent
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
+ def handle_execute(rc, out, err):
+ if rc == 0:
+ cfg.load()
else:
+ # Need to work on error handling, need consistent
+ raise dbus.exceptions.DBusException(
+ VG_INTERFACE,
+ 'Exit code %s, stderr = %s' % (str(rc), err))
+
+ @staticmethod
+ def validate_dbus_object(vg_uuid, vg_name):
+ dbo = cfg.om.get_object_by_uuid_lvm_id(vg_uuid, vg_name)
+ if not dbo:
raise dbus.exceptions.DBusException(
VG_INTERFACE,
'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
+ (vg_uuid, vg_name))
+ return dbo
+
+ @staticmethod
+ def _rename(uuid, vg_name, new_name, rename_options):
+ # Make sure we have a dbus object representing it
+ Vg.validate_dbus_object(uuid, vg_name)
+ rc, out, err = cmdhandler.vg_rename(
+ vg_name, new_name, rename_options)
+ Vg.handle_execute(rc, out, err)
return '/'
@dbus.service.method(
@@ -184,24 +190,10 @@ class Vg(AutomatedProperties):
@staticmethod
def _remove(uuid, vg_name, remove_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
-
- if dbo:
- # Remove the VG, if successful then remove from the model
- rc, out, err = cmdhandler.vg_remove(vg_name, remove_options)
-
- if rc == 0:
- cfg.load()
- else:
- # Need to work on error handling, need consistent
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
+ Vg.validate_dbus_object(uuid, vg_name)
+ # Remove the VG, if successful then remove from the model
+ rc, out, err = cmdhandler.vg_remove(vg_name, remove_options)
+ Vg.handle_execute(rc, out, err)
return '/'
@dbus.service.method(
@@ -216,26 +208,9 @@ class Vg(AutomatedProperties):
@staticmethod
def _change(uuid, vg_name, change_options):
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
-
- if dbo:
- rc, out, err = cmdhandler.vg_change(change_options, vg_name)
-
- # To use an example with d-feet (Method input)
- # {"activate": __import__('gi.repository.GLib', globals(),
- # locals(), ['Variant']).Variant("s", "n")}
-
- if rc == 0:
- cfg.load()
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
+ Vg.validate_dbus_object(uuid, vg_name)
+ rc, out, err = cmdhandler.vg_change(change_options, vg_name)
+ Vg.handle_execute(rc, out, err)
return '/'
# TODO: This should be broken into a number of different methods
@@ -256,34 +231,24 @@ class Vg(AutomatedProperties):
@staticmethod
def _reduce(uuid, vg_name, missing, pv_object_paths, reduce_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
-
- if dbo:
- pv_devices = []
-
- # If pv_object_paths is not empty, then get the device paths
- if pv_object_paths and len(pv_object_paths) > 0:
- for pv_op in pv_object_paths:
- pv = cfg.om.get_object_by_path(pv_op)
- if pv:
- pv_devices.append(pv.lvm_id)
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'PV Object path not found = %s!' % pv_op)
-
- rc, out, err = cmdhandler.vg_reduce(vg_name, missing, pv_devices,
- reduce_options)
- if rc == 0:
- cfg.load()
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE, 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
+ Vg.validate_dbus_object(uuid, vg_name)
+
+ pv_devices = []
+
+ # If pv_object_paths is not empty, then get the device paths
+ if pv_object_paths and len(pv_object_paths) > 0:
+ for pv_op in pv_object_paths:
+ pv = cfg.om.get_object_by_path(pv_op)
+ if pv:
+ pv_devices.append(pv.lvm_id)
+ else:
+ raise dbus.exceptions.DBusException(
+ VG_INTERFACE,
+ 'PV Object path not found = %s!' % pv_op)
+
+ rc, out, err = cmdhandler.vg_reduce(vg_name, missing, pv_devices,
+ reduce_options)
+ Vg.handle_execute(rc, out, err)
return '/'
@dbus.service.method(
@@ -300,36 +265,26 @@ class Vg(AutomatedProperties):
@staticmethod
def _extend(uuid, vg_name, pv_object_paths, extend_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
-
- if dbo:
- extend_devices = []
+ Vg.validate_dbus_object(uuid, vg_name)
- for i in pv_object_paths:
- pv = cfg.om.get_object_by_path(i)
- if pv:
- extend_devices.append(pv.lvm_id)
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE, 'PV Object path not found = %s!' % i)
+ extend_devices = []
- if len(extend_devices):
- rc, out, err = cmdhandler.vg_extend(vg_name, extend_devices,
- extend_options)
- if rc == 0:
- cfg.load()
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
+ for i in pv_object_paths:
+ pv = cfg.om.get_object_by_path(i)
+ if pv:
+ extend_devices.append(pv.lvm_id)
else:
raise dbus.exceptions.DBusException(
- VG_INTERFACE, 'No pv_object_paths provided!')
+ VG_INTERFACE, 'PV Object path not found = %s!' % i)
+
+ if len(extend_devices):
+ rc, out, err = cmdhandler.vg_extend(vg_name, extend_devices,
+ extend_options)
+ Vg.handle_execute(rc, out, err)
else:
raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
+ VG_INTERFACE, 'No pv_object_paths provided!')
+
return '/'
@dbus.service.method(
@@ -366,33 +321,24 @@ class Vg(AutomatedProperties):
create_options):
# Make sure we have a dbus object representing it
pv_dests = []
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
- if dbo:
- if len(pv_dests_and_ranges):
- for pr in pv_dests_and_ranges:
- pv_dbus_obj = cfg.om.get_object_by_path(pr[0])
- if not pv_dbus_obj:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'PV Destination (%s) not found' % pr[0])
+ Vg.validate_dbus_object(uuid, vg_name)
- pv_dests.append((pv_dbus_obj.lvm_id, pr[1], pr[2]))
+ if len(pv_dests_and_ranges):
+ for pr in pv_dests_and_ranges:
+ pv_dbus_obj = cfg.om.get_object_by_path(pr[0])
+ if not pv_dbus_obj:
+ raise dbus.exceptions.DBusException(
+ VG_INTERFACE,
+ 'PV Destination (%s) not found' % pr[0])
- rc, out, err = cmdhandler.vg_lv_create(
- vg_name, create_options, name, size_bytes, pv_dests)
+ pv_dests.append((pv_dbus_obj.lvm_id, pr[1], pr[2]))
- if rc == 0:
- return Vg.fetch_new_lv(vg_name, name)
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
+ rc, out, err = cmdhandler.vg_lv_create(
+ vg_name, create_options, name, size_bytes, pv_dests)
+
+ Vg.handle_execute(rc, out, err)
+ return Vg.fetch_new_lv(vg_name, name)
@dbus.service.method(
dbus_interface=VG_INTERFACE,
@@ -428,25 +374,13 @@ class Vg(AutomatedProperties):
def _lv_create_linear(uuid, vg_name, name, size_bytes,
thin_pool, create_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
-
- if dbo:
- rc, out, err = cmdhandler.vg_lv_create_linear(
- vg_name, create_options, name, size_bytes, thin_pool)
+ Vg.validate_dbus_object(uuid, vg_name)
- if rc == 0:
- created_lv = Vg.fetch_new_lv(vg_name, name)
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
+ rc, out, err = cmdhandler.vg_lv_create_linear(
+ vg_name, create_options, name, size_bytes, thin_pool)
- return created_lv
+ Vg.handle_execute(rc, out, err)
+ return Vg.fetch_new_lv(vg_name, name)
@dbus.service.method(
dbus_interface=VG_INTERFACE,
@@ -466,24 +400,12 @@ class Vg(AutomatedProperties):
def _lv_create_striped(uuid, vg_name, name, size_bytes, num_stripes,
stripe_size_kb, thin_pool, create_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
-
- if dbo:
- rc, out, err = cmdhandler.vg_lv_create_striped(
- vg_name, create_options, name, size_bytes,
- num_stripes, stripe_size_kb, thin_pool)
- if rc == 0:
- created_lv = Vg.fetch_new_lv(vg_name, name)
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE, 'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
-
- return created_lv
+ Vg.validate_dbus_object(uuid, vg_name)
+ rc, out, err = cmdhandler.vg_lv_create_striped(
+ vg_name, create_options, name, size_bytes,
+ num_stripes, stripe_size_kb, thin_pool)
+ Vg.handle_execute(rc, out, err)
+ return Vg.fetch_new_lv(vg_name, name)
@dbus.service.method(
dbus_interface=VG_INTERFACE,
@@ -506,25 +428,11 @@ class Vg(AutomatedProperties):
def _lv_create_mirror(uuid, vg_name, name, size_bytes,
num_copies, create_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
-
- if dbo:
- rc, out, err = cmdhandler.vg_lv_create_mirror(
- vg_name, create_options, name, size_bytes, num_copies)
- if rc == 0:
- created_lv = Vg.fetch_new_lv(vg_name, name)
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
-
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
-
- return created_lv
+ Vg.validate_dbus_object(uuid, vg_name)
+ rc, out, err = cmdhandler.vg_lv_create_mirror(
+ vg_name, create_options, name, size_bytes, num_copies)
+ Vg.handle_execute(rc, out, err)
+ return Vg.fetch_new_lv(vg_name, name)
@dbus.service.method(
dbus_interface=VG_INTERFACE,
@@ -545,26 +453,12 @@ class Vg(AutomatedProperties):
def _lv_create_raid(uuid, vg_name, name, raid_type, size_bytes,
num_stripes, stripe_size_kb, create_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
-
- if dbo:
- rc, out, err = cmdhandler.vg_lv_create_raid(
- vg_name, create_options, name, raid_type, size_bytes,
- num_stripes, stripe_size_kb)
- if rc == 0:
- created_lv = Vg.fetch_new_lv(vg_name, name)
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
-
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
-
- return created_lv
+ Vg.validate_dbus_object(uuid, vg_name)
+ rc, out, err = cmdhandler.vg_lv_create_raid(
+ vg_name, create_options, name, raid_type, size_bytes,
+ num_stripes, stripe_size_kb)
+ Vg.handle_execute(rc, out, err)
+ return Vg.fetch_new_lv(vg_name, name)
@dbus.service.method(
dbus_interface=VG_INTERFACE,
@@ -585,33 +479,27 @@ class Vg(AutomatedProperties):
def _create_pool(uuid, vg_name, meta_data_lv, data_lv,
create_options, create_method):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
+ Vg.validate_dbus_object(uuid, vg_name)
# Retrieve the full names for the metadata and data lv
md = cfg.om.get_object_by_path(meta_data_lv)
data = cfg.om.get_object_by_path(data_lv)
- if dbo and md and data:
+ if md and data:
new_name = data.Name
rc, out, err = create_method(
md.lv_full_name(), data.lv_full_name(), create_options)
+
if rc == 0:
mt_remove_dbus_objects((md, data))
- cache_pool_lv = Vg.fetch_new_lv(vg_name, new_name)
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
+
+ Vg.handle_execute(rc, out, err)
else:
msg = ""
- if not dbo:
- msg += 'VG with uuid %s and name %s not present!' % \
- (uuid, vg_name)
-
if not md:
msg += 'Meta data LV with object path %s not present!' % \
(meta_data_lv)
@@ -622,7 +510,7 @@ class Vg(AutomatedProperties):
raise dbus.exceptions.DBusException(VG_INTERFACE, msg)
- return cache_pool_lv
+ return Vg.fetch_new_lv(vg_name, new_name)
@dbus.service.method(
dbus_interface=VG_INTERFACE,
@@ -656,33 +544,21 @@ class Vg(AutomatedProperties):
pv_devices = []
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
-
- if dbo:
- # Check for existence of pv object paths
- for p in pv_object_paths:
- pv = cfg.om.get_object_by_path(p)
- if pv:
- pv_devices.append(pv.Name)
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE, 'PV object path = %s not found' % p)
+ Vg.validate_dbus_object(uuid, vg_name)
- rc, out, err = cmdhandler.pv_tag(
- pv_devices, tags_add, tags_del, tag_options)
- if rc == 0:
- cfg.load()
- return '/'
+ # Check for existence of pv object paths
+ for p in pv_object_paths:
+ pv = cfg.om.get_object_by_path(p)
+ if pv:
+ pv_devices.append(pv.Name)
else:
raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
+ VG_INTERFACE, 'PV object path = %s not found' % p)
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
+ rc, out, err = cmdhandler.pv_tag(
+ pv_devices, tags_add, tags_del, tag_options)
+ Vg.handle_execute(rc, out, err)
+ return '/'
@dbus.service.method(
dbus_interface=VG_INTERFACE,
@@ -720,25 +596,12 @@ class Vg(AutomatedProperties):
@staticmethod
def _vg_add_rm_tags(uuid, vg_name, tags_add, tags_del, tag_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
+ Vg.validate_dbus_object(uuid, vg_name)
- if dbo:
-
- rc, out, err = cmdhandler.vg_tag(
- vg_name, tags_add, tags_del, tag_options)
- if rc == 0:
- cfg.load()
- return '/'
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
-
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
+ rc, out, err = cmdhandler.vg_tag(
+ vg_name, tags_add, tags_del, tag_options)
+ Vg.handle_execute(rc, out, err)
+ return '/'
@dbus.service.method(
dbus_interface=VG_INTERFACE,
@@ -775,23 +638,10 @@ class Vg(AutomatedProperties):
@staticmethod
def _vg_change_set(uuid, vg_name, method, value, options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
-
- if dbo:
- rc, out, err = method(vg_name, value, options)
- if rc == 0:
- cfg.load()
- return '/'
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
-
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
+ Vg.validate_dbus_object(uuid, vg_name)
+ rc, out, err = method(vg_name, value, options)
+ Vg.handle_execute(rc, out, err)
+ return '/'
@dbus.service.method(
dbus_interface=VG_INTERFACE,
@@ -849,23 +699,11 @@ class Vg(AutomatedProperties):
def _vg_activate_deactivate(uuid, vg_name, activate, control_flags,
options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, vg_name)
-
- if dbo:
- rc, out, err = cmdhandler.activate_deactivate(
- 'vgchange', vg_name, activate, control_flags, options)
- if rc == 0:
- cfg.load()
- return '/'
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- VG_INTERFACE,
- 'VG with uuid %s and name %s not present!' %
- (uuid, vg_name))
+ Vg.validate_dbus_object(uuid, vg_name)
+ rc, out, err = cmdhandler.activate_deactivate(
+ 'vgchange', vg_name, activate, control_flags, options)
+ Vg.handle_execute(rc, out, err)
+ return '/'
@dbus.service.method(
dbus_interface=VG_INTERFACE,
7 years, 2 months
master - lvmdbusd: lv.py, remove duplicate code
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=83a19075861d86...
Commit: 83a19075861d86d7800e395f4c30f90dabc11692
Parent: 2350ea0060cd729f36245df5622b38c4b8d9bb12
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Feb 1 15:38:55 2017 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Wed Feb 1 15:38:55 2017 -0600
lvmdbusd: lv.py, remove duplicate code
Move similar code to common functions, less is more!
---
daemons/lvmdbusd/lv.py | 268 +++++++++++++++++-------------------------------
1 files changed, 92 insertions(+), 176 deletions(-)
diff --git a/daemons/lvmdbusd/lv.py b/daemons/lvmdbusd/lv.py
index fa54322..6c93e4d 100644
--- a/daemons/lvmdbusd/lv.py
+++ b/daemons/lvmdbusd/lv.py
@@ -272,6 +272,26 @@ class LvCommon(AutomatedProperties):
self.state = object_state
self._move_pv = self._get_move_pv()
+ @staticmethod
+ def handle_execute(rc, out, err):
+ if rc == 0:
+ cfg.load()
+ else:
+ # Need to work on error handling, need consistent
+ raise dbus.exceptions.DBusException(
+ LV_INTERFACE,
+ 'Exit code %s, stderr = %s' % (str(rc), err))
+
+ @staticmethod
+ def validate_dbus_object(lv_uuid, lv_name):
+ dbo = cfg.om.get_object_by_uuid_lvm_id(lv_uuid, lv_name)
+ if not dbo:
+ raise dbus.exceptions.DBusException(
+ LV_INTERFACE,
+ 'LV with uuid %s and name %s not present!' %
+ (lv_uuid, lv_name))
+ return dbo
+
@property
def VolumeType(self):
type_map = {'C': 'Cache', 'm': 'mirrored',
@@ -408,24 +428,10 @@ class Lv(LvCommon):
@staticmethod
def _remove(lv_uuid, lv_name, remove_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(lv_uuid, lv_name)
-
- if dbo:
- # Remove the LV, if successful then remove from the model
- rc, out, err = cmdhandler.lv_remove(lv_name, remove_options)
-
- if rc == 0:
- cfg.load()
- else:
- # Need to work on error handling, need consistent
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'LV with uuid %s and name %s not present!' %
- (lv_uuid, lv_name))
+ LvCommon.validate_dbus_object(lv_uuid, lv_name)
+ # Remove the LV, if successful then remove from the model
+ rc, out, err = cmdhandler.lv_remove(lv_name, remove_options)
+ LvCommon.handle_execute(rc, out, err)
return '/'
@dbus.service.method(
@@ -443,24 +449,11 @@ class Lv(LvCommon):
@staticmethod
def _rename(lv_uuid, lv_name, new_name, rename_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(lv_uuid, lv_name)
-
- if dbo:
- # Rename the logical volume
- rc, out, err = cmdhandler.lv_rename(lv_name, new_name,
- rename_options)
- if rc == 0:
- cfg.load()
- else:
- # Need to work on error handling, need consistent
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'LV with uuid %s and name %s not present!' %
- (lv_uuid, lv_name))
+ LvCommon.validate_dbus_object(lv_uuid, lv_name)
+ # Rename the logical volume
+ rc, out, err = cmdhandler.lv_rename(lv_name, new_name,
+ rename_options)
+ LvCommon.handle_execute(rc, out, err)
return '/'
@dbus.service.method(
@@ -500,32 +493,21 @@ class Lv(LvCommon):
def _snap_shot(lv_uuid, lv_name, name, optional_size,
snapshot_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(lv_uuid, lv_name)
+ dbo = LvCommon.validate_dbus_object(lv_uuid, lv_name)
+ # If you specify a size you get a 'thick' snapshot even if
+ # it is a thin lv
+ if not dbo.IsThinVolume:
+ if optional_size == 0:
+ space = dbo.SizeBytes / 80
+ remainder = space % 512
+ optional_size = space + 512 - remainder
+
+ rc, out, err = cmdhandler.vg_lv_snapshot(
+ lv_name, snapshot_options, name, optional_size)
+ LvCommon.handle_execute(rc, out, err)
+ full_name = "%s/%s" % (dbo.vg_name_lookup(), name)
+ return cfg.om.get_object_path_by_lvm_id(full_name)
- if dbo:
- # If you specify a size you get a 'thick' snapshot even if
- # it is a thin lv
- if not dbo.IsThinVolume:
- if optional_size == 0:
- space = dbo.SizeBytes / 80
- remainder = space % 512
- optional_size = space + 512 - remainder
-
- rc, out, err = cmdhandler.vg_lv_snapshot(
- lv_name, snapshot_options, name, optional_size)
- if rc == 0:
- cfg.load()
- full_name = "%s/%s" % (dbo.vg_name_lookup(), name)
- return cfg.om.get_object_path_by_lvm_id(full_name)
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'LV with uuid %s and name %s not present!' %
- (lv_uuid, lv_name))
@dbus.service.method(
dbus_interface=LV_INTERFACE,
@@ -548,38 +530,24 @@ class Lv(LvCommon):
resize_options):
# Make sure we have a dbus object representing it
pv_dests = []
- dbo = cfg.om.get_object_by_uuid_lvm_id(lv_uuid, lv_name)
-
- if dbo:
- # If we have PVs, verify them
- if len(pv_dests_and_ranges):
- for pr in pv_dests_and_ranges:
- pv_dbus_obj = cfg.om.get_object_by_path(pr[0])
- if not pv_dbus_obj:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'PV Destination (%s) not found' % pr[0])
+ dbo = LvCommon.validate_dbus_object(lv_uuid, lv_name)
- pv_dests.append((pv_dbus_obj.lvm_id, pr[1], pr[2]))
+ # If we have PVs, verify them
+ if len(pv_dests_and_ranges):
+ for pr in pv_dests_and_ranges:
+ pv_dbus_obj = cfg.om.get_object_by_path(pr[0])
+ if not pv_dbus_obj:
+ raise dbus.exceptions.DBusException(
+ LV_INTERFACE,
+ 'PV Destination (%s) not found' % pr[0])
- size_change = new_size_bytes - dbo.SizeBytes
+ pv_dests.append((pv_dbus_obj.lvm_id, pr[1], pr[2]))
- rc, out, err = cmdhandler.lv_resize(dbo.lvm_id, size_change,
- pv_dests, resize_options)
-
- if rc == 0:
- # Refresh what's changed
- cfg.load()
- return "/"
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'LV with uuid %s and name %s not present!' %
- (lv_uuid, lv_name))
+ size_change = new_size_bytes - dbo.SizeBytes
+ rc, out, err = cmdhandler.lv_resize(dbo.lvm_id, size_change,
+ pv_dests, resize_options)
+ LvCommon.handle_execute(rc, out, err)
+ return "/"
@dbus.service.method(
dbus_interface=LV_INTERFACE,
@@ -612,23 +580,11 @@ class Lv(LvCommon):
def _lv_activate_deactivate(uuid, lv_name, activate, control_flags,
options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, lv_name)
-
- if dbo:
- rc, out, err = cmdhandler.activate_deactivate(
- 'lvchange', lv_name, activate, control_flags, options)
- if rc == 0:
- cfg.load()
- return '/'
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'LV with uuid %s and name %s not present!' %
- (uuid, lv_name))
+ LvCommon.validate_dbus_object(uuid, lv_name)
+ rc, out, err = cmdhandler.activate_deactivate(
+ 'lvchange', lv_name, activate, control_flags, options)
+ LvCommon.handle_execute(rc, out, err)
+ return '/'
@dbus.service.method(
dbus_interface=LV_INTERFACE,
@@ -660,25 +616,11 @@ class Lv(LvCommon):
@staticmethod
def _add_rm_tags(uuid, lv_name, tags_add, tags_del, tag_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(uuid, lv_name)
-
- if dbo:
-
- rc, out, err = cmdhandler.lv_tag(
- lv_name, tags_add, tags_del, tag_options)
- if rc == 0:
- cfg.load()
- return '/'
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
-
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'LV with uuid %s and name %s not present!' %
- (uuid, lv_name))
+ LvCommon.validate_dbus_object(uuid, lv_name)
+ rc, out, err = cmdhandler.lv_tag(
+ lv_name, tags_add, tags_del, tag_options)
+ LvCommon.handle_execute(rc, out, err)
+ return '/'
@dbus.service.method(
dbus_interface=LV_INTERFACE,
@@ -736,24 +678,13 @@ class LvThinPool(Lv):
@staticmethod
def _lv_create(lv_uuid, lv_name, name, size_bytes, create_options):
# Make sure we have a dbus object representing it
- dbo = cfg.om.get_object_by_uuid_lvm_id(lv_uuid, lv_name)
+ dbo = LvCommon.validate_dbus_object(lv_uuid, lv_name)
- if dbo:
- rc, out, err = cmdhandler.lv_lv_create(
- lv_name, create_options, name, size_bytes)
- if rc == 0:
- full_name = "%s/%s" % (dbo.vg_name_lookup(), name)
- cfg.load()
- return cfg.om.get_object_path_by_lvm_id(full_name)
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'LV with uuid %s and name %s not present!' %
- (lv_uuid, lv_name))
+ rc, out, err = cmdhandler.lv_lv_create(
+ lv_name, create_options, name, size_bytes)
+ LvCommon.handle_execute(rc, out, err)
+ full_name = "%s/%s" % (dbo.vg_name_lookup(), name)
+ return cfg.om.get_object_path_by_lvm_id(full_name)
@dbus.service.method(
dbus_interface=THIN_POOL_INTERFACE,
@@ -790,14 +721,13 @@ class LvCachePool(Lv):
@staticmethod
def _cache_lv(lv_uuid, lv_name, lv_object_path, cache_options):
-
# Make sure we have a dbus object representing cache pool
- dbo = cfg.om.get_object_by_uuid_lvm_id(lv_uuid, lv_name)
+ dbo = LvCommon.validate_dbus_object(lv_uuid, lv_name)
# Make sure we have dbus object representing lv to cache
lv_to_cache = cfg.om.get_object_by_path(lv_object_path)
- if dbo and lv_to_cache:
+ if lv_to_cache:
fcn = lv_to_cache.lv_full_name()
rc, out, err = cmdhandler.lv_cache_lv(
dbo.lv_full_name(), fcn, cache_options)
@@ -809,22 +739,14 @@ class LvCachePool(Lv):
cfg.load()
lv_converted = cfg.om.get_object_path_by_lvm_id(fcn)
-
else:
raise dbus.exceptions.DBusException(
LV_INTERFACE,
'Exit code %s, stderr = %s' % (str(rc), err))
else:
- msg = ""
- if not dbo:
- dbo += 'CachePool LV with uuid %s and name %s not present!' % \
- (lv_uuid, lv_name)
-
- if not lv_to_cache:
- dbo += 'LV to cache with object path %s not present!' % \
- (lv_object_path)
-
- raise dbus.exceptions.DBusException(LV_INTERFACE, msg)
+ raise dbus.exceptions.DBusException(
+ LV_INTERFACE, 'LV to cache with object path %s not present!' %
+ lv_object_path)
return lv_converted
@dbus.service.method(
@@ -855,31 +777,25 @@ class LvCacheLv(Lv):
@staticmethod
def _detach_lv(lv_uuid, lv_name, detach_options, destroy_cache):
# Make sure we have a dbus object representing cache pool
- dbo = cfg.om.get_object_by_uuid_lvm_id(lv_uuid, lv_name)
-
- if dbo:
+ dbo = LvCommon.validate_dbus_object(lv_uuid, lv_name)
- # Get current cache name
- cache_pool = cfg.om.get_object_by_path(dbo.CachePool)
+ # Get current cache name
+ cache_pool = cfg.om.get_object_by_path(dbo.CachePool)
- rc, out, err = cmdhandler.lv_detach_cache(
- dbo.lv_full_name(), detach_options, destroy_cache)
- if rc == 0:
- # The cache pool gets removed as hidden and put back to
- # visible, so lets delete
- mt_remove_dbus_objects((cache_pool, dbo))
- cfg.load()
+ rc, out, err = cmdhandler.lv_detach_cache(
+ dbo.lv_full_name(), detach_options, destroy_cache)
+ if rc == 0:
+ # The cache pool gets removed as hidden and put back to
+ # visible, so lets delete
+ mt_remove_dbus_objects((cache_pool, dbo))
+ cfg.load()
- uncached_lv_path = cfg.om.get_object_path_by_lvm_id(lv_name)
- else:
- raise dbus.exceptions.DBusException(
- LV_INTERFACE,
- 'Exit code %s, stderr = %s' % (str(rc), err))
+ uncached_lv_path = cfg.om.get_object_path_by_lvm_id(lv_name)
else:
raise dbus.exceptions.DBusException(
LV_INTERFACE,
- 'LV with uuid %s and name %s not present!' %
- (lv_uuid, lv_name))
+ 'Exit code %s, stderr = %s' % (str(rc), err))
+
return uncached_lv_path
@dbus.service.method(
7 years, 2 months