Skip to contentSkip to conversation

xen-block: Use specific blockdev driver

PATCH In review Anthony PERARD via 2 participants 2 messages Apr 30, 2021 – May 5, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen-block: Use specific blockdev driver

From: Anthony PERARD <[email protected]>

... when a xen-block backend instance is created via xenstore.

Following 8d17adf34f50 ("block: remove support for using "file" driver with block/char devices"), using the "file" blockdev driver for everything doesn't work anymore, we need to use the "host_device" driver when the disk image is a block device and "file" driver when it is a regular file.

---
 hw/block/xen-block.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
hw/block/xen-block.c +13 -1
index 83754a434481..674953f1adee 100644
@@ -728,6 +728,8 @@ static XenBlockDrive *xen_block_drive_create(const char *id,
     XenBlockDrive *drive = NULL;
     QDict *file_layer;
     QDict *driver_layer;
+    struct stat st;
+    int rc;
 
     if (params) {
         char **v = g_strsplit(params, ":", 2);
@@ -761,7 +763,17 @@ static XenBlockDrive *xen_block_drive_create(const char *id,
     file_layer = qdict_new();
     driver_layer = qdict_new();
 
-    qdict_put_str(file_layer, "driver", "file");
+    rc = stat(filename, &st);
+    if (rc) {
+        error_setg_errno(errp, errno, "Could not stat file '%s'", filename);
+        goto done;
+    }
+    if (S_ISBLK(st.st_mode)) {
+        qdict_put_str(file_layer, "driver", "host_device");
+    } else {
+        qdict_put_str(file_layer, "driver", "file");
+    }
+
     qdict_put_str(file_layer, "filename", filename);
     g_free(filename);
 
Signature · 1 line
Anthony PERARD
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Anthony PERARD

From: Anthony PERARD <[email protected]>

... when a xen-block backend instance is created via xenstore.

Following 8d17adf34f50 ("block: remove support for using "file" driver with block/char devices"), using the "file" blockdev driver for everything doesn't work anymore, we need to use the "host_device" driver when the disk image is a block device and "file" driver when it is a regular file.

Quoted 37 lines
---
  hw/block/xen-block.c | 14 +++++++++++++-
  1 file changed, 13 insertions(+), 1 deletion(-)
hw/block/xen-block.c +13 -1
index 83754a434481..674953f1adee 100644
@@ -728,6 +728,8 @@ static XenBlockDrive *xen_block_drive_create(const char *id,
      XenBlockDrive *drive = NULL;
      QDict *file_layer;
      QDict *driver_layer;
+    struct stat st;
+    int rc;
 
      if (params) {
          char **v = g_strsplit(params, ":", 2);
@@ -761,7 +763,17 @@ static XenBlockDrive *xen_block_drive_create(const char *id,
      file_layer = qdict_new();
      driver_layer = qdict_new();
 
-    qdict_put_str(file_layer, "driver", "file");
+    rc = stat(filename, &st);
+    if (rc) {
+        error_setg_errno(errp, errno, "Could not stat file '%s'", filename);
+        goto done;
+    }
+    if (S_ISBLK(st.st_mode)) {
+        qdict_put_str(file_layer, "driver", "host_device");
+    } else {
+        qdict_put_str(file_layer, "driver", "file");
+    }
+
      qdict_put_str(file_layer, "filename", filename);
      g_free(filename);