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

[lvm-devel] [PATCH] Remove LV if zeroing was requested but failed



If zeroing of LV was requested for lvcreate but failed,
it seems nicer if the lvcreate fails and the (incomplete) LV is removed.

Attached patch changes lvcreate to abort in the following cases:
  - if zeroing was requested but activation was disabled
  - if zeroing was requested but activation failed,
  - if zeroing was requested but zeroing failed

A test script is also attached.

Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America
If zeroing is requested but failed or unavailable,
the incomplete LV should be removed.

Index: LVM2.work/tools/lvcreate.c
===================================================================
--- LVM2.work.orig/tools/lvcreate.c
+++ LVM2.work/tools/lvcreate.c
@@ -631,6 +631,12 @@ static int _lvcreate(struct cmd_context 
 		lp->extents = lp->extents - size_rest + lp->stripes;
 	}
 
+	if (lp->zero && !activation()) {
+		log_error("Can't zero the volume without using "
+			  "device-mapper kernel driver");
+		return 0;
+	}
+
 	if (lp->snapshot) {
 		if (!activation()) {
 			log_error("Can't create snapshot without using "
@@ -831,14 +837,21 @@ static int _lvcreate(struct cmd_context 
 			goto error;
 		}
 	} else if (!activate_lv(cmd, lv)) {
+		if (lp->zero) {
+			log_error("Aborting. Failed to activate new LV.");
+			goto error;
+		}
 		log_error("Failed to activate new LV.");
 		return 0;
 	}
 
-	if ((lp->zero || lp->snapshot) && activation()) {
-		if (!set_lv(cmd, lv, UINT64_C(0), 0) && lp->snapshot) {
-			log_error("Aborting. Failed to wipe snapshot "
-				  "exception store.");
+	if (lp->zero || lp->snapshot) {
+		if (!set_lv(cmd, lv, UINT64_C(0), 0)) {
+			if (lp->snapshot)
+				log_error("Aborting. Failed to wipe snapshot "
+					  "exception store.");
+			else
+				log_error("Aborting. Failed to zero new LV.");
 			goto error;
 		}
 	} else

Attachment: cleanup-lvcreate.sh
Description: Bourne shell script


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