master - cleanup: add dev-ext-udev-constants.h with constants/names of the properties/values used from udev db
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=28ba0450e93db3...
Commit: 28ba0450e93db30ee4dd815cbe85478b3c6a719a
Parent: 1c7a509bed900e27932df585f70c0c2ad994d1a9
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Jan 29 16:44:34 2015 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Jan 30 13:17:12 2015 +0100
cleanup: add dev-ext-udev-constants.h with constants/names of the properties/values used from udev db
---
include/.symlinks.in | 1 +
lib/device/dev-ext-udev-constants.h | 52 +++++++++++++++++++++++++++++++++++
lib/device/dev-md.c | 5 ++-
lib/device/dev-type.c | 5 ++-
lib/filters/filter-fwraid.c | 5 ++-
lib/filters/filter-mpath.c | 7 +++--
lib/filters/filter-usable.c | 3 +-
7 files changed, 68 insertions(+), 10 deletions(-)
diff --git a/include/.symlinks.in b/include/.symlinks.in
index 48c4d9d..96f4a01 100644
--- a/include/.symlinks.in
+++ b/include/.symlinks.in
@@ -13,6 +13,7 @@
@top_srcdir(a)/lib/datastruct/btree.h
@top_srcdir(a)/lib/datastruct/str_list.h
@top_srcdir(a)/lib/device/dev-cache.h
+@top_srcdir(a)/lib/device/dev-ext-udev-constants.h
@top_srcdir(a)/lib/device/dev-type.h
@top_srcdir(a)/lib/device/device.h
@top_srcdir(a)/lib/device/device-types.h
diff --git a/lib/device/dev-ext-udev-constants.h b/lib/device/dev-ext-udev-constants.h
new file mode 100644
index 0000000..a84d7bc
--- /dev/null
+++ b/lib/device/dev-ext-udev-constants.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2015 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*************************************************************************
+ * Properties saved in udev db and accesible via libudev and used by LVM *
+ *************************************************************************/
+
+/*
+ * DEV_EXT_UDEV_BLKID_TYPE property with various DEV_EXT_UDEV_BLKID_TYPE_*
+ * values that is saved in udev db via blkid call in udev rules
+ */
+#define DEV_EXT_UDEV_BLKID_TYPE "ID_FS_TYPE"
+/*
+ * mpath_member is forced by multipath - it's set in udev db via
+ * multipath call overwriting any existing ID_FS_TYPE value for
+ * a device which is a multipath component which prevents incorrect
+ * claim of the device by any other block device subsystem
+ */
+#define DEV_EXT_UDEV_BLKID_TYPE_MPATH "mpath_member"
+/* FW RAIDs are all *_raid_member types except linux_raid_member which denotes SW RAID */
+#define DEV_EXT_UDEV_BLKID_TYPE_RAID_SUFFIX "_raid_member"
+#define DEV_EXT_UDEV_BLKID_TYPE_SW_RAID "linux_raid_member"
+#define DEV_EXT_UDEV_BLKID_PART_TABLE_TYPE "ID_PART_TABLE_TYPE"
+#define DEV_EXT_UDEV_BLKID_PART_ENTRY_DISK "ID_PART_ENTRY_DISK"
+
+/*
+ * DEV_EXT_UDEV_MPATH_DEVICE_PATH is set by multipath in udev db
+ * with value either 0 or 1. The same functionality as
+ * DEV_EXT_UDEV_BLKID_TYPE_MPATH actually, but introduced later
+ * for some reason.
+ */
+#define DEV_EXT_UDEV_MPATH_DEVICE_PATH "DM_MULTIPATH_DEVICE_PATH"
+
+
+/***********************************************************
+ * Sysfs attributes accessible via libudev and used by LVM *
+ ***********************************************************/
+
+/* the value of size sysfs attribute is size in bytes */
+#define DEV_EXT_UDEV_SYSFS_ATTR_SIZE "size"
+
diff --git a/lib/device/dev-md.c b/lib/device/dev-md.c
index 535259f..603010c 100644
--- a/lib/device/dev-md.c
+++ b/lib/device/dev-md.c
@@ -18,6 +18,7 @@
#include "xlate.h"
#ifdef UDEV_SYNC_SUPPORT
#include <libudev.h> /* for MD detection using udev db records */
+#include "dev-ext-udev-constants.h"
#endif
#ifdef __linux__
@@ -93,10 +94,10 @@ static int _udev_dev_is_md(struct device *dev)
if (!(ext = dev_ext_get(dev)))
return_0;
- if (!(value = udev_device_get_property_value((struct udev_device *)ext->handle, "ID_FS_TYPE")))
+ if (!(value = udev_device_get_property_value((struct udev_device *)ext->handle, DEV_EXT_UDEV_BLKID_TYPE)))
return 0;
- return !strcmp(value, "linux_raid_member");
+ return !strcmp(value, DEV_EXT_UDEV_BLKID_TYPE_SW_RAID);
}
#else
static int _udev_dev_is_md(struct device *dev)
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index 58bd177..ba30982 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -27,6 +27,7 @@
#ifdef UDEV_SYNC_SUPPORT
#include <libudev.h>
+#include "dev-ext-udev-constants.h"
#endif
#include "device-types.h"
@@ -337,10 +338,10 @@ static int _udev_dev_is_partitioned(struct device *dev)
if (!(ext = dev_ext_get(dev)))
return_0;
- if (!(value = udev_device_get_property_value((struct udev_device *)ext->handle, "ID_PART_TABLE_TYPE")))
+ if (!(value = udev_device_get_property_value((struct udev_device *)ext->handle, DEV_EXT_UDEV_BLKID_PART_TABLE_TYPE)))
return 0;
- if ((value = udev_device_get_property_value((struct udev_device *)ext->handle, "ID_PART_ENTRY_DISK")))
+ if ((value = udev_device_get_property_value((struct udev_device *)ext->handle, DEV_EXT_UDEV_BLKID_PART_ENTRY_DISK)))
return 0;
return 1;
diff --git a/lib/filters/filter-fwraid.c b/lib/filters/filter-fwraid.c
index 2a0c598..f16833e 100644
--- a/lib/filters/filter-fwraid.c
+++ b/lib/filters/filter-fwraid.c
@@ -17,6 +17,7 @@
#ifdef UDEV_SYNC_SUPPORT
#include <libudev.h>
+#include "dev-ext-udev-constants.h"
#endif
#ifdef __linux__
@@ -26,8 +27,8 @@ static int _udev_dev_is_fwraid(struct device *dev)
{
const char *value;
- value = udev_device_get_property_value((struct udev_device *)dev->ext.handle, "ID_FS_TYPE");
- if (value && strcmp(value, "linux_raid_member") && strstr(value, "_raid_member"))
+ value = udev_device_get_property_value((struct udev_device *)dev->ext.handle, DEV_EXT_UDEV_BLKID_TYPE);
+ if (value && strcmp(value, DEV_EXT_UDEV_BLKID_TYPE_SW_RAID) && strstr(value, DEV_EXT_UDEV_BLKID_TYPE_RAID_SUFFIX))
return 1;
return 0;
diff --git a/lib/filters/filter-mpath.c b/lib/filters/filter-mpath.c
index fefc8e0..0016a51 100644
--- a/lib/filters/filter-mpath.c
+++ b/lib/filters/filter-mpath.c
@@ -17,6 +17,7 @@
#include "activate.h"
#ifdef UDEV_SYNC_SUPPORT
#include <libudev.h>
+#include "dev-ext-udev-constants.h"
#endif
#ifdef __linux__
@@ -153,11 +154,11 @@ static int _udev_dev_is_mpath(struct device *dev)
if (!(ext = dev_ext_get(dev)))
return_0;
- value = udev_device_get_property_value((struct udev_device *)ext->handle, "ID_FS_TYPE");
- if (value && !strcmp(value, "mpath_member"))
+ value = udev_device_get_property_value((struct udev_device *)ext->handle, DEV_EXT_UDEV_BLKID_TYPE);
+ if (value && !strcmp(value, DEV_EXT_UDEV_BLKID_TYPE_MPATH))
return 1;
- value = udev_device_get_property_value((struct udev_device *)ext->handle, "DM_MULTIPATH_DEVICE_PATH");
+ value = udev_device_get_property_value((struct udev_device *)ext->handle, DEV_EXT_UDEV_MPATH_DEVICE_PATH);
if (value && !strcmp(value, "1"))
return 1;
diff --git a/lib/filters/filter-usable.c b/lib/filters/filter-usable.c
index 667cdac..a4cfc69 100644
--- a/lib/filters/filter-usable.c
+++ b/lib/filters/filter-usable.c
@@ -17,6 +17,7 @@
#include "activate.h" /* device_is_usable */
#ifdef UDEV_SYNC_SUPPORT
#include <libudev.h>
+#include "dev-ext-udev-constants.h"
#endif
static const char *_too_small_to_hold_pv_msg = "Too small to hold a PV";
@@ -66,7 +67,7 @@ static int _udev_check_pv_min_size(struct device *dev)
if (!(ext = dev_ext_get(dev)))
return_0;
- if (!(size_str = udev_device_get_sysattr_value((struct udev_device *)ext->handle, "size"))) {
+ if (!(size_str = udev_device_get_sysattr_value((struct udev_device *)ext->handle, DEV_EXT_UDEV_SYSFS_ATTR_SIZE))) {
log_debug_devs("%s: Skipping: failed to get size from sysfs [%s:%p]",
dev_name(dev), dev_ext_name(dev), dev->ext.handle);
return 0;
8 years
master - filters: add firmware RAID filter
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1c7a509bed900e...
Commit: 1c7a509bed900e27932df585f70c0c2ad994d1a9
Parent: 787f6ce04ab2d2420cda199c34fdd795153b593f
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Sep 9 15:05:57 2014 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Jan 30 13:17:12 2015 +0100
filters: add firmware RAID filter
Just like MD filtering that detects components of software RAID (md),
add detection for firmware RAID.
We're not adding any native code to detect this - there are lots of
firmware RAIDs out there which is just out of LVM scope. However,
with current changes with which we're able to get device info from
external sources (e.g. external_device_info_source="udev"), we can
do this easily if the external device status source has this kind
of information - which is the case of "udev" source where the results
of blkid scans are stored.
This detection should cover all firmware RAIDs that blkid can detect and
which are identified as:
ID_FS_TYPE = {adaptec,ddf,hpt45x,hpt37x,isw,jmicron,lsi_mega,nvidia,promise_fasttrack,silicon_medley,via}_raid_member
---
conf/example.conf.in | 8 +++
lib/Makefile.in | 1 +
lib/commands/toolcontext.c | 13 ++++-
lib/config/config_settings.h | 1 +
lib/config/defaults.h | 1 +
lib/filters/filter-fwraid.c | 122 ++++++++++++++++++++++++++++++++++++++++++
lib/filters/filter.h | 1 +
lib/misc/lvm-globals.c | 11 ++++
lib/misc/lvm-globals.h | 2 +
9 files changed, 157 insertions(+), 3 deletions(-)
diff --git a/conf/example.conf.in b/conf/example.conf.in
index df28a7b..d9f10bf 100644
--- a/conf/example.conf.in
+++ b/conf/example.conf.in
@@ -178,6 +178,14 @@ devices {
# 1 enables; 0 disables.
md_component_detection = 1
+ # By default, LVM2 will not ignore devices used as components of
+ # firmware RAID devices. Set to 1 to enable this detection.
+ # N.B. LVM2 itself is not detecting firmware RAID - an
+ # auxiliary_device_status_source other than "native" must
+ # be used for this detection to be successful.
+ # 1 enables; 0 disables
+ fw_raid_component_detection = 0
+
# By default, if a PV is placed directly upon an md device, LVM2
# will align its data blocks with the md device's stripe-width.
# 1 enables; 0 disables.
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 99cc0fe..62600d5 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -70,6 +70,7 @@ SOURCES =\
filters/filter-regex.c \
filters/filter-sysfs.c \
filters/filter-md.c \
+ filters/filter-fwraid.c \
filters/filter-mpath.c \
filters/filter-partitioned.c \
filters/filter-type.c \
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index e914e93..7f92ef6 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -846,7 +846,7 @@ static int _init_dev_cache(struct cmd_context *cmd)
return 1;
}
-#define MAX_FILTERS 7
+#define MAX_FILTERS 8
static struct dev_filter *_init_lvmetad_filter_chain(struct cmd_context *cmd)
{
@@ -916,6 +916,13 @@ static struct dev_filter *_init_lvmetad_filter_chain(struct cmd_context *cmd)
nr_filt++;
}
+ /* firmware raid filter. Optional, non-critical. */
+ if (find_config_tree_bool(cmd, devices_fw_raid_component_detection_CFG, NULL)) {
+ init_fwraid_filtering(1);
+ if ((filters[nr_filt] = fwraid_filter_create(cmd->dev_types)))
+ nr_filt++;
+ }
+
if (!(composite = composite_filter_create(nr_filt, 1, filters)))
goto_bad;
@@ -937,7 +944,7 @@ bad:
* sysfs filter -> global regex filter -> type filter ->
* usable device filter(FILTER_MODE_PRE_LVMETAD) ->
* mpath component filter -> partitioned filter ->
- * md component filter
+ * md component filter -> fw raid filter
*
* - cmd->filter - the filter chain used for lvmetad responses:
* persistent filter -> usable device filter(FILTER_MODE_POST_LVMETAD) ->
@@ -953,7 +960,7 @@ bad:
* global regex filter -> type filter ->
* usable device filter(FILTER_MODE_NO_LVMETAD) ->
* mpath component filter -> partitioned filter ->
- * md component filter
+ * md component filter -> fw raid filter
*
*/
static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache)
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index 52d7f0f..f916a5f 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -103,6 +103,7 @@ cfg_array(devices_types_CFG, "types", devices_CFG_SECTION, CFG_DEFAULT_UNDEFINED
cfg(devices_sysfs_scan_CFG, "sysfs_scan", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_SYSFS_SCAN, vsn(1, 0, 8), NULL)
cfg(devices_multipath_component_detection_CFG, "multipath_component_detection", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MULTIPATH_COMPONENT_DETECTION, vsn(2, 2, 89), NULL)
cfg(devices_md_component_detection_CFG, "md_component_detection", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MD_COMPONENT_DETECTION, vsn(1, 0, 18), NULL)
+cfg(devices_fw_raid_component_detection_CFG, "fw_raid_component_detection", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_FW_RAID_COMPONENT_DETECTION, vsn(2, 2, 112), NULL)
cfg(devices_md_chunk_alignment_CFG, "md_chunk_alignment", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MD_CHUNK_ALIGNMENT, vsn(2, 2, 48), NULL)
cfg(devices_default_data_alignment_CFG, "default_data_alignment", devices_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_DATA_ALIGNMENT, vsn(2, 2, 75), NULL)
cfg(devices_data_alignment_detection_CFG, "data_alignment_detection", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_DATA_ALIGNMENT_DETECTION, vsn(2, 2, 51), NULL)
diff --git a/lib/config/defaults.h b/lib/config/defaults.h
index dfbfea8..9d2cff9 100644
--- a/lib/config/defaults.h
+++ b/lib/config/defaults.h
@@ -33,6 +33,7 @@
#define DEFAULT_EXTERNAL_DEVICE_INFO_SOURCE "none"
#define DEFAULT_SYSFS_SCAN 1
#define DEFAULT_MD_COMPONENT_DETECTION 1
+#define DEFAULT_FW_RAID_COMPONENT_DETECTION 0
#define DEFAULT_MD_CHUNK_ALIGNMENT 1
#define DEFAULT_IGNORE_LVM_MIRRORS 1
#define DEFAULT_MULTIPATH_COMPONENT_DETECTION 1
diff --git a/lib/filters/filter-fwraid.c b/lib/filters/filter-fwraid.c
new file mode 100644
index 0000000..2a0c598
--- /dev/null
+++ b/lib/filters/filter-fwraid.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "lib.h"
+#include "filter.h"
+
+#ifdef UDEV_SYNC_SUPPORT
+#include <libudev.h>
+#endif
+
+#ifdef __linux__
+
+#ifdef UDEV_SYNC_SUPPORT
+static int _udev_dev_is_fwraid(struct device *dev)
+{
+ const char *value;
+
+ value = udev_device_get_property_value((struct udev_device *)dev->ext.handle, "ID_FS_TYPE");
+ if (value && strcmp(value, "linux_raid_member") && strstr(value, "_raid_member"))
+ return 1;
+
+ return 0;
+}
+#else
+static int _udev_dev_is_fwraid(struct device *dev)
+{
+ return 0;
+}
+#endif
+
+static int _native_dev_is_fwraid(struct device *dev)
+{
+ log_verbose("%s: Firmware RAID detection is not supported by LVM natively. "
+ "Skipping firmware raid detection. ", dev_name(dev));
+ return 0;
+}
+
+static int _dev_is_fwraid(struct device *dev)
+{
+ if (dev->ext.src == DEV_EXT_NONE)
+ return _native_dev_is_fwraid(dev);
+
+ if (dev->ext.src == DEV_EXT_UDEV)
+ return _udev_dev_is_fwraid(dev);
+
+ log_error(INTERNAL_ERROR "Missing hook for firmware RAID recognition "
+ "using external device info source %s", dev_ext_name(dev));
+
+ return 0;
+}
+
+static int _ignore_fwraid(struct dev_filter *f __attribute__((unused)),
+ struct device *dev)
+{
+ int ret;
+
+ if (!fwraid_filtering())
+ return 1;
+
+ ret = _dev_is_fwraid(dev);
+
+ if (ret == 1) {
+ log_debug_devs("%s: Skipping firmware RAID component device [%s:%p]",
+ dev_name(dev), dev_ext_name(dev), dev->ext.handle);
+ return 0;
+ }
+
+ if (ret < 0) {
+ log_debug_devs("%s: Skipping: error in firmware RAID component detection",
+ dev_name(dev));
+ return 0;
+ }
+
+ return 1;
+}
+
+static void _destroy(struct dev_filter *f)
+{
+ if (f->use_count)
+ log_error(INTERNAL_ERROR "Destroying firmware RAID filter while in use %u times.", f->use_count);
+
+ dm_free(f);
+}
+
+struct dev_filter *fwraid_filter_create(struct dev_types *dt __attribute__((unused)))
+{
+ struct dev_filter *f;
+
+ if (!(f = dm_zalloc(sizeof(*f)))) {
+ log_error("Firmware RAID filter allocation failed");
+ return NULL;
+ }
+
+ f->passes_filter = _ignore_fwraid;
+ f->destroy = _destroy;
+ f->use_count = 0;
+ f->private = NULL;
+
+ log_debug_devs("Firmware RAID filter initialised.");
+
+ return f;
+}
+
+#else
+
+struct dev_filter *fwraid_filter_create(struct dev_types *dt __attribute__((unused)))
+{
+ return NULL;
+}
+
+#endif
diff --git a/lib/filters/filter.h b/lib/filters/filter.h
index e73cf9c..c03d8e2 100644
--- a/lib/filters/filter.h
+++ b/lib/filters/filter.h
@@ -24,6 +24,7 @@ struct dev_filter *composite_filter_create(int n, int use_dev_ext_info, struct d
struct dev_filter *lvm_type_filter_create(struct dev_types *dt);
struct dev_filter *md_filter_create(struct dev_types *dt);
+struct dev_filter *fwraid_filter_create(struct dev_types *dt);
struct dev_filter *mpath_filter_create(struct dev_types *dt);
struct dev_filter *partitioned_filter_create(struct dev_types *dt);
struct dev_filter *persistent_filter_create(struct dev_types *dt,
diff --git a/lib/misc/lvm-globals.c b/lib/misc/lvm-globals.c
index f0dab88..6455788 100644
--- a/lib/misc/lvm-globals.c
+++ b/lib/misc/lvm-globals.c
@@ -26,6 +26,7 @@ static int _verbose_level = VERBOSE_BASE_LEVEL;
static int _silent = 0;
static int _test = 0;
static int _md_filtering = 0;
+static int _fwraid_filtering = 0;
static int _pvmove = 0;
static int _full_scan_done = 0; /* Restrict to one full scan during each cmd */
static int _obtain_device_list_from_udev = DEFAULT_OBTAIN_DEVICE_LIST_FROM_UDEV;
@@ -75,6 +76,11 @@ void init_md_filtering(int level)
_md_filtering = level;
}
+void init_fwraid_filtering(int level)
+{
+ _fwraid_filtering = level;
+}
+
void init_pvmove(int level)
{
_pvmove = level;
@@ -221,6 +227,11 @@ int md_filtering(void)
return _md_filtering;
}
+int fwraid_filtering(void)
+{
+ return _fwraid_filtering;
+}
+
int pvmove_mode(void)
{
return _pvmove;
diff --git a/lib/misc/lvm-globals.h b/lib/misc/lvm-globals.h
index 4c4cc1a..b25f4ae 100644
--- a/lib/misc/lvm-globals.h
+++ b/lib/misc/lvm-globals.h
@@ -24,6 +24,7 @@ void init_verbose(int level);
void init_silent(int silent);
void init_test(int level);
void init_md_filtering(int level);
+void init_fwraid_filtering(int level);
void init_pvmove(int level);
void init_full_scan_done(int level);
void init_external_device_info_source(unsigned src);
@@ -54,6 +55,7 @@ void set_sysfs_dir_path(const char *path);
int test_mode(void);
int md_filtering(void);
+int fwraid_filtering(void);
int pvmove_mode(void);
int full_scan_done(void);
int obtain_device_list_from_udev(void);
8 years
master - filter-partitioned: use new 'udev' device status source to get partition status
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=787f6ce04ab2d2...
Commit: 787f6ce04ab2d2420cda199c34fdd795153b593f
Parent: 2fc126b00d83991c6a2f3ed9aa61457294a4c45e
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Sep 3 15:49:36 2014 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Jan 30 13:17:12 2015 +0100
filter-partitioned: use new 'udev' device status source to get partition status
Partitioned devices are marked in udev db as:
ID_PART_TABLE="<partition table type name>"
and at the same time they are *not* marked with:
ID_PART_ENTRY_DISK="<parent disk major:minor>"
Where partition table type name is dos/gpt/... But checking the presence
of this variable is enough for LVM here - it just needs to know whether
there's a partition table or not, not interested in the actual type.
The same applies for parent disk major:minor.
---
lib/device/dev-type.c | 59 ++++++++++++++++++++++++++++++++++++-
lib/filters/filter-partitioned.c | 21 ++++---------
2 files changed, 64 insertions(+), 16 deletions(-)
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index dc8b61d..58bd177 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -25,6 +25,10 @@
#include <blkid.h>
#endif
+#ifdef UDEV_SYNC_SUPPORT
+#include <libudev.h>
+#endif
+
#include "device-types.h"
struct dev_types *create_dev_types(const char *proc_dir,
@@ -324,8 +328,34 @@ static int _has_partition_table(struct device *dev)
return ret;
}
-int dev_is_partitioned(struct dev_types *dt, struct device *dev)
+#ifdef UDEV_SYNC_SUPPORT
+static int _udev_dev_is_partitioned(struct device *dev)
+{
+ const char *value;
+ struct dev_ext *ext;
+
+ if (!(ext = dev_ext_get(dev)))
+ return_0;
+
+ if (!(value = udev_device_get_property_value((struct udev_device *)ext->handle, "ID_PART_TABLE_TYPE")))
+ return 0;
+
+ if ((value = udev_device_get_property_value((struct udev_device *)ext->handle, "ID_PART_ENTRY_DISK")))
+ return 0;
+
+ return 1;
+}
+#else
+static int _udev_dev_is_partitioned(struct device *dev)
+{
+ return 0;
+}
+#endif
+
+static int _native_dev_is_partitioned(struct dev_types *dt, struct device *dev)
{
+ int r;
+
if (!_is_partitionable(dt, dev))
return 0;
@@ -333,7 +363,32 @@ int dev_is_partitioned(struct dev_types *dt, struct device *dev)
if (MAJOR(dev->dev) == dt->dasd_major)
return 1;
- return _has_partition_table(dev);
+ if (!dev_open_readonly_quiet(dev)) {
+ log_debug_devs("%s: failed to open device, considering device "
+ "is partitioned", dev_name(dev));
+ return 1;
+ }
+
+ r = _has_partition_table(dev);
+
+ if (!dev_close(dev))
+ stack;
+
+ return r;
+}
+
+int dev_is_partitioned(struct dev_types *dt, struct device *dev)
+{
+ if (dev->ext.src == DEV_EXT_NONE)
+ return _native_dev_is_partitioned(dt, dev);
+
+ if (dev->ext.src == DEV_EXT_UDEV)
+ return _udev_dev_is_partitioned(dev);
+
+ log_error(INTERNAL_ERROR "Missing hook for partition table recognition "
+ "using external device info source %s", dev_ext_name(dev));
+
+ return 0;
}
/*
diff --git a/lib/filters/filter-partitioned.c b/lib/filters/filter-partitioned.c
index 9a90557..2c21452 100644
--- a/lib/filters/filter-partitioned.c
+++ b/lib/filters/filter-partitioned.c
@@ -15,28 +15,21 @@
#include "lib.h"
#include "filter.h"
+#ifdef UDEV_SYNC_SUPPORT
+#include <libudev.h>
+#endif
static int _passes_partitioned_filter(struct dev_filter *f, struct device *dev)
{
struct dev_types *dt = (struct dev_types *) f->private;
- int ret = 0;
-
- if (!dev_open_readonly_quiet(dev)) {
- log_debug_devs("%s: Skipping: open failed", dev_name(dev));
- return 0;
- }
if (dev_is_partitioned(dt, dev)) {
- log_debug_devs("%s: Skipping: Partition table signature found",
- dev_name(dev));
- goto out;
+ log_debug_devs("%s: Skipping: Partition table signature found [%s:%p]",
+ dev_name(dev), dev_ext_name(dev), dev->ext.handle);
+ return 0;
}
- ret = 1;
-out:
- if (!dev_close(dev))
- stack;
- return ret;
+ return 1;
}
static void _partitioned_filter_destroy(struct dev_filter *f)
8 years
master - filter-usable: move check for pv_min_size from filter-partitioned to filter-usable and use new 'udev' external device info source for this check
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=2fc126b00d8399...
Commit: 2fc126b00d83991c6a2f3ed9aa61457294a4c45e
Parent: 9c030e81a4e2d1e6b7024991c29114c59337553e
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Jan 29 14:24:06 2015 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Jan 30 13:01:12 2015 +0100
filter-usable: move check for pv_min_size from filter-partitioned to filter-usable and use new 'udev' external device info source for this check
The filter-partitioned code should contain only checks in "partition" domain.
The check for pv_min_size should actually be a part of filter-usable.
If the device size is less than pv_min_size, such device is not usable
as a PV so this check clearly belongs here logically.
With udev external info source, we can get device size via libudev's
sysfs reading interface and we can avoid opening the device this way
effectively.
---
lib/filters/filter-partitioned.c | 22 +-------
lib/filters/filter-usable.c | 109 +++++++++++++++++++++++++++++++++++++-
2 files changed, 111 insertions(+), 20 deletions(-)
diff --git a/lib/filters/filter-partitioned.c b/lib/filters/filter-partitioned.c
index e3caa0e..9a90557 100644
--- a/lib/filters/filter-partitioned.c
+++ b/lib/filters/filter-partitioned.c
@@ -19,39 +19,23 @@
static int _passes_partitioned_filter(struct dev_filter *f, struct device *dev)
{
struct dev_types *dt = (struct dev_types *) f->private;
- const char *name = dev_name(dev);
int ret = 0;
- uint64_t size;
- /* Check it's accessible */
if (!dev_open_readonly_quiet(dev)) {
- log_debug_devs("%s: Skipping: open failed", name);
+ log_debug_devs("%s: Skipping: open failed", dev_name(dev));
return 0;
}
- /* Check it's not too small */
- if (!dev_get_size(dev, &size)) {
- log_debug_devs("%s: Skipping: dev_get_size failed", name);
- goto out;
- }
-
- if (size < pv_min_size()) {
- log_debug_devs("%s: Skipping: Too small to hold a PV", name);
- goto out;
- }
-
if (dev_is_partitioned(dt, dev)) {
log_debug_devs("%s: Skipping: Partition table signature found",
- name);
+ dev_name(dev));
goto out;
}
ret = 1;
-
- out:
+out:
if (!dev_close(dev))
stack;
-
return ret;
}
diff --git a/lib/filters/filter-usable.c b/lib/filters/filter-usable.c
index f34a325..667cdac 100644
--- a/lib/filters/filter-usable.c
+++ b/lib/filters/filter-usable.c
@@ -15,6 +15,100 @@
#include "lib.h"
#include "filter.h"
#include "activate.h" /* device_is_usable */
+#ifdef UDEV_SYNC_SUPPORT
+#include <libudev.h>
+#endif
+
+static const char *_too_small_to_hold_pv_msg = "Too small to hold a PV";
+
+static int _native_check_pv_min_size(struct device *dev)
+{
+ uint64_t size;
+ int ret = 0;
+
+ /* Check it's accessible */
+ if (!dev_open_readonly_quiet(dev)) {
+ log_debug_devs("%s: Skipping: open failed [%s:%p]",
+ dev_name(dev), dev_ext_name(dev), dev->ext.handle);
+ return 0;
+ }
+
+ /* Check it's not too small */
+ if (!dev_get_size(dev, &size)) {
+ log_debug_devs("%s: Skipping: dev_get_size failed [%s:%p]",
+ dev_name(dev), dev_ext_name(dev), dev->ext.handle);
+ goto out;
+ }
+
+ if (size < pv_min_size()) {
+ log_debug_devs("%s: Skipping: %s [%s:%p]", dev_name(dev),
+ _too_small_to_hold_pv_msg,
+ dev_ext_name(dev), dev->ext.handle);
+ goto out;
+ }
+
+ ret = 1;
+out:
+ if (!dev_close(dev))
+ stack;
+
+ return ret;
+}
+
+#ifdef UDEV_SYNC_SUPPORT
+static int _udev_check_pv_min_size(struct device *dev)
+{
+ struct dev_ext *ext;
+ const char *size_str;
+ char *endp;
+ uint64_t size;
+
+ if (!(ext = dev_ext_get(dev)))
+ return_0;
+
+ if (!(size_str = udev_device_get_sysattr_value((struct udev_device *)ext->handle, "size"))) {
+ log_debug_devs("%s: Skipping: failed to get size from sysfs [%s:%p]",
+ dev_name(dev), dev_ext_name(dev), dev->ext.handle);
+ return 0;
+ }
+
+ errno = 0;
+ size = strtoull(size_str, &endp, 10);
+ if (errno || !endp || *endp) {
+ log_debug_devs("%s: Skipping: failed to parse size from sysfs [%s:%p]",
+ dev_name(dev), dev_ext_name(dev), dev->ext.handle);
+ return 0;
+ }
+
+ if (size < pv_min_size()) {
+ log_debug_devs("%s: Skipping: %s [%s:%p]", dev_name(dev),
+ _too_small_to_hold_pv_msg,
+ dev_ext_name(dev), dev->ext.handle);
+ return 0;
+ }
+
+ return 1;
+}
+#else
+static int _udev_check_pv_min_size(struct device *dev)
+{
+ return 1;
+}
+#endif
+
+static int _check_pv_min_size(struct device *dev)
+{
+ if (dev->ext.src == DEV_EXT_NONE)
+ return _native_check_pv_min_size(dev);
+
+ if (dev->ext.src == DEV_EXT_UDEV)
+ return _udev_check_pv_min_size(dev);
+
+ log_error(INTERNAL_ERROR "Missing hook for PV min size check "
+ "using external device info source %s", dev_ext_name(dev));
+
+ return 0;
+}
static int _passes_usable_filter(struct dev_filter *f, struct device *dev)
{
@@ -22,7 +116,20 @@ static int _passes_usable_filter(struct dev_filter *f, struct device *dev)
struct dev_usable_check_params ucp = {0};
int r;
- /* filter only device-mapper devices */
+ /* check if the device is not too small to hold a PV */
+ switch (mode) {
+ case FILTER_MODE_NO_LVMETAD:
+ /* fall through */
+ case FILTER_MODE_PRE_LVMETAD:
+ if (!_check_pv_min_size(dev))
+ return 0;
+ break;
+ case FILTER_MODE_POST_LVMETAD:
+ /* nothing to do here */
+ break;
+ }
+
+ /* further checks are done on dm devices only */
if (!dm_is_dm_major(MAJOR(dev->dev)))
return 1;
8 years
master - filter-mpath: use new 'udev' external device info source to get mpath component status
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9c030e81a4e2d1...
Commit: 9c030e81a4e2d1e6b7024991c29114c59337553e
Parent: 590fbd89618fa8fb2556c89c1d12b5deb5b5f1a4
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Sep 3 15:48:37 2014 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Jan 30 13:01:12 2015 +0100
filter-mpath: use new 'udev' external device info source to get mpath component status
mpath components are marked in udev db as:
ID_FS_TYPE="mpath_member"
or
DM_MULTIPATH_DEVICE_PATH="1"
(it depends on udev rule/blkid version used for handling mpath)
---
lib/filters/filter-mpath.c | 48 ++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/lib/filters/filter-mpath.c b/lib/filters/filter-mpath.c
index 0f12c73..fefc8e0 100644
--- a/lib/filters/filter-mpath.c
+++ b/lib/filters/filter-mpath.c
@@ -15,6 +15,9 @@
#include "lib.h"
#include "filter.h"
#include "activate.h"
+#ifdef UDEV_SYNC_SUPPORT
+#include <libudev.h>
+#endif
#ifdef __linux__
@@ -141,7 +144,33 @@ static int _get_parent_mpath(const char *dir, char *name, int max_size)
return r;
}
-static int _dev_is_mpath(struct dev_filter *f, struct device *dev)
+#ifdef UDEV_SYNC_SUPPORT
+static int _udev_dev_is_mpath(struct device *dev)
+{
+ const char *value;
+ struct dev_ext *ext;
+
+ if (!(ext = dev_ext_get(dev)))
+ return_0;
+
+ value = udev_device_get_property_value((struct udev_device *)ext->handle, "ID_FS_TYPE");
+ if (value && !strcmp(value, "mpath_member"))
+ return 1;
+
+ value = udev_device_get_property_value((struct udev_device *)ext->handle, "DM_MULTIPATH_DEVICE_PATH");
+ if (value && !strcmp(value, "1"))
+ return 1;
+
+ return 0;
+}
+#else
+static int _udev_dev_is_mpath(struct device *dev)
+{
+ return 0;
+}
+#endif
+
+static int _native_dev_is_mpath(struct dev_filter *f, struct device *dev)
{
struct dev_types *dt = (struct dev_types *) f->private;
const char *part_name, *name;
@@ -200,10 +229,25 @@ static int _dev_is_mpath(struct dev_filter *f, struct device *dev)
return lvm_dm_prefix_check(major, minor, MPATH_PREFIX);
}
+static int _dev_is_mpath(struct dev_filter *f, struct device *dev)
+{
+ if (dev->ext.src == DEV_EXT_NONE)
+ return _native_dev_is_mpath(f, dev);
+
+ if (dev->ext.src == DEV_EXT_UDEV)
+ return _udev_dev_is_mpath(dev);
+
+ log_error(INTERNAL_ERROR "Missing hook for mpath recognition "
+ "using external device info source %s", dev_ext_name(dev));
+
+ return 0;
+}
+
static int _ignore_mpath(struct dev_filter *f, struct device *dev)
{
if (_dev_is_mpath(f, dev) == 1) {
- log_debug_devs("%s: Skipping mpath component device", dev_name(dev));
+ log_debug_devs("%s: Skipping mpath component device [%s:%p]",
+ dev_name(dev), dev_ext_name(dev), dev->ext.handle);
return 0;
}
8 years
master - filter-md: use new 'udev' external device info source to get MD component status
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=590fbd89618fa8...
Commit: 590fbd89618fa8fb2556c89c1d12b5deb5b5f1a4
Parent: bf8943b0f63336272f3434455b906e0167e27b52
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Sep 3 15:47:52 2014 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Jan 30 13:01:12 2015 +0100
filter-md: use new 'udev' external device info source to get MD component status
MD components are marked in udev db as:
ID_FS_TYPE="linux_raid_member"
---
lib/device/dev-md.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
lib/filters/filter-md.c | 3 ++-
2 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/lib/device/dev-md.c b/lib/device/dev-md.c
index 76e3093..535259f 100644
--- a/lib/device/dev-md.c
+++ b/lib/device/dev-md.c
@@ -16,6 +16,9 @@
#include "lib.h"
#include "dev-type.h"
#include "xlate.h"
+#ifdef UDEV_SYNC_SUPPORT
+#include <libudev.h> /* for MD detection using udev db records */
+#endif
#ifdef __linux__
@@ -81,10 +84,31 @@ static uint64_t _v1_sb_offset(uint64_t size, md_minor_version_t minor_version)
return sb_offset;
}
+#ifdef UDEV_SYNC_SUPPORT
+static int _udev_dev_is_md(struct device *dev)
+{
+ const char *value;
+ struct dev_ext *ext;
+
+ if (!(ext = dev_ext_get(dev)))
+ return_0;
+
+ if (!(value = udev_device_get_property_value((struct udev_device *)ext->handle, "ID_FS_TYPE")))
+ return 0;
+
+ return !strcmp(value, "linux_raid_member");
+}
+#else
+static int _udev_dev_is_md(struct device *dev)
+{
+ return 0;
+}
+#endif
+
/*
* Returns -1 on error
*/
-int dev_is_md(struct device *dev, uint64_t *offset_found)
+static int _native_dev_is_md(struct device *dev, uint64_t *offset_found)
{
int ret = 1;
md_minor_version_t minor;
@@ -129,6 +153,27 @@ out:
return ret;
}
+int dev_is_md(struct device *dev, uint64_t *offset_found)
+{
+
+ /*
+ * If non-native device status source is selected, use it
+ * only if offset_found is not requested as this
+ * information is not in udev db.
+ */
+ if ((dev->ext.src == DEV_EXT_NONE) || offset_found)
+ return _native_dev_is_md(dev, offset_found);
+
+ if (dev->ext.src == DEV_EXT_UDEV)
+ return _udev_dev_is_md(dev);
+
+ log_error(INTERNAL_ERROR "Missing hook for MD device recognition "
+ "using external device info source %s", dev_ext_name(dev));
+
+ return -1;
+
+}
+
static int _md_sysfs_attribute_snprintf(char *path, size_t size,
struct dev_types *dt,
struct device *blkdev,
diff --git a/lib/filters/filter-md.c b/lib/filters/filter-md.c
index fe79f3d..ad9f540 100644
--- a/lib/filters/filter-md.c
+++ b/lib/filters/filter-md.c
@@ -29,7 +29,8 @@ static int _ignore_md(struct dev_filter *f __attribute__((unused)),
ret = dev_is_md(dev, NULL);
if (ret == 1) {
- log_debug_devs("%s: Skipping md component device", dev_name(dev));
+ log_debug_devs("%s: Skipping md component device [%s:%p]",
+ dev_name(dev), dev_ext_name(dev), dev->ext.handle);
return 0;
}
8 years
master - conf: add devices/external_device_info_source to lvm.conf
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=bf8943b0f63336...
Commit: bf8943b0f63336272f3434455b906e0167e27b52
Parent: c50a90c9e6084350682a315ed1732c2a54a3a828
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Dec 15 16:27:33 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Jan 30 13:01:12 2015 +0100
conf: add devices/external_device_info_source to lvm.conf
---
conf/example.conf.in | 16 ++++++++++++++++
lib/commands/toolcontext.c | 11 +++++++++++
lib/config/config_settings.h | 1 +
lib/config/defaults.h | 1 +
lib/filters/filter-composite.c | 2 +-
lib/misc/lvm-globals.c | 11 +++++++++++
lib/misc/lvm-globals.h | 2 ++
7 files changed, 43 insertions(+), 1 deletions(-)
diff --git a/conf/example.conf.in b/conf/example.conf.in
index 0ba9ccb..df28a7b 100644
--- a/conf/example.conf.in
+++ b/conf/example.conf.in
@@ -39,6 +39,22 @@ devices {
# to use with LVM2.
scan = [ "/dev" ]
+ # Select external device information source to use for further and more
+ # detailed device determination. Some information may already be available
+ # in the system and LVM2 can use this information to determine the exact
+ # type or use of the device it processes. Using existing external device
+ # information source can speed up device processing as LVM2 does not need
+ # to run its own native routines to acquire this information. For example,
+ # such information is used to drive LVM2 filtering like MD component
+ # detection, multipath component detection, partition detection and others.
+ # Possible options are:
+ # "none" - No external device information source is used.
+ #
+ # "udev" - Reuse existing udev database records. Applicable
+ # only if LVM is compiled with udev support.
+ #
+ external_device_info_source = "none"
+
# If set, the cache of block device nodes with all associated symlinks
# will be constructed out of the existing udev database content.
# This avoids using and opening any inapplicable non-block devices or
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 83238fb..e914e93 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -307,6 +307,7 @@ int process_profilable_config(struct cmd_context *cmd) {
static int _process_config(struct cmd_context *cmd)
{
mode_t old_umask;
+ const char *dev_ext_info_src;
const char *read_ahead;
struct stat st;
const struct dm_config_node *cn;
@@ -340,6 +341,16 @@ static int _process_config(struct cmd_context *cmd)
return_0;
#endif
+ dev_ext_info_src = find_config_tree_str(cmd, devices_external_device_info_source_CFG, NULL);
+ if (!strcmp(dev_ext_info_src, "none"))
+ init_external_device_info_source(DEV_EXT_NONE);
+ else if (!strcmp(dev_ext_info_src, "udev"))
+ init_external_device_info_source(DEV_EXT_UDEV);
+ else {
+ log_error("Invalid external device info source specification.");
+ return 0;
+ }
+
/* proc dir */
if (dm_snprintf(cmd->proc_dir, sizeof(cmd->proc_dir), "%s",
find_config_tree_str(cmd, global_proc_CFG, NULL)) < 0) {
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index 8978b5b..52d7f0f 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -91,6 +91,7 @@ cfg(devices_dir_CFG, "dir", devices_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_DEV
cfg_array(devices_scan_CFG, "scan", devices_CFG_SECTION, 0, CFG_TYPE_STRING, "#S/dev", vsn(1, 0, 0), NULL)
cfg_array(devices_loopfiles_CFG, "loopfiles", devices_CFG_SECTION, CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(1, 2, 0), NULL)
cfg(devices_obtain_device_list_from_udev_CFG, "obtain_device_list_from_udev", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_OBTAIN_DEVICE_LIST_FROM_UDEV, vsn(2, 2, 85), NULL)
+cfg(devices_external_device_info_source_CFG, "external_device_info_source", devices_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_EXTERNAL_DEVICE_INFO_SOURCE, vsn(2, 2, 115), NULL)
cfg_array(devices_preferred_names_CFG, "preferred_names", devices_CFG_SECTION, CFG_ALLOW_EMPTY | CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(1, 2, 19), NULL)
cfg_array(devices_filter_CFG, "filter", devices_CFG_SECTION, CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(1, 0, 0), NULL)
cfg_array(devices_global_filter_CFG, "global_filter", devices_CFG_SECTION, CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(2, 2, 98), NULL)
diff --git a/lib/config/defaults.h b/lib/config/defaults.h
index 1431de2..dfbfea8 100644
--- a/lib/config/defaults.h
+++ b/lib/config/defaults.h
@@ -30,6 +30,7 @@
#define DEFAULT_DEV_DIR "/dev"
#define DEFAULT_PROC_DIR "/proc"
#define DEFAULT_OBTAIN_DEVICE_LIST_FROM_UDEV 1
+#define DEFAULT_EXTERNAL_DEVICE_INFO_SOURCE "none"
#define DEFAULT_SYSFS_SCAN 1
#define DEFAULT_MD_COMPONENT_DETECTION 1
#define DEFAULT_MD_CHUNK_ALIGNMENT 1
diff --git a/lib/filters/filter-composite.c b/lib/filters/filter-composite.c
index 950705b..1a2e172 100644
--- a/lib/filters/filter-composite.c
+++ b/lib/filters/filter-composite.c
@@ -31,7 +31,7 @@ static int _and_p_with_dev_ext_info(struct dev_filter *f, struct device *dev)
{
int r;
- dev_ext_enable(dev, DEV_EXT_NONE);
+ dev_ext_enable(dev, external_device_info_source());
r = _and_p(f, dev);
dev_ext_disable(dev);
diff --git a/lib/misc/lvm-globals.c b/lib/misc/lvm-globals.c
index ee192b0..f0dab88 100644
--- a/lib/misc/lvm-globals.c
+++ b/lib/misc/lvm-globals.c
@@ -29,6 +29,7 @@ static int _md_filtering = 0;
static int _pvmove = 0;
static int _full_scan_done = 0; /* Restrict to one full scan during each cmd */
static int _obtain_device_list_from_udev = DEFAULT_OBTAIN_DEVICE_LIST_FROM_UDEV;
+static unsigned _external_device_info_source = DEV_EXT_NONE;
static int _trust_cache = 0; /* Don't scan when incomplete VGs encountered */
static int _debug_level = 0;
static int _debug_classes_logged = DEFAULT_LOGGED_DEBUG_CLASSES;
@@ -89,6 +90,11 @@ void init_obtain_device_list_from_udev(int device_list_from_udev)
_obtain_device_list_from_udev = device_list_from_udev;
}
+void init_external_device_info_source(unsigned src)
+{
+ _external_device_info_source = src;
+}
+
void init_trust_cache(int trustcache)
{
_trust_cache = trustcache;
@@ -230,6 +236,11 @@ int obtain_device_list_from_udev(void)
return _obtain_device_list_from_udev;
}
+unsigned external_device_info_source(void)
+{
+ return _external_device_info_source;
+}
+
int trust_cache(void)
{
return _trust_cache;
diff --git a/lib/misc/lvm-globals.h b/lib/misc/lvm-globals.h
index 4af713b..4c4cc1a 100644
--- a/lib/misc/lvm-globals.h
+++ b/lib/misc/lvm-globals.h
@@ -26,6 +26,7 @@ void init_test(int level);
void init_md_filtering(int level);
void init_pvmove(int level);
void init_full_scan_done(int level);
+void init_external_device_info_source(unsigned src);
void init_obtain_device_list_from_udev(int device_list_from_udev);
void init_trust_cache(int trustcache);
void init_debug(int level);
@@ -56,6 +57,7 @@ int md_filtering(void);
int pvmove_mode(void);
int full_scan_done(void);
int obtain_device_list_from_udev(void);
+unsigned external_device_info_source(void);
int trust_cache(void);
int verbose_level(void);
int silent_mode(void);
8 years
master - filter-composite: add external device info hooks
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c50a90c9e60843...
Commit: c50a90c9e6084350682a315ed1732c2a54a3a828
Parent: fbfde21e7cdc770f0a1189d40f983aa046d605bb
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Dec 15 15:12:42 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Jan 30 13:01:12 2015 +0100
filter-composite: add external device info hooks
Composite filter is a filter that can put several filters in one set.
This patch adds a switch when creating the composite filter which will
enable or disable external device info handles for all the filters
the composite filter encompasses.
We want to use this external device info for majority of the filters
which are in the "lvmetad filter chain" (or the respective part if
we're not using lvmetad).
Following patches will use the enabled external device handle in
concrete filters from the composite filter...
---
lib/commands/toolcontext.c | 6 +++---
lib/filters/filter-composite.c | 15 +++++++++++++--
lib/filters/filter.h | 3 ++-
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 3900179..83238fb 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -905,7 +905,7 @@ static struct dev_filter *_init_lvmetad_filter_chain(struct cmd_context *cmd)
nr_filt++;
}
- if (!(composite = composite_filter_create(nr_filt, filters)))
+ if (!(composite = composite_filter_create(nr_filt, 1, filters)))
goto_bad;
return composite;
@@ -985,7 +985,7 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
if (!(filter_components[1] = regex_filter_create(cn->v)))
goto_bad;
/* we have two filter components - create composite filter */
- if (!(filter = composite_filter_create(2, filter_components)))
+ if (!(filter = composite_filter_create(2, 0, filter_components)))
goto_bad;
} else
/* we have only one filter component - no need to create composite filter */
@@ -1004,7 +1004,7 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
if (lvmetad_used()) {
filter_components[0] = cmd->lvmetad_filter;
filter_components[1] = cmd->filter;
- if (!(cmd->full_filter = composite_filter_create(2, filter_components)))
+ if (!(cmd->full_filter = composite_filter_create(2, 0, filter_components)))
goto_bad;
} else
cmd->full_filter = filter;
diff --git a/lib/filters/filter-composite.c b/lib/filters/filter-composite.c
index a6ba71a..950705b 100644
--- a/lib/filters/filter-composite.c
+++ b/lib/filters/filter-composite.c
@@ -27,6 +27,17 @@ static int _and_p(struct dev_filter *f, struct device *dev)
return 1;
}
+static int _and_p_with_dev_ext_info(struct dev_filter *f, struct device *dev)
+{
+ int r;
+
+ dev_ext_enable(dev, DEV_EXT_NONE);
+ r = _and_p(f, dev);
+ dev_ext_disable(dev);
+
+ return r;
+}
+
static void _composite_destroy(struct dev_filter *f)
{
struct dev_filter **filters;
@@ -62,7 +73,7 @@ static void _wipe(struct dev_filter *f)
(*filters)->wipe(*filters);
}
-struct dev_filter *composite_filter_create(int n, struct dev_filter **filters)
+struct dev_filter *composite_filter_create(int n, int use_dev_ext_info, struct dev_filter **filters)
{
struct dev_filter **filters_copy, *cft;
@@ -83,7 +94,7 @@ struct dev_filter *composite_filter_create(int n, struct dev_filter **filters)
return NULL;
}
- cft->passes_filter = _and_p;
+ cft->passes_filter = use_dev_ext_info ? _and_p_with_dev_ext_info : _and_p;
cft->destroy = _composite_destroy;
cft->dump = _dump;
cft->wipe = _wipe;
diff --git a/lib/filters/filter.h b/lib/filters/filter.h
index 0519439..e73cf9c 100644
--- a/lib/filters/filter.h
+++ b/lib/filters/filter.h
@@ -20,7 +20,8 @@
#include "dev-cache.h"
#include "dev-type.h"
-struct dev_filter *composite_filter_create(int n, struct dev_filter **filters);
+struct dev_filter *composite_filter_create(int n, int use_dev_ext_info, struct dev_filter **filters);
+
struct dev_filter *lvm_type_filter_create(struct dev_types *dt);
struct dev_filter *md_filter_create(struct dev_types *dt);
struct dev_filter *mpath_filter_create(struct dev_types *dt);
8 years
master - device: add infrastructure to support external device info
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fbfde21e7cdc77...
Commit: fbfde21e7cdc770f0a1189d40f983aa046d605bb
Parent: 578b236a19fab565a4416b17cbc26d53a72b66db
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Dec 12 12:55:41 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Jan 30 13:01:12 2015 +0100
device: add infrastructure to support external device info
---
lib/Makefile.in | 1 +
lib/device/dev-cache.c | 3 +
lib/device/dev-ext.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++++
lib/device/device.h | 27 ++++++++
4 files changed, 195 insertions(+), 0 deletions(-)
diff --git a/lib/Makefile.in b/lib/Makefile.in
index bad5d8c..99cc0fe 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -56,6 +56,7 @@ SOURCES =\
datastruct/btree.c \
datastruct/str_list.c \
device/dev-cache.c \
+ device/dev-ext.c \
device/dev-io.c \
device/dev-md.c \
device/dev-swap.c \
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index ba4ee54..7ad9fb8 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -64,6 +64,9 @@ static void _dev_init(struct device *dev, int max_error_count)
dev->read_ahead = -1;
dev->max_error_count = max_error_count;
+ dev->ext.enabled = 0;
+ dev->ext.src = DEV_EXT_NONE;
+
dm_list_init(&dev->aliases);
dm_list_init(&dev->open_list);
}
diff --git a/lib/device/dev-ext.c b/lib/device/dev-ext.c
new file mode 100644
index 0000000..8f2024e
--- /dev/null
+++ b/lib/device/dev-ext.c
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "lib.h"
+#include "device.h"
+
+#ifdef UDEV_SYNC_SUPPORT
+#include <libudev.h>
+#endif
+
+struct ext_registry_item {
+ const char *name;
+ struct dev_ext *(* dev_ext_get) (struct device *dev);
+ int (*dev_ext_release) (struct device *dev);
+};
+
+#define EXT_REGISTER(id,name) [id] = { #name, &_dev_ext_get_ ## name, &_dev_ext_release_ ## name }
+
+/*
+ * DEV_EXT_NONE
+ */
+static struct dev_ext *_dev_ext_get_none(struct device *dev)
+{
+ dev->ext.handle = NULL;
+ return &dev->ext;
+}
+
+static int _dev_ext_release_none(struct device *dev)
+{
+ dev->ext.handle = NULL;
+ return 1;
+}
+
+/*
+ * DEV_EXT_UDEV
+ */
+static struct dev_ext *_dev_ext_get_udev(struct device *dev)
+{
+#ifdef UDEV_SYNC_SUPPORT
+ struct udev *udev;
+ struct udev_device *udev_device;
+
+ if (dev->ext.handle)
+ return &dev->ext;
+
+ if (!(udev = udev_get_library_context()))
+ return_NULL;
+
+ if (!(udev_device = udev_device_new_from_devnum(udev, 'b', dev->dev)))
+ return_NULL;
+
+ dev->ext.handle = (void *) udev_device;
+ return &dev->ext;
+#else
+ return NULL;
+#endif
+}
+
+static int _dev_ext_release_udev(struct device *dev)
+{
+#ifdef UDEV_SYNC_SUPPORT
+ if (!dev->ext.handle)
+ return 1;
+
+ /* udev_device_unref can't fail - it has no return value */
+ udev_device_unref((struct udev_device *) dev->ext.handle);
+ dev->ext.handle = NULL;
+ return 1;
+#else
+ return 0;
+#endif
+}
+
+static struct ext_registry_item _ext_registry[DEV_EXT_NUM] = {
+ EXT_REGISTER(DEV_EXT_NONE, none),
+ EXT_REGISTER(DEV_EXT_UDEV, udev)
+};
+
+const char *dev_ext_name(struct device *dev)
+{
+ return _ext_registry[dev->ext.src].name;
+}
+
+static const char *_ext_attached_msg = "External handle attached to device";
+
+struct dev_ext *dev_ext_get(struct device *dev)
+{
+ struct dev_ext *ext;
+ void *handle_ptr;
+
+ handle_ptr = dev->ext.handle;
+
+ if (!(ext = _ext_registry[dev->ext.src].dev_ext_get(dev)))
+ log_error("Failed to get external handle for device %s [%s].",
+ dev_name(dev), dev_ext_name(dev));
+ else if (handle_ptr != dev->ext.handle)
+ log_debug_devs("%s %s [%s:%p]", _ext_attached_msg, dev_name(dev),
+ dev_ext_name(dev), dev->ext.handle);
+
+ return ext;
+}
+
+int dev_ext_release(struct device *dev)
+{
+ int r;
+ void *handle_ptr;
+
+ if (!dev->ext.enabled ||
+ !dev->ext.handle)
+ return 1;
+
+ handle_ptr = dev->ext.handle;
+
+ if (!(r = _ext_registry[dev->ext.src].dev_ext_release(dev)))
+ log_error("Failed to release external handle for device %s [%s:%p].",
+ dev_name(dev), dev_ext_name(dev), dev->ext.handle);
+ else
+ log_debug_devs("External handle detached from device %s [%s:%p]",
+ dev_name(dev), dev_ext_name(dev), handle_ptr);
+
+ return r;
+}
+
+int dev_ext_enable(struct device *dev, dev_ext_t src)
+{
+ if (dev->ext.enabled && (dev->ext.src != src) && !dev_ext_release(dev)) {
+ log_error("Failed to enable external handle for device %s [%s].",
+ dev_name(dev), _ext_registry[src].name);
+ return 0;
+ }
+
+ dev->ext.src = src;
+ dev->ext.enabled = 1;
+
+ return 1;
+}
+
+int dev_ext_disable(struct device *dev)
+{
+ if (!dev->ext.enabled)
+ return 1;
+
+ if (!dev_ext_release(dev)) {
+ log_error("Failed to disable external handle for device %s [%s].",
+ dev_name(dev), dev_ext_name(dev));
+ return 0;
+ }
+
+ dev->ext.enabled = 0;
+ dev->ext.src = DEV_EXT_NONE;
+
+ return 1;
+}
diff --git a/lib/device/device.h b/lib/device/device.h
index c916a4b..0d38f96 100644
--- a/lib/device/device.h
+++ b/lib/device/device.h
@@ -29,6 +29,23 @@
#define DEV_O_DIRECT_TESTED 0x00000040 /* DEV_O_DIRECT is reliable */
/*
+ * Support for external device info.
+ * Any new external device info source needs to be
+ * registered using EXT_REGISTER macro in dev-ext.c.
+ */
+typedef enum {
+ DEV_EXT_NONE,
+ DEV_EXT_UDEV,
+ DEV_EXT_NUM
+} dev_ext_t;
+
+struct dev_ext {
+ int enabled;
+ dev_ext_t src;
+ void *handle;
+};
+
+/*
* All devices in LVM will be represented by one of these.
* pointer comparisons are valid.
*/
@@ -47,6 +64,7 @@ struct device {
uint32_t flags;
uint64_t end;
struct dm_list open_list;
+ struct dev_ext ext;
char pvid[ID_LEN + 1];
char _padding[7];
@@ -64,6 +82,15 @@ struct device_area {
};
/*
+ * Support for external device info.
+ */
+const char *dev_ext_name(struct device *dev);
+int dev_ext_enable(struct device *dev, dev_ext_t src);
+int dev_ext_disable(struct device *dev);
+struct dev_ext *dev_ext_get(struct device *dev);
+int dev_ext_release(struct device *dev);
+
+/*
* All io should use these routines.
*/
int dev_get_block_size(struct device *dev, unsigned int *phys_block_size, unsigned int *block_size);
8 years
master - revert "cache: add pool deps for preload"
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=578b236a19fab5...
Commit: 578b236a19fab565a4416b17cbc26d53a72b66db
Parent: d021284bcfda0222f10787ea798077f312ee3275
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Jan 30 12:31:09 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Jan 30 12:33:52 2015 +0100
revert "cache: add pool deps for preload"
This reverts commit c3bb6d77dd6193755070c62c6f3adb93c1976f19.
Since we now have for_each_sub_lv() scanning all sub LVs,
this commit could be safely reverted.
---
lib/activate/activate.c | 5 -----
1 files changed, 0 insertions(+), 5 deletions(-)
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index fc9bc4b..dbfb427 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -1876,11 +1876,6 @@ static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
if (!for_each_sub_lv((struct logical_volume *)ondisk_lv, &_preload_detached_lv, &detached))
goto_out;
- /* ATM cache/thin pool is not scanned in 'for_each_sub_lv()', TODO explore better way */
- if (lv_is_cache(ondisk_lv) &&
- !for_each_sub_lv(first_seg(ondisk_lv)->pool_lv, &_preload_detached_lv, &detached))
- goto_out;
-
/*
* Preload any snapshots that are being removed.
*/
8 years