[libvirt] [PATCH v6 1/4] add new virDomainCoreDumpWithFormat API

qiaonuohan at cn.fujitsu.com qiaonuohan at cn.fujitsu.com
Sun Mar 16 06:07:07 UTC 2014


--memory-only option is introduced without compression supported. Now qemu has
support dumping domain's memory in kdump-compressed format. This patch is adding
new virDomainCoreDumpWithFormat API, so that the format in which qemu dumps
domain's memory can be specified.

Signed-off-by: Qiao Nuohan <qiaonuohan at cn.fujitsu.com>
---
 include/libvirt/libvirt.h.in |  8 ++++
 src/driver.h                 |  7 ++++
 src/libvirt.c                | 92 ++++++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |  5 +++
 src/remote/remote_driver.c   |  1 +
 src/remote/remote_protocol.x | 15 +++++++-
 src/remote_protocol-structs  |  7 ++++
 src/test/test_driver.c       | 21 ++++++++--
 8 files changed, 152 insertions(+), 4 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 295d551..a0a8722 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1731,6 +1731,14 @@ int                     virDomainCoreDump       (virDomainPtr domain,
                                                  unsigned int flags);
 
 /*
+ * Domain core dump with format specified
+ */
+int                 virDomainCoreDumpWithFormat (virDomainPtr domain,
+                                                 const char *to,
+                                                 const char *dumpformat,
+                                                 unsigned int flags);
+
+/*
  * Screenshot of current domain console
  */
 char *                  virDomainScreenshot     (virDomainPtr domain,
diff --git a/src/driver.h b/src/driver.h
index fbfaac4..784c20b 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -306,6 +306,12 @@ typedef int
                         const char *to,
                         unsigned int flags);
 
+typedef int
+(*virDrvDomainCoreDumpWithFormat)(virDomainPtr domain,
+                                  const char *to,
+                                  const char *dumpformat,
+                                  unsigned int flags);
+
 typedef char *
 (*virDrvDomainScreenshot)(virDomainPtr domain,
                           virStreamPtr stream,
@@ -1200,6 +1206,7 @@ struct _virDriver {
     virDrvDomainSaveImageGetXMLDesc domainSaveImageGetXMLDesc;
     virDrvDomainSaveImageDefineXML domainSaveImageDefineXML;
     virDrvDomainCoreDump domainCoreDump;
+    virDrvDomainCoreDumpWithFormat domainCoreDumpWithFormat;
     virDrvDomainScreenshot domainScreenshot;
     virDrvDomainSetVcpus domainSetVcpus;
     virDrvDomainSetVcpusFlags domainSetVcpusFlags;
diff --git a/src/libvirt.c b/src/libvirt.c
index a385935..57dfa6b 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -2997,6 +2997,98 @@ error:
     return -1;
 }
 
+/**
+ * virDomainCoreDumpWithFormat:
+ * @domain: a domain object
+ * @to: path for the core file
+ * @dumpformat: format of domain memory's dump
+ * @flags: bitwise-OR of virDomainCoreDumpFlags
+ *
+ * This method will dump the core of a domain on a given file for analysis.
+ * Note that for remote Xen Daemon the file path will be interpreted in
+ * the remote host. Hypervisors may require  the user to manually ensure
+ * proper permissions on the file named by @to.
+ *
+ * If @flags includes VIR_DUMP_MEMORY_ONLY and @dumpformat is set, libvirt
+ * will ask qemu dump domain's memory in the format specified by @dumpformat.
+ *
+ * If @flags includes VIR_DUMP_CRASH, then leave the guest shut off with
+ * a crashed state after the dump completes.  If @flags includes
+ * VIR_DUMP_LIVE, then make the core dump while continuing to allow
+ * the guest to run; otherwise, the guest is suspended during the dump.
+ * VIR_DUMP_RESET flag forces reset of the quest after dump.
+ * The above three flags are mutually exclusive.
+ *
+ * Additionally, if @flags includes VIR_DUMP_BYPASS_CACHE, then libvirt
+ * will attempt to bypass the file system cache while creating the file,
+ * or fail if it cannot do so for the given system; this can allow less
+ * pressure on file system cache, but also risks slowing saves to NFS.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virDomainCoreDumpWithFormat(virDomainPtr domain, const char *to, const char
+                            *dumpformat, unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain, "to=%s, dumpformat=%s, flags=%x", to, dumpformat,
+                     flags);
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;
+
+    virCheckReadOnlyGoto(conn->flags, error);
+    virCheckNonNullArgGoto(to, error);
+
+    if ((flags & VIR_DUMP_CRASH) && (flags & VIR_DUMP_LIVE)) {
+        virReportInvalidArg(flags, "%s",
+                            _("crash and live flags are mutually exclusive"));
+        goto error;
+    }
+
+    if ((flags & VIR_DUMP_CRASH) && (flags & VIR_DUMP_RESET)) {
+        virReportInvalidArg(flags, "%s",
+                            _("crash and reset flags are mutually exclusive"));
+        goto error;
+    }
+
+    if ((flags & VIR_DUMP_LIVE) && (flags & VIR_DUMP_RESET)) {
+        virReportInvalidArg(flags, "%s",
+                            _("live and reset flags are mutually exclusive"));
+        goto error;
+    }
+
+    if (conn->driver->domainCoreDumpWithFormat) {
+        int ret;
+        char *absolute_to;
+
+        /* We must absolutize the file path as the save is done out of process */
+        if (virFileAbsPath(to, &absolute_to) < 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("could not build absolute core file path"));
+            goto error;
+        }
+
+        ret = conn->driver->domainCoreDumpWithFormat(domain, absolute_to,
+                                                     dumpformat, flags);
+
+        VIR_FREE(absolute_to);
+
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+
+error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
 
 /**
  * virDomainScreenshot:
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 6ed6ce6..9ab0c92 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -645,5 +645,10 @@ LIBVIRT_1.2.1 {
         virConnectNetworkEventDeregisterAny;
 } LIBVIRT_1.1.3;
 
+LIBVIRT_1.2.3 {
+    global:
+        virDomainCoreDumpWithFormat;
+} LIBVIRT_1.2.1;
+
 
 # .... define new API here using predicted next version number ....
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 955465a..0a15267 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -7516,6 +7516,7 @@ static virDriver remote_driver = {
     .domainSaveImageGetXMLDesc = remoteDomainSaveImageGetXMLDesc, /* 0.9.4 */
     .domainSaveImageDefineXML = remoteDomainSaveImageDefineXML, /* 0.9.4 */
     .domainCoreDump = remoteDomainCoreDump, /* 0.3.0 */
+    .domainCoreDumpWithFormat = remoteDomainCoreDumpWithFormat, /* 1.2.3 */
     .domainScreenshot = remoteDomainScreenshot, /* 0.9.2 */
     .domainSetVcpus = remoteDomainSetVcpus, /* 0.3.0 */
     .domainSetVcpusFlags = remoteDomainSetVcpusFlags, /* 0.8.5 */
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index f1f2359..3f894ee 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -904,6 +904,13 @@ struct remote_domain_core_dump_args {
     unsigned int flags;
 };
 
+struct remote_domain_core_dump_with_format_args {
+    remote_nonnull_domain dom;
+    remote_nonnull_string to;
+    remote_string dumpformat;
+    unsigned int flags;
+};
+
 struct remote_domain_screenshot_args {
     remote_nonnull_domain dom;
     unsigned int screen;
@@ -5262,5 +5269,11 @@ enum remote_procedure {
      * @generate: both
      * @acl: none
      */
-    REMOTE_PROC_DOMAIN_EVENT_CALLBACK_DEVICE_REMOVED = 333
+    REMOTE_PROC_DOMAIN_EVENT_CALLBACK_DEVICE_REMOVED = 333,
+
+    /**
+     * @generate: both
+     * @acl: domain:core_dump
+     */
+    REMOTE_PROC_DOMAIN_CORE_DUMP_WITH_FORMAT = 334
 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 5636d55..c2f7665 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -557,6 +557,12 @@ struct remote_domain_core_dump_args {
         remote_nonnull_string      to;
         u_int                      flags;
 };
+struct remote_domain_core_dump_with_format_args {
+        remote_nonnull_domain      dom;
+        remote_nonnull_string      to;
+        remote_string              dumpformat;
+        u_int                      flags;
+};
 struct remote_domain_screenshot_args {
         remote_nonnull_domain      dom;
         u_int                      screen;
@@ -2755,4 +2761,5 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_EVENT_CALLBACK_BALLOON_CHANGE = 331,
         REMOTE_PROC_DOMAIN_EVENT_CALLBACK_PMSUSPEND_DISK = 332,
         REMOTE_PROC_DOMAIN_EVENT_CALLBACK_DEVICE_REMOVED = 333,
+        REMOTE_PROC_DOMAIN_CORE_DUMP_WITH_FORMAT = 334,
 };
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 6806ffd..2505998 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2427,9 +2427,10 @@ testDomainRestore(virConnectPtr conn,
     return testDomainRestoreFlags(conn, path, NULL, 0);
 }
 
-static int testDomainCoreDump(virDomainPtr domain,
-                              const char *to,
-                              unsigned int flags)
+static int testDomainCoreDumpWithFormat(virDomainPtr domain,
+                                        const char *to,
+                                        const char *dumpformat,
+                                        unsigned int flags)
 {
     testConnPtr privconn = domain->conn->privateData;
     int fd = -1;
@@ -2467,6 +2468,13 @@ static int testDomainCoreDump(virDomainPtr domain,
         goto cleanup;
     }
 
+    /* we don't support dumpformat in test driver */
+    if (dumpformat != NULL) {
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                       _("dumpformat is not supported here"));
+        goto cleanup;
+    }
+
     if (flags & VIR_DUMP_CRASH) {
         testDomainShutdownState(domain, privdom, VIR_DOMAIN_SHUTOFF_CRASHED);
         event = virDomainEventLifecycleNewFromObj(privdom,
@@ -2490,6 +2498,12 @@ cleanup:
     return ret;
 }
 
+static int testDomainCoreDump(virDomainPtr domain,
+                              const char *to,
+                              unsigned int flags) {
+    return testDomainCoreDumpWithFormat(domain, to, NULL, flags);
+}
+
 static char *testDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) {
     char *ret;
 
@@ -7359,6 +7373,7 @@ static virDriver testDriver = {
     .domainRestore = testDomainRestore, /* 0.3.2 */
     .domainRestoreFlags = testDomainRestoreFlags, /* 0.9.4 */
     .domainCoreDump = testDomainCoreDump, /* 0.3.2 */
+    .domainCoreDumpWithFormat = testDomainCoreDumpWithFormat, /* 1.2.3 */
     .domainSetVcpus = testDomainSetVcpus, /* 0.1.4 */
     .domainSetVcpusFlags = testDomainSetVcpusFlags, /* 0.8.5 */
     .domainGetVcpusFlags = testDomainGetVcpusFlags, /* 0.8.5 */
-- 
1.8.5.3




More information about the libvir-list mailing list