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 <[email protected]>
Acked-by: Mark Michelson <[email protected]>
Signed-off-by: Numan Siddique <[email protected]>
  • Loading branch information
numansiddique committed Aug 29, 2019
1 parent ff4439d commit 2cfaaa4
Show file tree
Hide file tree
Showing 19 changed files with 520 additions and 113 deletions.
30 changes: 17 additions & 13 deletions Documentation/intro/install/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,17 @@ For example::
If you have built Open vSwitch in a separate directory, then you
need to provide that path in the option - --with-ovs-build.

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 @@ -338,9 +338,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 @@ -350,7 +354,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 @@ -360,23 +364,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
6 changes: 5 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ SUFFIXES += .in
-e 's,[@]LOGDIR[@],$(LOGDIR),g' \
-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 @@ -205,6 +205,7 @@ SUFFIXES += .xml
DBDIR='$(DBDIR)' \
PYTHON='$(PYTHON)' \
RUNDIR='$(RUNDIR)' \
OVN_RUNDIR='$(OVN_RUNDIR)' \
VERSION='$(VERSION)' \
localstatedir='$(localstatedir)' \
pkgdatadir='$(pkgdatadir)' \
Expand Down Expand Up @@ -498,6 +499,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
2 changes: 2 additions & 0 deletions TODO_SPLIT.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Immediate tasks
- ovn-architecture manpage generation.
This needs to be fixed.

* Cleanup the acinclude.m4 and m4 folder

Immediate to Short-term tasks
-----------------------------

Expand Down
34 changes: 16 additions & 18 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ OVS_CHECK_ESX
OVS_CHECK_WIN64
OVS_CHECK_WIN32
OVS_CHECK_VISUAL_STUDIO_DDK
OVS_CHECK_COVERAGE
OVN_CHECK_COVERAGE
OVS_CHECK_NDEBUG
OVS_CHECK_NETLINK
OVS_CHECK_OPENSSL
OVS_CHECK_LIBCAPNG
OVS_CHECK_LOGDIR
OVS_CHECK_PYTHON2
OVS_CHECK_PYTHON3
OVS_CHECK_PYTHON
OVS_CHECK_FLAKE8
OVS_CHECK_SPHINX
OVS_CHECK_DOT
OVN_CHECK_LIBCAPNG
OVN_CHECK_LOGDIR
OVN_CHECK_PYTHON2
OVN_CHECK_PYTHON3
OVN_CHECK_PYTHON
OVN_CHECK_FLAKE8
OVN_CHECK_SPHINX
OVN_CHECK_DOT
OVS_CHECK_IF_DL
OVS_CHECK_STRTOK_R
AC_CHECK_DECLS([sys_siglist], [], [], [[#include <signal.h>]])
Expand All @@ -116,14 +116,12 @@ AC_CHECK_HEADERS([net/if_mib.h], [], [], [[#include <sys/types.h>
#include <net/if.h>]])

OVS_CHECK_PKIDIR
OVS_CHECK_RUNDIR
OVS_CHECK_DBDIR
OVS_CHECK_BACKTRACE
OVS_CHECK_PERF_EVENT
OVS_CHECK_VALGRIND
OVS_CHECK_SOCKET_LIBS
OVS_CHECK_XENSERVER_VERSION
OVS_CHECK_GROFF
OVN_CHECK_RUNDIR
OVN_CHECK_DBDIR
OVN_CHECK_BACKTRACE
OVN_CHECK_PERF_EVENT
OVN_CHECK_VALGRIND
OVN_CHECK_GROFF
OVS_CHECK_TLS
OVS_CHECK_ATOMIC_LIBS
OVS_CHECK_GCC4_ATOMICS
Expand All @@ -137,7 +135,7 @@ OVS_CHECK_LINUX_HOST
OVS_LIBTOOL_VERSIONS
OVS_CHECK_CXX
AX_FUNC_POSIX_MEMALIGN
OVS_CHECK_UNBOUND
OVN_CHECK_UNBOUND

OVS_CHECK_INCLUDE_NEXT([stdio.h string.h])
AC_CONFIG_FILES([lib/libovn.sym])
Expand Down
4 changes: 3 additions & 1 deletion controller/ovn-controller.c
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions lib/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/ovn-sb-idl.c
/ovn-sb-idl.h
/ovn-sb-idl.ovsidl
/ovn-dirs.c
21 changes: 20 additions & 1 deletion lib/automake.mk
Original file line number Diff line number Diff line change
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,17 +25,35 @@ 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 \
lib/ovn-sb-idl.h

CLEANFILES += $(nodist_lib_libovn_la_SOURCES)

# ovn-sb IDL
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,[@]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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 */
Loading

0 comments on commit 2cfaaa4

Please sign in to comment.