[PATCH 6/9] qemu: monitor: Add monitor infrastructure for 'snapshot-load' QMP command

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

 



Libvirt currently loads snapshots via the '-loadvm' commandline option
but that uses the same logic as the 'loadvm' text monitor command used
to pick the disk image with the 'vmstate' section. Since libvirt now
implements our own logic to pick the 'vmstate' device it can happen that
we pick a different than qemu and thus qemu would fail to load the
snapshot. This happens currently on VMs with UEFI firmware with NVRAM
image in qcow2 format.

To fix this libvirt will need to use the 'snapshot-load' QMP command
instead of relying on '-savevm'.

Implement the monitor bits for 'snapshot-load'.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_monitor.c      | 16 ++++++++++++++++
 src/qemu/qemu_monitor.h      |  7 +++++++
 src/qemu/qemu_monitor_json.c | 31 +++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  7 +++++++
 4 files changed, 61 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index fd888e2468..73f37d26eb 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2780,6 +2780,22 @@ qemuMonitorSnapshotSave(qemuMonitor *mon,
 }


+int
+qemuMonitorSnapshotLoad(qemuMonitor *mon,
+                        const char *jobname,
+                        const char *snapshotname,
+                        const char *vmstate_disk,
+                        const char **disks)
+{
+    VIR_DEBUG("jobname='%s', snapshotname='%s', vmstate_disk='%s'",
+              jobname, snapshotname, vmstate_disk);
+
+    QEMU_CHECK_MONITOR(mon);
+
+    return qemuMonitorJSONSnapshotLoad(mon, jobname, snapshotname, vmstate_disk, disks);
+}
+
+
 int
 qemuMonitorSnapshotDelete(qemuMonitor *mon,
                           const char *jobname,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 035c9a7e3c..aded771315 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1626,6 +1626,13 @@ qemuMonitorSnapshotSave(qemuMonitor *mon,
                         const char *vmstate_disk,
                         const char **disks);

+int
+qemuMonitorSnapshotLoad(qemuMonitor *mon,
+                        const char *jobname,
+                        const char *snapshotname,
+                        const char *vmstate_disk,
+                        const char **disks);
+
 int
 qemuMonitorSnapshotDelete(qemuMonitor *mon,
                           const char *jobname,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index c594b33106..b3924461a9 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8754,6 +8754,37 @@ qemuMonitorJSONSnapshotSave(qemuMonitor *mon,
 }


+int
+qemuMonitorJSONSnapshotLoad(qemuMonitor *mon,
+                            const char *jobname,
+                            const char *snapshotname,
+                            const char *vmstate_disk,
+                            const char **disks)
+{
+    g_autoptr(virJSONValue) cmd = NULL;
+    g_autoptr(virJSONValue) reply = NULL;
+    g_autoptr(virJSONValue) devices = virJSONValueNewArray();
+
+    for (; *disks; disks++) {
+        if (virJSONValueArrayAppendString(devices, *disks) < 0)
+            return -1;
+    }
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("snapshot-load",
+                                           "s:job-id", jobname,
+                                           "s:tag", snapshotname,
+                                           "s:vmstate", vmstate_disk,
+                                           "a:devices", &devices,
+                                           NULL)))
+        return -1;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        return -1;
+
+    return qemuMonitorJSONCheckError(cmd, reply);
+}
+
+
 int
 qemuMonitorJSONSnapshotDelete(qemuMonitor *mon,
                               const char *jobname,
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index ab3c2cb7c8..0214e9e9ff 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -804,6 +804,13 @@ qemuMonitorJSONSnapshotSave(qemuMonitor *mon,
                             const char *vmstate_disk,
                             const char **disks);

+int
+qemuMonitorJSONSnapshotLoad(qemuMonitor *mon,
+                            const char *jobname,
+                            const char *snapshotname,
+                            const char *vmstate_disk,
+                            const char **disks);
+
 int
 qemuMonitorJSONSnapshotDelete(qemuMonitor *mon,
                               const char *jobname,
-- 
2.47.0




[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