summaryrefslogtreecommitdiff
path: root/lib/commands/toolcontext.c
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2020-06-23 13:25:41 -0500
committerDavid Teigland <teigland@redhat.com>2020-07-16 16:00:28 -0500
commit150cffe7c52289203edbc318a7494be42fa659c3 (patch)
tree06b5f38e9547ad96d270aa0036f91601bb15c40a /lib/commands/toolcontext.c
parentb0787033023fdc213f3fdd3efc488e70f44e1fcd (diff)
downloadlvm2-dev-dct-deviceid-7.tar.gz
device usage based on devices_file and device_iddev-dct-deviceid-7
devices_file, e.g. /etc/lvm/lvm_devices.dat, is a list of devices that lvm can use. Option --devicesfile can sepecify a different file with a separate set of devices for lvm to use. This option allows different applications to use lvm on different sets of devices. In most cases (with limited exceptions), lvm will not read or use a device not listed in devices_file. When the devices_file is used, the filter-regex is not used and the filter settings in lvm.conf are ignored. lvm uses the devices_file to control access to devices using the new filter-deviceid. Setting --devicesfile to "" on the command line, or devicesfile to "" in lvm.conf will disable the use of the devices_file and filter-deviceid. This allows lvm to see and use any device on the system. In this case lvm will fall back to using filter-regex and the filter config settings in lvm.conf. device_id, e.g. wwid or serial number from sysfs, is a unique ID that identifies a device without reading it, and which will change if the device is copied to another. The device_id is used in the devices_file and is included in VG metadata sections. Each device_id has a device_id_type which indicates where the device_id comes from, e.g. "sys_wwid" means the device_id comes from the sysfs wwid file. Others are sys_serial, mpath_uuid, loop_file, devname. (devname is the device path which is a fallback when no other proper device_id_type is available.) filter-deviceid permits lvm to use only devices on the system that have a device_id matching a devices_file entry. Using the device_id, lvm can determine the set of devices to use without reading any devices, so devices_file will constrain lvm in two ways: 1. it limits the devices that lvm will read. 2. it limits the devices that lvm will use. In some uncommon cases, e.g. when devices have no unique ID and device_id has to fall back to using the devname, lvm may need to read all devices on the system to determine which ones correspond to the devices_file entries. In this case, the devices_file does not limit the devices that lvm reads, but it does limit the devices that lvm uses. pvcreate/vgcreate/vgextend are not constrained by the devices_file, and will look outside it to find the new PV. They assign the new PV a device_id and add it to the devices_file. It is also possible to explicitly add new PVs to devices_file before using them in pvcreate/etc, in which case these commands would not need to access devices outside devices_file. (A config setting may be added to control the ability of these commands to search outside devices_file.) vgimportdevices VG looks at all devices on the system to find an existing VG and add its devices to the devices_file. The command is not limited by an existing devices_file. The command will also add device_ids to the VG metadata if the VG does not yet include device_ids. vgimportdevices -a imports devices for all accessible VGs. Since vgimportdevices does not limit itself to devices in an existing devices_file, the lvm.conf regex filter applies. Adding --foreign will import devices for foreign VGs, but device_ids are not added to foreign VGs. Incomplete VGs are not imported. The lvmdevices command manages the devices file. The primary purpose is to edit the devices file, but it will read PV headers to find/check PVIDs. (It does not read, process or modify VG metadata.) lvmdevices . Displays devices_file entries. lvmdevices --check . Checks devices_file entries. lvmdevices --update . Updates devices_file entries. lvmdevices --adddev <devname> . Adds devices_file entry (reads pv header). lvmdevices --deldev <devname> . Removes devices_file entry. lvmdevices --addpvid <pvid> . Reads pv header of all devices to find <pvid>, and if found adds devices_file entry. lvmdevices --delpvid <pvid> . Removes devices_file entry. TODO: pvchange --deviceidupdate PV vgchange --deviceidupdate VG duplicate PV resolution using device_id vgimportclone needs to update device_file pvchange --uuid needs to update device_file config setting device_id_types to control idtypes used search for pvid when no wwid is available and PV is missing device_id_type for md devices config setting pvcreate_extends_devices_file=0|1 shortsystemid crc of systemid and written in pv header use shortsystemid for new filter and orphan PV ownership
Diffstat (limited to 'lib/commands/toolcontext.c')
-rw-r--r--lib/commands/toolcontext.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 63b6811e5..e4e7b6757 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1066,7 +1066,14 @@ static int _init_dev_cache(struct cmd_context *cmd)
return 1;
}
-#define MAX_FILTERS 10
+static int _init_device_ids(struct cmd_context *cmd)
+{
+ dm_list_init(&cmd->use_device_ids);
+ cmd->devices_file = find_config_tree_str(cmd, devices_devicesfile_CFG, NULL);
+ return 1;
+}
+
+#define MAX_FILTERS 11
static struct dev_filter *_init_filter_chain(struct cmd_context *cmd)
{
@@ -1085,6 +1092,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 +1133,13 @@ static struct dev_filter *_init_filter_chain(struct cmd_context *cmd)
}
nr_filt++;
+ /* filter based on the device_ids saved in the lvm_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");
@@ -1717,6 +1734,9 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd,
if (!_init_dev_cache(cmd))
goto_out;
+ if (!_init_device_ids(cmd))
+ return_0;
+
memlock_init(cmd);
if (!_init_formats(cmd))
@@ -1921,6 +1941,9 @@ int refresh_toolcontext(struct cmd_context *cmd)
if (!_init_dev_cache(cmd))
return_0;
+ if (!_init_device_ids(cmd))
+ return_0;
+
if (!_init_formats(cmd))
return_0;