From 939f5310b9e58a560247c44cbd8a8f8af86aae7c Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 31 Aug 2016 13:05:53 -0500 Subject: [PATCH] lvmetad: use udev to ignore multipath components during scan When scanning devs to populate lvmetad during system startup, filter-mpath with native sysfs multipath component detection may not detect that a dev is multipath component. This is because the multipath devices may not be set up yet. Because of this, pvscan will scan multipath components during startup, will see them as duplicate PVs, and will disable lvmetad. This will leave lvmetad disabled on systems using multipath, unless something or someone runs pvscan --cache to rescan. To avoid this problem, the code that is scanning devices to populate lvmetad will now check the udev db to see if a dev is a multipath component that should be skipped. (This may not be perfect due to inherent udev races, but will cover most cases and will be at least as good as it's ever been.) --- lib/cache/lvmetad.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c index 0503d918a..c31219ed8 100644 --- a/lib/cache/lvmetad.c +++ b/lib/cache/lvmetad.c @@ -24,6 +24,10 @@ #include "lvm-signal.h" #include "lvmlockd.h" #include "str_list.h" +#ifdef UDEV_SYNC_SUPPORT +#include +#include "dev-ext-udev-constants.h" +#endif #include @@ -2036,6 +2040,44 @@ out: return vg_ret; } +#ifdef UDEV_SYNC_SUPPORT +static int _dev_is_mpath_component(struct udev *udev_context, struct device *dev) +{ + struct udev_device *udev_device; + const char *value; + int ret = 0; + + if (!udev_context) + return_0; + + if (!(udev_device = udev_device_new_from_devnum(udev_context, 'b', dev->dev))) { + return_0; + } + + if (!udev_device_get_is_initialized(udev_device)) { + ret = 0; + goto_out; + } + + value = udev_device_get_property_value(udev_device, DEV_EXT_UDEV_BLKID_TYPE); + if (value && !strcmp(value, DEV_EXT_UDEV_BLKID_TYPE_MPATH)) { + log_debug("Dev %s is mpath component (%s)", dev_name(dev), value); + ret = 1; + goto out; + } + + value = udev_device_get_property_value(udev_device, DEV_EXT_UDEV_MPATH_DEVICE_PATH); + if (value && !strcmp(value, "1")) { + log_debug("Dev %s is mpath component (device path)", dev_name(dev)); + ret = 1; + goto out; + } +out: + udev_device_unref(udev_device); + return ret; +} +#endif + int lvmetad_pvscan_single(struct cmd_context *cmd, struct device *dev, struct dm_list *found_vgnames, struct dm_list *changed_vgnames) @@ -2051,6 +2093,15 @@ int lvmetad_pvscan_single(struct cmd_context *cmd, struct device *dev, return 0; } +#ifdef UDEV_SYNC_SUPPORT + struct udev *udev_context = udev_get_library_context(); + + if (_dev_is_mpath_component(udev_context, dev)) { + log_debug("Ignore multipath component for pvscan."); + return 1; + } +#endif + if (!label_read(dev, &label, 0)) { log_print_unless_silent("No PV label found on %s.", dev_name(dev)); if (!lvmetad_pv_gone_by_dev(dev))