shared snapshot removal fix and cleanups
cover shared snapshot removal fix and cleanups
Mikulas,
These patches apply at the end of the quilt series I published here:
http://people.redhat.com/msnitzer/patches/multisnap/lvm2/LVM2-2.02.62/
Please make sure you have udev_sync enabled when testing; otherwise the shared exception store (-cow and -real) device removal will be unreliable (racing with udev).
Mike Snitzer (3):
Use the origin's uuid as the basis for the shared cow's uuid. Introduce find_shared_cow() and lv_is_shared_cow() wrappers. Eliminate 'shared_snapshot' from 'struct logical_volume'.
lib/activate/dev_manager.c | 37 ++++++++++++++++----------- lib/format_text/flags.c | 1 + lib/metadata/lv_alloc.h | 2 +- lib/metadata/lv_manip.c | 3 +- lib/metadata/metadata-exported.h | 10 ++++---- lib/metadata/snapshot_manip.c | 50 ++++++++++++++++++++++++++++++------- lib/report/report.c | 8 +++--- tools/lvresize.c | 3 +- 8 files changed, 75 insertions(+), 39 deletions(-)
PATCH 1/3 Use the origin's uuid as the basis for the shared cow's uuid.
This is needed to allow proper cleanup of the shared cow now that we only support info-by-uuid. Using the cow's uuid relied on info-by-name to cleanup the shared cow.
--- lib/activate/dev_manager.c | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-)
lib/activate/dev_manager.c +17 -11
@@ -1179,8 +1179,12 @@ static int _add_origin_target_to_dtree(struct dev_manager *dm,unsigned n;const char **snapids;struct lv_list *lvl; -if (!(cow_dlid =build_dlid (dm, - lv->shared_snapshot->cow->lvid.s,"cow" ))) +/* +* Using origin uuid so info-by-uuid -cow cleanup works. +* An origin with a shared snapshot store will only ever +* have one -cow device. +*/ +if (!(cow_dlid =build_dlid (dm, lv->lvid.s,"cow" ))) return_0; n =0 ; dm_list_iterate_items(lvl, &lv->vg->lvs) {
@@ -1300,8 +1304,9 @@ static int _add_target_to_dtree(struct dev_manager *dm, }static int _add_new_lv_to_dtree (struct dev_manager *dm,struct dm_tree *dtree, -struct logical_volume *lv, -const char *lv_name,const char *layer); +struct logical_volume *lv, +struct logical_volume *identity_lv, +const char *layer); static int _add_segment_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
@@ -1341,7 +1346,7 @@ static int _add_segment_to_dtree(struct dev_manager *dm,return 0 ; }if (lv_is_multisnap_origin (seg->lv)) { -if (!_add_new_lv_to_dtree (dm, dtree, seg->lv->shared_snapshot->cow, seg->lv->name,"cow" )) +if (!_add_new_lv_to_dtree (dm, dtree, seg->lv->shared_snapshot->cow, seg->lv,"cow" )) return_0; } else if (lv_is_merging_origin(seg->lv)) { if (!_add_new_lv_to_dtree(dm, dtree,
@@ -1394,7 +1399,8 @@ static int _add_segment_to_dtree(struct dev_manager *dm,static int _add_new_lv_to_dtree (struct dev_manager *dm,struct dm_tree *dtree,struct logical_volume *lv, -const char *lv_name,const char *layer) +struct logical_volume *identity_lv, +const char *layer) {struct lv_segment *seg;struct lv_layer *lvlayer;
@@ -1429,13 +1435,13 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,if (lv_is_cow (lv) &&find_cow (lv)->status &SNAPSHOT_SHARED && !layer)return 1 ; -if (!lv_name) - lv_name = lv->name; +if (!identity_lv) + identity_lv = lv; -if (!(name =build_dm_name (dm->mem, lv->vg->name, lv_name, layer))) +if (!(name =build_dm_name (dm->mem, lv->vg->name, identity_lv->name, layer))) return_0; -if (!(dlid =build_dlid (dm, lv->lvid.s, layer))) +if (!(dlid =build_dlid (dm, identity_lv->lvid.s, layer))) return_0;/* We've already processed this node if it already has a context ptr */
@@ -1445,7 +1451,7 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,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); + identity_lv->name, layer);return 0 ; }
Signature · 1 line
1.6.5.2
PATCH 2/3 Introduce find_shared_cow() and lv_is_shared_cow() wrappers.
In reply to Mike Snitzer--- lib/activate/dev_manager.c | 11 +++++---- lib/metadata/metadata-exported.h | 3 ++ lib/metadata/snapshot_manip.c | 39 ++++++++++++++++++++++++++++++------- lib/report/report.c | 8 +++--- tools/lvresize.c | 3 +- 5 files changed, 45 insertions(+), 19 deletions(-)
lib/activate/dev_manager.c +6 -5
@@ -1211,8 +1211,8 @@ static int _add_origin_target_to_dtree(struct dev_manager *dm, }if (!dm_tree_node_add_snapshot_shared_target (dnode, lv->size, real_dlid, cow_dlid, - lv->shared_snapshot->exception_store, - lv->shared_snapshot->chunk_size, +find_shared_cow (lv)->exception_store, +find_shared_cow (lv)->chunk_size, n, snapids)) return_0; }else {
@@ -1261,7 +1261,7 @@ static int _add_snapshot_target_to_dtree(struct dev_manager *dm,return 0 ; } -if (snap_seg->status &SNAPSHOT_SHARED ) +if (lv_is_shared_cow (lv))return 1 ;if (!(origin_dlid =build_dlid (dm, snap_seg->origin->lvid.s,"real" )))
@@ -1346,7 +1346,8 @@ static int _add_segment_to_dtree(struct dev_manager *dm,return 0 ; }if (lv_is_multisnap_origin (seg->lv)) { -if (!_add_new_lv_to_dtree (dm, dtree, seg->lv->shared_snapshot->cow, seg->lv,"cow" )) +if (!_add_new_lv_to_dtree (dm, dtree, +find_shared_cow (seg->lv)->cow, seg->lv,"cow" )) return_0; } else if (lv_is_merging_origin(seg->lv)) { if (!_add_new_lv_to_dtree(dm, dtree,
@@ -1432,7 +1433,7 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree, } } -if (lv_is_cow (lv) &&find_cow (lv)->status &SNAPSHOT_SHARED && !layer) +if (lv_is_shared_cow (lv) && !layer)return 1 ;if (!identity_lv)
lib/metadata/metadata-exported.h +3 -0
@@ -633,6 +633,7 @@ int lv_is_merging_origin(const struct logical_volume *origin);int lv_is_merging_cow (const struct logical_volume *snapshot);int lv_is_multisnap_origin (const struct logical_volume *lv);int lv_is_multisnap_cow (const struct logical_volume *lv); +int lv_is_shared_cow (const struct logical_volume *lv);/* Test if given LV is visible from user's perspective */ int lv_is_visible (const struct logical_volume *lv);
@@ -641,6 +642,8 @@ int pv_is_in_vg(struct volume_group *vg, struct physical_volume *pv);struct lv_segment *find_merging_cow (const struct logical_volume *origin); +struct lv_segment *find_shared_cow (const struct logical_volume *origin); +/* Given a cow LV, return return the snapshot lv_segment that uses it */ struct lv_segment *find_cow (const struct logical_volume *lv);
lib/metadata/snapshot_manip.c +31 -8
@@ -41,6 +41,11 @@ int lv_is_multisnap_cow(const struct logical_volume *lv)return seg &&seg_is_virtual (seg) && seg->origin; } +int lv_is_shared_cow (const struct logical_volume *lv) +{ +return lv_is_cow (lv) && (find_cow (lv)->status &SNAPSHOT_SHARED ); +} +int lv_is_visible (const struct logical_volume *lv) {if (lv->status &SNAPSHOT )
@@ -89,12 +94,31 @@ struct lv_segment *find_cow(const struct logical_volume *lv)return lv->snapshot; } +struct lv_segment *find_shared_cow (const struct logical_volume *origin) +{ +if (!lv_is_multisnap_origin (origin)) +return NULL ; + +return origin->shared_snapshot; +} +/* Given a cow LV, return its origin */ struct logical_volume *origin_from_cow (const struct logical_volume *lv) {return lv->snapshot->origin; } +static void init_shared_snapshot (struct lv_segment *cow_seg, +struct logical_volume *origin) +{ + origin->shared_snapshot = cow_seg; +} + +static void clear_shared_snapshot (struct logical_volume *origin) +{ + origin->shared_snapshot =NULL ; +} +int init_snapshot_seg (struct lv_segment *seg,struct logical_volume *origin,struct logical_volume *cow,const char *exception_store,uint32_t chunk_size,int merge)
@@ -128,12 +152,11 @@ int init_snapshot_seg(struct lv_segment *seg, struct logical_volume *origin,init_snapshot_merge (seg, origin);if (seg->status &SNAPSHOT_SHARED ) { -if (!origin->shared_snapshot) { - origin->shared_snapshot = seg; - }else { -log_err ("Origin '%s' has already a shared snapshot." , origin->name); +if (lv_is_multisnap_origin (origin)) { +log_err ("Origin '%s' already has a shared snapshot." , origin->name); return_0; } +init_shared_snapshot (seg, origin); }dm_list_add (&origin->snapshot_segs, &seg->origin_list);
@@ -189,8 +212,8 @@ int vg_add_snapshot(struct logical_volume *origin,return 0 ; } -if (snapshot_flags &SNAPSHOT_SHARED && origin->shared_snapshot) { -log_error ("Origin has already a shared snapshot." ); +if (snapshot_flags &SNAPSHOT_SHARED &&lv_is_multisnap_origin (origin)) { +log_error ("Origin already has a shared snapshot." );return 0 ; }
@@ -228,8 +251,8 @@ int vg_remove_snapshot(struct logical_volume *cow) preload_origin =1 ; } -if (cow->snapshot->origin->shared_snapshot == cow->snapshot) - cow->snapshot->origin->shared_snapshot =NULL ; +if (find_shared_cow (origin) ==find_cow (cow)) +clear_shared_snapshot (origin);if (!lv_remove (cow->snapshot->lv)) { log_error("Failed to remove internal snapshot LV %s",
lib/report/report.c +4 -4
@@ -383,8 +383,8 @@ static int _lvstatus_disp(struct dm_report *rh __attribute((unused)), struct dm_ repstr[5 ] ='-' ; } -if (lv_is_cow (lv) && lv->snapshot->status &SNAPSHOT_SHARED ) - lv = lv->snapshot->origin; +if (lv_is_shared_cow (lv)) + lv =origin_from_cow (lv);else if (lv_is_multisnap_cow (lv)) lv =first_seg (lv)->origin;else
@@ -1044,8 +1044,8 @@ report_empty:return 1 ; } -if (lv->snapshot->status &SNAPSHOT_SHARED ) - lv = lv->snapshot->origin; +if (lv_is_shared_cow (lv)) + lv =origin_from_cow (lv);if (lv_info (lv->vg->cmd, lv, &info,0 ,0 ) && !info.exists) goto report_empty;
tools/lvresize.c +1 -2
@@ -575,8 +575,7 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,return ECMD_FAILED ; } } -if (lp->resize ==LV_REDUCE && -lv_is_cow (lv) && lv->snapshot->status &SNAPSHOT_SHARED ) { +if (lp->resize ==LV_REDUCE &&lv_is_shared_cow (lv)) {log_error ("Shared snapshot cannot be reduced." );return ECMD_FAILED ; }
Signature · 1 line
1.6.5.2
PATCH 3/3 Eliminate 'shared_snapshot' from 'struct logical_volume'.
In reply to Mike SnitzerJust use 'snapshot' for origin lv's reference to the shared snapshot store; also set SNAPSHOT_SHARED in the origin lv's status.
Move SNAPSHOT_SHARED flag so it doesn't overlap with legacy hole in flags. Change 'snapshot_flags' to be 64bit.
--- lib/format_text/flags.c | 1 + lib/metadata/lv_alloc.h | 2 +- lib/metadata/lv_manip.c | 3 +-- lib/metadata/metadata-exported.h | 7 ++----- lib/metadata/snapshot_manip.c | 17 ++++++++++++----- 5 files changed, 17 insertions(+), 13 deletions(-)
lib/format_text/flags.c +1 -0
@@ -61,6 +61,7 @@ static const struct flag _lv_flags[] = { {MIRRORED, NULL, 0}, {VIRTUAL, NULL, 0}, {SNAPSHOT, NULL, 0}, + {SNAPSHOT_SHARED, NULL, 0}, {MERGING, NULL, 0}, {ACTIVATE_EXCL, NULL, 0}, {CONVERTING, NULL, 0},
lib/metadata/lv_alloc.h +1 -1
@@ -30,7 +30,7 @@ struct lv_segment *alloc_lv_segment(struct dm_pool *mem,struct lv_segment *alloc_snapshot_seg (struct logical_volume *lv,uint64_t status,uint32_t old_le_count, -uint32_t snapshot_flags); +uint64_t snapshot_flags);int set_lv_segment_area_pv (struct lv_segment *seg,uint32_t area_num,struct physical_volume *pv,uint32_t pe);
lib/metadata/lv_manip.c +1 -2
@@ -216,7 +216,7 @@ struct lv_segment *alloc_lv_segment(struct dm_pool *mem,struct lv_segment *alloc_snapshot_seg (struct logical_volume *lv,uint64_t status,uint32_t old_le_count, -uint32_t snapshot_flags) +uint64_t snapshot_flags) {struct lv_segment *seg;const struct segment_type *segtype;
@@ -1890,7 +1890,6 @@ struct logical_volume *alloc_lv(struct dm_pool *mem) } lv->snapshot =NULL ; - lv->shared_snapshot =NULL ;dm_list_init (&lv->snapshot_segs);dm_list_init (&lv->segments);dm_list_init (&lv->tags);
lib/metadata/metadata-exported.h +2 -5
@@ -61,7 +61,6 @@//#define ACTIVATE_EXCL 0x00100000U /* LV - internal use only */ //#define PRECOMMITTED 0x00200000U /* VG - internal use only */ #define CONVERTING 0x00400000U/* LV */ -#define SNAPSHOT_SHARED 0x02000000U/* SEG */ #define MISSING_PV 0x00800000U/* PV */ #define PARTIAL_LV 0x01000000U/* LV - derived flag, not
@@ -72,6 +71,7 @@//#define VIRTUAL_ORIGIN 0x08000000U /* LV - internal use only */ #define MERGING 0x10000000U/* LV SEG */ +#define SNAPSHOT_SHARED 0x20000000U/* LV SEG */ #define LVM_READ 0x00000100U/* LV VG */ #define LVM_WRITE 0x00000200U/* LV VG */
@@ -335,9 +335,6 @@ struct logical_volume {struct dm_list snapshot_segs;struct lv_segment *snapshot; -/* A shared-snapshot segment for this origin */ -struct lv_segment *shared_snapshot; -struct dm_list segments;struct dm_list tags;struct dm_list segs_using_this_lv;
@@ -661,7 +658,7 @@ void clear_snapshot_merge(struct logical_volume *origin);int vg_add_snapshot (struct logical_volume *origin,struct logical_volume *cow,union lvid *lvid,uint32_t extent_count,const char *exception_store,uint32_t chunk_size, -unsigned snapshot_flags); +uint64_t snapshot_flags);int vg_remove_snapshot (struct logical_volume *cow);
lib/metadata/snapshot_manip.c +12 -5
@@ -32,7 +32,7 @@ int lv_is_cow(const struct logical_volume *lv)int lv_is_multisnap_origin (const struct logical_volume *lv) { -return lv_is_origin (lv) && lv->shared_snapshot; +return lv_is_origin (lv) && (lv->status &SNAPSHOT_SHARED ); }int lv_is_multisnap_cow (const struct logical_volume *lv)
@@ -58,6 +58,9 @@ int lv_is_visible(const struct logical_volume *lv)if (lv_is_merging_cow (lv))return 0 ; +if (lv_is_shared_cow (lv)) +return 0 ; +return lv_is_visible (origin_from_cow (lv)); }
@@ -99,7 +102,7 @@ struct lv_segment *find_shared_cow(const struct logical_volume *origin)if (!lv_is_multisnap_origin (origin))return NULL ; -return origin->shared_snapshot; +return find_cow (origin); }/* Given a cow LV, return its origin */
@@ -111,12 +114,16 @@ struct logical_volume *origin_from_cow(const struct logical_volume *lv)static void init_shared_snapshot (struct lv_segment *cow_seg,struct logical_volume *origin) { - origin->shared_snapshot = cow_seg; +/* Clear VISIBLE_LV for the same reasons as init_snapshot_merge */ + cow_seg->lv->status &= ~VISIBLE_LV ; + origin->snapshot = cow_seg; + origin->status |=SNAPSHOT_SHARED ; }static void clear_shared_snapshot (struct logical_volume *origin) { - origin->shared_snapshot =NULL ; + origin->snapshot =NULL ; + origin->status &= ~SNAPSHOT_SHARED ; } int init_snapshot_seg(struct lv_segment *seg, struct logical_volume *origin,
@@ -194,7 +201,7 @@ void clear_snapshot_merge(struct logical_volume *origin)int vg_add_snapshot (struct logical_volume *origin,struct logical_volume *cow,union lvid *lvid,uint32_t extent_count,const char *exception_store, -uint32_t chunk_size,unsigned snapshot_flags) +uint32_t chunk_size,uint64_t snapshot_flags) {struct logical_volume *snap;struct lv_segment *seg;
Signature · 1 line
1.6.5.2