From e3591a59adc3802a0ec32808f4b9dc95b903b7d3 Mon Sep 17 00:00:00 2001 From: Dimitri John Ledkov Date: Tue, 29 Apr 2014 16:45:44 +0100 Subject: Add support for nvme device in grub-mkdevicemap Author: Colin Watson Bug-Debian: https://bugs.debian.org/746396 Bug-Ubuntu: https://bugs.launchpad.net/bugs/1275162 Forwarded: no Last-Update: 2014-05-08 Patch-Name: probe_nvme.patch --- grub-core/osdep/linux/getroot.c | 14 ++++++++++++++ util/deviceiter.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c index 6788e39..f97f3a6 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c @@ -896,6 +896,20 @@ grub_util_part_to_disk (const char *os_dev, struct stat *st, *pp = '\0'; return path; } + + /* If this is an NVMe device. */ + if (strncmp ("nvme", p, sizeof ("nvme") - 1) == 0) + { + /* /dev/nvme[0-9]+n[0-9]+(p[0-9]+)? */ + p = strchr (p, 'p'); + if (p) + { + *is_part = 1; + *p = '\0'; + } + + return path; + } } return path; diff --git a/util/deviceiter.c b/util/deviceiter.c index d3d38a1..dbf4060 100644 --- a/util/deviceiter.c +++ b/util/deviceiter.c @@ -383,6 +383,12 @@ get_fio_disk_name (char *name, int unit) { sprintf (name, "/dev/fio%c", unit + 'a'); } + +static void +get_nvme_disk_name (char *name, int controller, int namespace) +{ + sprintf (name, "/dev/nvme%dn%d", controller, namespace); +} #endif static struct seen_device @@ -913,6 +919,29 @@ grub_util_iterate_devices (int (*hook) (const char *, int, void *), void *hook_d } } + /* This is for standard NVMe controllers + /dev/nvmenp. No idea about + actual limits of how many controllers a system can have and/or + how many namespace that would be, 10 for now. */ + { + int controller, namespace; + + for (controller = 0; controller < 10; controller++) + { + for (namespace = 0; namespace < 10; namespace++) + { + char name[16]; + + get_nvme_disk_name (name, controller, namespace); + if (check_device_readable_unique (name)) + { + if (hook (name, 0, hook_data)) + goto out; + } + } + } + } + # ifdef HAVE_DEVICE_MAPPER # define dmraid_check(cond, ...) \ if (! (cond)) \