Add the query-dump API's in order to allow the dump-guest-memory
to be used to monitor progress.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_monitor.c | 14 +++++++++
src/qemu/qemu_monitor.h | 11 +++++++
src/qemu/qemu_monitor_json.c | 69 ++++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 4 +++
4 files changed, 98 insertions(+)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index ae64edd95..41a04dd00 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2760,6 +2760,20 @@ qemuMonitorMigrateCancel(qemuMonitorPtr mon)
}
+int
+qemuMonitorQueryDump(qemuMonitorPtr mon,
+ qemuMonitorDumpStatsPtr stats)
+{
+ QEMU_CHECK_MONITOR(mon);
+
+ /* No capability is supported without JSON monitor */
+ if (!mon->json)
+ return 0;
+
+ return qemuMonitorJSONQueryDump(mon, stats);
+}
+
+
/**
* Returns 1 if @capability is supported, 0 if it's not, or -1 on error.
*/
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index ab4c67ef3..b4322e360 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -775,6 +775,17 @@ int qemuMonitorMigrateCancel(qemuMonitorPtr mon);
int qemuMonitorGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
const char *capability);
+typedef struct _qemuMonitorDumpStats qemuMonitorDumpStats;
+typedef qemuMonitorDumpStats *qemuMonitorDumpStatsPtr;
+struct _qemuMonitorDumpStats {
+ int status; /* qemuMonitorDumpStatus */
+ unsigned long long completed; /* bytes written */
+ unsigned long long total; /* total bytes to be written */
+};
+
+int qemuMonitorQueryDump(qemuMonitorPtr mon,
+ qemuMonitorDumpStatsPtr stats);
+
int qemuMonitorDumpToFd(qemuMonitorPtr mon,
int fd,
const char *dumpformat);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 7e3cdce9c..f29588c4d 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -3131,6 +3131,75 @@ int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon)
return ret;
}
+
+/* qemuMonitorJSONQueryDump:
+ * @mon: Monitor pointer
+ * @stats: Dump "stats"
+ *
+ * Attempt to make a "query-dump" call, check for errors, and get/return
+ * the current from the reply
+ *
+ * Returns: 0 on success, -1 on failure
+ */
+int
+qemuMonitorJSONQueryDump(qemuMonitorPtr mon,
+ qemuMonitorDumpStatsPtr stats)
+{
+ int ret = -1;
+ virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-dump", NULL);
+ virJSONValuePtr reply = NULL;
+ virJSONValuePtr result = NULL;
+ const char *statusstr;
+
+ if (!cmd)
+ return -1;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ goto cleanup;
+
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ goto cleanup;
+
+ if (!(result = virJSONValueObjectGetObject(reply, "return")))
+ goto cleanup;
+
+ if (!(statusstr = virJSONValueObjectGetString(result, "status"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("incomplete result, failed to get status"));
+ goto cleanup;
+ }
+
+ stats->status = qemuMonitorDumpStatusTypeFromString(statusstr);
+ if (stats->status < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("incomplete result, unknown status string
'%s'"),
+ statusstr);
+ goto cleanup;
+ }
+
+ if (virJSONValueObjectGetNumberUlong(result, "completed",
+ &stats->completed) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("incomplete result, failed to get completed"));
+ goto cleanup;
+ }
+
+ if (virJSONValueObjectGetNumberUlong(result, "total", &stats->total)
< 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("incomplete result, failed to get total"));
+ goto cleanup;
+ }
+
+ ret = 0;
+
+ cleanup:
+ virJSONValueFree(cmd);
+ virJSONValueFree(reply);
+ virJSONValueFree(result);
+ return ret;
+}
+
+
int
qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
const char *capability)
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 739a99293..090e3a144 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -162,6 +162,10 @@ int qemuMonitorJSONGetSpiceMigrationStatus(qemuMonitorPtr mon,
int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon);
+int
+qemuMonitorJSONQueryDump(qemuMonitorPtr mon,
+ qemuMonitorDumpStatsPtr stats);
+
int qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
const char *capability);
--
2.13.6