render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
0a7476
From a69ce7395989807eefad14ff7c66540d621bd303 Mon Sep 17 00:00:00 2001
0a7476
Message-Id: <a69ce7395989807eefad14ff7c66540d621bd303@dist-git>
0a7476
From: Laine Stump <laine@laine.org>
0a7476
Date: Thu, 11 Apr 2019 15:14:49 -0400
0a7476
Subject: [PATCH] qemu_hotplug: new function qemuDomainRemoveAuditDevice()
0a7476
0a7476
This function can be called with a virDomainDevicePtr and whether or
0a7476
not the removal was successful, and it will call the appropriate
0a7476
virDomainAudit*() function with the appropriate args for whatever type
0a7476
of device it's given (or do nothing, if that's appropriate). This
0a7476
permits generalizing some code that currently has a separate copy for
0a7476
each type of device.
0a7476
0a7476
NB: Although the function initially will be called only with
0a7476
success=false, that has been made an argument so that in the future
0a7476
(when the qemuDomainRemove*Device() functions have had their common
0a7476
functionality consolidated into qemuDomainRemoveDevice()), this new
0a7476
common code can call qemuDomainRemoveAuditDevice() for all types.
0a7476
0a7476
Signed-off-by: Laine Stump <laine@laine.org>
0a7476
ACKed-by: Peter Krempa <pkrempa@redhat.com>
0a7476
(cherry picked from commit b914e0eca385b52ede39b1b046bc9bf7a4fbbc2a)
0a7476
0a7476
Partially-Resolves: https://bugzilla.redhat.com/1658198
0a7476
Signed-off-by: Laine Stump <laine@redhat.com>
0a7476
Signed-off-by: Laine Stump <laine@laine.org>
0a7476
Message-Id: <20190411191453.24055-38-laine@redhat.com>
0a7476
Acked-by: Michal Privoznik <mprivozn@redhat.com>
0a7476
---
0a7476
 src/qemu/qemu_hotplug.c | 55 +++++++++++++++++++++++++++++++++++++++++
0a7476
 1 file changed, 55 insertions(+)
0a7476
0a7476
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
0a7476
index dea881fd0b..482111c46e 100644
0a7476
--- a/src/qemu/qemu_hotplug.c
0a7476
+++ b/src/qemu/qemu_hotplug.c
0a7476
@@ -4650,6 +4650,61 @@ qemuDomainRemoveRedirdevDevice(virQEMUDriverPtr driver,
0a7476
 }
0a7476
 
0a7476
 
0a7476
+static void ATTRIBUTE_UNUSED
0a7476
+qemuDomainRemoveAuditDevice(virDomainObjPtr vm,
0a7476
+                            virDomainDeviceDefPtr detach,
0a7476
+                            bool success)
0a7476
+{
0a7476
+    switch ((virDomainDeviceType)detach->type) {
0a7476
+    case VIR_DOMAIN_DEVICE_DISK:
0a7476
+        virDomainAuditDisk(vm, detach->data.disk->src, NULL, "detach", success);
0a7476
+        break;
0a7476
+    case VIR_DOMAIN_DEVICE_NET:
0a7476
+        virDomainAuditNet(vm, detach->data.net, NULL, "detach", success);
0a7476
+        break;
0a7476
+    case VIR_DOMAIN_DEVICE_HOSTDEV:
0a7476
+        virDomainAuditHostdev(vm, detach->data.hostdev, "detach", success);
0a7476
+        break;
0a7476
+
0a7476
+    case VIR_DOMAIN_DEVICE_INPUT:
0a7476
+    case VIR_DOMAIN_DEVICE_CHR:
0a7476
+    case VIR_DOMAIN_DEVICE_RNG:
0a7476
+    case VIR_DOMAIN_DEVICE_MEMORY:
0a7476
+    case VIR_DOMAIN_DEVICE_SHMEM:
0a7476
+    case VIR_DOMAIN_DEVICE_REDIRDEV:
0a7476
+       /*
0a7476
+        * These devices are supposed to be audited, but current code
0a7476
+        * doesn't audit on failure to remove the device.
0a7476
+        */
0a7476
+       break;
0a7476
+
0a7476
+
0a7476
+    case VIR_DOMAIN_DEVICE_LEASE:
0a7476
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
0a7476
+    case VIR_DOMAIN_DEVICE_WATCHDOG:
0a7476
+    case VIR_DOMAIN_DEVICE_VSOCK:
0a7476
+        /* These devices don't have associated audit logs */
0a7476
+        break;
0a7476
+
0a7476
+    case VIR_DOMAIN_DEVICE_FS:
0a7476
+    case VIR_DOMAIN_DEVICE_SOUND:
0a7476
+    case VIR_DOMAIN_DEVICE_VIDEO:
0a7476
+    case VIR_DOMAIN_DEVICE_GRAPHICS:
0a7476
+    case VIR_DOMAIN_DEVICE_HUB:
0a7476
+    case VIR_DOMAIN_DEVICE_SMARTCARD:
0a7476
+    case VIR_DOMAIN_DEVICE_MEMBALLOON:
0a7476
+    case VIR_DOMAIN_DEVICE_NVRAM:
0a7476
+    case VIR_DOMAIN_DEVICE_NONE:
0a7476
+    case VIR_DOMAIN_DEVICE_TPM:
0a7476
+    case VIR_DOMAIN_DEVICE_PANIC:
0a7476
+    case VIR_DOMAIN_DEVICE_IOMMU:
0a7476
+    case VIR_DOMAIN_DEVICE_LAST:
0a7476
+        /* libvirt doesn't yet support detaching these devices */
0a7476
+        break;
0a7476
+    }
0a7476
+}
0a7476
+
0a7476
+
0a7476
 int
0a7476
 qemuDomainRemoveDevice(virQEMUDriverPtr driver,
0a7476
                        virDomainObjPtr vm,
0a7476
-- 
0a7476
2.21.0
0a7476