[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v4 4/6] xenstore: add support for changing log functionality dynamically



Today 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_CONTROL 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>

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
Reviewed-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/xenstore/xenstored_control.c | 34 ++++++++++++++++++++++++++++++++++
 tools/xenstore/xenstored_core.c    | 15 +++++++++++----
 tools/xenstore/xenstored_core.h    |  3 +++
 3 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/tools/xenstore/xenstored_control.c 
b/tools/xenstore/xenstored_control.c
index 3080e47..c3587ad 100644
--- a/tools/xenstore/xenstored_control.c
+++ b/tools/xenstore/xenstored_control.c
@@ -44,6 +44,38 @@ static int do_control_check(void *ctx, struct connection 
*conn,
        return 0;
 }
 
+static int do_control_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_CONTROL);
+       return 0;
+}
+
+static int do_control_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_CONTROL);
+       return 0;
+}
+
 static int do_control_print(void *ctx, struct connection *conn,
                            char **vec, int num)
 {
@@ -60,6 +92,8 @@ static int do_control_help(void *, struct connection *, char 
**, int);
 
 static struct cmd_s cmds[] = {
        { "check", do_control_check, "" },
+       { "log", do_control_log, "on|off" },
+       { "logfile", do_control_logfile, "<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 94c0a1d..1b79a48 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -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,
diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h
index 89c1d75..d315568 100644
--- a/tools/xenstore/xenstored_core.h
+++ b/tools/xenstore/xenstored_core.h
@@ -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;
-- 
2.10.2


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.