QEMU has a special blockdev backend for a cdrom called 'host_cdrom'. Use it for SCSI hostdevs so that guests can detect the cdrom properly. For testing purposes we format a cdrom if the fake adapter name is "cdrom". Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_process.c | 4 ++++ .../hostdev-scsi-virtio-scsi.x86_64-2.8.0.args | 3 +++ .../hostdev-scsi-virtio-scsi.x86_64-4.1.0.args | 3 +++ .../hostdev-scsi-virtio-scsi.x86_64-latest.args | 4 ++++ tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.xml | 8 ++++++++ tests/qemuxml2argvtest.c | 7 ++++++- tests/qemuxml2xmloutdata/hostdev-scsi-virtio-scsi.xml | 8 ++++++++ 7 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 70b8d39db9..6e6073c0e1 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6233,6 +6233,10 @@ qemuProcessPrepareHostHostdev(virDomainHostdevDefPtr hostdev) return -1; src->path = g_strdup_printf("/dev/%s", devstr); + + if (virFileIsCDROM(src->path) == 1) + src->hostcdrom = true; + break; } diff --git a/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.x86_64-2.8.0.args b/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.x86_64-2.8.0.args index bb8a466f70..03ed12912e 100644 --- a/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.x86_64-2.8.0.args +++ b/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.x86_64-2.8.0.args @@ -58,5 +58,8 @@ drive=drive-hostdev4,id=hostdev4 \ 3260/iqn.1992-01.com.example%3Astorage/2,if=none,format=raw,id=drive-hostdev5 \ -device scsi-generic,bus=scsi0.0,channel=0,scsi-id=3,lun=5,\ drive=drive-hostdev5,id=hostdev5 \ +-drive file=/dev/sr0,if=none,format=raw,id=drive-hostdev6,readonly=on \ +-device scsi-generic,bus=scsi0.0,channel=0,scsi-id=4,lun=5,\ +drive=drive-hostdev6,id=hostdev6 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \ -msg timestamp=on diff --git a/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.x86_64-4.1.0.args b/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.x86_64-4.1.0.args index 973ae5677a..5aaf2a9ea2 100644 --- a/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.x86_64-4.1.0.args +++ b/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.x86_64-4.1.0.args @@ -70,6 +70,9 @@ file.initiator-name=iqn.2020-07.com.example:test,if=none,format=raw,\ id=drive-hostdev5 \ -device scsi-generic,bus=scsi0.0,channel=0,scsi-id=3,lun=5,\ drive=drive-hostdev5,id=hostdev5 \ +-drive file=/dev/sr0,if=none,format=raw,id=drive-hostdev6,readonly=on \ +-device scsi-generic,bus=scsi0.0,channel=0,scsi-id=4,lun=5,\ +drive=drive-hostdev6,id=hostdev6 \ -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/hostdev-scsi-virtio-scsi.x86_64-latest.args b/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.x86_64-latest.args index c00ef41bf2..b26fbe36ff 100644 --- a/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.x86_64-latest.args +++ b/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.x86_64-latest.args @@ -76,6 +76,10 @@ keyid=masterKey0,iv=AAECAwQFBgcICQoLDA0ODw==,format=base64 \ "node-name":"libvirt-8-backend","read-only":false}' \ -device scsi-generic,bus=scsi0.0,channel=0,scsi-id=3,lun=5,\ drive=libvirt-8-backend,id=hostdev5 \ +-blockdev '{"driver":"host_cdrom","filename":"/dev/sr0",\ +"node-name":"libvirt-9-backend","read-only":true}' \ +-device scsi-generic,bus=scsi0.0,channel=0,scsi-id=4,lun=5,\ +drive=libvirt-9-backend,id=hostdev6 \ -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/hostdev-scsi-virtio-scsi.xml b/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.xml index d096e0cb28..9374acef90 100644 --- a/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.xml +++ b/tests/qemuxml2argvdata/hostdev-scsi-virtio-scsi.xml @@ -82,6 +82,14 @@ </source> <address type='drive' controller='0' bus='0' target='3' unit='5'/> </hostdev> + <hostdev mode='subsystem' type='scsi' managed='yes'> + <source> + <adapter name='cdrom'/> + <address bus='0' target='0' unit='0'/> + </source> + <readonly/> + <address type='drive' controller='0' bus='0' target='4' unit='5'/> + </hostdev> <memballoon model='virtio'/> </devices> </domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 3c1bec804a..3db4824a26 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -419,7 +419,12 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv, switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: - scsisrc->u.host.src->path = g_strdup("/dev/sg0"); + if (STREQ(scsisrc->u.host.adapter, "cdrom")) { + scsisrc->u.host.src->path = g_strdup("/dev/sr0"); + scsisrc->u.host.src->hostcdrom = true; + } else { + scsisrc->u.host.src->path = g_strdup("/dev/sg0"); + } break; case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI: diff --git a/tests/qemuxml2xmloutdata/hostdev-scsi-virtio-scsi.xml b/tests/qemuxml2xmloutdata/hostdev-scsi-virtio-scsi.xml index 3e2e21dc55..6f6899c114 100644 --- a/tests/qemuxml2xmloutdata/hostdev-scsi-virtio-scsi.xml +++ b/tests/qemuxml2xmloutdata/hostdev-scsi-virtio-scsi.xml @@ -89,6 +89,14 @@ </source> <address type='drive' controller='0' bus='0' target='3' unit='5'/> </hostdev> + <hostdev mode='subsystem' type='scsi' managed='yes'> + <source> + <adapter name='cdrom'/> + <address bus='0' target='0' unit='0'/> + </source> + <readonly/> + <address type='drive' controller='0' bus='0' target='4' unit='5'/> + </hostdev> <memballoon model='virtio'> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </memballoon> -- 2.26.2