From 5b7f6ad698e13112e3eba6a3fe2e4d7c67e91579 Mon Sep 17 00:00:00 2001 From: Mike Snitzer Date: Tue, 5 Jan 2010 21:14:04 +0000 Subject: [PATCH] Use snapshot metadata usage to determine if snapshot is empty Version >= 1.8.0 of the DM snapshot target appends 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). Also update LVM2 to be aware of the possibility for "Merge failed" in the snapshot-merge target's status. Signed-off-by: Mike Snitzer --- WHATS_NEW | 1 + lib/snapshot/snapshot.c | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 886a9faf9..b594f9f0a 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.57 - ==================================== + Use snapshot metadata usage to determine if a snapshot is empty. Add --poll flag to vgchange and lvchange. Propagate commit and revert metadata notification to other nodes in cluster. Use proper mask for VG lock mode in clvmd. diff --git a/lib/snapshot/snapshot.c b/lib/snapshot/snapshot.c index d5bac31b4..b45844277 100644 --- a/lib/snapshot/snapshot.c +++ b/lib/snapshot/snapshot.c @@ -95,19 +95,27 @@ 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; + int r; - if (sscanf(params, "%" PRIu64 "/%" PRIu64, - &numerator, &denominator) == 2) { - *total_numerator += numerator; - *total_denominator += denominator; - if (!numerator) + /* + * snapshot target's percent format: + * <= 1.7.0: / + * >= 1.8.0: / + */ + 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 (r == 3 && 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; - } else if (!strcmp(params, "Invalid")) + } else if (!strcmp(params, "Invalid") || + !strcmp(params, "Merge failed")) *percent_range = PERCENT_INVALID; else return 0; -- 2.43.5