[PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev

-drive detects whether a device is a cdrom automatically but we need to use 'host_cdrom' when using blockdev explicitly. Fix the hostdev code which was recently converted to -blockdev. Warning: I _don't_ have a box with a CDROM handy so this code is not tested in action! Peter Krempa (6): qemuProcessCreatePretendCmd: Split up preparation and command building qemu: hostdev: Prepare definition bits in qemuDomainPrepareHostdev qemu: Prepare hostdev data which depends on the host state separately qemuxml2argvmock: Remove mocking of 'virSCSIDeviceGetSgName' qemu: Detect whether a SCSI hostdev is a cdrom qemu: Add test cases for 'host_cdrom' blockdev backend via <disk> src/qemu/qemu_command.c | 33 +----- src/qemu/qemu_domain.c | 5 + src/qemu/qemu_driver.c | 65 ++++++++++- src/qemu/qemu_hotplug.c | 3 + src/qemu/qemu_process.c | 103 +++++++++++++++--- src/qemu/qemu_process.h | 21 ++-- tests/qemuxml2argvdata/disk-cdrom.args | 4 +- .../disk-cdrom.x86_64-2.12.0.args | 4 +- .../disk-cdrom.x86_64-latest.args | 6 +- tests/qemuxml2argvdata/disk-cdrom.xml | 5 +- ...hostdev-scsi-virtio-scsi.x86_64-2.8.0.args | 3 + ...hostdev-scsi-virtio-scsi.x86_64-4.1.0.args | 3 + ...ostdev-scsi-virtio-scsi.x86_64-latest.args | 4 + .../hostdev-scsi-virtio-scsi.xml | 8 ++ tests/qemuxml2argvmock.c | 13 --- tests/qemuxml2argvtest.c | 45 +++++++- tests/qemuxml2xmloutdata/disk-cdrom.xml | 5 +- .../hostdev-scsi-virtio-scsi.xml | 8 ++ 18 files changed, 252 insertions(+), 86 deletions(-) -- 2.26.2

Host preparation steps which are deliberately skipped when pretend-creating a commandline are normally executed after VM object preparation. In the test code we are faking some of the host preparation steps, but we were doing that prior to the call to qemuProcessPrepareDomain embedded in qemuProcessCreatePretendCmd. By splitting up qemuProcessCreatePretendCmd into two functions we can ensure that the ordering of the prepare steps stays consistent. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_driver.c | 9 ++++++--- src/qemu/qemu_process.c | 42 +++++++++++++++++++++++++--------------- src/qemu/qemu_process.h | 19 +++++++++++------- tests/qemuxml2argvtest.c | 11 +++++++---- 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 825bdd9119..f07a27d525 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6451,9 +6451,12 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, vm->def->nets[i] = newNet; } - if (!(cmd = qemuProcessCreatePretendCmd(driver, vm, NULL, - qemuCheckFips(), true, false, - VIR_QEMU_PROCESS_START_COLD))) + if (qemuProcessCreatePretendCmdPrepare(driver, vm, NULL, true, + VIR_QEMU_PROCESS_START_COLD) < 0) + goto cleanup; + + if (!(cmd = qemuProcessCreatePretendCmdBuild(driver, vm, NULL, + qemuCheckFips(), true, false))) goto cleanup; ret = virCommandToString(cmd, false); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 5bc76a75e3..85943594fa 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7267,35 +7267,45 @@ qemuProcessStart(virConnectPtr conn, } -virCommandPtr -qemuProcessCreatePretendCmd(virQEMUDriverPtr driver, - virDomainObjPtr vm, - const char *migrateURI, - bool enableFips, - bool standalone, - bool jsonPropsValidation, - unsigned int flags) +int +qemuProcessCreatePretendCmdPrepare(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *migrateURI, + bool standalone, + unsigned int flags) { - unsigned int buildflags = 0; - virCheckFlags(VIR_QEMU_PROCESS_START_COLD | VIR_QEMU_PROCESS_START_PAUSED | - VIR_QEMU_PROCESS_START_AUTODESTROY, NULL); + VIR_QEMU_PROCESS_START_AUTODESTROY, -1); flags |= VIR_QEMU_PROCESS_START_PRETEND; flags |= VIR_QEMU_PROCESS_START_NEW; if (standalone) flags |= VIR_QEMU_PROCESS_START_STANDALONE; - if (jsonPropsValidation) - buildflags = QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON; - if (qemuProcessInit(driver, vm, NULL, QEMU_ASYNC_JOB_NONE, !!migrateURI, flags) < 0) - return NULL; + return -1; if (qemuProcessPrepareDomain(driver, vm, flags) < 0) - return NULL; + return -1; + + return 0; +} + + +virCommandPtr +qemuProcessCreatePretendCmdBuild(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *migrateURI, + bool enableFips, + bool standalone, + bool jsonPropsValidation) +{ + unsigned int buildflags = 0; + + if (jsonPropsValidation) + buildflags = QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON; VIR_DEBUG("Building emulator command line"); return qemuBuildCommandLine(driver, diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index dbd989c321..830b2b23d6 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -96,13 +96,18 @@ int qemuProcessStart(virConnectPtr conn, virNetDevVPortProfileOp vmop, unsigned int flags); -virCommandPtr qemuProcessCreatePretendCmd(virQEMUDriverPtr driver, - virDomainObjPtr vm, - const char *migrateURI, - bool enableFips, - bool standalone, - bool jsonPropsValidation, - unsigned int flags); +int qemuProcessCreatePretendCmdPrepare(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *migrateURI, + bool standalone, + unsigned int flags); + +virCommandPtr qemuProcessCreatePretendCmdBuild(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *migrateURI, + bool enableFips, + bool standalone, + bool jsonPropsValidation); int qemuProcessInit(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 8aa791d9f7..7270f2c3cc 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -401,6 +401,10 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv, { size_t i; + if (qemuProcessCreatePretendCmdPrepare(drv, vm, migrateURI, false, + VIR_QEMU_PROCESS_START_COLD) < 0) + return NULL; + for (i = 0; i < vm->def->nhostdevs; i++) { virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i]; @@ -466,10 +470,9 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv, } } - return qemuProcessCreatePretendCmd(drv, vm, migrateURI, - (flags & FLAG_FIPS), false, - jsonPropsValidation, - VIR_QEMU_PROCESS_START_COLD); + return qemuProcessCreatePretendCmdBuild(drv, vm, migrateURI, + (flags & FLAG_FIPS), false, + jsonPropsValidation); } -- 2.26.2

qemuBuildHostdevSCSIAttachPrepare is supposed to prepare the data structure used for attaching the hostdev not preparing the hostdev definition itself. Move the corresponding bits to qemuDomainPrepareHostdev Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_command.c | 2 -- src/qemu/qemu_domain.c | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 697a2db62b..5e7454a6e8 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5134,7 +5134,6 @@ qemuBuildHostdevSCSIAttachPrepare(virDomainHostdevDefPtr hostdev, src = scsisrc->u.host.src; - src->type = VIR_STORAGE_TYPE_BLOCK; src->path = g_strdup_printf("/dev/%s", devstr); break; @@ -5149,7 +5148,6 @@ qemuBuildHostdevSCSIAttachPrepare(virDomainHostdevDefPtr hostdev, return NULL; } - src->readonly = hostdev->readonly; ret->storageNodeName = src->nodestorage; *backendAlias = src->nodestorage; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 5e603284be..ddfdac657a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -10408,6 +10408,9 @@ qemuDomainPrepareHostdev(virDomainHostdevDefPtr hostdev, virObjectUnref(scsisrc->u.host.src); scsisrc->u.host.src = virStorageSourceNew(); src = scsisrc->u.host.src; + + src->type = VIR_STORAGE_TYPE_BLOCK; + break; case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI: @@ -10423,6 +10426,8 @@ qemuDomainPrepareHostdev(virDomainHostdevDefPtr hostdev, if (src) { const char *backendalias = hostdev->info->alias; + src->readonly = hostdev->readonly; + if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV_HOSTDEV_SCSI)) { src->id = qemuDomainStorageIdNew(priv); src->nodestorage = g_strdup_printf("libvirt-%d-backend", src->id); -- 2.26.2

SCSI hostdev setup requires querying the host os for the actual path of the configured hostdev. This was historically done in the command line formatter. Our new approach is to split out this part into 'qemuProcessPrepareHost' which is designed to be skipped in tests. Refactor the hostdev code to use this new semantics, and add appropriate handlers filling in the data for tests and the qemuConnectDomainXMLToNative users. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_command.c | 31 +--------------------- src/qemu/qemu_driver.c | 56 +++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_hotplug.c | 3 +++ src/qemu/qemu_process.c | 57 ++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_process.h | 2 ++ tests/qemuxml2argvtest.c | 18 +++++++++++++ 6 files changed, 137 insertions(+), 30 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 5e7454a6e8..87ebdf4170 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4537,19 +4537,6 @@ qemuBuildHubCommandLine(virCommandPtr cmd, } -static char * -qemuBuildSCSIHostHostdevDrvStr(virDomainHostdevDefPtr dev) -{ - virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi; - virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host; - - return virSCSIDeviceGetSgName(NULL, - scsihostsrc->adapter, - scsihostsrc->bus, - scsihostsrc->target, - scsihostsrc->unit); -} - static char * qemuBuildSCSIiSCSIHostdevDrvStr(virDomainHostdevDefPtr dev, virQEMUCapsPtr qemuCaps) @@ -4626,9 +4613,7 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev, return NULL; virBufferAdd(&buf, source, -1); } else { - if (!(source = qemuBuildSCSIHostHostdevDrvStr(dev))) - return NULL; - virBufferAsprintf(&buf, "file=/dev/%s,if=none,format=raw", source); + virBufferAsprintf(&buf, "file=%s,if=none,format=raw", scsisrc->u.host.src->path); } if (!(drivealias = qemuAliasFromHostdev(dev))) @@ -5119,23 +5104,9 @@ qemuBuildHostdevSCSIAttachPrepare(virDomainHostdevDefPtr hostdev, virStorageSourcePtr src = NULL; if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV_HOSTDEV_SCSI)) { - g_autofree char *devstr = NULL; - switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: - if (!scsisrc->u.host.src) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("SCSI host device data structure was not initialized")); - return NULL; - } - - if (!(devstr = qemuBuildSCSIHostHostdevDrvStr(hostdev))) - return NULL; - src = scsisrc->u.host.src; - - src->path = g_strdup_printf("/dev/%s", devstr); - break; case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI: diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f07a27d525..bb4a46be98 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6398,6 +6398,59 @@ static char } +static int +qemuConnectDomainXMLToNativePrepareHostHostdev(virDomainHostdevDefPtr hostdev) +{ + if (virHostdevIsSCSIDevice(hostdev)) { + virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi; + + switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { + case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: { + virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host; + virStorageSourcePtr src = scsisrc->u.host.src; + g_autofree char *devstr = NULL; + + if (!(devstr = virSCSIDeviceGetSgName(NULL, + scsihostsrc->adapter, + scsihostsrc->bus, + scsihostsrc->target, + scsihostsrc->unit))) + return -1; + + src->path = g_strdup_printf("/dev/%s", devstr); + break; + } + + case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI: + break; + + case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_LAST: + default: + virReportEnumRangeError(virDomainHostdevSCSIProtocolType, scsisrc->protocol); + return -1; + } + } + + return 0; +} + + +static int +qemuConnectDomainXMLToNativePrepareHost(virDomainObjPtr vm) +{ + size_t i; + + for (i = 0; i < vm->def->nhostdevs; i++) { + virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i]; + + if (qemuConnectDomainXMLToNativePrepareHostHostdev(hostdev) < 0) + return -1; + } + + return 0; +} + + static char *qemuConnectDomainXMLToNative(virConnectPtr conn, const char *format, const char *xmlData, @@ -6455,6 +6508,9 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, VIR_QEMU_PROCESS_START_COLD) < 0) goto cleanup; + if (qemuConnectDomainXMLToNativePrepareHost(vm) < 0) + goto cleanup; + if (!(cmd = qemuProcessCreatePretendCmdBuild(driver, vm, NULL, qemuCheckFips(), true, false))) goto cleanup; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 79fc8baa5c..b6d5c856a1 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2608,6 +2608,9 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriverPtr driver, if (qemuDomainPrepareHostdev(hostdev, priv) < 0) goto cleanup; + if (qemuProcessPrepareHostHostdev(hostdev) < 0) + goto cleanup; + if (!(data = qemuBuildHostdevSCSIAttachPrepare(hostdev, &backendalias, priv->qemuCaps))) goto cleanup; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 85943594fa..70b8d39db9 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6213,6 +6213,59 @@ qemuProcessPrepareDomainHostdevs(virDomainObjPtr vm, } +int +qemuProcessPrepareHostHostdev(virDomainHostdevDefPtr hostdev) +{ + if (virHostdevIsSCSIDevice(hostdev)) { + virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi; + + switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { + case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: { + virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host; + virStorageSourcePtr src = scsisrc->u.host.src; + g_autofree char *devstr = NULL; + + if (!(devstr = virSCSIDeviceGetSgName(NULL, + scsihostsrc->adapter, + scsihostsrc->bus, + scsihostsrc->target, + scsihostsrc->unit))) + return -1; + + src->path = g_strdup_printf("/dev/%s", devstr); + break; + } + + case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI: + break; + + case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_LAST: + default: + virReportEnumRangeError(virDomainHostdevSCSIProtocolType, scsisrc->protocol); + return -1; + } + } + + return 0; +} + + +static int +qemuProcessPrepareHostHostdevs(virDomainObjPtr vm) +{ + size_t i; + + for (i = 0; i < vm->def->nhostdevs; i++) { + virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i]; + + if (qemuProcessPrepareHostHostdev(hostdev) < 0) + return -1; + } + + return 0; +} + + static void qemuProcessPrepareAllowReboot(virDomainObjPtr vm) { @@ -6595,6 +6648,10 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver, if (qemuProcessPrepareHostStorage(driver, vm, flags) < 0) return -1; + VIR_DEBUG("Preparing hostdevs (host-side)"); + if (qemuProcessPrepareHostHostdevs(vm) < 0) + return -1; + VIR_DEBUG("Preparing external devices"); if (qemuExtDevicesPrepareHost(driver, vm) < 0) return -1; diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 830b2b23d6..f4feeaa68f 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -122,6 +122,8 @@ int qemuProcessPrepareDomain(virQEMUDriverPtr driver, int qemuProcessOpenVhostVsock(virDomainVsockDefPtr vsock); +int qemuProcessPrepareHostHostdev(virDomainHostdevDefPtr hostdev); + int qemuProcessPrepareHost(virQEMUDriverPtr driver, virDomainObjPtr vm, unsigned int flags); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 7270f2c3cc..3c1bec804a 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -413,6 +413,24 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv, hostdev->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT) { hostdev->source.subsys.u.pci.backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO; } + + if (virHostdevIsSCSIDevice(hostdev)) { + virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi; + + switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { + case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: + scsisrc->u.host.src->path = g_strdup("/dev/sg0"); + break; + + case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI: + break; + + case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_LAST: + default: + virReportEnumRangeError(virDomainHostdevSCSIProtocolType, scsisrc->protocol); + return NULL; + } + } } for (i = 0; i < vm->def->nfss; i++) { -- 2.26.2

Hostdev setup code no longer resolves hostdev name in the commandline formatter but we mock it directly in the monitor code. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/qemuxml2argvmock.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index b9322f4f2a..565d2aefca 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -121,19 +121,6 @@ virMemoryMaxValue(bool capped G_GNUC_UNUSED) return LLONG_MAX; } -char * -virSCSIDeviceGetSgName(const char *sysfs_prefix G_GNUC_UNUSED, - const char *adapter G_GNUC_UNUSED, - unsigned int bus G_GNUC_UNUSED, - unsigned int target G_GNUC_UNUSED, - unsigned long long unit G_GNUC_UNUSED) -{ - char *ret; - - ret = g_strdup("sg0"); - return ret; -} - int virSCSIVHostOpenVhostSCSI(int *vhostfd) { -- 2.26.2

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@redhat.com> --- 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

Simulate that the device is a cdrom when the path equals to /dev/cdrom to provide testing for the 'host_cdrom' backend. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/qemuxml2argvdata/disk-cdrom.args | 4 ++-- tests/qemuxml2argvdata/disk-cdrom.x86_64-2.12.0.args | 4 ++-- tests/qemuxml2argvdata/disk-cdrom.x86_64-latest.args | 6 +++--- tests/qemuxml2argvdata/disk-cdrom.xml | 5 +++-- tests/qemuxml2argvtest.c | 11 +++++++++++ tests/qemuxml2xmloutdata/disk-cdrom.xml | 5 +++-- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/tests/qemuxml2argvdata/disk-cdrom.args b/tests/qemuxml2argvdata/disk-cdrom.args index cbac368129..e506a4befe 100644 --- a/tests/qemuxml2argvdata/disk-cdrom.args +++ b/tests/qemuxml2argvdata/disk-cdrom.args @@ -25,8 +25,8 @@ server,nowait \ -no-shutdown \ -no-acpi \ -usb \ --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=/dev/cdrom,format=raw,if=none,id=drive-ide0-0-0,readonly=on \ +-device ide-cd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ -drive file=/root/boot.iso,format=raw,if=none,id=drive-ide0-0-1,readonly=on \ -device ide-cd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1 \ -drive if=none,id=drive-ide0-1-0,readonly=on \ diff --git a/tests/qemuxml2argvdata/disk-cdrom.x86_64-2.12.0.args b/tests/qemuxml2argvdata/disk-cdrom.x86_64-2.12.0.args index 2440acc78a..0621746a3b 100644 --- a/tests/qemuxml2argvdata/disk-cdrom.x86_64-2.12.0.args +++ b/tests/qemuxml2argvdata/disk-cdrom.x86_64-2.12.0.args @@ -27,8 +27,8 @@ file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ -no-acpi \ -boot strict=on \ -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ --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=/dev/cdrom,format=raw,if=none,id=drive-ide0-0-0,readonly=on \ +-device ide-cd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ -drive file=/root/boot.iso,format=raw,if=none,id=drive-ide0-0-1,readonly=on \ -device ide-cd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1 \ -drive if=none,id=drive-ide0-1-0,readonly=on \ diff --git a/tests/qemuxml2argvdata/disk-cdrom.x86_64-latest.args b/tests/qemuxml2argvdata/disk-cdrom.x86_64-latest.args index 0d375ffd1c..beac75ec1d 100644 --- a/tests/qemuxml2argvdata/disk-cdrom.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-cdrom.x86_64-latest.args @@ -29,11 +29,11 @@ file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ -no-acpi \ -boot strict=on \ -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ --blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1",\ +-blockdev '{"driver":"host_cdrom","filename":"/dev/cdrom",\ "node-name":"libvirt-4-storage","auto-read-only":true,"discard":"unmap"}' \ --blockdev '{"node-name":"libvirt-4-format","read-only":false,"driver":"raw",\ +-blockdev '{"node-name":"libvirt-4-format","read-only":true,"driver":"raw",\ "file":"libvirt-4-storage"}' \ --device ide-hd,bus=ide.0,unit=0,drive=libvirt-4-format,id=ide0-0-0,bootindex=1 \ +-device ide-cd,bus=ide.0,unit=0,drive=libvirt-4-format,id=ide0-0-0 \ -blockdev '{"driver":"file","filename":"/root/boot.iso",\ "node-name":"libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-3-format","read-only":true,"driver":"raw",\ diff --git a/tests/qemuxml2argvdata/disk-cdrom.xml b/tests/qemuxml2argvdata/disk-cdrom.xml index b051b16642..54d2927ac3 100644 --- a/tests/qemuxml2argvdata/disk-cdrom.xml +++ b/tests/qemuxml2argvdata/disk-cdrom.xml @@ -14,10 +14,11 @@ <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-i386</emulator> - <disk type='block' device='disk'> + <disk type='block' device='cdrom'> <driver name='qemu' type='raw'/> - <source dev='/dev/HostVG/QEMUGuest1'/> + <source dev='/dev/cdrom'/> <target dev='hda' bus='ide'/> + <readonly/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> <disk type='file' device='cdrom'> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 3db4824a26..21bbd2c09d 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -405,6 +405,17 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv, VIR_QEMU_PROCESS_START_COLD) < 0) return NULL; + for (i = 0; i < vm->def->ndisks; i++) { + virDomainDiskDefPtr disk = vm->def->disks[i]; + + /* host cdrom requires special treatment in qemu, mock it */ + if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM && + disk->src->format == VIR_STORAGE_FILE_RAW && + virStorageSourceIsBlockLocal(disk->src) && + STREQ(disk->src->path, "/dev/cdrom")) + disk->src->hostcdrom = true; + } + for (i = 0; i < vm->def->nhostdevs; i++) { virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i]; diff --git a/tests/qemuxml2xmloutdata/disk-cdrom.xml b/tests/qemuxml2xmloutdata/disk-cdrom.xml index 3e6475c276..3a8c34761d 100644 --- a/tests/qemuxml2xmloutdata/disk-cdrom.xml +++ b/tests/qemuxml2xmloutdata/disk-cdrom.xml @@ -14,10 +14,11 @@ <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-i386</emulator> - <disk type='block' device='disk'> + <disk type='block' device='cdrom'> <driver name='qemu' type='raw'/> - <source dev='/dev/HostVG/QEMUGuest1'/> + <source dev='/dev/cdrom'/> <target dev='hda' bus='ide'/> + <readonly/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> <disk type='file' device='cdrom'> -- 2.26.2

Greetings All,
Sent: Thursday, October 15, 2020 at 6:25 PM From: "Peter Krempa" <pkrempa@redhat.com> To: libvir-list@redhat.com Cc: "daggs" <daggs@gmx.com> Subject: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
-drive detects whether a device is a cdrom automatically but we need to use 'host_cdrom' when using blockdev explicitly. Fix the hostdev code which was recently converted to -blockdev.
Warning:
I _don't_ have a box with a CDROM handy so this code is not tested in action!
Peter Krempa (6): qemuProcessCreatePretendCmd: Split up preparation and command building qemu: hostdev: Prepare definition bits in qemuDomainPrepareHostdev qemu: Prepare hostdev data which depends on the host state separately qemuxml2argvmock: Remove mocking of 'virSCSIDeviceGetSgName' qemu: Detect whether a SCSI hostdev is a cdrom qemu: Add test cases for 'host_cdrom' blockdev backend via <disk>
I've tested the bellow on libvirt 6.8.0, I wasn't able to get it to work, with the same entry as the example, e.g.: <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='0' unit='0'/> </hostdev> I get this error: error: XML error: SCSI host device doesn't support managed mode. if I mark the managed as no (like other pci pass-through devices I have in the vm), I get this error: error: internal error: Cannot parse adapter 'cdrom' full machine xml can be found at https://dpaste.com/G32WWAJA2 Dagg.

On Sun, Oct 18, 2020 at 14:34:16 +0200, daggs wrote:
Greetings All,
Sent: Thursday, October 15, 2020 at 6:25 PM From: "Peter Krempa" <pkrempa@redhat.com> To: libvir-list@redhat.com Cc: "daggs" <daggs@gmx.com> Subject: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
-drive detects whether a device is a cdrom automatically but we need to use 'host_cdrom' when using blockdev explicitly. Fix the hostdev code which was recently converted to -blockdev.
Warning:
I _don't_ have a box with a CDROM handy so this code is not tested in action!
Peter Krempa (6): qemuProcessCreatePretendCmd: Split up preparation and command building qemu: hostdev: Prepare definition bits in qemuDomainPrepareHostdev qemu: Prepare hostdev data which depends on the host state separately qemuxml2argvmock: Remove mocking of 'virSCSIDeviceGetSgName' qemu: Detect whether a SCSI hostdev is a cdrom qemu: Add test cases for 'host_cdrom' blockdev backend via <disk>
I've tested the bellow on libvirt 6.8.0, I wasn't able to get it to work, with the same entry as the example, e.g.: <hostdev mode='subsystem' type='scsi' managed='yes'> <source> <adapter name='cdrom'/>
This is purely for tests, to force a cdrom since we can't probe the host. Using it for a VM will fail.
<address bus='0' target='0' unit='0'/> </source> <readonly/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </hostdev> I get this error: error: XML error: SCSI host device doesn't support managed mode.
if I mark the managed as no (like other pci pass-through devices I have in the vm), I get this error: error: internal error: Cannot parse adapter 'cdrom'
Yup, this is expected, you need to use a real 'adapterN' here.

Greetings Peter,
Sent: Monday, October 19, 2020 at 10:17 AM From: "Peter Krempa" <pkrempa@redhat.com> To: "daggs" <daggs@gmx.com> Cc: libvir-list@redhat.com Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
On Sun, Oct 18, 2020 at 14:34:16 +0200, daggs wrote:
This is purely for tests, to force a cdrom since we can't probe the host. Using it for a VM will fail.
Yup, this is expected, you need to use a real 'adapterN' here.
so there is a bug in my xml? if so, where is the error? Dagg.

On Mon, Oct 19, 2020 at 09:45:31 +0200, daggs wrote:
Greetings Peter,
Sent: Monday, October 19, 2020 at 10:17 AM From: "Peter Krempa" <pkrempa@redhat.com> To: "daggs" <daggs@gmx.com> Cc: libvir-list@redhat.com Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
On Sun, Oct 18, 2020 at 14:34:16 +0200, daggs wrote:
This is purely for tests, to force a cdrom since we can't probe the host. Using it for a VM will fail.
Yup, this is expected, you need to use a real 'adapterN' here.
so there is a bug in my xml? if so, where is the error?
Well, you used an XML from our tests, with following config: <hostdev mode='subsystem' type='scsi' managed='yes'> <source> <adapter name='cdrom'/> If you look into patch 5/6 for the change to tests/qemuxml2argvtest.c you'll see that using 'cdrom' as an adapter name is a hack made for just tests. That will _not_ work anywhere else. You should use the XML that you've used before with the adapter name corresponding to the adapter the cdrom is on. The command line you've posted: -blockdev '{"driver":"host_device","filename":"/dev/sg0","node-name":"libvirt-2-backend","read-only":true}' \ -device scsi-generic,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=libvirt-2-backend,id=hostdev0 \ Shows that nothing has changed, but unfortunately doesn't show enough for me to debug it. Unfortunately the cdrom detection code doesn't log anything so debug logs won't help either. I'll need to try it in a nested virtualization environment since I don't have a physical CD drive handy.

Greetings Peter,
Sent: Monday, October 19, 2020 at 11:06 AM From: "Peter Krempa" <pkrempa@redhat.com> To: "daggs" <daggs@gmx.com> Cc: libvir-list@redhat.com Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
Well, you used an XML from our tests, with following config:
<hostdev mode='subsystem' type='scsi' managed='yes'> <source> <adapter name='cdrom'/>
If you look into patch 5/6 for the change to tests/qemuxml2argvtest.c you'll see that using 'cdrom' as an adapter name is a hack made for just tests. That will _not_ work anywhere else.
You should use the XML that you've used before with the adapter name corresponding to the adapter the cdrom is on.
The command line you've posted:
-blockdev '{"driver":"host_device","filename":"/dev/sg0","node-name":"libvirt-2-backend","read-only":true}' \ -device scsi-generic,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=libvirt-2-backend,id=hostdev0 \
Shows that nothing has changed, but unfortunately doesn't show enough for me to debug it. Unfortunately the cdrom detection code doesn't log anything so debug logs won't help either.
I'll need to try it in a nested virtualization environment since I don't have a physical CD drive handy.
if you wish, you can send my a patch with the debug code you want to add, I'll apply it, run and send you the log. Dagg.

On Mon, Oct 19, 2020 at 4:07 PM Peter Krempa <pkrempa@redhat.com> wrote:
On Mon, Oct 19, 2020 at 09:45:31 +0200, daggs wrote:
Greetings Peter,
Sent: Monday, October 19, 2020 at 10:17 AM From: "Peter Krempa" <pkrempa@redhat.com> To: "daggs" <daggs@gmx.com> Cc: libvir-list@redhat.com Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
On Sun, Oct 18, 2020 at 14:34:16 +0200, daggs wrote:
This is purely for tests, to force a cdrom since we can't probe the host. Using it for a VM will fail.
Yup, this is expected, you need to use a real 'adapterN' here.
so there is a bug in my xml? if so, where is the error?
Well, you used an XML from our tests, with following config:
<hostdev mode='subsystem' type='scsi' managed='yes'> <source> <adapter name='cdrom'/>
If you look into patch 5/6 for the change to tests/qemuxml2argvtest.c you'll see that using 'cdrom' as an adapter name is a hack made for just tests. That will _not_ work anywhere else.
You should use the XML that you've used before with the adapter name corresponding to the adapter the cdrom is on.
The command line you've posted:
-blockdev '{"driver":"host_device","filename":"/dev/sg0","node-name":"libvirt-2-backend","read-only":true}' \ -device scsi-generic,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=libvirt-2-backend,id=hostdev0 \
Shows that nothing has changed, but unfortunately doesn't show enough for me to debug it. Unfortunately the cdrom detection code doesn't log anything so debug logs won't help either.
I'll need to try it in a nested virtualization environment since I don't have a physical CD drive handy.
You can emulate it by scsi_debug: ➜ ~ modprobe scsi_debug ptype=5 ➜ ~ lsscsi [2:0:0:0] cd/dvd Linux scsi_debug 0188 /dev/sr0

Greetings Han,
Sent: Tuesday, October 20, 2020 at 12:33 PM From: "Han Han" <hhan@redhat.com> To: "Peter Krempa" <pkrempa@redhat.com> Cc: "daggs" <daggs@gmx.com>, libvir-list@redhat.com Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
You can emulate it by scsi_debug: ➜ ~ modprobe scsi_debug ptype=5 ➜ ~ lsscsi [2:0:0:0] cd/dvd Linux scsi_debug 0188 /dev/sr0
extremely cool, I did not know that. thanks for sharing Dagg.

On Thu, Oct 15, 2020 at 17:25:08 +0200, Peter Krempa wrote:
-drive detects whether a device is a cdrom automatically but we need to use 'host_cdrom' when using blockdev explicitly. Fix the hostdev code which was recently converted to -blockdev.
Warning:
I _don't_ have a box with a CDROM handy so this code is not tested in action!
I've tried this a bit more in a virtual environment ...
Peter Krempa (6): qemuProcessCreatePretendCmd: Split up preparation and command building qemu: hostdev: Prepare definition bits in qemuDomainPrepareHostdev qemu: Prepare hostdev data which depends on the host state separately qemuxml2argvmock: Remove mocking of 'virSCSIDeviceGetSgName'
These above are pure refactors which are IMO worth keeping, so somebody, please review.
qemu: Detect whether a SCSI hostdev is a cdrom qemu: Add test cases for 'host_cdrom' blockdev backend via <disk>
(self) NACK to those above 'host_cdrom' doesn't work with /dev/sg* as it doesn't detect that its a generic device for passthrough. Using 'host_device' is needed here, so the code we have currently is correct. I've tried this in nested virtual environment and the passthrough works fine for me. daggs, I need to start over, could you please post the following info. (please gather it again, so that it's all consistent): host OS side: libvirt version lsblk lsscsi VM XML file VM command line guest OS side: lsblk lsscsi lspci thanks!

Sent: Monday, October 19, 2020 at 7:35 PM From: "Peter Krempa" <pkrempa@redhat.com> To: libvir-list@redhat.com Cc: "daggs" <daggs@gmx.com> Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
(self) NACK to those above 'host_cdrom' doesn't work with /dev/sg* as it doesn't detect that its a generic device for passthrough. Using 'host_device' is needed here, so the code we have currently is correct.
I've tried this in nested virtual environment and the passthrough works fine for me.
daggs,
I need to start over, could you please post the following info. (please gather it again, so that it's all consistent):
host OS side:
libvirt version
Greetings Peter, libvirtd (libvirt) 6.8.0
lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 2.7T 0 disk └─sda1 8:1 0 2.7T 0 part /mnt/media sdb 8:16 1 14.3G 0 disk ├─sdb1 8:17 1 2M 0 part ├─sdb2 8:18 1 128M 0 part ├─sdb3 8:19 1 2.5G 0 part [SWAP] └─sdb4 8:20 1 11.7G 0 part / sr0 11:0 1 1024M 0 rom
lsscsi [0:0:0:0] cd/dvd HL-DT-ST DVDRAM GH24NSD1 LW00 /dev/sr0 [3:0:0:0] disk ATA ST3000DM001-1ER1 CC25 /dev/sda [6:0:0:0] disk SanDisk Ultra Fit 1.00 /dev/sdb
VM XML file <domain type='kvm' id='3'> <name>streamer-vm-q35</name> <uuid>4fb1463b-837c-40fc-a760-a69afc040a1a</uuid> <memory unit='KiB'>8388608</memory> <currentMemory unit='KiB'>8388608</currentMemory> <vcpu placement='static' current='1'>2</vcpu> <resource> <partition>/machine</partition> </resource> <os> <type arch='x86_64' machine='pc-q35-5.0'>hvm</type> <loader readonly='yes' type='pflash'>/usr/share/qemu/edk2-x86_64-secure-code.fd</loader> <nvram template='/usr/share/qemu/edk2-i386-vars.fd'>/var/lib/libvirt/qemu/nvram/streamer-vm-q35_VARS.fd</nvram> <boot dev='hd'/> </os> <features> <acpi/> <apic/> <smm state='on'/> </features> <cpu mode='host-passthrough' check='none' migratable='on'> <topology sockets='1' dies='1' cores='1' threads='2'/> </cpu> <clock offset='utc'> <timer name='rtc' tickpolicy='catchup'/> <timer name='pit' tickpolicy='delay'/> <timer name='hpet' present='no'/> </clock> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <pm> <suspend-to-mem enabled='no'/> <suspend-to-disk enabled='no'/> </pm> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> <disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/home/streamer/streamer.qcow2' index='1'/> <backingStore/> <target dev='vda' bus='virtio'/> <alias name='virtio-disk0'/> <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/> </disk> <controller type='usb' index='0' model='qemu-xhci'> <alias name='usb'/> <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/> </controller> <controller type='sata' index='0'> <alias name='ide'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/> </controller> <controller type='pci' index='0' model='pcie-root'> <alias name='pcie.0'/> </controller> <controller type='pci' index='1' model='dmi-to-pci-bridge'> <model name='i82801b11-bridge'/> <alias name='pci.1'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x1e' function='0x0'/> </controller> <controller type='pci' index='2' model='pci-bridge'> <model name='pci-bridge'/> <target chassisNr='2'/> <alias name='pci.2'/> <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> </controller> <controller type='pci' index='3' model='pcie-root-port'> <model name='pcie-root-port'/> <target chassis='3' port='0x8'/> <alias name='pci.3'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0' multifunction='on'/> </controller> <controller type='pci' index='4' model='pcie-root-port'> <model name='pcie-root-port'/> <target chassis='4' port='0x9'/> <alias name='pci.4'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <controller type='pci' index='5' model='pcie-root-port'> <model name='pcie-root-port'/> <target chassis='5' port='0xa'/> <alias name='pci.5'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='pci' index='6' model='pcie-root-port'> <model name='pcie-root-port'/> <target chassis='6' port='0xb'/> <alias name='pci.6'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x3'/> </controller> <controller type='pci' index='7' model='pcie-root-port'> <model name='pcie-root-port'/> <target chassis='7' port='0xc'/> <alias name='pci.7'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x4'/> </controller> <controller type='scsi' index='0' model='virtio-scsi'> <alias name='scsi0'/> <address type='pci' domain='0x0000' bus='0x02' slot='0x01' function='0x0'/> </controller> <interface type='network'> <mac address='52:54:00:5a:4c:8c'/> <source network='default' portid='11d02025-6f04-4cfd-9236-28af102b6edf' bridge='virtsw'/> <target dev='virtsw-streamer'/> <model type='e1000e'/> <alias name='net0'/> <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/> </interface> <serial type='pty'> <source path='/dev/pts/2'/> <target type='isa-serial' port='0'> <model name='isa-serial'/> </target> <alias name='serial0'/> </serial> <console type='pty' tty='/dev/pts/2'> <source path='/dev/pts/2'/> <target type='serial' port='0'/> <alias name='serial0'/> </console> <input type='mouse' bus='ps2'> <alias name='input0'/> </input> <input type='keyboard' bus='ps2'> <alias name='input1'/> </input> <hostdev mode='subsystem' type='scsi' managed='no'> <source> <adapter name='scsi_host0'/> <address bus='0' target='0' unit='0'/> </source> <readonly/> <alias name='hostdev0'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </hostdev> <hostdev mode='subsystem' type='pci' managed='yes'> <driver name='vfio'/> <source> <address domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </source> <alias name='hostdev1'/> <rom file='/home/streamer/gpu-8086:5902-uefi.rom'/> <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/> </hostdev> <hostdev mode='subsystem' type='pci' managed='yes'> <driver name='vfio'/> <source> <address domain='0x0000' bus='0x00' slot='0x1f' function='0x3'/> </source> <alias name='hostdev2'/> <address type='pci' domain='0x0000' bus='0x02' slot='0x02' function='0x0'/> </hostdev> <hostdev mode='subsystem' type='usb' managed='yes'> <source startupPolicy='optional' missing='yes'> <vendor id='0x046d'/> <product id='0xc52e'/> </source> <alias name='hostdev3'/> <address type='usb' bus='0' port='1'/> </hostdev> <hostdev mode='subsystem' type='usb' managed='yes'> <source startupPolicy='optional' missing='yes'> <vendor id='0x2548'/> <product id='0x1002'/> </source> <alias name='hostdev4'/> <address type='usb' bus='0' port='2'/> </hostdev> <memballoon model='virtio'> <alias name='balloon0'/> <address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/> </memballoon> </devices> <seclabel type='dynamic' model='dac' relabel='yes'> <label>+77:+77</label> <imagelabel>+77:+77</imagelabel> </seclabel> </domain
VM command line /usr/bin/qemu-system-x86_64 -name guest=streamer-vm-q35,debug-threads=on -S -object secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-3-streamer-vm-q35/master-key.aes -blockdev {"driver":"file","filename":"/usr/share/qemu/edk2-x86_64-secure-code.fd","node-name":"libvirt-pflash0-storage","auto-read-only":true,"discard":"unmap"} -blockdev {"node-name":"libvirt-pflash0-format","read-only":true,"driver":"raw","file":"libvirt-pflash0-storage"} -blockdev {"driver":"file","filename":"/var/lib/libvirt/qemu/nvram/streamer-vm-q35_VARS.fd","node-name":"libvirt-pflash1-storage","auto-read-only":true,"discard":"unmap"} -blockdev {"node-name":"libvirt-pflash1-format","read-only":false,"driver":"raw","file":"libvirt-pflash1-storage"} -machine pc-q35-5.0,accel=kvm,usb=off,smm=on,dump-guest-core=off,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format -cpu host,migratable=on -m 8192 -overcommit mem-lock=off -smp 1,maxcpus=2,sockets=1,dies=1,cores=1,threads=2 -uuid 4fb1463b-837c-40fc-a760-a69afc040a1a -display none -no-user-config -nodefaults -chardev socket,id=charmonitor,fd=29,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew -global kvm-pit.lost_tick_policy=delay -no-hpet -no-shutdown -global ICH9-LPC.disable_s3=1 -global ICH9-LPC.disable_s4=1 -boot strict=on -device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e -device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x0 -device pcie-root-port,port=0x8,chassis=3,id=pci.3,bus=pcie.0,multifunction=on,addr=0x1 -device pcie-root-port,port=0x9,chassis=4,id=pci.4,bus=pcie.0,addr=0x1.0x1 -device pcie-root-port,port=0xa,chassis=5,id=pci.5,bus=pcie.0,addr=0x1.0x2 -device pcie-root-port,port=0xb,chassis=6,id=pci.6,bus=pcie.0,addr=0x1.0x3 -device pcie-root-port,port=0xc,chassis=7,id=pci.7,bus=pcie.0,addr=0x1.0x4 -device qemu-xhci,id=usb,bus=pci.4,addr=0x0 -device virtio-scsi-pci,id=scsi0,bus=pci.2,addr=0x1 -blockdev {"driver":"file","filename":"/home/streamer/streamer.qcow2","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"} -blockdev {"node-name":"libvirt-1-format","read-only":false,"driver":"qcow2","file":"libvirt-1-storage","backing":null} -device virtio-blk-pci,bus=pci.5,addr=0x0,drive=libvirt-1-format,id=virtio-disk0,bootindex=1 -netdev tap,fd=31,id=hostnet0 -device e1000e,netdev=hostnet0,id=net0,mac=52:54:00:5a:4c:8c,bus=pci.3,addr=0x0 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -blockdev {"driver":"host_device","filename":"/dev/sg0","node-name":"libvirt-2-backend","read-only":true} -device scsi-generic,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=libvirt-2-backend,id=hostdev0 -device vfio-pci,host=0000:00:02.0,id=hostdev1,bus=pci.7,addr=0x0,romfile=/home/streamer/gpu-8086:5902-uefi.rom -device vfio-pci,host=0000:00:1f.3,id=hostdev2,bus=pci.2,addr=0x2 -device usb-host,id=hostdev3,bus=usb.0,port=1 -device usb-host,id=hostdev4,bus=usb.0,port=2 -device virtio-balloon-pci,id=balloon0,bus=pci.6,addr=0x0 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny -msg timestamp=on
guest OS side:
lsblk
system has no lsblk so here is the content of /dev/disk and the output of blkid: /dev/disk/by-label: total 0 lrwxrwxrwx 1 root root 10 Oct 19 13:08 Storage -> ../../vda2 lrwxrwxrwx 1 root root 10 Oct 19 13:08 System -> ../../vda1 /dev/disk/by-partuuid: total 0 lrwxrwxrwx 1 root root 10 Oct 19 13:08 ad58aa27-01 -> ../../vda1 lrwxrwxrwx 1 root root 10 Oct 19 13:08 ad58aa27-02 -> ../../vda2 /dev/disk/by-path: total 0 lrwxrwxrwx 1 root root 9 Oct 19 13:08 pci-0000:03:00.0 -> ../../vda lrwxrwxrwx 1 root root 10 Oct 19 13:08 pci-0000:03:00.0-part1 -> ../../vda1 lrwxrwxrwx 1 root root 10 Oct 19 13:08 pci-0000:03:00.0-part2 -> ../../vda2 lrwxrwxrwx 1 root root 9 Oct 19 13:08 virtio-pci-0000:03:00.0 -> ../../vda lrwxrwxrwx 1 root root 10 Oct 19 13:08 virtio-pci-0000:03:00.0-part1 -> ../../vda1 lrwxrwxrwx 1 root root 10 Oct 19 13:08 virtio-pci-0000:03:00.0-part2 -> ../../vda2 /dev/disk/by-uuid: total 0 lrwxrwxrwx 1 root root 10 Oct 19 13:08 0672-E518 -> ../../vda1 lrwxrwxrwx 1 root root 10 Oct 19 13:08 51eb82f3-0710-4bfa-82b0-fd0d1da1abeb -> ../../vda2 /dev/vda1: SEC_TYPE="msdos" LABEL_FATBOOT="System" LABEL="System" UUID="0672-E518" TYPE="vfat" PARTUUID="ad58aa27-01" /dev/vda2: LABEL="Storage" UUID="51eb82f3-0710-4bfa-82b0-fd0d1da1abeb" TYPE="ext4" PARTUUID="ad58aa27-02" /dev/loop0: TYPE="squashfs"
lsscsi system has no /proc/scsi, thus no output. will this help? lrwxrwxrwx 1 root root 0 Oct 19 13:08 /sys/bus/scsi/devices/host0 -> ../../../devices/pci0000:00/0000:00:1f.2/ata1/host0 lrwxrwxrwx 1 root root 0 Oct 19 13:08 /sys/bus/scsi/devices/host1 -> ../../../devices/pci0000:00/0000:00:1f.2/ata2/host1 lrwxrwxrwx 1 root root 0 Oct 19 13:08 /sys/bus/scsi/devices/host2 -> ../../../devices/pci0000:00/0000:00:1f.2/ata3/host2 lrwxrwxrwx 1 root root 0 Oct 19 13:08 /sys/bus/scsi/devices/host3 -> ../../../devices/pci0000:00/0000:00:1f.2/ata4/host3 lrwxrwxrwx 1 root root 0 Oct 19 13:08 /sys/bus/scsi/devices/host4 -> ../../../devices/pci0000:00/0000:00:1f.2/ata5/host4 lrwxrwxrwx 1 root root 0 Oct 19 13:08 /sys/bus/scsi/devices/host5 -> ../../../devices/pci0000:00/0000:00:1f.2/ata6/host5
lspci 00:00.0 Host bridge: Intel Corporation 82G33/G31/P35/P31 Express DRAM Controller 00:01.0 PCI bridge: Red Hat, Inc. QEMU PCIe Root port 00:01.1 PCI bridge: Red Hat, Inc. QEMU PCIe Root port 00:01.2 PCI bridge: Red Hat, Inc. QEMU PCIe Root port 00:01.3 PCI bridge: Red Hat, Inc. QEMU PCIe Root port 00:01.4 PCI bridge: Red Hat, Inc. QEMU PCIe Root port 00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev 92) 00:1f.0 ISA bridge: Intel Corporation 82801IB (ICH9) LPC Interface Controller (rev 02) 00:1f.2 SATA controller: Intel Corporation 82801IR/IO/IH (ICH9R/DO/DH) 6 port SATA Controller [AHCI mode] (rev 02) 00:1f.3 SMBus: Intel Corporation 82801I (ICH9 Family) SMBus Controller (rev 02) 01:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection 02:00.0 USB controller: Red Hat, Inc. QEMU XHCI Host Controller (rev 01) 03:00.0 SCSI storage controller: Red Hat, Inc. Virtio block device (rev 01) 04:00.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon (rev 01) 05:00.0 VGA compatible controller: Intel Corporation HD Graphics 610 (rev 04) 06:00.0 PCI bridge: Red Hat, Inc. QEMU PCI-PCI bridge 07:01.0 SCSI storage controller: Red Hat, Inc. Virtio SCSI 07:02.0 Audio device: Intel Corporation 100 Series/C230 Series Chipset Family HD Audio Controller (rev 31)
thanks!

On Mon, Oct 19, 2020 at 20:37:53 +0200, daggs wrote:
Greetings Peter,
Sent: Monday, October 19, 2020 at 7:35 PM From: "Peter Krempa" <pkrempa@redhat.com> To: libvir-list@redhat.com Cc: "daggs" <daggs@gmx.com> Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
[...]
lsscsi system has no /proc/scsi, thus no output. will this help? lrwxrwxrwx 1 root root 0 Oct 19 13:08 /sys/bus/scsi/devices/host0 -> ../../../devices/pci0000:00/0000:00:1f.2/ata1/host0 lrwxrwxrwx 1 root root 0 Oct 19 13:08 /sys/bus/scsi/devices/host1 -> ../../../devices/pci0000:00/0000:00:1f.2/ata2/host1 lrwxrwxrwx 1 root root 0 Oct 19 13:08 /sys/bus/scsi/devices/host2 -> ../../../devices/pci0000:00/0000:00:1f.2/ata3/host2 lrwxrwxrwx 1 root root 0 Oct 19 13:08 /sys/bus/scsi/devices/host3 -> ../../../devices/pci0000:00/0000:00:1f.2/ata4/host3 lrwxrwxrwx 1 root root 0 Oct 19 13:08 /sys/bus/scsi/devices/host4 -> ../../../devices/pci0000:00/0000:00:1f.2/ata5/host4 lrwxrwxrwx 1 root root 0 Oct 19 13:08 /sys/bus/scsi/devices/host5 -> ../../../devices/pci0000:00/0000:00:1f.2/ata6/host5
try 'ls -lia /sys/bus/scsi/devices' that has all the data

Greetings Peter,
Sent: Tuesday, October 20, 2020 at 3:00 PM From: "Peter Krempa" <pkrempa@redhat.com> To: "daggs" <daggs@gmx.com> Cc: libvir-list@redhat.com Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
[...]
try 'ls -lia /sys/bus/scsi/devices' that has all the data
$ ls -lia /sys/bus/scsi/devices total 0 7017 drwxr-xr-x 2 root root 0 Oct 20 11:11 . 7015 drwxr-xr-x 4 root root 0 Oct 20 11:11 .. 17968 lrwxrwxrwx 1 root root 0 Oct 20 11:11 host0 -> ../../../devices/pci0000:00/0000:00:1f.2/ata1/host0 18016 lrwxrwxrwx 1 root root 0 Oct 20 11:11 host1 -> ../../../devices/pci0000:00/0000:00:1f.2/ata2/host1 18064 lrwxrwxrwx 1 root root 0 Oct 20 11:11 host2 -> ../../../devices/pci0000:00/0000:00:1f.2/ata3/host2 18112 lrwxrwxrwx 1 root root 0 Oct 20 11:11 host3 -> ../../../devices/pci0000:00/0000:00:1f.2/ata4/host3 18160 lrwxrwxrwx 1 root root 0 Oct 20 11:11 host4 -> ../../../devices/pci0000:00/0000:00:1f.2/ata5/host4 18208 lrwxrwxrwx 1 root root 0 Oct 20 11:11 host5 -> ../../../devices/pci0000:00/0000:00:1f.2/ata6/host5 Dagg.

On Tue, Oct 20, 2020 at 14:10:12 +0200, daggs wrote:
Greetings Peter,
Sent: Tuesday, October 20, 2020 at 3:00 PM From: "Peter Krempa" <pkrempa@redhat.com> To: "daggs" <daggs@gmx.com> Cc: libvir-list@redhat.com Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
[...]
try 'ls -lia /sys/bus/scsi/devices' that has all the data
$ ls -lia /sys/bus/scsi/devices total 0 7017 drwxr-xr-x 2 root root 0 Oct 20 11:11 . 7015 drwxr-xr-x 4 root root 0 Oct 20 11:11 .. 17968 lrwxrwxrwx 1 root root 0 Oct 20 11:11 host0 -> ../../../devices/pci0000:00/0000:00:1f.2/ata1/host0 18016 lrwxrwxrwx 1 root root 0 Oct 20 11:11 host1 -> ../../../devices/pci0000:00/0000:00:1f.2/ata2/host1 18064 lrwxrwxrwx 1 root root 0 Oct 20 11:11 host2 -> ../../../devices/pci0000:00/0000:00:1f.2/ata3/host2 18112 lrwxrwxrwx 1 root root 0 Oct 20 11:11 host3 -> ../../../devices/pci0000:00/0000:00:1f.2/ata4/host3 18160 lrwxrwxrwx 1 root root 0 Oct 20 11:11 host4 -> ../../../devices/pci0000:00/0000:00:1f.2/ata5/host4 18208 lrwxrwxrwx 1 root root 0 Oct 20 11:11 host5 -> ../../../devices/pci0000:00/0000:00:1f.2/ata6/host5
Oh, so your guest OS doesn't seem to recognize virtio-scsi apparently! On my test VM I've got the following: $ ls -lia /sys/bus/scsi/devices total 0 5659 drwxr-xr-x. 2 root root 0 Oct 19 17:34 . 5657 drwxr-xr-x. 4 root root 0 Oct 19 17:34 .. 18418 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 0:0:0:0 -> ../../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0 20322 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 6:0:0:1 -> ../../../devices/pci0000:00/0000:00:02.7/0000:08:00.0/virtio6/host6/target6:0:0/6:0:0:1 19773 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 6:0:0:3 -> ../../../devices/pci0000:00/0000:00:02.7/0000:08:00.0/virtio6/host6/target6:0:0/6:0:0:3 15523 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host0 -> ../../../devices/pci0000:00/0000:00:1f.2/ata1/host0 15571 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host1 -> ../../../devices/pci0000:00/0000:00:1f.2/ata2/host1 15619 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host2 -> ../../../devices/pci0000:00/0000:00:1f.2/ata3/host2 15667 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host3 -> ../../../devices/pci0000:00/0000:00:1f.2/ata4/host3 15715 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host4 -> ../../../devices/pci0000:00/0000:00:1f.2/ata5/host4 15763 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host5 -> ../../../devices/pci0000:00/0000:00:1f.2/ata6/host5 19403 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host6 -> ../../../devices/pci0000:00/0000:00:02.7/0000:08:00.0/virtio6/host6 18376 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 target0:0:0 -> ../../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0 19733 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 target6:0:0 -> ../../../devices/pci0000:00/0000:00:02.7/0000:08:00.0/virtio6/host6/target6:0:0 You can see that host6 is a virtio-scsi controller and it has targets. You need to figure out why your guest doesn't have the driver. Alternative would be to use a different scsi controller model, but any emulated will result in overhead, so the best solution will be to get drivers. Sorry I've mislead you with the initial red herring, but your report really came after I've modified how we do hostdevs so I thought I messed up something.

Greetings Peter,
Sent: Tuesday, October 20, 2020 at 3:22 PM From: "Peter Krempa" <pkrempa@redhat.com> To: "daggs" <daggs@gmx.com> Cc: libvir-list@redhat.com Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
Oh, so your guest OS doesn't seem to recognize virtio-scsi apparently!
On my test VM I've got the following:
$ ls -lia /sys/bus/scsi/devices total 0 5659 drwxr-xr-x. 2 root root 0 Oct 19 17:34 . 5657 drwxr-xr-x. 4 root root 0 Oct 19 17:34 .. 18418 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 0:0:0:0 -> ../../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0 20322 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 6:0:0:1 -> ../../../devices/pci0000:00/0000:00:02.7/0000:08:00.0/virtio6/host6/target6:0:0/6:0:0:1 19773 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 6:0:0:3 -> ../../../devices/pci0000:00/0000:00:02.7/0000:08:00.0/virtio6/host6/target6:0:0/6:0:0:3 15523 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host0 -> ../../../devices/pci0000:00/0000:00:1f.2/ata1/host0 15571 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host1 -> ../../../devices/pci0000:00/0000:00:1f.2/ata2/host1 15619 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host2 -> ../../../devices/pci0000:00/0000:00:1f.2/ata3/host2 15667 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host3 -> ../../../devices/pci0000:00/0000:00:1f.2/ata4/host3 15715 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host4 -> ../../../devices/pci0000:00/0000:00:1f.2/ata5/host4 15763 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host5 -> ../../../devices/pci0000:00/0000:00:1f.2/ata6/host5 19403 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 host6 -> ../../../devices/pci0000:00/0000:00:02.7/0000:08:00.0/virtio6/host6 18376 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 target0:0:0 -> ../../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0 19733 lrwxrwxrwx. 1 root root 0 Oct 19 17:34 target6:0:0 -> ../../../devices/pci0000:00/0000:00:02.7/0000:08:00.0/virtio6/host6/target6:0:0
You can see that host6 is a virtio-scsi controller and it has targets.
You need to figure out why your guest doesn't have the driver. Alternative would be to use a different scsi controller model, but any emulated will result in overhead, so the best solution will be to get drivers.
Sorry I've mislead you with the initial red herring, but your report really came after I've modified how we do hostdevs so I thought I messed up something.
that might consistent with the fact that I had to use e1000e for the nic because virtio didn't worked as should. the docs states the model one of 'auto', 'buslogic', 'ibmvscsi', 'lsilogic', 'lsisas1068', 'lsisas1078', 'virtio-scsi', 'vmpvscsi', 'virtio-transitional', 'virtio-non-transitional'. any recommendation on which to use? DAgg.

Greetings Peter,
Sent: Tuesday, October 20, 2020 at 3:39 PM From: "daggs" <daggs@gmx.com> To: "Peter Krempa" <pkrempa@redhat.com> Cc: libvir-list@redhat.com Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
Greetings Peter,
that might consistent with the fact that I had to use e1000e for the nic because virtio didn't worked as should. the docs states the model one of 'auto', 'buslogic', 'ibmvscsi', 'lsilogic', 'lsisas1068', 'lsisas1078', 'virtio-scsi', 'vmpvscsi', 'virtio-transitional', 'virtio-non-transitional'. any recommendation on which to use?
DAgg.
so apparently, the os I'm using in the vm comes with scsi virtio disabled in the kernel... will rebuild the os and report. thanks for all your work. Dagg.

Greetings Peter,
Sent: Tuesday, October 20, 2020 at 2:54 PM From: "daggs" <daggs@gmx.com> To: "daggs" <daggs@gmx.com> Cc: "Peter Krempa" <pkrempa@redhat.com>, libvir-list@redhat.com Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
Greetings Peter,
so apparently, the os I'm using in the vm comes with scsi virtio disabled in the kernel... will rebuild the os and report.
thanks for all your work.
Dagg.
I've built the os with scsi virtio, now I do see the cdrom, see: # ls -lia /sys/bus/scsi/devices total 0 7017 drwxr-xr-x 2 root root 0 Oct 22 2020 . 7015 drwxr-xr-x 4 root root 0 Oct 22 2020 .. 18874 lrwxrwxrwx 1 root root 0 Oct 22 2020 0:0:0:0 -> ../../../devices/pci0000:00/0000:00:1e.0/0000:06:00.0/0000:07:01.0/virtio2/host0/target0:0:0/0:0:0:0 17468 lrwxrwxrwx 1 root root 0 Oct 22 2020 host0 -> ../../../devices/pci0000:00/0000:00:1e.0/0000:06:00.0/0000:07:01.0/virtio2/host0 18051 lrwxrwxrwx 1 root root 0 Oct 22 2020 host1 -> ../../../devices/pci0000:00/0000:00:1f.2/ata1/host1 18099 lrwxrwxrwx 1 root root 0 Oct 22 2020 host2 -> ../../../devices/pci0000:00/0000:00:1f.2/ata2/host2 18147 lrwxrwxrwx 1 root root 0 Oct 22 2020 host3 -> ../../../devices/pci0000:00/0000:00:1f.2/ata3/host3 18195 lrwxrwxrwx 1 root root 0 Oct 22 2020 host4 -> ../../../devices/pci0000:00/0000:00:1f.2/ata4/host4 18243 lrwxrwxrwx 1 root root 0 Oct 22 2020 host5 -> ../../../devices/pci0000:00/0000:00:1f.2/ata5/host5 18291 lrwxrwxrwx 1 root root 0 Oct 22 2020 host6 -> ../../../devices/pci0000:00/0000:00:1f.2/ata6/host6 18835 lrwxrwxrwx 1 root root 0 Oct 22 2020 target0:0:0 -> ../../../devices/pci0000:00/0000:00:1e.0/0000:06:00.0/0000:07:01.0/virtio2/host0/target0:0:0 I've tested with 6.7.0 and 6.8.0 + your patchset, in both the cdrom is visible, in 6.7.0, the guest's dmesg is filled with theses errors: [ 57.510366] sr 0:0:0:0: ioctl_internal_command return code = 8000002 [ 57.510400] sr 0:0:0:0: Sense Key : 0xb [current] [ 57.510403] sr 0:0:0:0: ASC=0x0 ASCQ=0x6 every few seconds these lines are added to the log. with 6.8.0 + your patchset, I see these outputs only few times in the boot process. here is the dmesg: https://dpaste.com/F32A9B92H I've inserted a audio cd and expected the os ui to detected it but it didn't. I assume there is another bug there. anything I can do to help hunting this bug? Thanks. Dagg.

Greetings Peter,
Sent: Thursday, October 22, 2020 at 8:54 PM From: "daggs" <daggs@gmx.com> To: "Peter Krempa" <pkrempa@redhat.com> Cc: libvir-list@redhat.com Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
Greetings Peter,
I've built the os with scsi virtio, now I do see the cdrom, see: # ls -lia /sys/bus/scsi/devices total 0 7017 drwxr-xr-x 2 root root 0 Oct 22 2020 . 7015 drwxr-xr-x 4 root root 0 Oct 22 2020 .. 18874 lrwxrwxrwx 1 root root 0 Oct 22 2020 0:0:0:0 -> ../../../devices/pci0000:00/0000:00:1e.0/0000:06:00.0/0000:07:01.0/virtio2/host0/target0:0:0/0:0:0:0 17468 lrwxrwxrwx 1 root root 0 Oct 22 2020 host0 -> ../../../devices/pci0000:00/0000:00:1e.0/0000:06:00.0/0000:07:01.0/virtio2/host0 18051 lrwxrwxrwx 1 root root 0 Oct 22 2020 host1 -> ../../../devices/pci0000:00/0000:00:1f.2/ata1/host1 18099 lrwxrwxrwx 1 root root 0 Oct 22 2020 host2 -> ../../../devices/pci0000:00/0000:00:1f.2/ata2/host2 18147 lrwxrwxrwx 1 root root 0 Oct 22 2020 host3 -> ../../../devices/pci0000:00/0000:00:1f.2/ata3/host3 18195 lrwxrwxrwx 1 root root 0 Oct 22 2020 host4 -> ../../../devices/pci0000:00/0000:00:1f.2/ata4/host4 18243 lrwxrwxrwx 1 root root 0 Oct 22 2020 host5 -> ../../../devices/pci0000:00/0000:00:1f.2/ata5/host5 18291 lrwxrwxrwx 1 root root 0 Oct 22 2020 host6 -> ../../../devices/pci0000:00/0000:00:1f.2/ata6/host6 18835 lrwxrwxrwx 1 root root 0 Oct 22 2020 target0:0:0 -> ../../../devices/pci0000:00/0000:00:1e.0/0000:06:00.0/0000:07:01.0/virtio2/host0/target0:0:0
I've tested with 6.7.0 and 6.8.0 + your patchset, in both the cdrom is visible, in 6.7.0, the guest's dmesg is filled with theses errors: [ 57.510366] sr 0:0:0:0: ioctl_internal_command return code = 8000002 [ 57.510400] sr 0:0:0:0: Sense Key : 0xb [current] [ 57.510403] sr 0:0:0:0: ASC=0x0 ASCQ=0x6
every few seconds these lines are added to the log. with 6.8.0 + your patchset, I see these outputs only few times in the boot process. here is the dmesg: https://dpaste.com/F32A9B92H I've inserted a audio cd and expected the os ui to detected it but it didn't. I assume there is another bug there. anything I can do to help hunting this bug?
looks like I was mistaken, I see the same prints in 6.8.0 + your patchset. this means it is not related, so question is, is this a livbirt misconfig or qemu bug? any insights? Thanks, Dagg.

Peter,
Sent: Saturday, October 24, 2020 at 8:28 AM From: "daggs" <daggs@gmx.com> To: "Peter Krempa" <pkrempa@redhat.com> Cc: libvir-list@redhat.com Subject: Re: [PATCH 0/6] qemu: Fix cdrom as SCSI hostdev via -blockdev
Greetings Peter,
looks like I was mistaken, I see the same prints in 6.8.0 + your patchset. this means it is not related, so question is, is this a livbirt misconfig or qemu bug?
any insights?
can you comment on the below please? I think it is an qemu bug Dagg.

On 10/15/20 5:25 PM, Peter Krempa wrote:
-drive detects whether a device is a cdrom automatically but we need to use 'host_cdrom' when using blockdev explicitly. Fix the hostdev code which was recently converted to -blockdev.
Warning:
I _don't_ have a box with a CDROM handy so this code is not tested in action!
Peter Krempa (6): qemuProcessCreatePretendCmd: Split up preparation and command building qemu: hostdev: Prepare definition bits in qemuDomainPrepareHostdev qemu: Prepare hostdev data which depends on the host state separately qemuxml2argvmock: Remove mocking of 'virSCSIDeviceGetSgName' qemu: Detect whether a SCSI hostdev is a cdrom qemu: Add test cases for 'host_cdrom' blockdev backend via <disk>
src/qemu/qemu_command.c | 33 +----- src/qemu/qemu_domain.c | 5 + src/qemu/qemu_driver.c | 65 ++++++++++- src/qemu/qemu_hotplug.c | 3 + src/qemu/qemu_process.c | 103 +++++++++++++++--- src/qemu/qemu_process.h | 21 ++-- tests/qemuxml2argvdata/disk-cdrom.args | 4 +- .../disk-cdrom.x86_64-2.12.0.args | 4 +- .../disk-cdrom.x86_64-latest.args | 6 +- tests/qemuxml2argvdata/disk-cdrom.xml | 5 +- ...hostdev-scsi-virtio-scsi.x86_64-2.8.0.args | 3 + ...hostdev-scsi-virtio-scsi.x86_64-4.1.0.args | 3 + ...ostdev-scsi-virtio-scsi.x86_64-latest.args | 4 + .../hostdev-scsi-virtio-scsi.xml | 8 ++ tests/qemuxml2argvmock.c | 13 --- tests/qemuxml2argvtest.c | 45 +++++++- tests/qemuxml2xmloutdata/disk-cdrom.xml | 5 +- .../hostdev-scsi-virtio-scsi.xml | 8 ++ 18 files changed, 252 insertions(+), 86 deletions(-)
To patches 1-4: Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (4)
-
daggs
-
Han Han
-
Michal Prívozník
-
Peter Krempa