[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] xl: Implement network-detach command
# HG changeset patch # User Keir Fraser <keir.fraser@xxxxxxxxxx> # Date 1273736981 -3600 # Node ID dcacf3300a0b26d7d76300c5269c73713ab15a1c # Parent 5e997c43d6c12bb7a6f0885adf15d4fadff053cf xl: Implement network-detach command Signed-off-by: Eric Chanudet <eric.chanudet@xxxxxxxxxx> --- tools/libxl/libxl_utils.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_utils.h | 6 +++ tools/libxl/xl_cmdimpl.c | 42 ++++++++++++++++++++++++++ tools/libxl/xl_cmdimpl.h | 1 tools/libxl/xl_cmdtable.c | 5 +++ 5 files changed, 128 insertions(+) diff -r 5e997c43d6c1 -r dcacf3300a0b tools/libxl/libxl_utils.c --- a/tools/libxl/libxl_utils.c Thu May 13 08:48:35 2010 +0100 +++ b/tools/libxl/libxl_utils.c Thu May 13 08:49:41 2010 +0100 @@ -356,3 +356,77 @@ int libxl_pipe(struct libxl_ctx *ctx, in } return 0; } + +int libxl_mac_to_device_nic(struct libxl_ctx *ctx, uint32_t domid, + const char *mac, libxl_device_nic *nic) +{ + libxl_nicinfo *nics; + unsigned int nb, i; + uint8_t mac_n[6]; + uint8_t *a, *b; + const char *tok; + char *endptr; + + nics = libxl_list_nics(ctx, domid, &nb); + if (!nics) { + return ERROR_FAIL; + } + + for (i = 0, tok = mac; *tok && (i < 6); ++i, tok += 3) { + mac_n[i] = strtol(tok, &endptr, 16); + if (endptr != (tok + 2)) { + return ERROR_INVAL; + } + } + memset(nic, 0, sizeof (libxl_device_nic)); + for (; nb; --nb, ++nics) { + for (i = 0, a = nics->mac, b = mac_n; + (b < mac_n + 6) && (*a == *b); ++a, ++b) + ; + if ((b >= mac_n + 6) && (*a == *b)) { + nic->backend_domid = nics->backend_id; + nic->domid = nics->frontend_id; + nic->devid = nics->devid; + memcpy(nic->mac, nics->mac, sizeof (nic->mac)); + nic->script = nics->script; + libxl_free(ctx, nics); + return 0; + } + } + + libxl_free(ctx, nics); + return 0; +} + +int libxl_devid_to_device_nic(struct libxl_ctx *ctx, uint32_t domid, + const char *devid, libxl_device_nic *nic) +{ + char *tok, *val; + char *dompath, *nic_path_fe, *nic_path_be; + unsigned int i; + + memset(nic, 0, sizeof (libxl_device_nic)); + dompath = libxl_xs_get_dompath(ctx, domid); + if (!dompath) { + return ERROR_FAIL; + } + nic_path_fe = libxl_sprintf(ctx, "%s/device/vif/%s", dompath, devid); + nic_path_be = 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)); + nic->backend_domid = strtoul(val, NULL, 10); + nic->devid = strtoul(devid, NULL, 10); + libxl_free(ctx, val); + + 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, ":")) { + nic->mac[i] = strtoul(tok, NULL, 16); + } + libxl_free(ctx, val); + nic->script = libxl_xs_read(ctx, XBT_NULL, + libxl_sprintf(ctx, "%s/script", nic_path_be)); + libxl_free(ctx, nic_path_fe); + libxl_free(ctx, nic_path_be); + return 0; +} diff -r 5e997c43d6c1 -r dcacf3300a0b tools/libxl/libxl_utils.h --- a/tools/libxl/libxl_utils.h Thu May 13 08:48:35 2010 +0100 +++ b/tools/libxl/libxl_utils.h Thu May 13 08:49:41 2010 +0100 @@ -55,6 +55,12 @@ void libxl_report_child_exitstatus(struc /* treats all exit statuses as errors; if that's not what you want, * check status yourself first */ + +int libxl_mac_to_device_nic(struct libxl_ctx *ctx, uint32_t domid, + const char *mac, libxl_device_nic *nic); +int libxl_devid_to_device_nic(struct libxl_ctx *ctx, uint32_t domid, + const char *devid, libxl_device_nic *nic); + /* log levels: */ #define XL_LOG_DEBUG 3 #define XL_LOG_INFO 2 diff -r 5e997c43d6c1 -r dcacf3300a0b tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Thu May 13 08:48:35 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Thu May 13 08:49:41 2010 +0100 @@ -3302,3 +3302,45 @@ int main_networklist(int argc, char **ar } exit(0); } + +int main_networkdetach(int argc, char **argv) +{ + int opt; + libxl_device_nic nic; + + if (argc != 3) { + help("network-detach"); + exit(0); + } + while ((opt = getopt(argc, argv, "hl")) != -1) { + switch (opt) { + case 'h': + help("network-detach"); + exit(0); + default: + fprintf(stderr, "option `%c' not supported.\n", opt); + break; + } + } + + if (domain_qualifier_to_domid(argv[1], &domid, 0) < 0) { + fprintf(stderr, "%s is an invalid domain identifier\n", argv[1]); + exit(1); + } + + if (!strchr(argv[2], ':')) { + if (libxl_devid_to_device_nic(&ctx, domid, argv[2], &nic)) { + fprintf(stderr, "Unknown device %s.\n", argv[2]); + exit(1); + } + } else { + if (libxl_mac_to_device_nic(&ctx, domid, argv[2], &nic)) { + fprintf(stderr, "Unknown device %s.\n", argv[2]); + exit(1); + } + } + if (libxl_device_nic_del(&ctx, &nic, 1)) { + fprintf(stderr, "libxl_device_nic_del failed.\n"); + } + exit(0); +} diff -r 5e997c43d6c1 -r dcacf3300a0b tools/libxl/xl_cmdimpl.h --- a/tools/libxl/xl_cmdimpl.h Thu May 13 08:48:35 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.h Thu May 13 08:49:41 2010 +0100 @@ -44,5 +44,6 @@ int main_top(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); +int main_networkdetach(int argc, char **argv); void help(char *command); diff -r 5e997c43d6c1 -r dcacf3300a0b tools/libxl/xl_cmdtable.c --- a/tools/libxl/xl_cmdtable.c Thu May 13 08:48:35 2010 +0100 +++ b/tools/libxl/xl_cmdtable.c Thu May 13 08:49:41 2010 +0100 @@ -199,6 +199,11 @@ struct cmd_spec cmd_table[] = { "List virtual network interfaces for a domain", "<Domain(s)>", }, + { "network-detach", + &main_networkdetach, + "Destroy a domain's virtual network device", + "<Domain> <DevId|mac>", + }, }; 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 |