Skip to content

Commit

Permalink
ovsdb-idlc: Eliminate <prefix>_init() function from generated code.
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Andy Zhou <[email protected]>
  • Loading branch information
blp committed Oct 19, 2016
1 parent cad9a99 commit 74e98ef
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 148 deletions.
3 changes: 0 additions & 3 deletions ovn/controller-vtep/ovn-controller-vtep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 0 additions & 3 deletions ovn/controller/ovn-controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,6 @@ main(int argc, char *argv[])

daemonize_complete();

ovsrec_init();
sbrec_init();

ofctrl_init(&group_table);
pinctrl_init();
lflow_init();
Expand Down
3 changes: 0 additions & 3 deletions ovn/northd/ovn-northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4777,9 +4777,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));
Expand Down
1 change: 0 additions & 1 deletion ovn/utilities/ovn-nbctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion ovn/utilities/ovn-sbctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion ovn/utilities/ovn-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
87 changes: 30 additions & 57 deletions ovsdb/ovsdb-idlc.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down Expand Up @@ -319,7 +318,6 @@ enum { sizeof_bool = 1 };
enum { sizeof_bool = sizeof(bool) };
#endif

static bool inited;
''' % schema.idlHeader

# Cast functions.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -910,7 +895,6 @@ void
{
struct ovsdb_datum datum;

ovs_assert(inited);
if (%(c)s) {
ovsdb_datum_from_smap(&datum, %(c)s);
} else {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1067,7 +1050,6 @@ void
{
struct ovsdb_datum datum;

ovs_assert(inited);
if (%(c)s) {
ovsdb_datum_from_smap(&datum, %(c)s);
} else {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 " "
Expand All @@ -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 *
Expand Down
54 changes: 26 additions & 28 deletions python/ovs/db/data.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -198,19 +198,18 @@ def to_json(self):

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:
Expand Down Expand Up @@ -562,27 +561,26 @@ def conforms_to_type(self):
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
Loading

0 comments on commit 74e98ef

Please sign in to comment.