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

[Xen-changelog] [xen-unstable] libxenlight: add console command



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1259578056 0
# Node ID 6864bc03783fed55abdef5f6b34e2efd57cf47d0
# Parent  414af64799998613271ddf14af3c2972b53770a6
libxenlight: add console command

This patch adds "xl console" command similar to "xm console".

Signed-off-by: Tomasz Wroblewski <tomasz.wroblewski@xxxxxxxxxx>
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
Acked-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
 tools/libxl/libxl.c |   15 ++++++++++++++
 tools/libxl/libxl.h |    2 +
 tools/libxl/xl.c    |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 70 insertions(+), 1 deletion(-)

diff -r 414af6479999 -r 6864bc03783f tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Mon Nov 30 10:41:28 2009 +0000
+++ b/tools/libxl/libxl.c       Mon Nov 30 10:47:36 2009 +0000
@@ -470,6 +470,21 @@ int libxl_domain_destroy(struct libxl_ct
         return -1;
     }
     return 0;
+}
+
+int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num)
+{
+    struct stat st;
+    const char *XENCONSOLE = "/usr/lib/xen/bin/xenconsole";
+    char *cmd;
+
+    if (stat(XENCONSOLE, &st) != 0) {
+        XL_LOG(ctx, XL_LOG_ERROR, "could not access %s", XENCONSOLE);
+        return ERROR_FAIL;
+    }
+
+    cmd = libxl_sprintf(ctx, "%s %d --num %d", XENCONSOLE, domid, cons_num);
+    return (system(cmd) != 0) ? ERROR_FAIL : 0;
 }
 
 static char ** libxl_build_device_model_args(struct libxl_ctx *ctx,
diff -r 414af6479999 -r 6864bc03783f tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Mon Nov 30 10:41:28 2009 +0000
+++ b/tools/libxl/libxl.h       Mon Nov 30 10:47:36 2009 +0000
@@ -266,6 +266,8 @@ int libxl_domain_pause(struct libxl_ctx 
 int libxl_domain_pause(struct libxl_ctx *ctx, uint32_t domid);
 int libxl_domain_unpause(struct libxl_ctx *ctx, uint32_t domid);
 
+int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
+
 struct libxl_dominfo * libxl_domain_list(struct libxl_ctx *ctx, int 
*nb_domain);
 xc_dominfo_t * libxl_domain_infolist(struct libxl_ctx *ctx, int *nb_domain);
 
diff -r 414af6479999 -r 6864bc03783f tools/libxl/xl.c
--- a/tools/libxl/xl.c  Mon Nov 30 10:41:28 2009 +0000
+++ b/tools/libxl/xl.c  Mon Nov 30 10:47:36 2009 +0000
@@ -711,6 +711,7 @@ static void help(char *command)
         printf(" pci-list                      list pass-through pci devices 
for a domain\n\n");
         printf(" pause                         pause execution of a 
domain\n\n");
         printf(" unpause                       unpause a paused domain\n\n");
+        printf(" console                       attach to domain's 
console\n\n");
     } else if(!strcmp(command, "create")) {
         printf("Usage: xl create <ConfigFile> [options] [vars]\n\n");
         printf("Create a domain based on <ConfigFile>.\n\n");
@@ -738,7 +739,56 @@ static void help(char *command)
     } else if(!strcmp(command, "destroy")) {
         printf("Usage: xl destroy <Domain>\n\n");
         printf("Terminate a domain immediately.\n\n");
-    }
+    } else if (!strcmp(command, "console")) {
+        printf("Usage: xl console <Domain>\n\n");
+        printf("Attach to domain's console.\n\n");
+    }
+}
+
+void console(char *p, int cons_num)
+{
+    struct libxl_ctx ctx;
+    uint32_t domid;
+
+    libxl_ctx_init(&ctx);
+    libxl_ctx_set_log(&ctx, log_callback, NULL);
+
+    if (libxl_param_to_domid(&ctx, p, &domid) < 0) {
+        fprintf(stderr, "%s is an invalid domain identifier\n", p);
+        exit(2);
+    }
+    libxl_console_attach(&ctx, domid, cons_num);
+}
+
+int main_console(int argc, char **argv)
+{
+    int opt = 0, cons_num = 0;
+    char *p = NULL;
+
+    while ((opt = getopt(argc, argv, "hn:")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("console");
+            exit(0);
+        case 'n':
+            if (optarg) {
+                cons_num = strtol(optarg, NULL, 10);
+            }
+            break;
+        default:
+            fprintf(stderr, "option not supported\n");
+            break;
+        }
+    }
+    if (optind >= argc) {
+        help("console");
+        exit(2);
+    }
+
+    p = argv[optind];
+
+    console(p, cons_num);
+    exit(0);
 }
 
 void pcilist(char *dom)
@@ -1117,6 +1167,8 @@ int main(int argc, char **argv)
         main_pause(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "unpause")) {
         main_unpause(argc - 1, argv + 1);
+    } else if (!strcmp(argv[1], "console")) {
+        main_console(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "help")) {
         if (argc > 2)
             help(argv[2]);

_______________________________________________
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®.