[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 2 of 4 RFC] xl/remus: Network buffering cmdline switch, setup/teardown
Add appropriate code to xl_cmdline.c to setup network buffers for each vif belonging to the guest. Also provide a command line switch to explicitly "enable" network buffering. Signed-off-by: Shriram Rajagopalan <rshriram@xxxxxxxxx> diff -r 3ae38cbe535c -r 3cd67f6ff63a tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Wed Jul 24 22:55:00 2013 -0700 +++ b/tools/libxl/libxl_types.idl Thu Jul 25 00:02:19 2013 -0700 @@ -521,6 +521,7 @@ libxl_domain_remus_info = Struct("domain ("interval", integer), ("blackhole", bool), ("compression", bool), + ("netbuf_iflist", libxl_string_list), ]) libxl_event_type = Enumeration("event_type", [ diff -r 3ae38cbe535c -r 3cd67f6ff63a tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Jul 24 22:55:00 2013 -0700 +++ b/tools/libxl/xl_cmdimpl.c Thu Jul 25 00:02:19 2013 -0700 @@ -7039,10 +7039,109 @@ done: return ret; } +static char **get_guest_vifnames(uint32_t domid, int *num_vifs) +{ + char **viflist; + libxl_device_nic *nics; + libxl_nicinfo nicinfo; + int nb, i; + + nics = libxl_device_nic_list(ctx, domid, &nb); + if (!nics) { *num_vifs = 0; return NULL;} + + viflist = calloc((nb + 1), sizeof(char *)); + if (!viflist) { + perror("failed to allocate memory to hold vif names!"); + exit(-1); + } + + for (i = 0; i < nb; ++i) { + if (!libxl_device_nic_getinfo(ctx, domid, &nics[i], &nicinfo)) { + if (asprintf(&viflist[i], "vif%u.%d", domid, nicinfo.devid) < 0) { + perror("Cannot alloc memory while getting guest vif names"); + exit(-1); + } + libxl_nicinfo_dispose(&nicinfo); + } + libxl_device_nic_dispose(&nics[i]); + } + free(nics); + + *num_vifs = nb; + return viflist; +} + +static int remus_setup_network_buffers(uint32_t domid, + char ***pifblist, int *num_ifbs) +{ + + char **viflist, **ifblist; + int nb, i, j; + + viflist = get_guest_vifnames(domid, &nb); + fprintf(stderr, "Domain %u has %d vifs\n", domid, nb); + + if (!viflist) { *num_ifbs = 0; *ifblist = NULL; return 0;} + + ifblist = calloc((nb + 1), sizeof(char *)); + if (!ifblist) { + perror("failed to allocate memory for ifb list!"); + exit(-1); + } + + /* For each vif, install the network buffer */ + for (i = 0; i < nb; ++i) { + ifblist[i] = remus_install_netbuf_on_dev(viflist[i]); + if (ifblist[i] == NULL) { + fprintf(stderr, "Failed to setup output buffer for interface %s\n", + viflist[i]); + break; + } + } + + if (i < nb) { + j = i; + remus_uninstall_netbufs(viflist, nb, ifblist, j); + for (i = 0; i < nb; i++) + free(viflist[i]); + free(viflist); + + for (i = 0; i < j; i++) + free(ifblist[i]); + free(ifblist); + *num_ifbs = 0; + *pifblist = NULL; + return -1; + } + + for (i = 0; i < nb; i++) + free(viflist[i]); + free(viflist); + + *num_ifbs = nb; + *pifblist = ifblist; + return 0; +} + +static void remus_teardown_network_buffers(uint32_t domid, char **ifblist, + int num_ifbs) +{ + int nb, i; + char **viflist; + + viflist = get_guest_vifnames(domid, &nb); + remus_uninstall_netbufs(viflist, nb, ifblist, num_ifbs); + + for (i = 0; i < nb; i++) + free(viflist[i]); + free(viflist); + +} + int main_remus(int argc, char **argv) { uint32_t domid; - int opt, rc, daemonize = 1; + int opt, rc, daemonize = 1, netbuf = 0, num_ifbs = 0; const char *ssh_command = "ssh"; char *host = NULL, *rune = NULL; libxl_domain_remus_info r_info; @@ -7057,7 +7156,7 @@ int main_remus(int argc, char **argv) r_info.blackhole = 0; r_info.compression = 1; - SWITCH_FOREACH_OPT(opt, "bui:s:e", NULL, "remus", 2) { + SWITCH_FOREACH_OPT(opt, "bui:s:en", NULL, "remus", 2) { case 'i': r_info.interval = atoi(optarg); break; @@ -7073,6 +7172,9 @@ int main_remus(int argc, char **argv) case 'e': daemonize = 0; break; + case 'n': + netbuf = 1; + break; } domid = find_domain(argv[optind]); @@ -7109,6 +7211,19 @@ int main_remus(int argc, char **argv) rune); } + if (netbuf) { + rc = remus_setup_network_buffers(domid, + (char ***)(&r_info.netbuf_iflist), + &num_ifbs); + if (rc) { + fprintf(stderr, "Failed to properly setup network " + "buffering. Exiting..\n"); + close(send_fd); + return -ERROR_FAIL; + } else + fprintf(stderr, "Network buffers setup on %d interfaces\n", num_ifbs); + } + /* Point of no return */ rc = libxl_domain_remus_start(ctx, &r_info, domid, send_fd, recv_fd, 0); @@ -7126,6 +7241,9 @@ int main_remus(int argc, char **argv) libxl_domain_resume(ctx, domid, 1, 0); } + if (netbuf) + remus_teardown_network_buffers(domid, (char **)r_info.netbuf_iflist, num_ifbs); + close(send_fd); return -ERROR_FAIL; } diff -r 3ae38cbe535c -r 3cd67f6ff63a tools/libxl/xl_cmdtable.c --- a/tools/libxl/xl_cmdtable.c Wed Jul 24 22:55:00 2013 -0700 +++ b/tools/libxl/xl_cmdtable.c Thu Jul 25 00:02:19 2013 -0700 @@ -485,8 +485,8 @@ struct cmd_spec cmd_table[] = { " to sh. If empty, run <host> instead of \n" " ssh <host> xl migrate-receive -r [-e]\n" "-e Do not wait in the background (on <host>) for the death\n" - " of the domain." - + " of the domain.\n" + "-n Enable Remus network buffering\n" }, }; _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |