Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/qemu/qemu_block.c | 78 ++++++++++++++++++++++++++-----------------
src/qemu/qemu_block.h | 10 ++++++
2 files changed, 57 insertions(+), 31 deletions(-)
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 5b34461853..902ec7b2a5 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -3204,28 +3204,22 @@ qemuBlockExportAddNBD(virDomainObj *vm,
int
-qemuBlockCommit(virDomainObj *vm,
- virQEMUDriver *driver,
- const char *path,
- const char *base,
- const char *top,
- unsigned long bandwidth,
- unsigned int flags)
+qemuBlockCommitImpl(virDomainObj *vm,
+ virQEMUDriver *driver,
+ virDomainDiskDef *disk,
+ virStorageSource *baseSource,
+ virStorageSource *topSource,
+ virStorageSource *top_parent,
+ unsigned long bandwidth,
+ unsigned int flags)
{
qemuDomainObjPrivate *priv = vm->privateData;
int rc = -1;
- virDomainDiskDef *disk = NULL;
- virStorageSource *topSource;
- virStorageSource *baseSource = NULL;
- virStorageSource *top_parent = NULL;
bool clean_access = false;
g_autofree char *backingPath = NULL;
qemuBlockJobData *job = NULL;
g_autoptr(virStorageSource) mirror = NULL;
- if (virDomainObjCheckActive(vm) < 0)
- return -1;
-
/* Convert bandwidth MiB to bytes, if necessary */
if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES)) {
if (bandwidth > LLONG_MAX >> 20) {
@@ -3237,9 +3231,6 @@ qemuBlockCommit(virDomainObj *vm,
bandwidth <<= 20;
}
- if (!(disk = qemuDomainDiskByName(vm->def, path)))
- return -1;
-
if (!qemuDomainDiskBlockJobIsSupported(disk))
return -1;
@@ -3256,12 +3247,6 @@ qemuBlockCommit(virDomainObj *vm,
if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0)
return -1;
- if (!top || STREQ(top, disk->dst))
- topSource = disk->src;
- else if (!(topSource = virStorageSourceChainLookup(disk->src, NULL, top,
- disk->dst, &top_parent)))
- return -1;
-
if (topSource == disk->src) {
/* XXX Should we auto-pivot when COMMIT_ACTIVE is not specified? */
if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_ACTIVE)) {
@@ -3280,22 +3265,16 @@ qemuBlockCommit(virDomainObj *vm,
if (!virStorageSourceHasBacking(topSource)) {
virReportError(VIR_ERR_INVALID_ARG,
_("top '%s' in chain for '%s' has no backing
file"),
- topSource->path, path);
+ topSource->path, disk->src->path);
return -1;
}
- if (!base && (flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW))
- baseSource = topSource->backingStore;
- else if (!(baseSource = virStorageSourceChainLookup(disk->src, topSource,
- base, disk->dst, NULL)))
- return -1;
-
if ((flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW) &&
baseSource != topSource->backingStore) {
virReportError(VIR_ERR_INVALID_ARG,
_("base '%s' is not immediately below '%s' in
chain "
"for '%s'"),
- base, topSource->path, path);
+ baseSource->path, topSource->path, disk->src->path);
return -1;
}
@@ -3400,6 +3379,43 @@ qemuBlockCommit(virDomainObj *vm,
}
+int
+qemuBlockCommit(virDomainObj *vm,
+ virQEMUDriver *driver,
+ const char *path,
+ const char *base,
+ const char *top,
+ unsigned long bandwidth,
+ unsigned int flags)
+{
+ virDomainDiskDef *disk = NULL;
+ virStorageSource *topSource;
+ virStorageSource *baseSource = NULL;
+ virStorageSource *top_parent = NULL;
+
+ if (virDomainObjCheckActive(vm) < 0)
+ return -1;
+
+ if (!(disk = qemuDomainDiskByName(vm->def, path)))
+ return -1;
+
+ if (!top || STREQ(top, disk->dst))
+ topSource = disk->src;
+ else if (!(topSource = virStorageSourceChainLookup(disk->src, NULL, top,
+ disk->dst, &top_parent)))
+ return -1;
+
+ if (!base && (flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW))
+ baseSource = topSource->backingStore;
+ else if (!(baseSource = virStorageSourceChainLookup(disk->src, topSource,
+ base, disk->dst, NULL)))
+ return -1;
+
+ return qemuBlockCommitImpl(vm, driver, disk, baseSource, topSource,
+ top_parent, bandwidth, flags);
+}
+
+
/* Called while holding the VM job lock, to implement a block job
* abort with pivot; this updates the VM definition as appropriate, on
* either success or failure. */
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index d4b564e177..35f7718697 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -277,6 +277,16 @@ qemuBlockExportAddNBD(virDomainObj *vm,
bool writable,
const char *bitmap);
+int
+qemuBlockCommitImpl(virDomainObj *vm,
+ virQEMUDriver *driver,
+ virDomainDiskDef *disk,
+ virStorageSource *baseSource,
+ virStorageSource *topSource,
+ virStorageSource *top_parent,
+ unsigned long bandwidth,
+ unsigned int flags);
+
int
qemuBlockCommit(virDomainObj *vm,
virQEMUDriver *driver,
--
2.37.2