|
|
404507 |
From 1cc1a4e1c069571d0db11848a5949da143c76166 Mon Sep 17 00:00:00 2001
|
|
|
404507 |
Message-Id: <1cc1a4e1c069571d0db11848a5949da143c76166@dist-git>
|
|
|
404507 |
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
|
|
|
404507 |
Date: Mon, 27 Nov 2017 14:21:02 +0100
|
|
|
404507 |
Subject: [PATCH] qemu: Properly label and create evdev on input device hotplug
|
|
|
404507 |
MIME-Version: 1.0
|
|
|
404507 |
Content-Type: text/plain; charset=UTF-8
|
|
|
404507 |
Content-Transfer-Encoding: 8bit
|
|
|
404507 |
|
|
|
404507 |
Utilize all the newly introduced function to create the evdev node
|
|
|
404507 |
and label it on hotplug and destroy it on hotunplug.
|
|
|
404507 |
|
|
|
404507 |
This was forgotten in commits bc9ffaf and 67486bb.
|
|
|
404507 |
|
|
|
404507 |
https://bugzilla.redhat.com/show_bug.cgi?id=1509866
|
|
|
404507 |
(cherry picked from commit 2814f66f281064477815065bf3ddc5f5cec82062)
|
|
|
404507 |
Signed-off-by: Ján Tomko <jtomko@redhat.com>
|
|
|
404507 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
404507 |
---
|
|
|
404507 |
src/qemu/qemu_hotplug.c | 40 +++++++++++++++++++++++++++++++++++++---
|
|
|
404507 |
1 file changed, 37 insertions(+), 3 deletions(-)
|
|
|
404507 |
|
|
|
404507 |
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
|
|
|
404507 |
index edf07d0b65..56e8a93885 100644
|
|
|
404507 |
--- a/src/qemu/qemu_hotplug.c
|
|
|
404507 |
+++ b/src/qemu/qemu_hotplug.c
|
|
|
404507 |
@@ -2746,7 +2746,11 @@ qemuDomainAttachInputDevice(virQEMUDriverPtr driver,
|
|
|
404507 |
qemuDomainObjPrivatePtr priv = vm->privateData;
|
|
|
404507 |
virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_INPUT,
|
|
|
404507 |
{ .input = input } };
|
|
|
404507 |
+ virErrorPtr originalError = NULL;
|
|
|
404507 |
bool releaseaddr = false;
|
|
|
404507 |
+ bool teardowndevice = false;
|
|
|
404507 |
+ bool teardownlabel = false;
|
|
|
404507 |
+ bool teardowncgroup = false;
|
|
|
404507 |
|
|
|
404507 |
if (input->bus != VIR_DOMAIN_INPUT_BUS_USB &&
|
|
|
404507 |
input->bus != VIR_DOMAIN_INPUT_BUS_VIRTIO) {
|
|
|
404507 |
@@ -2773,6 +2777,18 @@ qemuDomainAttachInputDevice(virQEMUDriverPtr driver,
|
|
|
404507 |
if (qemuBuildInputDevStr(&devstr, vm->def, input, priv->qemuCaps) < 0)
|
|
|
404507 |
goto cleanup;
|
|
|
404507 |
|
|
|
404507 |
+ if (qemuDomainNamespaceSetupInput(vm, input) < 0)
|
|
|
404507 |
+ goto cleanup;
|
|
|
404507 |
+ teardowndevice = true;
|
|
|
404507 |
+
|
|
|
404507 |
+ if (qemuSetupInputCgroup(vm, input) < 0)
|
|
|
404507 |
+ goto cleanup;
|
|
|
404507 |
+ teardowncgroup = true;
|
|
|
404507 |
+
|
|
|
404507 |
+ if (qemuSecuritySetInputLabel(vm, input) < 0)
|
|
|
404507 |
+ goto cleanup;
|
|
|
404507 |
+ teardownlabel = true;
|
|
|
404507 |
+
|
|
|
404507 |
if (VIR_REALLOC_N(vm->def->inputs, vm->def->ninputs + 1) < 0)
|
|
|
404507 |
goto cleanup;
|
|
|
404507 |
|
|
|
404507 |
@@ -2788,14 +2804,23 @@ qemuDomainAttachInputDevice(virQEMUDriverPtr driver,
|
|
|
404507 |
VIR_APPEND_ELEMENT_COPY_INPLACE(vm->def->inputs, vm->def->ninputs, input);
|
|
|
404507 |
|
|
|
404507 |
ret = 0;
|
|
|
404507 |
- releaseaddr = false;
|
|
|
404507 |
|
|
|
404507 |
audit:
|
|
|
404507 |
virDomainAuditInput(vm, input, "attach", ret == 0);
|
|
|
404507 |
|
|
|
404507 |
cleanup:
|
|
|
404507 |
- if (releaseaddr)
|
|
|
404507 |
- qemuDomainReleaseDeviceAddress(vm, &input->info, NULL);
|
|
|
404507 |
+ if (ret < 0) {
|
|
|
404507 |
+ virErrorPreserveLast(&originalError);
|
|
|
404507 |
+ if (teardownlabel)
|
|
|
404507 |
+ qemuSecurityRestoreInputLabel(vm, input);
|
|
|
404507 |
+ if (teardowncgroup)
|
|
|
404507 |
+ qemuTeardownInputCgroup(vm, input);
|
|
|
404507 |
+ if (teardowndevice)
|
|
|
404507 |
+ qemuDomainNamespaceTeardownInput(vm, input);
|
|
|
404507 |
+ if (releaseaddr)
|
|
|
404507 |
+ qemuDomainReleaseDeviceAddress(vm, &input->info, NULL);
|
|
|
404507 |
+ virErrorRestore(&originalError);
|
|
|
404507 |
+ }
|
|
|
404507 |
|
|
|
404507 |
VIR_FREE(devstr);
|
|
|
404507 |
return ret;
|
|
|
404507 |
@@ -4283,6 +4308,15 @@ qemuDomainRemoveInputDevice(virDomainObjPtr vm,
|
|
|
404507 |
break;
|
|
|
404507 |
}
|
|
|
404507 |
qemuDomainReleaseDeviceAddress(vm, &dev->info, NULL);
|
|
|
404507 |
+ if (qemuSecurityRestoreInputLabel(vm, dev) < 0)
|
|
|
404507 |
+ VIR_WARN("Unable to restore security label on input device");
|
|
|
404507 |
+
|
|
|
404507 |
+ if (qemuTeardownInputCgroup(vm, dev) < 0)
|
|
|
404507 |
+ VIR_WARN("Unable to remove input device cgroup ACL");
|
|
|
404507 |
+
|
|
|
404507 |
+ if (qemuDomainNamespaceTeardownInput(vm, dev) < 0)
|
|
|
404507 |
+ VIR_WARN("Unable to remove input device from /dev");
|
|
|
404507 |
+
|
|
|
404507 |
virDomainInputDefFree(vm->def->inputs[i]);
|
|
|
404507 |
VIR_DELETE_ELEMENT(vm->def->inputs, i, vm->def->ninputs);
|
|
|
404507 |
return 0;
|
|
|
404507 |
--
|
|
|
404507 |
2.15.1
|
|
|
404507 |
|