A backup blockjob needs to be able to notify the parent backup job as
well as track all data to be able to clean up the bitmap and blockdev
used for the backup.
Add the data structure, job allocation function and status XML formatter
and parser.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_blockjob.c | 34 +++++++++++++++++++++++++++++++++-
src/qemu/qemu_blockjob.h | 18 ++++++++++++++++++
src/qemu/qemu_domain.c | 21 +++++++++++++++++++++
3 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index 5455eaba65..d434b8bddd 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -78,8 +78,12 @@ qemuBlockJobDataDisposeJobdata(qemuBlockJobDataPtr job)
{
if (job->type == QEMU_BLOCKJOB_TYPE_CREATE)
virObjectUnref(job->data.create.src);
-}
+ if (job->type == QEMU_BLOCKJOB_TYPE_BACKUP) {
+ virObjectUnref(job->data.backup.store);
+ g_free(job->data.backup.bitmap);
+ }
+}
static void
qemuBlockJobDataDispose(void *obj)
@@ -370,6 +374,34 @@ qemuBlockJobDiskNewCopy(virDomainObjPtr vm,
}
+qemuBlockJobDataPtr
+qemuBlockJobDiskNewBackup(virDomainObjPtr vm,
+ virDomainDiskDefPtr disk,
+ virStorageSourcePtr store,
+ bool deleteStore,
+ const char *bitmap)
+{
+ g_autoptr(qemuBlockJobData) job = NULL;
+ g_autofree char *jobname = NULL;
+
+ jobname = g_strdup_printf("backup-%s-%s", disk->dst,
disk->src->nodeformat);
+
+ if (!(job = qemuBlockJobDataNew(QEMU_BLOCKJOB_TYPE_BACKUP, jobname)))
+ return NULL;
+
+ job->data.backup.bitmap = g_strdup(bitmap);
+ job->data.backup.store = virObjectRef(store);
+ job->data.backup.deleteStore = deleteStore;
+
+ /* backup jobs are usually started in bulk by transaction so the caller
+ * shall save the status XML */
+ if (qemuBlockJobRegister(job, vm, disk, false) < 0)
+ return NULL;
+
+ return g_steal_pointer(&job);
+}
+
+
/**
* qemuBlockJobDiskGetJob:
* @disk: disk definition
diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h
index 4734984c99..52b03aaf9e 100644
--- a/src/qemu/qemu_blockjob.h
+++ b/src/qemu/qemu_blockjob.h
@@ -107,6 +107,16 @@ struct _qemuBlockJobCopyData {
};
+typedef struct _qemuBlockJobBackupData qemuBlockJobBackupData;
+typedef qemuBlockJobBackupData *qemuBlockJobDataBackupPtr;
+
+struct _qemuBlockJobBackupData {
+ virStorageSourcePtr store;
+ bool deleteStore;
+ char *bitmap;
+};
+
+
typedef struct _qemuBlockJobData qemuBlockJobData;
typedef qemuBlockJobData *qemuBlockJobDataPtr;
@@ -124,6 +134,7 @@ struct _qemuBlockJobData {
qemuBlockJobCommitData commit;
qemuBlockJobCreateData create;
qemuBlockJobCopyData copy;
+ qemuBlockJobBackupData backup;
} data;
int type; /* qemuBlockJobType */
@@ -184,6 +195,13 @@ qemuBlockJobDiskNewCopy(virDomainObjPtr vm,
bool shallow,
bool reuse);
+qemuBlockJobDataPtr
+qemuBlockJobDiskNewBackup(virDomainObjPtr vm,
+ virDomainDiskDefPtr disk,
+ virStorageSourcePtr store,
+ bool deleteStore,
+ const char *bitmap);
+
qemuBlockJobDataPtr
qemuBlockJobDiskGetJob(virDomainDiskDefPtr disk)
ATTRIBUTE_NONNULL(1);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 98d0dad861..f4f841526e 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2608,6 +2608,18 @@ qemuDomainObjPrivateXMLFormatBlockjobIterator(void *payload,
break;
case QEMU_BLOCKJOB_TYPE_BACKUP:
+ virBufferEscapeString(&childBuf, "<bitmap
name='%s'/>\n", job->data.backup.bitmap);
+ if (job->data.backup.store) {
+ if (qemuDomainObjPrivateXMLFormatBlockjobFormatSource(&childBuf,
+ "store",
+
job->data.backup.store,
+ data->xmlopt,
+ false) < 0)
+ return -1;
+
+ if (job->data.backup.deleteStore)
+ virBufferAddLit(&childBuf, "<deleteStore/>\n");
+ }
break;
case QEMU_BLOCKJOB_TYPE_BROKEN:
@@ -3199,6 +3211,15 @@
qemuDomainObjPrivateXMLParseBlockjobDataSpecific(qemuBlockJobDataPtr job,
break;
case QEMU_BLOCKJOB_TYPE_BACKUP:
+ job->data.backup.bitmap =
virXPathString("string(./bitmap/@name)", ctxt);
+
+ if (!(tmp = virXPathNode("./store", ctxt)) ||
+ !(job->data.backup.store =
qemuDomainObjPrivateXMLParseBlockjobChain(tmp, ctxt, xmlopt)))
+ goto broken;
+
+ if (virXPathNode("./deleteStore", ctxt))
+ job->data.backup.deleteStore = true;
+
break;
case QEMU_BLOCKJOB_TYPE_BROKEN:
--
2.23.0