Blame SOURCES/0102-imsm-limit-support-to-first-NVMe-namespace.patch

e95a18
From a8f3cfd54e45c8aabc4a99cdc92b6b9080b26607 Mon Sep 17 00:00:00 2001
e95a18
From: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
e95a18
Date: Wed, 4 Nov 2020 10:01:28 +0100
e95a18
Subject: [PATCH 102/108] imsm: limit support to first NVMe namespace
e95a18
e95a18
Due to metadata limitations NVMe multinamespace support has to be removed.
e95a18
e95a18
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
e95a18
---
e95a18
 platform-intel.c | 31 +++++++++++++++++++++++++++++++
e95a18
 platform-intel.h |  1 +
e95a18
 super-intel.c    | 11 ++++++++++-
e95a18
 3 files changed, 42 insertions(+), 1 deletion(-)
e95a18
e95a18
diff --git a/platform-intel.c b/platform-intel.c
e95a18
index 04bffc5..f1f6d4c 100644
e95a18
--- a/platform-intel.c
e95a18
+++ b/platform-intel.c
e95a18
@@ -766,3 +766,34 @@ char *vmd_domain_to_controller(struct sys_dev *hba, char *buf)
e95a18
 	closedir(dir);
e95a18
 	return NULL;
e95a18
 }
e95a18
+/* Verify that NVMe drive is supported by IMSM
e95a18
+ * Returns:
e95a18
+ *	0 - not supported
e95a18
+ *	1 - supported
e95a18
+ */
e95a18
+int imsm_is_nvme_supported(int disk_fd, int verbose)
e95a18
+{
e95a18
+	char nsid_path[PATH_MAX];
e95a18
+	char buf[PATH_MAX];
e95a18
+	struct stat stb;
e95a18
+
e95a18
+	if (disk_fd < 0)
e95a18
+		return 0;
e95a18
+
e95a18
+	if (fstat(disk_fd, &stb))
e95a18
+		return 0;
e95a18
+
e95a18
+	snprintf(nsid_path, PATH_MAX-1, "/sys/dev/block/%d:%d/nsid",
e95a18
+		 major(stb.st_rdev), minor(stb.st_rdev));
e95a18
+
e95a18
+	if (load_sys(nsid_path, buf, sizeof(buf))) {
e95a18
+		pr_err("Cannot read %s, rejecting drive\n", nsid_path);
e95a18
+		return 0;
e95a18
+	}
e95a18
+	if (strtoll(buf, NULL, 10) != 1) {
e95a18
+		if (verbose)
e95a18
+			pr_err("Only first namespace is supported by IMSM, aborting\n");
e95a18
+		return 0;
e95a18
+	}
e95a18
+	return 1;
e95a18
+}
e95a18
diff --git a/platform-intel.h b/platform-intel.h
e95a18
index 7cb370e..7371478 100644
e95a18
--- a/platform-intel.h
e95a18
+++ b/platform-intel.h
e95a18
@@ -251,4 +251,5 @@ const struct orom_entry *get_orom_entry_by_device_id(__u16 dev_id);
e95a18
 const struct imsm_orom *get_orom_by_device_id(__u16 device_id);
e95a18
 struct sys_dev *device_by_id(__u16 device_id);
e95a18
 struct sys_dev *device_by_id_and_path(__u16 device_id, const char *path);
e95a18
+int imsm_is_nvme_supported(int disk_fd, int verbose);
e95a18
 char *vmd_domain_to_controller(struct sys_dev *hba, char *buf);
e95a18
diff --git a/super-intel.c b/super-intel.c
e95a18
index 95f4eaf..715febf 100644
e95a18
--- a/super-intel.c
e95a18
+++ b/super-intel.c
e95a18
@@ -2364,7 +2364,9 @@ static int print_nvme_info(struct sys_dev *hba)
e95a18
 				continue;
e95a18
 			if (path_attached_to_hba(rp, hba->path)) {
e95a18
 				fd = open_dev(ent->d_name);
e95a18
-				if (fd < 0) {
e95a18
+				if (!imsm_is_nvme_supported(fd, 0)) {
e95a18
+					if (fd >= 0)
e95a18
+						close(fd);
e95a18
 					free(rp);
e95a18
 					continue;
e95a18
 				}
e95a18
@@ -5868,6 +5870,13 @@ static int add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk,
e95a18
 		snprintf(controller_path, PATH_MAX-1, "%s/device", devpath);
e95a18
 		free(devpath);
e95a18
 
e95a18
+		if (!imsm_is_nvme_supported(dd->fd, 1)) {
e95a18
+			if (dd->devname)
e95a18
+				free(dd->devname);
e95a18
+			free(dd);
e95a18
+			return 1;
e95a18
+		}
e95a18
+
e95a18
 		if (devpath_to_vendor(controller_path) == 0x8086) {
e95a18
 			/*
e95a18
 			 * If Intel's NVMe drive has serial ended with
e95a18
-- 
e95a18
2.7.5
e95a18