@@ -76,9 +76,6 @@ main(int argc, char *argv[])
daemonize_complete();
- vteprec_init();
- sbrec_init();
-
/* Connect to VTEP database. */
struct ovsdb_idl_loop vtep_idl_loop = OVSDB_IDL_LOOP_INITIALIZER(
ovsdb_idl_create(vtep_remote, &vteprec_idl_class, true, true));
@@ -432,9 +432,6 @@ main(int argc, char *argv[])
daemonize_complete();
- ovsrec_init();
- sbrec_init();
-
ofctrl_init(&group_table);
pinctrl_init();
lflow_init();
@@ -4744,9 +4744,6 @@ main(int argc, char *argv[])
daemonize_complete();
- nbrec_init();
- sbrec_init();
-
/* We want to detect (almost) all changes to the ovn-nb db. */
struct ovsdb_idl_loop ovnnb_idl_loop = OVSDB_IDL_LOOP_INITIALIZER(
ovsdb_idl_create(ovnnb_db, &nbrec_idl_class, true, true));
@@ -99,7 +99,6 @@ main(int argc, char *argv[])
fatal_ignore_sigpipe();
vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN);
vlog_set_levels_from_string_assert("reconnect:warn");
- nbrec_init();
nbctl_cmd_init();
@@ -97,7 +97,6 @@ main(int argc, char *argv[])
fatal_ignore_sigpipe();
vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN);
vlog_set_levels_from_string_assert("reconnect:warn");
- sbrec_init();
sbctl_cmd_init();
@@ -76,7 +76,6 @@ main(int argc, char *argv[])
service_start(&argc, &argv);
fatal_ignore_sigpipe();
vlog_set_levels_from_string_assert("reconnect:warn");
- sbrec_init();
/* Parse command line. */
parse_options(argc, argv);
@@ -283,7 +283,6 @@ bool %(s)s_is_updated(const struct %(s)s *, enum %(s)s_column_id);
print "\nextern struct ovsdb_idl_table_class %stable_classes[%sN_TABLES];" % (prefix, prefix.upper())
print "\nextern struct ovsdb_idl_class %sidl_class;" % prefix
- print "\nvoid %sinit(void);" % prefix
print "\nconst char * %sget_db_version(void);" % prefix
print "\n#endif /* %(prefix)sIDL_HEADER */" % {'prefix': prefix.upper()}
@@ -319,7 +318,6 @@ enum { sizeof_bool = 1 };
enum { sizeof_bool = sizeof(bool) };
#endif
-static bool inited;
''' % schema.idlHeader
# Cast functions.
@@ -345,7 +343,6 @@ static struct %(s)s *
static void
%(s)s_parse_%(c)s(struct ovsdb_idl_row *row_, const struct ovsdb_datum *datum)
{
- ovs_assert(inited);
struct %(s)s *row = %(s)s_cast(row_);''' % {'s': structName,
'c': columnName}
type = column.type
@@ -447,9 +444,8 @@ static void
static void
%(s)s_unparse_%(c)s(struct ovsdb_idl_row *row_)
{
- struct %(s)s *row = %(s)s_cast(row_);
-
- ovs_assert(inited);''' % {'s': structName, 'c': columnName}
+ struct %(s)s *row = %(s)s_cast(row_);''' % {'s': structName,
+ 'c': columnName}
if type.is_smap():
print " smap_destroy(&row->%s);" % columnName
@@ -614,7 +610,6 @@ bool
void
%(s)s_verify_%(c)s(const struct %(s)s *row)
{
- ovs_assert(inited);
ovsdb_idl_txn_verify(&row->header_, &%(s)s_col_%(c)s);
}''' % {'s': structName,
'S': structName.upper(),
@@ -675,7 +670,6 @@ const struct ovsdb_datum *
{
struct ovsdb_datum datum;
- ovs_assert(inited);
if (%(c)s) {
ovsdb_datum_from_smap(&datum, %(c)s);
} else {
@@ -708,11 +702,10 @@ const struct ovsdb_datum *
void
%(s)s_set_%(c)s(const struct %(s)s *row, %(args)s)
{
- ovs_assert(inited);
struct ovsdb_datum datum;""" % {'s': structName,
- 'c': columnName,
- 'args': ', '.join(['%(type)s%(name)s'
- % m for m in members])}
+ 'c': columnName,
+ 'args': ', '.join(['%(type)s%(name)s'
+ % m for m in members])}
if type.n_min == 1 and type.n_max == 1:
print " union ovsdb_atom key;"
if type.value:
@@ -793,8 +786,6 @@ void
{
struct ovsdb_datum *datum;
- ovs_assert(inited);
-
datum = xmalloc(sizeof *datum);
datum->n = 1;
datum->keys = xmalloc(datum->n * sizeof *datum->keys);
@@ -821,8 +812,6 @@ void
{
struct ovsdb_datum *datum;
- ovs_assert(inited);
-
datum = xmalloc(sizeof *datum);
datum->n = 1;
datum->keys = xmalloc(datum->n * sizeof *datum->keys);
@@ -851,8 +840,6 @@ void
{
struct ovsdb_datum *datum;
- ovs_assert(inited);
-
datum = xmalloc(sizeof *datum);
datum->n = 1;
datum->keys = xmalloc(datum->n * sizeof *datum->values);
@@ -877,8 +864,6 @@ void
{
struct ovsdb_datum *datum;
- ovs_assert(inited);
-
datum = xmalloc(sizeof *datum);
datum->n = 1;
datum->keys = xmalloc(datum->n * sizeof *datum->values);
@@ -910,7 +895,6 @@ void
{
struct ovsdb_datum datum;
- ovs_assert(inited);
if (%(c)s) {
ovsdb_datum_from_smap(&datum, %(c)s);
} else {
@@ -952,7 +936,6 @@ void
{'s': structName, 'c': columnName,
'args': ', '.join(['%(type)s%(name)s' % m for m in members])}
print "{"
- print " ovs_assert(inited);"
print " struct ovsdb_datum datum;"
free = []
if type.n_min == 1 and type.n_max == 1:
@@ -1067,7 +1050,6 @@ void
{
struct ovsdb_datum datum;
- ovs_assert(inited);
if (%(c)s) {
ovsdb_datum_from_smap(&datum, %(c)s);
} else {
@@ -1106,7 +1088,6 @@ void
{'s': structName, 'c': columnName,
'args': ', '.join(['%(type)s%(name)s' % m for m in members])}
print "{"
- print " ovs_assert(inited);"
print " struct ovsdb_datum datum;"
free = []
if type.n_min == 1 and type.n_max == 1:
@@ -1203,29 +1184,37 @@ void
'P': prefix.upper(),}
# Table columns.
- print "\nstruct ovsdb_idl_column %s_columns[%s_N_COLUMNS];" % (
+ for columnName, column in sorted_columns(table):
+ prereqs = []
+ x = column.type.cInitType("%s_col_%s" % (tableName, columnName), prereqs)
+ if prereqs:
+ print '\n'.join(prereqs)
+ print "\nstruct ovsdb_idl_column %s_columns[%s_N_COLUMNS] = {" % (
structName, structName.upper())
- print """
-static void\n%s_columns_init(void)
-{
- struct ovsdb_idl_column *c;\
-""" % structName
for columnName, column in sorted_columns(table):
- cs = "%s_col_%s" % (structName, columnName)
- d = {'cs': cs, 'c': columnName, 's': structName}
if column.mutable:
mutable = "true"
else:
mutable = "false"
- print
- print " /* Initialize %(cs)s. */" % d
- print " c = &%(cs)s;" % d
- print " c->name = \"%(c)s\";" % d
- print column.type.cInitType(" ", "c->type")
- print " c->mutable = %s;" % mutable
- print " c->parse = %(s)s_parse_%(c)s;" % d
- print " c->unparse = %(s)s_unparse_%(c)s;" % d
- print "}"
+ type_init = '\n'.join(" " + x
+ for x in column.type.cInitType("%s_col_%s" % (tableName, columnName), prereqs))
+ print """\
+ [%(P)s%(T)s_COL_%(C)s] = {
+ .name = "%(c)s",
+ .type = {
+%(type)s
+ },
+ .mutable = %(mutable)s,
+ .parse = %(s)s_parse_%(c)s,
+ .unparse = %(s)s_unparse_%(c)s,
+ },\n""" % {'P': prefix.upper(),
+ 'T': tableName.upper(),
+ 'c': columnName,
+ 'C': columnName.upper(),
+ 's': structName,
+ 'mutable': mutable,
+ 'type': type_init}
+ print "};"
# Table classes.
print ""
@@ -1248,22 +1237,6 @@ static void\n%s_columns_init(void)
schema.name, prefix, prefix)
print "};"
- # global init function
- print """
-void
-%sinit(void)
-{
- if (inited) {
- return;
- }
- assert_single_threaded();
- inited = true;
-""" % prefix
- for tableName, table in sorted(schema.tables.iteritems()):
- structName = "%s%s" % (prefix, tableName.lower())
- print " %s_columns_init();" % structName
- print "}"
-
print """
/* Return the schema version. The caller must not free the returned value. */
const char *
@@ -1,4 +1,4 @@
-# Copyright (c) 2009, 2010, 2011, 2014 Nicira, Inc.
+# Copyright (c) 2009, 2010, 2011, 2014, 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.
@@ -198,19 +198,18 @@ class Atom(object):
def cInitAtom(self, var):
if self.type == ovs.db.types.IntegerType:
- return ['%s.integer = %d;' % (var, self.value)]
+ return '.integer = %d' % self.value
elif self.type == ovs.db.types.RealType:
- return ['%s.real = %.15g;' % (var, self.value)]
+ return '.real = %.15g' % self.value
elif self.type == ovs.db.types.BooleanType:
if self.value:
- return ['%s.boolean = true;']
+ return '.boolean = true'
else:
- return ['%s.boolean = false;']
+ return '.boolean = false'
elif self.type == ovs.db.types.StringType:
- return ['%s.string = xstrdup("%s");'
- % (var, escapeCString(self.value))]
+ return '.string = "%s"' % escapeCString(self.value)
elif self.type == ovs.db.types.UuidType:
- return ovs.ovsuuid.to_c_assignment(self.value, var)
+ return '.uuid = %s' % ovs.ovsuuid.to_c_assignment(self.value)
def toEnglish(self, escapeLiteral=returnUnchanged):
if self.type == ovs.db.types.IntegerType:
@@ -562,27 +561,26 @@ class Datum(object):
n = len(self.values)
return self.type.n_min <= n <= self.type.n_max
- def cInitDatum(self, var):
- if len(self.values) == 0:
- return ["ovsdb_datum_init_empty(%s);" % var]
-
- s = ["%s->n = %d;" % (var, len(self.values))]
- s += ["%s->keys = xmalloc(%d * sizeof *%s->keys);"
- % (var, len(self.values), var)]
+ def cDeclareDatum(self, name):
+ n = len(self.values)
+ if n == 0:
+ return ["static struct ovsdb_datum %s = { .n = 0 };"]
- for i, key in enumerate(sorted(self.values)):
- s += key.cInitAtom("%s->keys[%d]" % (var, i))
+ s = ["static union ovsdb_atom %s_keys[%d] = {" % (name, n)]
+ for key in sorted(self.values):
+ s += [" { %s }," % key.cInitAtom(key)]
+ s += ["};"]
if self.type.value:
- s += ["%s->values = xmalloc(%d * sizeof *%s->values);"
- % (var, len(self.values), var)]
- for i, (key, value) in enumerate(sorted(self.values.items())):
- s += value.cInitAtom("%s->values[%d]" % (var, i))
- else:
- s += ["%s->values = NULL;" % var]
-
- if len(self.values) > 1:
- s += ["ovsdb_datum_sort_assert(%s, OVSDB_TYPE_%s);"
- % (var, self.type.key.type.to_string().upper())]
-
+ s = ["static union ovsdb_atom %s_values[%d] = {" % (name, n)]
+ for k, v in sorted(self.values.items()):
+ s += [" { %s }," % v.cInitAtom(v)]
+ s += ["};"]
+
+ s += ["static struct ovsdb_datum %s = {" % name]
+ s += [" .n = %d," % n]
+ s += [" .keys = %s_keys," % name]
+ if self.type.value:
+ s += [" .values = %s_values," % name]
+ s += ["};"]
return s
@@ -402,40 +402,50 @@ class BaseType(object):
StringType: '%s = NULL;'}[self.type]
return pattern % var
- def cInitBaseType(self, indent, var):
- stmts = []
- stmts.append('ovsdb_base_type_init(&%s, %s);' % (
- var, self.toAtomicType()))
+ def cInitBaseType(self, prefix, prereqs):
+ init = [".type = %s," % self.toAtomicType()]
if self.enum:
- stmts.append("%s.enum_ = xmalloc(sizeof *%s.enum_);"
- % (var, var))
- stmts += self.enum.cInitDatum("%s.enum_" % var)
+ datum_name = "%s_enum" % prefix
+ init += [".enum_ = &%s," % datum_name]
+ prereqs += self.enum.cDeclareDatum(datum_name)
if self.type == IntegerType:
- if self.min is not None:
- stmts.append('%s.u.integer.min = INT64_C(%d);'
- % (var, self.min))
- if self.max is not None:
- stmts.append('%s.u.integer.max = INT64_C(%d);'
- % (var, self.max))
+ if self.min is None:
+ low = "INT64_MIN"
+ else:
+ low = "INT64_C(%d)" % self.min
+ if self.max is None:
+ high = "INT64_MAX"
+ else:
+ high = "INT64_C(%d)" % self.max
+ init.append(".u.integer = { .min = %s, .max = %s }," % (low, high))
elif self.type == RealType:
- if self.min is not None:
- stmts.append('%s.u.real.min = %d;' % (var, self.min))
- if self.max is not None:
- stmts.append('%s.u.real.max = %d;' % (var, self.max))
+ if self.min is None:
+ low = "-DBL_MAX"
+ else:
+ low = self.min
+ if self.max is None:
+ high = "DBL_MAX"
+ else:
+ high = self.max
+ init.append(".u.real = { .min = %s, .max = %s }," % (low, high))
elif self.type == StringType:
- if self.min_length is not None:
- stmts.append('%s.u.string.minLen = %d;'
- % (var, self.min_length))
- if self.max_length != sys.maxsize:
- stmts.append('%s.u.string.maxLen = %d;'
- % (var, self.max_length))
+ if self.min is None:
+ low = 0
+ else:
+ low = self.min_length
+ if self.max is None:
+ high = "UINT_MAX"
+ else:
+ high = self.max_length
+ init.append(".u.string = { .minLen = %s, .maxLen = %s }," % (
+ low, high))
elif self.type == UuidType:
if self.ref_table_name is not None:
- stmts.append('%s.u.uuid.refTableName = "%s";'
- % (var, escapeCString(self.ref_table_name)))
- stmts.append('%s.u.uuid.refType = OVSDB_REF_%s;'
- % (var, self.ref_type.upper()))
- return '\n'.join([indent + stmt for stmt in stmts])
+ init.append(".u.uuid = { .refTableName = \"%s\", "
+ ".refType = OVSDB_REF_%s }," % (
+ escapeCString(self.ref_table_name),
+ self.ref_type.upper()))
+ return init
class Type(object):
@@ -613,17 +623,23 @@ class Type(object):
else:
return ""
- def cInitType(self, indent, var):
- initKey = self.key.cInitBaseType(indent, "%s.key" % var)
+ def cInitType(self, prefix, prereqs):
+ init = [".key = {"]
+ init += [" " + x for x in self.key.cInitBaseType(prefix + "_key",
+ prereqs)]
+ init += ["},"]
if self.value:
- initValue = self.value.cInitBaseType(indent, "%s.value" % var)
+ init += [".value = {"]
+ init += [" " + x
+ for x in self.value.cInitBaseType(prefix + "_value",
+ prereqs)]
+ init += ["},"]
else:
- initValue = ('%sovsdb_base_type_init(&%s.value, '
- 'OVSDB_TYPE_VOID);' % (indent, var))
- initMin = "%s%s.n_min = %s;" % (indent, var, self.n_min)
+ init.append(".value = OVSDB_BASE_VOID_INIT,")
+ init.append(".n_min = %s," % self.n_min)
if self.n_max == sys.maxsize:
n_max = "UINT_MAX"
else:
n_max = self.n_max
- initMax = "%s%s.n_max = %s;" % (indent, var, n_max)
- return "\n".join((initKey, initValue, initMin, initMax))
+ init.append(".n_max = %s," % n_max)
+ return init
@@ -1,4 +1,4 @@
-# Copyright (c) 2009, 2010, 2011 Nicira, Inc.
+# Copyright (c) 2009, 2010, 2011, 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.
@@ -63,11 +63,8 @@ def to_json(uuid_):
return ["uuid", str(uuid_)]
-def to_c_assignment(uuid_, var):
- """Returns an array of strings, each of which contain a C statement. The
- statements assign 'uuid_' to a "struct uuid" as defined in Open vSwitch
- lib/uuid.h."""
-
+def to_c_initializer(uuid_, var):
hex_string = uuid_.hex
- return ["%s.parts[%d] = 0x%s;" % (var, x, hex_string[x * 8:(x + 1) * 8])
+ parts = ["0x%s" % (hex_string[x * 8:(x + 1) * 8])
for x in range(4)]
+ return "{ %s }," % ", ".join(parts)
@@ -2381,8 +2381,6 @@ do_idl(struct ovs_cmdl_context *ctx)
int i;
bool track;
- idltest_init();
-
track = ((struct test_ovsdb_pvt_context *)(ctx->pvt))->track;
idl = ovsdb_idl_create(ctx->argv[1], &idltest_idl_class, true, true);
@@ -2530,7 +2528,6 @@ do_idl_partial_update_map_column(struct ovs_cmdl_context *ctx)
int step = 0;
char key_to_delete[100];
- idltest_init();
idl = ovsdb_idl_create(ctx->argv[1], &idltest_idl_class, false, true);
ovsdb_idl_add_table(idl, &idltest_table_simple2);
ovsdb_idl_add_column(idl, &idltest_simple2_col_name);
@@ -2638,7 +2635,6 @@ do_idl_partial_update_set_column(struct ovs_cmdl_context *ctx)
const struct ovsdb_datum *uref OVS_UNUSED;
int step = 0;
- idltest_init();
idl = ovsdb_idl_create(ctx->argv[1], &idltest_idl_class, false, true);
ovsdb_idl_add_table(idl, &idltest_table_simple3);
ovsdb_idl_add_column(idl, &idltest_simple3_col_name);
@@ -141,7 +141,6 @@ main(int argc, char *argv[])
fatal_ignore_sigpipe();
vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN);
vlog_set_levels_from_string_assert("reconnect:warn");
- ovsrec_init();
vsctl_cmd_init();
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
+/* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 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.
@@ -75,7 +75,6 @@ main(int argc, char *argv[])
service_start(&argc, &argv);
remote = parse_options(argc, argv, &unixctl_path);
fatal_ignore_sigpipe();
- ovsrec_init();
daemonize_start(true);
@@ -105,7 +105,6 @@ main(int argc, char *argv[])
fatal_ignore_sigpipe();
vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN);
vlog_set_levels_from_string_assert("reconnect:warn");
- vteprec_init();
vtep_ctl_cmd_init();
Signed-off-by: Ben Pfaff <blp@ovn.org> --- ovn/controller-vtep/ovn-controller-vtep.c | 3 -- ovn/controller/ovn-controller.c | 3 -- ovn/northd/ovn-northd.c | 3 -- ovn/utilities/ovn-nbctl.c | 1 - ovn/utilities/ovn-sbctl.c | 1 - ovn/utilities/ovn-trace.c | 1 - ovsdb/ovsdb-idlc.in | 87 +++++++++++------------------- python/ovs/db/data.py | 54 +++++++++---------- python/ovs/db/types.py | 88 ++++++++++++++++++------------- python/ovs/ovsuuid.py | 11 ++-- tests/test-ovsdb.c | 4 -- utilities/ovs-vsctl.c | 1 - vswitchd/ovs-vswitchd.c | 3 +- vtep/vtep-ctl.c | 1 - 14 files changed, 113 insertions(+), 148 deletions(-)