xenstore: enhance runtime debug capabilities
cover xenstore: enhance runtime debug capabilities
Today xenstored supports logging only via a command line parameter. This means that logging is either all the time off (default) or on. To switch logging on the Xen host has to be rebooted as xenstored isn't restartable.
This patch series changes this by using the XS_DEBUG wire command of Xenstore to control various debug functions:
- switch logging on/off
- specify logfile to use
- write memory usage to file
This will enable the host administrator to control above functionality without the need of specifying any additional command line parameters of xenstored or to restart the host in case of debug information needed.
Juergen Gross (4):
xenstore: enhance debug command support
xenstore: add support for changing log functionality dynamically
xenstore: make memory report available via XS_DEBUG
xenstore: remove memory report command line support
tools/xenstore/Makefile | 4 +- tools/xenstore/xenstore_control.c | 65 +++++++++---- tools/xenstore/xenstored_core.c | 81 ++++------------ tools/xenstore/xenstored_core.h | 6 +- tools/xenstore/xenstored_debug.c | 194 ++++++++++++++++++++++++++++++++++++++ tools/xenstore/xenstored_debug.h | 19 ++++ tools/xenstore/xs.c | 1 - 7 files changed, 284 insertions(+), 86 deletions(-) create mode 100644 tools/xenstore/xenstored_debug.c create mode 100644 tools/xenstore/xenstored_debug.h
Signature · 7 lines
2.10.2 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/4 xenstore: enhance debug command support
The Xenstore protocol supports the XS_DEBUG command for triggering various actions in the Xenstore daemon. Enhance that support by using a command table and adding a help function. Move all the XS_DEBUG related code to a new source file xenstored_debug.c.
Support multiple debug commands in the associated xenstore-control program used to issue XS_DEBUG commands.
--- tools/xenstore/Makefile | 4 +- tools/xenstore/xenstore_control.c | 65 ++++++++++++++------ tools/xenstore/xenstored_core.c | 29 +-------- tools/xenstore/xenstored_core.h | 2 +- tools/xenstore/xenstored_debug.c | 124 ++++++++++++++++++++++++++++++++++++++ tools/xenstore/xenstored_debug.h | 19 ++++++ tools/xenstore/xs.c | 1 - 7 files changed, 196 insertions(+), 48 deletions(-) create mode 100644 tools/xenstore/xenstored_debug.c create mode 100644 tools/xenstore/xenstored_debug.h
tools/xenstore/Makefile +3 -1
@@ -23,7 +23,9 @@ LDFLAGS += $(LDFLAGS-y) CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod CLIENTS += xenstore-write xenstore-ls xenstore-watch -XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o hashtable.o +XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o +XENSTORED_OBJS += xenstored_transaction.o xenstored_debug.o +XENSTORED_OBJS += xs_lib.o talloc.o utils.o tdb.o hashtable.o XENSTORED_OBJS_$(CONFIG_Linux) = xenstored_posix.o XENSTORED_OBJS_$(CONFIG_SunOS) = xenstored_solaris.o xenstored_posix.o xenstored_probes.o
tools/xenstore/xenstore_control.c +46 -19
75 lines not on this page · raw message
tools/xenstore/xenstored_core.c +3 -26
@@ -51,6 +51,7 @@#include "xenstored_watch.h" #include "xenstored_transaction.h" #include "xenstored_domain.h" +#include "xenstored_debug.h" #include "tdb.h" #include "hashtable.h"
@@ -84,7 +85,6 @@ static TDB_CONTEXT *tdb_ctx = NULL;static bool trigger_talloc_report = false;static void corrupt (struct connection *conn,const char *fmt, ...); -static void check_store (void );static const char *sockmsg_string (enum xsd_sockmsg_type type);#define log (...) \
@@ -1261,34 +1261,11 @@ static int do_set_perms(struct connection *conn, struct buffered_data *in)return 0 ; } -static int do_debug (struct connection *conn,struct buffered_data *in) -{ -int num; - -if (conn->id !=0 ) -return EACCES ; - - num =xs_count_strings (in->buffer, in->used); - -if (streq (in->buffer,"print" )) { -if (num <2 ) -return EINVAL ; -xprintf ("debug: %s" , in->buffer +get_string (in,0 )); - } - -if (streq (in->buffer,"check" )) -check_store (); - -send_ack (conn,XS_DEBUG ); - -return 0 ; -} -static struct {const char *str;int (*func)(struct connection *conn,struct buffered_data *in); }const wire_funcs[XS_TYPE_COUNT ] = { - [XS_DEBUG ] = {"DEBUG" , do_debug }, + [XS_DEBUG ] = {"DEBUG" , do_xs_debug }, [XS_DIRECTORY ] = {"DIRECTORY" , send_directory }, [XS_READ ] = {"READ" , do_read }, [XS_GET_PERMS ] = {"GET_PERMS" , do_get_perms },
@@ -1764,7 +1741,7 @@ static void clean_store(struct hashtable *reachable) } -static void check_store (void ) +void check_store (void ) {char * root =talloc_strdup (NULL ,"/" ); struct hashtable * reachable =
tools/xenstore/xenstored_core.h +1 -1
@@ -158,7 +158,7 @@ TDB_CONTEXT *tdb_context(struct connection *conn);bool replace_tdb (const char *newname,TDB_CONTEXT *newtdb);struct connection *new_connection (connwritefn_t *write,connreadfn_t *read); - +void check_store (void );/* Is this a valid node name? */ bool is_valid_nodename (const char *node);
tools/xenstore/xenstored_debug.c new file +124 -0
124 lines not on this page · raw message
tools/xenstore/xenstored_debug.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +Interactive commands for Xen Store Daemon. +Copyright (C) 2017 Juergen Gross, SUSE Linux GmbH + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +int do_xs_debug (struct connection *conn,struct buffered_data *in);
tools/xenstore/xs.c +0 -1
@@ -1165,7 +1165,6 @@ out:return port; } -/* Only useful for DEBUG versions */ char *xs_debug_command (struct xs_handle *h,const char *cmd,void *data,unsigned int len) {
Signature · 7 lines
2.10.2 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 2/4 xenstore: add support for changing log functionality dynamically
In reply to Juergen GrossToday Xenstore supports logging only if specified at start of the Xenstore daemon. As it can't be disabled during runtime it is not recommended to start xenstored with logging enabled.
Add support for switching logging on and off at runtime and to specify a (new) logfile. This is done via the XS_DEBUG wire command which can be sent with xenstore-control.
To switch logging on just use:
xenstore-control log on
To switch it off again:
xenstore-control log off
To specify a (new) logfile:
xenstore-control logfile <file>
--- tools/xenstore/xenstored_core.c | 15 +++++++++++---- tools/xenstore/xenstored_core.h | 3 +++ tools/xenstore/xenstored_debug.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-)
tools/xenstore/xenstored_core.c +11 -4
@@ -80,7 +80,7 @@ static int tracefd = -1;static bool recovery = true;static int reopen_log_pipe[2 ];static int reopen_log_pipe0_pollfd_idx =-1 ; -static char *tracefile =NULL ; +char *tracefile =NULL ;static TDB_CONTEXT *tdb_ctx =NULL ;static bool trigger_talloc_report = false;
@@ -205,12 +205,17 @@ static void trigger_reopen_log(int signal __attribute__((unused))) dummy =write (reopen_log_pipe[1 ], &c,1 ); } +void close_log (void ) +{ +if (tracefd >0 ) +close (tracefd); + tracefd =-1 ; +} -static void reopen_log (void ) +void reopen_log (void ) {if (tracefile) { -if (tracefd >0 ) -close (tracefd); +close_log (); tracefd =open (tracefile,O_WRONLY |O_CREAT |O_APPEND ,0600 );
@@ -2030,6 +2035,8 @@ int main(int argc, char *argv[])finish_daemonize ();signal (SIGHUP , trigger_reopen_log); +if (tracefile) + tracefile =talloc_strdup (NULL , tracefile);/* Get ready to listen to the tools. */ initialize_fds(*sock, &sock_pollfd_idx, *ro_sock, &ro_sock_pollfd_idx,
tools/xenstore/xenstored_core.h +3 -0
@@ -168,7 +168,10 @@ void trace_create(const void *data, const char *type);void trace_destroy (const void *data,const char *type);void trace (const char *fmt, ...);void dtrace_io (const struct connection *conn,const struct buffered_data *data,int out); +void reopen_log (void ); +void close_log (void ); +extern char *tracefile;extern int dom0_domid;extern int dom0_event;extern int priv_domid;
tools/xenstore/xenstored_debug.c +34 -0
@@ -44,6 +44,38 @@ static int do_debug_check(void *ctx, struct connection *conn,return 0 ; } +static int do_debug_log (void *ctx,struct connection *conn, +char **vec,int num) +{ +if (num !=1 ) +return EINVAL ; + +if (!strcmp (vec[0 ],"on" )) +reopen_log (); +else if (!strcmp (vec[0 ],"off" )) +close_log (); +else +return EINVAL ; + +send_ack (conn,XS_DEBUG ); +return 0 ; +} + +static int do_debug_logfile (void *ctx,struct connection *conn, +char **vec,int num) +{ +if (num !=1 ) +return EINVAL ; + +close_log (); +talloc_free (tracefile); + tracefile =talloc_strdup (NULL , vec[0 ]); +reopen_log (); + +send_ack (conn,XS_DEBUG ); +return 0 ; +} +static int do_debug_print (void *ctx,struct connection *conn,char **vec,int num) {
@@ -60,6 +92,8 @@ static int do_debug_help(void *, struct connection *, char **, int);static struct cmd_s cmds[] = { {"check" , do_debug_check,"" }, + {"log" , do_debug_log,"on|off" }, + {"logfile" , do_debug_logfile,"<file>" }, {"print" , do_debug_print,"<string>" }, {"help" , do_debug_help,"" }, };
Signature · 7 lines
2.10.2 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 3/4 xenstore: make memory report available via XS_DEBUG
In reply to Juergen GrossAdd a XS_DEBUG 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>
--- tools/xenstore/xenstored_core.c | 2 +- tools/xenstore/xenstored_core.h | 1 + tools/xenstore/xenstored_debug.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-)
tools/xenstore/xenstored_core.c +1 -1
@@ -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 ;
tools/xenstore/xenstored_core.h +1 -0
@@ -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;
tools/xenstore/xenstored_debug.c +36 -0
@@ -76,6 +76,41 @@ static int do_debug_logfile(void *ctx, struct connection *conn,return 0 ; } +static int do_debug_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 { + 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_DEBUG ); +return 0 ; +} +static int do_debug_print (void *ctx,struct connection *conn,char **vec,int num) {
@@ -94,6 +129,7 @@ static struct cmd_s cmds[] = { { "check", do_debug_check, "" }, { "log", do_debug_log, "on|off" }, { "logfile", do_debug_logfile, "<file>" }, + { "memreport", do_debug_memreport, "[<file>]" }, { "print", do_debug_print, "<string>" }, { "help", do_debug_help, "" }, };
Signature · 7 lines
2.10.2 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 3/4] xenstore: make memory report available via XS_DEBUG
Quoted 5 lines · Juergen Gross
Add a
XS_DEBUGcommand 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.
Quoted 8 lines
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>
I think this should be named xenstore-debug to match the wire command name.
(Will review this series in detail later)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 3/4] xenstore: make memory report available via XS_DEBUG
Quoted 8 lines · Wei Liu
Quoted 7 lines · Juergen Gross
Add a
XS_DEBUGcommand 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:
Quoted 8 lines
Quoted 6 lines
xenstore-control memreport
To dump the report to a new file call:
xenstore-control memreport <file>
I think this should be named xenstore-debug to match the wire command name.
So you think I should rename the already existing program?
BTW: I'd rather rename XS_DEBUG to XS_CONTROL (or make that an alias to XS_DEBUG), as I think there are more useful ways to control xenstore behavior, e.g. by modifying quota (per domain or globally).
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 3/4] xenstore: make memory report available via XS_DEBUG
Quoted 11 lines · Juergen Gross
Quoted 10 lines · Wei Liu
Quoted 9 lines · Juergen Gross
Add a
XS_DEBUGcommand 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
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
To dump the report to a new file call:
xenstore-control memreport <file>
I think this should be named xenstore-debug to match the wire command name.
So you think I should rename the already existing program?
Oops. No.
Quoted 5 lines
BTW: I'd rather rename
XS_DEBUGtoXS_CONTROL(or make that an alias toXS_DEBUG), as I think there are more useful ways to control xenstore behavior, e.g. by modifying quota (per domain or globally).
Yes, this is better.
We should rename XS_DEBUG to XS_CONTROL and then
#define XS_DEBUG XS_CONTROL
in header file.
Quoted 2 lines
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 4/4 xenstore: remove memory report command line support
In reply to Juergen GrossAs a memory report can now be triggered via XS_DEBUG support via command line and signal handler is no longer needed. Remove it.
--- tools/xenstore/xenstored_core.c | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-)
tools/xenstore/xenstored_core.c +2 -33
@@ -82,7 +82,6 @@ static int reopen_log_pipe[2];static int reopen_log_pipe0_pollfd_idx =-1 ;char *tracefile =NULL ;static TDB_CONTEXT *tdb_ctx =NULL ; -static bool trigger_talloc_report = false;static void corrupt (struct connection *conn,const char *fmt, ...);static const char *sockmsg_string (enum xsd_sockmsg_type type);
@@ -1792,10 +1791,6 @@ static void init_sockets(int **psock, int **pro_sock)static int minus_one =-1 ; *psock = *pro_sock = &minus_one; } - -static void do_talloc_report (int sig) -{ -}#else static int destroy_fd (void *_fd) {
@@ -1855,11 +1850,6 @@ static void init_sockets(int **psock, int **pro_sock) } - -static void do_talloc_report (int sig) -{ - trigger_talloc_report = true; -}#endif static void usage (void )
@@ -1884,7 +1874,6 @@ static void usage(void)" -R, --no-recovery to request that no recovery should be attempted when\n" " the store is corrupted (debug only),\n" " -I, --internal-db store database in memory, not on disk\n" -" -M, --memory-debug <file> support memory debugging to file,\n" " -V, --verbose to request verbose execution.\n"); }
@@ -1906,7 +1895,6 @@ static struct option options[] = { { "internal-db", 0, NULL, 'I' }, { "verbose", 0, NULL, 'V' }, { "watch-nb", 1, NULL, 'W' }, - { "memory-debug", 1, NULL, 'M' }, { NULL, 0, NULL, 0 } };extern void dump_conn (struct connection *conn);
@@ -1922,11 +1910,10 @@ int main(int argc, char *argv[])bool outputpid = false;bool no_domain_init = false;const char *pidfile =NULL ; -const char *memfile =NULL ;int timeout; -while ((opt =getopt_long (argc, argv,"DE:F:HNPS:t:T:RVW:M:" , options, +while ((opt =getopt_long (argc, argv,"DE:F:HNPS:t:T:RVW:" , options,NULL )) !=-1 ) {switch (opt) {case 'D' :
@@ -1977,9 +1964,6 @@ int main(int argc, char *argv[])case 'p' : priv_domid =strtol (optarg,NULL ,10 );break ; -case 'M' : - memfile = optarg; -break ; } }if (optind != argc)
@@ -2006,10 +1990,7 @@ int main(int argc, char *argv[])/* Don't kill us with SIGPIPE. */ signal (SIGPIPE ,SIG_IGN ); -if (memfile) { -talloc_enable_null_tracking (); -signal (SIGUSR1 , do_talloc_report); - } +talloc_enable_null_tracking ();init_sockets (&sock, &ro_sock);
@@ -2054,18 +2035,6 @@ int main(int argc, char *argv[])for (;;) {struct connection *conn, *next; -if (trigger_talloc_report) { -FILE *out; - -assert (memfile); - trigger_talloc_report = false; - out =fopen (memfile,"a" ); -if (out) { -talloc_report_full (NULL , out); -fclose (out); - } - } -if (poll (fds, nr_fds, timeout) <0 ) {if (errno ==EINTR )continue ;
Signature · 7 lines
2.10.2 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel