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

[lvm-devel] [PATCH] Remove leftover mirror log on creation failure



When a creation of mirrored LV fails during its course,
mirror log LV is left unremoved.
The patch removes the log LV if error occurs after commiting it.

# dmsetup create --notable testvg-lv0_mlog
# lvcreate -l1 -m1 -nlv0 testvg
  device-mapper: create ioctl failed: Device or resource busy
  Aborting. Failed to activate mirror log. Remove new LVs and retry.
  Failed to create mirror log.
# lvs -a
  LV       VG     Attr   LSize Origin Snap%  Move Log Copy% 
  lv0_mlog testvg -wi-d- 4.00M

Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America
create_mirror_log() commits vg so that mirrorlog can be activated
for writing initial data.
If something failed after the commit, the function has to uncommit it:
i.e. remove the mirrorlog and commit vg again.
lv_remove_single() does the job.

How to reproduce:
  # dmsetup create --notable testvg-lv0_mlog
  # lvcreate -l1 -m1 -n lv0 testvg

Index: LVM2.work/tools/toollib.c
===================================================================
--- LVM2.work.orig/tools/toollib.c
+++ LVM2.work/tools/toollib.c
@@ -1338,6 +1338,7 @@ struct logical_volume *create_mirror_log
 	char *log_name;
 	size_t len;
 	struct str_list *sl;
+	int committed = 0;
 
 	len = strlen(lv_name) + 32;
 	if (!(log_name = alloca(len)) ||
@@ -1379,6 +1380,8 @@ struct logical_volume *create_mirror_log
 		goto error;
 	}
 
+	committed = 1;
+
 	if (!activation() && in_sync) {
 		log_error("Aborting. Unable to create in-sync mirror log "
 			  "while activation is disabled.");
@@ -1386,8 +1389,7 @@ struct logical_volume *create_mirror_log
 	}
 
 	if (!activate_lv(cmd, log_lv)) {
-		log_error("Aborting. Failed to activate mirror log. "
-			  "Remove new LVs and retry.");
+		log_error("Aborting. Failed to activate mirror log.");
 		goto error;
 	}
 
@@ -1398,20 +1400,17 @@ struct logical_volume *create_mirror_log
 
 	if (activation() && !set_lv(cmd, log_lv, log_lv->size,
 				    in_sync ? -1 : 0)) {
-		log_error("Aborting. Failed to wipe mirror log. "
-			  "Remove new LV and retry.");
+		log_error("Aborting. Failed to wipe mirror log.");
 		goto error;
 	}
 
 	if (activation() && !_write_log_header(cmd, log_lv)) {
-		log_error("Aborting. Failed to write mirror log header. "
-			  "Remove new LV and retry.");
+		log_error("Aborting. Failed to write mirror log header.");
 		goto error;
 	}
 
 	if (!deactivate_lv(cmd, log_lv)) {
-		log_error("Aborting. Failed to deactivate mirror log. "
-			  "Remove new LV and retry.");
+		log_error("Aborting. Failed to deactivate mirror log.");
 		goto error;
 	}
 
@@ -1419,6 +1418,9 @@ struct logical_volume *create_mirror_log
 
 	return log_lv;
 error:
-	/* FIXME Attempt to clean up. */
+	/* Mirror log has been written to metadata. Remove it. */
+	if (committed && !lv_remove_single(cmd, log_lv, DONT_PROMPT_OVERRIDE))
+		stack;
+
 	return NULL;
 }

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