|
|
5bf14f |
From 6da53c0e2aab200605722795798b1e4f2352cd64 Mon Sep 17 00:00:00 2001
|
|
|
5bf14f |
From: Blazej Kucman <blazej.kucman@intel.com>
|
|
|
5bf14f |
Date: Mon, 2 Dec 2019 10:52:05 +0100
|
|
|
5bf14f |
Subject: [RHEL7.9 PATCH 50/71] imsm: Change the way of printing nvme drives in
|
|
|
5bf14f |
detail-platform.
|
|
|
5bf14f |
|
|
|
5bf14f |
Change NVMe controller path to device node path
|
|
|
5bf14f |
in mdadm --detail-platform and print serial number.
|
|
|
5bf14f |
The method imsm_read_serial always trimes serial to
|
|
|
5bf14f |
MAX_RAID_SERIAL_LEN, added parameter 'serial_buf_len'
|
|
|
5bf14f |
will be used to check the serial fit
|
|
|
5bf14f |
to passed buffor, if not, will be trimed.
|
|
|
5bf14f |
|
|
|
5bf14f |
Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
|
|
|
5bf14f |
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
|
|
|
5bf14f |
---
|
|
|
5bf14f |
super-intel.c | 97 ++++++++++++++++++++++++++++-------------------------------
|
|
|
5bf14f |
1 file changed, 46 insertions(+), 51 deletions(-)
|
|
|
5bf14f |
|
|
|
5bf14f |
diff --git a/super-intel.c b/super-intel.c
|
|
|
5bf14f |
index 86dcb69..5c1f759 100644
|
|
|
5bf14f |
--- a/super-intel.c
|
|
|
5bf14f |
+++ b/super-intel.c
|
|
|
5bf14f |
@@ -2218,7 +2218,8 @@ static void brief_detail_super_imsm(struct supertype *st, char *subarray)
|
|
|
5bf14f |
super->current_vol = temp_vol;
|
|
|
5bf14f |
}
|
|
|
5bf14f |
|
|
|
5bf14f |
-static int imsm_read_serial(int fd, char *devname, __u8 *serial);
|
|
|
5bf14f |
+static int imsm_read_serial(int fd, char *devname, __u8 *serial,
|
|
|
5bf14f |
+ size_t serial_buf_len);
|
|
|
5bf14f |
static void fd2devname(int fd, char *name);
|
|
|
5bf14f |
|
|
|
5bf14f |
static int ahci_enumerate_ports(const char *hba_path, int port_count, int host_base, int verbose)
|
|
|
5bf14f |
@@ -2364,8 +2365,9 @@ static int ahci_enumerate_ports(const char *hba_path, int port_count, int host_b
|
|
|
5bf14f |
else {
|
|
|
5bf14f |
fd2devname(fd, buf);
|
|
|
5bf14f |
printf(" Port%d : %s", port, buf);
|
|
|
5bf14f |
- if (imsm_read_serial(fd, NULL, (__u8 *) buf) == 0)
|
|
|
5bf14f |
- printf(" (%.*s)\n", MAX_RAID_SERIAL_LEN, buf);
|
|
|
5bf14f |
+ if (imsm_read_serial(fd, NULL, (__u8 *)buf,
|
|
|
5bf14f |
+ sizeof(buf)) == 0)
|
|
|
5bf14f |
+ printf(" (%s)\n", buf);
|
|
|
5bf14f |
else
|
|
|
5bf14f |
printf(" ()\n");
|
|
|
5bf14f |
close(fd);
|
|
|
5bf14f |
@@ -2388,52 +2390,45 @@ static int ahci_enumerate_ports(const char *hba_path, int port_count, int host_b
|
|
|
5bf14f |
return err;
|
|
|
5bf14f |
}
|
|
|
5bf14f |
|
|
|
5bf14f |
-static int print_vmd_attached_devs(struct sys_dev *hba)
|
|
|
5bf14f |
+static int print_nvme_info(struct sys_dev *hba)
|
|
|
5bf14f |
{
|
|
|
5bf14f |
+ char buf[1024];
|
|
|
5bf14f |
struct dirent *ent;
|
|
|
5bf14f |
DIR *dir;
|
|
|
5bf14f |
- char path[292];
|
|
|
5bf14f |
- char link[256];
|
|
|
5bf14f |
- char *c, *rp;
|
|
|
5bf14f |
-
|
|
|
5bf14f |
- if (hba->type != SYS_DEV_VMD)
|
|
|
5bf14f |
- return 1;
|
|
|
5bf14f |
+ char *rp;
|
|
|
5bf14f |
+ int fd;
|
|
|
5bf14f |
|
|
|
5bf14f |
- /* scroll through /sys/dev/block looking for devices attached to
|
|
|
5bf14f |
- * this hba
|
|
|
5bf14f |
- */
|
|
|
5bf14f |
- dir = opendir("/sys/bus/pci/drivers/nvme");
|
|
|
5bf14f |
+ dir = opendir("/sys/block/");
|
|
|
5bf14f |
if (!dir)
|
|
|
5bf14f |
return 1;
|
|
|
5bf14f |
|
|
|
5bf14f |
for (ent = readdir(dir); ent; ent = readdir(dir)) {
|
|
|
5bf14f |
- int n;
|
|
|
5bf14f |
-
|
|
|
5bf14f |
- /* is 'ent' a device? check that the 'subsystem' link exists and
|
|
|
5bf14f |
- * that its target matches 'bus'
|
|
|
5bf14f |
- */
|
|
|
5bf14f |
- sprintf(path, "/sys/bus/pci/drivers/nvme/%s/subsystem",
|
|
|
5bf14f |
- ent->d_name);
|
|
|
5bf14f |
- n = readlink(path, link, sizeof(link));
|
|
|
5bf14f |
- if (n < 0 || n >= (int)sizeof(link))
|
|
|
5bf14f |
- continue;
|
|
|
5bf14f |
- link[n] = '\0';
|
|
|
5bf14f |
- c = strrchr(link, '/');
|
|
|
5bf14f |
- if (!c)
|
|
|
5bf14f |
- continue;
|
|
|
5bf14f |
- if (strncmp("pci", c+1, strlen("pci")) != 0)
|
|
|
5bf14f |
- continue;
|
|
|
5bf14f |
-
|
|
|
5bf14f |
- sprintf(path, "/sys/bus/pci/drivers/nvme/%s", ent->d_name);
|
|
|
5bf14f |
-
|
|
|
5bf14f |
- rp = realpath(path, NULL);
|
|
|
5bf14f |
- if (!rp)
|
|
|
5bf14f |
- continue;
|
|
|
5bf14f |
+ if (strstr(ent->d_name, "nvme")) {
|
|
|
5bf14f |
+ sprintf(buf, "/sys/block/%s", ent->d_name);
|
|
|
5bf14f |
+ rp = realpath(buf, NULL);
|
|
|
5bf14f |
+ if (!rp)
|
|
|
5bf14f |
+ continue;
|
|
|
5bf14f |
+ if (path_attached_to_hba(rp, hba->path)) {
|
|
|
5bf14f |
+ fd = open_dev(ent->d_name);
|
|
|
5bf14f |
+ if (fd < 0) {
|
|
|
5bf14f |
+ free(rp);
|
|
|
5bf14f |
+ continue;
|
|
|
5bf14f |
+ }
|
|
|
5bf14f |
|
|
|
5bf14f |
- if (path_attached_to_hba(rp, hba->path)) {
|
|
|
5bf14f |
- printf(" NVMe under VMD : %s\n", rp);
|
|
|
5bf14f |
+ fd2devname(fd, buf);
|
|
|
5bf14f |
+ if (hba->type == SYS_DEV_VMD)
|
|
|
5bf14f |
+ printf(" NVMe under VMD : %s", buf);
|
|
|
5bf14f |
+ else if (hba->type == SYS_DEV_NVME)
|
|
|
5bf14f |
+ printf(" NVMe Device : %s", buf);
|
|
|
5bf14f |
+ if (!imsm_read_serial(fd, NULL, (__u8 *)buf,
|
|
|
5bf14f |
+ sizeof(buf)))
|
|
|
5bf14f |
+ printf(" (%s)\n", buf);
|
|
|
5bf14f |
+ else
|
|
|
5bf14f |
+ printf("()\n");
|
|
|
5bf14f |
+ close(fd);
|
|
|
5bf14f |
+ }
|
|
|
5bf14f |
+ free(rp);
|
|
|
5bf14f |
}
|
|
|
5bf14f |
- free(rp);
|
|
|
5bf14f |
}
|
|
|
5bf14f |
|
|
|
5bf14f |
closedir(dir);
|
|
|
5bf14f |
@@ -2648,7 +2643,7 @@ static int detail_platform_imsm(int verbose, int enumerate_only, char *controlle
|
|
|
5bf14f |
char buf[PATH_MAX];
|
|
|
5bf14f |
printf(" I/O Controller : %s (%s)\n",
|
|
|
5bf14f |
vmd_domain_to_controller(hba, buf), get_sys_dev_type(hba->type));
|
|
|
5bf14f |
- if (print_vmd_attached_devs(hba)) {
|
|
|
5bf14f |
+ if (print_nvme_info(hba)) {
|
|
|
5bf14f |
if (verbose > 0)
|
|
|
5bf14f |
pr_err("failed to get devices attached to VMD domain.\n");
|
|
|
5bf14f |
result |= 2;
|
|
|
5bf14f |
@@ -2663,7 +2658,7 @@ static int detail_platform_imsm(int verbose, int enumerate_only, char *controlle
|
|
|
5bf14f |
if (entry->type == SYS_DEV_NVME) {
|
|
|
5bf14f |
for (hba = list; hba; hba = hba->next) {
|
|
|
5bf14f |
if (hba->type == SYS_DEV_NVME)
|
|
|
5bf14f |
- printf(" NVMe Device : %s\n", hba->path);
|
|
|
5bf14f |
+ print_nvme_info(hba);
|
|
|
5bf14f |
}
|
|
|
5bf14f |
printf("\n");
|
|
|
5bf14f |
continue;
|
|
|
5bf14f |
@@ -4028,11 +4023,11 @@ static int nvme_get_serial(int fd, void *buf, size_t buf_len)
|
|
|
5bf14f |
extern int scsi_get_serial(int fd, void *buf, size_t buf_len);
|
|
|
5bf14f |
|
|
|
5bf14f |
static int imsm_read_serial(int fd, char *devname,
|
|
|
5bf14f |
- __u8 serial[MAX_RAID_SERIAL_LEN])
|
|
|
5bf14f |
+ __u8 *serial, size_t serial_buf_len)
|
|
|
5bf14f |
{
|
|
|
5bf14f |
char buf[50];
|
|
|
5bf14f |
int rv;
|
|
|
5bf14f |
- int len;
|
|
|
5bf14f |
+ size_t len;
|
|
|
5bf14f |
char *dest;
|
|
|
5bf14f |
char *src;
|
|
|
5bf14f |
unsigned int i;
|
|
|
5bf14f |
@@ -4075,13 +4070,13 @@ static int imsm_read_serial(int fd, char *devname,
|
|
|
5bf14f |
len = dest - buf;
|
|
|
5bf14f |
dest = buf;
|
|
|
5bf14f |
|
|
|
5bf14f |
- /* truncate leading characters */
|
|
|
5bf14f |
- if (len > MAX_RAID_SERIAL_LEN) {
|
|
|
5bf14f |
- dest += len - MAX_RAID_SERIAL_LEN;
|
|
|
5bf14f |
- len = MAX_RAID_SERIAL_LEN;
|
|
|
5bf14f |
+ if (len > serial_buf_len) {
|
|
|
5bf14f |
+ /* truncate leading characters */
|
|
|
5bf14f |
+ dest += len - serial_buf_len;
|
|
|
5bf14f |
+ len = serial_buf_len;
|
|
|
5bf14f |
}
|
|
|
5bf14f |
|
|
|
5bf14f |
- memset(serial, 0, MAX_RAID_SERIAL_LEN);
|
|
|
5bf14f |
+ memset(serial, 0, serial_buf_len);
|
|
|
5bf14f |
memcpy(serial, dest, len);
|
|
|
5bf14f |
|
|
|
5bf14f |
return 0;
|
|
|
5bf14f |
@@ -4136,7 +4131,7 @@ load_imsm_disk(int fd, struct intel_super *super, char *devname, int keep_fd)
|
|
|
5bf14f |
char name[40];
|
|
|
5bf14f |
__u8 serial[MAX_RAID_SERIAL_LEN];
|
|
|
5bf14f |
|
|
|
5bf14f |
- rv = imsm_read_serial(fd, devname, serial);
|
|
|
5bf14f |
+ rv = imsm_read_serial(fd, devname, serial, MAX_RAID_SERIAL_LEN);
|
|
|
5bf14f |
|
|
|
5bf14f |
if (rv != 0)
|
|
|
5bf14f |
return 2;
|
|
|
5bf14f |
@@ -5844,7 +5839,7 @@ int mark_spare(struct dl *disk)
|
|
|
5bf14f |
return ret_val;
|
|
|
5bf14f |
|
|
|
5bf14f |
ret_val = 0;
|
|
|
5bf14f |
- if (!imsm_read_serial(disk->fd, NULL, serial)) {
|
|
|
5bf14f |
+ if (!imsm_read_serial(disk->fd, NULL, serial, MAX_RAID_SERIAL_LEN)) {
|
|
|
5bf14f |
/* Restore disk serial number, because takeover marks disk
|
|
|
5bf14f |
* as failed and adds to serial ':0' before it becomes
|
|
|
5bf14f |
* a spare disk.
|
|
|
5bf14f |
@@ -5895,7 +5890,7 @@ static int add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk,
|
|
|
5bf14f |
dd->fd = fd;
|
|
|
5bf14f |
dd->e = NULL;
|
|
|
5bf14f |
dd->action = DISK_ADD;
|
|
|
5bf14f |
- rv = imsm_read_serial(fd, devname, dd->serial);
|
|
|
5bf14f |
+ rv = imsm_read_serial(fd, devname, dd->serial, MAX_RAID_SERIAL_LEN);
|
|
|
5bf14f |
if (rv) {
|
|
|
5bf14f |
pr_err("failed to retrieve scsi serial, aborting\n");
|
|
|
5bf14f |
if (dd->devname)
|
|
|
5bf14f |
--
|
|
|
5bf14f |
2.7.5
|
|
|
5bf14f |
|