]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: snapshot: move transient snapshot code to qemu_process
authorPeter Krempa <pkrempa@redhat.com>
Tue, 27 Apr 2021 18:31:11 +0000 (20:31 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 24 May 2021 18:38:07 +0000 (20:38 +0200)
The code deals with the startup of the VM and just uses the snapshot
code to achieve the desired outcome.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/qemu/qemu_process.c
src/qemu/qemu_snapshot.c
src/qemu/qemu_snapshot.h

index 06f27d6e3c11fdf0eedc443f20aa49960b2307ce..4a53cf95458fb3446461d21a0dd189ef2acdd7a0 100644 (file)
@@ -6936,6 +6936,66 @@ qemuProcessEnablePerf(virDomainObj *vm)
 }
 
 
+static int
+qemuProcessSetupDisksTransientSnapshot(virDomainObj *vm,
+                                       qemuDomainAsyncJob asyncJob)
+{
+    qemuDomainObjPrivate *priv = vm->privateData;
+    g_autoptr(qemuSnapshotDiskContext) snapctxt = NULL;
+    g_autoptr(GHashTable) blockNamedNodeData = NULL;
+    size_t i;
+
+    if (!(blockNamedNodeData = qemuBlockGetNamedNodeData(vm, asyncJob)))
+        return -1;
+
+    snapctxt = qemuSnapshotDiskContextNew(vm->def->ndisks, vm, asyncJob);
+
+    for (i = 0; i < vm->def->ndisks; i++) {
+        virDomainDiskDef *domdisk = vm->def->disks[i];
+        g_autoptr(virDomainSnapshotDiskDef) snapdisk = NULL;
+
+        if (!domdisk->transient)
+            continue;
+
+        /* validation code makes sure that we do this only for local disks
+         * with a file source */
+
+        if (!(snapdisk = qemuSnapshotGetTransientDiskDef(domdisk)))
+            return -1;
+
+        if (qemuSnapshotDiskPrepareOne(snapctxt, domdisk, snapdisk,
+                                       blockNamedNodeData,
+                                       false,
+                                       false) < 0)
+            return -1;
+    }
+
+    if (qemuSnapshotDiskCreate(snapctxt) < 0)
+        return -1;
+
+    /* the overlays are established, so they can be deleted on shutdown */
+    priv->inhibitDiskTransientDelete = false;
+
+    return 0;
+}
+
+
+static int
+qemuProcessSetupDisksTransient(virDomainObj *vm,
+                               qemuDomainAsyncJob asyncJob)
+{
+    qemuDomainObjPrivate *priv = vm->privateData;
+
+    if (!(virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)))
+        return 0;
+
+    if (qemuProcessSetupDisksTransientSnapshot(vm, asyncJob) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 /**
  * qemuProcessLaunch:
  *
@@ -7290,7 +7350,7 @@ qemuProcessLaunch(virConnectPtr conn,
 
     if (!incoming && !snapshot) {
         VIR_DEBUG("Setting up transient disk");
-        if (qemuSnapshotCreateDisksTransient(vm, asyncJob) < 0)
+        if (qemuProcessSetupDisksTransient(vm, asyncJob) < 0)
             goto cleanup;
     }
 
index d87f164ebfd0b5399639dabcfb79eb811c35ee04..928b7af287ea9d50eb8c944f8f133b8924dc4617 100644 (file)
@@ -906,7 +906,7 @@ struct _qemuSnapshotDiskContext {
 typedef struct _qemuSnapshotDiskContext qemuSnapshotDiskContext;
 
 
-static qemuSnapshotDiskContext *
+qemuSnapshotDiskContext *
 qemuSnapshotDiskContextNew(size_t ndisks,
                            virDomainObj *vm,
                            qemuDomainAsyncJob asyncJob)
@@ -925,7 +925,7 @@ qemuSnapshotDiskContextNew(size_t ndisks,
 }
 
 
-static void
+void
 qemuSnapshotDiskContextCleanup(qemuSnapshotDiskContext *snapctxt)
 {
     if (!snapctxt)
@@ -940,8 +940,6 @@ qemuSnapshotDiskContextCleanup(qemuSnapshotDiskContext *snapctxt)
     g_free(snapctxt);
 }
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuSnapshotDiskContext, qemuSnapshotDiskContextCleanup);
-
 
 /**
  * qemuSnapshotDiskBitmapsPropagate:
@@ -1032,7 +1030,7 @@ qemuSnapshotDiskPrepareOneBlockdev(virQEMUDriver *driver,
 }
 
 
-static int
+int
 qemuSnapshotDiskPrepareOne(qemuSnapshotDiskContext *snapctxt,
                            virDomainDiskDef *disk,
                            virDomainSnapshotDiskDef *snapdisk,
@@ -1170,7 +1168,7 @@ qemuSnapshotDiskPrepareActiveExternal(virDomainObj *vm,
 }
 
 
-static virDomainSnapshotDiskDef *
+virDomainSnapshotDiskDef *
 qemuSnapshotGetTransientDiskDef(virDomainDiskDef *domdisk)
 {
     g_autoptr(virDomainSnapshotDiskDef) snapdisk = g_new0(virDomainSnapshotDiskDef, 1);
@@ -1193,40 +1191,6 @@ qemuSnapshotGetTransientDiskDef(virDomainDiskDef *domdisk)
 }
 
 
-static qemuSnapshotDiskContext *
-qemuSnapshotDiskPrepareDisksTransient(virDomainObj *vm,
-                                      GHashTable *blockNamedNodeData,
-                                      qemuDomainAsyncJob asyncJob)
-{
-    g_autoptr(qemuSnapshotDiskContext) snapctxt = NULL;
-    size_t i;
-
-    snapctxt = qemuSnapshotDiskContextNew(vm->def->ndisks, vm, asyncJob);
-
-    for (i = 0; i < vm->def->ndisks; i++) {
-        virDomainDiskDef *domdisk = vm->def->disks[i];
-        g_autoptr(virDomainSnapshotDiskDef) snapdisk = NULL;
-
-        if (!domdisk->transient)
-            continue;
-
-        /* validation code makes sure that we do this only for local disks
-         * with a file source */
-
-        if (!(snapdisk = qemuSnapshotGetTransientDiskDef(domdisk)))
-            return NULL;
-
-        if (qemuSnapshotDiskPrepareOne(snapctxt, domdisk, snapdisk,
-                                       blockNamedNodeData,
-                                       false,
-                                       false) < 0)
-            return NULL;
-    }
-
-    return g_steal_pointer(&snapctxt);
-}
-
-
 static void
 qemuSnapshotDiskUpdateSourceRenumber(virStorageSource *src)
 {
@@ -1285,7 +1249,7 @@ qemuSnapshotDiskUpdateSource(virDomainObj *vm,
 }
 
 
-static int
+int
 qemuSnapshotDiskCreate(qemuSnapshotDiskContext *snapctxt)
 {
     qemuDomainObjPrivate *priv = snapctxt->vm->privateData;
@@ -1353,43 +1317,6 @@ qemuSnapshotCreateActiveExternalDisks(virDomainObj *vm,
 }
 
 
-/**
- * qemuSnapshotCreateDisksTransient:
- * @vm: domain object
- * @asyncJob: qemu async job type
- *
- * Creates overlays on top of disks which are configured as <transient/>. Note
- * that the validation code ensures that <transient> disks have appropriate
- * configuration.
- */
-int
-qemuSnapshotCreateDisksTransient(virDomainObj *vm,
-                                 qemuDomainAsyncJob asyncJob)
-{
-    qemuDomainObjPrivate *priv = vm->privateData;
-    g_autoptr(qemuSnapshotDiskContext) snapctxt = NULL;
-    g_autoptr(GHashTable) blockNamedNodeData = NULL;
-
-    if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
-        if (!(blockNamedNodeData = qemuBlockGetNamedNodeData(vm, asyncJob)))
-            return -1;
-
-        if (!(snapctxt = qemuSnapshotDiskPrepareDisksTransient(vm,
-                                                               blockNamedNodeData,
-                                                               asyncJob)))
-            return -1;
-
-        if (qemuSnapshotDiskCreate(snapctxt) < 0)
-            return -1;
-    }
-
-    /* the overlays are established, so they can be deleted on shutdown */
-    priv->inhibitDiskTransientDelete = false;
-
-    return 0;
-}
-
-
 static int
 qemuSnapshotCreateActiveExternal(virQEMUDriver *driver,
                                  virDomainObj *vm,
index 62ff22221d6ca0bf7640c42da7d03976e07c9c73..4fba7e4e242778abbfd1f3b6c349ffd4c26f317f 100644 (file)
@@ -55,6 +55,28 @@ qemuSnapshotDelete(virDomainObj *vm,
                    virDomainSnapshotPtr snapshot,
                    unsigned int flags);
 
+
+typedef struct _qemuSnapshotDiskContext qemuSnapshotDiskContext;
+
+qemuSnapshotDiskContext *
+qemuSnapshotDiskContextNew(size_t ndisks,
+                           virDomainObj *vm,
+                           qemuDomainAsyncJob asyncJob);
+
+void
+qemuSnapshotDiskContextCleanup(qemuSnapshotDiskContext *snapctxt);
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuSnapshotDiskContext, qemuSnapshotDiskContextCleanup);
+
+int
+qemuSnapshotDiskPrepareOne(qemuSnapshotDiskContext *snapctxt,
+                           virDomainDiskDef *disk,
+                           virDomainSnapshotDiskDef *snapdisk,
+                           GHashTable *blockNamedNodeData,
+                           bool reuse,
+                           bool updateConfig);
 int
-qemuSnapshotCreateDisksTransient(virDomainObj *vm,
-                                 qemuDomainAsyncJob asyncJob);
+qemuSnapshotDiskCreate(qemuSnapshotDiskContext *snapctxt);
+
+virDomainSnapshotDiskDef *
+qemuSnapshotGetTransientDiskDef(virDomainDiskDef *domdisk);