[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] [PATCH] Fix RHBZ 754198 (multiple dmeventd snapshot extensions)



Hi,

the attached patch should fix the problem encountered in 754198. Namely,
we failed to reset the percent threshold for the next check after
extending a snapshot. To this end, I have added a special exit code,
ENO_ACTION_NEEDED -- however, this is not absolutely required, and is
only an optimisation. On the other hand, it is likely an important
optimisation, because without this, all snapshots filled above 50 % will
run a LVM command (with all the associated overhead) every 10
seconds. There are more possible uses for this new exit code, so I think
it's a good idea anyway.

Documentation *might* need updating (although it's currently only used
by --use-policies, which is not an entirely user-level option...).

Other than that, the patch is relatively straightforward.

Yours,
   Petr

Index: daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
===================================================================
RCS file: /cvs/lvm2/LVM2/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c,v
retrieving revision 1.16
diff -u -p -r1.16 dmeventd_snapshot.c
--- daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c	19 Oct 2011 14:31:49 -0000	1.16
+++ daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c	15 Nov 2011 21:55:36 -0000
@@ -115,10 +115,11 @@ static int _run(const char *cmd, ...)
         return 1; /* all good */
 }
 
-static int _extend(const char *device)
+static int _extend(const char *device, int *check_thr)
 {
 	char *vg = NULL, *lv = NULL, *layer = NULL;
 	char cmd_str[1024];
+	int r;
 
 	if (!dm_split_lvm_name(dmeventd_lvm2_pool(), device, &vg, &lv, &layer)) {
 		syslog(LOG_ERR, "Unable to determine VG name from %s.", device);
@@ -130,7 +131,15 @@ static int _extend(const char *device)
 		return 0;
 	}
 
-	return dmeventd_lvm2_run(cmd_str) == ECMD_PROCESSED;
+	r = dmeventd_lvm2_run(cmd_str);
+	if ( r == ENO_ACTION_NEEDED )
+		return 1;
+
+	/* snapshot was resized, reset the counter */
+	*check_thr = CHECK_MINIMUM;
+	if ( r == ECMD_PROCESSED )
+		return 1;
+	return 0;
 }
 
 static void _umount(const char *device, int major, int minor)
@@ -222,9 +231,10 @@ void process_event(struct dm_task *dmt,
 		if (percent >= WARNING_THRESH) /* Print a warning to syslog. */
 			syslog(LOG_WARNING, "Snapshot %s is now %i%% full.\n", device, percent);
 		/* Try to extend the snapshot, in accord with user-set policies */
-		if (!_extend(device))
+		if (!_extend(device, percent_check))
 			syslog(LOG_ERR, "Failed to extend snapshot %s.", device);
 	}
+
 out:
 	dmeventd_lvm2_unlock();
 }
Index: lib/commands/errors.h
===================================================================
RCS file: /cvs/lvm2/LVM2/lib/commands/errors.h,v
retrieving revision 1.6
diff -u -p -r1.6 errors.h
--- lib/commands/errors.h	30 Jun 2009 18:39:31 -0000	1.6
+++ lib/commands/errors.h	15 Nov 2011 21:55:36 -0000
@@ -20,6 +20,7 @@
 #define ENO_SUCH_CMD		2
 #define EINVALID_CMD_LINE	3
 #define ECMD_FAILED		5
+#define ENO_ACTION_NEEDED	6
 
 /* FIXME Also returned by cmdlib. */
 
Index: test/t-lvextend-snapshot-dmeventd.sh
===================================================================
RCS file: /cvs/lvm2/LVM2/test/t-lvextend-snapshot-dmeventd.sh,v
retrieving revision 1.2
diff -u -p -r1.2 t-lvextend-snapshot-dmeventd.sh
--- test/t-lvextend-snapshot-dmeventd.sh	5 Jan 2011 00:16:20 -0000	1.2
+++ test/t-lvextend-snapshot-dmeventd.sh	15 Nov 2011 21:56:04 -0000
@@ -27,7 +27,7 @@ percent() {
 
 which mkfs.ext2 || exit 200
 
-aux prepare_vg 2
+aux prepare_vg 3
 aux prepare_dmeventd
 
 lvcreate -l 8 -n base $vg
@@ -44,8 +44,19 @@ sleep 10 # dmeventd only checks every 10
 post=`percent`
 
 test $pre = $post
+
 write 2 5000
 pre=`percent`
 sleep 10 # dmeventd only checks every 10 seconds :(
 post=`percent`
 test $pre -gt $post
+
+# check that a second extension happens; we used to fail to extend when the
+# utilisation ended up between THRESH and (THRESH + 10)... see RHBZ 754198
+# (the utilisation after the write should be 57 %)
+
+write 3 5000
+pre=`percent`
+sleep 10 # dmeventd only checks every 10 seconds :(
+post=`percent`
+test $pre -gt $post
Index: tools/lvresize.c
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/lvresize.c,v
retrieving revision 1.139
diff -u -p -r1.139 lvresize.c
--- tools/lvresize.c	6 Oct 2011 15:32:27 -0000	1.139
+++ tools/lvresize.c	15 Nov 2011 21:56:21 -0000
@@ -391,6 +391,8 @@ static int _lvresize(struct cmd_context 
 			return ECMD_FAILED;
 		}
 		_adjust_policy_params(cmd, lv, lp);
+		if (!lp->extents)
+			return ENO_ACTION_NEEDED;
 	}
 
 	if (!lv_is_visible(lv)) {
-- 
id' Ash = Ash; id' Dust = Dust; id' _ = undefined

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]