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

[Xen-changelog] [xen-unstable] xl: Add subcommand 'xl dmesg'



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1274856351 -3600
# Node ID f31030d32fe53f143324eca587a0b9052a73c110
# Parent  10ad9b50b4ca85d4ff19d87ffb6e66b0472c4926
xl: Add subcommand 'xl dmesg'

Can be used to read and/or clear dmesg buffer.

Signed-off-by: Yu Zhiguo <yuzg@xxxxxxxxxxxxxx>
---
 tools/libxl/libxl.c       |   66 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl.h       |   18 ++++++++++++
 tools/libxl/xl_cmdimpl.c  |   38 ++++++++++++++++++++++++++
 tools/libxl/xl_cmdimpl.h  |    1 
 tools/libxl/xl_cmdtable.c |    6 ++++
 5 files changed, 129 insertions(+)

diff -r 10ad9b50b4ca -r f31030d32fe5 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Tue May 25 11:28:58 2010 +0100
+++ b/tools/libxl/libxl.c       Wed May 26 07:45:51 2010 +0100
@@ -2827,6 +2827,72 @@ int libxl_send_debug_keys(struct libxl_c
     return xc_send_debug_keys(ctx->xch, keys);
 }
 
+struct libxl_xen_console_reader *
+    libxl_xen_console_read_start(struct libxl_ctx *ctx, int clear)
+{
+    struct libxl_xen_console_reader *cr;
+    unsigned int size = 16384;
+    char *buf = malloc(size);
+
+    if (!buf) {
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "cannot malloc buffer for 
libxl_xen_console_reader,"
+            " size is %u", size);
+        return NULL;
+    }
+
+    cr = malloc(sizeof(struct libxl_xen_console_reader));
+    if (!cr) {
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "cannot malloc 
libxl_xen_console_reader");
+        return NULL;
+    }
+
+    memset(cr, 0, sizeof(struct libxl_xen_console_reader));
+    cr->buffer = buf;
+    cr->size = size;
+    cr->count = size;
+    cr->clear = clear;
+    cr->incremental = 1;
+
+    return cr;
+}
+
+/* return values:                                          *line_r
+ *   1          success, whole line obtained from buffer    non-0
+ *   0          no more lines available right now           0
+ *   negative   error code ERROR_*                          0
+ * On success *line_r is updated to point to a nul-terminated
+ * string which is valid until the next call on the same console
+ * reader.  The libxl caller may overwrite parts of the string
+ * if it wishes. */
+int libxl_xen_console_read_line(struct libxl_ctx *ctx,
+                                struct libxl_xen_console_reader *cr,
+                                char **line_r)
+{
+    int ret;
+
+    memset(cr->buffer, 0, cr->size);
+    ret = xc_readconsolering(ctx->xch, &cr->buffer, &cr->count,
+                             cr->clear, cr->incremental, &cr->index);
+    if (!ret) {
+        if (cr->count) {
+            *line_r = cr->buffer;
+            ret = 1;
+        } else {
+            *line_r = NULL;
+            ret = 0;
+        }
+    }
+
+    return ret;
+}
+
+void libxl_xen_console_read_finish(struct libxl_ctx *ctx,
+                                   struct libxl_xen_console_reader *cr)
+{
+    free(cr->buffer);
+    free(cr);
+}
+
 uint32_t libxl_vm_get_start_time(struct libxl_ctx *ctx, uint32_t domid)
 {
     char *dompath = libxl_xs_get_dompath(ctx, domid);
diff -r 10ad9b50b4ca -r f31030d32fe5 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Tue May 25 11:28:58 2010 +0100
+++ b/tools/libxl/libxl.h       Wed May 26 07:45:51 2010 +0100
@@ -512,6 +512,24 @@ int libxl_send_trigger(struct libxl_ctx 
                        char *trigger_name, uint32_t vcpuid);
 int libxl_send_sysrq(struct libxl_ctx *ctx, uint32_t domid, char sysrq);
 int libxl_send_debug_keys(struct libxl_ctx *ctx, char *keys);
+
+struct libxl_xen_console_reader {
+    char *buffer;
+    unsigned int size;
+    unsigned int count;
+    unsigned int clear;
+    unsigned int incremental;
+    unsigned int index;
+};
+
+struct libxl_xen_console_reader *
+    libxl_xen_console_read_start(struct libxl_ctx *ctx, int clear);
+int libxl_xen_console_read_line(struct libxl_ctx *ctx,
+                                struct libxl_xen_console_reader *cr,
+                                char **line_r);
+void libxl_xen_console_read_finish(struct libxl_ctx *ctx,
+                                   struct libxl_xen_console_reader *cr);
+
 uint32_t libxl_vm_get_start_time(struct libxl_ctx *ctx, uint32_t domid);
 
 char *libxl_tmem_list(struct libxl_ctx *ctx, uint32_t domid, int use_long);
diff -r 10ad9b50b4ca -r f31030d32fe5 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Tue May 25 11:28:58 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Wed May 26 07:45:51 2010 +0100
@@ -3246,6 +3246,44 @@ int main_debug_keys(int argc, char **arg
     exit(0);
 }
 
+int main_dmesg(int argc, char **argv)
+{
+    unsigned int clear = 0;
+    struct libxl_xen_console_reader *cr;
+    char *line;
+    int opt, ret = 1;
+
+    while ((opt = getopt(argc, argv, "hc")) != -1) {
+        switch (opt) {
+        case 'c':
+            clear = 1;
+            break;
+        case 'h':
+            help("dmesg");
+            exit(0);
+        default:
+            fprintf(stderr, "option not supported\n");
+            break;
+        }
+    }
+
+    cr = libxl_xen_console_read_start(&ctx, clear);
+    if (!cr)
+        goto finish;
+
+    while (1) {
+        ret = libxl_xen_console_read_line(&ctx, cr, &line);
+        if (ret > 0)
+            printf(line);
+        else
+            break;
+    }
+
+finish:
+    libxl_xen_console_read_finish(&ctx, cr);
+    exit(ret);
+}
+
 int main_top(int argc, char **argv)
 {
     int opt;
diff -r 10ad9b50b4ca -r f31030d32fe5 tools/libxl/xl_cmdimpl.h
--- a/tools/libxl/xl_cmdimpl.h  Tue May 25 11:28:58 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.h  Wed May 26 07:45:51 2010 +0100
@@ -45,6 +45,7 @@ int main_trigger(int argc, char **argv);
 int main_trigger(int argc, char **argv);
 int main_sysrq(int argc, char **argv);
 int main_debug_keys(int argc, char **argv);
+int main_dmesg(int argc, char **argv);
 int main_top(int argc, char **argv);
 int main_networkattach(int argc, char **argv);
 int main_networklist(int argc, char **argv);
diff -r 10ad9b50b4ca -r f31030d32fe5 tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Tue May 25 11:28:58 2010 +0100
+++ b/tools/libxl/xl_cmdtable.c Wed May 26 07:45:51 2010 +0100
@@ -191,6 +191,12 @@ struct cmd_spec cmd_table[] = {
       "Send debug keys to Xen",
       "<Keys>",
     },
+    { "dmesg",
+      &main_dmesg,
+      "Read and/or clear dmesg buffer",
+      "[-c]",
+      "  -c                        Clear dmesg buffer as well as printing it",
+    },
     { "top",
       &main_top,
       "Monitor a host and the domains in real time",

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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