Blob Blame History Raw
From ba2963bc57c8c8a3d6f7cc2fd274c9ebd4ddb7d8 Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <lersek@redhat.com>
Date: Wed, 6 Jul 2022 12:32:15 +0200
Subject: [PATCH] convert/convert_linux: complete the remapping of NVMe devices

In commit 75872bf282d7 ("input: -i vmx: Add support for NVMe devices",
2022-04-08), we missed that pathnames such as

  /dev/nvme0n1[p1]

would not match our "rex_device_cciss" and "rex_device" regular
expressions.

As a consequence, we don't remap such pathnames now in the boot config
files with Augeas.

Add a new regex and associated mapping logic for this kind of pathname.

Notes:

(1) "rex_device_cciss" could be extended internally with an alternative
pattern:

  ^/dev/(cciss/c\\d+d\\d+|nvme\\d+n1)(?:p(\\d+))?$
                         ^^^^^^^^^^^

but Rich suggested we should add a separate, complete regexp for
maintainability.

(2) Even with a separate regexp, we could reuse the existent CCISS pattern
handler:

  if PCRE.matches rex_device_cciss value ||
     PCRE.matches rex_device_nvme value then (
    let device = PCRE.sub 1
    and part = try PCRE.sub 2 with Not_found -> "" in
    "/dev/" ^ replace device ^ part
  )

Namely, although "PCRE.matches" creates/updates global state, and
"PCRE.sub" reads that state, the "||" operator in OCaml has short-circuit
behavior, and both regexps have the same structure.

But, using the same maintainability argument, let's keep the handler logic
for NVMe detached.

Fixes: 75872bf282d7f2322110caca70963717b43806b1
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2101665
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20220706103215.5607-1-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
(cherry picked from commit 4368b94ee1724c16aa35c0ee42ce4c51ce037b5a)
---
 convert/convert_linux.ml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml
index 59d143bd..a66ff1e4 100644
--- a/convert/convert_linux.ml
+++ b/convert/convert_linux.ml
@@ -1199,6 +1199,7 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ =
     (* Map device names for each entry. *)
     let rex_resume = PCRE.compile "^resume=(/dev/[-a-z\\d/_]+)(.*)$"
     and rex_device_cciss = PCRE.compile "^/dev/(cciss/c\\d+d\\d+)(?:p(\\d+))?$"
+    and rex_device_nvme = PCRE.compile "^/dev/(nvme\\d+n1)(?:p(\\d+))?$"
     and rex_device = PCRE.compile "^/dev/([a-z]+)(\\d*)?$" in
 
     let rec replace_if_device path value =
@@ -1221,6 +1222,11 @@ let convert (g : G.guestfs) source inspect keep_serial_console _ =
         and part = try PCRE.sub 2 with Not_found -> "" in
         "/dev/" ^ replace device ^ part
       )
+      else if PCRE.matches rex_device_nvme value then (
+        let device = PCRE.sub 1
+        and part = try PCRE.sub 2 with Not_found -> "" in
+        "/dev/" ^ replace device ^ part
+      )
       else if PCRE.matches rex_device value then (
         let device = PCRE.sub 1
         and part = try PCRE.sub 2 with Not_found -> "" in