The created job will be needed by external snapshot delete code so
rework qemuBlockCommit to return that pointer.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/qemu/qemu_block.c | 42 +++++++++++++++++++++++-------------------
src/qemu/qemu_block.h | 2 +-
src/qemu/qemu_driver.c | 5 ++++-
3 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 24c82377b0..0a0d942e71 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -3201,8 +3201,12 @@ qemuBlockExportAddNBD(virDomainObj *vm,
/* The autofinalize argument controls if the qemu block job will be automatically
* finalized. This is used when deleting external snapshots where we need to
* disable automatic finalization for some use-case. The default value passed
- * to this argument should be VIR_TRISTATE_BOOL_YES.*/
-int
+ * to this argument should be VIR_TRISTATE_BOOL_YES.
+ *
+ * Returns qemuBlockJobData pointer on success, NULL on error. Caller is responsible
+ * to call virObjectUnref on the pointer.
+ */
+qemuBlockJobData *
qemuBlockCommit(virDomainObj *vm,
virDomainDiskDef *disk,
virStorageSource *baseSource,
@@ -3222,7 +3226,7 @@ qemuBlockCommit(virDomainObj *vm,
g_autoptr(virStorageSource) mirror = NULL;
if (virDomainObjCheckActive(vm) < 0)
- return -1;
+ return NULL;
/* Convert bandwidth MiB to bytes, if necessary */
if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES)) {
@@ -3230,26 +3234,26 @@ qemuBlockCommit(virDomainObj *vm,
virReportError(VIR_ERR_OVERFLOW,
_("bandwidth must be less than %llu"),
LLONG_MAX >> 20);
- return -1;
+ return NULL;
}
bandwidth <<= 20;
}
if (!qemuDomainDiskBlockJobIsSupported(disk))
- return -1;
+ return NULL;
if (virStorageSourceIsEmpty(disk->src)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk %s has no source file to be committed"),
disk->dst);
- return -1;
+ return NULL;
}
if (qemuDomainDiskBlockJobIsActive(disk))
- return -1;
+ return NULL;
if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0)
- return -1;
+ return NULL;
if (topSource == disk->src) {
/* XXX Should we auto-pivot when COMMIT_ACTIVE is not specified? */
@@ -3257,20 +3261,20 @@ qemuBlockCommit(virDomainObj *vm,
virReportError(VIR_ERR_INVALID_ARG,
_("commit of '%s' active layer requires active
flag"),
disk->dst);
- return -1;
+ return NULL;
}
} else if (flags & VIR_DOMAIN_BLOCK_COMMIT_ACTIVE) {
virReportError(VIR_ERR_INVALID_ARG,
_("active commit requested but '%s' is not
active"),
topSource->path);
- return -1;
+ return NULL;
}
if (!virStorageSourceHasBacking(topSource)) {
virReportError(VIR_ERR_INVALID_ARG,
_("top '%s' in chain for '%s' has no backing
file"),
topSource->path, disk->src->path);
- return -1;
+ return NULL;
}
if ((flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW) &&
@@ -3279,33 +3283,33 @@ qemuBlockCommit(virDomainObj *vm,
_("base '%s' is not immediately below '%s' in
chain "
"for '%s'"),
baseSource->path, topSource->path, disk->src->path);
- return -1;
+ return NULL;
}
/* For an active commit, clone enough of the base to act as the mirror */
if (topSource == disk->src) {
if (!(mirror = virStorageSourceCopy(baseSource, false)))
- return -1;
+ return NULL;
if (virStorageSourceInitChainElement(mirror,
disk->src,
true) < 0)
- return -1;
+ return NULL;
}
if (flags & VIR_DOMAIN_BLOCK_COMMIT_RELATIVE &&
topSource != disk->src) {
if (top_parent &&
qemuBlockUpdateRelativeBacking(vm, top_parent, disk->src) < 0)
- return -1;
+ return NULL;
if (virStorageSourceGetRelativeBackingPath(topSource, baseSource,
&backingPath) < 0)
- return -1;
+ return NULL;
if (!backingPath) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("can't keep relative backing relationship"));
- return -1;
+ return NULL;
}
}
@@ -3367,7 +3371,7 @@ qemuBlockCommit(virDomainObj *vm,
}
qemuBlockJobStarted(job, vm);
- return 0;
+ return job;
error:
if (clean_access) {
@@ -3384,7 +3388,7 @@ qemuBlockCommit(virDomainObj *vm,
}
qemuBlockJobStartupFinalize(vm, job);
- return -1;
+ return NULL;
}
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index c169432d9c..a8079c2207 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -277,7 +277,7 @@ qemuBlockExportAddNBD(virDomainObj *vm,
bool writable,
const char *bitmap);
-int
+qemuBlockJobData *
qemuBlockCommit(virDomainObj *vm,
virDomainDiskDef *disk,
virStorageSource *baseSource,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 12fca22616..53533062e1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14999,6 +14999,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
virStorageSource *topSource;
virStorageSource *baseSource = NULL;
virStorageSource *top_parent = NULL;
+ g_autoptr(qemuBlockJobData) job = NULL;
virCheckFlags(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW |
VIR_DOMAIN_BLOCK_COMMIT_ACTIVE |
@@ -15030,9 +15031,11 @@ qemuDomainBlockCommit(virDomainPtr dom,
base, disk->dst, NULL)))
goto endjob;
- ret = qemuBlockCommit(vm, disk, baseSource, topSource, top_parent,
+ job = qemuBlockCommit(vm, disk, baseSource, topSource, top_parent,
bandwidth, VIR_ASYNC_JOB_NONE, VIR_TRISTATE_BOOL_YES,
flags);
+ if (job)
+ ret = 0;
endjob:
virDomainObjEndJob(vm);
--
2.38.1