[ovs-dev] [PATCH v5 2/8] ovn-util: Add common functions for the default NB and SB databases.

2016-08-14 Thread Ben Pfaff
Signed-off-by: Ben Pfaff 
Acked-by: Ryan Moats 
---
 ovn/controller-vtep/ovn-controller-vtep.c |  5 +++--
 ovn/lib/ovn-util.c| 27 +
 ovn/lib/ovn-util.h|  4 
 ovn/northd/ovn-northd.c   | 27 -
 ovn/utilities/ovn-nbctl.c | 20 ---
 ovn/utilities/ovn-sbctl.c | 33 ++-
 6 files changed, 48 insertions(+), 68 deletions(-)

diff --git a/ovn/controller-vtep/ovn-controller-vtep.c 
b/ovn/controller-vtep/ovn-controller-vtep.c
index 36005ed..baee789 100644
--- a/ovn/controller-vtep/ovn-controller-vtep.c
+++ b/ovn/controller-vtep/ovn-controller-vtep.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015 Nicira, Inc.
+/* Copyright (c) 2015, 2016 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@
 #include "openvswitch/vconn.h"
 #include "openvswitch/vlog.h"
 #include "ovn/lib/ovn-sb-idl.h"
+#include "ovn/lib/ovn-util.h"
 #include "vtep/vtep-idl.h"
 
 #include "binding.h"
@@ -231,7 +232,7 @@ parse_options(int argc, char *argv[])
 free(short_options);
 
 if (!ovnsb_remote) {
-ovnsb_remote = xstrdup(default_db());
+ovnsb_remote = xstrdup(default_sb_db());
 }
 
 if (!vtep_remote) {
diff --git a/ovn/lib/ovn-util.c b/ovn/lib/ovn-util.c
index b51cb4a..ff0d204 100644
--- a/ovn/lib/ovn-util.c
+++ b/ovn/lib/ovn-util.c
@@ -14,6 +14,7 @@
 
 #include 
 #include "ovn-util.h"
+#include "dirs.h"
 #include "openvswitch/vlog.h"
 #include "ovn/lib/ovn-nb-idl.h"
 
@@ -201,3 +202,29 @@ alloc_nat_zone_key(const char *key, const char *type)
 {
 return xasprintf("%s_%s", key, type);
 }
+
+const char *
+default_nb_db(void)
+{
+static char *def;
+if (!def) {
+def = getenv("OVN_NB_DB");
+if (!def) {
+def = xasprintf("unix:%s/ovnnb_db.sock", ovs_rundir());
+}
+}
+return def;
+}
+
+const char *
+default_sb_db(void)
+{
+static char *def;
+if (!def) {
+def = getenv("OVN_SB_DB");
+if (!def) {
+def = xasprintf("unix:%s/ovnsb_db.sock", ovs_rundir());
+}
+}
+return def;
+}
diff --git a/ovn/lib/ovn-util.h b/ovn/lib/ovn-util.h
index 97d9483..c2ac471 100644
--- a/ovn/lib/ovn-util.h
+++ b/ovn/lib/ovn-util.h
@@ -59,4 +59,8 @@ bool extract_lrp_networks(const struct 
nbrec_logical_router_port *,
 void destroy_lport_addresses(struct lport_addresses *);
 
 char *alloc_nat_zone_key(const char *key, const char *type);
+
+const char *default_nb_db(void);
+const char *default_sb_db(void);
+
 #endif
diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c
index 8f99533..1bb0430 100644
--- a/ovn/northd/ovn-northd.c
+++ b/ovn/northd/ovn-northd.c
@@ -56,9 +56,6 @@ struct northd_context {
 static const char *ovnnb_db;
 static const char *ovnsb_db;
 
-static const char *default_nb_db(void);
-static const char *default_sb_db(void);
-
 #define MAC_ADDR_PREFIX 0x0A00ULL
 #define MAC_ADDR_SPACE 0xff
 
@@ -4173,28 +4170,6 @@ ovnsb_db_run(struct northd_context *ctx, struct 
ovsdb_idl_loop *sb_loop)
 update_northbound_cfg(ctx, sb_loop);
 }
 
-static char *default_nb_db_;
-
-static const char *
-default_nb_db(void)
-{
-if (!default_nb_db_) {
-default_nb_db_ = xasprintf("unix:%s/ovnnb_db.sock", ovs_rundir());
-}
-return default_nb_db_;
-}
-
-static char *default_sb_db_;
-
-static const char *
-default_sb_db(void)
-{
-if (!default_sb_db_) {
-default_sb_db_ = xasprintf("unix:%s/ovnsb_db.sock", ovs_rundir());
-}
-return default_sb_db_;
-}
-
 static void
 parse_options(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
 {
@@ -4398,8 +4373,6 @@ main(int argc, char *argv[])
 ovsdb_idl_loop_destroy(&ovnsb_idl_loop);
 service_stop();
 
-free(default_nb_db_);
-free(default_sb_db_);
 exit(res);
 }
 
diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index 9d5b1df..d6d64ea 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -25,6 +25,7 @@
 #include "fatal-signal.h"
 #include "openvswitch/json.h"
 #include "ovn/lib/ovn-nb-idl.h"
+#include "ovn/lib/ovn-util.h"
 #include "packets.h"
 #include "poll-loop.h"
 #include "process.h"
@@ -77,7 +78,6 @@ OVS_NO_RETURN static void nbctl_exit(int status);
 static void nbctl_cmd_init(void);
 OVS_NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[], struct shash *local_options);
-static const char *nbctl_default_db(void);
 static void run_prerequisites(struct ctl_command[], size_t n_commands,
   struct ovsdb_idl *);
 static bool do_nbctl(const char *args, struct ctl_command *, size_t n,
@@ -153,19 +153,6 @@ main(int argc, char *argv[])
 }
 }
 
-static const char *
-nbctl_default_db(void)
-{
-static char *def;
-if (!def) {
-def = getenv("O

Re: [ovs-dev] [PATCH v5 2/8] ovn-util: Add common functions for the default NB and SB databases.

2016-08-15 Thread Justin Pettit

> On Aug 14, 2016, at 3:24 PM, Ben Pfaff  wrote:
> 
> Signed-off-by: Ben Pfaff 
> Acked-by: Ryan Moats 

I gave an ack for v3 not realizing that we were already up to v5.

Acked-by: Justin Pettit 

--Justin


___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev