Blame SOURCES/lvm2-2_02_183-pvscan-lvmetad-use-udev-info-to-improve-md-component.patch

12cbd3
 lib/device/dev-md.c   | 14 ++++++++++--
12cbd3
 lib/device/dev-type.c | 62 +++++++++++++++++++++++++++++++++++++++++----------
12cbd3
 lib/device/dev-type.h |  1 +
12cbd3
 tools/pvscan.c        |  3 ++-
12cbd3
 4 files changed, 65 insertions(+), 15 deletions(-)
12cbd3
12cbd3
diff --git a/lib/device/dev-md.c b/lib/device/dev-md.c
12cbd3
index 185499b..9728507 100644
12cbd3
--- a/lib/device/dev-md.c
12cbd3
+++ b/lib/device/dev-md.c
12cbd3
@@ -190,14 +190,24 @@ out:
12cbd3
 
12cbd3
 int dev_is_md(struct device *dev, uint64_t *offset_found, int full)
12cbd3
 {
12cbd3
+	int ret;
12cbd3
 
12cbd3
 	/*
12cbd3
 	 * If non-native device status source is selected, use it
12cbd3
 	 * only if offset_found is not requested as this
12cbd3
 	 * information is not in udev db.
12cbd3
 	 */
12cbd3
-	if ((dev->ext.src == DEV_EXT_NONE) || offset_found)
12cbd3
-		return _native_dev_is_md(dev, offset_found, full);
12cbd3
+	if ((dev->ext.src == DEV_EXT_NONE) || offset_found) {
12cbd3
+		ret = _native_dev_is_md(dev, offset_found, full);
12cbd3
+
12cbd3
+		if (!full) {
12cbd3
+			if (!ret || (ret == -EAGAIN)) {
12cbd3
+				if (udev_dev_is_md_component(dev))
12cbd3
+					return 1;
12cbd3
+			}
12cbd3
+		}
12cbd3
+		return ret;
12cbd3
+	}
12cbd3
 
12cbd3
 	if (dev->ext.src == DEV_EXT_UDEV)
12cbd3
 		return _udev_dev_is_md(dev);
12cbd3
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
12cbd3
index eda7982..331fe07 100644
12cbd3
--- a/lib/device/dev-type.c
12cbd3
+++ b/lib/device/dev-type.c
12cbd3
@@ -1003,25 +1003,23 @@ int dev_is_rotational(struct dev_types *dt, struct device *dev)
12cbd3
  *        failed already due to timeout in udev - in both cases the
12cbd3
  *        udev_device_get_is_initialized returns 0.
12cbd3
  */
12cbd3
-#define UDEV_DEV_IS_MPATH_COMPONENT_ITERATION_COUNT 100
12cbd3
-#define UDEV_DEV_IS_MPATH_COMPONENT_USLEEP 100000
12cbd3
+#define UDEV_DEV_IS_COMPONENT_ITERATION_COUNT 100
12cbd3
+#define UDEV_DEV_IS_COMPONENT_USLEEP 100000
12cbd3
 
12cbd3
-int udev_dev_is_mpath_component(struct device *dev)
12cbd3
+static struct udev_device *_udev_get_dev(struct device *dev)
12cbd3
 {
12cbd3
 	struct udev *udev_context = udev_get_library_context();
12cbd3
 	struct udev_device *udev_device = NULL;
12cbd3
-	const char *value;
12cbd3
 	int initialized = 0;
12cbd3
 	unsigned i = 0;
12cbd3
-	int ret = 0;
12cbd3
 
12cbd3
 	if (!udev_context) {
12cbd3
 		log_warn("WARNING: No udev context available to check if device %s is multipath component.", dev_name(dev));
12cbd3
-		return 0;
12cbd3
+		return NULL;
12cbd3
 	}
12cbd3
 
12cbd3
 	while (1) {
12cbd3
-		if (i >= UDEV_DEV_IS_MPATH_COMPONENT_ITERATION_COUNT)
12cbd3
+		if (i >= UDEV_DEV_IS_COMPONENT_ITERATION_COUNT)
12cbd3
 			break;
12cbd3
 
12cbd3
 		if (udev_device)
12cbd3
@@ -1029,7 +1027,7 @@ int udev_dev_is_mpath_component(struct device *dev)
12cbd3
 
12cbd3
 		if (!(udev_device = udev_device_new_from_devnum(udev_context, 'b', dev->dev))) {
12cbd3
 			log_warn("WARNING: Failed to get udev device handler for device %s.", dev_name(dev));
12cbd3
-			return 0;
12cbd3
+			return NULL;
12cbd3
 		}
12cbd3
 
12cbd3
 #ifdef HAVE_LIBUDEV_UDEV_DEVICE_GET_IS_INITIALIZED
12cbd3
@@ -1041,19 +1039,32 @@ int udev_dev_is_mpath_component(struct device *dev)
12cbd3
 #endif
12cbd3
 
12cbd3
 		log_debug("Device %s not initialized in udev database (%u/%u, %u microseconds).", dev_name(dev),
12cbd3
-			   i + 1, UDEV_DEV_IS_MPATH_COMPONENT_ITERATION_COUNT,
12cbd3
-			   i * UDEV_DEV_IS_MPATH_COMPONENT_USLEEP);
12cbd3
+			   i + 1, UDEV_DEV_IS_COMPONENT_ITERATION_COUNT,
12cbd3
+			   i * UDEV_DEV_IS_COMPONENT_USLEEP);
12cbd3
 
12cbd3
-		usleep(UDEV_DEV_IS_MPATH_COMPONENT_USLEEP);
12cbd3
+		usleep(UDEV_DEV_IS_COMPONENT_USLEEP);
12cbd3
 		i++;
12cbd3
 	}
12cbd3
 
12cbd3
 	if (!initialized) {
12cbd3
 		log_warn("WARNING: Device %s not initialized in udev database even after waiting %u microseconds.",
12cbd3
-			  dev_name(dev), i * UDEV_DEV_IS_MPATH_COMPONENT_USLEEP);
12cbd3
+			  dev_name(dev), i * UDEV_DEV_IS_COMPONENT_USLEEP);
12cbd3
 		goto out;
12cbd3
 	}
12cbd3
 
12cbd3
+out:
12cbd3
+	return udev_device;
12cbd3
+}
12cbd3
+
12cbd3
+int udev_dev_is_mpath_component(struct device *dev)
12cbd3
+{
12cbd3
+	struct udev_device *udev_device;
12cbd3
+	const char *value;
12cbd3
+	int ret = 0;
12cbd3
+
12cbd3
+	if (!(udev_device = _udev_get_dev(dev)))
12cbd3
+		return 0;
12cbd3
+
12cbd3
 	value = udev_device_get_property_value(udev_device, DEV_EXT_UDEV_BLKID_TYPE);
12cbd3
 	if (value && !strcmp(value, DEV_EXT_UDEV_BLKID_TYPE_MPATH)) {
12cbd3
 		log_debug("Device %s is multipath component based on blkid variable in udev db (%s=\"%s\").",
12cbd3
@@ -1073,6 +1084,28 @@ out:
12cbd3
 	udev_device_unref(udev_device);
12cbd3
 	return ret;
12cbd3
 }
12cbd3
+
12cbd3
+int udev_dev_is_md_component(struct device *dev)
12cbd3
+{
12cbd3
+	struct udev_device *udev_device;
12cbd3
+	const char *value;
12cbd3
+	int ret = 0;
12cbd3
+
12cbd3
+	if (!(udev_device = _udev_get_dev(dev)))
12cbd3
+		return 0;
12cbd3
+
12cbd3
+	value = udev_device_get_property_value(udev_device, DEV_EXT_UDEV_BLKID_TYPE);
12cbd3
+	if (value && !strcmp(value, DEV_EXT_UDEV_BLKID_TYPE_SW_RAID)) {
12cbd3
+		log_debug("Device %s is md raid component based on blkid variable in udev db (%s=\"%s\").",
12cbd3
+			   dev_name(dev), DEV_EXT_UDEV_BLKID_TYPE, value);
12cbd3
+		ret = 1;
12cbd3
+		goto out;
12cbd3
+	}
12cbd3
+out:
12cbd3
+	udev_device_unref(udev_device);
12cbd3
+	return ret;
12cbd3
+}
12cbd3
+
12cbd3
 #else
12cbd3
 
12cbd3
 int udev_dev_is_mpath_component(struct device *dev)
12cbd3
@@ -1080,4 +1113,9 @@ int udev_dev_is_mpath_component(struct device *dev)
12cbd3
 	return 0;
12cbd3
 }
12cbd3
 
12cbd3
+int udev_dev_is_md_component(struct device *dev)
12cbd3
+{
12cbd3
+	return 0;
12cbd3
+}
12cbd3
+
12cbd3
 #endif
12cbd3
diff --git a/lib/device/dev-type.h b/lib/device/dev-type.h
12cbd3
index f629a02..2644383 100644
12cbd3
--- a/lib/device/dev-type.h
12cbd3
+++ b/lib/device/dev-type.h
12cbd3
@@ -62,6 +62,7 @@ int dev_is_swap(struct device *dev, uint64_t *signature, int full);
12cbd3
 int dev_is_luks(struct device *dev, uint64_t *signature, int full);
12cbd3
 int dasd_is_cdl_formatted(struct device *dev);
12cbd3
 int udev_dev_is_mpath_component(struct device *dev);
12cbd3
+int udev_dev_is_md_component(struct device *dev);
12cbd3
 
12cbd3
 int dev_is_lvm1(struct device *dev, char *buf, int buflen);
12cbd3
 int dev_is_pool(struct device *dev, char *buf, int buflen);
12cbd3
diff --git a/tools/pvscan.c b/tools/pvscan.c
12cbd3
index 47ad0f1..cdccfb5 100644
12cbd3
--- a/tools/pvscan.c
12cbd3
+++ b/tools/pvscan.c
12cbd3
@@ -455,7 +455,8 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv)
12cbd3
 		if (dev_is_md_with_end_superblock(cmd->dev_types, dev)) {
12cbd3
 			cmd->use_full_md_check = 1;
12cbd3
 			use_full_md_check = 1;
12cbd3
-			log_debug("Found md with end superblock %s", dev_name(dev));
12cbd3
+			log_debug("Found md component in sysfs with end superblock %s", dev_name(dev));
12cbd3
+			break;
12cbd3
 		}
12cbd3
 	}
12cbd3
 	dev_iter_destroy(iter);