diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index eaeeb3a05de13bd375791cd8d5653352b2688f83..bef8f2c495ba909bff4d186af4fb4ad530d8500a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1890,6 +1890,7 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus); const char *contAlias; char *backendAlias = NULL; + char *scsiVPDDeviceId = NULL; int controllerModel; if (qemuCheckDiskConfig(disk, qemuCaps) < 0) @@ -1979,6 +1980,21 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, virBufferAddLit(&opt, "scsi-cd"); else virBufferAddLit(&opt, "scsi-hd"); + + /* qemu historically used the name of -drive as one of the device + * ids in the Vital Product Data Device Identification page if + * disk serial was not set and the disk serial otherwise. + * To avoid a guest-visible regression we need to provide it + * ourselves especially for cases when -blockdev will be used */ + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_DISK_DEVICE_ID)) { + if (disk->serial) { + if (VIR_STRDUP(scsiVPDDeviceId, disk->serial) < 0) + goto error; + } else { + if (!(scsiVPDDeviceId = qemuAliasDiskDriveFromDisk(disk))) + goto error; + } + } } if (!(contAlias = virDomainControllerAliasFind(def, VIR_DOMAIN_CONTROLLER_TYPE_SCSI, @@ -2021,6 +2037,10 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, disk->info.addr.drive.target, disk->info.addr.drive.unit); } + + if (scsiVPDDeviceId) + virBufferStrcat(&opt, ",device_id=", scsiVPDDeviceId, NULL); + break; case VIR_DOMAIN_DISK_BUS_SATA: diff --git a/tests/qemuxml2argvdata/controller-virtio-scsi.x86_64-latest.args b/tests/qemuxml2argvdata/controller-virtio-scsi.x86_64-latest.args index cf8a497eb74a1dde057c22c877d31085bf85f8db..095b4724d338e8096df4a85eb58c848094bfc5be 100644 --- a/tests/qemuxml2argvdata/controller-virtio-scsi.x86_64-latest.args +++ b/tests/qemuxml2argvdata/controller-virtio-scsi.x86_64-latest.args @@ -30,20 +30,20 @@ file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ -device virtio-scsi-pci,id=scsi3,max_sectors=512,bus=pci.0,addr=0x5 \ -device virtio-scsi-pci,id=scsi4,ioeventfd=on,bus=pci.0,addr=0x6 \ -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-scsi0-0-0-0 \ --device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0-0-0-0,\ -id=scsi0-0-0-0,bootindex=1 \ +-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,\ +device_id=drive-scsi0-0-0-0,drive=drive-scsi0-0-0-0,id=scsi0-0-0-0,bootindex=1 \ -drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-scsi1-0-0-0 \ --device scsi-hd,bus=scsi1.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi1-0-0-0,\ -id=scsi1-0-0-0 \ +-device scsi-hd,bus=scsi1.0,channel=0,scsi-id=0,lun=0,\ +device_id=drive-scsi1-0-0-0,drive=drive-scsi1-0-0-0,id=scsi1-0-0-0 \ -drive file=/dev/HostVG/QEMUGuest3,format=raw,if=none,id=drive-scsi2-0-0-0 \ --device scsi-hd,bus=scsi2.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi2-0-0-0,\ -id=scsi2-0-0-0 \ +-device scsi-hd,bus=scsi2.0,channel=0,scsi-id=0,lun=0,\ +device_id=drive-scsi2-0-0-0,drive=drive-scsi2-0-0-0,id=scsi2-0-0-0 \ -drive file=/dev/HostVG/QEMUGuest4,format=raw,if=none,id=drive-scsi3-0-0-0 \ --device scsi-hd,bus=scsi3.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi3-0-0-0,\ -id=scsi3-0-0-0 \ +-device scsi-hd,bus=scsi3.0,channel=0,scsi-id=0,lun=0,\ +device_id=drive-scsi3-0-0-0,drive=drive-scsi3-0-0-0,id=scsi3-0-0-0 \ -drive file=/dev/HostVG/QEMUGuest5,format=raw,if=none,id=drive-scsi4-0-0-0 \ --device scsi-hd,bus=scsi4.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi4-0-0-0,\ -id=scsi4-0-0-0 \ +-device scsi-hd,bus=scsi4.0,channel=0,scsi-id=0,lun=0,\ +device_id=drive-scsi4-0-0-0,drive=drive-scsi4-0-0-0,id=scsi4-0-0-0 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x7 \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ resourcecontrol=deny \ diff --git a/tests/qemuxml2argvdata/disk-cache.x86_64-latest.args b/tests/qemuxml2argvdata/disk-cache.x86_64-latest.args index 9220e6bee950f3da2ebe1bf52ba824142fc7c0f1..7f703d0861d6c23bf7376c9592b98d666c6d0504 100644 --- a/tests/qemuxml2argvdata/disk-cache.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-cache.x86_64-latest.args @@ -35,8 +35,8 @@ cache=unsafe \ write-cache=on \ -drive file=/dev/HostVG/QEMUGuest1,format=qcow2,if=none,id=drive-scsi0-0-0,\ cache=none \ --device scsi-hd,bus=scsi0.0,scsi-id=0,drive=drive-scsi0-0-0,id=scsi0-0-0,\ -write-cache=on \ +-device scsi-hd,bus=scsi0.0,scsi-id=0,device_id=drive-scsi0-0-0,\ +drive=drive-scsi0-0-0,id=scsi0-0-0,write-cache=on \ -drive file=/dev/HostVG/QEMUGuest1,format=qcow2,if=none,id=drive-virtio-disk0,\ cache=writethrough \ -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x3,drive=drive-virtio-disk0,\ diff --git a/tests/qemuxml2argvdata/disk-scsi-device-auto.x86_64-latest.args b/tests/qemuxml2argvdata/disk-scsi-device-auto.x86_64-latest.args index 549a16280832a398f530af8025d0b721e75ec6d5..508daa0365601b3245dfded1767d54227cc6baf4 100644 --- a/tests/qemuxml2argvdata/disk-scsi-device-auto.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-scsi-device-auto.x86_64-latest.args @@ -28,7 +28,8 @@ file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \ -drive file=/tmp/scsidisk.img,format=raw,if=none,id=drive-scsi0-0-0 \ --device scsi-hd,bus=scsi0.0,scsi-id=0,drive=drive-scsi0-0-0,id=scsi0-0-0 \ +-device scsi-hd,bus=scsi0.0,scsi-id=0,device_id=drive-scsi0-0-0,\ +drive=drive-scsi0-0-0,id=scsi0-0-0 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ resourcecontrol=deny \ diff --git a/tests/qemuxml2argvdata/disk-scsi.x86_64-latest.args b/tests/qemuxml2argvdata/disk-scsi.x86_64-latest.args index 68a8b2921d6862050867e3e70cc3d8c3cd4bc5ec..e5b930a28a29d4e636083b9ebe83365b208d4941 100644 --- a/tests/qemuxml2argvdata/disk-scsi.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-scsi.x86_64-latest.args @@ -31,16 +31,18 @@ file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \ -drive file=/tmp/scsidisk.img,format=raw,if=none,id=drive-scsi0-0-0 \ --device scsi-hd,bus=scsi0.0,scsi-id=0,drive=drive-scsi0-0-0,id=scsi0-0-0 \ +-device scsi-hd,bus=scsi0.0,scsi-id=0,device_id=drive-scsi0-0-0,\ +drive=drive-scsi0-0-0,id=scsi0-0-0 \ -drive file=/tmp/scsidisk2.img,format=raw,if=none,id=drive-scsi1-0-0-0 \ --device scsi-hd,bus=scsi1.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi1-0-0-0,\ -id=scsi1-0-0-0,serial=abcdefghijklmn \ +-device scsi-hd,bus=scsi1.0,channel=0,scsi-id=0,lun=0,device_id=abcdefghijklmn,\ +drive=drive-scsi1-0-0-0,id=scsi1-0-0-0,serial=abcdefghijklmn \ -drive file=/tmp/scsidisk3.img,format=raw,if=none,id=drive-scsi2-0-0-0 \ --device scsi-hd,bus=scsi2.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi2-0-0-0,\ -id=scsi2-0-0-0,wwn=0x5000c50015ea71ac \ +-device scsi-hd,bus=scsi2.0,channel=0,scsi-id=0,lun=0,\ +device_id=drive-scsi2-0-0-0,drive=drive-scsi2-0-0-0,id=scsi2-0-0-0,\ +wwn=0x5000c50015ea71ac \ -drive file=/tmp/scsidisk4.img,format=raw,if=none,id=drive-scsi3-0-0-0 \ --device scsi-hd,bus=scsi3.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi3-0-0-0,\ -id=scsi3-0-0-0 \ +-device scsi-hd,bus=scsi3.0,channel=0,scsi-id=0,lun=0,\ +device_id=drive-scsi3-0-0-0,drive=drive-scsi3-0-0-0,id=scsi3-0-0-0 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ resourcecontrol=deny \ diff --git a/tests/qemuxml2argvdata/disk-shared.x86_64-latest.args b/tests/qemuxml2argvdata/disk-shared.x86_64-latest.args index 4913d1ed200fa3a9f1b4d10690b1feec28f48ec2..141cf735a53c67c1a8420bfc2ae14e37e5b0ecb2 100644 --- a/tests/qemuxml2argvdata/disk-shared.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-shared.x86_64-latest.args @@ -33,8 +33,9 @@ bootindex=1,write-cache=on,serial=XYZXYZXYZYXXYZYZYXYZY \ readonly=on \ -device ide-cd,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 \ -drive file=/dev/scsi,format=raw,if=none,id=drive-scsi0-0-0-0,cache=none \ --device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,share-rw=on,\ -drive=drive-scsi0-0-0-0,id=scsi0-0-0-0,write-cache=on \ +-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,\ +device_id=drive-scsi0-0-0-0,share-rw=on,drive=drive-scsi0-0-0-0,id=scsi0-0-0-0,\ +write-cache=on \ -drive file=/dev/virtio,format=raw,if=none,id=drive-virtio-disk0,cache=none \ -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x3,share-rw=on,\ drive=drive-virtio-disk0,id=virtio-disk0,write-cache=on \ diff --git a/tests/qemuxml2argvdata/iothreads-virtio-scsi-pci.x86_64-latest.args b/tests/qemuxml2argvdata/iothreads-virtio-scsi-pci.x86_64-latest.args index 4513edcdd0db789a8c76762618ac6a487e529c4d..cde42c7dd17492d0d3f255efa01f92332ba0cc96 100644 --- a/tests/qemuxml2argvdata/iothreads-virtio-scsi-pci.x86_64-latest.args +++ b/tests/qemuxml2argvdata/iothreads-virtio-scsi-pci.x86_64-latest.args @@ -35,8 +35,8 @@ id=drive-virtio-disk1 \ drive=drive-virtio-disk1,id=virtio-disk1 \ -drive file=/var/lib/libvirt/images/iothrtest2.img,format=raw,if=none,\ id=drive-scsi0-0-0-3 \ --device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=3,drive=drive-scsi0-0-0-3,\ -id=scsi0-0-0-3 \ +-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=3,\ +device_id=drive-scsi0-0-0-3,drive=drive-scsi0-0-0-3,id=scsi0-0-0-3 \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ resourcecontrol=deny \ -msg timestamp=on