Skip to contentSkip to conversation

master - snapshots: fix incorrect calculation of cow size

PATCH Zdenek Kabelac 1 participant 1 message Feb 26, 2014

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=40e6176d251b68f5be8ca7925a2f073982de6cec
Commit:        40e6176d251b68f5be8ca7925a2f073982de6cec
Parent:        014ba37cb19c9172b1b81af3f31897939f72b1d2
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Tue Feb 25 19:43:07 2014 +0100
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Wed Feb 26 14:25:09 2014 +0100

snapshots: fix incorrect calculation of cow size

Code uses target driver version for better estimation of max size of COW device for snapshot.

The bug can be tested with this script:
VG=vg1
lvremove -f $VG/origin
set -e
lvcreate -L 2143289344b -n origin $VG
lvcreate -n snap -c 8k -L 2304M -s $VG/origin
dd if=/dev/zero of=/dev/$VG/snap bs=1M count=2044 oflag=direct

The bug happens when these two conditions are met
* origin size is divisible by (chunk_size/16) - so that the last metadata area is filled completely
* the miscalculated snapshot metadata size is divisible by extent size - so that there is no padding to extent boundary which would otherwise save us

---
 WHATS_NEW                     |    1 +
 lib/activate/activate.h       |    5 ++++
 lib/metadata/snapshot_manip.c |   43 ++++++++++++++++++++++++++++++----------
 lib/snapshot/snapshot.c       |   15 ++++++++++++-
 test/shell/snapshot-usage.sh  |    2 +-
 5 files changed, 52 insertions(+), 14 deletions(-)
WHATS_NEW +1 -0
index 9a3da75..224e351 100644
@@ -1,5 +1,6 @@
 Version 2.02.106 - 
 ====================================
+  Fix calculation of maximum size of COW device for snapshot (2.02.99).
   Do not allow stripe size to be bigger then extent size for lvresize.
   Zero snapshot COW header when creating read-only snapshot.
   Comment out config lines in dumpconfig output without default values defined.
lib/activate/activate.h +5 -0
index c3cf3d9..ad14a57 100644
@@ -55,6 +55,11 @@ struct lv_activate_opts {
 /* target attribute flags */
 #define MIRROR_LOG_CLUSTERED	0x00000001U
 
+/* snapshot target attribute flags */
+enum {
+	SNAPSHOT_FEATURE_FIXED_LEAK		= (1 << 0), /* version 1.12 */
+};
+
 /* thin target attribute flags */
 enum {
 	/* bitfields - new features from 1.1 version */
lib/metadata/snapshot_manip.c +32 -11

67 lines not on this page · raw message

lib/snapshot/snapshot.c +13 -2
index 91e778f..0b7b845 100644
@@ -142,19 +142,30 @@ static int _snap_target_percent(void **target_state __attribute__((unused)),
 
 static int _snap_target_present(struct cmd_context *cmd,
 				const struct lv_segment *seg,
-				unsigned *attributes __attribute__((unused)))
+				unsigned *attributes)
 {
 	static int _snap_checked = 0;
 	static int _snap_merge_checked = 0;
 	static int _snap_present = 0;
 	static int _snap_merge_present = 0;
+	static unsigned _snap_attrs = 0;
+	uint32_t maj, min, patchlevel;
 
 	if (!_snap_checked) {
+		_snap_checked = 1;
 		_snap_present = target_present(cmd, "snapshot", 1) &&
 		    target_present(cmd, "snapshot-origin", 0);
-		_snap_checked = 1;
+
+		if (_snap_present &&
+		    target_version("snapshot", &maj, &min, &patchlevel) &&
+		    (maj > 1 ||
+		     (maj == 1 && (min >= 12 || (min == 10 && patchlevel >= 2)))))
+			_snap_attrs |= SNAPSHOT_FEATURE_FIXED_LEAK;
+		else
+			log_very_verbose("Target snapshot may leak metadata.");
 	}
 
+	/* TODO: test everything at once */
 	if (seg && (seg->status & MERGING)) {
 		if (!_snap_merge_checked) {
 			_snap_merge_present = target_present(cmd, "snapshot-merge", 0);
test/shell/snapshot-usage.sh +1 -1
index 4d15fb1..cb60556 100644
@@ -110,7 +110,7 @@ lvextend --use-policies $vg1/lvol1
 check lv_field $vg1/lvol1 size "18.00k"
 
 lvextend -l+33 $vg1/lvol1
-check lv_field $vg1/lvol1 size "28.00k"
+check lv_field $vg1/lvol1 size "32.00k"
 
 fill 20K
 lvremove -f $vg1