From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>,
wei.liu2@citrix.com, ian.jackson@eu.citrix.com
Subject: [PATCH v4 5/6] xenstore: make memory report available via XS_CONTROL
Date: Fri, 24 Feb 2017 07:21:44 +0100 [thread overview]
Message-ID: <20170224062145.2041-6-jgross@suse.com> (raw)
In-Reply-To: <20170224062145.2041-1-jgross@suse.com>
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 | 40 ++++++++++++++++++++++++++++++++++++++
tools/xenstore/xenstored_core.c | 2 +-
tools/xenstore/xenstored_core.h | 1 +
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_control.c
index c3587ad..7c14911 100644
--- a/tools/xenstore/xenstored_control.c
+++ b/tools/xenstore/xenstored_control.c
@@ -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, "" },
};
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 1b79a48..b1f8fbc 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -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;
diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h
index d315568..92cccb6 100644
--- a/tools/xenstore/xenstored_core.h
+++ b/tools/xenstore/xenstored_core.h
@@ -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;
--
2.10.2
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-02-24 6:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-24 6:21 [PATCH v4 0/6] xenstore: enhance runtime debug capabilities Juergen Gross
2017-02-24 6:21 ` [PATCH v4 1/6] xenstore: rename XS_DEBUG wire command Juergen Gross
2017-02-24 6:21 ` [PATCH v4 2/6] xenstore: Split out XS_CONTROL action to dedicated source file Juergen Gross
2017-02-24 6:21 ` [PATCH v4 3/6] xenstore: enhance control command support Juergen Gross
2017-02-24 10:02 ` Wei Liu
2017-02-24 6:21 ` [PATCH v4 4/6] xenstore: add support for changing log functionality dynamically Juergen Gross
2017-02-24 6:21 ` Juergen Gross [this message]
2017-02-24 6:21 ` [PATCH v4 6/6] xenstore: remove memory report command line support Juergen Gross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170224062145.2041-6-jgross@suse.com \
--to=jgross@suse.com \
--cc=ian.jackson@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).