diff mbox series

[v2,2/3] libxl: Support blktap with HVM device model

Message ID 20240407204953.60442-3-jandryuk@gmail.com (mailing list archive)
State New
Headers show
Series libxl: blktap/tapback support | expand

Commit Message

Jason Andryuk April 7, 2024, 8:49 p.m. UTC
blktap exposes disks over UNIX socket Network Block Device (NBD).
Modify libxl__device_disk_find_local_path() to provide back the
QEMU-formatted NBD path.  This allows tapdisk to be used for booting an
HVM.

Use the nbd+unix:/// format specified by the protocol at
https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md

Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
---
v2:
Add Anthony's R-b
Add matching { } to else
---
 tools/libs/light/libxl_disk.c | 18 ++++++++++++++----
 tools/libs/light/libxl_dm.c   |  1 -
 2 files changed, 14 insertions(+), 5 deletions(-)

Comments

Jan Beulich April 8, 2024, 6:36 a.m. UTC | #1
On 07.04.2024 22:49, Jason Andryuk wrote:
> blktap exposes disks over UNIX socket Network Block Device (NBD).
> Modify libxl__device_disk_find_local_path() to provide back the
> QEMU-formatted NBD path.  This allows tapdisk to be used for booting an
> HVM.
> 
> Use the nbd+unix:/// format specified by the protocol at
> https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md
> 
> Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
> Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
> Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>

Please remember to keep tags in chronological order, i.e. R-b after S-o-b.

It's also not clear to me whether this could sensibly go in ahead of patch 1;
for now I'll assume it shouldn't.

Jan
diff mbox series

Patch

diff --git a/tools/libs/light/libxl_disk.c b/tools/libs/light/libxl_disk.c
index 819d34933b..432970f5a7 100644
--- a/tools/libs/light/libxl_disk.c
+++ b/tools/libs/light/libxl_disk.c
@@ -1724,7 +1724,8 @@  char *libxl__device_disk_find_local_path(libxl__gc *gc,
      * If the format isn't raw and / or we're using a script, then see
      * if the script has written a path to the "cooked" node
      */
-    if (disk->script && guest_domid != INVALID_DOMID) {
+    if ((disk->script && guest_domid != INVALID_DOMID) ||
+        disk->backend == LIBXL_DISK_BACKEND_TAP) {
         libxl__device device;
         char *be_path, *pdpath;
         int rc;
@@ -1744,10 +1745,19 @@  char *libxl__device_disk_find_local_path(libxl__gc *gc,
         LOGD(DEBUG, guest_domid, "Attempting to read node %s", pdpath);
         path = libxl__xs_read(gc, XBT_NULL, pdpath);
 
-        if (path)
+        if (path) {
             LOGD(DEBUG, guest_domid, "Accessing cooked block device %s", path);
-        else
-            LOGD(DEBUG, guest_domid, "No physical-device-path, can't access locally.");
+
+            /* tapdisk exposes disks locally over UNIX socket NBD. */
+            if (disk->backend == LIBXL_DISK_BACKEND_TAP) {
+                path = libxl__sprintf(gc, "nbd+unix:///?socket=%s", path);
+                LOGD(DEBUG, guest_domid,
+                     "Directly accessing local TAP target %s", path);
+            }
+        } else {
+            LOGD(DEBUG, guest_domid,
+                "No physical-device-path, can't access locally.");
+	}
 
         goto out;
     }
diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c
index 0b03a7c747..1a24e7961a 100644
--- a/tools/libs/light/libxl_dm.c
+++ b/tools/libs/light/libxl_dm.c
@@ -1915,7 +1915,6 @@  static int libxl__build_device_model_args_new(libxl__gc *gc,
                     continue;
                 }
 
-                assert(disks[i].backend != LIBXL_DISK_BACKEND_TAP);
                 target_path = libxl__device_disk_find_local_path(gc,
                                     guest_domid, &disks[i], true);