Skip to content

Commit

Permalink
Add support for using OVN specific rundirs
Browse files Browse the repository at this point in the history
Until now, OVN uses the openvswitch rundirs (rundir, logdir, etcdir).
The commit [1] changed the package name from openvswitch to ovn, but
it didn't take into the account the effects of it. When "make install"
is run ovn-ctl utility is copied to /usr/local/share/ovn/scripts folder.
ovn-ctl depends on 'ovs-lib' and it is not present in this scripts foler.
Because of which we cannot start OVN services using ovn-ctl.

This patch addresses all these issues. It changes the rundir to
ovn specific ones. (i.e /usr/local/var/run/ovn, /usr/local/var/log/ovn,
/usr/local/etc/ovn with default configuration).

[1] - 7795e0e("Change the package name from openvswitch to ovn in AC_INIT()")

Tested:by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Numan Siddique <nusiddiq@redhat.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
  • Loading branch information
numansiddique authored and ovsrobot committed Aug 13, 2019
1 parent 7984c60 commit 28f87d1
Show file tree
Hide file tree
Showing 17 changed files with 491 additions and 55 deletions.
30 changes: 17 additions & 13 deletions Documentation/intro/install/general.rst
Expand Up @@ -153,17 +153,17 @@ invoke configure without any arguments. For example::

$ ./configure

By default all files are installed under ``/usr/local``. OVN and Open vSwitch
also expects to find its database in ``/usr/local/etc/openvswitch`` by default.
By default all files are installed under ``/usr/local``. OVN expects to find
its database in ``/usr/local/etc/ovn`` by default.
If you want to install all files into, e.g., ``/usr`` and ``/var`` instead of
``/usr/local`` and ``/usr/local/var`` and expect to use ``/etc/openvswitch`` as
``/usr/local`` and ``/usr/local/var`` and expect to use ``/etc/ovn`` as
the default database directory, add options as shown here::

$ ./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc

.. note::

Open vSwitch and OVN installed with packages like .rpm (e.g. via
OVN installed with packages like .rpm (e.g. via
``yum install`` or ``rpm -ivh``) and .deb (e.g. via
``apt-get install`` or ``dpkg -i``) use the above configure options.

Expand Down Expand Up @@ -319,9 +319,13 @@ and stopping ovn-northd, ovn-controller and ovsdb-servers. After installation,
the daemons can be started by using the ovn-ctl utility. This will take care
to setup initial conditions, and start the daemons in the correct order.
The ovn-ctl utility is located in '$(pkgdatadir)/scripts', and defaults to
'/usr/local/share/openvswitch/scripts'. An example after install might be::
'/usr/local/share/ovn/scripts'. ovn-ctl utility requires the 'ovs-lib'
helper shell script which is present in '/usr/local/share/openvswitch/scripts'.
So invoking ovn-ctl as "./ovn-ctl" will fail.

$ export PATH=$PATH:/usr/local/share/openvswitch/scripts
An example after install might be::

$ export PATH=$PATH:/usr/local/share/ovn/scripts
$ ovn-ctl start_northd
$ ovn-ctl start_controller

Expand All @@ -331,7 +335,7 @@ Starting OVN Central services
OVN central services includes ovn-northd, Northbound and
Southbound ovsdb-server.

$ export PATH=$PATH:/usr/local/share/openvswitch/scripts
$ export PATH=$PATH:/usr/local/share/ovn/scripts
$ ovn-ctl start_northd

Refer to ovn-ctl(8) for more information and the supported options.
Expand All @@ -341,23 +345,23 @@ Before starting ovn-northd you need to start OVN Northbound and Southbound
ovsdb-servers. Before ovsdb-servers can be started,
configure the Northbound and Southbound databases::

$ mkdir -p /usr/local/etc/openvswitch
$ ovsdb-tool create /usr/local/etc/openvswitch/ovnnb_db.db \
$ mkdir -p /usr/local/etc/ovn
$ ovsdb-tool create /usr/local/etc/ovn/ovnnb_db.db \
ovn-nb.ovsschema
$ ovsdb-tool create /usr/local/etc/openvswitch/ovnsb_db.db \
$ ovsdb-tool create /usr/local/etc/ovn/ovnsb_db.db \
ovn-sb.ovsschema

Configure ovsdb-servers to use databases created above, to listen on a Unix
domain socket and to use the SSL configuration in the database::

$ mkdir -p /usr/local/var/run/openvswitch
$ ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/ovnnb_db.sock \
$ mkdir -p /usr/local/var/run/ovn
$ ovsdb-server --remote=punix:/usr/local/var/run/ovn/ovnnb_db.sock \
--remote=db:OVN_Northbound,NB_Global,connections \
--private-key=db:OVN_Northbound,SSL,private_key \
--certificate=db:OVN_Northbound,SSL,certificate \
--bootstrap-ca-cert=db:OVN_Northbound,SSL,ca_cert \
--pidfile --detach --log-file
$ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/ovnsb_db.sock \
$ovsdb-server --remote=punix:/usr/local/var/run/ovn/ovnsb_db.sock \
--remote=db:OVN_Southbound,SB_Global,connections \
--private-key=db:OVN_Southbound,SSL,private_key \
--certificate=db:OVN_Southbound,SSL,certificate \
Expand Down
5 changes: 5 additions & 0 deletions Makefile.am
Expand Up @@ -177,6 +177,7 @@ SUFFIXES += .in
-e 's,[@]DBDIR[@],$(DBDIR),g' \
-e 's,[@]PYTHON[@],$(PYTHON),g' \
-e 's,[@]RUNDIR[@],$(RUNDIR),g' \
-e 's,[@]OVN_RUNDIR[@],$(OVN_RUNDIR),g' \
-e 's,[@]VERSION[@],$(VERSION),g' \
-e 's,[@]localstatedir[@],$(localstatedir),g' \
-e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \
Expand All @@ -202,6 +203,7 @@ SUFFIXES += .xml
DBDIR='$(DBDIR)' \
PYTHON='$(PYTHON)' \
RUNDIR='$(RUNDIR)' \
OVN_RUNDIR='$(OVN_RUNDIR)' \
VERSION='$(VERSION)' \
localstatedir='$(localstatedir)' \
pkgdatadir='$(pkgdatadir)' \
Expand Down Expand Up @@ -502,6 +504,9 @@ ALL_LOCAL += ovn-sb.ovsschema.stamp
ovn-sb.ovsschema.stamp: ovn-sb.ovsschema
$(srcdir)/build-aux/cksum-schema-check $? $@

pkgdata_DATA += ovn-nb.ovsschema
pkgdata_DATA += ovn-sb.ovsschema

CLEANFILES += ovn-sb.ovsschema.stamp

include Documentation/automake.mk
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -123,6 +123,7 @@ AC_CHECK_HEADERS([net/if_mib.h], [], [], [[#include <sys/types.h>

OVS_CHECK_PKIDIR
OVS_CHECK_RUNDIR
OVN_CHECK_RUNDIR
OVS_CHECK_DBDIR
OVS_CHECK_BACKTRACE
OVS_CHECK_PERF_EVENT
Expand Down
4 changes: 3 additions & 1 deletion controller/ovn-controller.c
Expand Up @@ -1715,7 +1715,9 @@ main(int argc, char *argv[])

daemonize_start(false);

retval = unixctl_server_create(NULL, &unixctl);
char *abs_unixctl_path = get_abs_unix_ctl_path();
retval = unixctl_server_create(abs_unixctl_path, &unixctl);
free(abs_unixctl_path);
if (retval) {
exit(EXIT_FAILURE);
}
Expand Down
20 changes: 19 additions & 1 deletion lib/automake.mk
Expand Up @@ -9,6 +9,7 @@ lib_libovn_la_SOURCES = \
lib/actions.c \
lib/chassis-index.c \
lib/chassis-index.h \
lib/ovn-dirs.h \
lib/expr.c \
lib/extend-table.h \
lib/extend-table.c \
Expand All @@ -24,6 +25,7 @@ lib_libovn_la_SOURCES = \
lib/inc-proc-eng.c \
lib/inc-proc-eng.h
nodist_lib_libovn_la_SOURCES = \
lib/ovn-dirs.c \
lib/ovn-nb-idl.c \
lib/ovn-nb-idl.h \
lib/ovn-sb-idl.c \
Expand All @@ -34,7 +36,23 @@ OVSIDL_BUILT += \
lib/ovn-sb-idl.c \
lib/ovn-sb-idl.h \
lib/ovn-sb-idl.ovsidl
EXTRA_DIST += lib/ovn-sb-idl.ann
EXTRA_DIST += \
lib/ovn-sb-idl.ann \
lib/ovn-dirs.c.in

lib/ovn-dirs.c: lib/ovn-dirs.c.in Makefile
$(AM_V_GEN)($(ro_c) && sed < $(srcdir)/lib/ovn-dirs.c.in \
-e 's,[@]srcdir[@],$(srcdir),g' \
-e 's,[@]LOGDIR[@],"$(LOGDIR)",g' \
-e 's,[@]RUNDIR[@],"$(RUNDIR)",g' \
-e 's,[@]OVN_RUNDIR[@],"$(OVN_RUNDIR)",g' \
-e 's,[@]DBDIR[@],"$(DBDIR)",g' \
-e 's,[@]bindir[@],"$(bindir)",g' \
-e 's,[@]sysconfdir[@],"$(sysconfdir)",g' \
-e 's,[@]pkgdatadir[@],"$(pkgdatadir)",g') \
> lib/ovn-dirs.c.tmp && \
mv lib/ovn-dirs.c.tmp lib/ovn-dirs.c

OVN_SB_IDL_FILES = \
$(srcdir)/ovn-sb.ovsschema \
$(srcdir)/lib/ovn-sb-idl.ann
Expand Down
112 changes: 112 additions & 0 deletions lib/ovn-dirs.c.in
@@ -0,0 +1,112 @@
#line 2 "@srcdir@/lib/dirs.c.in"
/*
* Copyright (c) 2019
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <config.h>
#include "ovn-dirs.h"
#include <stdlib.h>
#include "lib/ovs-thread.h"
#include "lib/util.h"

struct directory {
const char *value; /* Actual value; NULL if not yet determined. */
const char *default_value; /* Default value. */
const char *var_name; /* Environment variable to override default. */
struct ovsthread_once once; /* Ensures 'value' gets initialized once. */
};

static const char *
get_dir(struct directory *d)
{
if (ovsthread_once_start(&d->once)) {
d->value = getenv(d->var_name);
if (!d->value || !d->value[0]) {
d->value = d->default_value;
}
ovsthread_once_done(&d->once);
}
return d->value;
}

const char *
ovn_sysconfdir(void)
{
static struct directory d = {
NULL, @sysconfdir@, "OVN_SYSCONFDIR", OVSTHREAD_ONCE_INITIALIZER
};

return get_dir(&d);
}

const char *
ovn_pkgdatadir(void)
{
static struct directory d = {
NULL, @pkgdatadir@, "OVN_PKGDATADIR", OVSTHREAD_ONCE_INITIALIZER
};

return get_dir(&d);
}

const char *
ovn_rundir(void)
{
static struct directory d = {
NULL, @OVN_RUNDIR@, "OVN_RUNDIR", OVSTHREAD_ONCE_INITIALIZER
};

return get_dir(&d);
}

const char *
ovn_logdir(void)
{
static struct directory d = {
NULL, @LOGDIR@, "OVN_LOGDIR", OVSTHREAD_ONCE_INITIALIZER
};

return get_dir(&d);
}

const char *
ovn_dbdir(void)
{
static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
static const char *dbdir;

if (ovsthread_once_start(&once)) {
dbdir = getenv("OVN_DBDIR");
if (!dbdir || !dbdir[0]) {
char *sysconfdir = getenv("OVN_SYSCONFDIR");

dbdir = (sysconfdir
? xasprintf("%s/ovn", sysconfdir)
: @DBDIR@);
}
ovsthread_once_done(&once);
}
return dbdir;
}

const char *
ovn_bindir(void)
{
static struct directory d = {
NULL, @bindir@, "OVN_BINDIR", OVSTHREAD_ONCE_INITIALIZER
};

return get_dir(&d);
}
35 changes: 35 additions & 0 deletions lib/ovn-dirs.h
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2019.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef OVN_DIRS_H
#define OVN_DIRS_H 1

#ifdef __cplusplus
extern "C" {
#endif

const char *ovn_sysconfdir(void); /* /usr/local/etc */
const char *ovn_pkgdatadir(void); /* /usr/local/share/ovn */
const char *ovn_rundir(void); /* /usr/local/var/run/ovn */
const char *ovn_logdir(void); /* /usr/local/var/log/ovn */
const char *ovn_dbdir(void); /* /usr/local/etc/ovn */
const char *ovn_bindir(void); /* /usr/local/bin */

#ifdef __cplusplus
}
#endif

#endif /* OVN_DIRS_H */
24 changes: 21 additions & 3 deletions lib/ovn-util.c
Expand Up @@ -13,8 +13,10 @@
*/

#include <config.h>
#include <unistd.h>

#include "ovn-util.h"
#include "dirs.h"
#include "ovn-dirs.h"
#include "openvswitch/vlog.h"
#include "ovn-nb-idl.h"
#include "ovn-sb-idl.h"
Expand Down Expand Up @@ -296,7 +298,7 @@ default_nb_db(void)
if (!def) {
def = getenv("OVN_NB_DB");
if (!def) {
def = xasprintf("unix:%s/ovnnb_db.sock", ovs_rundir());
def = xasprintf("unix:%s/ovnnb_db.sock", ovn_rundir());
}
}
return def;
Expand All @@ -309,12 +311,28 @@ default_sb_db(void)
if (!def) {
def = getenv("OVN_SB_DB");
if (!def) {
def = xasprintf("unix:%s/ovnsb_db.sock", ovs_rundir());
def = xasprintf("unix:%s/ovnsb_db.sock", ovn_rundir());
}
}
return def;
}

char *
get_abs_unix_ctl_path(void)
{
#ifdef _WIN32
enum { WINDOWS = 1 };
#else
enum { WINDOWS = 0 };
#endif

long int pid = getpid();
char *abs_path =
WINDOWS ? xasprintf("%s/%s.ctl", ovn_rundir(), program_name)
: xasprintf("%s/%s.%ld.ctl", ovn_rundir(), program_name, pid);
return abs_path;
}

/* l3gateway, chassisredirect, and patch
* are not in this list since they are
* only set in the SB DB by northd
Expand Down
1 change: 1 addition & 0 deletions lib/ovn-util.h
Expand Up @@ -67,6 +67,7 @@ char *alloc_nat_zone_key(const struct uuid *key, const char *type);

const char *default_nb_db(void);
const char *default_sb_db(void);
char *get_abs_unix_ctl_path(void);

struct ovsdb_idl_table_class;
const char *db_table_usage(struct ds *tables,
Expand Down
11 changes: 11 additions & 0 deletions m4/openvswitch.m4
Expand Up @@ -330,6 +330,17 @@ AC_DEFUN([OVS_CHECK_RUNDIR],
[RUNDIR='${localstatedir}/run/openvswitch'])
AC_SUBST([RUNDIR])])

dnl Checks for the directory in which to store pidfiles.
AC_DEFUN([OVN_CHECK_RUNDIR],
[AC_ARG_WITH(
[rundir],
AC_HELP_STRING([--with-ovn-rundir=DIR],
[directory used for pidfiles
[[LOCALSTATEDIR/run/ovn]]]),
[OVN_RUNDIR=$withval],
[OVN_RUNDIR='${localstatedir}/run/ovn'])
AC_SUBST([OVN_RUNDIR])])

dnl Checks for the directory in which to store logs.
AC_DEFUN([OVS_CHECK_LOGDIR],
[AC_ARG_WITH(
Expand Down

0 comments on commit 28f87d1

Please sign in to comment.