ovsdb-idl: Update IDL data when "set" functions are called.
authorBen Pfaff <blp@nicira.com>
Tue, 8 Dec 2009 17:48:37 +0000 (09:48 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 8 Dec 2009 18:59:46 +0000 (10:59 -0800)
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
ovsdb/ovsdb-idlc.in
tests/test-ovsdb.c

index 32eddb1..22e20db 100644 (file)
@@ -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);
index 9807738..d6fc14a 100755 (executable)
@@ -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,
index 4949e39..1f697b4 100644 (file)
@@ -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();
     }