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

[lvm-devel] [PATCH] [draft] add lvconvert --repair --auto that honours lvm.conf mirror policy



Hi,

I'm attaching a draft version of basic configuration capability for automatic
mirror repairs. This will make dmeventd respect the two lvm.conf options
setting failed mirror replacement policies. It doesn't affect the basic
(manual) lvconvert --repair mode (I have added --auto for that purpose; it
might need a better name though).

Please note that the patch is untested yet, but I'd like to get feedback
anyway. Thanks!

diff -rN -u -p old-upstream/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c new-upstream/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
--- old-upstream/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c	2009-05-21 17:18:07.568851726 +0200
+++ new-upstream/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c	2009-05-21 17:18:07.828854184 +0200
@@ -152,7 +152,7 @@ static int _remove_failed_devices(const 
 	}
 
 	/* FIXME Is any sanity-checking required on %s? */
-	if (CMD_SIZE <= snprintf(cmd_str, CMD_SIZE, "vgreduce --config devices{ignore_suspended_devices=1} --removemissing --force %s", vg)) {
+	if (CMD_SIZE <= snprintf(cmd_str, CMD_SIZE, "lvconvert --config devices{ignore_suspended_devices=1} --repair --auto %s/%s", vg, lv)) {
 		/* this error should be caught above, but doesn't hurt to check again */
 		syslog(LOG_ERR, "Unable to form LVM command: Device name too long");
 		dm_pool_empty(_mem_pool);  /* FIXME: not safe with multiple threads */
diff -rN -u -p old-upstream/lib/config/defaults.h new-upstream/lib/config/defaults.h
--- old-upstream/lib/config/defaults.h	2009-05-21 17:18:07.588853081 +0200
+++ new-upstream/lib/config/defaults.h	2009-05-21 17:18:07.836855900 +0200
@@ -126,4 +126,7 @@
 #define DEFAULT_SEGS_SORT "vg_name,lv_name,seg_start"
 #define DEFAULT_PVSEGS_SORT "pv_name,pvseg_start"
 
+#define DEFAULT_MIRROR_DEVICE_FAULT_POLICY "remove"
+#define DEFAULT_MIRROR_LOG_FAULT_POLICY "allocate"
+
 #endif				/* _LVM_DEFAULTS_H */
diff -rN -u -p old-upstream/tools/args.h new-upstream/tools/args.h
--- old-upstream/tools/args.h	2009-05-21 17:18:07.760853014 +0200
+++ new-upstream/tools/args.h	2009-05-21 17:18:07.892855824 +0200
@@ -50,6 +50,7 @@ arg(resync_ARG, '\0', "resync", NULL, 0)
 arg(corelog_ARG, '\0', "corelog", NULL, 0)
 arg(mirrorlog_ARG, '\0', "mirrorlog", string_arg, 0)
 arg(repair_ARG, '\0', "repair", NULL, 0)
+arg(auto_ARG, '\0', "auto", NULL, 0)
 arg(monitor_ARG, '\0', "monitor", yes_no_arg, 0)
 arg(config_ARG, '\0', "config", string_arg, 0)
 arg(trustcache_ARG, '\0', "trustcache", NULL, 0)
diff -rN -u -p old-upstream/tools/lvconvert.c new-upstream/tools/lvconvert.c
--- old-upstream/tools/lvconvert.c	2009-05-21 17:18:07.768852564 +0200
+++ new-upstream/tools/lvconvert.c	2009-05-21 17:18:07.892855824 +0200
@@ -448,6 +448,22 @@ static int _lvconvert_mirrors(struct cmd
 	struct logical_volume *log_lv;
 	int failed_mirrors = 0, failed_log = 0;
 	struct dm_list *old_pvh = NULL, *remove_pvs = NULL;
+	const char *leg_policy = NULL, *log_policy = NULL;
+
+	int repair = arg_count(cmd, repair_ARG);
+	int auto_repair = repair && arg_count(cmd, auto_ARG);
+	int replace_log = 1, replace_legs = 1;
+
+	if (auto_repair) {
+		leg_policy = find_config_tree_str(cmd,
+					"activation/mirror_device_fault_policy",
+					DEFAULT_MIRROR_DEVICE_FAULT_POLICY);
+		log_policy = find_config_tree_str(cmd,
+					"activation/mirror_log_fault_policy",
+					DEFAULT_MIRROR_LOG_FAULT_POLICY);
+		replace_legs = strcmp(leg_policy, "remove");
+		replace_log = strcmp(log_policy, "remove");
+	}
 
 	seg = first_seg(lv);
 	existing_mirrors = lv_mirror_count(lv);
@@ -455,12 +471,12 @@ static int _lvconvert_mirrors(struct cmd
 	/* If called with no argument, try collapsing the resync layers */
 	if (!arg_count(cmd, mirrors_ARG) && !arg_count(cmd, mirrorlog_ARG) &&
 	    !arg_count(cmd, corelog_ARG) && !arg_count(cmd, regionsize_ARG) &&
-	    !arg_count(cmd, repair_ARG)) {
+	    !repair) {
 		lp->need_polling = 1;
 		return 1;
 	}
 
-	if (arg_count(cmd, mirrors_ARG) && arg_count(cmd, repair_ARG)) {
+	if (arg_count(cmd, mirrors_ARG) && repair) {
 		log_error("You can only use one of -m, --repair.");
 		return 0;
 	}
@@ -482,7 +498,7 @@ static int _lvconvert_mirrors(struct cmd
 	else
 		lp->mirrors += 1;
 
-	if (arg_count(cmd,repair_ARG)) {
+	if (repair) {
 		cmd->handles_missing_pvs = 1;
 		cmd->partial_activation = 1;
 		lp->need_polling = 0;
@@ -573,7 +589,7 @@ static int _lvconvert_mirrors(struct cmd
 	 */
 	if (lp->mirrors < existing_mirrors) {
 		/* Reduce number of mirrors */
-		if (arg_count(cmd, repair_ARG) || lp->pv_count)
+		if (repair || lp->pv_count)
 			remove_pvs = lp->pvh;
 		if (!lv_remove_mirrors(cmd, lv, existing_mirrors - lp->mirrors,
 				       (corelog || lp->mirrors == 1) ? 1U : 0U,
@@ -706,13 +722,15 @@ static int _lvconvert_mirrors(struct cmd
 
 	if (failed_log || failed_mirrors) {
 		lp->pvh = old_pvh;
-		if (failed_log)
+		if (failed_log && replace_log)
 			failed_log = corelog = 0;
-		lp->mirrors += failed_mirrors;
+		if (replace_legs)
+			lp->mirrors += failed_mirrors;
 		failed_mirrors = 0;
 		existing_mirrors = lv_mirror_count(lv);
 		/* Now replace missing devices. */
-		goto restart;
+		if (replace_log || replace_legs)
+			goto restart;
 	}
 
 	if (!lp->need_polling)
Yours,
   Petr.

-- 
Peter Rockai | me()mornfall!net | prockai()redhat!com
 http://blog.mornfall.net | http://web.mornfall.net

"In My Egotistical Opinion, most people's C programs should be
 indented six feet downward and covered with dirt."
     -- Blair P. Houghton on the subject of C program indentation

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