render / rpms / libvirt

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