LVM: add split capability
PATCH 1/1 LVM: add split capability
Patch name: lvm-add-split-capability.patch
This patch adds the capability to split off a mirror leg. Essentially, we replace the function that pulls a leg from a mirror and frees it with just the function that pulls it.
The following command line interface is enforced:
prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of legs to split off, and where 'name' is the name of the newly split off logical volume.
It can be seen that '--splitmirror <n>' is exactly the same as '--mirrors -<n>' (note the minus sign), except there is the additional notion to keep the image being detached from the mirror instead of just throwing it away. So, we _could_ have a '--keep' argument or something that could be used in conjunction with '--mirrors' to denote the fact that we wish to keep the image being detached. It has been suggested that we could have two ways of specifying this action. I have not implemented that here. I am strictly choosing '--splitmirror' and purposefully choosing not to have something additional for '--mirrors'. I think this prevents confusion. The additional argument for '--mirrors' will have to come by way of another patch.
Also, I have chosen to make the '-n <name>' argument manditory. Perhaps in the future when we decide on a useful default name we can relax this enforcement. There is no reason to withhold the capability because we haven't formed a concensous on what a default name should be. [Perhaps we will make a better informed decision on that when we begin to implement '--track_deltas'.]
*********************************************************
This patch combines the two previous split mirror patches.
It cleans up the comments and removes the error I made of adding code in the first patch that was being removed in the second. The 'splitmirror' argument is changed to 'splitmirrors'. (splitmirror will still work.) Man page language clean-up. Fix bug introduce in the initialization of 'lp->alloc'.
*********************************************************
lib/metadata/mirror.c +71 -6
@@ -472,6 +472,9 @@ static int _is_mirror_image_removable(st* mirror layer and merge mirrors to the original LV. * removable_pvs should be NULL and num_removed should be * seg->area_count - 1. +* split: if non-NULL, split the mimage off rather than removing +* it, making this argument its name (only one leg can be +* split off at a time). * removed: if non NULL, the number of removed mirror images is set * as a result *
@@ -486,7 +489,9 @@ static int _is_mirror_image_removable(ststatic int _remove_mirror_images (struct logical_volume *lv,uint32_t num_removed,struct dm_list *removable_pvs, -unsigned remove_log,unsigned collapse, +unsigned remove_log, +unsigned collapse, +const char *split,uint32_t *removed) {uint32_t m;
@@ -537,13 +542,30 @@ static int _remove_mirror_images(structfor (m = new_area_count; m < mirrored_seg->area_count; m++) {seg_lv (mirrored_seg, m)->status &= ~MIRROR_IMAGE ;lv_set_visible (seg_lv (mirrored_seg, m)); -if (!(lvl =dm_pool_alloc (lv->vg->cmd->mem,sizeof (*lvl)))) { + +if (split) { +remove_seg_from_segs_using_this_lv (seg_lv (mirrored_seg, m), + mirrored_seg); + + sub_lv =seg_lv (mirrored_seg, m); + sub_lv->name =dm_pool_strdup (lv->vg->cmd->mem, split); +if (!sub_lv->name) { +log_error ("Unable to rename newly split LV" ); +return 0 ; + } + +break ; + } + + lvl =dm_pool_alloc (lv->vg->cmd->mem,sizeof (*lvl)); +if (!lvl) {log_error ("lv_list alloc failed" );return 0 ; } lvl->lv =seg_lv (mirrored_seg, m);dm_list_add (&tmp_orphan_lvs, &lvl->list); -release_lv_segment_area (mirrored_seg, m, mirrored_seg->area_len); +release_lv_segment_area (mirrored_seg, m, + mirrored_seg->area_len); } mirrored_seg->area_count = new_area_count;
@@ -671,7 +693,7 @@ int remove_mirror_images(struct logical_ removed_once =first_seg (next_lv)->area_count -1 ;if (!_remove_mirror_images (next_lv, removed_once, - removable_pvs, remove_log,0 , &r)) + removable_pvs, remove_log,0 ,0 , &r)) return_0;if (r < removed_once) {
@@ -745,7 +767,7 @@ int collapse_mirrored_lv(struct logical_if (!_remove_mirror_images (mirror_seg->lv, mirror_seg->area_count -1 , -NULL ,1 ,1 ,NULL )) { +NULL ,1 ,1 ,0 ,NULL )) {log_error ("Failed to release mirror images" );return 0 ; }
@@ -866,7 +888,7 @@ int reconfigure_mirror_images(struct lv_init_mirror_in_sync (in_sync); r =_remove_mirror_images (mirrored_seg->lv, old_num_mirrors - num_mirrors, - removable_pvs, remove_log,0 ,NULL ); + removable_pvs, remove_log,0 ,0 ,NULL );if (!r)/* Unable to remove bad devices */ return 0 ;
@@ -1596,6 +1618,49 @@ int lv_add_mirrors(struct cmd_context *creturn 0 ; } +int lv_split_mirror_images (struct logical_volume *lv,const char *split_lv_name, +uint32_t split_count,struct dm_list *removable_pvs) +{ +int r; + +/* +* FIXME: Need ability to split off more than one mirror leg +* +* Right now, we only allow the user to split a single +* leg off at a time. In the future, we might allow a +* 4-way mirror to be split into 2 2-way mirrors, but +* not right now. +*/ +if (split_count !=1 ) { +log_error ("Unable to split more than one leg from a mirror." ); + return_0; + } + +/* Can't split a mirror that is not in-sync... unless force? */ +if (!_mirrored_lv_in_sync (lv)) { +log_error ("Unable to split mirror that is not in-sync." ); + return_0; + } + +/* +* FIXME: Generate default name when not supplied. +* +* If we were going to generate a default name, we would +* do it here. Better to wait for a decision on the form +* of the default name when '--track_deltas' (the ability +* to merge a split leg back in and only copy the changes) +* is being implemented. For now, we force the user to +* come up with a name for their LV. +*/ + r =_remove_mirror_images (lv, split_count, + removable_pvs,0 ,0 , + split_lv_name,NULL ); +if (!r) +return 0 ; + +return 1 ; +} +/* * Generic interface for removing mirror and/or mirror log. * 'mirror' is the number of mirrors to be removed.
man/lvconvert.8.in +35 -9
70 lines not on this page · raw message
tools/args.h +1 -0
@@ -50,6 +50,7 @@ arg(nosync_ARG, '\0', "nosync", NULL, 0) arg(resync_ARG, '\0', "resync", NULL, 0) arg(corelog_ARG, '\0', "corelog", NULL, 0) arg(mirrorlog_ARG, '\0', "mirrorlog", string_arg, 0) +arg(splitmirrors_ARG, '\0', "splitmirrors", int_arg, 0) arg(repair_ARG, '\0', "repair", NULL, 0) arg(use_policies_ARG, '\0', "use-policies", NULL, 0)arg (monitor_ARG,'\0' ,"monitor" , yes_no_arg,0 )
tools/commands.h +4 -2
@@ -96,6 +96,7 @@ xx(lvconvert,0 ,"lvconvert " "[-m|--mirrors Mirrors [{--mirrorlog {disk|core|redundant}|--corelog}]]\n" +"[--splitmirrors Images -n SplitLogicalVolumeName]\n" "\t[--repair [--use-policies]]\n" "\t[-R|--regionsize MirrorLogRegionSize]\n" "\t[--alloc AllocationPolicy]\n"
@@ -122,8 +123,9 @@ xx(lvconvert, "\tOriginalLogicalVolume[Path] SnapshotLogicalVolume[Path]\n", alloc_ARG, background_ARG, chunksize_ARG, corelog_ARG, interval_ARG, - mirrorlog_ARG, mirrors_ARG, noudevsync_ARG, regionsize_ARG, repair_ARG, - snapshot_ARG, test_ARG, use_policies_ARG, yes_ARG, force_ARG, zero_ARG) + splitmirrors_ARG, name_ARG, mirrorlog_ARG, mirrors_ARG, noudevsync_ARG, + regionsize_ARG, repair_ARG, snapshot_ARG, test_ARG, use_policies_ARG, + yes_ARG, force_ARG, zero_ARG) xx(lvcreate, "Create a logical volume",
tools/lvconvert.c +60 -8
118 lines not on this page · raw message
PATCH 1/1 LVM: add split capability
Hi,
Quoted 6 lines · Jonathan Brassow
It cleans up the comments and removes the error I made of adding code in the first patch that was being removed in the second. The 'splitmirror' argument is changed to 'splitmirrors'. (splitmirror will still work.) Man page language clean-up.
Fix bug introduce in the initialization of '
lp->alloc'.
(in lvconvert.c, line ~132)
tools/lvconvert.c static int _read_params(struct lvconvert · line 179
Quoted 4 lines
tools/lvconvert.c +1
-3- lp->alloc =ALLOC_INHERIT ; -if (arg_count (cmd, alloc_ARG)) - lp->alloc =arg_uint_value (cmd, alloc_ARG, lp->alloc); + lp->alloc =arg_uint_value (cmd, alloc_ARG,ALLOC_INHERIT );
I don't quite understand this bug (nor the fix; although the original code was a little weird). However, could you please post it separately and note what the problem was?
Also, changes like the following (that got interwoven with other changes, so copying it out here) make the review needlessly harder (since the reviewer has to check that the change is just superficial).
lib/metadata/mirror.c static int _remove_mirror_images(struct · line 561
Quoted 3 lines
lib/metadata/mirror.c +2
-1-if (!(lvl =dm_pool_alloc (lv->vg->cmd->mem,sizeof (*lvl)))) { + lvl =dm_pool_alloc (lv->vg->cmd->mem,sizeof (*lvl)); +if (!lvl) {
(The rest of the patch is in original order, with inline review comments.)
lib/metadata/mirror.c static int _is_mirror_image_removable(st · line 496
Quoted 9 lines
static int _remove_mirror_images(struct
logical_volume*lv,lib/metadata/mirror.c +3
-1uint32_t num_removed, struct dm_list *removable_pvs, - unsigned remove_log, unsigned collapse, + unsigned remove_log, + unsigned collapse, + const char *split, uint32_t *removed) {
It might be worth considering chopping up this function into a few smaller pieces, considering how big it has grown, and the huge parameter list. This may require some refactoring (I haven't checked very closely) and would be probably best done in a separate (followup, I guess) patch.
Quoted 16 lines
lib/metadata/mirror.c +10
-1uint32_t m;@@ -537,13 +542,30 @@ static int _remove_mirror_images(structfor (m = new_area_count; m < mirrored_seg->area_count; m++) {seg_lv (mirrored_seg, m)->status &= ~MIRROR_IMAGE ;lv_set_visible (seg_lv (mirrored_seg, m)); -if (!(lvl =dm_pool_alloc (lv->vg->cmd->mem,sizeof (*lvl)))) { + +if (split) { +remove_seg_from_segs_using_this_lv (seg_lv (mirrored_seg, m), + mirrored_seg); + + sub_lv =seg_lv (mirrored_seg, m); + sub_lv->name =dm_pool_strdup (lv->vg->cmd->mem, split); +if (!sub_lv->name) { +log_error ("Unable to rename newly split LV" ); +return 0 ;
lib/metadata/mirror.c static int _remove_mirror_images(struct · line 564
Quoted 10 lines
lib/metadata/mirror.c +7
-0+ } + +break ; + } + + lvl =dm_pool_alloc (lv->vg->cmd->mem,sizeof (*lvl)); +if (!lvl) {log_error ("lv_list alloc failed" );return 0 ; }
Looks reasonable.
lib/metadata/mirror.c static int _remove_mirror_images(struct · line 568
Quoted 5 lines
lib/metadata/mirror.c +2
-1lvl->lv =seg_lv (mirrored_seg, m);dm_list_add (&tmp_orphan_lvs, &lvl->list); -release_lv_segment_area (mirrored_seg, m, mirrored_seg->area_len); +release_lv_segment_area (mirrored_seg, m, + mirrored_seg->area_len);
Again, a superfluous change.
lib/metadata/mirror.c int collapse_mirrored_lv(struct logical_ · line 773
Quoted 7 lines
lib/metadata/mirror.c +1
-1if (!_remove_mirror_images (mirror_seg->lv, mirror_seg->area_count -1 , -NULL ,1 ,1 ,NULL )) { +NULL ,1 ,1 ,0 ,NULL )) {lib/metadata/mirror.c +0
-0log_error ("Failed to release mirror images" );return 0 ; }
This demonstrates the problem with many parameters in _remove_mirror_images:
NULL 1, 1, 0, NULL -- what exactly does that mean? Hard to tell, and even when you are looking at the prototype, you may need to resort to counting on fingers to figure which parameter is what. Also, the second-to-last 0 ought to be NULL, as far as I can tell (in other instances, left out from here, too).
Quoted 32 lines
lib/metadata/mirror.c +32
-0+int lv_split_mirror_images (struct logical_volume *lv,const char *split_lv_name, +uint32_t split_count,struct dm_list *removable_pvs) +{ +int r; + +/* +* FIXME: Need ability to split off more than one mirror leg +* +* Right now, we only allow the user to split a single +* leg off at a time. In the future, we might allow a +* 4-way mirror to be split into 2 2-way mirrors, but +* not right now. +*/ +if (split_count !=1 ) { +log_error ("Unable to split more than one leg from a mirror." ); + return_0; + } + +/* Can't split a mirror that is not in-sync... unless force? */ +if (!_mirrored_lv_in_sync (lv)) { +log_error ("Unable to split mirror that is not in-sync." ); + return_0; + } + +/* +* FIXME: Generate default name when not supplied. +* +* If we were going to generate a default name, we would +* do it here. Better to wait for a decision on the form +* of the default name when '--track_deltas' (the ability +* to merge a split leg back in and only copy the changes) +* is being implemented. For now, we force the user to
lib/metadata/mirror.c int lv_add_mirrors(struct cmd_context *c · line 1662
Quoted 10 lines
lib/metadata/mirror.c +10
-0+* come up with a name for their LV. +*/ + r =_remove_mirror_images (lv, split_count, + removable_pvs,0 ,0 , + split_lv_name,NULL ); +if (!r) +return 0 ; + +return 1 ; +}
OK. Basically a safe entrypoint for the _remove_mirror_images for the split case. It seems the "r" variable and the conditional return 0 could be dropped in favour of just saying "return _remove_mirror_images" (but that's cosmetics).
[snip documentation and bookkeeping]
Quoted 22 lines
Index:
LVM2/tools/lvconvert.c
===================================================================tools/lvconvert.c +4
-0@@ -16,12 +16,16 @@#include "polldaemon.h" #include "lv_alloc.h" +#define MIRROR_FLAG_KEEP_IMAGES 0x1 +#define MIRROR_FLAG_TRACK_DELTAS 0x2 +struct lvconvert_params {int snapshot;int zero;const char *origin;const char *lv_name; +const char *lv_split_name;const char *lv_name_full;const char *vg_name;int wait_completion;
tools/lvconvert.c struct lvconvert_params { · line 40
Quoted 7 lines
tools/lvconvert.c +2
-0@@ -30,8 +34,10 @@ struct lvconvert_params {uint32_t chunk_size;uint32_t region_size; +int track_deltas;uint32_t mirrors;sign_t mirrors_sign; +uint32_t mirror_flags;
Hmm, would it make more sense to use mirror_keep_images:1 and mirror_track_deltas:1 instead of doing the bit-mapping by hand? I think the code is less error-prone that way, since you need to be a lot less careful about operator priorities, masking and so on. We don't need to store this anywhere, so I think any advantages a single variable holding all the flags may have are moot here.
Quoted 41 lines
tools/lvconvert.c +40
-0+if (arg_count (cmd, splitmirrors_ARG) &&arg_count (cmd, mirrors_ARG)) { +log_error ("--mirrors (-m) and --splitmirrors are " +"mutually exclusive" ); +return 0 ; + } + +/* +* The '--splitmirrors n' argument is equivalent to '--mirrors -n' +* (note the minus sign), except that it signifies the additional +* intent to keep the mimage that is detached, rather than +* discarding it. +*/ +if (arg_count (cmd, splitmirrors_ARG)) { +if (!arg_count (cmd, name_ARG)) { +log_error ("The split off mirror image requires a name" ); +return 0 ; + } + + lp->lv_split_name =arg_value (cmd, name_ARG); +if (!apply_lvname_restrictions (lp->lv_split_name)) + return_0; + + lp->mirror_flags |=MIRROR_FLAG_KEEP_IMAGES ; +if (arg_sign_value (cmd, mirrors_ARG,0 ) ==SIGN_MINUS ) { +log_error ("Argument to --splitmirrors" +" cannot be negative" ); +return 0 ; + } + lp->mirrors =arg_uint_value (cmd, splitmirrors_ARG,0 ); + lp->mirrors_sign =SIGN_MINUS ; + }else if (arg_count (cmd, name_ARG)) { +log_error ("The 'name' argument is only valid" +" with --splitmirrors" ); +return 0 ; + } +if (arg_count (cmd, mirrors_ARG)) { +/* +* --splitmirrors has been chosen as the mechanism for +* specifying the intent of detaching and keeping a mimage +* versus an argument such as '--keep' being added here.
tools/lvconvert.c static int _read_params(struct lvconvert
Quoted 10 lines
tools/lvconvert.c +2
-3+*/ lp->mirrors =arg_uint_value (cmd, mirrors_ARG,0 ); lp->mirrors_sign =arg_sign_value (cmd, mirrors_ARG,0 ); } - lp->alloc =ALLOC_INHERIT ; -if (arg_count (cmd, alloc_ARG)) - lp->alloc =arg_uint_value (cmd, alloc_ARG, lp->alloc); + lp->alloc =arg_uint_value (cmd, alloc_ARG,ALLOC_INHERIT );
See above near the top of this mail.
[snip]
Quoted 11 lines
tools/lvconvert.c +4
-3@@ -681,10 +726,17 @@ static int _lvconvert_mirrors(struct cmd/* Reduce number of mirrors */ if (repair || lp->pv_count) remove_pvs = lp->pvh; -if (!lv_remove_mirrors (cmd, lv, existing_mirrors - lp->mirrors, - (!log_count || lp->mirrors ==1 ) ?1U :0U , - remove_pvs,0 )) + + if (lp->mirror_flags & MIRROR_FLAG_KEEP_IMAGES) { + if (!lv_split_mirror_images(lv, lp->lv_split_name, + existing_mirrors - lp->mirrors,
tools/lvconvert.c static int _lvconvert_mirrors(struct cmd · line 742
Quoted 10 lines
tools/lvconvert.c +6
-0+ remove_pvs)) +return 0 ; + }else if (!lv_remove_mirrors (cmd, lv, existing_mirrors - lp->mirrors, + (!log_count || lp->mirrors ==1 ) ?1U :0U , + remove_pvs,0 )) return_0; +if (lp->mirrors >1 && !_lv_update_log_type (cmd, lp, lv, log_count)) return_0;
OK.
Overall, the patch looks OK to me, although I'd probably give it another iteration to address the mentioned issues (I'd also say that the _remove_mirror_images refactor I have mentioned is, although quite desirable, not something that should hold this patch back.)
Yours,
Petr.
PATCH 1/1 LVM: add split capability
Quoted 14 lines · Petr Rockai
Hi,
Quoted 9 lines · Jonathan Brassow
It cleans up the comments and removes the error I made of adding code in the
first patch that was being removed in the second. The 'splitmirror' argument
is changed to 'splitmirrors'. (splitmirror will still work.) Man page
language clean-up.Fix bug introduce in the initialization of '
lp->alloc'.(in
lvconvert.c, line ~132)
Quoted 9 lines
tools/lvconvert.c static int _read_params(struct lvconvert · line 179
Quoted 4 lines
tools/lvconvert.c +1
-3- lp->alloc =ALLOC_INHERIT ; -if (arg_count (cmd, alloc_ARG)) - lp->alloc =arg_uint_value (cmd, alloc_ARG, lp->alloc); + lp->alloc =arg_uint_value (cmd, alloc_ARG,ALLOC_INHERIT );I don't quite understand this bug (nor the fix; although the original code was
a little weird). However, could you please post it separately and note what the
problem was?
Yes, I will shamefully admit that I got a little carried away with cosmetic changes when I should have isolated them to separate patches. There was no problem with the original code (which is why you don't see one), but with the change I made in a previous patch (I left the 'if' statement in place while moving the ALLOC_INHERIT - leaving the door open for uninitialized variable).
Quoted 8 lines
Also, changes like the following (that got interwoven with other changes, so
copying it out here) make the review needlessly harder (since the reviewer has
to check that the change is just superficial).lib/metadata/mirror.c static int _remove_mirror_images(struct · line 561
Quoted 3 lines
lib/metadata/mirror.c +2
-1-if (!(lvl =dm_pool_alloc (lv->vg->cmd->mem,sizeof (*lvl)))) { + lvl =dm_pool_alloc (lv->vg->cmd->mem,sizeof (*lvl)); +if (!lvl) {
Dido.
Quoted 19 lines
(The rest of the patch is in original order, with inline review comments.)
Quoted 9 lines
static int _remove_mirror_images(struct
logical_volume*lv,
uint32_tnum_removed, structdm_list*removable_pvs,lib/metadata/mirror.c +3
-1- unsigned remove_log, unsigned collapse, +unsigned remove_log, + unsigned collapse, + const char *split,uint32_t *removed){
It might be worth considering chopping up this function into a few smaller
pieces, considering how big it has grown, and the huge parameter list. This may
require some refactoring (I haven't checked very closely) and would be probably
best done in a separate (followup, I guess) patch.
YES! I haven't bothered to split this function up yet, but it is begging for this to happen. Split, remove, collapse all revolve around what happens in this function. I need to extract that and possibly create three different wrapping functions for the aforementioned. This becomes simply unavoidable with the addition of '--track_deltas'. I suspect that we need a different class of primitives (i.e. new base mirror functions) that will allow us to more flexibly construct our mirror operations - rather than constantly adding bloat to existing functions.
Quoted 27 lines
Quoted 15 lines
lib/metadata/mirror.c +10
-1@@ -537,13 +542,30 @@ static int _remove_mirror_images(structfor (m = new_area_count; m < mirrored_seg->area_count; m++) {seg_lv (mirrored_seg, m)->status &= ~MIRROR_IMAGE ;lv_set_visible (seg_lv (mirrored_seg, m)); -if (!(lvl =dm_pool_alloc (lv->vg->cmd->mem,sizeof (*lvl)))) { + +if (split) { +remove_seg_from_segs_using_this_lv (seg_lv (mirrored_seg, m), + mirrored_seg); + + sub_lv =seg_lv (mirrored_seg, m); + sub_lv->name =dm_pool_strdup (lv->vg->cmd->mem, split); +if (!sub_lv->name) { +log_error ("Unable to rename newly split LV" ); +return 0 ;lib/metadata/mirror.c static int _remove_mirror_images(struct · line 564
Quoted 10 lines
lib/metadata/mirror.c +7
-0+ } + +break ; + } + + lvl =dm_pool_alloc (lv->vg->cmd->mem,sizeof (*lvl)); +if (!lvl) {log_error ("lv_list alloc failed" );return 0 ; }Looks reasonable.
Quoted 6 lines
lib/metadata/mirror.c static int _remove_mirror_images(struct · line 568
Quoted 5 lines
lib/metadata/mirror.c +2
-1lvl->lv =seg_lv (mirrored_seg, m);dm_list_add (&tmp_orphan_lvs, &lvl->list); -release_lv_segment_area (mirrored_seg, m, mirrored_seg->area_len); +release_lv_segment_area (mirrored_seg, m, + mirrored_seg->area_len);Again, a superfluous change.
yup :(
Quoted 17 lines
Quoted 8 lines
lib/metadata/mirror.c +1
-1if (!_remove_mirror_images (mirror_seg->lv, mirror_seg->area_count -1 , -NULL ,1 ,1 ,NULL )) { +NULL ,1 ,1 ,0 ,NULL )) {log_error("Failed to release mirror images"); return 0; }This demonstrates the problem with many parameters in
_remove_mirror_images:
NULL 1, 1, 0, NULL -- what exactly does that mean? Hard to tell, and even when
you are looking at the prototype, you may need to resort to counting on fingers
to figure which parameter is what. Also, the second-to-last 0 ought to be NULL,
as far as I can tell (in other instances, left out from here, too).
Good catch (s/0/NULL/). and again, I couldn't agree with you more on the function splitting.
Quoted 78 lines
Quoted 34 lines
+int lv_split_mirror_images(struct
logical_volume*lv, const char*split_lv_name,lib/metadata/mirror.c +31
-0+ uint32_t split_count, struct dm_list *removable_pvs) +{ + int r; + +/* +* FIXME: Need ability to split off more than one mirror leg +* +* Right now, we only allow the user to split a single +* leg off at a time. In the future, we might allow a +* 4-way mirror to be split into 2 2-way mirrors, but +* not right now. +*/ +if (split_count !=1 ) { +log_error ("Unable to split more than one leg from a mirror." ); + return_0; + } + +/* Can't split a mirror that is not in-sync... unless force? */ +if (!_mirrored_lv_in_sync (lv)) { +log_error ("Unable to split mirror that is not in-sync." ); + return_0; + } + +/* +* FIXME: Generate default name when not supplied. +* +* If we were going to generate a default name, we would +* do it here. Better to wait for a decision on the form +* of the default name when '--track_deltas' (the ability +* to merge a split leg back in and only copy the changes) +* is being implemented. For now, we force the user to lib/metadata/mirror.c int lv_add_mirrors(struct cmd_context *c · line 1662
Quoted 10 lines
lib/metadata/mirror.c +10
-0+* come up with a name for their LV. +*/ + r =_remove_mirror_images (lv, split_count, + removable_pvs,0 ,0 , + split_lv_name,NULL ); +if (!r) +return 0 ; + +return 1 ; +}OK. Basically a safe entrypoint for the
_remove_mirror_imagesfor the split
case. It seems the "r" variable and the conditional return 0 could be dropped
in favour of just saying "return_remove_mirror_images" (but that's cosmetics).[snip documentation and bookkeeping]
Quoted 25 lines
Index:
LVM2/tools/lvconvert.c
===================================================================tools/lvconvert.c +4
-0@@ -16,12 +16,16 @@#include "polldaemon.h" #include "lv_alloc.h" +#define MIRROR_FLAG_KEEP_IMAGES 0x1 +#define MIRROR_FLAG_TRACK_DELTAS 0x2 +struct lvconvert_params {int snapshot;int zero;const char *origin;const char *lv_name; +const char *lv_split_name;const char *lv_name_full;const char *vg_name;int wait_completion;@@ -30,8 +34,10 @@ struct lvconvert_params {uint32_t chunk_size;uint32_t region_size;
Quoted 14 lines
tools/lvconvert.c struct lvconvert_params { · line 40
Quoted 4 lines
tools/lvconvert.c +2
-0+int track_deltas;uint32_t mirrors;sign_t mirrors_sign; +uint32_t mirror_flags;Hmm, would it make more sense to use mirror_keep_images:1 and mirror_track_deltas:1 instead of doing the bit-mapping by hand? I think the
code is less error-prone that way, since you need to be a lot less careful
about operator priorities, masking and so on. We don't need to store this
anywhere, so I think any advantages a single variable holding all the flags may
have are moot here.
you might be right... I suppose it depends on how many flags we accumulate. Right now, I only see the 2, so I think we could go either way.
Quoted 81 lines
Quoted 49 lines
tools/lvconvert.c +36
-0+if (arg_count (cmd, splitmirrors_ARG) &&arg_count (cmd, mirrors_ARG)) { +log_error ("--mirrors (-m) and --splitmirrors are " +"mutually exclusive" ); +return 0 ; + } + +/* +* The '--splitmirrors n' argument is equivalent to '--mirrors -n' +* (note the minus sign), except that it signifies the additional +* intent to keep the mimage that is detached, rather than +* discarding it. +*/ +if (arg_count (cmd, splitmirrors_ARG)) { +if (!arg_count (cmd, name_ARG)) { +log_error ("The split off mirror image requires a name" ); +return 0 ; + } + + lp->lv_split_name =arg_value (cmd, name_ARG); +if (!apply_lvname_restrictions (lp->lv_split_name)) + return_0; + + lp->mirror_flags |=MIRROR_FLAG_KEEP_IMAGES ; +if (arg_sign_value (cmd, mirrors_ARG,0 ) ==SIGN_MINUS ) { +log_error ("Argument to --splitmirrors" +" cannot be negative" ); +return 0 ; + } + lp->mirrors =arg_uint_value (cmd, splitmirrors_ARG,0 ); + lp->mirrors_sign =SIGN_MINUS ; + }else if (arg_count (cmd, name_ARG)) { +log_error ("The 'name' argument is only valid" +" with --splitmirrors" ); +return 0 ; + } +if (arg_count(cmd, mirrors_ARG)) {tools/lvconvert.c +5
-0+/* +* --splitmirrors has been chosen as the mechanism for +* specifying the intent of detaching and keeping a mimage +* versus an argument such as '--keep' being added here. +*/ lp->mirrors = arg_uint_value(cmd, mirrors_ARG, 0); lp->mirrors_sign = arg_sign_value(cmd, mirrors_ARG, 0); }tools/lvconvert.c static int _read_params(struct lvconvert · line 179
Quoted 4 lines
tools/lvconvert.c +1
-3- lp->alloc =ALLOC_INHERIT ; -if (arg_count (cmd, alloc_ARG)) - lp->alloc =arg_uint_value (cmd, alloc_ARG, lp->alloc); + lp->alloc =arg_uint_value (cmd, alloc_ARG,ALLOC_INHERIT );See above near the top of this mail.
[snip]
Quoted 21 lines
tools/lvconvert.c +10
-3@@ -681,10 +726,17 @@ static int _lvconvert_mirrors(struct cmd/* Reduce number of mirrors */ if (repair || lp->pv_count) remove_pvs = lp->pvh; -if (!lv_remove_mirrors (cmd, lv, existing_mirrors - lp->mirrors, - (!log_count || lp->mirrors ==1 ) ?1U :0U , - remove_pvs,0 )) + +if (lp->mirror_flags &MIRROR_FLAG_KEEP_IMAGES ) { +if (!lv_split_mirror_images (lv, lp->lv_split_name, + existing_mirrors - lp->mirrors, + remove_pvs)) +return 0 ; + }else if (!lv_remove_mirrors (cmd, lv, existing_mirrors - lp- >mirrors, + (!log_count || lp->mirrors ==1 ) ?1U :0U , + remove_pvs,0 )) return_0; +if (lp->mirrors >1 && !_lv_update_log_type (cmd, lp, lv, log_count))Quoted 1 line
return_0;OK.
Quoted 6 lines
Overall, the patch looks OK to me, although I'd probably give it another
iteration to address the mentioned issues (I'd also say that the_remove_mirror_imagesrefactor I have mentioned is, although quite desirable,
not something that should hold this patch back.)
Thank-you for your review. I'll likely respin - unless it has already been pulled in. I'll definitely address the s/0/NULL/ issue. _remove_mirror_images will be a prereq for the upcoming '-- track_deltas' patches.
brassow
PATCH 1/1 LVM: add split capability
In reply to Jonathan BrassowQuoted 1 line · Jon Brassow
Patch name: lvm-add-split-capability.patch
Patch doesn't apply/compile - log_count undefined, and lv_split_mirror_images not exported.
Please fix and repost.
Alasdair
PATCH 1/1 LVM: add split capability
Quoted 8 lines · Alasdair G Kergon
Quoted 1 line · Jon Brassow
Patch name: lvm-add-split-capability.patch
Patch doesn't apply/compile -
log_countundefined, andlv_split_mirror_images
not exported.Please fix and repost.
Indeed, this is because this patch was to come after the 'redundant mirror log' patch series.
I will fix this patch to put it up front and address Petr's concerns.
brassow