+ if (!list_is_empty(&dst->dst_refs)) {
+ /* Omit duplicates. */
+ weak = CONTAINER_OF(list_back(&dst->dst_refs),
+ struct ovsdb_weak_ref, dst_node);
+ if (weak->src == src) {
+ return;
+ }
+ }
+
+ weak = xmalloc(sizeof *weak);
+ weak->src = src;
+ list_push_back(&dst->dst_refs, &weak->dst_node);
+ list_push_back(&src->src_refs, &weak->src_node);
+}
+
+static struct ovsdb_error * WARN_UNUSED_RESULT
+assess_weak_refs(struct ovsdb_txn *txn, struct ovsdb_txn_row *txn_row)
+{
+ struct ovsdb_table *table;
+ struct shash_node *node;
+
+ if (txn_row->old) {
+ /* Mark rows that have weak references to 'txn_row' as modified, so
+ * that their weak references will get reassessed. */
+ struct ovsdb_weak_ref *weak, *next;
+
+ LIST_FOR_EACH_SAFE (weak, next, dst_node, &txn_row->old->dst_refs) {
+ if (!weak->src->txn_row) {
+ ovsdb_txn_row_modify(txn, weak->src);
+ }
+ }
+ }
+
+ if (!txn_row->new) {
+ /* We don't have to do anything about references that originate at
+ * 'txn_row', because ovsdb_row_destroy() will remove those weak
+ * references. */
+ return NULL;
+ }
+
+ table = txn_row->table;
+ SHASH_FOR_EACH (node, &table->schema->columns) {
+ const struct ovsdb_column *column = node->data;
+ struct ovsdb_datum *datum = &txn_row->new->fields[column->index];
+ unsigned int orig_n, i;
+ bool zero = false;
+
+ orig_n = datum->n;
+
+ if (ovsdb_base_type_is_weak_ref(&column->type.key)) {
+ for (i = 0; i < datum->n; ) {
+ const struct ovsdb_row *row;
+
+ row = ovsdb_table_get_row(column->type.key.u.uuid.refTable,
+ &datum->keys[i].uuid);
+ if (row) {
+ add_weak_ref(txn, txn_row->new, row);
+ i++;
+ } else {
+ if (uuid_is_zero(&datum->keys[i].uuid)) {
+ zero = true;
+ }
+ ovsdb_datum_remove_unsafe(datum, i, &column->type);
+ }
+ }
+ }
+
+ if (ovsdb_base_type_is_weak_ref(&column->type.value)) {
+ for (i = 0; i < datum->n; ) {
+ const struct ovsdb_row *row;
+
+ row = ovsdb_table_get_row(column->type.value.u.uuid.refTable,
+ &datum->values[i].uuid);
+ if (row) {
+ add_weak_ref(txn, txn_row->new, row);
+ i++;
+ } else {
+ if (uuid_is_zero(&datum->values[i].uuid)) {
+ zero = true;
+ }
+ ovsdb_datum_remove_unsafe(datum, i, &column->type);