WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] xl: Add subcommand 'xl dmesg'

To: Keir Fraser <keir.fraser@xxxxxxxxxxxxx>, Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Subject: [Xen-devel] xl: Add subcommand 'xl dmesg'
From: Yu Zhiguo <yuzg@xxxxxxxxxxxxxx>
Date: Thu, 20 May 2010 11:52:56 +0800
Cc: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Wed, 19 May 2010 20:53:29 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 3.0a1 (Windows/2008050715)
Can be used to read and/or clear dmesg buffer.

Signed-off-by: Yu Zhiguo <yuzg@xxxxxxxxxxxxxx>

diff -r 840f269d95fb -r ab11e3eab7cc tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed May 19 22:59:52 2010 +0100
+++ b/tools/libxl/libxl.c       Thu May 20 19:52:13 2010 +0800
@@ -2827,6 +2827,18 @@
     return xc_send_debug_keys(ctx->xch, keys);
 }
 
+int libxl_readconsolering(struct libxl_ctx *ctx, char **pbuffer,
+                          unsigned int *pnr_chars, int clear,
+                          int incremental, uint32_t *pindex)
+{
+    int ret;
+
+    ret = xc_readconsolering(ctx->xch, pbuffer, pnr_chars, clear,
+                             incremental, pindex);
+
+    return ret;
+}
+
 uint32_t libxl_vm_get_start_time(struct libxl_ctx *ctx, uint32_t domid)
 {
     char *dompath = libxl_xs_get_dompath(ctx, domid);
diff -r 840f269d95fb -r ab11e3eab7cc tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Wed May 19 22:59:52 2010 +0100
+++ b/tools/libxl/libxl.h       Thu May 20 19:52:13 2010 +0800
@@ -512,6 +512,9 @@
                        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);
+int libxl_readconsolering(struct libxl_ctx *ctx, char **pbuffer,
+                          unsigned int *pnr_chars, int clear,
+                          int incremental, uint32_t *pindex);
 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 840f269d95fb -r ab11e3eab7cc tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Wed May 19 22:59:52 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Thu May 20 19:52:13 2010 +0800
@@ -3246,6 +3246,66 @@
     exit(0);
 }
 
+int main_dmesg(int argc, char **argv)
+{
+    unsigned int clear = 0, index = 0, incremental = 0;
+    unsigned int count = 16384 + 1, size = count;
+    char *str, *ptr;
+    int opt, ret;
+
+    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;
+        }
+    }
+
+    str = malloc(size);
+    memset(str, 0, size);
+    ret = libxl_readconsolering(&ctx, &str, &count, clear,
+                                incremental, &index);
+    if (ret < 0)
+        goto out;
+
+    while (!incremental && count == size) {
+        size += count - 1;
+        if (size < count)
+            break;
+
+        ptr = realloc(str, size);
+        if (!ptr)
+            break;
+
+        str = ptr + count;
+        count = size - count;
+        ret = libxl_readconsolering(&ctx, &str, &count, clear,
+                                    1, &index);
+        if (ret < 0) {
+            str = ptr;
+            break;
+        }
+
+        count += str - ptr;
+        str = ptr;
+    }
+
+out:
+    printf(str);
+    free(str);
+
+    if (ret)
+        exit(1);
+
+    exit(0);
+}
+
 int main_top(int argc, char **argv)
 {
     int opt;
diff -r 840f269d95fb -r ab11e3eab7cc tools/libxl/xl_cmdimpl.h
--- a/tools/libxl/xl_cmdimpl.h  Wed May 19 22:59:52 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.h  Thu May 20 19:52:13 2010 +0800
@@ -45,6 +45,7 @@
 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 840f269d95fb -r ab11e3eab7cc tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Wed May 19 22:59:52 2010 +0100
+++ b/tools/libxl/xl_cmdtable.c Thu May 20 19:52:13 2010 +0800
@@ -191,6 +191,12 @@
       "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-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>