Skip to contentSkip to conversation

block: Set the name of BlockBackend if possible

PATCH New Annie Li 1 participant 2 messages Oct 27, 2022 Block layer

lore
Share & tools
lore

Annie Li

author
#0 lore raw

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

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

---
 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(-)
block/block-backend.c +9 -1
index aa4adf06ae..255b009270 100644
@@ -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);
+    }
+}
hw/core/qdev-properties-system.c +1 -0
index a91f60567a..9504acf4df 100644
@@ -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) {
include/sysemu/block-backend-global-state.h +2 -0
index 415f0c91d7..95f166f9c7 100644
@@ -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 */
Signature · 1 line
2.34.3
author
#1 lore raw

PATCH 2/2 iotests: Adjust 186.out to account for 'null' node-name

A recent enhancement for setting the block backend name fails test 186 due to a 'null' node-name. This is expected; adjust the expected test output accordingly.

---
 tests/qemu-iotests/186.out | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
tests/qemu-iotests/186.out +18 -18
index 01530040e5..27316bba46 100644
@@ -57,7 +57,7 @@ qdev_id: [not inserted]
 Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device ide-hd,drive=null
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) info block
-null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": true, "driver": "null-co"} (null-co)
     Attached to:      /machine/peripheral-anon/device[N]
     Cache mode:       writeback
 (qemu) quit
@@ -65,7 +65,7 @@ null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
 Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device ide-hd,drive=null,id=qdev_id
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) info block
-null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": true, "driver": "null-co"} (null-co)
     Attached to:      qdev_id
     Cache mode:       writeback
 (qemu) quit
@@ -73,7 +73,7 @@ null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
 Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device scsi-hd,drive=null
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) info block
-null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": true, "driver": "null-co"} (null-co)
     Attached to:      /machine/peripheral-anon/device[N]
     Cache mode:       writeback
 (qemu) quit
@@ -81,7 +81,7 @@ null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
 Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device scsi-hd,drive=null,id=qdev_id
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) info block
-null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": true, "driver": "null-co"} (null-co)
     Attached to:      qdev_id
     Cache mode:       writeback
 (qemu) quit
@@ -89,7 +89,7 @@ null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
 Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device virtio-blk-pci,drive=null
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) info block
-null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": true, "driver": "null-co"} (null-co)
     Attached to:      /machine/peripheral-anon/device[N]/virtio-backend
     Cache mode:       writeback
 (qemu) quit
@@ -97,7 +97,7 @@ null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
 Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device virtio-blk-pci,drive=null,id=qdev_id
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) info block
-null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": true, "driver": "null-co"} (null-co)
     Attached to:      /machine/peripheral/qdev_id/virtio-backend
     Cache mode:       writeback
 (qemu) quit
@@ -105,7 +105,7 @@ null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
 Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device floppy,drive=null
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) info block
-null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": true, "driver": "null-co"} (null-co)
     Attached to:      /machine/peripheral-anon/device[N]
     Removable device: not locked, tray closed
     Cache mode:       writeback
@@ -114,7 +114,7 @@ null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
 Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device floppy,drive=null,id=qdev_id
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) info block
-null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": true, "driver": "null-co"} (null-co)
     Attached to:      qdev_id
     Removable device: not locked, tray closed
     Cache mode:       writeback
@@ -123,7 +123,7 @@ null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
 Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device ide-cd,drive=null
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) info block
-null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": true, "driver": "null-co"} (null-co)
     Attached to:      /machine/peripheral-anon/device[N]
     Removable device: not locked, tray closed
     Cache mode:       writeback
@@ -132,7 +132,7 @@ null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
 Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device ide-cd,drive=null,id=qdev_id
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) info block
-null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": true, "driver": "null-co"} (null-co)
     Attached to:      qdev_id
     Removable device: not locked, tray closed
     Cache mode:       writeback
@@ -141,7 +141,7 @@ null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
 Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device scsi-cd,drive=null
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) info block
-null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": true, "driver": "null-co"} (null-co)
     Attached to:      /machine/peripheral-anon/device[N]
     Removable device: not locked, tray closed
     Cache mode:       writeback
@@ -150,7 +150,7 @@ null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
 Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device scsi-cd,drive=null,id=qdev_id
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) info block
-null: json:{"read-zeroes": true, "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": true, "driver": "null-co"} (null-co)
     Attached to:      qdev_id
     Removable device: not locked, tray closed
     Cache mode:       writeback
@@ -166,7 +166,7 @@ none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
     Removable device: not locked, tray closed
     Cache mode:       writeback
 
-null: json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
     Attached to:      qdev_id
     Cache mode:       writeback
 (qemu) quit
@@ -178,7 +178,7 @@ none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
     Removable device: not locked, tray closed
     Cache mode:       writeback
 
-null: json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
     Attached to:      qdev_id
     Cache mode:       writeback
 (qemu) quit
@@ -190,7 +190,7 @@ none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
     Removable device: not locked, tray closed
     Cache mode:       writeback
 
-null: json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
     Attached to:      /machine/peripheral/qdev_id/virtio-backend
     Cache mode:       writeback
 (qemu) quit
@@ -202,7 +202,7 @@ none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
     Removable device: not locked, tray closed
     Cache mode:       writeback
 
-null: json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
     Attached to:      qdev_id
     Removable device: not locked, tray closed
     Cache mode:       writeback
@@ -215,7 +215,7 @@ none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
     Removable device: not locked, tray closed
     Cache mode:       writeback
 
-null: json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
     Attached to:      qdev_id
     Removable device: not locked, tray closed
     Cache mode:       writeback
@@ -228,7 +228,7 @@ none0 (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
     Removable device: not locked, tray closed
     Cache mode:       writeback
 
-null: json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
+null (null): json:{"read-zeroes": "on", "driver": "null-co"} (null-co)
     Attached to:      qdev_id
     Removable device: not locked, tray closed
     Cache mode:       writeback
Signature · 1 line
2.34.3