From d5e4790ea5bb422fb12663362825e31b7350e6ec Mon Sep 17 00:00:00 2001 Message-Id: From: John Ferlan Date: Fri, 19 Sep 2014 08:32:38 -0400 Subject: [PATCH] qemu: Process the hostdev "rawio" setting https://bugzilla.redhat.com/show_bug.cgi?id=1103739 Mimic the "Disk" processing for 'rawio', but for a scsi_host hostdev lun device. (cherry picked from commit 74eaa0918b7fa612e534bd7ddb2c6aac436fc50c) Signed-off-by: John Ferlan Signed-off-by: Jiri Denemark --- src/qemu/qemu_domain.c | 18 ++++++++++++++++++ src/qemu/qemu_domain.h | 4 ++++ src/qemu/qemu_driver.c | 1 + src/qemu/qemu_process.c | 20 ++++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9b3edd7..746625a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1944,6 +1944,10 @@ void qemuDomainObjCheckTaint(virQEMUDriverPtr driver, for (i = 0; i < obj->def->ndisks; i++) qemuDomainObjCheckDiskTaint(driver, obj, obj->def->disks[i], logFD); + for (i = 0; i < obj->def->nhostdevs; i++) + qemuDomainObjCheckHostdevTaint(driver, obj, obj->def->hostdevs[i], + logFD); + for (i = 0; i < obj->def->nnets; i++) qemuDomainObjCheckNetTaint(driver, obj, obj->def->nets[i], logFD); @@ -1970,6 +1974,20 @@ void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver, } +void qemuDomainObjCheckHostdevTaint(virQEMUDriverPtr driver, + virDomainObjPtr obj, + virDomainHostdevDefPtr hostdev, + int logFD) +{ + virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi; + + if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI && + scsisrc->rawio == VIR_TRISTATE_BOOL_YES) + qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES, + logFD); +} + + void qemuDomainObjCheckNetTaint(virQEMUDriverPtr driver, virDomainObjPtr obj, virDomainNetDefPtr net, diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 4ae2c57..d21acd7 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -301,6 +301,10 @@ void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver, virDomainObjPtr obj, virDomainDiskDefPtr disk, int logFD); +void qemuDomainObjCheckHostdevTaint(virQEMUDriverPtr driver, + virDomainObjPtr obj, + virDomainHostdevDefPtr disk, + int logFD); void qemuDomainObjCheckNetTaint(virQEMUDriverPtr driver, virDomainObjPtr obj, virDomainNetDefPtr net, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 808d35f..6629946 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6684,6 +6684,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, break; case VIR_DOMAIN_DEVICE_HOSTDEV: + qemuDomainObjCheckHostdevTaint(driver, vm, dev->data.hostdev, -1); ret = qemuDomainAttachHostDevice(dom->conn, driver, vm, dev->data.hostdev); if (!ret) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 528b6eb..5c3b3c8 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3981,6 +3981,7 @@ int qemuProcessStart(virConnectPtr conn, struct qemuProcessHookData hookData; unsigned long cur_balloon; size_t i; + bool rawio_set = false; char *nodeset = NULL; virBitmapPtr nodemask = NULL; unsigned int stop_flags; @@ -4358,6 +4359,7 @@ int qemuProcessStart(virConnectPtr conn, if (vm->def->disks[i]->rawio == 1) { #ifdef CAP_SYS_RAWIO virCommandAllowCap(cmd, CAP_SYS_RAWIO); + rawio_set = true; #else virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Raw I/O is not supported on this platform")); @@ -4374,6 +4376,24 @@ int qemuProcessStart(virConnectPtr conn, goto cleanup; } + /* If rawio not already set, check hostdevs as well */ + if (!rawio_set) { + for (i = 0; i < vm->def->nhostdevs; i++) { + virDomainHostdevSubsysSCSIPtr scsisrc = + &vm->def->hostdevs[i]->source.subsys.u.scsi; + if (scsisrc->rawio == VIR_TRISTATE_BOOL_YES) { +#ifdef CAP_SYS_RAWIO + virCommandAllowCap(cmd, CAP_SYS_RAWIO); + break; +#else + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Raw I/O is not supported on this platform")); + goto cleanup; +#endif + } + } + } + virCommandSetPreExecHook(cmd, qemuProcessHook, &hookData); virCommandSetMaxProcesses(cmd, cfg->maxProcesses); virCommandSetMaxFiles(cmd, cfg->maxFiles); -- 2.1.1