ovsdb: Centralize and make consistent setting txn_row members of rows.
authorBen Pfaff <blp@nicira.com>
Fri, 12 Mar 2010 00:56:36 +0000 (16:56 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 17 Mar 2010 21:24:55 +0000 (14:24 -0700)
When a transaction modified a row, the "old" row's txn_row member was
not being set to the txn_row.  This commit changes that and factors out
the code to set the txn_row member of the rows within a txn_row.

This is not a bug fix, because nothing previously cared about the txn_row
member of the old version of a row, but it does matter for an upcoming
commit.

ovsdb/transaction.c

index 137ae06..154f811 100644 (file)
@@ -343,15 +343,23 @@ ovsdb_txn_create_txn_table(struct ovsdb_txn *txn, struct ovsdb_table *table)
 
 static struct ovsdb_txn_row *
 ovsdb_txn_row_create(struct ovsdb_txn *txn, struct ovsdb_table *table,
-                     const struct ovsdb_row *old, struct ovsdb_row *new)
+                     const struct ovsdb_row *old_, struct ovsdb_row *new)
 {
+    struct ovsdb_row *old = (struct ovsdb_row *) old_;
     struct ovsdb_txn_table *txn_table;
     struct ovsdb_txn_row *txn_row;
 
     txn_row = xmalloc(sizeof *txn_row);
-    txn_row->old = (struct ovsdb_row *) old;
+    txn_row->old = old;
     txn_row->new = new;
 
+    if (old) {
+        old->txn_row = txn_row;
+    }
+    if (new) {
+        new->txn_row = txn_row;
+    }
+
     txn_table = ovsdb_txn_create_txn_table(txn, table);
     hmap_insert(&txn_table->txn_rows, &txn_row->hmap_node,
                 ovsdb_row_hash(old ? old : new));
@@ -374,7 +382,7 @@ ovsdb_txn_row_modify(struct ovsdb_txn *txn, const struct ovsdb_row *ro_row_)
         rw_row = ovsdb_row_clone(ro_row);
         rw_row->n_refs = ro_row->n_refs;
         uuid_generate(ovsdb_row_get_version_rw(rw_row));
-        rw_row->txn_row = ovsdb_txn_row_create(txn, table, ro_row, rw_row);
+        ovsdb_txn_row_create(txn, table, ro_row, rw_row);
         hmap_replace(&table->rows, &ro_row->hmap_node, &rw_row->hmap_node);
 
         return rw_row;
@@ -389,7 +397,7 @@ ovsdb_txn_row_insert(struct ovsdb_txn *txn, struct ovsdb_row *row)
 
     uuid_generate(ovsdb_row_get_version_rw(row));
 
-    row->txn_row = ovsdb_txn_row_create(txn, table, NULL, row);
+    ovsdb_txn_row_create(txn, table, NULL, row);
     hmap_insert(&table->rows, &row->hmap_node, hash);
 }
 
@@ -405,7 +413,7 @@ ovsdb_txn_row_delete(struct ovsdb_txn *txn, const struct ovsdb_row *row_)
     hmap_remove(&table->rows, &row->hmap_node);
 
     if (!txn_row) {
-        row->txn_row = ovsdb_txn_row_create(txn, table, row, NULL);
+        ovsdb_txn_row_create(txn, table, row, NULL);
     } else {
         assert(txn_row->new == row);
         if (txn_row->old) {