mrc0mmand / rpms / lvm2

Forked from rpms/lvm2 3 years ago
Clone

Blame SOURCES/lvm2-2_02_104-various-udev-support-fixes.patch

191583
 WHATS_NEW                        |  3 +++
191583
 daemons/clvmd/lvm-functions.c    |  2 +-
191583
 lib/activate/activate.c          | 21 +++++++++++++--------
191583
 lib/activate/activate.h          | 20 ++++++++++++++++----
191583
 lib/activate/dev_manager.c       | 18 +++++++++++-------
191583
 lib/format_text/flags.c          |  1 +
191583
 lib/locking/file_locking.c       |  6 ++++--
191583
 lib/locking/no_locking.c         |  6 ++++--
191583
 lib/metadata/lv_manip.c          |  3 +++
191583
 lib/metadata/metadata-exported.h |  8 +++++++-
191583
 lib/metadata/thin_manip.c        |  1 +
191583
 tools/lvconvert.c                | 20 ++++++++++++--------
191583
 udev/11-dm-lvm.rules.in          |  2 +-
191583
 udev/69-dm-lvm-metad.rules.in    |  3 ++-
191583
 14 files changed, 79 insertions(+), 35 deletions(-)
191583
191583
diff --git a/WHATS_NEW b/WHATS_NEW
191583
index 7fd107a..2532a99 100644
191583
--- a/WHATS_NEW
191583
+++ b/WHATS_NEW
191583
@@ -1,5 +1,8 @@
191583
 Version 2.02.104 - 
191583
 ===================================
191583
+  Fix missing lvmetad scan for PVs found on MD partitions.
191583
+  Add internal flag for temporary LVs to properly direct udev to not interfere.
191583
+  Respect DM_UDEV_DISABLE_OTHER_RULES_FLAG in lvmetad udev rules.
191583
   Workaround VG refresh race during autoactivation by retrying the refresh.
191583
   Add dev-block-<major>:<minor>.device systemd alias for complete PV tracking.
191583
   Use major:minor as short form of --major and --minor arg for pvscan --cache.
191583
diff --git a/daemons/clvmd/lvm-functions.c b/daemons/clvmd/lvm-functions.c
191583
index f544218..b15732f 100644
191583
--- a/daemons/clvmd/lvm-functions.c
191583
+++ b/daemons/clvmd/lvm-functions.c
191583
@@ -401,7 +401,7 @@ static int do_activate_lv(char *resource, unsigned char command, unsigned char l
191583
 	}
191583
 
191583
 	/* Now activate it */
191583
-	if (!lv_activate(cmd, resource, exclusive, 0, NULL))
191583
+	if (!lv_activate(cmd, resource, exclusive, 0, 0, NULL))
191583
 		goto error;
191583
 
191583
 	return 0;
191583
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
191583
index c077113..6ab95aa 100644
191583
--- a/lib/activate/activate.c
191583
+++ b/lib/activate/activate.c
191583
@@ -338,12 +338,12 @@ int lv_activation_filter(struct cmd_context *cmd, const char *lvid_s,
191583
 	return 1;
191583
 }
191583
 int lv_activate(struct cmd_context *cmd, const char *lvid_s, int exclusive, int noscan,
191583
-		struct logical_volume *lv)
191583
+		int temporary, struct logical_volume *lv)
191583
 {
191583
 	return 1;
191583
 }
191583
 int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s, int exclusive,
191583
-			    int noscan, struct logical_volume *lv)
191583
+			    int noscan, int temporary, struct logical_volume *lv)
191583
 {
191583
 	return 1;
191583
 }
191583
@@ -2028,10 +2028,11 @@ static int _lv_activate(struct cmd_context *cmd, const char *lvid_s,
191583
 	if (filter)
191583
 		laopts->read_only = _passes_readonly_filter(cmd, lv);
191583
 
191583
-	log_debug_activation("Activating %s/%s%s%s%s.", lv->vg->name, lv->name,
191583
+	log_debug_activation("Activating %s/%s%s%s%s%s.", lv->vg->name, lv->name,
191583
 			     laopts->exclusive ? " exclusively" : "",
191583
 			     laopts->read_only ? " read-only" : "",
191583
-			     laopts->noscan ? " noscan" : "");
191583
+			     laopts->noscan ? " noscan" : "",
191583
+			     laopts->temporary ? " temporary" : "");
191583
 
191583
 	if (!lv_info(cmd, lv, 0, &info, 0, 0))
191583
 		goto_out;
191583
@@ -2069,9 +2070,11 @@ out:
191583
 
191583
 /* Activate LV */
191583
 int lv_activate(struct cmd_context *cmd, const char *lvid_s, int exclusive,
191583
-		int noscan, struct logical_volume *lv)
191583
+		int noscan, int temporary, struct logical_volume *lv)
191583
 {
191583
-	struct lv_activate_opts laopts = { .exclusive = exclusive, .noscan = noscan };
191583
+	struct lv_activate_opts laopts = { .exclusive = exclusive,
191583
+					   .noscan = noscan,
191583
+					   .temporary = temporary };
191583
 
191583
 	if (!_lv_activate(cmd, lvid_s, &laopts, 0, lv))
191583
 		return_0;
191583
@@ -2081,9 +2084,11 @@ int lv_activate(struct cmd_context *cmd, const char *lvid_s, int exclusive,
191583
 
191583
 /* Activate LV only if it passes filter */
191583
 int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s, int exclusive,
191583
-			    int noscan, struct logical_volume *lv)
191583
+			    int noscan, int temporary, struct logical_volume *lv)
191583
 {
191583
-	struct lv_activate_opts laopts = { .exclusive = exclusive, .noscan = noscan  };
191583
+	struct lv_activate_opts laopts = { .exclusive = exclusive,
191583
+					   .noscan = noscan,
191583
+					   .temporary = temporary };
191583
 
191583
 	if (!_lv_activate(cmd, lvid_s, &laopts, 1, lv))
191583
 		return_0;
191583
diff --git a/lib/activate/activate.h b/lib/activate/activate.h
191583
index 4eac320..df888cd 100644
191583
--- a/lib/activate/activate.h
191583
+++ b/lib/activate/activate.h
191583
@@ -38,7 +38,18 @@ struct lv_activate_opts {
191583
 	int skip_in_use;
191583
 	unsigned revert;
191583
 	unsigned read_only;
191583
-	unsigned noscan;
191583
+	unsigned noscan;	/* Mark this LV to avoid its scanning. This also
191583
+				   directs udev to use proper udev flag to avoid
191583
+				   any scanning in udev. This udev flag is automatically
191583
+				   dropped in udev db on any spurious event that follows. */
191583
+	unsigned temporary;	/* Mark this LV as temporary. It means, the LV
191583
+				 * is created, used and deactivated within single
191583
+				 * LVM command execution. Such LVs are mostly helper
191583
+				 * LVs to do some action or cleanup before the proper
191583
+				 * LV is created. This also directs udev to use proper
191583
+				 * set of flags to avoid any scanning in udev. These udev
191583
+				 * flags are persistent in udev db for any spurious event
191583
+				 * that follows. */
191583
 };
191583
 
191583
 /* target attribute flags */
191583
@@ -81,9 +92,10 @@ int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid_s, unsigned o
191583
 int lv_resume(struct cmd_context *cmd, const char *lvid_s, unsigned origin_only, struct logical_volume *lv);
191583
 int lv_resume_if_active(struct cmd_context *cmd, const char *lvid_s,
191583
 			unsigned origin_only, unsigned exclusive, unsigned revert, struct logical_volume *lv);
191583
-int lv_activate(struct cmd_context *cmd, const char *lvid_s, int exclusive, int noscan, struct logical_volume *lv);
191583
-int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s,
191583
-			    int exclusive, int noscan, struct logical_volume *lv);
191583
+int lv_activate(struct cmd_context *cmd, const char *lvid_s, int exclusive,
191583
+		int noscan, int temporary, struct logical_volume *lv);
191583
+int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s, int exclusive,
191583
+			    int noscan, int temporary, struct logical_volume *lv);
191583
 int lv_deactivate(struct cmd_context *cmd, const char *lvid_s, struct logical_volume *lv);
191583
 
191583
 int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv);
191583
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
191583
index 0f5a04c..0b911f2 100644
191583
--- a/lib/activate/dev_manager.c
191583
+++ b/lib/activate/dev_manager.c
191583
@@ -1400,7 +1400,7 @@ static int _check_udev_fallback(struct cmd_context *cmd)
191583
 #endif /* UDEV_SYNC_SUPPORT */
191583
 
191583
 static uint16_t _get_udev_flags(struct dev_manager *dm, struct logical_volume *lv,
191583
-				const char *layer, uint16_t flags)
191583
+				const char *layer, int noscan, int temporary)
191583
 {
191583
 	uint16_t udev_flags = 0;
191583
 
191583
@@ -1449,9 +1449,14 @@ static uint16_t _get_udev_flags(struct dev_manager *dm, struct logical_volume *l
191583
 			      DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG;
191583
 
191583
 	/*
191583
-	 * Firmly set requested flags.
191583
+	 * LVM subsystem specific flags.
191583
 	 */
191583
-	udev_flags |= flags;
191583
+	if (noscan)
191583
+		udev_flags |= DM_SUBSYSTEM_UDEV_FLAG0;
191583
+
191583
+	if (temporary)
191583
+		udev_flags |= DM_UDEV_DISABLE_DISK_RULES_FLAG |
191583
+			      DM_UDEV_DISABLE_OTHER_RULES_FLAG;
191583
 
191583
 	return udev_flags;
191583
 }
191583
@@ -1499,7 +1504,7 @@ static int _add_dev_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
191583
 	}
191583
 
191583
 	if (info.exists && !dm_tree_add_dev_with_udev_flags(dtree, info.major, info.minor,
191583
-							_get_udev_flags(dm, lv, layer, 0))) {
191583
+							_get_udev_flags(dm, lv, layer, 0, 0))) {
191583
 		log_error("Failed to add device (%" PRIu32 ":%" PRIu32") to dtree",
191583
 			  info.major, info.minor);
191583
 		return 0;
191583
@@ -2340,7 +2345,7 @@ static int _set_udev_flags_for_children(struct dev_manager *dm,
191583
 		}
191583
 
191583
 		dm_tree_node_set_udev_flags(child,
191583
-					    _get_udev_flags(dm, lvl->lv, NULL, 0));
191583
+					    _get_udev_flags(dm, lvl->lv, NULL, 0, 0));
191583
 	}
191583
 
191583
 	return 1;
191583
@@ -2417,8 +2422,7 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
191583
 					     read_only_lv(lv, laopts),
191583
 					     ((lv->vg->status & PRECOMMITTED) | laopts->revert) ? 1 : 0,
191583
 					     lvlayer,
191583
-					     _get_udev_flags(dm, lv, layer,
191583
-						laopts->noscan ? LVM_UDEV_NOSCAN_FLAG : 0))))
191583
+					     _get_udev_flags(dm, lv, layer, laopts->noscan, laopts->temporary))))
191583
 		return_0;
191583
 
191583
 	/* Store existing name so we can do rename later */
191583
diff --git a/lib/format_text/flags.c b/lib/format_text/flags.c
191583
index a27b791..e31429e 100644
191583
--- a/lib/format_text/flags.c
191583
+++ b/lib/format_text/flags.c
191583
@@ -62,6 +62,7 @@ static const struct flag _lv_flags[] = {
191583
 	{LV_WRITEMOSTLY, "WRITEMOSTLY", STATUS_FLAG},
191583
 	{LV_ACTIVATION_SKIP, "ACTIVATION_SKIP", COMPATIBLE_FLAG},
191583
 	{LV_NOSCAN, NULL, 0},
191583
+	{LV_TEMPORARY, NULL, 0},
191583
 	{POOL_METADATA_SPARE, NULL, 0},
191583
 	{RAID, NULL, 0},
191583
 	{RAID_META, NULL, 0},
191583
diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c
191583
index b6b2b10..ab3dabd 100644
191583
--- a/lib/locking/file_locking.c
191583
+++ b/lib/locking/file_locking.c
191583
@@ -305,7 +305,8 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
191583
 			break;
191583
 		case LCK_READ:
191583
 			log_very_verbose("Locking LV %s (R)", resource);
191583
-			if (!lv_activate_with_filter(cmd, resource, 0, lv->status & LV_NOSCAN ? 1 : 0, lv_ondisk(lv)))
191583
+			if (!lv_activate_with_filter(cmd, resource, 0, lv->status & LV_NOSCAN ? 1 : 0,
191583
+						     lv->status & LV_TEMPORARY ? 1 : 0, lv_ondisk(lv)))
191583
 				return 0;
191583
 			break;
191583
 		case LCK_PREAD:
191583
@@ -318,7 +319,8 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
191583
 			break;
191583
 		case LCK_EXCL:
191583
 			log_very_verbose("Locking LV %s (EX)", resource);
191583
-			if (!lv_activate_with_filter(cmd, resource, 1, lv->status & LV_NOSCAN ? 1 : 0, lv_ondisk(lv)))
191583
+			if (!lv_activate_with_filter(cmd, resource, 1, lv->status & LV_NOSCAN ? 1 : 0,
191583
+						     lv->status & LV_TEMPORARY ? 1 : 0, lv_ondisk(lv)))
191583
 				return 0;
191583
 			break;
191583
 		default:
191583
diff --git a/lib/locking/no_locking.c b/lib/locking/no_locking.c
191583
index 4772706..dac2f80 100644
191583
--- a/lib/locking/no_locking.c
191583
+++ b/lib/locking/no_locking.c
191583
@@ -48,11 +48,13 @@ static int _no_lock_resource(struct cmd_context *cmd, const char *resource,
191583
 		case LCK_UNLOCK:
191583
 			return lv_resume_if_active(cmd, resource, (flags & LCK_ORIGIN_ONLY) ? 1: 0, 0, (flags & LCK_REVERT) ? 1 : 0, lv_ondisk(lv));
191583
 		case LCK_READ:
191583
-			return lv_activate_with_filter(cmd, resource, 0, lv->status & LV_NOSCAN ? 1 : 0, lv_ondisk(lv));
191583
+			return lv_activate_with_filter(cmd, resource, 0, lv->status & LV_NOSCAN ? 1 : 0,
191583
+						       lv->status & LV_TEMPORARY ? 1 : 0, lv_ondisk(lv));
191583
 		case LCK_WRITE:
191583
 			return lv_suspend_if_active(cmd, resource, (flags & LCK_ORIGIN_ONLY) ? 1 : 0, 0, lv_ondisk(lv), lv);
191583
 		case LCK_EXCL:
191583
-			return lv_activate_with_filter(cmd, resource, 1, lv->status & LV_NOSCAN ? 1 : 0, lv_ondisk(lv));
191583
+			return lv_activate_with_filter(cmd, resource, 1, lv->status & LV_NOSCAN ? 1 : 0,
191583
+						       lv->status & LV_TEMPORARY ? 1 : 0, lv_ondisk(lv));
191583
 		default:
191583
 			break;
191583
 		}
191583
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
191583
index 22327d7..8884c50 100644
191583
--- a/lib/metadata/lv_manip.c
191583
+++ b/lib/metadata/lv_manip.c
191583
@@ -5983,6 +5983,9 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
191583
 	if (lp->zero)
191583
 		lv->status |= LV_NOSCAN;
191583
 
191583
+	if (lp->temporary)
191583
+		lv->status |= LV_TEMPORARY;
191583
+
191583
 	if (lv_is_thin_pool(lv)) {
191583
 		if (is_change_activating(lp->activate)) {
191583
 			if (vg_is_clustered(lv->vg)) {
191583
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
191583
index 1e9543a..c00e4e5 100644
191583
--- a/lib/metadata/metadata-exported.h
191583
+++ b/lib/metadata/metadata-exported.h
191583
@@ -102,7 +102,12 @@
191583
 #define LV_WRITEMOSTLY		UINT64_C(0x0000020000000000)	/* LV (RAID1) */
191583
 
191583
 #define LV_ACTIVATION_SKIP	UINT64_C(0x0000040000000000)	/* LV */
191583
-#define LV_NOSCAN		UINT64_C(0x0000080000000000)	/* LV */
191583
+#define LV_NOSCAN		UINT64_C(0x0000080000000000)	/* LV - internal use only - the LV
191583
+									should not be scanned */
191583
+#define LV_TEMPORARY		UINT64_C(0x0000100000000000)	/* LV - internal use only - the LV
191583
+								        is supposed to be created and
191583
+									removed during single LVM
191583
+									command execution. */
191583
 
191583
 /* Format features flags */
191583
 #define FMT_SEGMENTS		0x00000001U	/* Arbitrary segment params? */
191583
@@ -721,6 +726,7 @@ struct lvcreate_params {
191583
 	int log_count; /* mirror */
191583
 	int nosync; /* mirror */
191583
 	int poolmetadataspare; /* thin pool */
191583
+	int temporary; /* temporary LV */
191583
 #define ACTIVATION_SKIP_SET		0x01 /* request to set LV activation skip flag state */
191583
 #define ACTIVATION_SKIP_SET_ENABLED	0x02 /* set the LV activation skip flag state to 'enabled' */
191583
 #define ACTIVATION_SKIP_IGNORE		0x04 /* request to ignore LV activation skip flag (if any) */
191583
diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c
191583
index a6e0fc2..bd5b117 100644
191583
--- a/lib/metadata/thin_manip.c
191583
+++ b/lib/metadata/thin_manip.c
191583
@@ -809,6 +809,7 @@ static struct logical_volume *_alloc_pool_metadata_spare(struct volume_group *vg
191583
 		.stripes = 1,
191583
 		.vg_name = vg->name,
191583
 		.zero = 1,
191583
+		.temporary = 1,
191583
 	};
191583
 
191583
 	dm_list_init(&lp.tags);
191583
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
191583
index 1098642..170d76f 100644
191583
--- a/tools/lvconvert.c
191583
+++ b/tools/lvconvert.c
191583
@@ -2431,14 +2431,8 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
191583
 			goto mda_write;
191583
 		}
191583
 
191583
-		metadata_lv->status |= LV_NOSCAN;
191583
-		if (!lv_is_active(metadata_lv) &&
191583
-		    !activate_lv_local(cmd, metadata_lv)) {
191583
-			log_error("Aborting. Failed to activate thin metadata lv.");
191583
-			return 0;
191583
-		}
191583
-		if (!set_lv(cmd, metadata_lv, UINT64_C(0), 0)) {
191583
-			log_error("Aborting. Failed to wipe thin metadata lv.");
191583
+		if (!deactivate_lv(cmd, metadata_lv)) {
191583
+			log_error("Aborting. Failed to deactivate thin metadata lv.");
191583
 			return 0;
191583
 		}
191583
 
191583
@@ -2458,6 +2452,16 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
191583
 					&lp->thin_chunk_size_calc_policy, &lp->chunk_size,
191583
 					&lp->discards, &lp->poolmetadata_size, &lp->zero))
191583
 			return_0;
191583
+
191583
+		metadata_lv->status |= LV_TEMPORARY;
191583
+		if (!activate_lv_local(cmd, metadata_lv)) {
191583
+			log_error("Aborting. Failed to activate thin metadata lv.");
191583
+			return 0;
191583
+		}
191583
+		if (!set_lv(cmd, metadata_lv, UINT64_C(0), 0)) {
191583
+			log_error("Aborting. Failed to wipe thin metadata lv.");
191583
+			return 0;
191583
+		}
191583
 	}
191583
 
191583
 	if (!deactivate_lv(cmd, metadata_lv)) {
191583
diff --git a/udev/11-dm-lvm.rules.in b/udev/11-dm-lvm.rules.in
191583
index 5032280..9ca0375 100644
191583
--- a/udev/11-dm-lvm.rules.in
191583
+++ b/udev/11-dm-lvm.rules.in
191583
@@ -32,7 +32,7 @@ IMPORT{program}="(DM_EXEC)/dmsetup splitname --nameprefixes --noheadings --rows
191583
 # uevent that follows for this LV, even an artificially generated one).
191583
 ENV{DM_SUBSYSTEM_UDEV_FLAG0}=="1", ENV{DM_NOSCAN}="1", ENV{DM_DISABLE_OTHER_RULES_FLAG_OLD}="$env{DM_UDEV_DISABLE_OTHER_RULES_FLAG}", ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="1"
191583
 ENV{DM_SUBSYSTEM_UDEV_FLAG0}!="1", IMPORT{db}="DM_NOSCAN", IMPORT{db}="DM_DISABLE_OTHER_RULES_FLAG_OLD"
191583
-ENV{DM_SUBSYSTEM_UDEV_FLAG0}!="1", ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="$env{DM_DISABLE_OTHER_RULES_FLAG_OLD}", \
191583
+ENV{DM_SUBSYSTEM_UDEV_FLAG0}!="1", ENV{DM_NOSCAN}=="1", ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}="$env{DM_DISABLE_OTHER_RULES_FLAG_OLD}", \
191583
 				   ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG_OLD}="", ENV{DM_NOSCAN}=""
191583
 
191583
 ENV{DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG}=="1", GOTO="lvm_end"
191583
diff --git a/udev/69-dm-lvm-metad.rules.in b/udev/69-dm-lvm-metad.rules.in
191583
index 3e303b1..5b15b6f 100644
191583
--- a/udev/69-dm-lvm-metad.rules.in
191583
+++ b/udev/69-dm-lvm-metad.rules.in
191583
@@ -17,7 +17,7 @@
191583
 SUBSYSTEM!="block", GOTO="lvm_end"
191583
 (LVM_EXEC_RULE)
191583
 
191583
-ENV{DM_NOSCAN}=="1", GOTO="lvm_end"
191583
+ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", GOTO="lvm_end"
191583
 
191583
 # If the PV label got lost, inform lvmetad immediately.
191583
 # Detect the lost PV label by comparing previous ID_FS_TYPE value with current one.
191583
@@ -51,6 +51,7 @@ KERNEL!="md[0-9]*", GOTO="next"
191583
 IMPORT{db}="LVM_MD_PV_ACTIVATED"
191583
 ACTION=="add", ENV{LVM_MD_PV_ACTIVATED}=="1", GOTO="lvm_scan"
191583
 ACTION=="change", ENV{LVM_MD_PV_ACTIVATED}!="1", TEST=="md/array_state", ENV{LVM_MD_PV_ACTIVATED}="1", GOTO="lvm_scan"
191583
+ACTION=="add", KERNEL=="md[0-9]*p[0-9]*", GOTO="lvm_scan"
191583
 GOTO="lvm_end"
191583
 
191583
 # Loop device: