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

[Xen-changelog] [xen-unstable] xl: network2-list command



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1275891075 -3600
# Node ID a08a8256e997cfbccca94d9470f44434ddbdd4a5
# Parent  112f706e1d481dd25a5088c3faf5647950bbe630
xl: network2-list command

Usage: xl network2-list <Domains>

Signed-off-by: Eric Chanudet <eric.chanudet@xxxxxxxxxx>
---
 tools/libxl/libxl.c       |   63 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl.h       |   15 ++++++++++
 tools/libxl/xl.h          |    1 
 tools/libxl/xl_cmdimpl.c  |   45 ++++++++++++++++++++++++++++++++
 tools/libxl/xl_cmdtable.c |    5 +++
 5 files changed, 129 insertions(+)

diff -r 112f706e1d48 -r a08a8256e997 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Mon Jun 07 07:09:41 2010 +0100
+++ b/tools/libxl/libxl.c       Mon Jun 07 07:11:15 2010 +0100
@@ -1693,6 +1693,69 @@ int libxl_device_net2_add(struct libxl_c
     flexarray_free(front);
     return 0;
 }
+
+libxl_net2info *libxl_device_net2_list(struct libxl_ctx *ctx, uint32_t domid, 
unsigned int *nb)
+{
+    char *dompath, *net2_path_fe;
+    char **l;
+    char *val, *tok;
+    unsigned int nb_net2s, i;
+    libxl_net2info *res, *net2s;
+
+    dompath = libxl_xs_get_dompath(ctx, domid);
+    if (!dompath) {
+        return NULL;
+    }
+    l = libxl_xs_directory(ctx, XBT_NULL,
+                           libxl_sprintf(ctx, "%s/device/vif2", dompath), 
&nb_net2s);
+    if (!l) {
+        return NULL;
+    }
+    res = libxl_calloc(ctx, nb_net2s, sizeof (libxl_net2info));
+    if (!res) {
+        libxl_free(ctx, l);
+        return NULL;
+    }
+    net2s = res;
+    for (*nb = nb_net2s; nb_net2s > 0; --nb_net2s, ++l, ++net2s) {
+        net2_path_fe = libxl_sprintf(ctx, "%s/device/vif2/%s", dompath, *l);
+
+        net2s->backend = libxl_xs_read(ctx, XBT_NULL,
+                                       libxl_sprintf(ctx, "%s/backend", 
net2_path_fe));
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/backend-id", 
net2_path_fe));
+        net2s->backend_id = val ? strtoul(val, NULL, 10) : -1;
+
+        net2s->devid = strtoul(*l, NULL, 10);
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/state", 
net2_path_fe));
+        net2s->state = val ? strtoul(val, NULL, 10) : -1;
+
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/mac", 
net2_path_fe));
+        for (i = 0, tok = strtok(val, ":"); tok && (i < 6);
+             ++i, tok = strtok(NULL, ":")) {
+            net2s->mac[i] = strtoul(tok, NULL, 16);
+        }
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, 
"%s/remote-trusted", net2_path_fe));
+        net2s->trusted = val ? strtoul(val, NULL, 10) : -1;
+
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/remote-mac", 
net2_path_fe));
+        for (i = 0, tok = strtok(val, ":"); tok && (i < 6);
+             ++i, tok = strtok(NULL, ":")) {
+            net2s->back_mac[i] = strtoul(tok, NULL, 16);
+        }
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/filter-mac", 
net2_path_fe));
+        net2s->filter_mac = val ? strtoul(val, NULL, 10) : -1;
+
+        net2s->frontend = libxl_xs_read(ctx, XBT_NULL,
+                                        libxl_sprintf(ctx, "%s/frontend", 
net2s->backend));
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, 
"%s/frontend-id", net2s->backend));
+        net2s->frontend_id = val ? strtoul(val, NULL, 10) : -1;
+        libxl_free(ctx, net2_path_fe);
+    }
+
+    libxl_free(ctx, l);
+    return res;
+}
+
 
 
/******************************************************************************/
 int libxl_device_console_add(struct libxl_ctx *ctx, uint32_t domid, 
libxl_device_console *console)
diff -r 112f706e1d48 -r a08a8256e997 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Mon Jun 07 07:09:41 2010 +0100
+++ b/tools/libxl/libxl.h       Mon Jun 07 07:11:15 2010 +0100
@@ -554,8 +554,23 @@ int libxl_tmem_shared_auth(struct libxl_
 int libxl_tmem_shared_auth(struct libxl_ctx *ctx, uint32_t domid, char* uuid,
                            int auth);
 
+typedef struct {
+    char *backend;
+    uint32_t backend_id;
+    char *frontend;
+    uint32_t frontend_id;
+    int devid;
+    int state;
+    uint8_t mac[6];
+    int trusted;
+    uint8_t back_mac[6];
+    int filter_mac;
+} libxl_net2info;
+
 int libxl_device_net2_add(struct libxl_ctx *ctx, uint32_t domid,
                           libxl_device_net2 *net2);
+libxl_net2info *libxl_device_net2_list(struct libxl_ctx *ctx, uint32_t domid,
+                                       unsigned int *nb);
 
 /* common paths */
 const char *libxl_sbindir_path(void);
diff -r 112f706e1d48 -r a08a8256e997 tools/libxl/xl.h
--- a/tools/libxl/xl.h  Mon Jun 07 07:09:41 2010 +0100
+++ b/tools/libxl/xl.h  Mon Jun 07 07:11:15 2010 +0100
@@ -73,6 +73,7 @@ int main_tmem_set(int argc, char **argv)
 int main_tmem_set(int argc, char **argv);
 int main_tmem_shared_auth(int argc, char **argv);
 int main_network2attach(int argc, char **argv);
+int main_network2list(int argc, char **argv);
 
 void help(char *command);
 
diff -r 112f706e1d48 -r a08a8256e997 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Mon Jun 07 07:09:41 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Mon Jun 07 07:11:15 2010 +0100
@@ -3877,6 +3877,51 @@ int main_network2attach(int argc, char *
     exit(0);
 }
 
+int main_network2list(int argc, char **argv)
+{
+    int opt;
+    unsigned int nb;
+    libxl_net2info *net2s;
+
+    if (argc < 3) {
+        help("network2-list");
+        exit(0);
+    }
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("network2-list");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    printf("%-3s %-2s %-5s %-17s %-17s %-7s %-6s %-30s\n",
+           "Idx", "BE", "state", "Mac Addr.", "Remote Mac Addr.",
+           "trusted", "filter", "backend");
+    for (argv += 2, argc -=2; argc > 0; --argc, ++argv) {
+        if (domain_qualifier_to_domid(*argv, &domid, 0) < 0) {
+            fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
+            continue;
+        }
+        if ((net2s = libxl_device_net2_list(&ctx, domid, &nb))) {
+            for (; nb > 0; --nb, ++net2s) {
+                printf("%3d %2d %5d ", net2s->devid, net2s->backend_id, 
net2s->state);
+                printf("%02x:%02x:%02x:%02x:%02x:%02x ",
+                       net2s->mac[0], net2s->mac[1], net2s->mac[2],
+                       net2s->mac[3], net2s->mac[4], net2s->mac[5]);
+                printf("%02x:%02x:%02x:%02x:%02x:%02x ",
+                       net2s->back_mac[0], net2s->back_mac[1], 
net2s->back_mac[2],
+                       net2s->back_mac[3], net2s->back_mac[4], 
net2s->back_mac[5]);
+                printf("%-7d %-6d %-30s\n", net2s->trusted, net2s->filter_mac, 
net2s->backend);
+            }
+        }
+    }
+    exit(0);
+}
+
 static char *uptime_to_string(unsigned long time, int short_mode)
 {
     int sec, min, hour, day;
diff -r 112f706e1d48 -r a08a8256e997 tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Mon Jun 07 07:09:41 2010 +0100
+++ b/tools/libxl/xl_cmdtable.c Mon Jun 07 07:11:15 2010 +0100
@@ -295,6 +295,11 @@ struct cmd_spec cmd_table[] = {
       " [filter_mac=<0|1>] [front_filter_mac=<0|1>] [pdev=<PDEV>]"
       " [max_bypasses=n]",
     },
+    { "network2-list",
+      &main_network2list,
+      "list version 2 virtual network interfaces for a domain",
+      "<Domain(s)>",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);

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