diff mbox series

[1/2] block: Set the name of BlockBackend if possible

Message ID 20221027202332.3229-1-annie.li@oracle.com
State New
Headers show
Series [1/2] block: Set the name of BlockBackend if possible | expand

Commit Message

Annie Li Oct. 27, 2022, 8:23 p.m. UTC
When QEMU emulates the SCSI device, it sets the 'device_id' of
the SCSI device with the serial number configured by 'serial='
property, or with 'blk->name' of the block backend otherwise.
Then QEMU emulates SCSI commands and fills the mandatory Device
identification page(0x83) with the 'device_id' info.

However, 'blk->name' of the block backend is NULL if the block
backend is defined by '-blockdev' option. This causes the QEMU
returns unconfigured empty page to the guest. As a result, this
may cause various issues on the guest side. For example, Windows
guest crashes due this in BZ#1708490, BZ#1722710#c10. This crash
issue has been fixed in Windows vioscsi driver by patching the vpd
page[1], but it is better for QEMU to return the non NULL vpd page
if possible.

This patch sets the 'blk->name' of the block backend that is
defined by '-blockdev' option, so the QEMU returns non NULL vpd
page when emulating SCSI device.

[1] https://github.com/virtio-win/kvm-guest-drivers-windows/commit/b57548c769ed9f431c34f6449ce432dd077cb02e

Signed-off-by: Annie Li <annie.li@oracle.com>
---
 block/block-backend.c                       | 10 +++++++++-
 hw/core/qdev-properties-system.c            |  1 +
 include/sysemu/block-backend-global-state.h |  2 ++
 3 files changed, 12 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/block/block-backend.c b/block/block-backend.c
index aa4adf06ae..255b009270 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -471,8 +471,9 @@  BlockBackend *blk_new_open(const char *filename, const char *reference,
 static void blk_delete(BlockBackend *blk)
 {
     assert(!blk->refcnt);
-    assert(!blk->name);
     assert(!blk->dev);
+    g_free(blk->name);
+    blk->name = NULL;
     if (blk->public.throttle_group_member.throttle_state) {
         blk_io_limits_disable(blk);
     }
@@ -2594,3 +2595,10 @@  int blk_make_empty(BlockBackend *blk, Error **errp)
 
     return bdrv_make_empty(blk->root, errp);
 }
+
+void blk_set_name(BlockBackend *blk, char *name)
+{
+    if (!blk->name) {
+        blk->name = g_strdup(name);
+    }
+}
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index a91f60567a..9504acf4df 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -144,6 +144,7 @@  static void set_drive_helper(Object *obj, Visitor *v, const char *name,
             ctx = iothread ? bdrv_get_aio_context(bs) : qemu_get_aio_context();
             blk = blk_new(ctx, 0, BLK_PERM_ALL);
             blk_created = true;
+            blk_set_name(blk, str);
 
             ret = blk_insert_bs(blk, bs, errp);
             if (ret < 0) {
diff --git a/include/sysemu/block-backend-global-state.h b/include/sysemu/block-backend-global-state.h
index 415f0c91d7..95f166f9c7 100644
--- a/include/sysemu/block-backend-global-state.h
+++ b/include/sysemu/block-backend-global-state.h
@@ -113,4 +113,6 @@  const BdrvChild *blk_root(BlockBackend *blk);
 
 int blk_make_empty(BlockBackend *blk, Error **errp);
 
+void blk_set_name(BlockBackend *blk, char *name);
+
 #endif /* BLOCK_BACKEND_GLOBAL_STATE_H */