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] [PATCH 2 of 7] xl: network2-list command

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 2 of 7] xl: network2-list command
From: Eric Chanudet <eric.chanudet@xxxxxxxxxx>
Date: Fri, 04 Jun 2010 15:30:14 +0100
Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxx>
Delivery-date: Fri, 04 Jun 2010 07:35:18 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1275661812@xxxxxxxxxxxxxxxxxxxxx>
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>
References: <patchbomb.1275661812@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.5.3
This patch adds network2-list command to xl.

Usage: xl network2-list <Domains>

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -1686,6 +1686,69 @@ int libxl_device_net2_add(struct libxl_c
     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 --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -552,7 +552,21 @@ int libxl_tmem_set(struct libxl_ctx *ctx
 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);
 
 #endif /* LIBXL_H */
 
diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h
--- a/tools/libxl/xl.h
+++ b/tools/libxl/xl.h
@@ -73,6 +73,7 @@ int main_tmem_thaw(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 --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -3869,6 +3869,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 --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c
+++ b/tools/libxl/xl_cmdtable.c
@@ -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-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel