|
|
c401cc |
From 8af5fddcda3fe76db25ea4172c7f21a9d19178a0 Mon Sep 17 00:00:00 2001
|
|
|
c401cc |
Message-Id: <8af5fddcda3fe76db25ea4172c7f21a9d19178a0.1386932210.git.jdenemar@redhat.com>
|
|
|
c401cc |
From: Cole Robinson <crobinso@redhat.com>
|
|
|
c401cc |
Date: Mon, 9 Dec 2013 20:12:43 +0100
|
|
|
c401cc |
Subject: [PATCH] qemu: hotplug: Only label hostdev after checking device
|
|
|
c401cc |
conflicts
|
|
|
c401cc |
|
|
|
c401cc |
https://bugzilla.redhat.com/show_bug.cgi?id=1025108
|
|
|
c401cc |
|
|
|
c401cc |
Similar to what Jiri did for cgroup setup/teardown in 05e149f94, push
|
|
|
c401cc |
it all into the device handler functions so we can do the necessary prep
|
|
|
c401cc |
work before claiming the device.
|
|
|
c401cc |
|
|
|
c401cc |
This also fixes hotplugging USB devices by product/vendor (virt-manager's
|
|
|
c401cc |
default behavior):
|
|
|
c401cc |
|
|
|
c401cc |
https://bugzilla.redhat.com/show_bug.cgi?id=1016511
|
|
|
c401cc |
(cherry picked from commit ee414b5d6d1601bde8440a9de050c02447bbd3bf)
|
|
|
c401cc |
|
|
|
c401cc |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
c401cc |
---
|
|
|
c401cc |
src/qemu/qemu_hotplug.c | 42 ++++++++++++++++++++++++++++++++++--------
|
|
|
c401cc |
1 file changed, 34 insertions(+), 8 deletions(-)
|
|
|
c401cc |
|
|
|
c401cc |
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
|
|
|
c401cc |
index a60c08d..f2b6dba 100644
|
|
|
c401cc |
--- a/src/qemu/qemu_hotplug.c
|
|
|
c401cc |
+++ b/src/qemu/qemu_hotplug.c
|
|
|
c401cc |
@@ -1013,6 +1013,7 @@ int qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
|
|
|
c401cc |
char *configfd_name = NULL;
|
|
|
c401cc |
bool releaseaddr = false;
|
|
|
c401cc |
bool teardowncgroup = false;
|
|
|
c401cc |
+ bool teardownlabel = false;
|
|
|
c401cc |
int backend = hostdev->source.subsys.u.pci.backend;
|
|
|
c401cc |
|
|
|
c401cc |
if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0)
|
|
|
c401cc |
@@ -1053,6 +1054,11 @@ int qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
|
|
|
c401cc |
goto error;
|
|
|
c401cc |
teardowncgroup = true;
|
|
|
c401cc |
|
|
|
c401cc |
+ if (virSecurityManagerSetHostdevLabel(driver->securityManager,
|
|
|
c401cc |
+ vm->def, hostdev, NULL) < 0)
|
|
|
c401cc |
+ goto error;
|
|
|
c401cc |
+ teardownlabel = true;
|
|
|
c401cc |
+
|
|
|
c401cc |
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
|
|
|
c401cc |
if (qemuAssignDeviceHostdevAlias(vm->def, hostdev, -1) < 0)
|
|
|
c401cc |
goto error;
|
|
|
c401cc |
@@ -1110,6 +1116,10 @@ int qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
|
|
|
c401cc |
error:
|
|
|
c401cc |
if (teardowncgroup && qemuTeardownHostdevCgroup(vm, hostdev) < 0)
|
|
|
c401cc |
VIR_WARN("Unable to remove host device cgroup ACL on hotplug fail");
|
|
|
c401cc |
+ if (teardownlabel &&
|
|
|
c401cc |
+ virSecurityManagerRestoreHostdevLabel(driver->securityManager,
|
|
|
c401cc |
+ vm->def, hostdev, NULL) < 0)
|
|
|
c401cc |
+ VIR_WARN("Unable to restore host device labelling on hotplug fail");
|
|
|
c401cc |
|
|
|
c401cc |
if (releaseaddr)
|
|
|
c401cc |
qemuDomainReleaseDeviceAddress(vm, hostdev->info, NULL);
|
|
|
c401cc |
@@ -1304,6 +1314,7 @@ int qemuDomainAttachHostUsbDevice(virQEMUDriverPtr driver,
|
|
|
c401cc |
char *devstr = NULL;
|
|
|
c401cc |
bool added = false;
|
|
|
c401cc |
bool teardowncgroup = false;
|
|
|
c401cc |
+ bool teardownlabel = false;
|
|
|
c401cc |
int ret = -1;
|
|
|
c401cc |
|
|
|
c401cc |
if (qemuFindHostdevUSBDevice(hostdev, true, &usb) < 0)
|
|
|
c401cc |
@@ -1325,6 +1336,11 @@ int qemuDomainAttachHostUsbDevice(virQEMUDriverPtr driver,
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
teardowncgroup = true;
|
|
|
c401cc |
|
|
|
c401cc |
+ if (virSecurityManagerSetHostdevLabel(driver->securityManager,
|
|
|
c401cc |
+ vm->def, hostdev, NULL) < 0)
|
|
|
c401cc |
+ goto cleanup;
|
|
|
c401cc |
+ teardownlabel = true;
|
|
|
c401cc |
+
|
|
|
c401cc |
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
|
|
|
c401cc |
if (qemuAssignDeviceHostdevAlias(vm->def, hostdev, -1) < 0)
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
@@ -1351,10 +1367,14 @@ int qemuDomainAttachHostUsbDevice(virQEMUDriverPtr driver,
|
|
|
c401cc |
|
|
|
c401cc |
ret = 0;
|
|
|
c401cc |
cleanup:
|
|
|
c401cc |
- if (ret < 0 &&
|
|
|
c401cc |
- teardowncgroup &&
|
|
|
c401cc |
- qemuTeardownHostdevCgroup(vm, hostdev) < 0)
|
|
|
c401cc |
- VIR_WARN("Unable to remove host device cgroup ACL on hotplug fail");
|
|
|
c401cc |
+ if (ret < 0) {
|
|
|
c401cc |
+ if (teardowncgroup && qemuTeardownHostdevCgroup(vm, hostdev) < 0)
|
|
|
c401cc |
+ VIR_WARN("Unable to remove host device cgroup ACL on hotplug fail");
|
|
|
c401cc |
+ if (teardownlabel &&
|
|
|
c401cc |
+ virSecurityManagerRestoreHostdevLabel(driver->securityManager,
|
|
|
c401cc |
+ vm->def, hostdev, NULL) < 0)
|
|
|
c401cc |
+ VIR_WARN("Unable to restore host device labelling on hotplug fail");
|
|
|
c401cc |
+ }
|
|
|
c401cc |
if (added)
|
|
|
c401cc |
virUSBDeviceListSteal(driver->activeUsbHostdevs, usb);
|
|
|
c401cc |
virUSBDeviceFree(usb);
|
|
|
c401cc |
@@ -1373,6 +1393,7 @@ qemuDomainAttachHostScsiDevice(virQEMUDriverPtr driver,
|
|
|
c401cc |
char *devstr = NULL;
|
|
|
c401cc |
char *drvstr = NULL;
|
|
|
c401cc |
bool teardowncgroup = false;
|
|
|
c401cc |
+ bool teardownlabel = false;
|
|
|
c401cc |
|
|
|
c401cc |
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DRIVE) ||
|
|
|
c401cc |
!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) ||
|
|
|
c401cc |
@@ -1397,6 +1418,11 @@ qemuDomainAttachHostScsiDevice(virQEMUDriverPtr driver,
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
teardowncgroup = true;
|
|
|
c401cc |
|
|
|
c401cc |
+ if (virSecurityManagerSetHostdevLabel(driver->securityManager,
|
|
|
c401cc |
+ vm->def, hostdev, NULL) < 0)
|
|
|
c401cc |
+ goto cleanup;
|
|
|
c401cc |
+ teardownlabel = true;
|
|
|
c401cc |
+
|
|
|
c401cc |
if (qemuAssignDeviceHostdevAlias(vm->def, hostdev, -1) < 0)
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
|
|
|
c401cc |
@@ -1438,6 +1464,10 @@ cleanup:
|
|
|
c401cc |
qemuDomainReAttachHostScsiDevices(driver, vm->def->name, &hostdev, 1);
|
|
|
c401cc |
if (teardowncgroup && qemuTeardownHostdevCgroup(vm, hostdev) < 0)
|
|
|
c401cc |
VIR_WARN("Unable to remove host device cgroup ACL on hotplug fail");
|
|
|
c401cc |
+ if (teardownlabel &&
|
|
|
c401cc |
+ virSecurityManagerRestoreHostdevLabel(driver->securityManager,
|
|
|
c401cc |
+ vm->def, hostdev, NULL) < 0)
|
|
|
c401cc |
+ VIR_WARN("Unable to restore host device labelling on hotplug fail");
|
|
|
c401cc |
}
|
|
|
c401cc |
VIR_FREE(drvstr);
|
|
|
c401cc |
VIR_FREE(devstr);
|
|
|
c401cc |
@@ -1455,10 +1485,6 @@ int qemuDomainAttachHostDevice(virQEMUDriverPtr driver,
|
|
|
c401cc |
return -1;
|
|
|
c401cc |
}
|
|
|
c401cc |
|
|
|
c401cc |
- if (virSecurityManagerSetHostdevLabel(driver->securityManager,
|
|
|
c401cc |
- vm->def, hostdev, NULL) < 0)
|
|
|
c401cc |
- return -1;
|
|
|
c401cc |
-
|
|
|
c401cc |
switch (hostdev->source.subsys.type) {
|
|
|
c401cc |
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
|
|
|
c401cc |
if (qemuDomainAttachHostPciDevice(driver, vm,
|
|
|
c401cc |
--
|
|
|
c401cc |
1.8.5.1
|
|
|
c401cc |
|