[PATCH 14/21] qemu: blockjob: Track internal data for 'backup' blockjob

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/qemu/qemu_blockjob.c | 32 +++++++++++++++++++++++++++++++-
 src/qemu/qemu_blockjob.h | 16 ++++++++++++++++
 src/qemu/qemu_domain.c   | 13 +++++++++++++
 3 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index eafad0432c..8dbb09c30a 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -77,8 +77,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)
@@ -369,6 +373,32 @@ qemuBlockJobDiskNewCopy(virDomainObjPtr vm,
 }


+qemuBlockJobDataPtr
+qemuBlockJobDiskNewBackup(virDomainObjPtr vm,
+                          virDomainDiskDefPtr disk,
+                          virStorageSourcePtr store,
+                          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);
+
+    /* 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..bfae410d14 100644
--- a/src/qemu/qemu_blockjob.h
+++ b/src/qemu/qemu_blockjob.h
@@ -107,6 +107,15 @@ struct _qemuBlockJobCopyData {
 };


+typedef struct _qemuBlockJobBackupData qemuBlockJobBackupData;
+typedef qemuBlockJobBackupData *qemuBlockJobDataBackupPtr;
+
+struct _qemuBlockJobBackupData {
+    virStorageSourcePtr store;
+    char *bitmap;
+};
+
+
 typedef struct _qemuBlockJobData qemuBlockJobData;
 typedef qemuBlockJobData *qemuBlockJobDataPtr;

@@ -124,6 +133,7 @@ struct _qemuBlockJobData {
         qemuBlockJobCommitData commit;
         qemuBlockJobCreateData create;
         qemuBlockJobCopyData copy;
+        qemuBlockJobBackupData backup;
     } data;

     int type; /* qemuBlockJobType */
@@ -184,6 +194,12 @@ qemuBlockJobDiskNewCopy(virDomainObjPtr vm,
                         bool shallow,
                         bool reuse);

+qemuBlockJobDataPtr
+qemuBlockJobDiskNewBackup(virDomainObjPtr vm,
+                          virDomainDiskDefPtr disk,
+                          virStorageSourcePtr store,
+                          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 a4c9ac11be..94d291e881 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2608,6 +2608,14 @@ qemuDomainObjPrivateXMLFormatBlockjobIterator(void *payload,
             break;

         case QEMU_BLOCKJOB_TYPE_BACKUP:
+            virBufferEscapeString(&childBuf, "<bitmap name='%s'/>\n", job->data.backup.bitmap);
+            if (job->data.backup.store &&
+                qemuDomainObjPrivateXMLFormatBlockjobFormatSource(&childBuf,
+                                                                  "store",
+                                                                  job->data.backup.store,
+                                                                  data->xmlopt,
+                                                                  false) < 0)
+                return -1;
             break;

         case QEMU_BLOCKJOB_TYPE_BROKEN:
@@ -3199,6 +3207,11 @@ 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;
             break;

         case QEMU_BLOCKJOB_TYPE_BROKEN:
-- 
2.23.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux