Snapshots alter the set of disk image files opened by qemu, so
they must be audited. But they don't involve a full disk definition
structure, just the new filename. Make the next patch easier by
refactoring the audit routines to just operate on file name.
* src/conf/domain_audit.h (virDomainAuditDisk): Update prototype.
* src/conf/domain_audit.c (virDomainAuditDisk): Act on strings,
not definition structures.
(virDomainAuditStart): Update caller.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia)
(qemuDomainAttachPciDiskDevice, qemuDomainAttachSCSIDisk)
(qemuDomainAttachUsbMassstorageDevice)
(qemuDomainDetachPciDiskDevice, qemuDomainDetachDiskDevice):
Likewise.
---
src/conf/domain_audit.c | 12 ++++--------
src/conf/domain_audit.h | 4 ++--
src/qemu/qemu_hotplug.c | 18 +++++++++---------
3 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index 9d89c94..7d3eb5b 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -60,7 +60,7 @@ virDomainAuditGetRdev(const char *path ATTRIBUTE_UNUSED)
void
virDomainAuditDisk(virDomainObjPtr vm,
- virDomainDiskDefPtr oldDef, virDomainDiskDefPtr newDef,
+ const char *oldDef, const char *newDef,
const char *reason, bool success)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -80,15 +80,11 @@ virDomainAuditDisk(virDomainObjPtr vm,
virt = "?";
}
- if (!(oldsrc = virAuditEncode("old-disk",
- oldDef && oldDef->src ?
- oldDef->src : "?"))) {
+ if (!(oldsrc = virAuditEncode("old-disk", VIR_AUDIT_STR(oldDef)))) {
VIR_WARN("OOM while encoding audit message");
goto cleanup;
}
- if (!(newsrc = virAuditEncode("new-disk",
- newDef && newDef->src ?
- newDef->src : "?"))) {
+ if (!(newsrc = virAuditEncode("new-disk", VIR_AUDIT_STR(newDef)))) {
VIR_WARN("OOM while encoding audit message");
goto cleanup;
}
@@ -520,7 +516,7 @@ virDomainAuditStart(virDomainObjPtr vm, const char *reason, bool
success)
for (i = 0 ; i < vm->def->ndisks ; i++) {
virDomainDiskDefPtr disk = vm->def->disks[i];
if (disk->src) /* Skips CDROM without media initially inserted */
- virDomainAuditDisk(vm, NULL, disk, "start", true);
+ virDomainAuditDisk(vm, NULL, disk->src, "start", true);
}
for (i = 0 ; i < vm->def->nfss ; i++) {
diff --git a/src/conf/domain_audit.h b/src/conf/domain_audit.h
index 0e88fd3..da9e257 100644
--- a/src/conf/domain_audit.h
+++ b/src/conf/domain_audit.h
@@ -35,8 +35,8 @@ void virDomainAuditStop(virDomainObjPtr vm,
const char *reason)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
void virDomainAuditDisk(virDomainObjPtr vm,
- virDomainDiskDefPtr oldDef,
- virDomainDiskDefPtr newDef,
+ const char *oldDef,
+ const char *newDef,
const char *reason,
bool success)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index b7fdfa0..cd59283 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -114,7 +114,7 @@ int qemuDomainChangeEjectableMedia(struct qemud_driver *driver,
}
qemuDomainObjExitMonitorWithDriver(driver, vm);
- virDomainAuditDisk(vm, origdisk, disk, "update", ret >= 0);
+ virDomainAuditDisk(vm, origdisk->src, disk->src, "update", ret >=
0);
if (ret < 0)
goto error;
@@ -224,7 +224,7 @@ int qemuDomainAttachPciDiskDevice(struct qemud_driver *driver,
}
qemuDomainObjExitMonitorWithDriver(driver, vm);
- virDomainAuditDisk(vm, NULL, disk, "attach", ret >= 0);
+ virDomainAuditDisk(vm, NULL, disk->src, "attach", ret >= 0);
if (ret < 0)
goto error;
@@ -468,7 +468,7 @@ int qemuDomainAttachSCSIDisk(struct qemud_driver *driver,
}
qemuDomainObjExitMonitorWithDriver(driver, vm);
- virDomainAuditDisk(vm, NULL, disk, "attach", ret >= 0);
+ virDomainAuditDisk(vm, NULL, disk->src, "attach", ret >= 0);
if (ret < 0)
goto error;
@@ -560,7 +560,7 @@ int qemuDomainAttachUsbMassstorageDevice(struct qemud_driver *driver,
}
qemuDomainObjExitMonitorWithDriver(driver, vm);
- virDomainAuditDisk(vm, NULL, disk, "attach", ret >= 0);
+ virDomainAuditDisk(vm, NULL, disk->src, "attach", ret >= 0);
if (ret < 0)
goto error;
@@ -1277,14 +1277,14 @@ int qemuDomainDetachPciDiskDevice(struct qemud_driver *driver,
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) {
qemuDomainObjExitMonitorWithDriver(driver, vm);
- virDomainAuditDisk(vm, detach, NULL, "detach", false);
+ virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
goto cleanup;
}
} else {
if (qemuMonitorRemovePCIDevice(priv->mon,
&detach->info.addr.pci) < 0) {
qemuDomainObjExitMonitorWithDriver(driver, vm);
- virDomainAuditDisk(vm, detach, NULL, "detach", false);
+ virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
goto cleanup;
}
}
@@ -1294,7 +1294,7 @@ int qemuDomainDetachPciDiskDevice(struct qemud_driver *driver,
qemuDomainObjExitMonitorWithDriver(driver, vm);
- virDomainAuditDisk(vm, detach, NULL, "detach", true);
+ virDomainAuditDisk(vm, detach->src, NULL, "detach", true);
if (qemuCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE) &&
qemuDomainPCIAddressReleaseSlot(priv->pciaddrs,
@@ -1372,7 +1372,7 @@ int qemuDomainDetachDiskDevice(struct qemud_driver *driver,
qemuDomainObjEnterMonitorWithDriver(driver, vm);
if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) {
qemuDomainObjExitMonitorWithDriver(driver, vm);
- virDomainAuditDisk(vm, detach, NULL, "detach", false);
+ virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
goto cleanup;
}
@@ -1381,7 +1381,7 @@ int qemuDomainDetachDiskDevice(struct qemud_driver *driver,
qemuDomainObjExitMonitorWithDriver(driver, vm);
- virDomainAuditDisk(vm, detach, NULL, "detach", true);
+ virDomainAuditDisk(vm, detach->src, NULL, "detach", true);
virDomainDiskRemove(vm->def, i);
--
1.7.4.4