diff mbox

[ovs-dev,1/3] ovs-router: fix refcnt leak when program terminates.

Message ID 20170529194023.15414-2-fbl@redhat.com
State Accepted
Headers show

Commit Message

Flavio Leitner May 29, 2017, 7:40 p.m. UTC
Install a handler to flush routes and release devices when
the program is terminating.

Signed-off-by: Flavio Leitner <fbl@redhat.com>
---
 lib/ovs-router.c | 34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

Comments

Ben Pfaff June 7, 2017, 12:10 a.m. UTC | #1
On Mon, May 29, 2017 at 04:40:21PM -0300, Flavio Leitner wrote:
> Install a handler to flush routes and release devices when
> the program is terminating.
> 
> Signed-off-by: Flavio Leitner <fbl@redhat.com>

Thank you!  I applied this to master.

If you think that this is a bug fix that I should backport to earlier
versions, let me know.
Flavio Leitner June 7, 2017, 2:54 p.m. UTC | #2
On Tue, Jun 06, 2017 at 05:10:10PM -0700, Ben Pfaff wrote:
> On Mon, May 29, 2017 at 04:40:21PM -0300, Flavio Leitner wrote:
> > Install a handler to flush routes and release devices when
> > the program is terminating.
> > 
> > Signed-off-by: Flavio Leitner <fbl@redhat.com>
> 
> Thank you!  I applied this to master.
> 
> If you think that this is a bug fix that I should backport to earlier
> versions, let me know.

The bug is definitely present on branch-2.7. However, I don't know a
way to trigger it there, so I suspect the backport isn't required.

Thanks Ben,
diff mbox

Patch

diff --git a/lib/ovs-router.c b/lib/ovs-router.c
index 96871d1..dd23c88 100644
--- a/lib/ovs-router.c
+++ b/lib/ovs-router.c
@@ -33,6 +33,7 @@ 
 #include "command-line.h"
 #include "compiler.h"
 #include "dpif.h"
+#include "fatal-signal.h"
 #include "openvswitch/dynamic-string.h"
 #include "netdev.h"
 #include "packets.h"
@@ -484,16 +485,33 @@  ovs_router_flush(void)
     seq_change(tnl_conf_seq);
 }
 
+static void
+ovs_router_flush_handler(void *aux OVS_UNUSED)
+{
+    ovs_router_flush();
+}
+
 /* May not be called more than once. */
 void
 ovs_router_init(void)
 {
-    classifier_init(&cls, NULL);
-    unixctl_command_register("ovs/route/add", "ip_addr/prefix_len out_br_name [gw] [pkt_mark=mark]", 2, 4,
-                             ovs_router_add, NULL);
-    unixctl_command_register("ovs/route/show", "", 0, 0, ovs_router_show, NULL);
-    unixctl_command_register("ovs/route/del", "ip_addr/prefix_len [pkt_mark=mark]", 1, 2,
-                             ovs_router_del, NULL);
-    unixctl_command_register("ovs/route/lookup", "ip_addr [pkt_mark=mark]", 1, 2,
-                             ovs_router_lookup_cmd, NULL);
+    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
+
+    if (ovsthread_once_start(&once)) {
+        fatal_signal_add_hook(ovs_router_flush_handler, NULL, NULL, true);
+        classifier_init(&cls, NULL);
+        unixctl_command_register("ovs/route/add",
+                                 "ip_addr/prefix_len out_br_name [gw] "
+                                 "[pkt_mark=mark]",
+                                 2, 4, ovs_router_add, NULL);
+        unixctl_command_register("ovs/route/show", "", 0, 0,
+                                 ovs_router_show, NULL);
+        unixctl_command_register("ovs/route/del", "ip_addr/prefix_len "
+                                 "[pkt_mark=mark]", 1, 2, ovs_router_del,
+                                 NULL);
+        unixctl_command_register("ovs/route/lookup", "ip_addr "
+                                 "[pkt_mark=mark]", 1, 2,
+                                 ovs_router_lookup_cmd, NULL);
+        ovsthread_once_done(&once);
+    }
 }