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>
Reviewed-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Tested-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
This commit is contained in:
Stefan Berger 2013-04-12 16:55:46 -04:00 committed by Stefan Berger
parent 2c9a063973
commit 22feb0d3e7

View File

@ -130,6 +130,31 @@ int qemuTeardownDiskCgroup(virDomainObjPtr vm,
&data); &data);
} }
static int
qemuSetupChrSourceCgroup(virDomainDefPtr def,
virDomainChrSourceDefPtr dev,
qemuCgroupData *data)
{
int rc;
if (dev->type != VIR_DOMAIN_CHR_TYPE_DEV)
return 0;
VIR_DEBUG("Process path '%s' for device", dev->data.file.path);
rc = virCgroupAllowDevicePath(data->cgroup, dev->data.file.path,
VIR_CGROUP_DEVICE_RW);
virDomainAuditCgroupPath(data->vm, data->cgroup, "allow",
dev->data.file.path, "rw", rc);
if (rc < 0) {
virReportSystemError(-rc,
_("Unable to allow device %s for %s"),
dev->data.file.path, def->name);
return -1;
}
return 0;
}
static int static int
qemuSetupChardevCgroup(virDomainDefPtr def, qemuSetupChardevCgroup(virDomainDefPtr def,
@ -137,25 +162,28 @@ qemuSetupChardevCgroup(virDomainDefPtr def,
void *opaque) void *opaque)
{ {
qemuCgroupData *data = opaque; qemuCgroupData *data = opaque;
int rc;
if (dev->source.type != VIR_DOMAIN_CHR_TYPE_DEV) return qemuSetupChrSourceCgroup(def, &dev->source, data);
return 0; }
VIR_DEBUG("Process path '%s' for disk", dev->source.data.file.path); static int
rc = virCgroupAllowDevicePath(data->cgroup, dev->source.data.file.path, qemuSetupTPMCgroup(virDomainDefPtr def,
VIR_CGROUP_DEVICE_RW); virDomainTPMDefPtr dev,
virDomainAuditCgroupPath(data->vm, data->cgroup, "allow", qemuCgroupData *data)
dev->source.data.file.path, "rw", rc); {
if (rc < 0) { int rc = 0;
virReportSystemError(-rc,
_("Unable to allow device %s for %s"), switch (dev->type) {
dev->source.data.file.path, def->name); case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
return -1; rc = qemuSetupChrSourceCgroup(def, &dev->data.passthrough.source,
data);
break;
case VIR_DOMAIN_TPM_TYPE_LAST:
break;
} }
return 0; return rc;
} }
@ -275,6 +303,11 @@ int qemuSetupCgroup(virQEMUDriverPtr driver,
&data) < 0) &data) < 0)
goto cleanup; goto cleanup;
if (vm->def->tpm)
qemuSetupTPMCgroup(vm->def,
vm->def->tpm,
&data);
for (i = 0; i < vm->def->nhostdevs; i++) { for (i = 0; i < vm->def->nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i]; virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i];
virUSBDevicePtr usb; virUSBDevicePtr usb;