Signed-off-by: Ben Pfaff <b...@ovn.org> --- 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 <config.h> #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 861f872..292df05 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 0x0A0000000000ULL #define MAC_ADDR_SPACE 0xffffff @@ -4012,28 +4009,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) { @@ -4233,8 +4208,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("OVN_NB_DB"); - if (!def) { - def = xasprintf("unix:%s/ovnnb_db.sock", ovs_rundir()); - } - } - return def; -} - static void parse_options(int argc, char *argv[], struct shash *local_options) { @@ -310,7 +297,7 @@ parse_options(int argc, char *argv[], struct shash *local_options) free(short_options); if (!db) { - db = nbctl_default_db(); + db = default_nb_db(); } for (i = n_global_long_options; options[i].name; i++) { @@ -424,7 +411,8 @@ Options:\n\ -t, --timeout=SECS wait at most SECS seconds\n\ --dry-run do not commit changes to database\n\ --oneline print exactly one line of output per command\n", - program_name, program_name, ctl_get_db_cmd_usage(), nbctl_default_db()); + program_name, program_name, ctl_get_db_cmd_usage(), + default_nb_db()); vlog_usage(); printf("\ --no-syslog equivalent to --verbose=nbctl:syslog:warn\n"); diff --git a/ovn/utilities/ovn-sbctl.c b/ovn/utilities/ovn-sbctl.c index 50c9f17..11d4c52 100644 --- a/ovn/utilities/ovn-sbctl.c +++ b/ovn/utilities/ovn-sbctl.c @@ -27,27 +27,27 @@ #include <string.h> #include <unistd.h> -#include "db-ctl-base.h" -#include "dirs.h" - #include "command-line.h" #include "compiler.h" -#include "openvswitch/dynamic-string.h" +#include "db-ctl-base.h" +#include "dirs.h" #include "fatal-signal.h" +#include "openvswitch/dynamic-string.h" #include "openvswitch/json.h" +#include "openvswitch/shash.h" +#include "openvswitch/vlog.h" +#include "ovn/lib/ovn-sb-idl.h" +#include "ovn/lib/ovn-util.h" #include "ovsdb-data.h" #include "ovsdb-idl.h" #include "poll-loop.h" #include "process.h" #include "sset.h" -#include "openvswitch/shash.h" #include "stream-ssl.h" #include "stream.h" #include "table.h" #include "timeval.h" #include "util.h" -#include "openvswitch/vlog.h" -#include "ovn/lib/ovn-sb-idl.h" VLOG_DEFINE_THIS_MODULE(sbctl); @@ -78,7 +78,6 @@ OVS_NO_RETURN static void sbctl_exit(int status); static void sbctl_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 *sbctl_default_db(void); static void run_prerequisites(struct ctl_command[], size_t n_commands, struct ovsdb_idl *); static bool do_sbctl(const char *args, struct ctl_command *, size_t n, @@ -151,19 +150,6 @@ main(int argc, char *argv[]) } } -static const char * -sbctl_default_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; -} - static void parse_options(int argc, char *argv[], struct shash *local_options) { @@ -286,7 +272,7 @@ parse_options(int argc, char *argv[], struct shash *local_options) free(short_options); if (!db) { - db = sbctl_default_db(); + db = default_sb_db(); } for (i = n_global_long_options; options[i].name; i++) { @@ -331,7 +317,8 @@ Options:\n\ -t, --timeout=SECS wait at most SECS seconds\n\ --dry-run do not commit changes to database\n\ --oneline print exactly one line of output per command\n", - program_name, program_name, ctl_get_db_cmd_usage(), sbctl_default_db()); + program_name, program_name, ctl_get_db_cmd_usage(), + default_sb_db()); vlog_usage(); printf("\ --no-syslog equivalent to --verbose=sbctl:syslog:warn\n"); -- 2.1.3 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev