From c52678ee9b996460ff7b0fe2063295d86448f810 Mon Sep 17 00:00:00 2001 From: Mike Snitzer Date: Wed, 13 Jan 2010 01:56:18 +0000 Subject: [PATCH] Rename segment and lv status flag from SNAPSHOT_MERGE to MERGING. Eliminate 'merging_snapshot' from 'struct logical_volume' and just use 'snapshot' for origin lv's reference to the merging snapshot; also set MERGING in the origin lv's status. --- lib/format_text/flags.c | 2 +- lib/metadata/lv_manip.c | 1 - lib/metadata/metadata-exported.h | 5 +---- lib/metadata/snapshot_manip.c | 23 ++++++++++++++--------- lib/snapshot/snapshot.c | 4 ++-- tools/toollib.c | 2 +- tools/vgchange.c | 6 ++---- 7 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/format_text/flags.c b/lib/format_text/flags.c index eeabc90a6..a41dc1a7d 100644 --- a/lib/format_text/flags.c +++ b/lib/format_text/flags.c @@ -61,7 +61,7 @@ static const struct flag _lv_flags[] = { {MIRRORED, NULL, 0}, {VIRTUAL, NULL, 0}, {SNAPSHOT, NULL, 0}, - {SNAPSHOT_MERGE, NULL, 0}, + {MERGING, NULL, 0}, {ACTIVATE_EXCL, NULL, 0}, {CONVERTING, NULL, 0}, {PARTIAL_LV, NULL, 0}, diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index a1794e61c..8c0ecf9e1 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -1877,7 +1877,6 @@ 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); diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index 721b57c8b..8342dc03c 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -69,7 +69,7 @@ //#define POSTORDER_OPEN_FLAG 0x04000000U temporary use inside vg_read_internal. */ //#define VIRTUAL_ORIGIN 0x08000000U /* LV - internal use only */ -#define SNAPSHOT_MERGE 0x10000000U /* SEG */ +#define MERGING 0x10000000U /* LV SEG */ #define LVM_READ 0x00000100U /* LV VG */ #define LVM_WRITE 0x00000200U /* LV VG */ @@ -330,9 +330,6 @@ 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; diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c index 4bdd9db3f..19effe380 100644 --- a/lib/metadata/snapshot_manip.c +++ b/lib/metadata/snapshot_manip.c @@ -25,7 +25,7 @@ int lv_is_origin(const struct logical_volume *lv) int lv_is_cow(const struct logical_volume *lv) { - return lv->snapshot ? 1 : 0; + return (!lv_is_origin(lv) && lv->snapshot) ? 1 : 0; } int lv_is_visible(const struct logical_volume *lv) @@ -53,18 +53,21 @@ int lv_is_virtual_origin(const struct logical_volume *lv) int lv_is_merging_origin(const struct logical_volume *origin) { - return origin->merging_snapshot ? 1 : 0; + return (origin->status & MERGING) ? 1 : 0; } struct lv_segment *find_merging_cow(const struct logical_volume *origin) { - return origin->merging_snapshot; + /* FIXME: eliminate this wrapper and just use find_cow()? + * - find_merging_cow() adds to code clarity in caller + */ + return find_cow(origin); } int lv_is_merging_cow(const struct logical_volume *snapshot) { - /* NOTE: use of find_cow() rather than find_merging_cow() */ - return (find_cow(snapshot)->status & SNAPSHOT_MERGE) ? 1 : 0; + /* checks lv_segment's status to see if cow is merging */ + return (find_cow(snapshot)->status & MERGING) ? 1 : 0; } /* Given a cow LV, return the snapshot lv_segment that uses it */ @@ -117,15 +120,17 @@ void init_snapshot_merge(struct lv_segment *cow_seg, * merge metadata (cow_seg->lv is now "internal") */ cow_seg->lv->status &= ~VISIBLE_LV; - cow_seg->status |= SNAPSHOT_MERGE; - origin->merging_snapshot = cow_seg; + cow_seg->status |= MERGING; + origin->snapshot = cow_seg; + origin->status |= MERGING; } void clear_snapshot_merge(struct logical_volume *origin) { /* clear merge attributes */ - origin->merging_snapshot->status &= ~SNAPSHOT_MERGE; - origin->merging_snapshot = NULL; + origin->snapshot->status &= ~MERGING; + origin->snapshot = NULL; + origin->status &= ~MERGING; } int vg_add_snapshot(struct logical_volume *origin, diff --git a/lib/snapshot/snapshot.c b/lib/snapshot/snapshot.c index 0e8ac4d6e..8e1f89262 100644 --- a/lib/snapshot/snapshot.c +++ b/lib/snapshot/snapshot.c @@ -84,7 +84,7 @@ 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); - if (!(seg->status & SNAPSHOT_MERGE)) + if (!(seg->status & MERGING)) outf(f, "cow_store = \"%s\"", seg->cow->name); else outf(f, "merging_store = \"%s\"", seg->cow->name); @@ -144,7 +144,7 @@ static int _snap_target_present(struct cmd_context *cmd, _snap_checked = 1; } - if (!_snap_merge_checked && seg && (seg->status & SNAPSHOT_MERGE)) { + if (!_snap_merge_checked && seg && (seg->status & MERGING)) { _snap_merge_present = target_present(cmd, "snapshot-merge", 0); _snap_merge_checked = 1; return _snap_present && _snap_merge_present; diff --git a/tools/toollib.c b/tools/toollib.c index 991fd30b2..6c1a42259 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -1307,7 +1307,7 @@ void lv_spawn_background_polling(struct cmd_context *cmd, pvmove_poll(cmd, pvname, 1); } - if (lv->status & CONVERTING || lv_is_merging_origin(lv)) { + if (lv->status & (CONVERTING|MERGING)) { log_verbose("Spawning background lvconvert process for %s", lv->name); lvconvert_poll(cmd, lv, 1); diff --git a/tools/vgchange.c b/tools/vgchange.c index 3056ebaa8..b4f5d003e 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -69,8 +69,7 @@ static int _poll_lvs_in_vg(struct cmd_context *cmd, lv_active = info.exists; if (lv_active && - (lv->status & (PVMOVE|CONVERTING) || - lv_is_merging_origin(lv))) { + (lv->status & (PVMOVE|CONVERTING|MERGING))) { lv_spawn_background_polling(cmd, lv); count++; } @@ -140,8 +139,7 @@ static int _activate_lvs_in_vg(struct cmd_context *cmd, if (background_polling() && activate != CHANGE_AN && activate != CHANGE_ALN && - (lv->status & (PVMOVE|CONVERTING) || - lv_is_merging_origin(lv))) + (lv->status & (PVMOVE|CONVERTING|MERGING))) lv_spawn_background_polling(cmd, lv); count++; -- 2.43.5