]> xenbits.xensource.com Git - xen.git/commitdiff
xenstore: make memory report available via XS_CONTROL
authorJuergen Gross <jgross@suse.com>
Fri, 24 Feb 2017 06:21:44 +0000 (07:21 +0100)
committerWei Liu <wei.liu2@citrix.com>
Tue, 28 Feb 2017 10:45:30 +0000 (10:45 +0000)
Add a XS_CONTROL command to xenstored for doing a talloc report to a
file. Right now this is supported by specifying a command line option
when starting xenstored and sending a signal to the daemon to trigger
the report.

To dump the report to the standard log file call:

xenstore-control memreport

To dump the report to a new file call:

xenstore-control memreport <file>

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
tools/xenstore/xenstored_control.c
tools/xenstore/xenstored_core.c
tools/xenstore/xenstored_core.h

index c3587adb3cc09bd8889c507b209d255178c9bbc9..7c149117b1db9dbf8de46a487f5d783a0f14f439 100644 (file)
@@ -76,6 +76,45 @@ static int do_control_logfile(void *ctx, struct connection *conn,
        return 0;
 }
 
+static int do_control_memreport(void *ctx, struct connection *conn,
+                               char **vec, int num)
+{
+       FILE *fp;
+       int fd;
+
+       if (num > 1)
+               return EINVAL;
+
+       if (num == 0) {
+               if (tracefd < 0) {
+                       if (!tracefile)
+                               return EBADF;
+                       fp = fopen(tracefile, "a");
+               } else {
+                       /*
+                        * Use dup() in order to avoid closing the file later
+                        * with fclose() which will release stream resources.
+                        */
+                       fd = dup(tracefd);
+                       if (fd < 0)
+                               return EBADF;
+                       fp = fdopen(fd, "a");
+                       if (!fp)
+                               close(fd);
+               }
+       } else
+               fp = fopen(vec[0], "a");
+
+       if (!fp)
+               return EBADF;
+
+       talloc_report_full(NULL, fp);
+       fclose(fp);
+
+       send_ack(conn, XS_CONTROL);
+       return 0;
+}
+
 static int do_control_print(void *ctx, struct connection *conn,
                            char **vec, int num)
 {
@@ -94,6 +133,7 @@ static struct cmd_s cmds[] = {
        { "check", do_control_check, "" },
        { "log", do_control_log, "on|off" },
        { "logfile", do_control_logfile, "<file>" },
+       { "memreport", do_control_memreport, "[<file>]" },
        { "print", do_control_print, "<string>" },
        { "help", do_control_help, "" },
 };
index 1b79a481b63674f1fe2599907fc17b310a642d99..b1f8fbc08a65daa0951a86dfd2f0142e658789c7 100644 (file)
@@ -76,7 +76,7 @@ static unsigned int nr_fds;
 
 static bool verbose = false;
 LIST_HEAD(connections);
-static int tracefd = -1;
+int tracefd = -1;
 static bool recovery = true;
 static int reopen_log_pipe[2];
 static int reopen_log_pipe0_pollfd_idx = -1;
index d3155683bad1fd7473572813eddeeb6a91076914..92cccb6b8c2511e13adc459a9f30055f3ab8b39e 100644 (file)
@@ -172,6 +172,7 @@ void reopen_log(void);
 void close_log(void);
 
 extern char *tracefile;
+extern int tracefd;
 extern int dom0_domid;
 extern int dom0_event;
 extern int priv_domid;