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

[lvm-devel] [PATCH 4/4] Renaming temporary mirror LVs



Temporary LVs for added mirrors are currently named as followings:
  - "<LV name>_resync<n>"
    This is a primary mirror leg for synching.
    "<n>" has no relationship to other numberings in the LV.
  - "<LV name>_mlog<n>"
    This is a mirror log for synching layer.

The patch changes their names to:
  - "<LV name>_mimagetmp_<n>"
    This is a primary mirror leg for synching.
    "<n>" is the number of the first LV of newly added images.
  - "<LV name>_mlogtmp_<n>"
    This is a mirror log for synching layer.

Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America
Changes naming of temporary mimage/mlog.
  - A temporary LV, which works as mimage in the inserted layer during
    the conversion, is '_mimagetmp_%d'
  - Mirror log for the synching is '_mlogtmp_%d'

We don't need to add them to apply_lv_name_restrictions() as they
contains 'mimage'/'mlog' strings already.

Index: LVM2.work/lib/metadata/metadata-exported.h
===================================================================
--- LVM2.work.orig/lib/metadata/metadata-exported.h
+++ LVM2.work/lib/metadata/metadata-exported.h
@@ -41,6 +41,9 @@ struct pv_segment;
 #define PV_MIN_SIZE ( 512L * 1024L >> SECTOR_SHIFT)	/* 512 KB in sectors */
 #define MAX_RESTRICTED_LVS 255	/* Used by FMT_RESTRICTED_LVIDS */
 
+/* Layer suffix */
+#define MIRROR_SYNC_LAYER "_mimagetmp"
+
 /* Various flags */
 /* Note that the bits no longer necessarily correspond to LVM1 disk format */
 
Index: LVM2.work/lib/metadata/mirror.c
===================================================================
--- LVM2.work.orig/lib/metadata/mirror.c
+++ LVM2.work/lib/metadata/mirror.c
@@ -1030,7 +1030,8 @@ revert_new_lv:
 static struct logical_volume *_create_mirror_log(struct logical_volume *lv,
 						 struct alloc_handle *ah,
 						 alloc_policy_t alloc,
-						 const char *lv_name)
+						 const char *lv_name,
+						 const char *suffix)
 {
 	struct logical_volume *log_lv;
 	char *log_name;
@@ -1042,7 +1043,7 @@ static struct logical_volume *_create_mi
 		return NULL;
 	}
 
-	if (dm_snprintf(log_name, len, "%s_mlog", lv->name) < 0) {
+	if (dm_snprintf(log_name, len, "%s%s", lv->name, suffix) < 0) {
 		log_error("log_name allocation failed.");
 		return NULL;
 	}
@@ -1075,7 +1076,9 @@ static struct logical_volume *_set_up_mi
 		return NULL;
 	}
 
-	if (!(log_lv = _create_mirror_log(lv, ah, alloc, lv->name))) {
+	if (!(log_lv = _create_mirror_log(lv, ah, alloc, lv->name,
+					  strstr(lv->name, MIRROR_SYNC_LAYER)
+						? "_mlogtmp_%d" : "_mlog"))) {
 		log_error("Failed to create mirror log.");
 		return NULL;
 	}
Index: LVM2.work/tools/lvconvert.c
===================================================================
--- LVM2.work.orig/tools/lvconvert.c
+++ LVM2.work/tools/lvconvert.c
@@ -227,6 +227,50 @@ static int _read_params(struct lvconvert
 	return 1;
 }
 
+static int _insert_lvconvert_layer(struct cmd_context *cmd,
+				   struct logical_volume *lv)
+{
+	char *format, *layer_name;
+	size_t len;
+	int i;
+
+	/*
+ 	 * We would like to give the same number for this layer
+ 	 * and the newly added mimage.
+ 	 * However, LV name of newly added mimage is determined *after*
+	 * the LV name of this layer is determined.
+	 *
+	 * So, use generate_lv_name() to generate mimage name first
+	 * and take the number from it.
+	 */
+
+	len = strlen(lv->name) + 32;
+	if (!(format = alloca(len)) ||
+	    !(layer_name = alloca(len)) ||
+	    dm_snprintf(format, len, "%s_mimage_%%d", lv->name) < 0) {
+		log_error("lvconvert: layer name allocation failed.");
+		return 0;
+	}
+
+	if (!generate_lv_name(lv->vg, format, layer_name, len) ||
+	    sscanf(layer_name, format, &i) != 1) {
+		log_error("lvconvert: layer name generation failed.");
+		return 0;
+	}
+
+	if (dm_snprintf(layer_name, len, MIRROR_SYNC_LAYER "_%d", i) < 0) {
+		log_error("layer name allocation failed.");
+		return 0;
+	}
+
+	if (!insert_layer_for_lv(cmd, lv, 0, layer_name)) {
+		log_error("Failed to insert resync layer");
+		return 0;
+	}
+
+	return 1;
+}
+
 static int lvconvert_mirrors(struct cmd_context * cmd, struct logical_volume * lv,
 			     struct lvconvert_params *lp)
 {
@@ -383,7 +427,7 @@ static int lvconvert_mirrors(struct cmd_
 		}
 		/* FIXME: can't have multiple mlogs. force corelog. */
 		corelog = 1;
-		if (!insert_layer_for_lv(cmd, lv, 0, "_resync%d")) {
+		if (!_insert_lvconvert_layer(cmd, lv)) {
 			log_error("Failed to insert resync layer");
 			return 0;
 		}
Index: LVM2.work/tools/toollib.c
===================================================================
--- LVM2.work.orig/tools/toollib.c
+++ LVM2.work/tools/toollib.c
@@ -1222,12 +1222,6 @@ int apply_lvname_restrictions(const char
 		return 0;
 	}
 
-	if (strstr(name, "_resync")) {
-		log_error("Names including \"_resync\" are reserved. "
-			  "Please choose a different LV name.");
-		return 0;
-	}
-
 	return 1;
 }
 

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