Skip to contentSkip to conversation

main - device usage based on devices file

PATCH David Teigland 1 participant 1 message Feb 23, 2021 Library code

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=83fe6e720f42711ff183a66909b690b726702f58
Commit:        83fe6e720f42711ff183a66909b690b726702f58
Parent:        f7d9542aed2615c2a3737ec055a15b79877ac7fc
Author:        David Teigland <[email protected]>
AuthorDate:    Tue Jun 23 13:25:41 2020 -0500
Committer:     David Teigland <[email protected]>
CommitterDate: Tue Feb 23 16:43:32 2021 -0600

device usage based on devices file

The LVM devices file lists devices that lvm can use. The default file is /etc/lvm/devices/system.devices, and the lvmdevices(8) command is used to add or remove device entries. If the file does not exist, or if lvm.conf includes use_devicesfile=0, then lvm will not use a devices file. When the devices file is in use, the regex filter is not used, and the filter settings in lvm.conf or on the command line are ignored.

LVM records devices in the devices file using hardware-specific IDs, such as the WWID, and attempts to use subsystem-specific IDs for virtual device types. These device IDs are also written in the VG metadata. When no hardware or virtual ID is available, lvm falls back using the unstable device name as the device ID. When devnames are used, lvm performs extra scanning to find devices if their devname changes, e.g. after reboot.

When proper device IDs are used, an lvm command will not look at devices outside the devices file, but when devnames are used as a fallback, lvm will scan devices outside the devices file to locate PVs on renamed devices. A config setting search_for_devnames can be used to control the scanning for renamed devname entries.

Related to the devices file, the new command option --devices <devnames> allows a list of devices to be specified for the command to use, overriding the devices file. The listed devices act as a sort of devices file in terms of limiting which devices lvm will see and use. Devices that are not listed will appear to be missing to the lvm command.

Multiple devices files can be kept in /etc/lvm/devices, which allows lvm to be used with different sets of devices, e.g. system devices do not need to be exposed to a specific application, and the application can use lvm on its own set of devices that are not exposed to the system. The option --devicesfile <filename> is used to select the devices file to use with the command. Without the option set, the default system devices file is used.

Setting --devicesfile "" causes lvm to not use a devices file.

An existing, empty devices file means lvm will see no devices.

The new command vgimportdevices adds PVs from a VG to the devices file and updates the VG metadata to include the device IDs. vgimportdevices -a will import all VGs into the system devices file.

LVM commands run by dmeventd not use a devices file by default, and will look at all devices on the system. A devices file can be created for dmeventd (/etc/lvm/devices/dmeventd.devices) If this file exists, lvm commands run by dmeventd will use it.

Internal implementaion:

- device_ids_read - read the devices file
. add struct dev_use (du) to cmd->use_devices for each devices file entry
- dev_cache_scan - get /dev entries
. add struct device (dev) to dev_cache for each device on the system
- device_ids_match - match devices file entries to /dev entries . match each du on cmd->use_devices to a dev in dev_cache, using device ID . on match, set du->dev, dev->id, dev->flags MATCHED_USE_ID
- label_scan - read lvm headers and metadata from devices
. filters are applied, those that do not need data from the device . filter-deviceid skips devs without MATCHED_USE_ID, i.e.
skips /dev entries that are not listed in the devices file
. read lvm label from dev
. filters are applied, those that use data from the device
. read lvm metadata from dev
. add info/vginfo structs for PVs/VGs (info is "lvmcache")
- device_ids_find_renamed_devs - handle devices with unstable devname ID where devname changed
. this step only needed when devs do not have proper device IDs,
and their dev names change, e.g. after reboot sdb becomes sdc.
. detect incorrect match because PVID in the devices file entry
does not match the PVID found when the device was read above
. undo incorrect match between du and dev above
. search system devices for new location of PVID
. update devices file with new devnames for PVIDs on renamed devices . label_scan the renamed devs
- continue with command processing

---
 daemons/lvmpolld/lvmpolld-cmd-utils.c  |    6 +
 daemons/lvmpolld/lvmpolld-core.c       |    8 +-
 daemons/lvmpolld/lvmpolld-data-utils.c |    7 +-
 daemons/lvmpolld/lvmpolld-data-utils.h |    4 +-
 daemons/lvmpolld/lvmpolld-protocol.h   |    1 +
 lib/Makefile.in                        |    2 +
 lib/cache/lvmcache.c                   |   88 +-
 lib/cache/lvmcache.h                   |    2 +
 lib/commands/toolcontext.c             |   20 +-
 lib/commands/toolcontext.h             |   14 +
 lib/config/config_settings.h           |   26 +
 lib/config/defaults.h                  |    5 +
 lib/device/dev-cache.c                 |  353 ++++-
 lib/device/dev-cache.h                 |    7 +-
 lib/device/dev-type.c                  |   39 +
 lib/device/dev-type.h                  |    1 +
 lib/device/device.h                    |   44 +
 lib/device/device_id.c                 | 2320 ++++++++++++++++++++++++++++++++
 lib/device/device_id.h                 |   55 +
 lib/filters/filter-deviceid.c          |   69 +
 lib/filters/filter-regex.c             |    7 +
 lib/filters/filter.h                   |    3 +
 lib/format_text/export.c               |    9 +
 lib/format_text/import_vsn1.c          |   34 +-
 lib/label/hints.c                      |   57 +-
 lib/label/label.c                      |   61 +-
 lib/label/label.h                      |    1 -
 lib/lvmpolld/lvmpolld-client.c         |    7 +
 lib/lvmpolld/polldaemon.h              |    1 +
 lib/metadata/pv.c                      |   14 +
 lib/metadata/pv.h                      |    4 +
 lib/report/columns.h                   |    2 +
 lib/report/properties.c                |    4 +
 lib/report/report.c                    |   36 +
 man/Makefile.in                        |    2 +-
 man/lvm.8_main                         |    6 +
 man/lvmdevices.8_des                   |   62 +
 man/lvmdevices.8_end                   |    0
 man/see_also.end                       |    2 +
 man/vgimportdevices.8_des              |   11 +
 man/vgimportdevices.8_end              |    0
 spec/packages.inc                      |    4 +
 tools/Makefile.in                      |    2 +
 tools/args.h                           |   30 +
 tools/command-lines.in                 |   46 +-
 tools/commands.h                       |    8 +
 tools/lvmcmdline.c                     |   71 +-
 tools/lvmdevices.c                     |  465 +++++++
 tools/polldaemon.c                     |    9 +
 tools/pvchange.c                       |   17 +
 tools/pvck.c                           |   42 +-
 tools/pvcreate.c                       |    2 +
 tools/pvscan.c                         |   48 +-
 tools/toollib.c                        |   29 +-
 tools/tools.h                          |    1 +
 tools/vgcreate.c                       |    4 +
 tools/vgextend.c                       |    4 +
 tools/vgimportclone.c                  |  420 ++++--
 tools/vgimportdevices.c                |  207 +++
 59 files changed, 4614 insertions(+), 189 deletions(-)
daemons/lvmpolld/lvmpolld-cmd-utils.c +6 -0
index 865b47ec9..2c3a77fac 100644
@@ -92,6 +92,12 @@ const char **cmdargv_ctr(const struct lvmpolld_lv *pdlv, const char *lvm_binary,
 	if (!add_to_cmd_arr(&cmd_argv, "-An", &i))
 		goto err;
 
+	if (pdlv->devicesfile) {
+		if (!add_to_cmd_arr(&cmd_argv, "--devicesfile", &i) ||
+		    !add_to_cmd_arr(&cmd_argv, pdlv->devicesfile, &i))
+			goto err;
+	}
+
 	/* terminating NULL */
 	if (!add_to_cmd_arr(&cmd_argv, NULL, &i))
 		goto err;
daemons/lvmpolld/lvmpolld-core.c +5 -3
index af98843c9..f7381eb35 100644
@@ -555,14 +555,15 @@ static struct lvmpolld_lv *construct_pdlv(request req, struct lvmpolld_state *ls
 				     const char *interval, const char *id,
 				     const char *vgname, const char *lvname,
 				     const char *sysdir, enum poll_type type,
-				     unsigned abort_polling, unsigned uinterval)
+				     unsigned abort_polling, unsigned uinterval,
+				     const char *devicesfile)
 {
 	const char **cmdargv, **cmdenvp;
 	struct lvmpolld_lv *pdlv;
 	unsigned handle_missing_pvs = daemon_request_int(req, LVMPD_PARM_HANDLE_MISSING_PVS, 0);
 
 	pdlv = pdlv_create(ls, id, vgname, lvname, sysdir, type,
-			   interval, uinterval, pdst);
+			   interval, uinterval, pdst, devicesfile);
 
 	if (!pdlv) {
 		ERROR(ls, "%s: %s", PD_LOG_PREFIX, "failed to create internal LV data structure.");
@@ -621,6 +622,7 @@ static response poll_init(client_handle h, struct lvmpolld_state *ls, request re
 	const char *lvname = daemon_request_str(req, LVMPD_PARM_LVNAME, NULL);
 	const char *vgname = daemon_request_str(req, LVMPD_PARM_VGNAME, NULL);
 	const char *sysdir = daemon_request_str(req, LVMPD_PARM_SYSDIR, NULL);
+	const char *devicesfile = daemon_request_str(req, LVMPD_PARM_DEVICESFILE, NULL);
 	unsigned abort_polling = daemon_request_int(req, LVMPD_PARM_ABORT, 0);
 
 	assert(type < POLL_TYPE_MAX);
@@ -680,7 +682,7 @@ static response poll_init(client_handle h, struct lvmpolld_state *ls, request re
 		pdlv->init_rq_count++; /* safe. protected by store lock */
 	} else {
 		pdlv = construct_pdlv(req, ls, pdst, interval, id, vgname,
-				      lvname, sysdir, type, abort_polling, 2 * uinterval);
+				      lvname, sysdir, type, abort_polling, 2 * uinterval, devicesfile);
 		if (!pdlv) {
 			pdst_unlock(pdst);
 			free(id);
daemons/lvmpolld/lvmpolld-data-utils.c +6 -1
index 23e316a96..6b66f1b67 100644
@@ -93,11 +93,13 @@ struct lvmpolld_lv *pdlv_create(struct lvmpolld_state *ls, const char *id,
 			   const char *vgname, const char *lvname,
 			   const char *sysdir, enum poll_type type,
 			   const char *sinterval, unsigned pdtimeout,
-			   struct lvmpolld_store *pdst)
+			   struct lvmpolld_store *pdst,
+			   const char *devicesfile)
 {
 	char *lvmpolld_id = strdup(id), /* copy */
 	     *full_lvname = _construct_full_lvname(vgname, lvname), /* copy */
 	     *lvm_system_dir_env = _construct_lvm_system_dir_env(sysdir); /* copy */
+	char *devicesfile_dup = devicesfile ? strdup(devicesfile) : NULL;
 
 	struct lvmpolld_lv tmp = {
 		.ls = ls,
@@ -105,6 +107,7 @@ struct lvmpolld_lv *pdlv_create(struct lvmpolld_state *ls, const char *id,
 		.lvmpolld_id = lvmpolld_id,
 		.lvid = _get_lvid(lvmpolld_id, sysdir),
 		.lvname = full_lvname,
+		.devicesfile = devicesfile_dup,
 		.lvm_system_dir_env = lvm_system_dir_env,
 		.sinterval = strdup(sinterval), /* copy */
 		.pdtimeout = pdtimeout < MIN_POLLING_TIMEOUT ? MIN_POLLING_TIMEOUT : pdtimeout,
@@ -124,6 +127,7 @@ struct lvmpolld_lv *pdlv_create(struct lvmpolld_state *ls, const char *id,
 	return pdlv;
 
 err:
+	free((void *)devicesfile_dup);
 	free((void *)full_lvname);
 	free((void *)lvmpolld_id);
 	free((void *)lvm_system_dir_env);
@@ -136,6 +140,7 @@ err:
 void pdlv_destroy(struct lvmpolld_lv *pdlv)
 {
 	free((void *)pdlv->lvmpolld_id);
+	free((void *)pdlv->devicesfile);
 	free((void *)pdlv->lvname);
 	free((void *)pdlv->sinterval);
 	free((void *)pdlv->lvm_system_dir_env);
daemons/lvmpolld/lvmpolld-data-utils.h +3 -1
index 5bb5c863d..96a27f1c8 100644
@@ -49,6 +49,7 @@ struct lvmpolld_lv {
 	const enum poll_type type;
 	const char *const lvid;
 	const char *const lvmpolld_id;
+	const char *const devicesfile;
 	const char *const lvname; /* full vg/lv name */
 	const unsigned pdtimeout; /* in seconds */
 	const char *const sinterval;
@@ -101,7 +102,8 @@ struct lvmpolld_lv *pdlv_create(struct lvmpolld_state *ls, const char *id,
 			   const char *vgname, const char *lvname,
 			   const char *sysdir, enum poll_type type,
 			   const char *sinterval, unsigned pdtimeout,
-			   struct lvmpolld_store *pdst);
+			   struct lvmpolld_store *pdst,
+			   const char *devicesfile);
 
 /* only call with appropriate struct lvmpolld_store lock held */
 void pdlv_destroy(struct lvmpolld_lv *pdlv);
daemons/lvmpolld/lvmpolld-protocol.h +1 -0
index 9b9890d7b..18c7de85a 100644
@@ -35,6 +35,7 @@
 #define LVMPD_PARM_SYSDIR		"sysdir"
 #define LVMPD_PARM_VALUE		"value" /* either retcode or signal value */
 #define LVMPD_PARM_VGNAME		"vgname"
+#define LVMPD_PARM_DEVICESFILE		"devicesfile"
 
 #define LVMPD_RESP_FAILED	"failed"
 #define LVMPD_RESP_FINISHED	"finished"
lib/Makefile.in +2 -0
index 8e50ec45c..3409cbd8c 100644
@@ -29,6 +29,7 @@ SOURCES =\
 	device/bcache.c \
 	device/bcache-utils.c \
 	device/dev-cache.c \
+	device/device_id.c \
 	device/dev-ext.c \
 	device/dev-io.c \
 	device/dev-md.c \
@@ -52,6 +53,7 @@ SOURCES =\
 	filters/filter-usable.c \
 	filters/filter-internal.c \
 	filters/filter-signature.c \
+	filters/filter-deviceid.c \
 	format_text/archive.c \
 	format_text/archiver.c \
 	format_text/export.c \
lib/cache/lvmcache.c +84 -4

160 lines not on this page · raw message

lib/cache/lvmcache.h +2 -0
index d00bba575..76429fc5b 100644
@@ -224,4 +224,6 @@ struct metadata_area *lvmcache_get_dev_mda(struct device *dev, int mda_num);
 
 void lvmcache_extra_md_component_checks(struct cmd_context *cmd);
 
+unsigned int lvmcache_vg_info_count(void);
+
 #endif
lib/commands/toolcontext.c +19 -1
index 63b6811e5..c3de18d7f 100644
@@ -32,6 +32,7 @@
 #include "lib/cache/lvmcache.h"
 #include "lib/format_text/archiver.h"
 #include "lib/lvmpolld/lvmpolld-client.h"
+#include "lib/device/device_id.h"
 
 #include <locale.h>
 #include <sys/stat.h>
@@ -1066,7 +1067,7 @@ static int _init_dev_cache(struct cmd_context *cmd)
 	return 1;
 }
 
-#define MAX_FILTERS 10
+#define MAX_FILTERS 11
 
 static struct dev_filter *_init_filter_chain(struct cmd_context *cmd)
 {
@@ -1085,6 +1086,9 @@ static struct dev_filter *_init_filter_chain(struct cmd_context *cmd)
 	 * sysfs filter. Only available on 2.6 kernels.  Non-critical.
 	 * Listed first because it's very efficient at eliminating
 	 * unavailable devices.
+	 *
+	 * TODO: I suspect that using the lvm_type and device_id
+	 * filters before this one may be more efficient.
 	 */
 	if (find_config_tree_bool(cmd, devices_sysfs_scan_CFG, NULL)) {
 		if ((filters[nr_filt] = sysfs_filter_create()))
@@ -1123,6 +1127,13 @@ static struct dev_filter *_init_filter_chain(struct cmd_context *cmd)
 	}
 	nr_filt++;
 
+	/* filter based on the device_ids saved in the devices file */
+	if (!(filters[nr_filt] = deviceid_filter_create(cmd))) {
+		log_error("Failed to create deviceid device filter");
+		goto bad;
+	}
+	nr_filt++;
+
 	/* usable device filter. Required. */
 	if (!(filters[nr_filt] = usable_filter_create(cmd, cmd->dev_types, FILTER_MODE_NO_LVMETAD))) {
 		log_error("Failed to create usabled device filter");
@@ -1485,6 +1496,7 @@ int init_run_by_dmeventd(struct cmd_context *cmd)
 	init_dmeventd_monitor(DMEVENTD_MONITOR_IGNORE);
 	init_ignore_suspended_devices(1);
 	init_disable_dmeventd_monitoring(1); /* Lock settings */
+	cmd->run_by_dmeventd = 1;
 
 	return 0;
 }
@@ -1717,6 +1729,8 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd,
 	if (!_init_dev_cache(cmd))
 		goto_out;
 
+	devices_file_init(cmd);
+
 	memlock_init(cmd);
 
 	if (!_init_formats(cmd))
@@ -1842,6 +1856,7 @@ int refresh_toolcontext(struct cmd_context *cmd)
 	_destroy_segtypes(&cmd->segtypes);
 	_destroy_formats(cmd, &cmd->formats);
 
+	devices_file_exit(cmd);
 	if (!dev_cache_exit())
 		stack;
 	_destroy_dev_types(cmd);
@@ -1921,6 +1936,8 @@ int refresh_toolcontext(struct cmd_context *cmd)
 	if (!_init_dev_cache(cmd))
 		return_0;
 
+	devices_file_init(cmd);
+
 	if (!_init_formats(cmd))
 		return_0;
 
@@ -1970,6 +1987,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
 	_destroy_filters(cmd);
 	if (cmd->mem)
 		dm_pool_destroy(cmd->mem);
+	devices_file_exit(cmd);
 	dev_cache_exit();
 	_destroy_dev_types(cmd);
 	_destroy_tags(cmd);
lib/commands/toolcontext.h +14 -0
index d20768ad0..977b31412 100644
@@ -182,14 +182,27 @@ struct cmd_context {
 	unsigned pvscan_recreate_hints:1;	/* enable special case hint handling for pvscan --cache */
 	unsigned scan_lvs:1;
 	unsigned wipe_outdated_pvs:1;
+	unsigned enable_devices_list:1;		/* command is using --devices option */
+	unsigned enable_devices_file:1;		/* command is using devices file */
+	unsigned pending_devices_file:1;	/* command may create and enable devices file */
+	unsigned create_edit_devices_file:1;	/* command expects to create and/or edit devices file */
+	unsigned edit_devices_file:1;		/* command expects to edit devices file */
+	unsigned filter_deviceid_skip:1;	/* don't use filter-deviceid */
+	unsigned filter_regex_with_devices_file:1; /* use filter-regex even when devices file is enabled */
 	unsigned filter_nodata_only:1;          /* only use filters that do not require data from the dev */
+	unsigned run_by_dmeventd:1;		/* command is being run by dmeventd */
+	unsigned sysinit:1;			/* --sysinit is used */
 
 	/*
 	 * Devices and filtering.
 	 */
 	struct dev_filter *filter;
 	struct dm_list hints;
+	struct dm_list use_devices;		/* struct dev_use for each entry in devices file */
 	const char *md_component_checks;
+	const char *search_for_devnames;	/* config file setting */
+	const char *devicesfile;                /* from --devicesfile option */
+	struct dm_list deviceslist;             /* from --devices option, struct dm_str_list */
 
 	/*
 	 * Configuration.
@@ -221,6 +234,7 @@ struct cmd_context {
 	char system_dir[PATH_MAX];
 	char dev_dir[PATH_MAX];
 	char proc_dir[PATH_MAX];
+	char devices_file_path[PATH_MAX];
 
 	/*
 	 * Reporting.
lib/config/config_settings.h +26 -0
index d61b707e9..ee5d97721 100644
@@ -288,6 +288,32 @@ cfg_array(devices_preferred_names_CFG, "preferred_names", devices_CFG_SECTION, C
 	"preferred_names = [ \"^/dev/mpath/\", \"^/dev/mapper/mpath\", \"^/dev/[hs]d\" ]\n"
 	"#\n")
 
+cfg(devices_use_devicesfile_CFG, "use_devicesfile", devices_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_BOOL, DEFAULT_USE_DEVICES_FILE, vsn(2, 3, 12), NULL, 0, NULL,
+	"Enable or disable the use of a devices file.\n"
+	"When enabled, lvm will only use devices that\n"
+	"are lised in the devices file. A devices file will\n"
+	"be used, regardless of this setting, when the --devicesfile\n"
+	"option is set to a specific file name.\n")
+
+cfg(devices_devicesfile_CFG, "devicesfile", devices_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_STRING, DEFAULT_DEVICES_FILE, vsn(2, 3, 12), NULL, 0, NULL,
+	"The name of the system devices file, listing devices that LVM should use.\n"
+	"This should not be used to select a non-system devices file.\n"
+	"The --devicesfile option is intended for alternative devices files.\n")
+
+cfg(devices_search_for_devnames_CFG, "search_for_devnames", devices_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_STRING, DEFAULT_SEARCH_FOR_DEVNAMES, vsn(2, 3, 12), NULL, 0, NULL,
+	"Look outside of the devices file for missing devname entries.\n"
+	"A devname entry is used for a device that does not have a stable\n"
+	"device id, e.g. wwid, so the unstable device name is used as\n"
+	"the device id. After reboot, or if the device is reattached,\n"
+	"the device name may change, in which case lvm will not find\n"
+	"the expected PV on the device listed in the devices file.\n"
+	"This setting controls whether lvm will search other devices,\n"
+	"outside the devices file, to look for the missing PV on a\n"
+	"renamed device. If \"none\", lvm will not look at other devices,\n"
+	"and the PV may appear to be missing. If \"auto\", lvm will look\n"
+	"at other devices, but only those that are likely to have the PV.\n"
+	"If \"all\", lvm will look at all devices on the system.\n")
+
 cfg_array(devices_filter_CFG, "filter", devices_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_STRING, "#Sa|.*|", vsn(1, 0, 0), NULL, 0, NULL,
 	"Limit the block devices that are used by LVM commands.\n"
 	"This is a list of regular expressions used to accept or reject block\n"
lib/config/defaults.h +5 -0
index bcc20cc97..2870dee12 100644
@@ -323,4 +323,9 @@
 
 #define DEFAULT_MD_COMPONENT_CHECKS "auto"
 
+#define DEFAULT_USE_DEVICES_FILE 0
+#define DEFAULT_DEVICES_FILE "system.devices"
+
+#define DEFAULT_SEARCH_FOR_DEVNAMES "auto"
+
 #endif				/* _LVM_DEFAULTS_H */
lib/device/dev-cache.c +348 -5

408 lines not on this page · raw message

lib/device/dev-cache.h +6 -1
index 7285bc3a7..9b7e39d33 100644
@@ -34,7 +34,6 @@ struct dev_filter {
 	const char *name;
 };
 
-int dev_cache_index_devs(void);
 struct dm_list *dev_cache_get_dev_list_for_vgid(const char *vgid);
 struct dm_list *dev_cache_get_dev_list_for_lvid(const char *lvid);
 
@@ -75,4 +74,10 @@ void dev_cache_failed_path(struct device *dev, const char *path);
 
 bool dev_cache_has_md_with_end_superblock(struct dev_types *dt);
 
+int get_sysfs_value(const char *path, char *buf, size_t buf_size, int error_if_no_value);
+
+int setup_devices_file(struct cmd_context *cmd);
+int setup_devices(struct cmd_context *cmd);
+int setup_device(struct cmd_context *cmd, const char *devname);
+
 #endif
lib/device/dev-type.c +39 -0
index 0411572fa..40c2a748e 100644
@@ -363,6 +363,45 @@ static int _loop_is_with_partscan(struct device *dev)
 	return partscan;
 }
 
+int dev_get_partition_number(struct device *dev, int *num)
+{
+	char path[PATH_MAX];
+	char buf[8] = { 0 };
+	dev_t devt = dev->dev;
+	struct stat sb;
+
+	if (dev->part != -1) {
+		*num = dev->part;
+		return 1;
+	}
+
+	if (dm_snprintf(path, sizeof(path), "%sdev/block/%d:%d/partition",
+			dm_sysfs_dir(), (int)MAJOR(devt), (int)MINOR(devt)) < 0) {
+		log_error("Failed to create sysfs path for %s", dev_name(dev));
+		return 0;
+	}
+
+	if (stat(path, &sb)) {
+		dev->part = 0;
+		*num = 0;
+		return 1;
+	}
+
+	if (!get_sysfs_value(path, buf, sizeof(buf), 0)) {
+		log_error("Failed to read sysfs path for %s", dev_name(dev));
+		return 0;
+	}
+
+	if (!buf[0]) {
+		log_error("Failed to read sysfs partition value for %s", dev_name(dev));
+		return 0;
+	}
+
+	dev->part = atoi(buf);
+	*num = dev->part;
+	return 1;
+}
+
 /* See linux/genhd.h and fs/partitions/msdos */
 #define PART_MAGIC 0xAA55
 #define PART_MAGIC_OFFSET UINT64_C(0x1FE)
lib/device/dev-type.h +1 -0
index f96b67ca3..45377c144 100644
@@ -83,6 +83,7 @@ int dev_is_md_with_end_superblock(struct dev_types *dt, struct device *dev);
 int major_max_partitions(struct dev_types *dt, int major);
 int dev_is_partitioned(struct dev_types *dt, struct device *dev);
 int dev_get_primary_dev(struct dev_types *dt, struct device *dev, dev_t *result);
+int dev_get_partition_number(struct device *dev, int *num);
 
 /* Various device properties */
 unsigned long dev_alignment_offset(struct dev_types *dt, struct device *dev);
lib/device/device.h +44 -0

68 lines not on this page · raw message

lib/device/device_id.c new file +2320 -0

2,024 lines not on this page · raw message

lib/device/device_id.h new file +55 -0

55 lines not on this page · raw message

lib/filters/filter-deviceid.c new file +69 -0

69 lines not on this page · raw message

lib/filters/filter-regex.c +7 -0
index 7575981af..c6916983b 100644

Lines of this file are not shown. View the raw message.

lib/filters/filter.h +3 -0
index bfd045be5..bd4293090 100644

Lines of this file are not shown. View the raw message.

lib/format_text/export.c +9 -0
index b5e987e01..33844a2fd 100644

Lines of this file are not shown. View the raw message.

lib/format_text/import_vsn1.c +27 -7
index 2bdbfeea9..ee56502e1 100644

Lines of this file are not shown. View the raw message.

lib/label/hints.c +50 -7

57 lines not on this page · raw message

lib/label/label.c +44 -17

61 lines not on this page · raw message

lib/label/label.h +0 -1
index 78724c1ce..fae0f1bcc 100644

Lines of this file are not shown. View the raw message.

lib/lvmpolld/lvmpolld-client.c +7 -0
index 1a76485c1..015cefafb 100644

Lines of this file are not shown. View the raw message.

lib/lvmpolld/polldaemon.h +1 -0
index 17ef7cb44..40ce7a546 100644

Lines of this file are not shown. View the raw message.

lib/metadata/pv.c +14 -0
index 9cebbac01..855d52594 100644

Lines of this file are not shown. View the raw message.

lib/metadata/pv.h +4 -0
index efa13e04b..95525a41a 100644

Lines of this file are not shown. View the raw message.

lib/report/columns.h +2 -0
index 426a32c50..8d2f7a993 100644

Lines of this file are not shown. View the raw message.

lib/report/properties.c +4 -0
index c013152f2..82a6a7856 100644

Lines of this file are not shown. View the raw message.

lib/report/report.c +36 -0
index 2f50a990c..80fae2147 100644

Lines of this file are not shown. View the raw message.

man/Makefile.in +1 -1
index 114e92b2a..3d4569673 100644

Lines of this file are not shown. View the raw message.

man/lvm.8_main +6 -0
index 9816f5fb6..ba151e367 100644

Lines of this file are not shown. View the raw message.

man/lvmdevices.8_des new file +62 -0

62 lines not on this page · raw message

man/lvmdevices.8_end new file +0 -0
new file mode 100644
index 000000000..e69de29bb
man/see_also.end +2 -0
index 505c1599a..4dc9b0ec0 100644

Lines of this file are not shown. View the raw message.

man/vgimportdevices.8_des new file +11 -0
new file mode 100644
index 000000000..7c2287cfd

Lines of this file are not shown. View the raw message.

man/vgimportdevices.8_end new file +0 -0
new file mode 100644
index 000000000..e69de29bb
spec/packages.inc +4 -0
index c0d37936f..71aaeea7a 100644

Lines of this file are not shown. View the raw message.

tools/Makefile.in +2 -0
index 11160e655..b26bc64a6 100644

Lines of this file are not shown. View the raw message.

tools/args.h +30 -0
index 3a7e5d488..ca8f9ec51 100644

Lines of this file are not shown. View the raw message.

tools/command-lines.in +44 -2

46 lines not on this page · raw message

tools/commands.h +8 -0
index ae1bf3934..b12e451f2 100644

Lines of this file are not shown. View the raw message.

tools/lvmcmdline.c +70 -1

71 lines not on this page · raw message

tools/lvmdevices.c new file +465 -0

465 lines not on this page · raw message

tools/polldaemon.c +9 -0
index b0294ebb3..d4e0be13e 100644

Lines of this file are not shown. View the raw message.

tools/pvchange.c +17 -0
index dd72bf1bd..5e457a60b 100644

Lines of this file are not shown. View the raw message.

tools/pvck.c +38 -4

42 lines not on this page · raw message

tools/pvcreate.c +2 -0
index 29ae0fa2e..71eb060a3 100644

Lines of this file are not shown. View the raw message.

tools/pvscan.c +44 -4

48 lines not on this page · raw message

tools/toollib.c +28 -1
index d9295bb82..5c9ccb6f2 100644

Lines of this file are not shown. View the raw message.

tools/tools.h +1 -0
index a0be4bedb..efbe1f44c 100644

Lines of this file are not shown. View the raw message.

tools/vgcreate.c +4 -0
index 09b6a6c95..73066e9a4 100644

Lines of this file are not shown. View the raw message.

tools/vgextend.c +4 -0
index 52393340f..04d37f886 100644

Lines of this file are not shown. View the raw message.

tools/vgimportclone.c +292 -128

420 lines not on this page · raw message

tools/vgimportdevices.c new file +207 -0

207 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.