[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 27/27] scsi-disk: Add device_id property
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 27/27] scsi-disk: Add device_id property |
Date: |
Fri, 1 Feb 2019 17:35:18 +0100 |
The new device_id property specifies which value to use for the vendor
specific designator in the Device Identification VPD page.
In particular, this is necessary for libvirt to maintain guest ABI
compatibility when no serial number is given and a VM is switched from
-drive (where the BlockBackend name is used) to -blockdev (where the
vendor specific designator is left out by default).
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
hw/scsi/scsi-disk.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 11392a8db8..e6db6d7c15 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -104,6 +104,7 @@ typedef struct SCSIDiskState
char *serial;
char *vendor;
char *product;
+ char *device_id;
bool tray_open;
bool tray_locked;
/*
@@ -642,13 +643,8 @@ static int scsi_disk_emulate_vpd_page(SCSIRequest *req,
uint8_t *outbuf)
case 0x83: /* Device identification page, mandatory */
{
- const char *str = s->serial ?: blk_name(s->qdev.conf.blk);
- int max_len = s->serial ? 20 : 255 - 8;
- int id_len = strlen(str);
+ int id_len = s->device_id ? MIN(strlen(s->device_id), 255 - 8) : 0;
- if (id_len > max_len) {
- id_len = max_len;
- }
DPRINTF("Inquiry EVPD[Device identification] "
"buffer size %zd\n", req->cmd.xfer);
@@ -657,7 +653,7 @@ static int scsi_disk_emulate_vpd_page(SCSIRequest *req,
uint8_t *outbuf)
outbuf[buflen++] = 0; /* not officially assigned */
outbuf[buflen++] = 0; /* reserved */
outbuf[buflen++] = id_len; /* length of data following */
- memcpy(outbuf + buflen, str, id_len);
+ memcpy(outbuf + buflen, s->device_id, id_len);
buflen += id_len;
}
@@ -2363,6 +2359,16 @@ static void scsi_realize(SCSIDevice *dev, Error **errp)
if (!s->vendor) {
s->vendor = g_strdup("QEMU");
}
+ if (!s->device_id) {
+ if (s->serial) {
+ s->device_id = g_strdup_printf("%.20s", s->serial);
+ } else {
+ const char *str = blk_name(s->qdev.conf.blk);
+ if (str && *str) {
+ s->device_id = g_strdup(str);
+ }
+ }
+ }
if (blk_is_sg(s->qdev.conf.blk)) {
error_setg(errp, "unwanted /dev/sg*");
@@ -2921,7 +2927,9 @@ static const TypeInfo scsi_disk_base_info = {
DEFINE_PROP_STRING("ver", SCSIDiskState, version), \
DEFINE_PROP_STRING("serial", SCSIDiskState, serial), \
DEFINE_PROP_STRING("vendor", SCSIDiskState, vendor), \
- DEFINE_PROP_STRING("product", SCSIDiskState, product)
+ DEFINE_PROP_STRING("product", SCSIDiskState, product), \
+ DEFINE_PROP_STRING("device_id", SCSIDiskState, device_id)
+
static Property scsi_hd_properties[] = {
DEFINE_SCSI_DISK_PROPERTIES(),
--
2.20.1
- [Qemu-devel] [PULL 11/27] iotests: Add VMDK tests for blockdev-create, (continued)
- [Qemu-devel] [PULL 11/27] iotests: Add VMDK tests for blockdev-create, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 10/27] iotests: Filter cid numbers in VMDK extent info, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 13/27] block/vpc: Don't take address of fields in packed structs, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 23/27] iotests/236: fix transaction kwarg order, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 03/27] qcow2: Assert that refcount block offsets fit in the refcount table, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 24/27] block: Fix invalidate_cache error path for parent activation, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 15/27] uuid: Make qemu_uuid_bswap() take and return a QemuUUID, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 07/27] iotests: Make 234 stable, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 08/27] vmdk: Refactor vmdk_create_extent, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 21/27] virtio-scsi: Forbid devices with different iothreads sharing a blockdev, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 27/27] scsi-disk: Add device_id property,
Kevin Wolf <=
- [Qemu-devel] [PULL 04/27] qemu-iotests: add test case for dmg, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 09/27] vmdk: Implement .bdrv_co_create callback, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 26/27] scsi-disk: Don't use empty string as device id, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 25/27] qtest.py: Wait for the result of qtest commands, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 22/27] iotests: Filter second BLOCK_JOB_ERROR from 229, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 14/27] block/vdi: Don't take address of fields in packed structs, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 18/27] block: Eliminate the S_1KiB, S_2KiB, ... macros, Kevin Wolf, 2019/02/01
- [Qemu-devel] [PULL 19/27] virtio-scsi: Move BlockBackend back to the main AioContext on unplug, Kevin Wolf, 2019/02/01
- Re: [Qemu-devel] [PULL 00/27] Block layer patches, no-reply, 2019/02/01
- Re: [Qemu-devel] [PULL 00/27] Block layer patches, no-reply, 2019/02/01