This neutral refactoring changes the existing source device name
calculation so that it can handle (in the next commit) NVMe device
names.

Existing source device names such as "hda" or "sda" are composed of a
prefix ("hd", "sd") + alphabetic device index ("a").  NVMe devices
have a namespace after the prefix and use a numeric index ("nvme0n1"
== "nvme" + "0" + "n1").  By refactoring the calculation into a
function we will be able to handle both.
---
 convert/convert_linux.ml | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml
index 58a2a2a84d..d9397cfad1 100644
--- a/convert/convert_linux.ml
+++ b/convert/convert_linux.ml
@@ -1022,16 +1022,18 @@ let convert (g : G.guestfs) source inspect 
keep_serial_console _ =
 
     let map =
       List.mapi (
-        fun i disk ->
-          let block_prefix_before_conversion =
-            match disk.s_controller with
-            | Some Source_IDE -> ide_block_prefix
-            | Some (Source_virtio_SCSI | Source_SCSI | Source_SATA) -> "sd"
-            | Some Source_virtio_blk -> "vd"
-            | None ->
-              (* This is basically a guess.  It assumes the source used IDE. *)
-              ide_block_prefix in
-          let source_dev = block_prefix_before_conversion ^ drive_name i in
+        fun i { s_controller } ->
+          let device_name_before_conversion i =
+            match s_controller with
+            | None (* If we don't have a controller, guess.  Assumes the
+                    * source used IDE.
+                    *)
+            | Some Source_IDE ->
+               ide_block_prefix ^ drive_name i
+            | Some (Source_virtio_SCSI | Source_SCSI | Source_SATA) ->
+               "sd" ^ drive_name i
+            | Some Source_virtio_blk -> "vd" ^ drive_name i in
+          let source_dev = device_name_before_conversion i in
           let target_dev = block_prefix_after_conversion ^ drive_name i in
           source_dev, target_dev
       ) source.s_disks in
-- 
2.35.1

_______________________________________________
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs

Reply via email to