lvm2 support for snapshot-merge
cover lvm2 support for snapshot-merge
This patchset adds libdm and lvm support for snapshot-merge target. It also adds --merge flag to lvconvert; lvconvert is the command that one will use to merge a snapshot in its origin device. The lvconvert manpage has been updated accordingly.
For more details please see the individual patch headers.
The LVM2 snapshot-merge quilt tree has been maintained here:
http://people.redhat.com/msnitzer/patches/snapshot-merge/lvm2/LVM2-2.02.55/
* Aside from snapshot-merge specific testing, these patches have survived 75+ iterations of lvm2's testsuite without any failures. The test kernel was 2.6.32-rc8 and lvm2 was 2.0.55 (with udev_sync enabled and dmeventd disabled).
Mike Snitzer (5):
use snapshot metadata usage to determine if snapshot is empty Add support for "snapshot-merge" target. device-mapper-merging-store-needs-cow-suffix lvm-merge-onactivate
lvm-merge-man-lvconvert
Mikulas Patocka (10):
lvm-merge-metadata
device-mapper-merge-activation
lvm-merge-lvconvert
lvm-merge-check-for-mounted-lv
lvm-merge-reporting
lvm-merge-origin-report-progress
lvm-merge-background-poll
lvm-merge-background-poll-on-lvvgchange
lvm-merge-reload-if-stopped-merging
lvm-merge-reload-proper-order
lib/activate/activate.c | 2 +- lib/activate/dev_manager.c | 94 +++++++++++++++-- lib/format_text/flags.c | 1 + lib/metadata/lv_manip.c | 31 ++++-- lib/metadata/metadata-exported.h | 6 +- lib/metadata/snapshot_manip.c | 13 ++- lib/report/report.c | 31 ++++-- lib/snapshot/snapshot.c | 41 +++++--- libdm/.exported_symbols | 1 + libdm/libdevmapper.h | 6 + libdm/libdm-deptree.c | 72 +++++++++++-- man/lvconvert.8.in | 29 +++++- tools/args.h | 1 + tools/commands.h | 11 ++- tools/lvconvert.c | 214 ++++++++++++++++++++++++++++++++++++-- tools/toollib.c | 14 +++- tools/vgchange.c | 3 +- 17 files changed, 505 insertions(+), 65 deletions(-)
PATCH 1/15 use snapshot metadata usage to determine if snapshot is empty
Future dm-snapshot will append metadata sectors used to a snapshot's status. This patch allows LVM2 to accurately determine if the snapshot store is empty. Knowing when a snapshot store is empty is important in the context of snapshot-merge (means merge is complete).
--- lib/snapshot/snapshot.c | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
lib/snapshot/snapshot.c +9 -7
@@ -95,15 +95,17 @@ static int _snap_target_percent(void **target_state __attribute((unused)), char *params, uint64_t *total_numerator, uint64_t *total_denominator) { - uint64_t numerator, denominator; + uint64_t total_sectors, sectors_allocated, metadata_sectors = 0; +int r; -if (sscanf (params,"%" PRIu64"/%" PRIu64, - &numerator, &denominator) ==2 ) { - *total_numerator += numerator; - *total_denominator += denominator; -if (!numerator) + r =sscanf (params,"%" PRIu64"/%" PRIu64" %" PRIu64, + §ors_allocated, &total_sectors, &metadata_sectors); +if (r ==2 || r ==3 ) { + *total_numerator += sectors_allocated; + *total_denominator += total_sectors; +if (sectors_allocated == metadata_sectors) *percent_range =PERCENT_0 ; -else if (numerator == denominator) +else if (sectors_allocated == total_sectors) *percent_range =PERCENT_100 ;else *percent_range =PERCENT_0_TO_100 ;
Signature · 1 line
1.6.5.2
PATCH 2/15 lvm-merge-metadata
In reply to Mike SnitzerFrom: Mikulas Patocka <[email protected]>
Add 'SNAPSHOT_MERGE' lv_segment 'status' flag.
Make 'merging_snapshot' pointer that points from the origin to the segment that represents the merging snapshot.
Import/export 'merging_store' metadata.
Do not allow creating snapshots while another snapshot is merging. Snapshot created in this state would certainly contain invalid data.
--- lib/format_text/flags.c | 1 + lib/metadata/lv_manip.c | 6 ++++++ lib/metadata/metadata-exported.h | 6 +++++- lib/metadata/snapshot_manip.c | 13 +++++++++++-- lib/snapshot/snapshot.c | 15 +++++++++++---- 5 files changed, 34 insertions(+), 7 deletions(-)
lib/format_text/flags.c +1 -0
@@ -61,6 +61,7 @@ static struct flag _lv_flags[] = { {MIRRORED, NULL, 0}, {VIRTUAL, NULL, 0}, {SNAPSHOT, NULL, 0}, + {SNAPSHOT_MERGE, NULL, 0}, {ACTIVATE_EXCL, NULL, 0}, {CONVERTING, NULL, 0}, {PARTIAL_LV, NULL, 0},
lib/metadata/lv_manip.c +6 -0
@@ -1873,6 +1873,7 @@ struct logical_volume *alloc_lv(struct dm_pool *mem) } lv->snapshot =NULL ; + lv->merging_snapshot =NULL ;dm_list_init (&lv->snapshot_segs);dm_list_init (&lv->segments);dm_list_init (&lv->tags);
@@ -2937,6 +2938,11 @@ int lv_create_single(struct volume_group *vg, "supported yet");return 0 ; } +if (org->merging_snapshot) { +log_error ("Snapshots while another snapshot " +"is merging is not supported" ); +return 0 ; + }if ((org->status &MIRROR_IMAGE ) || (org->status &MIRROR_LOG )) { log_error("Snapshots of mirror %ss "
lib/metadata/metadata-exported.h +5 -1
@@ -60,6 +60,7 @@//#define ACTIVATE_EXCL 0x00100000U /* LV - internal use only */ //#define PRECOMMITTED 0x00200000U /* VG - internal use only */ #define CONVERTING 0x00400000U/* LV */ +#define SNAPSHOT_MERGE 0x00800000U/* SEG */ #define MISSING_PV 0x00800000U/* PV */ #define PARTIAL_LV 0x01000000U/* LV - derived flag, not
@@ -328,6 +329,9 @@ struct logical_volume {struct dm_list snapshot_segs;struct lv_segment *snapshot; +/* A snapshot that is merging into this origin */ +struct lv_segment *merging_snapshot; +struct dm_list segments;struct dm_list tags;struct dm_list segs_using_this_lv;
@@ -622,7 +626,7 @@ struct lv_segment *find_cow(const struct logical_volume *lv);struct logical_volume *origin_from_cow (const struct logical_volume *lv);void init_snapshot_seg (struct lv_segment *seg,struct logical_volume *origin, -struct logical_volume *cow,uint32_t chunk_size); +struct logical_volume *cow,uint32_t chunk_size,int merge); int vg_add_snapshot(struct logical_volume *origin, struct logical_volume *cow, union lvid *lvid, uint32_t extent_count,
lib/metadata/snapshot_manip.c +11 -2
@@ -37,6 +37,9 @@ int lv_is_visible(const struct logical_volume *lv)if (lv_is_virtual_origin (origin_from_cow (lv)))return 1 ; +if (find_cow (lv)->status &SNAPSHOT_MERGE ) +return 0 ; +return lv_is_visible (origin_from_cow (lv)); }
@@ -62,7 +65,7 @@ struct logical_volume *origin_from_cow(const struct logical_volume *lv) }void init_snapshot_seg (struct lv_segment *seg,struct logical_volume *origin, -struct logical_volume *cow,uint32_t chunk_size) +struct logical_volume *cow,uint32_t chunk_size,int merge) { seg->chunk_size = chunk_size; seg->origin = origin;
@@ -79,6 +82,10 @@ void init_snapshot_seg(struct lv_segment *seg, struct logical_volume *origin, origin->status |=VIRTUAL_ORIGIN ; seg->lv->status |= (SNAPSHOT |VIRTUAL ); +if (merge) { + seg->status |=SNAPSHOT_MERGE ; + origin->merging_snapshot = seg; + }dm_list_add (&origin->snapshot_segs, &seg->origin_list); }
@@ -113,7 +120,7 @@ int vg_add_snapshot(struct logical_volume *origin,if (!(seg =alloc_snapshot_seg (snap,0 ,0 ))) return_0; -init_snapshot_seg (seg, origin, cow, chunk_size); +init_snapshot_seg (seg, origin, cow, chunk_size,0 );return 1 ; }
@@ -122,6 +129,8 @@ int vg_remove_snapshot(struct logical_volume *cow) {dm_list_del (&cow->snapshot->origin_list); cow->snapshot->origin->origin_count--; +if (cow->snapshot->origin->merging_snapshot == cow->snapshot) + cow->snapshot->origin->merging_snapshot =NULL ;if (!lv_remove (cow->snapshot->lv)) { log_error("Failed to remove internal snapshot LV %s",
lib/snapshot/snapshot.c +11 -4
@@ -37,7 +37,7 @@ static int _snap_text_import(struct lv_segment *seg, const struct config_node *suint32_t chunk_size;const char *org_name, *cow_name;struct logical_volume *org, *cow; -int old_suppress; +int old_suppress, merge =0 ;if (!get_config_uint32 (sn,"chunk_size" , &chunk_size)) {log_error ("Couldn't read chunk size for snapshot." );
@@ -46,7 +46,10 @@ static int _snap_text_import(struct lv_segment *seg, const struct config_node *s old_suppress =log_suppress (1 ); -if (!(cow_name =find_config_str (sn,"cow_store" ,NULL ))) { + cow_name =find_config_str (sn,"merging_store" ,NULL ); +if (cow_name) { + merge =1 ; + }else if (!(cow_name =find_config_str (sn,"cow_store" ,NULL ))) {log_suppress (old_suppress);log_error ("Snapshot cow storage not specified." );return 0 ;
@@ -72,7 +75,7 @@ static int _snap_text_import(struct lv_segment *seg, const struct config_node *sreturn 0 ; } -init_snapshot_seg (seg, org, cow, chunk_size); +init_snapshot_seg (seg, org, cow, chunk_size, merge);return 1 ; }
@@ -81,7 +84,11 @@ static int _snap_text_export(const struct lv_segment *seg, struct formatter *f) {outf (f,"chunk_size = %u" , seg->chunk_size);outf (f,"origin = \"%s\"" , seg->origin->name); -outf (f,"cow_store = \"%s\"" , seg->cow->name); +if (!(seg->status &SNAPSHOT_MERGE )) { +outf (f,"cow_store = \"%s\"" , seg->cow->name); + }else { +outf (f,"merging_store = \"%s\"" , seg->cow->name); + }return 1 ; }
Signature · 1 line
1.6.5.2
PATCH 2/15 lvm-merge-metadata
Dne 20.11.2009 23:35, Mike Snitzer napsal(a):
Quoted 17 lines
From: Mikulas Patocka <[email protected]>
Add '
SNAPSHOT_MERGE'lv_segment'status' flag.Make '
merging_snapshot' pointer that points from the origin to the segment that represents the merging snapshot.Import/export '
merging_store' metadata.Do not allow creating snapshots while another snapshot is merging. Snapshot created in this state would certainly contain invalid data.
lib/metadata/metadata-exported.h +0
-0
lib/metadata/metadata-exported.h line 65
Quoted 6 lines
lib/metadata/metadata-exported.h +1
-0@@ -60,6 +60,7 @@//#define ACTIVATE_EXCL 0x00100000U /* LV - internal use only */ //#define PRECOMMITTED 0x00200000U /* VG - internal use only */ #define CONVERTING 0x00400000U/* LV */ +#define SNAPSHOT_MERGE 0x00800000U/* SEG */ #define MISSING_PV 0x00800000U/* PV */
I think reusing these bitfields might lead to unexpected troubles.
Zdenek
Re: [PATCH 02/15] lvm-merge-metadata
Quoted 23 lines · Zdenek Kabelac
Dne 20.11.2009 23:35, Mike Snitzer napsal(a):
Quoted 22 lines
From: Mikulas Patocka <[email protected]>
Add '
SNAPSHOT_MERGE'lv_segment'status' flag.Make '
merging_snapshot' pointer that points from the origin to the segment that represents the merging snapshot.Import/export '
merging_store' metadata.Do not allow creating snapshots while another snapshot is merging. Snapshot created in this state would certainly contain invalid data.
lib/metadata/metadata-exported.h +1
-0@@ -60,6 +60,7 @@//#define ACTIVATE_EXCL 0x00100000U /* LV - internal use only */ //#define PRECOMMITTED 0x00200000U /* VG - internal use only */ #define CONVERTING 0x00400000U/* LV */ +#define SNAPSHOT_MERGE 0x00800000U/* SEG */
Quoted 3 lines
lib/metadata/metadata-exported.h line 65
Quoted 1 line
lib/metadata/metadata-exported.h +0
-0#define MISSING_PV 0x00800000U/* PV */ I think reusing these bitfields might lead to unexpected troubles.
Nice catch, surprised I missed that.
Looks like I'll go with:
#define SNAPSHOT_MERGE 0x10000000U
Re: [PATCH 02/15] lvm-merge-metadata
Dne 21.11.2009 03:06, Mike Snitzer napsal(a):
Quoted 26 lines
Quoted 23 lines · Zdenek Kabelac
Dne 20.11.2009 23:35, Mike Snitzer napsal(a):
Quoted 22 lines
From: Mikulas Patocka <[email protected]>
Add '
SNAPSHOT_MERGE'lv_segment'status' flag.Make '
merging_snapshot' pointer that points from the origin to the segment that represents the merging snapshot.Import/export '
merging_store' metadata.Do not allow creating snapshots while another snapshot is merging. Snapshot created in this state would certainly contain invalid data.
lib/metadata/metadata-exported.h +1
-0@@ -60,6 +60,7 @@//#define ACTIVATE_EXCL 0x00100000U /* LV - internal use only */ //#define PRECOMMITTED 0x00200000U /* VG - internal use only */ #define CONVERTING 0x00400000U/* LV */ +#define SNAPSHOT_MERGE 0x00800000U/* SEG */
Quoted 9 lines
Quoted 3 lines
lib/metadata/metadata-exported.h line 65
Quoted 1 line
lib/metadata/metadata-exported.h +0
-0#define MISSING_PV 0x00800000U/* PV */ I think reusing these bitfields might lead to unexpected troubles.
Nice catch, surprised I missed that.
Looks like I'll go with:
#defineSNAPSHOT_MERGE0x10000000U
Yes - one small step for you :), but we run out-of-bits here - for replicator I've tried to reduces bit usage just for 2 bits (instead of using separate bit for _rimage, _rlog, _slog, replicator-dev) - but together with crypto we are out-of-space.
So either we might switch to 64bit status (simple) - or use some solution based on function calls instead of bit checks.
Zdenek
Re: [PATCH 02/15] lvm-merge-metadata
Quoted 37 lines · Zdenek Kabelac
Dne 21.11.2009 03:06, Mike Snitzer napsal(a):
Quoted 26 lines
Quoted 23 lines · Zdenek Kabelac
Dne 20.11.2009 23:35, Mike Snitzer napsal(a):
Quoted 22 lines
From: Mikulas Patocka <[email protected]>
Add '
SNAPSHOT_MERGE'lv_segment'status' flag.Make '
merging_snapshot' pointer that points from the origin to the segment that represents the merging snapshot.Import/export '
merging_store' metadata.Do not allow creating snapshots while another snapshot is merging. Snapshot created in this state would certainly contain invalid data.
lib/metadata/metadata-exported.h +1
-0@@ -60,6 +60,7 @@//#define ACTIVATE_EXCL 0x00100000U /* LV - internal use only */ //#define PRECOMMITTED 0x00200000U /* VG - internal use only */ #define CONVERTING 0x00400000U/* LV */ +#define SNAPSHOT_MERGE 0x00800000U/* SEG */ Quoted 9 lines
Quoted 3 lines
lib/metadata/metadata-exported.h line 65
Quoted 1 line
lib/metadata/metadata-exported.h +0
-0#define MISSING_PV 0x00800000U/* PV */ I think reusing these bitfields might lead to unexpected troubles.
Nice catch, surprised I missed that.
Looks like I'll go with:
#defineSNAPSHOT_MERGE0x10000000U
Quoted 7 lines
Yes - one small step for you :), but we run out-of-bits here - for replicator I've tried to reduces bit usage just for 2 bits (instead of using separate bit for
_rimage,_rlog,_slog, replicator-dev) - but together with crypto we are out-of-space.So either we might switch to 64bit status (simple) - or use some solution based on function calls instead of bit checks.
Right, I think we should just switch to 64-bit status.
Mike
Re: [PATCH 02/15] lvm-merge-metadata
Quoted 1 line · Mike Snitzer
Right, I think we should just switch to 64-bit status.
Ack.
Alasdair
PATCH 3/15 Add support for "snapshot-merge" target.
In reply to Mike SnitzerIntroduces new libdevmapper function dm_tree_node_add_snapshot_merge_target
Verifies that the kernel (dm-snapshot) provides the 'snapshot-merge' target.
Activate origin LV as snapshot-merge target. Using snapshot-origin target would be pointless because the origin contains volatile data while a merge is in progress.
Because snapshot-merge target is activated in place of the snapshot-origin target it must be resumed after all other snapshots (just like snapshot-origin does) --- otherwise small window for data corruption would exist.
Ideally the merging snapshot would not be activated at all but if it is to be activated (because snapshot was already active) it _must_ be done after the snapshot-merge. This insures that DM's snapshot-merge target will perform exception handover in the proper order (new->resume before old->resume). DM's snapshot-merge does support handover if the reverse sequence is used (old->resume before new->resume) but DM will fail to resume the old snapshot; leaving it suspended.
To insure the proper activation sequence dm_tree_activate_children() was updated to accommodate an additional 'activation_priority' level. All regular snapshots are 0, snapshot-merge is 1, and merging snapshot is 2.
--- lib/snapshot/snapshot.c | 8 ++++- libdm/.exported_symbols | 1 + libdm/libdevmapper.h | 6 ++++ libdm/libdm-deptree.c | 72 ++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 76 insertions(+), 11 deletions(-)
lib/snapshot/snapshot.c +7 -1
@@ -125,16 +125,22 @@ static int _snap_target_percent(void **target_state __attribute((unused)), }static int _snap_target_present (struct cmd_context *cmd, -const struct lv_segment *seg __attribute((unused)), +const struct lv_segment *seg,unsigned *attributes __attribute((unused))) {static int _snap_checked =0 ; +static int _snap_merge_checked =0 ;static int _snap_present =0 ;if (!_snap_checked) _snap_present =target_present (cmd,"snapshot" ,1 ) &&target_present (cmd,"snapshot-origin" ,0 ); +if (!_snap_merge_checked && seg && (seg->status &SNAPSHOT_MERGE )) { + _snap_present &=target_present (cmd,"snapshot-merge" ,0 ); + _snap_merge_checked =1 ; + } + _snap_checked =1 ;return _snap_present;
libdm/.exported_symbols +1 -0
@@ -70,6 +70,7 @@ dm_tree_suspend_children dm_tree_children_use_uuid dm_tree_node_add_snapshot_origin_target dm_tree_node_add_snapshot_target +dm_tree_node_add_snapshot_merge_target dm_tree_node_add_error_target dm_tree_node_add_zero_target dm_tree_node_add_linear_target
libdm/libdevmapper.h +6 -0
@@ -392,6 +392,12 @@ int dm_tree_node_add_snapshot_target(struct dm_tree_node *node,const char *cow_uuid, int persistent, uint32_t chunk_size); +int dm_tree_node_add_snapshot_merge_target (struct dm_tree_node *node, +uint64_t size, +const char *origin_uuid, +const char *cow_uuid, +const char *merge_uuid, +uint32_t chunk_size);int dm_tree_node_add_error_target (struct dm_tree_node *node,uint64_t size); int dm_tree_node_add_zero_target(struct dm_tree_node *node,
libdm/libdm-deptree.c +62 -10
141 lines not on this page · raw message
Signature · 1 line
1.6.5.2
PATCH 4/15 device-mapper-merge-activation
In reply to Mike SnitzerFrom: Mikulas Patocka <[email protected]>
Conditionally push down either the "snapshot-origin" or "snapshot-merge" target based on whether the LV is a merging snapshot.
When activating a snapshot-merge target do not attempt to monitor the LV for events; the polldaemon will monitor the snapshot as it is merged.
Allow "snapshot-merge" target's usage to be parsed via standard "snapshot" methods.
--- lib/activate/activate.c | 2 +- lib/activate/dev_manager.c | 58 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 5 deletions(-)
lib/activate/activate.c +1 -1
@@ -750,7 +750,7 @@ int monitor_dev_for_events(struct cmd_context *cmd,* In case of a snapshot device, we monitor lv->snapshot->lv, * not the actual LV itself. */ -if (lv_is_cow (lv)) +if (lv_is_cow (lv) && !(find_cow (lv)->status &SNAPSHOT_MERGE ))return monitor_dev_for_events (cmd, lv->snapshot->lv, monitor);/*
lib/activate/dev_manager.c +54 -4
101 lines not on this page · raw message
Signature · 1 line
1.6.5.2
PATCH 5/15 device-mapper-merging-store-needs-cow-suffix
In reply to Mike SnitzerMerging device is loaded with "-cow" suffix and with base name of the origin. This is needed so that "-cow" device can be found and removed when lvremove is performed.
--- lib/activate/dev_manager.c | 22 +++++++++++++++++----- 1 files changed, 17 insertions(+), 5 deletions(-)
lib/activate/dev_manager.c +17 -5
@@ -1047,16 +1047,28 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,struct lv_segment *seg;struct lv_layer *lvlayer;struct dm_tree_node *dnode; -char *name, *dlid; +char *name, *dlid, *lv_name;uint32_t max_stripe_size =UINT32_C (0 );uint32_t read_ahead = lv->read_ahead;uint32_t read_ahead_flags =UINT32_C (0 );uint16_t udev_flags =0 ; -if (lv_is_cow (lv) &&find_cow (lv)->status &SNAPSHOT_MERGE && !layer) -return 1 ; + lv_name = lv->name; +if (lv_is_cow (lv) &&find_cow (lv)->status &SNAPSHOT_MERGE ) { +if (layer) { +/* +* use origin's name as basis for snapshot-merge device names; +* this allows _clean_tree to automatically cleanup "-cow" +* when the origin is resumed (after merge completes) +*/ + lv_name =origin_from_cow (lv)->name; + }else { +/* top-level snapshot device is not needed during merge */ +return 1 ; + } + } -if (!(name =build_dm_name (dm->mem, lv->vg->name, lv->name, layer))) +if (!(name =build_dm_name (dm->mem, lv->vg->name, lv_name, layer))) return_0;if (!(dlid =build_dlid (dm, lv->lvid.s, layer)))
@@ -1068,7 +1080,7 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,return 1 ;if (!(lvlayer =dm_pool_alloc (dm->mem,sizeof (*lvlayer)))) { -log_error ("_add_new_lv_to_dtree: pool alloc failed for %s %s." , lv->name, layer); +log_error ("_add_new_lv_to_dtree: pool alloc failed for %s %s." , lv_name, layer);return 0 ; }
Signature · 1 line
1.6.5.2
PATCH 6/15 lvm-merge-lvconvert
In reply to Mike SnitzerFrom: Mikulas Patocka <[email protected]>
Add --merge support to lvconvert to start merging a snapshot into its origin, example usage: lvconvert --merge vg/snaplv
--- tools/args.h | 1 + tools/commands.h | 11 ++++- tools/lvconvert.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 115 insertions(+), 9 deletions(-)
tools/args.h +1 -0
@@ -103,6 +103,7 @@ arg(list_ARG, 'l', "list", NULL, 0) arg(size_ARG, 'L', "size", size_mb_arg, 0) arg(logicalextent_ARG, 'L', "logicalextent", int_arg_with_sign, 0) arg(persistent_ARG, 'M', "persistent", yes_no_arg, 0) +arg(merge_ARG, '\0', "merge", NULL, 0) arg(major_ARG, 'j', "major", major_arg, 0) arg(mirrors_ARG, 'm', "mirrors", int_arg_with_sign, 0)arg (metadatatype_ARG,'M' ,"metadatatype" , metadatatype_arg,0 )
tools/commands.h +8 -3
@@ -119,11 +119,16 @@ xx(lvconvert, "\t[-v|--verbose]\n" "\t[-Z|--zero {y|n}]\n" "\t[--version]" "\n" - "\tOriginalLogicalVolume[Path] SnapshotLogicalVolume[Path]\n", + "\tOriginalLogicalVolume[Path] SnapshotLogicalVolume[Path]\n\n" + + "lvconvert " + "--merge\n" + "\tSnapshotLogicalVolume[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) + merge_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 +106 -6
168 lines not on this page · raw message
Signature · 1 line
1.6.5.2
PATCH 7/15 lvm-merge-check-for-mounted-lv
In reply to Mike SnitzerFrom: Mikulas Patocka <[email protected]>
Do not allow merging over mounted logical volumes. When preserving origin, check that the snapshot is not mounted.
--- tools/lvconvert.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
tools/lvconvert.c +14 -0
@@ -920,6 +920,7 @@ static int lvconvert_merge(struct cmd_context *cmd,int r =0 ;struct logical_volume *origin =origin_from_cow (lv);struct lv_segment *cow_seg =find_cow (lv); +struct lvinfo info;/* Check if merge is possible */ if (cow_seg->status &SNAPSHOT_MERGE ) {
@@ -932,6 +933,19 @@ static int lvconvert_merge(struct cmd_context *cmd,return 0 ; } +if (lv_info (cmd, origin, &info,1 ,0 )) { +if (info.open_count) { +log_error ("Can't merge over open origin volume" ); +return 0 ; + } + } +if (lv_info (cmd, lv, &info,1 ,0 )) { +if (info.open_count) { +log_error ("Can't merge when snapshot is open" ); +return 0 ; + } + } +/* * Even though lv_is_visible(cow_seg->lv) returns 0, * the cow_seg->lv (name: snapshotX) is _not_ hidden;
Signature · 1 line
1.6.5.2
PATCH 8/15 lvm-merge-reporting
In reply to Mike SnitzerFrom: Mikulas Patocka <[email protected]>
Report merging snapshot as 'S' instead of 's':
This is useful for when the snapshot is still active and merging hasn't started yet; it shows a merge is pending. Once merging starts the merging snapshot will be hidden but can still be displayed with 'lvs -a'
Report snapshot origin with merging snapshot as 'O' instead of 'o':
Before merge starts this shows that a merge is pending. While merging the snapshot will be hidden, 'O' enables a user to see that there is a snapshot merging.
--- lib/report/report.c | 17 ++++++++++++----- 1 files changed, 12 insertions(+), 5 deletions(-)
lib/report/report.c +12 -5
@@ -314,8 +314,12 @@ static int _lvstatus_disp(struct dm_report *rh __attribute((unused)), struct dm_else if (lv->status &VIRTUAL ) repstr[0 ] ='v' ;/* Origin takes precedence over Mirror */ -else if (lv_is_origin (lv)) - repstr[0 ] ='o' ; +else if (lv_is_origin (lv)) { +if (lv->merging_snapshot) + repstr[0 ] ='O' ; +else + repstr[0 ] ='o' ; + }else if (lv->status &MIRRORED ) {if (lv->status &MIRROR_NOTSYNCED ) repstr[0 ] ='M' ;
@@ -328,9 +332,12 @@ static int _lvstatus_disp(struct dm_report *rh __attribute((unused)), struct dm_ repstr[0 ] ='I' ; else if (lv->status & MIRROR_LOG) repstr[0 ] ='l' ; - else if (lv_is_cow(lv)) - repstr[0 ] ='s' ; - else + else if (lv_is_cow(lv)) { +if (find_cow (lv)->status &SNAPSHOT_MERGE ) + repstr[0 ] ='S' ; +else + repstr[0 ] ='s' ; + } else repstr[0 ] ='-' ;if (lv->status &PVMOVE )
Signature · 1 line
1.6.5.2
PATCH 9/15 lvm-merge-origin-report-progress
In reply to Mike SnitzerFrom: Mikulas Patocka <[email protected]>
When there is merging snapshot, report percentage on the origin LV. Because the snapshot LV will be hidden this is needed so the user can see merging progress with "lvs" command.
--- lib/report/report.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
lib/report/report.c +1 -1
@@ -1032,7 +1032,7 @@ static int _snpercent_disp(struct dm_report *rh __attribute((unused)), struct dmreturn 0 ; } -if (!lv_is_cow (lv) || +if ((!lv_is_cow (lv) && !lv->merging_snapshot) || (lv_info (lv->vg->cmd, lv, &info,0 ,0 ) && !info.exists)) { *sortval =UINT64_C (0 );dm_report_field_set_value (field,"" , sortval);
Signature · 1 line
1.6.5.2
PATCH 10/15 lvm-merge-background-poll
In reply to Mike SnitzerFrom: Mikulas Patocka <[email protected]>
Background poll for lvconvert --merge command. The merging snapshot is removed when the merge finishes.
--- tools/lvconvert.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 69 insertions(+), 4 deletions(-)
tools/lvconvert.c +69 -4
@@ -41,6 +41,8 @@ struct lvconvert_params {int pv_count;char **pvs;struct dm_list *pvh; + +struct logical_volume *lv_to_poll; }; static int _lvconvert_name_params(struct lvconvert_params *lp,
@@ -329,6 +331,54 @@ out:return r; } +static int _finish_lvconvert_merge (struct cmd_context *cmd, +struct volume_group *vg, +struct logical_volume *lv, +struct dm_list *lvs_changed __attribute((unused))) +{ +struct lv_segment *snap_seg = lv->merging_snapshot; +if (!snap_seg) { +log_error ("Logical volume %s has no merging snapshot." , lv->name); +return 0 ; + } + +log_print ("Merge into logical volume %s finished." , lv->name); +if (!lv_remove_single (cmd, snap_seg->cow,DONT_PROMPT )) { +log_error ("Could not remove snapshot %s merged into %s." , + snap_seg->cow->name, lv->name); +return 0 ; + } + +return 1 ; +} + +static progress_t _poll_merge_progress (struct cmd_context *cmd, +struct logical_volume *lv, +const char *name __attribute((unused)), +struct daemon_parms *parms) +{ +float percent =0.0 ; +percent_range_t percent_range; + +if (!lv_snapshot_percent (lv, &percent, &percent_range)) { +log_error ("%s: Failed query for merging percentage" , lv->name); +return PROGRESS_CHECK_FAILED ; + }else if (percent_range ==PERCENT_INVALID ) { +log_error ("%s: Merging snapshot invalidated, aborting merge" , lv->name); +return PROGRESS_CHECK_FAILED ; + } + +if (parms->progress_display) +log_print ("%s: %s: %.1f%%" , lv->name, parms->progress_title, percent); +else +log_verbose ("%s: %s: %.1f%%" , lv->name, parms->progress_title, percent); + +if (percent_range ==PERCENT_0 ) +return PROGRESS_FINISHED_ALL ; + +return PROGRESS_UNFINISHED ; +} +static struct poll_functions _lvconvert_mirror_fns = { .get_copy_vg = _get_lvconvert_vg, .get_copy_lv = _get_lvconvert_lv,
@@ -337,6 +387,13 @@ static struct poll_functions _lvconvert_mirror_fns = { .finish_copy = _finish_lvconvert_mirror, }; +static struct poll_functions _lvconvert_merge_fns = { + .get_copy_vg = _get_lvconvert_vg, + .get_copy_lv = _get_lvconvert_lv, + .poll_progress = _poll_merge_progress, + .finish_copy = _finish_lvconvert_merge, +}; +int lvconvert_poll (struct cmd_context *cmd,struct logical_volume *lv,unsigned background) {
@@ -353,8 +410,12 @@ int lvconvert_poll(struct cmd_context *cmd, struct logical_volume *lv,memcpy (uuid, &lv->lvid,sizeof (lv->lvid)); -return poll_daemon (cmd, lv_full_name, uuid, background,0 , - &_lvconvert_mirror_fns,"Converted" ); +if (!lv->merging_snapshot) +return poll_daemon (cmd, lv_full_name, uuid, background,0 , + &_lvconvert_mirror_fns,"Converted" ); +else +return poll_daemon (cmd, lv_full_name, uuid, background,0 , + &_lvconvert_merge_fns,"Merged" ); } static int _insert_lvconvert_layer(struct cmd_context *cmd,
@@ -987,6 +1048,9 @@ static int lvconvert_merge(struct cmd_context *cmd,/* merge is running regardless of this deactivation failure */ } + lp->need_polling =1 ; + lp->lv_to_poll = origin; + r =1 ;log_print ("Merging of volume %s started." , lv->name); out:
@@ -1099,17 +1163,18 @@ int lvconvert(struct cmd_context * cmd, int argc, char **argv) }else lp.pvh = &vg->pvs; + lp.lv_to_poll = lvl->lv; ret =lvconvert_single (cmd, lvl->lv, &lp); bad:unlock_vg (cmd, lp.vg_name);if (ret ==ECMD_PROCESSED && lp.need_polling) { -if (!lv_info (cmd, lvl->lv, &info,1 ,0 ) || !info.exists) { +if (!lv_info (cmd, lp.lv_to_poll, &info,1 ,0 ) || !info.exists) {log_print ("Conversion starts after activation" ); goto out; } - ret =lvconvert_poll (cmd, lvl->lv, + ret =lvconvert_poll (cmd, lp.lv_to_poll, lp.wait_completion ?0 :1U ); } out:
Signature · 1 line
1.6.5.2
PATCH 11/15 lvm-merge-background-poll-on-lvvgchange
In reply to Mike SnitzerFrom: Mikulas Patocka <[email protected]>
Start background polling of merging stores on:
- lvchange -ay or vgchange -ay.
- lvchange --refresh or vgchange --refresh.
--- tools/toollib.c | 14 +++++++++++++- tools/vgchange.c | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-)
tools/toollib.c +13 -1
@@ -1262,6 +1262,18 @@ int lv_refresh(struct cmd_context *cmd, struct logical_volume *lv)if (!r) goto_out; +/* +* check if snapshot merge should be polled +* - unfortunately: even though the dev_manager will clear +* the lv's merge attributes if a merge is not possible; +* it is clearing a different instance of the lv (as +* retrieved with lv_from_lvid) +* - fortunately: polldaemon will immediately shutdown if the +* origin doesn't have a status with a snapshot percentage +*/ +if (lv_is_origin (lv) && lv->merging_snapshot) +lv_spawn_background_polling (cmd, lv); + out:return r; }
@@ -1296,7 +1308,7 @@ void lv_spawn_background_polling(struct cmd_context *cmd,pvmove_poll (cmd, pvname,1 ); } -if (lv->status &CONVERTING ) { +if (lv->status &CONVERTING || lv->merging_snapshot) {log_verbose ("Spawning background lvconvert process for %s" , lv->name);lvconvert_poll (cmd, lv,1 );
tools/vgchange.c +2 -1
@@ -104,7 +104,8 @@ static int _activate_lvs_in_vg(struct cmd_context *cmd, }if (activate !=CHANGE_AN && activate !=CHANGE_ALN && - (lv->status & (PVMOVE |CONVERTING ))) + (lv->status & (PVMOVE |CONVERTING ) || + lv->merging_snapshot))lv_spawn_background_polling (cmd, lv); count++;
Signature · 1 line
1.6.5.2
PATCH 12/15 lvm-merge-reload-if-stopped-merging
In reply to Mike SnitzerFrom: Mikulas Patocka <[email protected]>
Reload origin if merging has stopped.
--- lib/metadata/lv_manip.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
lib/metadata/lv_manip.c +4 -2
@@ -2061,6 +2061,7 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,struct volume_group *vg;struct lvinfo info;struct logical_volume *origin =NULL ; +int was_merging =0 ; vg = lv->vg;
@@ -2122,6 +2123,7 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,if (lv_is_cow (lv)) { origin =origin_from_cow (lv); + was_merging = !!origin->merging_snapshot;log_verbose ("Removing snapshot %s" , lv->name);if (!vg_remove_snapshot (lv)) return_0;
@@ -2139,8 +2141,8 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,backup (vg); -/* If no snapshots left, reload without -real. */ -if (origin && !lv_is_origin (origin)) { +/* If no snapshots left or if we stopped merging, reload */ +if (origin && (!lv_is_origin (origin) || was_merging)) {if (!suspend_lv (cmd, origin))log_error ("Failed to refresh %s without snapshot." , origin->name);else if (!resume_lv (cmd, origin))
Signature · 1 line
1.6.5.2
PATCH 13/15 lvm-merge-reload-proper-order
In reply to Mike SnitzerFrom: Mikulas Patocka <[email protected]>
When turning merging origin into non-merging origin, there is bad sequence:
snapshots are suspended, new origin is created, snapshots are resumed, new origin is resumed. So it allocates memory while suspended.
To fix it, move vg_commit after suspend_lv, so that the suspend code will treat it as precommitted vg and will preload new origin prior to suspend.
--- lib/metadata/lv_manip.c | 19 ++++++++++++++----- 1 files changed, 14 insertions(+), 5 deletions(-)
lib/metadata/lv_manip.c +14 -5
@@ -2136,19 +2136,28 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv, }/* store it on disks */ -if (!vg_write (vg) || !vg_commit (vg)) +if (!vg_write (vg)) return_0; -backup (vg); -/* If no snapshots left or if we stopped merging, reload */ if (origin && (!lv_is_origin (origin) || was_merging)) { -if (!suspend_lv (cmd, origin)) +if (!suspend_lv (cmd, origin)) {log_error ("Failed to refresh %s without snapshot." , origin->name); -else if (!resume_lv (cmd, origin)) +return 0 ; + } +if (!vg_commit (vg)) + return_0; +if (!resume_lv (cmd, origin)) {log_error ("Failed to resume %s." , origin->name); +return 0 ; + } + }else { +if (!vg_commit (vg)) + return_0; } +backup (vg); +if (lv_is_visible (lv))log_print ("Logical volume \"%s\" successfully removed" , lv->name);
Signature · 1 line
1.6.5.2
PATCH 14/15 lvm-merge-onactivate
In reply to Mike SnitzerMerge on activate support.
If either the origin or snapshot that is to be merged is open the merge will not start; only the merge metadata will be written. The merge will start on the next activation of the origin (or via lvchange --refresh) IFF both the origin and snapshot are closed.
Merge on activate is particularly important if we want to merge over a mounted filesystem that cannot be unmounted (until next boot) --- for example root.
--- lib/activate/dev_manager.c | 18 ++++++++++++++++++ lib/report/report.c | 12 ++++++++++-- tools/lvconvert.c | 23 +++++++++++++++++++---- 3 files changed, 47 insertions(+), 6 deletions(-)
lib/activate/dev_manager.c +18 -0
@@ -1047,12 +1047,30 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,struct lv_segment *seg;struct lv_layer *lvlayer;struct dm_tree_node *dnode; +struct dm_info dinfo;char *name, *dlid, *lv_name;uint32_t max_stripe_size =UINT32_C (0 );uint32_t read_ahead = lv->read_ahead;uint32_t read_ahead_flags =UINT32_C (0 );uint16_t udev_flags =0 ; +if (lv_is_origin (lv) && lv->merging_snapshot && !layer) { +/* +* Clear merge attributes if merge isn't currently possible: +* either origin or merging snapshot are open +* (must refresh info's open_count, so using the tree's +* existing nodes' info isn't an option) +*/ +if ((dev_manager_info (dm->mem,NULL , lv, +0 ,1 ,0 , &dinfo,NULL ) && dinfo.open_count) || + (dev_manager_info (dm->mem,NULL , lv->merging_snapshot->cow, +0 ,1 ,0 , &dinfo,NULL ) && dinfo.open_count)) { +/* clear merge attributes */ + lv->merging_snapshot->status &= ~SNAPSHOT_MERGE ; + lv->merging_snapshot =NULL ; + } + } + lv_name = lv->name;if (lv_is_cow (lv) &&find_cow (lv)->status &SNAPSHOT_MERGE ) {if (layer) {
lib/report/report.c +10 -2
@@ -1041,8 +1041,16 @@ static int _snpercent_disp(struct dm_report *rh __attribute((unused)), struct dmif (!lv_snapshot_percent (lv, &snap_percent, &percent_range) || (percent_range ==PERCENT_INVALID )) { - *sortval =UINT64_C (100 ); -dm_report_field_set_value (field,"100.00" , sortval); +if (!lv->merging_snapshot) { + *sortval =UINT64_C (100 ); +dm_report_field_set_value (field,"100.00" , sortval); + }else { +/* onactivate merge that hasn't started yet would +* otherwise display incorrect snap% in origin +*/ + *sortval =UINT64_C (0 ); +dm_report_field_set_value (field,"" , sortval); + }return 1 ; }
tools/lvconvert.c +19 -4
@@ -979,6 +979,7 @@ static int lvconvert_merge(struct cmd_context *cmd, struct lvconvert_params *lp) {int r =0 ; +int merge_on_activate =0 ;struct logical_volume *origin =origin_from_cow (lv);struct lv_segment *cow_seg =find_cow (lv);struct lvinfo info;
@@ -994,16 +995,20 @@ static int lvconvert_merge(struct cmd_context *cmd,return 0 ; } +/* +* merge on origin's next activation if either the +* origin or snapshot LV are currently open +*/ if (lv_info (cmd, origin, &info,1 ,0 )) {if (info.open_count) { -log_error ("Can't merge over open origin volume" ); -return 0 ; +log_print ("Can't merge over open origin volume" ); + merge_on_activate =1 ; } }if (lv_info (cmd, lv, &info,1 ,0 )) {if (info.open_count) { -log_error ("Can't merge when snapshot is open" ); -return 0 ; +log_print ("Can't merge when snapshot is open" ); + merge_on_activate =1 ; } }
@@ -1025,6 +1030,16 @@ static int lvconvert_merge(struct cmd_context *cmd,if (!vg_write (lv->vg)) return_0; +if (merge_on_activate) { +/* commit vg but skip starting the merge */ +if (!vg_commit (lv->vg)) + return_0; + r =1 ; +log_print ("Merging of snapshot %s will start " +"next activation." , lv->name); + goto out; + } +/* Perform merge */ if (!suspend_lv (cmd, origin)) {log_error ("Failed to suspend origin %s" , origin->name);
Signature · 1 line
1.6.5.2
PATCH 15/15 lvm-merge-man-lvconvert
In reply to Mike SnitzerUpdate lvconvert manpage for snapshot --merge
--- man/lvconvert.8.in | 29 ++++++++++++++++++++++++++++- 1 files changed, 28 insertions(+), 1 deletions(-)
man/lvconvert.8.in +28 -1
@@ -24,7 +24,18 @@ LogicalVolume[Path] [PhysicalVolume[Path][:PE[-PE]]...] [\-\-version] .br OriginalLogicalVolume[Path] SnapshotLogicalVolume[Path] +.br +.br +.B lvconvert +\-\-merge [\-b|\-\-background] [\-i|\-\-interval Seconds] +[\-h|\-?|\-\-help] +[\-v|\-\-verbose] +[\-\-version] +SnapshotLogicalVolume[Path] +.br + +.br .B lvconvert \-\-repair [\-h|\-?|\-\-help]
@@ -47,7 +58,7 @@ the freed extents come first from the specified PhysicalVolumes. .SH OPTIONS See \fBlvm\fP for common options. .br -Exactly one of \-\-mirrors, \-\-repair or \-\-snapshot arguments required. +Exactly one of \-\-mirrors, \-\-repair, \-\-snapshot or \-\-merge arguments required. .br .TP .I \-m, \-\-mirrors Mirrors
@@ -106,6 +117,17 @@ Power of 2 chunk size for the snapshot logical volume between 4k and 512k. .I \-Z, \-\-zero y|n Controls zeroing of the first KB of data in the snapshot. If the volume is read-only the snapshot will not be zeroed. +.TP +.I \-\-merge +Merges a snapshot into its origin volume. If both the origin and snapshot volume +are not open the merge will start immediately. Otherwise, the merge will start +the first time either the origin or snapshot are activated and both are closed. +Merging a snapshot into an origin that cannot be closed, for example a root +filesystem, is deferred until the next time the origin volume is activated. +When merging starts, the resulting logical volume will have the origin's name, +minor number and UUID. While the merge is in progress, reads or writes to the +origin appear as they were directed to the snapshot being merged. When the +merge finishes, the merged snapshot is removed. .br .SH Examples "lvconvert -m1 vg00/lvol1"
@@ -146,6 +168,11 @@ extents /dev/sda:0-15 and /dev/sdb:0-15 for allocation of new extents. converts mirror logical volume "vg00/lvmirror1" to linear, freeing physical extents from /dev/sda. +.br +"lvconvert --merge vg00/lvol1_snap" +.br +merges "vg00/lvol1_snap" into its origin. + .SH SEE ALSO .BR lvm (8), .BR vgcreate (8),
Signature · 1 line
1.6.5.2