[libvirt PATCH v3 06/10] qemuProcessStartWithMemoryState: make it possible to use without data

Pavel Hrdina posted 10 patches 1 year, 7 months ago
[libvirt PATCH v3 06/10] qemuProcessStartWithMemoryState: make it possible to use without data
Posted by Pavel Hrdina 1 year, 7 months ago
When used with internal snapshots there is no memory state file so we
have no data to load and decompression is not needed.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/qemu/qemu_process.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index c8430bf7b7..f96918073f 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8165,7 +8165,7 @@ qemuProcessStart(virConnectPtr conn,
  * @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
+ * @data: data from memory state file or NULL
  * @asyncJob: type of asynchronous job
  * @start_flags: flags to start QEMU process with
  * @reason: audit log reason
@@ -8175,7 +8175,8 @@ qemuProcessStart(virConnectPtr conn,
  * 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.
+ * correctly start QEMU process. In addition there is no memory state file so
+ * it's safe to pass NULL as @data.
  *
  * When restoring VM from saved image @snapshot needs to be NULL.
  *
@@ -8203,9 +8204,16 @@ qemuProcessStartWithMemoryState(virConnectPtr conn,
     g_autofree char *errbuf = NULL;
     int rc = 0;
 
-    if (virSaveCookieParseString(data->cookie, (virObject **)&cookie,
-                                 virDomainXMLOptionGetSaveCookie(driver->xmlopt)) < 0)
-        return -1;
+    if (data) {
+        if (virSaveCookieParseString(data->cookie, (virObject **)&cookie,
+                                     virDomainXMLOptionGetSaveCookie(driver->xmlopt)) < 0)
+            return -1;
+
+        if (qemuSaveImageDecompressionStart(data, fd, &intermediatefd,
+                                            &errbuf, &cmd) < 0) {
+            return -1;
+        }
+    }
 
     if (qemuSaveImageDecompressionStart(data, fd, &intermediatefd, &errbuf, &cmd) < 0)
         return -1;
@@ -8226,7 +8234,10 @@ qemuProcessStartWithMemoryState(virConnectPtr conn,
                          start_flags) == 0)
         *started = true;
 
-    rc = qemuSaveImageDecompressionStop(cmd, fd, &intermediatefd, errbuf, *started, path);
+    if (data) {
+        rc = qemuSaveImageDecompressionStop(cmd, fd, &intermediatefd, errbuf,
+                                            *started, path);
+    }
 
     virDomainAuditStart(vm, reason, *started);
     if (!*started || rc < 0)
-- 
2.41.0
Re: [libvirt PATCH v3 06/10] qemuProcessStartWithMemoryState: make it possible to use without data
Posted by Peter Krempa 1 year, 6 months ago
On Mon, Sep 18, 2023 at 15:29:23 +0200, Pavel Hrdina wrote:
> When used with internal snapshots there is no memory state file so we
> have no data to load and decompression is not needed.
> 
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  src/qemu/qemu_process.c | 23 +++++++++++++++++------
>  1 file changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index c8430bf7b7..f96918073f 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -8165,7 +8165,7 @@ qemuProcessStart(virConnectPtr conn,
>   * @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
> + * @data: data from memory state file or NULL
>   * @asyncJob: type of asynchronous job
>   * @start_flags: flags to start QEMU process with
>   * @reason: audit log reason
> @@ -8175,7 +8175,8 @@ qemuProcessStart(virConnectPtr conn,
>   * 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.
> + * correctly start QEMU process. In addition there is no memory state file so
> + * it's safe to pass NULL as @data.

This does not fully address my comment from previous patch. It says that
@data 'can' be NULL, not that it MUST be inull if @snapshot is non-null.