ovs-appctl: register unixctl commands in the beginning
authorHuanle Han <hanxueluo@gmail.com>
Wed, 15 Jul 2015 15:41:05 +0000 (23:41 +0800)
committerBen Pfaff <blp@nicira.com>
Thu, 16 Jul 2015 18:50:46 +0000 (11:50 -0700)
Some commands of ovs-appctl were lazily registered when first
bridg or bfd was added. Before that, calling these commands raised a
error("xxx is not a valid command"). The problem commangs included
"bfd/...", "upcall/...","dpif/...","fdb/..." and so on.

Fix this by moving the register into the "bridge_init" and
"bridge_init_ofproto". All commands are registered at the moment
ovs-vswitchd starts.

Signed-off-by: Huanle Han <hanxueluo@gmail.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/bfd.c
lib/bfd.h
ofproto/ofproto-dpif-upcall.c
ofproto/ofproto-dpif-upcall.h
ofproto/ofproto-dpif.c
ofproto/ofproto.c
vswitchd/bridge.c

index 92fdbd8..889c76e 100644 (file)
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -329,6 +329,16 @@ bfd_get_status(const struct bfd *bfd, struct smap *smap)
     ovs_mutex_unlock(&mutex);
 }
 
+void
+bfd_init(void)
+{
+    unixctl_command_register("bfd/show", "[interface]", 0, 1,
+                             bfd_unixctl_show, NULL);
+    unixctl_command_register("bfd/set-forwarding",
+                             "[interface] normal|false|true", 1, 2,
+                             bfd_unixctl_set_forwarding_override, NULL);
+}
+
 /* Initializes, destroys, or reconfigures the BFD session 'bfd' (named 'name'),
  * according to the database configuration contained in 'cfg'.  Takes ownership
  * of 'bfd', which may be NULL.  Returns a BFD object which may be used as a
@@ -338,7 +348,6 @@ struct bfd *
 bfd_configure(struct bfd *bfd, const char *name, const struct smap *cfg,
               struct netdev *netdev) OVS_EXCLUDED(mutex)
 {
-    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
     static atomic_count udp_src = ATOMIC_COUNT_INIT(0);
 
     int decay_min_rx;
@@ -350,15 +359,6 @@ bfd_configure(struct bfd *bfd, const char *name, const struct smap *cfg,
     struct in_addr in_addr;
     uint8_t ea[ETH_ADDR_LEN];
 
-    if (ovsthread_once_start(&once)) {
-        unixctl_command_register("bfd/show", "[interface]", 0, 1,
-                                 bfd_unixctl_show, NULL);
-        unixctl_command_register("bfd/set-forwarding",
-                                 "[interface] normal|false|true", 1, 2,
-                                 bfd_unixctl_set_forwarding_override, NULL);
-        ovsthread_once_done(&once);
-    }
-
     if (!cfg || !smap_get_bool(cfg, "enable", false)) {
         bfd_unref(bfd);
         return NULL;
index 19d294f..19da3a3 100644 (file)
--- a/lib/bfd.h
+++ b/lib/bfd.h
@@ -43,6 +43,7 @@ bool bfd_should_process_flow(const struct bfd *, const struct flow *,
 void bfd_process_packet(struct bfd *, const struct flow *,
                         const struct dp_packet *);
 
+void bfd_init(void);
 struct bfd *bfd_configure(struct bfd *, const char *name,
                           const struct smap *smap,
                           struct netdev *netdev);
index c39b571..4f607d6 100644 (file)
@@ -304,12 +304,10 @@ static upcall_callback upcall_cb;
 static atomic_bool enable_megaflows = ATOMIC_VAR_INIT(true);
 static atomic_bool enable_ufid = ATOMIC_VAR_INIT(true);
 
-struct udpif *
-udpif_create(struct dpif_backer *backer, struct dpif *dpif)
+void
+udpif_init(void)
 {
     static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
-    struct udpif *udpif = xzalloc(sizeof *udpif);
-
     if (ovsthread_once_start(&once)) {
         unixctl_command_register("upcall/show", "", 0, 0, upcall_unixctl_show,
                                  NULL);
@@ -329,6 +327,12 @@ udpif_create(struct dpif_backer *backer, struct dpif *dpif)
                                  upcall_unixctl_purge, NULL);
         ovsthread_once_done(&once);
     }
+}
+
+struct udpif *
+udpif_create(struct dpif_backer *backer, struct dpif *dpif)
+{
+    struct udpif *udpif = xzalloc(sizeof *udpif);
 
     udpif->dpif = dpif;
     udpif->backer = backer;
index ec19bd0..efa3cd1 100644 (file)
@@ -28,6 +28,7 @@ struct simap;
  * them.  Additionally, it's responsible for maintaining the datapath flow
  * table. */
 
+void udpif_init(void);
 struct udpif *udpif_create(struct dpif_backer *, struct dpif *);
 void udpif_run(struct udpif *udpif);
 void udpif_set_threads(struct udpif *, size_t n_handlers,
index 8575b1c..b08ea5d 100644 (file)
@@ -443,6 +443,9 @@ init(const struct shash *iface_hints)
 
         shash_add(&init_ofp_ports, node->name, new_hint);
     }
+
+    ofproto_unixctl_init();
+    udpif_init();
 }
 
 static void
@@ -1256,8 +1259,6 @@ construct(struct ofproto *ofproto_)
 
     guarded_list_init(&ofproto->pins);
 
-    ofproto_unixctl_init();
-
     hmap_init(&ofproto->vlandev_map);
     hmap_init(&ofproto->realdev_vid_map);
 
index 42bbc9b..6dda3cd 100644 (file)
@@ -379,6 +379,8 @@ ofproto_init(const struct shash *iface_hints)
     for (i = 0; i < n_ofproto_classes; i++) {
         ofproto_classes[i]->init(&init_ofp_ports);
     }
+
+    ofproto_unixctl_init();
 }
 
 /* 'type' should be a normalized datapath type, as returned by
@@ -507,8 +509,6 @@ ofproto_create(const char *datapath_name, const char *datapath_type,
 
     *ofprotop = NULL;
 
-    ofproto_unixctl_init();
-
     datapath_type = ofproto_normalize_type(datapath_type);
     class = ofproto_class_find__(datapath_type);
     if (!class) {
index d48cf7f..cecfad4 100644 (file)
@@ -473,6 +473,7 @@ bridge_init(const char *remote)
     lacp_init();
     bond_init();
     cfm_init();
+    bfd_init();
     ovs_numa_init();
     stp_init();
     lldp_init();