[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] xl: Implement network-list command
# HG changeset patch # User Keir Fraser <keir.fraser@xxxxxxxxxx> # Date 1273736915 -3600 # Node ID 5e997c43d6c12bb7a6f0885adf15d4fadff053cf # Parent faf4c485827fd07fdeb500b918a254cce8c73e6d xl: Implement network-list command Signed-off-by: Eric Chanudet <eric.chanudet@xxxxxxxxxx> --- tools/libxl/libxl.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl.h | 15 +++++++++++ tools/libxl/xl_cmdimpl.c | 48 ++++++++++++++++++++++++++++++++++++ tools/libxl/xl_cmdimpl.h | 1 tools/libxl/xl_cmdtable.c | 5 +++ 5 files changed, 129 insertions(+) diff -r faf4c485827f -r 5e997c43d6c1 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Thu May 13 08:46:57 2010 +0100 +++ b/tools/libxl/libxl.c Thu May 13 08:48:35 2010 +0100 @@ -1504,6 +1504,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 -r faf4c485827f -r 5e997c43d6c1 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Thu May 13 08:46:57 2010 +0100 +++ b/tools/libxl/libxl.h Thu May 13 08:48:35 2010 +0100 @@ -373,8 +373,23 @@ libxl_device_disk *libxl_device_disk_lis 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 -r faf4c485827f -r 5e997c43d6c1 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Thu May 13 08:46:57 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Thu May 13 08:48:35 2010 +0100 @@ -3254,3 +3254,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 -r faf4c485827f -r 5e997c43d6c1 tools/libxl/xl_cmdimpl.h --- a/tools/libxl/xl_cmdimpl.h Thu May 13 08:46:57 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.h Thu May 13 08:48:35 2010 +0100 @@ -43,5 +43,6 @@ int main_sysrq(int argc, char **argv); int main_sysrq(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); void help(char *command); diff -r faf4c485827f -r 5e997c43d6c1 tools/libxl/xl_cmdtable.c --- a/tools/libxl/xl_cmdtable.c Thu May 13 08:46:57 2010 +0100 +++ b/tools/libxl/xl_cmdtable.c Thu May 13 08:48:35 2010 +0100 @@ -194,6 +194,11 @@ struct cmd_spec cmd_table[] = { "[ip=<ip>] [script=<script>] [backend=<BackDomain>] [vifname=<name>] " "[rate=<rate>] [model=<model>][accel=<accel>]", }, + { "network-list", + &main_networklist, + "List 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
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |