From 173015bec6a08d61fa7bc3df06956484b1d1a294 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 26 Aug 2011 17:29:18 -0600 Subject: [PATCH] snapshot: forbid snapshot on autodestroy domain There is no reason to forbid pausing an autodestroy domain (not to mention that 'virsh start --paused --autodestroy' succeeds in creating a paused autodestroy domain). Meanwhile, qemu was failing to enforce the API documentation that autodestroy domains cannot be saved. And while the original documentation only mentioned save/restore, snapshots are another form of saving that are close enough in semantics as to make no sense on one-shot domains. * src/qemu/qemu_driver.c (qemudDomainSuspend): Drop bogus check. (qemuDomainSaveInternal, qemuDomainSnapshotCreateXML): Forbid saves of autodestroy domains. * src/libvirt.c (virDomainCreateWithFlags, virDomainCreateXML): Document snapshot interaction. --- src/libvirt.c | 4 ++-- src/qemu/qemu_driver.c | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index 80c8b7cd01..e4a21b6b22 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -1822,7 +1822,7 @@ virDomainGetConnect (virDomainPtr dom) * object is finally released. This will also happen if the * client application crashes / loses its connection to the * libvirtd daemon. Any domains marked for auto destroy will - * block attempts at migration or save-to-file + * block attempts at migration, save-to-file, or snapshots. * * Returns a new domain object or NULL in case of failure */ @@ -7073,7 +7073,7 @@ error: * object is finally released. This will also happen if the * client application crashes / loses its connection to the * libvirtd daemon. Any domains marked for auto destroy will - * block attempts at migration or save-to-file + * block attempts at migration, save-to-file, or snapshots. * * If the VIR_DOMAIN_START_BYPASS_CACHE flag is set, and there is a * managed save file for this domain (created by virDomainManagedSave()), diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5033998703..4e8c69187d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1361,12 +1361,6 @@ static int qemudDomainSuspend(virDomainPtr dom) { goto cleanup; } - if (qemuProcessAutoDestroyActive(driver, vm)) { - qemuReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("domain is marked for auto destroy")); - goto cleanup; - } - priv = vm->privateData; if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT) { @@ -2226,6 +2220,12 @@ qemuDomainSaveInternal(struct qemud_driver *driver, virDomainPtr dom, int directFlag = 0; virFileDirectFdPtr directFd = NULL; + if (qemuProcessAutoDestroyActive(driver, vm)) { + qemuReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("domain is marked for auto destroy")); + return -1; + } + memset(&header, 0, sizeof(header)); memcpy(header.magic, QEMUD_SAVE_MAGIC, sizeof(header.magic)); header.version = QEMUD_SAVE_VERSION; @@ -8481,6 +8481,12 @@ static virDomainSnapshotPtr qemuDomainSnapshotCreateXML(virDomainPtr domain, goto cleanup; } + if (qemuProcessAutoDestroyActive(driver, vm)) { + qemuReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("domain is marked for auto destroy")); + goto cleanup; + } + /* in a perfect world, we would allow qemu to tell us this. The problem * is that qemu only does this check device-by-device; so if you had a * domain that booted from a large qcow2 device, but had a secondary raw -- GitLab