xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Shriram Rajagopalan <rshriram@cs.ubc.ca>
To: xen-devel@lists.xen.org
Cc: Ian Campbell <ian.campbell@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH 2 of 4 RFC] xl/remus: Network buffering cmdline switch, setup/teardown
Date: Thu, 25 Jul 2013 00:09:28 -0700	[thread overview]
Message-ID: <3cd67f6ff63a50808a74.1374736168@athos.nss.cs.ubc.ca> (raw)
In-Reply-To: <patchbomb.1374736166@athos.nss.cs.ubc.ca>

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@cs.ubc.ca>

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"
     },
 };

  parent reply	other threads:[~2013-07-25  7:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-25  7:09 [PATCH 0 of 4 RFC] xl - Remus network buffering support Shriram Rajagopalan
2013-07-25  7:09 ` [PATCH 1 of 4 RFC] xl/remus : Network buffering setup helper functions Shriram Rajagopalan
2013-07-29 15:42   ` Ian Campbell
2013-07-29 18:00     ` Shriram Rajagopalan
2013-07-30 10:44       ` Ian Campbell
2013-07-25  7:09 ` Shriram Rajagopalan [this message]
2013-07-29 15:49   ` [PATCH 2 of 4 RFC] xl/remus: Network buffering cmdline switch, setup/teardown Ian Campbell
2013-07-29 19:00     ` Shriram Rajagopalan
2013-07-30 10:50       ` Ian Campbell
2013-07-30 15:25         ` Shriram Rajagopalan
2013-07-30 15:39           ` Ian Campbell
2013-07-25  7:09 ` [PATCH 3 of 4 RFC] xl/remus: Control network buffering in remus callbacks Shriram Rajagopalan
2013-07-29 16:06   ` Ian Campbell
2013-08-07 15:41     ` Ian Jackson
2013-08-07 15:38   ` Ian Jackson
2013-08-07 21:51     ` Shriram Rajagopalan
2013-08-08 11:07       ` Ian Jackson
2013-07-25  7:09 ` [PATCH 4 of 4 RFC] xl/remus: Add libnl3 dependency to autoconf scripts and libxl/Makefile Shriram Rajagopalan
2013-07-26  9:44   ` Wen Congyang
2013-07-26 13:51     ` Shriram Rajagopalan
2013-07-26  9:56   ` David Vrabel
2013-07-26 13:56     ` Shriram Rajagopalan
2013-07-29  5:58       ` Wen Congyang
2013-07-29 13:07         ` Shriram Rajagopalan
2013-07-29 15:41           ` David Vrabel
2013-07-30 16:11 ` [PATCH 0 of 4 RFC] xl - Remus network buffering support Roger Pau Monné
2013-07-31  8:33   ` Ian Campbell

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=3cd67f6ff63a50808a74.1374736168@athos.nss.cs.ubc.ca \
    --to=rshriram@cs.ubc.ca \
    --cc=ian.campbell@citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xen.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).