[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v3 09/11] QEMU Cgroup support for TPM passthrough



Some refactoring for virDomainChrSourceDef type of devices so
we can use common code.

Signed-off-by: Stefan Berger <stefanb linux vnet ibm com>

---
 src/qemu/qemu_cgroup.c |   53 +++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 43 insertions(+), 10 deletions(-)

Index: libvirt/src/qemu/qemu_cgroup.c
===================================================================
--- libvirt.orig/src/qemu/qemu_cgroup.c
+++ libvirt/src/qemu/qemu_cgroup.c
@@ -144,34 +144,62 @@ int qemuTeardownDiskCgroup(virDomainObjP
                                        &data);
 }
 
-
 static int
-qemuSetupChardevCgroup(virDomainDefPtr def,
-                       virDomainChrDefPtr dev,
-                       void *opaque)
+qemuSetupChrSourceCgroup(virDomainDefPtr def,
+                         virDomainChrSourceDefPtr dev,
+                         qemuCgroupData *data)
 {
-    qemuCgroupData *data = opaque;
     int rc;
 
-    if (dev->source.type != VIR_DOMAIN_CHR_TYPE_DEV)
+    if (dev->type != VIR_DOMAIN_CHR_TYPE_DEV)
         return 0;
 
+    VIR_DEBUG("Process path '%s' for device", dev->data.file.path);
 
-    VIR_DEBUG("Process path '%s' for disk", dev->source.data.file.path);
-    rc = virCgroupAllowDevicePath(data->cgroup, dev->source.data.file.path,
+    rc = virCgroupAllowDevicePath(data->cgroup, dev->data.file.path,
                                   VIR_CGROUP_DEVICE_RW);
     virDomainAuditCgroupPath(data->vm, data->cgroup, "allow",
-                             dev->source.data.file.path, "rw", rc);
+                             dev->data.file.path, "rw", rc);
     if (rc < 0) {
         virReportSystemError(-rc,
                              _("Unable to allow device %s for %s"),
-                             dev->source.data.file.path, def->name);
+                             dev->data.file.path, def->name);
         return -1;
     }
 
     return 0;
 }
 
+static int
+qemuSetupChardevCgroup(virDomainDefPtr def,
+                       virDomainChrDefPtr dev,
+                       void *opaque)
+{
+    qemuCgroupData *data = opaque;
+
+    return qemuSetupChrSourceCgroup(def, &dev->source, data);
+}
+
+
+static int
+qemuSetupTPMCgroup(virDomainDefPtr def,
+                   virDomainTPMDefPtr dev,
+                   qemuCgroupData *data)
+{
+    int rc = 0;
+
+    switch (dev->type) {
+    case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
+        rc = qemuSetupChrSourceCgroup(def, &dev->data.passthrough.source,
+                                      data);
+        break;
+    case VIR_DOMAIN_TPM_TYPE_LAST:
+        break;
+    }
+
+    return rc;
+}
+
 
 int qemuSetupHostUsbDeviceCgroup(virUSBDevicePtr dev ATTRIBUTE_UNUSED,
                                  const char *path,
@@ -289,6 +317,11 @@ int qemuSetupCgroup(virQEMUDriverPtr dri
                                    &data) < 0)
             goto cleanup;
 
+        if (vm->def->tpm)
+            qemuSetupTPMCgroup(vm->def,
+                               vm->def->tpm,
+                               &data);
+
         for (i = 0; i < vm->def->nhostdevs; i++) {
             virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i];
             virUSBDevicePtr usb;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]