Merge branch 'master' of ssh://git.onelab.eu/git/sliver-openvswitch
authorGiuseppe Lettieri <g.lettieri@iet.unipi.it>
Thu, 20 Dec 2012 15:40:50 +0000 (16:40 +0100)
committerGiuseppe Lettieri <g.lettieri@iet.unipi.it>
Thu, 20 Dec 2012 15:40:50 +0000 (16:40 +0100)
Conflicts:
lib/netdev-pltap.c

lib/netdev-pltap.c
planetlab/exp-tool/Makefile
sliver-openvswitch.spec

index b2cc3ec..6227308 100644 (file)
@@ -48,15 +48,14 @@ VLOG_DEFINE_THIS_MODULE(netdev_pltap);
 struct netdev_dev_pltap {
     struct netdev_dev netdev_dev;
     char *real_name;
-    char *error;
     struct netdev_stats stats;
+    enum netdev_flags new_flags;
     enum netdev_flags flags;
     int fd;
     struct sockaddr_in local_addr;
     int local_netmask;
     bool valid_local_ip;
     bool valid_local_netmask;
-    bool finalized;
     bool sync_flags_needed;
     struct list sync_list;
     unsigned int change_seq;
@@ -77,11 +76,15 @@ static struct shash pltap_netdev_devs = SHASH_INITIALIZER(&pltap_netdev_devs);
 static int netdev_pltap_create(const struct netdev_class *, const char *,
                                struct netdev_dev **);
 
-static struct shash pltap_creating = SHASH_INITIALIZER(&pltap_creating);
-
 static void netdev_pltap_update_seq(struct netdev_dev_pltap *);
 static int get_flags(struct netdev_dev_pltap *dev, enum netdev_flags *flags);
 
+static bool
+netdev_pltap_finalized(struct netdev_dev_pltap *dev)
+{
+    return dev->valid_local_ip && dev->valid_local_netmask;
+}
+
 static bool
 is_pltap_class(const struct netdev_class *class)
 {
@@ -132,11 +135,9 @@ netdev_pltap_create(const struct netdev_class *class OVS_UNUSED, const char *nam
     netdev_dev = xzalloc(sizeof *netdev_dev);
 
     netdev_dev->real_name = xzalloc(IFNAMSIZ + 1);
-    netdev_dev->error = NULL;
     memset(&netdev_dev->local_addr, 0, sizeof(netdev_dev->local_addr));
     netdev_dev->valid_local_ip = false;
     netdev_dev->valid_local_netmask = false;
-    netdev_dev->finalized = false;
     netdev_dev->flags = 0;
     netdev_dev->sync_flags_needed = false;
     list_init(&netdev_dev->sync_list);
@@ -175,6 +176,8 @@ netdev_pltap_destroy(struct netdev_dev *netdev_dev_)
     if (netdev_dev->fd != -1)
        close(netdev_dev->fd);
 
+    sync_done(netdev_dev);
+
     shash_find_and_delete(&pltap_netdev_devs,
                           netdev_dev_get_name(netdev_dev_));
     free(netdev_dev);
@@ -200,13 +203,26 @@ netdev_pltap_close(struct netdev *netdev_)
 }
 
 static int vsys_transaction(const char *script,
-       const char *msg, char *reply, size_t reply_size)
+       const char **preply, char *format, ...)
 {
+    char *msg = NULL, *reply = NULL;
+    const size_t reply_size = 1024;
     int ifd = -1, ofd = -1, maxfd;
     size_t bytes_to_write, bytes_to_read,
            bytes_written = 0, bytes_read = 0;
     int error = 0;
     char *ofname = NULL, *ifname = NULL;
+    va_list args;
+
+    va_start(args, format);
+    msg = xvasprintf(format, args);
+    va_end(args);
+    reply = (char*)xmalloc(reply_size);
+    if (!msg || !reply) {
+       VLOG_ERR("Out of memory");
+       error = ENOMEM;
+       goto cleanup;
+    }
 
     ofname = xasprintf("/vsys/%s.out", script);
     ifname = xasprintf("/vsys/%s.in", script);
@@ -288,12 +304,19 @@ static int vsys_transaction(const char *script,
     }
     if (bytes_read) {
        reply[bytes_read] = '\0';
-        VLOG_ERR("%s returned: %s", script, reply);
+       if (preply) {
+               *preply = reply;
+               reply = NULL; /* prevent freeing the reply msg */
+       } else {
+               VLOG_ERR("%s returned: %s", script, reply);
+       }
        error = EAGAIN;
        goto cleanup;
     }
 
 cleanup:
+    free(msg);
+    free(reply);
     free(ofname);
     free(ifname);
     close(ifd);
@@ -302,101 +325,69 @@ cleanup:
 }
 
 static int
-netdev_pltap_sync_flags(struct netdev_dev_pltap *dev)
+netdev_pltap_up(struct netdev_dev_pltap *dev)
 {
-    int error = 0;
-    char *msg = NULL, *reply = NULL;
-    const size_t reply_size = 1024;
-    enum netdev_flags flags = 0;
-
-
-    if (dev->fd < 0 || !dev->finalized) {
-       /* pretend we have synchronized, we will do it later */
-       sync_needed(dev);
+    if (!netdev_pltap_finalized(dev)) {
         return 0;
     }
+    
+    return vsys_transaction("vif_up", NULL, "%s\n"IP_FMT"\n%d\n",
+              dev->real_name,
+              IP_ARGS(&dev->local_addr.sin_addr),
+              dev->local_netmask);
+}
 
-    error = get_flags(dev, &flags);
-    if (error) {
-       VLOG_ERR("get_flags(%s): %s", dev->real_name, strerror(error));
-       goto cleanup;
+static int
+netdev_pltap_down(struct netdev_dev_pltap *dev)
+{
+    if (!netdev_pltap_finalized(dev)) {
+        return 0;
     }
-    VLOG_DBG("sync_flags(%s): current: %s %s",
-        dev->real_name,
-       (flags & NETDEV_UP ? "UP" : "-"),
-       (flags & NETDEV_PROMISC ? "PROMISC" : "-"));
+    
+    return vsys_transaction("vif_down", NULL, "%s\n", dev->real_name);
+}
 
-    if ((dev->flags & NETDEV_PROMISC) ^ (flags & NETDEV_PROMISC)) {
-           msg = xasprintf("%s\n%s",
-              dev->real_name,
-              (dev->flags & NETDEV_PROMISC ? "" : "-\n"));
-           reply = (char*)xmalloc(reply_size);
-           if (!msg || !reply) {
-               VLOG_ERR("Out of memory\n");
-               error = ENOMEM;
-               goto cleanup;
-           }
-           error = vsys_transaction("promisc", msg, reply, reply_size);
-           if (error) {
-               dev->error = reply;
-               reply = NULL; /* prevent free of reply msg */
-               goto cleanup;
-           }
-           netdev_pltap_update_seq(dev);
+static int
+netdev_pltap_promisc(struct netdev_dev_pltap *dev, bool promisc)
+{
+    if (!netdev_pltap_finalized(dev)) {
+        return 0;
     }
 
-cleanup:
-
-    sync_done(dev);
-    free(msg);
-    free(reply);
-
-    return error;
+    return vsys_transaction("promisc", NULL, "%s\n%s",
+              dev->real_name,
+              (promisc ? "" : "-\n"));
 }
 
-static int
-netdev_pltap_create_finalize(struct netdev_dev_pltap *dev)
+static void
+netdev_pltap_sync_flags(struct netdev_dev_pltap *dev)
 {
-    int error = 0;
-    char *msg = NULL, *reply = NULL;
-    const size_t reply_size = 1024;
 
-    if (dev->finalized)
-        return 0;
-    if (!dev->valid_local_ip || !dev->valid_local_netmask)
-        return 0;
+    if (dev->fd < 0 || !netdev_pltap_finalized(dev))
+       return;
     
-    msg = xasprintf("%s\n"IP_FMT"\n%d\n",
-       dev->real_name,
-       IP_ARGS(&dev->local_addr.sin_addr),
-       dev->local_netmask);
-    reply = (char*)xmalloc(reply_size);
-    if (!msg || !reply) {
-        VLOG_ERR("Out of memory");
-       error = ENOMEM;
-       goto cleanup;
-    }
-    error = vsys_transaction("vif_up", msg, reply, reply_size);
-    if (error) {
-       dev->error = reply;
-       reply = NULL; /* prevent free of reply msg */
-       goto cleanup;
+    VLOG_DBG("sync_flags(%s): current: %s %s  target: %s %s",
+        dev->real_name,
+       (dev->flags & NETDEV_UP ? "UP" : "-"),
+       (dev->flags & NETDEV_PROMISC ? "PROMISC" : "-"),
+       (dev->new_flags & NETDEV_UP ? "UP" : "-"),
+       (dev->new_flags & NETDEV_PROMISC ? "PROMISC" : "-"));
+
+    if ((dev->new_flags & NETDEV_UP) && !(dev->flags & NETDEV_UP)) {
+        (void) netdev_pltap_up(dev);
+    } else if (!(dev->new_flags & NETDEV_UP) && (dev->flags & NETDEV_UP)) {
+        (void) netdev_pltap_down(dev);
     }
-    dev->finalized = true;
-    error = netdev_pltap_sync_flags(dev);
-    if (error) {
-       goto cleanup;
+
+    if ((dev->new_flags & NETDEV_PROMISC) ^ (dev->flags & NETDEV_PROMISC)) {
+        (void) netdev_pltap_promisc(dev, dev->new_flags & NETDEV_PROMISC);
     }
-    free(dev->error);
-    dev->error = NULL;
-    netdev_pltap_update_seq(dev);
 
-cleanup:
-    free(msg);
-    free(reply);
-    return error;
+    netdev_pltap_update_seq(dev);
+    sync_done(dev);
 }
 
+
 static int
 netdev_pltap_get_config(struct netdev_dev *dev_, struct smap *args)
 {
@@ -408,7 +399,7 @@ netdev_pltap_get_config(struct netdev_dev *dev_, struct smap *args)
     if (netdev_dev->valid_local_netmask)
         smap_add_format(args, "local_netmask", "%"PRIu32,
             ntohs(netdev_dev->local_netmask));
-    return netdev_pltap_create_finalize(netdev_dev);
+    return 0;
 }
 
 static int
@@ -437,13 +428,21 @@ netdev_pltap_set_config(struct netdev_dev *dev_, const struct smap *args)
                netdev_dev_get_name(dev_), node->name);
        }
     }
-    return netdev_pltap_create_finalize(netdev_dev);        
+    if (netdev_pltap_finalized(netdev_dev)) {
+        netdev_dev->new_flags |= NETDEV_UP;
+        sync_needed(netdev_dev);
+    }
+    return 0;
 }
 
 static int
 netdev_pltap_listen(struct netdev *netdev_ OVS_UNUSED)
 {
-    return 0;
+    struct netdev_dev_pltap *dev = 
+       netdev_dev_pltap_cast(netdev_get_dev(netdev_));
+    if (!netdev_pltap_finalized(dev))
+        return 0;
+    return netdev_pltap_up(dev);
 }
 
 static int
@@ -456,8 +455,6 @@ netdev_pltap_recv(struct netdev *netdev_, void *buffer, size_t size)
         { .iov_base = prefix, .iov_len = 4 },
        { .iov_base = buffer, .iov_len = size }
     };
-    if (!dev->finalized)
-        return -EAGAIN;
     for (;;) {
         ssize_t retval;
         retval = readv(dev->fd, iov, 2);
@@ -482,7 +479,7 @@ netdev_pltap_recv_wait(struct netdev *netdev_)
 {
     struct netdev_dev_pltap *dev = 
        netdev_dev_pltap_cast(netdev_get_dev(netdev_));
-    if (dev->finalized && dev->fd >= 0) {
+    if (dev->fd >= 0 && netdev_pltap_finalized(dev)) {
         poll_fd_wait(dev->fd, POLLIN);
     }
 }
@@ -497,7 +494,7 @@ netdev_pltap_send(struct netdev *netdev_, const void *buffer, size_t size)
         { .iov_base = prefix, .iov_len = 4 },
        { .iov_base = (char*) buffer, .iov_len = size }
     };
-    if (dev->fd < 0 || !dev->finalized)
+    if (dev->fd < 0)
         return EAGAIN;
     for (;;) {
         ssize_t retval;
@@ -523,7 +520,7 @@ netdev_pltap_send_wait(struct netdev *netdev_)
 {
     struct netdev_dev_pltap *dev = 
        netdev_dev_pltap_cast(netdev_get_dev(netdev_));
-    if (dev->finalized && dev->fd >= 0) {
+    if (dev->fd >= 0 && netdev_pltap_finalized(dev)) {
         poll_fd_wait(dev->fd, POLLOUT);
     }
 }
@@ -536,8 +533,8 @@ netdev_pltap_drain(struct netdev *netdev_)
     char buffer[128];
     int error;
 
-    if (dev->fd < 0 || !dev->finalized)
-       return 0;
+    if (dev->fd < 0)
+       return EAGAIN;
     for (;;) {
        error = recv(dev->fd, buffer, 128, MSG_TRUNC);
        if (error) {
@@ -608,7 +605,7 @@ netdev_pltap_get_etheraddr(const struct netdev *netdev,
 {
     struct netdev_dev_pltap *dev = 
        netdev_dev_pltap_cast(netdev_get_dev(netdev));
-    if (dev->fd < 0 || !dev->finalized)
+    if (dev->fd < 0)
         return EAGAIN;
     return get_etheraddr(dev, mac);
 }
@@ -635,20 +632,24 @@ netdev_pltap_update_flags(struct netdev *netdev,
 {
     struct netdev_dev_pltap *dev =
         netdev_dev_pltap_cast(netdev_get_dev(netdev));
+    int error = 0;
 
     if ((off | on) & ~(NETDEV_UP | NETDEV_PROMISC)) {
         return EINVAL;
     }
 
+    if (netdev_pltap_finalized(dev)) {
+        error = get_flags(dev, &dev->flags);
+    }
     *old_flagsp = dev->flags;
-    dev->flags |= on;
-    dev->flags &= ~off;
-    if (*old_flagsp != dev->flags) {
+    dev->new_flags |= on;
+    dev->new_flags &= ~off;
+    if (dev->flags != dev->new_flags) {
        /* we cannot sync here, since we may be in a signal handler */
         sync_needed(dev);
     }
 
-    return 0;
+    return error;
 }
 
 static unsigned int
@@ -679,8 +680,8 @@ netdev_pltap_get_real_name(struct unixctl_conn *conn,
         unixctl_command_reply_error(conn, "no such pltap netdev");
         return;
     }
-    if (pltap_dev->error) {
-       unixctl_command_reply_error(conn, pltap_dev->error);
+    if (pltap_dev->fd < 0) {
+       unixctl_command_reply_error(conn, "no real device attached");
        return;
     }
 
@@ -712,8 +713,10 @@ netdev_pltap_run(void)
 static void
 netdev_pltap_wait(void)
 {
-    if (!list_is_empty(&sync_list))
+    if (!list_is_empty(&sync_list)) {
+        VLOG_DBG("netdev_pltap: scheduling sync");
         poll_immediate_wake();
+    }
 }
 
 const struct netdev_class netdev_pltap_class = {
index ec87871..e13374f 100644 (file)
@@ -3,6 +3,11 @@
 # HOST_<id> and IP_<id> for all nodes involved, as well as 
 # LINKS as a list of <node_id>-<node_id> elements
 
+# should work with any shell, but we have only tested bash
+SHELL=/bin/bash
+
+.DELETE_ON_ERROR:
+
 # run make CONF=anotherconfig.mk if you need several configs
 
 CONF ?= conf.mk
@@ -142,7 +147,7 @@ del-controllers: $(foreach id,$(ALL_NODE_IDS),del-controller-$(id))
 ### node-oriented targets
 # check ssh connectivity
 sshcheck-%: FORCE
-       @if $(SSH) $(HOST_$*) hostname &> /dev/null; then echo "ssh on" $(call display,$*) "OK" ; \
+       @if $(SSH) $(HOST_$*) hostname > /dev/null 2>&1; then echo "ssh on" $(call display,$*) "OK" ; \
         else echo "ssh on" $(call display,$*) "KO !!!"; fi
 
 ovsversion-%: FORCE
@@ -172,22 +177,24 @@ cache/host.%:
 
 cache/db.%:
        @echo "Starting db server on $(call display,$*) - logs in $(call log,$@)"
-       @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-db &> $(call log,$@) && touch $@
+       @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-db > $(call log,$@) 2>&1
+       @touch $@
 
 cache/switch.%: | cache/db.%
        @echo "Starting vswitchd on $(call display,$*) - logs in $(call log,$@)"
-       @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-switch &> $(call log,$@) && touch $@
+       @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-switch > $(call log,$@) 2>&1
+       @touch $@
 
 cache/bridge.%: | cache/db.%
        @echo "Creating bridge on $(call display,$*) - logs in $(call log,$@)"
        @$(SSH) $(HOST_$*) $(SUDO) \
-               sliver-ovs create-bridge $(BRIDGE) $(IP_$*) $(call default,BROPTIONS,$*) &> $(call log,$@) \
-        && { echo "IP_$*=$(IP_$*)"; echo "BROPTIONS_$*=$(call default,BROPTIONS,$*)"; } > $@
+               sliver-ovs create-bridge $(BRIDGE) $(IP_$*) $(call default,BROPTIONS,$*) > $(call log,$@) 2>&1
+       @{ echo "IP_$*=$(IP_$*)"; echo "BROPTIONS_$*=$(call default,BROPTIONS,$*)"; } > $@
 
 cache/controller.%: cache/bridge.%
        @echo "Setting controller $(call default,CONTROLLER,$*) on $(call display,$*) - logs in $(call log,$@)"
-       @$(SSH) $(HOST_$*) $(SUDO) ovs-vsctl set-controller $(BRIDGE) $(call default,CONTROLLER,$*) &> $(call log,$@) \
-        && echo "CONTROLLER_$*=$(call default,CONTROLLER,$*)" > $@
+       @$(SSH) $(HOST_$*) $(SUDO) ovs-vsctl set-controller $(BRIDGE) $(call default,CONTROLLER,$*) > $(call log,$@) 2>&1
+       @echo "CONTROLLER_$*=$(call default,CONTROLLER,$*)" > $@
 
 # xxx this probably needs a more thorough cleanup in cache/
 cache/stop.%: del-bridge.%
@@ -221,7 +228,7 @@ U/%: del-iface.%@1 del-iface.%@2
 # We invalidate the cache accordingly.
 del-bridge.%: | cache/db.%
        @echo "Deleting bridge on $(call display,$*)"
-       @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs del-bridge $(BRIDGE);
+       @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs del-bridge $(BRIDGE)
        @rm -f cache/bridge.$* \
              cache/iface.$*$(SEP)*@1 cache/iface.*$(SEP)$*@2 \
              cache/port.$*$(SEP)*@1  cache/port.*$(SEP)$*@2  \
@@ -299,13 +306,11 @@ remote-snapshot-links: $(addprefix cache/rsnap.links.,$(CONF_NODE_IDS))
 
 cache/rsnap.ip.%: FORCE
        @$(SSH) $(HOST_$*) $(SUDO) \
-               sliver-ovs get-local-ip $(BRIDGE) | sed 's/^/IP_$*=/' > $@ \
-        || { rm $@; exit 1; }
+               sliver-ovs get-local-ip $(BRIDGE) | sed 's/^/IP_$*=/' > $@ 
 
 cache/rsnap.links.%: FORCE
        @$(SSH) $(HOST_$*) $(SUDO) \
-               sliver-ovs get-local-links $(BRIDGE) | sed -n 's/^L/LINKS += /p' > $@ \
-        || { rm $@; exit 1; }
+               sliver-ovs get-local-links $(BRIDGE) | sed -n 's/^L/LINKS += /p' > $@
 
 ### update sliver-ovs
 update: $(addprefix update-,$(CONF_NODE_IDS))
@@ -355,8 +360,8 @@ del-iface.%: | cache/db.$$(call get,%)
 cache/iface.%: cache/bridge.$$(call get,%) | cache/db.$$(call get,%)
        @echo "Creating interface for link $(call linkpart,$(*F)) on $(call display,$(call get,$(*F))) - logs in $(call log,$@)"
        @$(SSH) $(call solve,$(call get,$(*F))) $(SUDO) sliver-ovs create-port $(BRIDGE) \
-               L$(call linkpart,$(*F)) &> $(call log,$@) \
-        && touch $@
+               L$(call linkpart,$(*F)) > $(call log,$@) 2>&1
+       @touch $@
 
 # cache/port.<node_id1>-<node_id2>@<endpoint>:
 #      Retrieves the local port of link <node_id1>-<node_id2> on
@@ -369,8 +374,7 @@ cache/iface.%: cache/bridge.$$(call get,%) | cache/db.$$(call get,%)
 cache/port.%: cache/iface.% cache/switch.$$(call get,%)
        @echo "Getting port number for link $(call linkpart,$(*F)) on $(call display,$(call get,$(*F))) - logs in $(call log,$@)"
        @$(SSH) $(call solve,$(call get,$(*F))) $(SUDO) \
-               sliver-ovs get-local-endpoint L$(call linkpart,$(*F)) > $@ 2> $(call log,$@) \
-        || { rm $@; exit 1; }
+               sliver-ovs get-local-endpoint L$(call linkpart,$(*F)) > $@ 2> $(call log,$@)
 
 
 # linkid=$(call linkpart,%)
@@ -388,8 +392,8 @@ cache/endpoint.%: cache/host.$$(call rget,%) cache/port.$$(call opp,%) cache/ifa
        @echo "Setting port number of link $(call linkpart,$(*F)) on $(call display,$(call get,$(*F))) - logs in $(call log,$@)"
        @$(SSH) $(call solve,$(call get,$(*F))) $(SUDO) sliver-ovs set-remote-endpoint L$(call linkpart,$(*F)) \
                        $$(cat cache/host.$(call rget,$(*F))) \
-                       $$(cat cache/port.$(call opp,$(*F))) 2> $(call log,$@) \
-        && touch $@
+                       $$(cat cache/port.$(call opp,$(*F))) 2> $(call log,$@)
+       @touch $@
 
 ####################
 CLEANTARGETS=$(addprefix del-,$(notdir $(wildcard cache/bridge.*)))
index 5fe2b71..ace5596 100644 (file)
@@ -49,6 +49,9 @@ rm -rf $RPM_BUILD_ROOT
 %postun
 
 %changelog
+* Fri Nov 23 2012 Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr> - sliver-openvswitch-1.8.90-6
+- fixes in the exp-tool makefile (bash redirections, scp with key..)
+
 * Tue Oct 16 2012 Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr> - sliver-openvswitch-1.8.90-5
 - numerous additional make targets for finer control (use make help)
 - including gprobe for reporting traffic to an ndnmap instance