This patch makes qemu driver support virDomainCoreDumpWithFormat API.
Signed-off-by: Qiao Nuohan <qiaonuohan(a)cn.fujitsu.com>
---
src/qemu/qemu_driver.c | 50 ++++++++++++++++++++++++++++++++++++--------
src/qemu/qemu_monitor.c | 6 +++---
src/qemu/qemu_monitor.h | 3 ++-
src/qemu/qemu_monitor_json.c | 21 ++++++++++++++-----
src/qemu/qemu_monitor_json.h | 3 ++-
tests/qemumonitorjsontest.c | 2 +-
6 files changed, 65 insertions(+), 20 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9aad2dc..868735c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3389,7 +3389,8 @@ cleanup:
}
static int qemuDumpToFd(virQEMUDriverPtr driver, virDomainObjPtr vm,
- int fd, enum qemuDomainAsyncJob asyncJob)
+ int fd, enum qemuDomainAsyncJob asyncJob,
+ const char *dumpformat)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
int ret = -1;
@@ -3409,7 +3410,20 @@ static int qemuDumpToFd(virQEMUDriverPtr driver, virDomainObjPtr
vm,
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
return -1;
- ret = qemuMonitorDumpToFd(priv->mon, fd);
+ if (dumpformat) {
+ ret = qemuMonitorGetDumpGuestMemoryCapability(priv->mon, dumpformat);
+
+ if (ret <= 0) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("unsupported dumpformat '%s'"),
dumpformat);
+ ret = -1;
+ goto cleanup;
+ }
+ }
+
+ ret = qemuMonitorDumpToFd(priv->mon, fd, dumpformat);
+
+cleanup:
qemuDomainObjExitMonitor(driver, vm);
return ret;
@@ -3420,7 +3434,8 @@ doCoreDump(virQEMUDriverPtr driver,
virDomainObjPtr vm,
const char *path,
virQEMUSaveFormat compress,
- unsigned int dump_flags)
+ unsigned int dump_flags,
+ const char *dumpformat)
{
int fd = -1;
int ret = -1;
@@ -3450,8 +3465,15 @@ doCoreDump(virQEMUDriverPtr driver,
goto cleanup;
if (dump_flags & VIR_DUMP_MEMORY_ONLY) {
- ret = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP);
+ ret = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP,
+ dumpformat);
} else {
+ if (dumpformat != NULL) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+ _("specifying dumpformat is only supported with "
+ "memory-only dump"));
+ goto cleanup;
+ }
ret = qemuMigrationToFile(driver, vm, fd, 0, path,
qemuCompressProgramName(compress), false,
QEMU_ASYNC_JOB_DUMP);
@@ -3513,8 +3535,9 @@ cleanup:
return ret;
}
-static int qemuDomainCoreDump(virDomainPtr dom,
+static int qemuDomainCoreDumpWithFormat(virDomainPtr dom,
const char *path,
+ const char *dumpformat,
unsigned int flags)
{
virQEMUDriverPtr driver = dom->conn->privateData;
@@ -3531,7 +3554,7 @@ static int qemuDomainCoreDump(virDomainPtr dom,
if (!(vm = qemuDomObjFromDomain(dom)))
return -1;
- if (virDomainCoreDumpEnsureACL(dom->conn, vm->def) < 0)
+ if (virDomainCoreDumpWithFormatEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
if (qemuDomainObjBeginAsyncJob(driver, vm,
@@ -3563,7 +3586,8 @@ static int qemuDomainCoreDump(virDomainPtr dom,
}
}
- ret = doCoreDump(driver, vm, path, getCompressionType(driver), flags);
+ ret = doCoreDump(driver, vm, path, getCompressionType(driver), flags,
+ dumpformat);
if (ret < 0)
goto endjob;
@@ -3617,6 +3641,13 @@ cleanup:
return ret;
}
+static int qemuDomainCoreDump(virDomainPtr dom,
+ const char *path,
+ unsigned int flags)
+{
+ return qemuDomainCoreDumpWithFormat(dom, path, NULL, flags);
+}
+
static char *
qemuDomainScreenshot(virDomainPtr dom,
virStreamPtr st,
@@ -3740,7 +3771,7 @@ static void processWatchdogEvent(virQEMUDriverPtr driver,
virDomainObjPtr vm, in
flags |= cfg->autoDumpBypassCache ? VIR_DUMP_BYPASS_CACHE: 0;
ret = doCoreDump(driver, vm, dumpfile,
- getCompressionType(driver), flags);
+ getCompressionType(driver), flags, NULL);
if (ret < 0)
virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("Dump failed"));
@@ -3804,7 +3835,7 @@ doCoreDumpToAutoDumpPath(virQEMUDriverPtr driver,
flags |= cfg->autoDumpBypassCache ? VIR_DUMP_BYPASS_CACHE: 0;
ret = doCoreDump(driver, vm, dumpfile,
- getCompressionType(driver), flags);
+ getCompressionType(driver), flags, NULL);
if (ret < 0)
virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("Dump failed"));
@@ -16625,6 +16656,7 @@ static virDriver qemuDriver = {
.domainSaveImageGetXMLDesc = qemuDomainSaveImageGetXMLDesc, /* 0.9.4 */
.domainSaveImageDefineXML = qemuDomainSaveImageDefineXML, /* 0.9.4 */
.domainCoreDump = qemuDomainCoreDump, /* 0.7.0 */
+ .domainCoreDumpWithFormat = qemuDomainCoreDumpWithFormat, /* 1.2.3 */
.domainScreenshot = qemuDomainScreenshot, /* 0.9.2 */
.domainSetVcpus = qemuDomainSetVcpus, /* 0.4.4 */
.domainSetVcpusFlags = qemuDomainSetVcpusFlags, /* 0.8.5 */
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 8104104..78b0634 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2366,10 +2366,10 @@ int qemuMonitorGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
}
int
-qemuMonitorDumpToFd(qemuMonitorPtr mon, int fd)
+qemuMonitorDumpToFd(qemuMonitorPtr mon, int fd, const char *dumpformat)
{
int ret;
- VIR_DEBUG("mon=%p fd=%d", mon, fd);
+ VIR_DEBUG("mon=%p fd=%d dumpformat=%s", mon, fd, dumpformat);
if (!mon) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
@@ -2389,7 +2389,7 @@ qemuMonitorDumpToFd(qemuMonitorPtr mon, int fd)
if (qemuMonitorSendFileHandle(mon, "dump", fd) < 0)
return -1;
- ret = qemuMonitorJSONDump(mon, "fd:dump");
+ ret = qemuMonitorJSONDump(mon, "fd:dump", dumpformat);
if (ret < 0) {
if (qemuMonitorCloseFileHandle(mon, "dump") < 0)
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 00a6554..603a9f8 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -498,7 +498,8 @@ int qemuMonitorGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
const char *capability);
int qemuMonitorDumpToFd(qemuMonitorPtr mon,
- int fd);
+ int fd,
+ const char *dumpformat);
int qemuMonitorGraphicsRelocate(qemuMonitorPtr mon,
int type,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 2cf706c..ecbcb77 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2701,16 +2701,27 @@ cleanup:
int
qemuMonitorJSONDump(qemuMonitorPtr mon,
- const char *protocol)
+ const char *protocol,
+ const char *dumpformat)
{
int ret;
virJSONValuePtr cmd = NULL;
virJSONValuePtr reply = NULL;
- cmd = qemuMonitorJSONMakeCommand("dump-guest-memory",
- "b:paging", false,
- "s:protocol", protocol,
- NULL);
+ /* when dumpformat is not NULL, "format":"xxx" is added to the
command */
+ if (dumpformat) {
+ cmd = qemuMonitorJSONMakeCommand("dump-guest-memory",
+ "b:paging", false,
+ "s:protocol", protocol,
+ "s:format", dumpformat,
+ NULL);
+ } else {
+ cmd = qemuMonitorJSONMakeCommand("dump-guest-memory",
+ "b:paging", false,
+ "s:protocol", protocol,
+ NULL);
+ }
+
if (!cmd)
return -1;
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 37e9456..f0a53de 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -151,7 +151,8 @@ int qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
const char *capability);
int qemuMonitorJSONDump(qemuMonitorPtr mon,
- const char *protocol);
+ const char *protocol,
+ const char *memory_dump_format);
int qemuMonitorJSONGraphicsRelocate(qemuMonitorPtr mon,
int type,
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index d7da5a8..8e3d0e4 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1154,7 +1154,7 @@ GEN_TEST_FUNC(qemuMonitorJSONSetMigrationDowntime, 1)
GEN_TEST_FUNC(qemuMonitorJSONMigrate, QEMU_MONITOR_MIGRATE_BACKGROUND |
QEMU_MONITOR_MIGRATE_NON_SHARED_DISK |
QEMU_MONITOR_MIGRATE_NON_SHARED_INC, "tcp:localhost:12345")
-GEN_TEST_FUNC(qemuMonitorJSONDump, "dummy_protocol")
+GEN_TEST_FUNC(qemuMonitorJSONDump, "dummy_protocol",
"dummy_dumpformat")
GEN_TEST_FUNC(qemuMonitorJSONGraphicsRelocate, VIR_DOMAIN_GRAPHICS_TYPE_SPICE,
"localhost", 12345, 12346, NULL)
GEN_TEST_FUNC(qemuMonitorJSONAddNetdev, "some_dummy_netdevstr")
--
1.8.5.3