mrc0mmand / rpms / lvm2

Forked from rpms/lvm2 2 years ago
Clone

Blame SOURCES/lvm2-2_02_182-scan-use-full-md-filter-when-md-1.0-devices-are-pres.patch

12cbd3
 lib/cache/lvmcache.c               |  2 +-
12cbd3
 lib/device/dev-md.c                | 27 ++++++++++----
12cbd3
 lib/device/dev-type.h              |  1 +
12cbd3
 lib/filters/filter-md.c            | 74 +++++++++++++++++++-------------------
12cbd3
 lib/label/label.c                  | 14 ++++++++
12cbd3
 test/shell/pvcreate-md-fake-hdr.sh |  3 +-
12cbd3
 6 files changed, 75 insertions(+), 46 deletions(-)
12cbd3
12cbd3
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
12cbd3
index 2fba3ff..f55a14c 100644
12cbd3
--- a/lib/cache/lvmcache.c
12cbd3
+++ b/lib/cache/lvmcache.c
12cbd3
@@ -1002,7 +1002,7 @@ int lvmcache_dev_is_unchosen_duplicate(struct device *dev)
12cbd3
  * unused_duplicate_devs list, and restrict what we allow done with it.
12cbd3
  *
12cbd3
  * In the case of md components, we usually filter these out in filter-md,
12cbd3
- * but in the special case of md superblocks <= 1.0 where the superblock
12cbd3
+ * but in the special case of md superblock version 1.0 where the superblock
12cbd3
  * is at the end of the device, filter-md doesn't always eliminate them
12cbd3
  * first, so we eliminate them here.
12cbd3
  *
12cbd3
diff --git a/lib/device/dev-md.c b/lib/device/dev-md.c
12cbd3
index f5a736f..7196dc0 100644
12cbd3
--- a/lib/device/dev-md.c
12cbd3
+++ b/lib/device/dev-md.c
12cbd3
@@ -142,13 +142,6 @@ static int _native_dev_is_md(struct device *dev, uint64_t *offset_found, int ful
12cbd3
 	 * command if it should do a full check (cmd->use_full_md_check),
12cbd3
 	 * and set it for commands that could possibly write to an md dev
12cbd3
 	 * (pvcreate/vgcreate/vgextend).
12cbd3
-	 *
12cbd3
-	 * For old md versions with magic numbers at the end of devices,
12cbd3
-	 * the md dev components won't be filtered out here when full is 0,
12cbd3
-	 * so they will be scanned, and appear as duplicate PVs in lvmcache.
12cbd3
-	 * The md device itself will be chosen as the primary duplicate,
12cbd3
-	 * and the components are dropped from the list of duplicates in,
12cbd3
-	 * i.e. a kind of post-scan filtering.
12cbd3
 	 */
12cbd3
 	if (!full) {
12cbd3
 		sb_offset = 0;
12cbd3
@@ -414,6 +407,26 @@ unsigned long dev_md_stripe_width(struct dev_types *dt, struct device *dev)
12cbd3
 	return stripe_width_sectors;
12cbd3
 }
12cbd3
 
12cbd3
+int dev_is_md_with_end_superblock(struct dev_types *dt, struct device *dev)
12cbd3
+{
12cbd3
+	char version_string[MD_MAX_SYSFS_SIZE];
12cbd3
+	const char *attribute = "metadata_version";
12cbd3
+
12cbd3
+	if (MAJOR(dev->dev) != dt->md_major)
12cbd3
+		return 0;
12cbd3
+
12cbd3
+	if (_md_sysfs_attribute_scanf(dt, dev, attribute,
12cbd3
+				      "%s", &version_string) != 1)
12cbd3
+		return -1;
12cbd3
+
12cbd3
+	log_very_verbose("Device %s %s is %s.",
12cbd3
+			 dev_name(dev), attribute, version_string);
12cbd3
+
12cbd3
+	if (!strcmp(version_string, "1.0"))
12cbd3
+		return 1;
12cbd3
+	return 0;
12cbd3
+}
12cbd3
+
12cbd3
 #else
12cbd3
 
12cbd3
 int dev_is_md(struct device *dev __attribute__((unused)),
12cbd3
diff --git a/lib/device/dev-type.h b/lib/device/dev-type.h
12cbd3
index 843e254..f629a02 100644
12cbd3
--- a/lib/device/dev-type.h
12cbd3
+++ b/lib/device/dev-type.h
12cbd3
@@ -76,6 +76,7 @@ int wipe_known_signatures(struct cmd_context *cmd, struct device *dev, const cha
12cbd3
 
12cbd3
 /* Type-specific device properties */
12cbd3
 unsigned long dev_md_stripe_width(struct dev_types *dt, struct device *dev);
12cbd3
+int dev_is_md_with_end_superblock(struct dev_types *dt, struct device *dev);
12cbd3
 
12cbd3
 /* Partitioning */
12cbd3
 int major_max_partitions(struct dev_types *dt, int major);
12cbd3
diff --git a/lib/filters/filter-md.c b/lib/filters/filter-md.c
12cbd3
index ab97b59..ad5b8e4 100644
12cbd3
--- a/lib/filters/filter-md.c
12cbd3
+++ b/lib/filters/filter-md.c
12cbd3
@@ -29,43 +29,43 @@
12cbd3
  *
12cbd3
  * (This is assuming lvm.conf md_component_detection=1.)
12cbd3
  *
12cbd3
- * If lvm does *not* ignore the components, then lvm will read lvm
12cbd3
- * labels from the md dev and from the component devs, and will see
12cbd3
- * them all as duplicates of each other.  LVM duplicate resolution
12cbd3
- * will then kick in and keep the md dev around to use and ignore
12cbd3
- * the components.
12cbd3
- *
12cbd3
- * It is better to exclude the components as early as possible during
12cbd3
- * lvm processing, ideally before lvm even looks for labels on the
12cbd3
- * components, so that duplicate resolution can be avoided.  There are
12cbd3
- * a number of ways that md components can be excluded earlier than
12cbd3
- * the duplicate resolution phase:
12cbd3
- *
12cbd3
- * - When external_device_info_source="udev", lvm discovers a device is
12cbd3
- *   an md component by asking udev during the initial filtering phase.
12cbd3
- *   However, lvm's default is to not use udev for this.  The
12cbd3
- *   alternative is "native" detection in which lvm tries to detect
12cbd3
- *   md components itself.
12cbd3
- *
12cbd3
- * - When using native detection, lvm's md filter looks for the md
12cbd3
- *   superblock at the start of devices.  It will see the md superblock
12cbd3
- *   on the components, exclude them in the md filter, and avoid
12cbd3
- *   handling them later in duplicate resolution.
12cbd3
- *
12cbd3
- * - When using native detection, lvm's md filter will not detect
12cbd3
- *   components when the md device has an older superblock version that
12cbd3
- *   places the superblock at the end of the device.  This case will
12cbd3
- *   fall back to duplicate resolution to exclude components.
12cbd3
- *
12cbd3
- * A variation of the description above occurs for lvm commands that
12cbd3
- * intend to create new PVs on devices (pvcreate, vgcreate, vgextend).
12cbd3
- * For these commands, the native md filter also reads the end of all
12cbd3
- * devices to check for the odd md superblocks.
12cbd3
- *
12cbd3
- * (The reason that external_device_info_source is not set to udev by
12cbd3
- * default is that there have be issues with udev not being promptly
12cbd3
- * or reliably updated about md state changes, causing the udev info
12cbd3
- * that lvm uses to be occasionally wrong.)
12cbd3
+ * If lvm does *not* ignore the components, then lvm may read lvm
12cbd3
+ * labels from the component devs and potentially the md dev,
12cbd3
+ * which can trigger duplicate detection, and/or cause lvm to display
12cbd3
+ * md components as PVs rather than ignoring them.
12cbd3
+ *
12cbd3
+ * If scanning md componenents causes duplicates to be seen, then
12cbd3
+ * the lvm duplicate resolution will exclude the components.
12cbd3
+ *
12cbd3
+ * The lvm md filter has three modes:
12cbd3
+ *
12cbd3
+ * 1. look for md superblock at the start of the device
12cbd3
+ * 2. look for md superblock at the start and end of the device
12cbd3
+ * 3. use udev to detect components
12cbd3
+ *
12cbd3
+ * mode 1 will not detect and exclude components of md devices
12cbd3
+ * that use superblock version 1.0 which is at the end of the device.
12cbd3
+ *
12cbd3
+ * mode 2 will detect these, but mode 2 doubles the i/o done by label
12cbd3
+ * scan, since there's a read at both the start and end of every device.
12cbd3
+ *
12cbd3
+ * mode 3 is used when external_device_info_source="udev".  It does
12cbd3
+ * not require any io from lvm, but this mode is not used by default
12cbd3
+ * because there have been problems getting reliable info from udev.
12cbd3
+ *
12cbd3
+ * lvm uses mode 2 when:
12cbd3
+ *
12cbd3
+ * - the command is pvcreate/vgcreate/vgextend, which format new
12cbd3
+ *   devices, and if the user ran these commands on a component
12cbd3
+ *   device of an md device 1.0, then it would cause problems.
12cbd3
+ *   FIXME: this would only really need to scan the end of the
12cbd3
+ *   devices being formatted, not all devices.
12cbd3
+ *
12cbd3
+ * - it sees an md device on the system using version 1.0.
12cbd3
+ *   The point of this is just to avoid displaying md components
12cbd3
+ *   from the 'pvs' command.
12cbd3
+ *   FIXME: the cost (double i/o) may not be worth the benefit
12cbd3
+ *   (not showing md components).
12cbd3
  */
12cbd3
 
12cbd3
 /*
12cbd3
diff --git a/lib/label/label.c b/lib/label/label.c
12cbd3
index e7e3997..6fb35ff 100644
12cbd3
--- a/lib/label/label.c
12cbd3
+++ b/lib/label/label.c
12cbd3
@@ -872,6 +872,20 @@ int label_scan(struct cmd_context *cmd)
12cbd3
 			bcache_invalidate_fd(scan_bcache, dev->bcache_fd);
12cbd3
 			_scan_dev_close(dev);
12cbd3
 		}
12cbd3
+
12cbd3
+		/*
12cbd3
+		 * When md devices exist that use the old superblock at the
12cbd3
+		 * end of the device, then in order to detect and filter out
12cbd3
+		 * the component devices of those md devs, we need to enable
12cbd3
+		 * the full md filter which scans both the start and the end
12cbd3
+		 * of every device.  This doubles the amount of scanning i/o,
12cbd3
+		 * which we want to avoid.  FIXME: it may not be worth the
12cbd3
+		 * cost of double i/o just to avoid displaying md component
12cbd3
+		 * devs in 'pvs', which is a pretty harmless effect from a
12cbd3
+		 * pretty uncommon situation.
12cbd3
+		 */
12cbd3
+		if (dev_is_md_with_end_superblock(cmd->dev_types, dev))
12cbd3
+			cmd->use_full_md_check = 1;
12cbd3
 	};
12cbd3
 	dev_iter_destroy(iter);
12cbd3
 
12cbd3
diff --git a/test/shell/pvcreate-md-fake-hdr.sh b/test/shell/pvcreate-md-fake-hdr.sh
12cbd3
index b89fe43..4c9ac7c 100644
12cbd3
--- a/test/shell/pvcreate-md-fake-hdr.sh
12cbd3
+++ b/test/shell/pvcreate-md-fake-hdr.sh
12cbd3
@@ -89,6 +89,7 @@ sleep 1
12cbd3
 # (when mdadm supports repair)
12cbd3
 if mdadm --action=repair "$mddev" ; then
12cbd3
 	sleep 1
12cbd3
+	pvscan -vvvv
12cbd3
 	# should be showing correctly PV3 & PV4
12cbd3
-	pvs
12cbd3
+	pvs -vvvv "$dev3" "$dev4"
12cbd3
 fi