main - filter-mpath: work with nvme devices
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=bee9f4efdd8195f383f026290b741314cdc42439 Commit: bee9f4efdd8195f383f026290b741314cdc42439 Parent: 48dfc388f7bde964d8e4d6816f27de858c984fb3 Author: David Teigland <[email protected]> AuthorDate: Thu Dec 3 10:48:21 2020 -0600 Committer: David Teigland <[email protected]> CommitterDate: Tue Feb 2 13:01:20 2021 -0600
filter-mpath: work with nvme devices
Recognize when a device is nvme, and apply filter-mpath to nvme devices in addition to scsi devices.
--- lib/device/dev-type.c | 81 +++++++++++++++++++---- lib/device/dev-type.h | 2 + lib/device/device.h | 1 + lib/filters/filter-mpath.c | 156 ++++++++++++++++++++++++++++++--------------- 4 files changed, 177 insertions(+), 63 deletions(-)
lib/device/dev-type.c +68 -13
@@ -21,6 +21,7 @@#include "lib/metadata/metadata.h" #include "lib/device/bcache.h" #include "lib/label/label.h" +#include "lib/commands/toolcontext.h" #ifdef BLKID_WIPING_SUPPORT #include <blkid.h>
@@ -67,6 +68,31 @@ int dev_is_pmem(struct device *dev)return is_pmem ?1 :0 ; } +/* +* An nvme device has major number 259 (BLKEXT), minor number <minor>, +* and reading /sys/dev/block/259:<minor>/device/dev shows a character +* device cmajor:cminor where cmajor matches the major number of the +* nvme character device entry in /proc/devices. Checking all of that +* is excessive and unnecessary compared to just comparing /dev/name*. +*/ + +int dev_is_nvme (struct dev_types *dt,struct device *dev) +{ +struct dm_str_list *strl; + +if (dev->flags &DEV_IS_NVME ) +return 1 ; + + dm_list_iterate_items(strl, &dev->aliases) { +if (!strncmp (strl->str,"/dev/nvme" ,9 )) { +log_debug ("Found nvme device %s" ,dev_name (dev)); + dev->flags |=DEV_IS_NVME ; +return 1 ; + } + } +return 0 ; +} +int dev_is_lv (struct device *dev) {FILE *fp;
@@ -302,6 +328,9 @@ int dev_subsystem_part_major(struct dev_types *dt, struct device *dev)const char *dev_subsystem_name (struct dev_types *dt,struct device *dev) { +if (dev->flags &DEV_IS_NVME ) +return "NVME" ; +if (MAJOR (dev->dev) == dt->device_mapper_major)return "DM" ;
@@ -348,7 +377,6 @@ int major_is_scsi_device(struct dev_types *dt, int major)return (dt->dev_type_array[major].flags &PARTITION_SCSI_DEVICE ) ?1 :0 ; } -static int _loop_is_with_partscan (struct device *dev) {FILE *fp;
@@ -398,6 +426,28 @@ struct partition {uint32_t nr_sects; } __attribute__((packed)); +static int _has_sys_partition (struct device *dev) +{ +char path[PATH_MAX ]; +struct stat info; +int major = (int )MAJOR (dev->dev); +int minor = (int )MINOR (dev->dev); + +/* check if dev is a partition */ +if (dm_snprintf (path,sizeof (path),"%s/dev/block/%d:%d/partition" , +dm_sysfs_dir (), major, minor) <0 ) { +log_error ("dm_snprintf partition failed" ); +return 0 ; + } + +if (stat (path, &info) ==-1 ) { +if (errno !=ENOENT ) +log_sys_error ("stat" , path); +return 0 ; + } +return 1 ; +} +static int _is_partitionable (struct dev_types *dt,struct device *dev) {int parts =major_max_partitions (dt,MAJOR (dev->dev));
@@ -414,6 +464,13 @@ static int _is_partitionable(struct dev_types *dt, struct device *dev) _loop_is_with_partscan(dev))return 1 ; +if (dev_is_nvme (dt, dev)) { +/* If this dev is already a partition then it's not partitionable. */ +if (_has_sys_partition (dev)) +return 0 ; +return 1 ; + } +if ((parts <=1 ) || (MINOR (dev->dev) % parts))return 0 ;
@@ -557,10 +614,17 @@ int dev_get_primary_dev(struct dev_types *dt, struct device *dev, dev_t *result)char path[PATH_MAX ];char temp_path[PATH_MAX ];char buffer[64 ]; -struct stat info;FILE *fp =NULL ;int parts, residue, size, ret =0 ; +/* +* /dev/nvme devs don't use the major:minor numbering like +* block dev types that have their own major number, so +* the calculation based on minor number doesn't work. +*/ +if (dev_is_nvme (dt, dev)) + goto sys_partition; +/* * Try to get the primary dev out of the * list of known device types first.
@@ -576,23 +640,14 @@ int dev_get_primary_dev(struct dev_types *dt, struct device *dev, dev_t *result) goto out; } + sys_partition:/* * If we can't get the primary dev out of the list of known device * types, try to look at sysfs directly then. This is more complex * way and it also requires certain sysfs layout to be present * which might not be there in old kernels! */ - -/* check if dev is a partition */ -if (dm_snprintf (path,sizeof (path),"%s/dev/block/%d:%d/partition" , - sysfs_dir, major, minor) <0 ) { -log_error ("dm_snprintf partition failed" ); - goto out; - } - -if (stat (path, &info) ==-1 ) { -if (errno !=ENOENT ) -log_sys_error ("stat" , path); +if (!_has_sys_partition (dev)) { *result = dev->dev; ret =1 ; goto out;/* dev is not a partition! */
lib/device/dev-type.h +2 -0
@@ -95,6 +95,8 @@ int dev_is_rotational(struct dev_types *dt, struct device *dev);int dev_is_pmem (struct device *dev); +int dev_is_nvme (struct dev_types *dt,struct device *dev); +int dev_is_lv (struct device *dev);int get_fs_block_size (struct device *dev,uint32_t *fs_block_size);
lib/device/device.h +1 -0
@@ -38,6 +38,7 @@#define DEV_SCAN_FOUND_LABEL 0x00010000/* label scan read dev and found label */ #define DEV_IS_MD_COMPONENT 0x00020000/* device is an md component */ #define DEV_UDEV_INFO_MISSING 0x00040000/* we have no udev info for this device */ +#define DEV_IS_NVME 0x00080000/* set if dev is nvme */ /* * Support for external device info.
lib/filters/filter-mpath.c +106 -50
298 lines not on this page · raw message