[Xen-devel] [PATCH]: Implement xl dump-core

Gianni Tedesco
Mon, 19 Jul 2010 14:23:46 -0000

Implements dump-core command which is similar to xm dump-core except
that it requires an additional argument which is the target filename.

 libxl.c            |    7 +++++++
 libxl.h            |    2 ++
 xl.h               |    1 +
 xl_cmdimpl.c       |   18 ++++++++++++++++++
 xl_cmdtable.c      |    5 +++++
 6 files changed, 35 insertions(+), 2 deletions(-)

Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com>

diff -r 12f0618400de tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Jul 16 13:54:44 2010 +0100
+++ b/tools/libxl/libxl.c	Mon Jul 19 15:22:06 2010 +0100
@@ -523,6 +523,13 @@
     return 0;
 }

+int libxl_domain_core_dump(struct libxl_ctx *ctx, uint32_t domid, const char
*filename)
+{
+    if ( xc_domain_dumpcore(ctx->xch, domid, filename) )
+        return ERROR_FAIL;
+    return 0;
+}
+
 int libxl_domain_unpause(struct libxl_ctx *ctx, uint32_t domid)
 {
     char *path;
diff -r 12f0618400de tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Fri Jul 16 13:54:44 2010 +0100
+++ b/tools/libxl/libxl.h	Mon Jul 19 15:22:06 2010 +0100
@@ -395,6 +395,8 @@
 int libxl_domain_pause(struct libxl_ctx *ctx, uint32_t domid);
 int libxl_domain_unpause(struct libxl_ctx *ctx, uint32_t domid);

+int libxl_domain_core_dump(struct libxl_ctx *ctx, uint32_t domid, const char
*filename);
+
 int libxl_domain_setmaxmem(struct libxl_ctx *ctx, uint32_t domid, uint32_t
target_memkb);
 int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t
target_memkb, int enforce);

diff -r 12f0618400de tools/libxl/xl.h
--- a/tools/libxl/xl.h	Fri Jul 16 13:54:44 2010 +0100
+++ b/tools/libxl/xl.h	Mon Jul 19 15:22:06 2010 +0100
@@ -37,6 +37,7 @@
 int main_migrate_receive(int argc, char **argv);
 int main_save(int argc, char **argv);
 int main_migrate(int argc, char **argv);
+int main_dump_core(int argc, char **argv);
 int main_pause(int argc, char **argv);
 int main_unpause(int argc, char **argv);
 int main_destroy(int argc, char **argv);
diff -r 12f0618400de tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri Jul 16 13:54:44 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Mon Jul 19 15:22:06 2010 +0100
@@ -2262,6 +2262,14 @@
     exit(-ERROR_BADFAIL);
 }

+static void core_dump_domain(const char *domain_spec, const char *filename)
+{
+    int rc;
+    find_domain(domain_spec);
+    rc=libxl_domain_core_dump(&ctx, domid, filename);
+    if (rc) { fprintf(stderr,"core dump failed
(rc=%d)\n.",rc);exit(-1); }
+}
+
 static void migrate_receive(int debug, int daemonize)
 {
     int rc, rc2;
@@ -2531,6 +2539,16 @@
     exit(0);
 }

+int main_dump_core(int argc, char **argv)
+{
+    if ( argc-optind < 2 ) {
+        help("dump-core");
+        exit(2);
+    }
+    core_dump_domain(argv[optind], argv[optind + 1]);
+    exit(0);
+}
+
 int main_pause(int argc, char **argv)
 {
     int opt;
diff -r 12f0618400de tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c	Fri Jul 16 13:54:44 2010 +0100
+++ b/tools/libxl/xl_cmdtable.c	Mon Jul 19 15:22:06 2010 +0100
@@ -102,6 +102,11 @@
       "-e              Do not wait in the background (on <host>) for
the death\n"
       "                of the domain."
     },
+    { "dump-core",
+      &main_dump_core,
+      "Core dump a domain",
+      "<Domain> <filename>"
+    },
     { "restore",
       &main_restore,
       "Restore a domain from a saved state",