master - pvmove: Enable all-or-nothing (atomic) pvmoves
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5ebff6cc9f631b7409d99b72fa0b39ccec30bf1f Commit: 5ebff6cc9f631b7409d99b72fa0b39ccec30bf1f Parent: b16f5633ab199dedfd25f08562f686a6fb4aba9d Author: Jonathan Brassow <[email protected]> AuthorDate: Tue Jun 17 22:59:36 2014 -0500 Committer: Jonathan Brassow <[email protected]> CommitterDate: Tue Jun 17 22:59:36 2014 -0500
pvmove: Enable all-or-nothing (atomic) pvmoves
pvmove can be used to move single LVs by name or multiple LVs that lie within the specified PV range (e.g. /dev/sdb1:0-1000). When moving more than one LV, the portions of those LVs that are in the range to be moved are added to a new temporary pvmove LV. The LVs then point to the range in the pvmove LV, rather than the PV range.
Example 1:
We have two LVs in this example. After they were created, the first LV was grown, yeilding two segments in LV1. So, there are two LVs with a total of three segments. Before pvmove: --------- --------- --------- | LV1s0 | | LV2s0 | | LV1s1 | --------- --------- --------- | | | ------------------------------------- PV | 000 - 255 | 256 - 511 | 512 - 767 | ------------------------------------- After pvmove inserts the temporary pvmove LV: --------- --------- --------- | LV1s0 | | LV2s0 | | LV1s1 | --------- --------- --------- | | | ------------------------------------- pvmove0 | seg 0 | seg 1 | seg 2 | ------------------------------------- | | | ------------------------------------- PV | 000 - 255 | 256 - 511 | 512 - 767 | ------------------------------------- Each of the affected LV segments now point to a range of blocks in the pvmove LV, which purposefully corresponds to the segments moved from the original LVs into the temporary pvmove LV.
The current implementation goes on from here to mirror the temporary pvmove LV by segment. Further, as the pvmove LV is activated, only one of its segments is actually mirrored (i.e. "moving") at a time. The rest are either complete or not addressed yet. If the pvmove is aborted, those segments that are completed will remain on the destination and those that are not yet addressed or in the process of moving will stay on the source PV. Thus, it is possible to have a partially completed move - some LVs (or certain segments of LVs) on the source PV and some on the destination.
Example 2:
What 'example 1' might look if it was half-way through the move. --------- --------- --------- | LV1s0 | | LV2s0 | | LV1s1 | --------- --------- --------- | | | ------------------------------------- pvmove0 | seg 0 | seg 1 | seg 2 | ------------------------------------- | | | | ------------------------- source PV | | 256 - 511 | 512 - 767 | | ------------------------- | || ------------------------- dest PV | 000 - 255 | 256 - 511 | -------------------------
This update allows the user to specify that they would like the pvmove mirror created "by LV" rather than "by segment". That is, the pvmove LV becomes an image in an encapsulating mirror along with the allocated copy image.
Example 3:
A pvmove that is performed "by LV" rather than "by segment".
--------- ---------
| LV1s0 | | LV2s0 |
--------- ---------
| |
-------------------------
pvmove0 | * LV-level mirror * |
-------------------------
/ \
pvmove_mimage0 / pvmove_mimage1
------------------------- -------------------------
| seg 0 | seg 1 | | seg 0 | seg 1 |
------------------------- -------------------------
| | | |
------------------------- -------------------------
| 000 - 255 | 256 - 511 | | 000 - 255 | 256 - 511 |
------------------------- -------------------------
source PV dest PVThe thing that differentiates a pvmove done in this way and a simple "up-convert" from linear to mirror is the preservation of the distinct segments. A normal up-convert would simply allocate the necessary space with no regard for segment boundaries. The pvmove operation must preserve the segments because they are the critical boundary between the segments of the LVs being moved. So, when the pvmove copy image is allocated, all corresponding segments must be allocated. The code that merges ajoining segments that are part of the same LV when the metadata is written must also be avoided in this case. This method of mirroring is unique enough to warrant its own definitional macro, MIRROR_BY_SEGMENTED_LV. This joins the two existing macros: MIRROR_BY_SEG (for original pvmove) and MIRROR_BY_LV (for user created mirrors).
The advantages of performing pvmove in this way is that all of the LVs affected can be moved together. It is an all-or-nothing approach that leaves all LV segments on the source PV if the move is aborted. Additionally, a mirror log can be used (in the future) to provide tracking of progress; allowing the copy to continue where it left off in the event there is a deactivation.
--- WHATS_NEW | 1 + lib/metadata/lv_alloc.h | 3 + lib/metadata/lv_manip.c | 108 ++++++++++++++++++++++++++++++++++- lib/metadata/merge.c | 7 ++- lib/metadata/metadata-exported.h | 4 + lib/metadata/mirror.c | 66 +++++++++++++++++---- man/pvmove.8.in | 34 ++++++++++- test/shell/pvmove-background.sh | 7 ++- test/shell/pvmove-basic.sh | 78 +++++++++++++++---------- test/shell/pvmove-cache-segtypes.sh | 24 +++++--- test/shell/pvmove-raid-segtypes.sh | 17 ++++-- test/shell/pvmove-restart.sh | 8 ++- test/shell/pvmove-thin-segtypes.sh | 13 +++- tools/args.h | 1 + tools/commands.h | 3 +- tools/pvmove.c | 45 ++++++++++++++- 16 files changed, 344 insertions(+), 75 deletions(-)
WHATS_NEW +1 -0
@@ -1,5 +1,6 @@ Version 2.02.107 - ================================== + Add support for all-or-nothing (atomic) pvmove. Automatically add snapshot metadata size for -l %ORIGIN calculation. When converting RAID origin to cache LV, properly rename sub-LVs. Use RemoveOnStop for lvm2-lvmetad.socket systemd unit.
lib/metadata/lv_alloc.h +3 -0
@@ -68,6 +68,9 @@ int lv_add_segment(struct alloc_handle *ah,int lv_add_mirror_areas (struct alloc_handle *ah,struct logical_volume *lv,uint32_t le,uint32_t region_size); +int lv_add_segmented_mirror_image (struct alloc_handle *ah, +struct logical_volume *lv,uint32_t le, +uint32_t region_size); int lv_add_mirror_lvs(struct logical_volume *lv, struct logical_volume **sub_lvs, uint32_t num_extra_areas,
lib/metadata/lv_manip.c +107 -1
120 lines not on this page · raw message
lib/metadata/merge.c +6 -1
@@ -38,11 +38,16 @@ static int _merge(struct lv_segment *first, struct lv_segment *second)int lv_merge_segments (struct logical_volume *lv) {struct dm_list *segh, *t; -struct lv_segment *current, *prev =NULL ; +struct lv_segment *seg, *current, *prev =NULL ;if (lv->status &LOCKED || lv->status &PVMOVE )return 1 ; +if ((lv->status &MIRROR_IMAGE ) && + (seg =get_only_segment_using_this_lv (lv)) && + (seg->lv->status &LOCKED || seg->lv->status &PVMOVE )) +return 1 ; + dm_list_iterate_safe(segh, t, &lv->segments) { current = dm_list_item(segh, struct lv_segment);
lib/metadata/metadata-exported.h +4 -0
@@ -133,6 +133,10 @@/* Mirror conversion type flags */ #define MIRROR_BY_SEG 0x00000001U/* segment-by-segment mirror */ #define MIRROR_BY_LV 0x00000002U/* mirror using whole mimage LVs */ +#define MIRROR_BY_SEGMENTED_LV 0x00000004U/* mirror using whole mimage +* LVs, but preserve the +* segment layout templated by +* the primary mimage */ #define MIRROR_SKIP_INIT_SYNC 0x00000010U/* skip initial sync */ /* vg_read and vg_read_for_update flags */
lib/metadata/mirror.c +53 -13
110 lines not on this page · raw message
man/pvmove.8.in +31 -3
@@ -6,6 +6,7 @@ pvmove \(em move physical extents .RB [ \-\-abort ] .RB [ \-\-alloc .IR AllocationPolicy ] +.RB [ \-\-atomic ] .RB [ \-b | \-\-background ] .RB [ \-\-commandprofile .IR ProfileName ]
@@ -35,8 +36,11 @@ is specified, the normal allocation rules for the Volume Group are used. If pvmove gets interrupted for any reason (e.g. the machine crashes) then run pvmove again without any PhysicalVolume arguments to restart any moves that were in progress from the last checkpoint. -Alternatively use \fBpvmove \-\-abort\fP at any time to abort them -at the last checkpoint. +Alternatively use \fBpvmove \-\-abort\fP at any time to abort. The +resulting location of logical volumes after an abort is issued depends +on whether the +.B \-\-atomic +option was used when starting the pvmove process. You can run more than one pvmove at once provided they are moving data off different SourcePhysicalVolumes, but additional pvmoves will ignore
@@ -77,11 +81,35 @@ is updated so that the Logical Volumes reflect the new data locations. Note that this new process cannot support the original LVM1 type of on-disk metadata. Metadata can be converted using \fBvgconvert\fP(8). +If the +.B \-\-atomic +option is used, a slightly different approach is used for the move. Again, +a temporary 'pvmove' logical volume is created to store the details of all +the data movements required. This temporary LV contains all the segments of +the various LVs that need to be moved. However this time, an identical +logical volume is allocated that contains the same number of segments and +a mirror is created to copy the contents from the first temporary LV to the +second. When a complete copy is accomplished, the temporary logical volumes +are removed, leaving behind the segments on the destination physical volume. +If an abort is issued during the move, all logical volumes being moved will +remain on the source physical volume. + .SH OPTIONS See \fBlvm\fP(8) for common options. .TP .B \-\-abort -Abort any moves in progress. +Abort any moves in progress. If the +.B \-\-atomic +option was used to start the pvmove, all logical volumes will remain on +the source physical volume. Otherwise, those segments that have completed +the move will stay on the destination physical volume, while those that +have not will remain on the source physical volume. +.TP +.B \-\-atomic +Make the entire operation atomic. That is, ensure that all affected logical +volumes are moved to the destination physical volume together; unless the move +has been aborted. If the move has been aborted, all logical volumes will +remain on the source physical volume. .TP .B \-\-noudevsync Disable udev synchronisation. The
test/shell/pvmove-background.sh +6 -1
@@ -15,10 +15,15 @@ aux prepare_vg 3 +for mode in "--atomic" "" +do lvcreate -aey -l1 -n $lv1 $vg "$dev1" lvs -o +devices | grep $dev1 -pvmove -i 1 -b "$dev1" "$dev2" +pvmove $mode -i 1 -b "$dev1" "$dev2" sleep 5 # arbitrary... lvs -o +devices | not grep "pvmove" lvs -o +devices | grep "$dev2" + +lvremove -ff $vg +done
test/shell/pvmove-basic.sh +46 -32
260 lines not on this page · raw message
test/shell/pvmove-cache-segtypes.sh +14 -10
@@ -29,6 +29,8 @@ aux have_raid 1 4 2 || skip aux prepare_vg 5 80 +for mode in "--atomic" "" +do # Each of the following tests does: # 1) Create two LVs - one linear and one other segment type # The two LVs will share a PV.
@@ -42,14 +44,14 @@ lvcreate --type cache-pool -n ${lv1}_pool -l 4 $vg "$dev1" check lv_tree_on $vg ${lv1}_foo "$dev1" check lv_tree_on $vg ${lv1}_pool "$dev1" -pvmove "$dev1" "$dev5" 2>&1 | tee out +pvmove $mode "$dev1" "$dev5" 2>&1 | tee out grep "Skipping cache-pool LV, ${lv1}_pool" out grep "Skipping cache-related LV, ${lv1}_pool_cmeta" out grep "Skipping cache-related LV, ${lv1}_pool_cdata" out check lv_tree_on $vg ${lv1}_foo "$dev5" not check lv_tree_on $vg ${lv1}_pool "$dev5" -#pvmove -n ${lv1}_pool "$dev5" "$dev4" +#pvmove $mode -n ${lv1}_pool "$dev5" "$dev4" #check lv_tree_on $vg ${lv1}_pool "$dev4" #check lv_tree_on $vg ${lv1}_foo "$dev5"
@@ -66,7 +68,7 @@ check lv_tree_on $vg ${lv1}_pool "$dev5" check lv_tree_on $vg ${lv1} "$dev1" aux mkdev_md5sum $vg $lv1 -pvmove "$dev1" "$dev3" 2>&1 | tee out +pvmove $mode "$dev1" "$dev3" 2>&1 | tee out grep "Skipping cache LV, ${lv1}" out check lv_tree_on $vg ${lv1}_foo "$dev3" #check lv_tree_on $vg ${lv1}_pool "$dev5"
@@ -74,7 +76,7 @@ lvs -a -o name,attr,devices $vg not check lv_tree_on $vg ${lv1} "$dev3" #check dev_md5sum $vg $lv1 -#pvmove -n $lv1 "$dev3" "$dev1" +#pvmove $mode -n $lv1 "$dev3" "$dev1" #check lv_tree_on $vg ${lv1}_foo "$dev3" #check lv_tree_on $vg ${lv1}_pool "$dev5" #check lv_tree_on $vg ${lv1} "$dev1"
@@ -91,14 +93,14 @@ check lv_tree_on $vg ${lv1} "$dev1" "$dev2" check lv_tree_on $vg ${lv1}_pool "$dev5" aux mkdev_md5sum $vg $lv1 -pvmove "$dev1" "$dev3" 2>&1 | tee out +pvmove $mode "$dev1" "$dev3" 2>&1 | tee out grep "Skipping cache LV, ${lv1}" out check lv_tree_on $vg ${lv1}_foo "$dev3" not check lv_tree_on $vg ${lv1} "$dev2" "$dev3" #check lv_tree_on $vg ${lv1}_pool "$dev5" #check dev_md5sum $vg $lv1 -- THIS IS WHERE THINGS FAIL IF PVMOVE NOT DISALLOWED -#pvmove -n $lv1 "$dev3" "$dev1" +#pvmove $mode -n $lv1 "$dev3" "$dev1" #check lv_tree_on $vg ${lv1}_foo "$dev3" #check lv_tree_on $vg ${lv1} "$dev1" "$dev2" #check lv_tree_on $vg ${lv1}_pool "$dev5"
@@ -120,7 +122,7 @@ check lv_tree_on $vg ${lv1} "$dev5" aux mkdev_md5sum $vg $lv1 # This will move ${lv1}_foo and the cache-pool data & meta # LVs, both of which contain a RAID1 _rimage & _rmeta LV - 5 total LVs -pvmove "$dev1" "$dev3" 2>&1 | tee out +pvmove $mode "$dev1" "$dev3" 2>&1 | tee out grep "Skipping cache-pool LV, ${lv1}_pool" out grep "Skipping cache-related LV, ${lv1}_pool_cmeta" out grep "Skipping cache-related LV, ${lv1}_pool_cdata" out
@@ -129,7 +131,7 @@ not check lv_tree_on $vg ${lv1}_pool "$dev2" "$dev3" #check lv_tree_on $vg ${lv1} "$dev5" #check dev_md5sum $vg $lv1 -#pvmove -n ${lv1}_pool "$dev3" "$dev1" +#pvmove $mode -n ${lv1}_pool "$dev3" "$dev1" #check lv_tree_on $vg ${lv1}_foo "$dev3" #check lv_tree_on $vg ${lv1}_pool "$dev1" "$dev2" #check lv_tree_on $vg ${lv1} "$dev5"
@@ -161,17 +163,19 @@ check lv_tree_on $vg thinpool "$dev1" "$dev3" "$dev4" aux mkdev_md5sum $vg thin_lv lvs -a -o name,attr,devices $vg # Should move ${lv1}_foo and thinpool_tmeta from dev1 to dev5 -pvmove "$dev1" "$dev5" 2>&1 | tee out +pvmove $mode "$dev1" "$dev5" 2>&1 | tee out lvs -a -o name,attr,devices $vg check lv_tree_on $vg ${lv1}_foo "$dev5" not check lv_tree_on $vg cachepool "$dev5" "$dev2" check lv_tree_on $vg thinpool "$dev3" "$dev4" "$dev5" # Move non-cache tmeta #check dev_md5sum $vg/thin_lv -#pvmove -n $vg/cachepool "$dev5" "$dev1" +#pvmove $mode -n $vg/cachepool "$dev5" "$dev1" #check lv_tree_on $vg ${lv1}_foo "$dev5" #check lv_tree_on $vg $vg/cachepool "$dev1" "$dev2" #check lv_tree_on $vg $vg/thinpool "$dev3" "$dev4" #check dev_md5sum $vg/thin_lv lvremove -ff $vg + +done
test/shell/pvmove-raid-segtypes.sh +11 -6
@@ -21,6 +21,8 @@ aux have_raid 1 3 5 || skip aux prepare_pvs 5 20 vgcreate -c n -s 128k $vg $(cat DEVICES) +for mode in "--atomic" "" +do # Each of the following tests does: # 1) Create two LVs - one linear and one other segment type # The two LVs will share a PV.
@@ -33,11 +35,11 @@ lvcreate -l 2 --type raid1 -m 1 -n $lv1 $vg "$dev1" "$dev2" check lv_tree_on $vg ${lv1}_foo "$dev1" check lv_tree_on $vg $lv1 "$dev1" "$dev2" aux mkdev_md5sum $vg $lv1 -pvmove "$dev1" "$dev5" +pvmove $mode "$dev1" "$dev5" check lv_tree_on $vg ${lv1}_foo "$dev5" check lv_tree_on $vg $lv1 "$dev2" "$dev5" check dev_md5sum $vg $lv1 -pvmove -n $lv1 "$dev5" "$dev4" +pvmove $mode -n $lv1 "$dev5" "$dev4" check lv_tree_on $vg $lv1 "$dev2" "$dev4" check lv_tree_on $vg ${lv1}_foo "$dev5" check dev_md5sum $vg $lv1
@@ -50,11 +52,11 @@ lvcreate -l 4 --type raid10 -i 2 -m 1 -n $lv1 $vg \ check lv_tree_on $vg ${lv1}_foo "$dev1" check lv_tree_on $vg $lv1 "$dev1" "$dev2" "$dev3" "$dev4" aux mkdev_md5sum $vg $lv1 -pvmove "$dev1" "$dev5" +pvmove $mode "$dev1" "$dev5" check lv_tree_on $vg ${lv1}_foo "$dev5" check lv_tree_on $vg $lv1 "$dev2" "$dev3" "$dev4" "$dev5" check dev_md5sum $vg $lv1 -pvmove -n $lv1 "$dev5" "$dev1" +pvmove $mode -n $lv1 "$dev5" "$dev1" check lv_tree_on $vg $lv1 "$dev1" "$dev2" "$dev3" "$dev4" check lv_tree_on $vg ${lv1}_foo "$dev5" check dev_md5sum $vg $lv1
@@ -67,13 +69,16 @@ lvcreate -l 4 --type raid5 -i 2 -n $lv1 $vg \ check lv_tree_on $vg ${lv1}_foo "$dev1" check lv_tree_on $vg $lv1 "$dev1" "$dev2" "$dev3" aux mkdev_md5sum $vg $lv1 -pvmove "$dev1" "$dev5" +pvmove $mode "$dev1" "$dev5" check lv_tree_on $vg ${lv1}_foo "$dev5" check lv_tree_on $vg $lv1 "$dev2" "$dev3" "$dev5" check dev_md5sum $vg $lv1 -pvmove -n $lv1 "$dev5" "$dev4" +pvmove $mode -n $lv1 "$dev5" "$dev4" check lv_tree_on $vg $lv1 "$dev2" "$dev3" "$dev4" check lv_tree_on $vg ${lv1}_foo "$dev5" check dev_md5sum $vg $lv1 +lvremove -ff $vg +done + vgremove -ff $vg
test/shell/pvmove-restart.sh +7 -1
@@ -17,6 +17,9 @@ aux prepare_pvs 3 60 vgcreate -s 128k $vg "$dev1" "$dev2" "$dev3" +for mode in "--atomic" "" +do + # Create multisegment LV lvcreate -an -Zn -l5 -n $lv1 $vg "$dev1" lvextend -l+10 $vg/$lv1 "$dev2"
@@ -37,7 +40,7 @@ wait # Simulate reboot - forcibly remove related devices dmsetup remove $vg-$lv1 -dmsetup remove $vg-pvmove0 +dmsetup remove /dev/mapper/$vg-pvmove0* # Check we really have pvmove volume check lv_attr_bit type $vg/pvmove0 "p"
@@ -81,4 +84,7 @@ aux delay_dev "$dev3" lvs -a -o+devices $vg +lvremove -ff $vg +done + vgremove -ff $vg
test/shell/pvmove-thin-segtypes.sh +9 -4
@@ -22,6 +22,9 @@ aux have_raid 1 3 5 || skip aux prepare_pvs 5 20 vgcreate -c n -s 128k $vg $(cat DEVICES) +for mode in "--atomic" "" +do + # Each of the following tests does: # 1) Create two LVs - one linear and one other segment type # The two LVs will share a PV.
@@ -35,11 +38,11 @@ lvcreate -T $vg/${lv1}_pool -l 4 -V 8 -n $lv1 "$dev1" check lv_tree_on $vg ${lv1}_foo "$dev1" check lv_tree_on $vg $lv1 "$dev1" aux mkdev_md5sum $vg $lv1 -pvmove "$dev1" "$dev5" +pvmove "$dev1" "$dev5" $mode check lv_tree_on $vg ${lv1}_foo "$dev5" check lv_tree_on $vg $lv1 "$dev5" check dev_md5sum $vg $lv1 -pvmove -n $lv1 "$dev5" "$dev4" +pvmove -n $lv1 "$dev5" "$dev4" $mode check lv_tree_on $vg $lv1 "$dev4" check lv_tree_on $vg ${lv1}_foo "$dev5" check dev_md5sum $vg $lv1
@@ -55,14 +58,16 @@ lvcreate -T $vg/${lv1}_raid1_pool -V 8 -n $lv1 check lv_tree_on $vg ${lv1}_foo "$dev1" check lv_tree_on $vg $lv1 "$dev1" "$dev2" aux mkdev_md5sum $vg $lv1 -pvmove "$dev1" "$dev5" +pvmove "$dev1" "$dev5" $mode check lv_tree_on $vg ${lv1}_foo "$dev5" check lv_tree_on $vg $lv1 "$dev2" "$dev5" check dev_md5sum $vg $lv1 -pvmove -n $lv1 "$dev5" "$dev4" +pvmove -n $lv1 "$dev5" "$dev4" $mode check lv_tree_on $vg $lv1 "$dev2" "$dev4" check lv_tree_on $vg ${lv1}_foo "$dev5" check dev_md5sum $vg $lv1 lvremove -ff $vg +done + vgremove -ff $vg
tools/args.h +1 -0
@@ -17,6 +17,7 @@* Put all long args that don't have a corresponding short option first. */ /* *INDENT-OFF* */ +arg(atomic_ARG, '\0', "atomic", NULL, 0) arg(version_ARG, '\0', "version", NULL, 0) arg(physicalvolumesize_ARG, '\0', "setphysicalvolumesize", size_mb_arg, 0)arg (ignorelockingfailure_ARG,'\0' ,"ignorelockingfailure" ,NULL ,0 )
tools/commands.h +2 -1
@@ -764,6 +764,7 @@ xx(pvmove,0 ,"pvmove " "\n" "\t[--abort]\n" +"\t[--atomic]\n" "\t[-A|--autobackup {y|n}]\n" "\t[--alloc AllocationPolicy]\n" "\t[-b|--background]\n"
@@ -780,7 +781,7 @@ xx(pvmove,"\tSourcePhysicalVolume[:PhysicalExtent[-PhysicalExtent]...]}\n" "\t[DestinationPhysicalVolume[:PhysicalExtent[-PhysicalExtent]...]...]\n" , - abort_ARG, alloc_ARG, autobackup_ARG, background_ARG, + abort_ARG, atomic_ARG, alloc_ARG, autobackup_ARG, background_ARG, interval_ARG, name_ARG, noudevsync_ARG, test_ARG) xx(pvremove,
tools/pvmove.c +43 -2
65 lines not on this page · raw message