From 8bc915de7a08d5b4210ba768d56f15211927d1e7 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 8 Dec 2009 09:48:37 -0800 Subject: [PATCH] ovsdb-idl: Update IDL data when "set" functions are called. Until now, the "set" functions generated by the IDL updated the data in the database (during commit) but not the data exposed by the IDL in its data structures. This was just an oversight, so this commit causes the data exposed by IDL to be updated also. --- lib/ovsdb-idl.c | 6 ++++++ ovsdb/ovsdb-idlc.in | 30 +++++++++++++++++++++--------- tests/test-ovsdb.c | 7 +------ 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 32eddb191..22e20db02 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -212,6 +212,7 @@ ovsdb_idl_run(struct ovsdb_idl *idl) { int i; + assert(!idl->txn); jsonrpc_session_run(idl->session); for (i = 0; jsonrpc_session_is_connected(idl->session) && i < 50; i++) { struct jsonrpc_msg *msg, *reply; @@ -889,6 +890,11 @@ ovsdb_idl_txn_disassemble(struct ovsdb_idl_txn *txn) HMAP_FOR_EACH_SAFE (row, next, struct ovsdb_idl_row, txn_node, &txn->txn_rows) { + if (row->old && row->written) { + (row->table->class->unparse)(row); + ovsdb_idl_row_clear_arcs(row, false); + (row->table->class->parse)(row); + } ovsdb_idl_row_clear_new(row); free(row->prereqs); diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index 980773873..d6fc14ab1 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -159,13 +159,18 @@ def cBaseType(prefix, type, refTable=None): 'boolean': 'bool ', 'string': 'char *'}[type] -def cCopyType(dst, src, type, refTable=None): +def cCopyType(indent, dstVar, dst, src, type, refTable=None): + args = {'indent': indent, + 'dstVar': dstVar, + 'dst': dst, + 'src': src} if type == 'uuid' and refTable: - return "%s = %s->header_.uuid;" % (dst, src) + return ("%(indent)s%(dstVar)s = %(src)s;\n" + + "%(indent)s%(dst)s = %(src)s->header_.uuid;") % args elif type == 'string': - return "%s = xstrdup(%s);" % (dst, src) + return "%(indent)s%(dstVar)s = %(dst)s = xstrdup(%(src)s);" % args else: - return "%s = %s;" % (dst, src) + return "%(dstVar)s = %(dst)s = %(src)s;" % args def typeIsOptionalPointer(type): return (type.min == 0 and type.max == 1 and not type.value @@ -495,10 +500,10 @@ void print print " datum.n = 1;" print " datum.keys = xmalloc(sizeof *datum.keys);" - print " %s" % cCopyType("datum.keys[0].%s" % type.key, keyVar, type.key, type.keyRefTable) + print cCopyType(" ", "row->%s" % keyVar, "datum.keys[0].%s" % type.key, keyVar, type.key, type.keyRefTable) if type.value: print " datum.values = xmalloc(sizeof *datum.values);" - print " %s" % cCopyType("datum.values[0].%s" % type.value, valueVar, type.value, type.valueRefTable) + print cCopyType(" ", "row->%s" % valueVar, "datum.values[0].%s" % type.value, valueVar, type.value, type.valueRefTable) else: print " datum.values = NULL;" elif typeIsOptionalPointer(type): @@ -506,15 +511,22 @@ void print " if (%s) {" % keyVar print " datum.n = 1;" print " datum.keys = xmalloc(sizeof *datum.keys);" - print " %s" % cCopyType("datum.keys[0].%s" % type.key, keyVar, type.key, type.keyRefTable) + print cCopyType(" ", "row->%s" % keyVar, "datum.keys[0].%s" % type.key, keyVar, type.key, type.keyRefTable) print " } else {" print " datum.n = 0;" print " datum.keys = NULL;" + print " row->%s = NULL;" % keyVar print " }" print " datum.values = NULL;" else: print " size_t i;" print + print " free(row->%s);" % keyVar + print " row->%s = %s ? xmalloc(%s * sizeof *row->%s) : NULL;" % (keyVar, nVar, nVar, keyVar) + print " row->%s = %s;" % (nVar, nVar) + if type.value: + print " free(row->%s);" % valueVar + print " row->%s = xmalloc(%s * sizeof *row->%s);" % (valueVar, nVar, valueVar) print " datum.n = %s;" % nVar print " datum.keys = xmalloc(%s * sizeof *datum.keys);" % nVar if type.value: @@ -522,9 +534,9 @@ void else: print " datum.values = NULL;" print " for (i = 0; i < %s; i++) {" % nVar - print " %s" % cCopyType("datum.keys[i].%s" % type.key, "%s[i]" % keyVar, type.key, type.keyRefTable) + print cCopyType(" ", "row->%s[i]" % keyVar, "datum.keys[i].%s" % type.key, "%s[i]" % keyVar, type.key, type.keyRefTable) if type.value: - print " %s" % cCopyType("datum.values[i].%s" % type.value, "%s[i]" % valueVar, type.value, type.valueRefTable) + print cCopyType(" ", "row->%s[i]" % valueVar, "datum.values[i].%s" % type.value, "%s[i]" % valueVar, type.value, type.valueRefTable) print " }" print " ovsdb_idl_txn_write(&row->header_, &%(s)s_columns[%(S)s_COL_%(C)s], &datum);" \ % {'s': structName, diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index 4949e3939..1f697b4fc 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -1476,13 +1476,8 @@ idl_set(struct ovsdb_idl *idl, char *commands, int step) } } - for (;;) { + while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) { ovsdb_idl_run(idl); - status = ovsdb_idl_txn_commit(txn); - if (status != TXN_INCOMPLETE) { - break; - } - ovsdb_idl_wait(idl); poll_block(); } -- 2.45.2