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

[lvm-devel] [PATCH] Fix a regression in '--nosync' option for mirrored LV



'--nosync' option of lvcreate is for skipping initial sync
of mirrors.
The option was implemented by passing the option to
create_mirror_log() function to control the initialization.
However, the new lv_add_mirrors() API didn't have a corresponding
option. So the option doesn't work properly.

This patch fixes it by adding a new flag for lv_add_mirrors(),
MIRROR_SKIP_INIT_SYNC, to skip initial sync.

Expected behavior is:
  * Default
      "Copy %" starts from 0 on create.
      "Copy %" resumes from the last status on reactivation.
  * '--corelog' only
      "Copy %" starts from 0 on create.
      "Copy %" starts from 0 on reactivation.
  * '--nosync' only
      "Copy %" starts from 100 on create.
      "Copy %" resumes from the last status on reactivation.
  * '--corelog' + '--nosync'
      "Copy %" starts from 100 on create.
      "Copy %" starts from 0 on reactivation.

Also attached is a test script for these combinations.
(Not in a 'make check' format as the script won't work on
 loopback devices which completes synchronization too fast.)

Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America
This patch fixes '--nosync' option by adding a new flag for lv_add_mirrors(),
MIRROR_SKIP_INIT_SYNC, to skip initial sync.

Expected behavior is:
  * Default
      "Copy %" starts from 0 on create.
      "Copy %" resumes from the last status on reactivation.
  * '--corelog' only
      "Copy %" starts from 0 on create.
      "Copy %" starts from 0 on reactivation.
  * '--nosync' only
      "Copy %" starts from 100 on create.
      "Copy %" resumes from the last status on reactivation.
  * '--corelog' + '--nosync'
      "Copy %" starts from 100 on create.
      "Copy %" starts from 0 on reactivation.

Index: LVM2.work/lib/metadata/mirror.c
===================================================================
--- LVM2.work.orig/lib/metadata/mirror.c
+++ LVM2.work/lib/metadata/mirror.c
@@ -1351,8 +1351,8 @@ int add_mirror_images(struct cmd_context
 	 * create and initialize mirror log
 	 */
 	if (log_count &&
-	    !(log_lv = _set_up_mirror_log(cmd, ah, lv, log_count,
-					  region_size, alloc, 0)))
+	    !(log_lv = _set_up_mirror_log(cmd, ah, lv, log_count, region_size,
+					  alloc, mirror_in_sync())))
 		return_0;
 
 	/* The log initialization involves vg metadata commit.
@@ -1422,7 +1422,10 @@ int lv_add_mirrors(struct cmd_context *c
 	 * the global mirror_in_sync status. As we are adding
 	 * a new mirror, it should be set as 'out-of-sync'
 	 * so that the sync starts. */
-	if (!log_count)
+	/* However, MIRROR_SKIP_INIT_SYNC even overrides it. */
+	if (flags & MIRROR_SKIP_INIT_SYNC)
+		init_mirror_in_sync(1);
+	else if (!log_count)
 		init_mirror_in_sync(0);
 
 	if (flags & MIRROR_BY_SEG) {
Index: LVM2.work/lib/metadata/metadata-exported.h
===================================================================
--- LVM2.work.orig/lib/metadata/metadata-exported.h
+++ LVM2.work/lib/metadata/metadata-exported.h
@@ -95,6 +95,7 @@ struct pv_segment;
 /* Mirror conversion type flags */
 #define MIRROR_BY_SEG		0x00000001U	/* segment-by-segment mirror */
 #define MIRROR_BY_LV		0x00000002U	/* mirror using whole mimage LVs */
+#define MIRROR_SKIP_INIT_SYNC	0x00000010U	/* skip initial sync */
 
 /* Ordered list - see lv_manip.c */
 typedef enum {
Index: LVM2.work/tools/lvcreate.c
===================================================================
--- LVM2.work.orig/tools/lvcreate.c
+++ LVM2.work/tools/lvcreate.c
@@ -790,7 +790,8 @@ static int _lvcreate(struct cmd_context 
 						lv->le_count,
 						lp->region_size),
 				    lp->corelog ? 0U : 1U, pvh, lp->alloc,
-				    MIRROR_BY_LV)) {
+				    MIRROR_BY_LV |
+				    (lp->nosync ? MIRROR_SKIP_INIT_SYNC : 0))) {
 			stack;
 			goto revert_new_lv;
 		}

Attachment: nosync-test.sh
Description: Bourne shell script


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