From: Eric Chanudet <eric.chanudet@citrix.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH 2 of 6] xl: network-list command
Date: Wed, 12 May 2010 18:32:10 +0100 [thread overview]
Message-ID: <de2cd57d8a0fc036eff7.1273685530@eric.cam.xci-test.com> (raw)
In-Reply-To: <patchbomb.1273685528@eric.cam.xci-test.com>
This patch adds network-list command to xl.
Usage: xl network-list <Domain(s)>
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -1505,6 +1505,66 @@ int libxl_device_nic_del(struct libxl_ct
return libxl_device_del(ctx, &device, wait);
}
+libxl_nicinfo *libxl_list_nics(struct libxl_ctx *ctx, uint32_t domid, unsigned int *nb)
+{
+ char *dompath, *nic_path_fe;
+ char **l;
+ char *val, *tok;
+ unsigned int nb_nics, i;
+ libxl_nicinfo *res, *nics;
+
+ dompath = libxl_xs_get_dompath(ctx, domid);
+ if (!dompath) {
+ return NULL;
+ }
+ l = libxl_xs_directory(ctx, XBT_NULL,
+ libxl_sprintf(ctx, "%s/device/vif", dompath), &nb_nics);
+ if (!l) {
+ return NULL;
+ }
+ res = libxl_calloc(ctx, nb_nics, sizeof (libxl_device_nic));
+ if (!res) {
+ libxl_free(ctx, l);
+ return NULL;
+ }
+ nics = res;
+ for (*nb = nb_nics; nb_nics > 0; --nb_nics, ++l, ++nics) {
+ nic_path_fe = libxl_sprintf(ctx, "%s/device/vif/%s", dompath, *l);
+
+ nics->backend = libxl_xs_read(ctx, XBT_NULL,
+ libxl_sprintf(ctx, "%s/backend", nic_path_fe));
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/backend-id", nic_path_fe));
+ nics->backend_id = val ? strtoul(val, NULL, 10) : -1;
+
+ nics->devid = strtoul(*l, NULL, 10);
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/state", nic_path_fe));
+ nics->state = val ? strtoul(val, NULL, 10) : -1;
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/mac", nic_path_fe));
+ for (i = 0, tok = strtok(val, ":"); tok && (i < 6);
+ ++i, tok = strtok(NULL, ":")) {
+ nics->mac[i] = strtoul(tok, NULL, 16);
+ }
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/event-channel", nic_path_fe));
+ nics->evtch = val ? strtol(val, NULL, 10) : -1;
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/tx-ring-ref", nic_path_fe));
+ nics->rref_tx = val ? strtol(val, NULL, 10) : -1;
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/rx-ring-ref", nic_path_fe));
+ nics->rref_rx = val ? strtol(val, NULL, 10) : -1;
+ nics->frontend = libxl_xs_read(ctx, XBT_NULL,
+ libxl_sprintf(ctx, "%s/frontend", nics->backend));
+ val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/frontend-id", nics->backend));
+ nics->frontend_id = val ? strtoul(val, NULL, 10) : -1;
+ nics->script = libxl_xs_read(ctx, XBT_NULL,
+ libxl_sprintf(ctx, "%s/script", nics->backend));
+
+ libxl_free(ctx, nic_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
@@ -372,8 +372,23 @@ int libxl_device_disk_del(struct libxl_c
libxl_device_disk *libxl_device_disk_list(struct libxl_ctx *ctx, uint32_t domid, int *num);
int libxl_cdrom_insert(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);
+typedef struct {
+ char *backend;
+ uint32_t backend_id;
+ char *frontend;
+ uint32_t frontend_id;
+ int devid;
+ int state;
+ char *script;
+ uint8_t mac[6];
+ int evtch;
+ int rref_tx;
+ int rref_rx;
+} libxl_nicinfo;
+
int libxl_device_nic_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);
int libxl_device_nic_del(struct libxl_ctx *ctx, libxl_device_nic *nic, int wait);
+libxl_nicinfo *libxl_list_nics(struct libxl_ctx *ctx, uint32_t domid, unsigned int *nb);
int libxl_device_console_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_console *console);
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
@@ -3141,3 +3141,51 @@ int main_networkattach(int argc, char **
}
exit(0);
}
+
+int main_networklist(int argc, char **argv)
+{
+ int opt;
+ libxl_nicinfo *nics;
+ unsigned int nb;
+
+ if (argc < 2) {
+ help("network-list");
+ exit(1);
+ }
+ while ((opt = getopt(argc, argv, "hl")) != -1) {
+ switch (opt) {
+ case 'h':
+ help("network-list");
+ exit(0);
+ default:
+ fprintf(stderr, "option `%c' not supported.\n", opt);
+ break;
+ }
+ }
+
+ /* Idx BE MAC Hdl Sta evch txr/rxr BE-path */
+ printf("%-3s %-2s %-17s %-6s %-5s %-6s %5s/%-5s %-30s\n",
+ "Idx", "BE", "Mac Addr.", "handle", "state", "evt-ch", "tx-", "rx-ring-ref", "BE-path");
+ for (++argv, --argc; 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 (!(nics = libxl_list_nics(&ctx, domid, &nb))) {
+ continue;
+ }
+ for (; nb > 0; --nb, ++nics) {
+ /* Idx BE */
+ printf("%-3d %-2d ", nics->devid, nics->backend_id);
+ /* MAC */
+ printf("%02x:%02x:%02x:%02x:%02x:%02x ",
+ nics->mac[0], nics->mac[1], nics->mac[2],
+ nics->mac[3], nics->mac[4], nics->mac[5]);
+ /* Hdl Sta evch txr/rxr BE-path */
+ printf("%6d %5d %6d %5d/%-11d %-30s\n",
+ nics->devid, nics->state, nics->evtch,
+ nics->rref_tx, nics->rref_rx, nics->backend);
+ }
+ }
+ exit(0);
+}
diff --git a/tools/libxl/xl_cmdimpl.h b/tools/libxl/xl_cmdimpl.h
--- a/tools/libxl/xl_cmdimpl.h
+++ b/tools/libxl/xl_cmdimpl.h
@@ -40,5 +40,6 @@ int main_domname(int argc, char **argv);
int main_rename(int argc, char **argv);
int main_trigger(int argc, char **argv);
int main_networkattach(int argc, char **argv);
+int main_networklist(int argc, char **argv);
void help(char *command);
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
@@ -176,6 +176,10 @@ struct cmd_spec cmd_table[] = {
&main_networkattach,
"Create a new virtual network device"
},
+ { "network-list",
+ &main_networklist,
+ "List virtual network interfaces for a domain"
+ },
};
int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
next prev parent reply other threads:[~2010-05-12 17:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-12 17:32 [PATCH 0 of 6] xl: network and block features Eric Chanudet
2010-05-12 17:32 ` [PATCH 1 of 6] xl: network-attach command Eric Chanudet
2010-05-13 0:45 ` Yang Hongyang
2010-05-13 13:24 ` Eric Chanudet (Intern)
2010-05-14 0:40 ` Yang Hongyang
2010-05-12 17:32 ` Eric Chanudet [this message]
2010-05-12 17:32 ` [PATCH 3 of 6] xl: network-detach command Eric Chanudet
2010-05-12 17:32 ` [PATCH 4 of 6] xl: block-attach command Eric Chanudet
2010-05-12 17:32 ` [PATCH 5 of 6] xl: block-list command Eric Chanudet
2010-05-12 17:32 ` [PATCH 6 of 6] xl: block-detach command Eric Chanudet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=de2cd57d8a0fc036eff7.1273685530@eric.cam.xci-test.com \
--to=eric.chanudet@citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.