[libvirt PATCH v3 05/10] qemuProcessStartWithMemoryState: add snapshot argument

Pavel Hrdina posted 10 patches 5 months, 1 week ago
[libvirt PATCH v3 05/10] qemuProcessStartWithMemoryState: add snapshot argument
Posted by Pavel Hrdina 5 months, 1 week ago
When called from snapshot code we will need to pass snapshot object in
order to make internal snapshots work correctly.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/qemu/qemu_process.c   | 9 ++++++++-
 src/qemu/qemu_process.h   | 1 +
 src/qemu/qemu_saveimage.c | 2 +-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index d414a40fd5..c8430bf7b7 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8164,6 +8164,7 @@ qemuProcessStart(virConnectPtr conn,
  * @vm: domain object
  * @fd: FD pointer of memory state file
  * @path: path to memory state file
+ * @snapshot: internal snapshot to load when starting QEMU process or NULL
  * @data: data from memory state file
  * @asyncJob: type of asynchronous job
  * @start_flags: flags to start QEMU process with
@@ -8173,6 +8174,11 @@ qemuProcessStart(virConnectPtr conn,
  * Start VM with existing memory state. Make sure that the stored memory state
  * is correctly decompressed so it can be loaded by QEMU process.
  *
+ * When reverting to internal snapshot callers needs to pass @snapshot as well
+ * correctly start QEMU process.
+ *
+ * When restoring VM from saved image @snapshot needs to be NULL.
+ *
  * For audit purposes the expected @reason is one of `restored` or `from-snapshot`.
  *
  * Returns 0 on success, -1 on error.
@@ -8183,6 +8189,7 @@ qemuProcessStartWithMemoryState(virConnectPtr conn,
                                 virDomainObj *vm,
                                 int *fd,
                                 const char *path,
+                                virDomainMomentObj *snapshot,
                                 virQEMUSaveData *data,
                                 virDomainAsyncJob asyncJob,
                                 unsigned int start_flags,
@@ -8214,7 +8221,7 @@ qemuProcessStartWithMemoryState(virConnectPtr conn,
         priv->disableSlirp = true;
 
     if (qemuProcessStart(conn, driver, vm, cookie ? cookie->cpu : NULL,
-                         asyncJob, "stdio", *fd, path, NULL,
+                         asyncJob, "stdio", *fd, path, snapshot,
                          VIR_NETDEV_VPORT_PROFILE_OP_RESTORE,
                          start_flags) == 0)
         *started = true;
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 26c9a04969..ce2f25a2e7 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -96,6 +96,7 @@ int qemuProcessStartWithMemoryState(virConnectPtr conn,
                                     virDomainObj *vm,
                                     int *fd,
                                     const char *path,
+                                    virDomainMomentObj *snapshot,
                                     virQEMUSaveData *data,
                                     virDomainAsyncJob asyncJob,
                                     unsigned int start_flags,
diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c
index 92dcf4b616..89112e3e44 100644
--- a/src/qemu/qemu_saveimage.c
+++ b/src/qemu/qemu_saveimage.c
@@ -698,7 +698,7 @@ qemuSaveImageStartVM(virConnectPtr conn,
     if (reset_nvram)
         start_flags |= VIR_QEMU_PROCESS_START_RESET_NVRAM;
 
-    if (qemuProcessStartWithMemoryState(conn, driver, vm, fd, path, data,
+    if (qemuProcessStartWithMemoryState(conn, driver, vm, fd, path, NULL, data,
                                         asyncJob, start_flags, "restored",
                                         &started) < 0) {
         goto cleanup;
-- 
2.41.0
Re: [libvirt PATCH v3 05/10] qemuProcessStartWithMemoryState: add snapshot argument
Posted by Peter Krempa 5 months ago
On Mon, Sep 18, 2023 at 15:29:22 +0200, Pavel Hrdina wrote:
> When called from snapshot code we will need to pass snapshot object in
> order to make internal snapshots work correctly.
> 
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  src/qemu/qemu_process.c   | 9 ++++++++-
>  src/qemu/qemu_process.h   | 1 +
>  src/qemu/qemu_saveimage.c | 2 +-
>  3 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index d414a40fd5..c8430bf7b7 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -8164,6 +8164,7 @@ qemuProcessStart(virConnectPtr conn,
>   * @vm: domain object
>   * @fd: FD pointer of memory state file
>   * @path: path to memory state file
> + * @snapshot: internal snapshot to load when starting QEMU process or NULL
>   * @data: data from memory state file
>   * @asyncJob: type of asynchronous job
>   * @start_flags: flags to start QEMU process with
> @@ -8173,6 +8174,11 @@ qemuProcessStart(virConnectPtr conn,
>   * Start VM with existing memory state. Make sure that the stored memory state
>   * is correctly decompressed so it can be loaded by QEMU process.
>   *
> + * When reverting to internal snapshot callers needs to pass @snapshot as well
> + * correctly start QEMU process.

It doesn't mention that callers must not pass the other state-related
parameters as both methods can't be used at once.

> + *
> + * When restoring VM from saved image @snapshot needs to be NULL.

This is only an implication (one way) that says that with a saveimage
@snapshot must be null, but not that it's also the other way around.