From 3e41a461b3f587c075005e3da4293e02efbc4f0d Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Fri, 20 Dec 2013 15:08:06 +0100 Subject: [PATCH] qemu: Fix job usage in qemuDomainBlockCopy Every API that is going to begin a job should do that before fetching data from vm->def. (cherry picked from commit ff5f30b6bfa317f2a4c33f69289baf4e887eb048) Conflicts: src/qemu/qemu_driver.c - context --- src/qemu/qemu_driver.c | 66 ++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e3849d7859..d2d4f99658 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13495,7 +13495,7 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *path, virDomainObjPtr vm; qemuDomainObjPrivatePtr priv; char *device = NULL; - virDomainDiskDefPtr disk; + virDomainDiskDefPtr disk = NULL; int ret = -1; int idx; struct stat st; @@ -13511,39 +13511,6 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *path, goto cleanup; priv = vm->privateData; cfg = virQEMUDriverGetConfig(driver); - if (!virDomainObjIsActive(vm)) { - virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("domain is not running")); - goto cleanup; - } - - device = qemuDiskPathToAlias(vm, path, &idx); - if (!device) { - goto cleanup; - } - disk = vm->def->disks[idx]; - if (disk->mirror) { - virReportError(VIR_ERR_BLOCK_COPY_ACTIVE, - _("disk '%s' already in active block copy job"), - disk->dst); - goto cleanup; - } - - if (!(virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DRIVE_MIRROR) && - virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKJOB_ASYNC))) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("block copy is not supported with this QEMU binary")); - goto cleanup; - } - if (vm->persistent) { - /* XXX if qemu ever lets us start a new domain with mirroring - * already active, we can relax this; but for now, the risk of - * 'managedsave' due to libvirt-guests means we can't risk - * this on persistent domains. */ - virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("domain is not transient")); - goto cleanup; - } if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; @@ -13553,6 +13520,35 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *path, _("domain is not running")); goto endjob; } + + device = qemuDiskPathToAlias(vm, path, &idx); + if (!device) { + goto endjob; + } + disk = vm->def->disks[idx]; + if (disk->mirror) { + virReportError(VIR_ERR_BLOCK_COPY_ACTIVE, + _("disk '%s' already in active block copy job"), + disk->dst); + goto endjob; + } + + if (!(virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DRIVE_MIRROR) && + virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKJOB_ASYNC))) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("block copy is not supported with this QEMU binary")); + goto endjob; + } + if (vm->persistent) { + /* XXX if qemu ever lets us start a new domain with mirroring + * already active, we can relax this; but for now, the risk of + * 'managedsave' due to libvirt-guests means we can't risk + * this on persistent domains. */ + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("domain is not transient")); + goto endjob; + } + if (qemuDomainDetermineDiskChain(driver, disk, false) < 0) goto endjob; @@ -13642,7 +13638,7 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *path, endjob: if (need_unlink && unlink(dest)) VIR_WARN("unable to unlink just-created %s", dest); - if (ret < 0) + if (ret < 0 && disk) disk->mirrorFormat = VIR_STORAGE_FILE_NONE; VIR_FREE(mirror); if (qemuDomainObjEndJob(driver, vm) == 0) {