qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen-block: Use specific blockdev driver
@ 2021-04-30 16:34 Anthony PERARD via
  2021-05-05 17:44 ` Paul Durrant
  0 siblings, 1 reply; 2+ messages in thread
From: Anthony PERARD via @ 2021-04-30 16:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Anthony PERARD, Stefano Stabellini, Paul Durrant, Kevin Wolf,
	Max Reitz, xen-devel, qemu-block

From: Anthony PERARD <anthony.perard@citrix.com>

... 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.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 hw/block/xen-block.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
index 83754a434481..674953f1adee 100644
--- a/hw/block/xen-block.c
+++ b/hw/block/xen-block.c
@@ -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);
 
-- 
Anthony PERARD



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] xen-block: Use specific blockdev driver
  2021-04-30 16:34 [PATCH] xen-block: Use specific blockdev driver Anthony PERARD via
@ 2021-05-05 17:44 ` Paul Durrant
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Durrant @ 2021-05-05 17:44 UTC (permalink / raw)
  To: Anthony PERARD, qemu-devel
  Cc: Kevin Wolf, xen-devel, Stefano Stabellini, qemu-block, Max Reitz

On 30/04/2021 17:34, Anthony PERARD wrote:
> From: Anthony PERARD <anthony.perard@citrix.com>
> 
> ... 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.
> 
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>

Acked-by: Paul Durrant <paul@xen.org>

> ---
>   hw/block/xen-block.c | 14 +++++++++++++-
>   1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
> index 83754a434481..674953f1adee 100644
> --- a/hw/block/xen-block.c
> +++ b/hw/block/xen-block.c
> @@ -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);
>   
> 



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-05 17:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-30 16:34 [PATCH] xen-block: Use specific blockdev driver Anthony PERARD via
2021-05-05 17:44 ` Paul Durrant

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).