ovsdb-client: support monitor-cond method
[cascardo/ovs.git] / lib / ovsdb-idl.c
index bfc133b..ae82f10 100644 (file)
@@ -79,8 +79,8 @@ enum ovsdb_idl_state {
     IDL_S_SCHEMA_REQUESTED,
     IDL_S_MONITOR_REQUESTED,
     IDL_S_MONITORING,
-    IDL_S_MONITOR2_REQUESTED,
-    IDL_S_MONITORING2,
+    IDL_S_MONITOR_COND_REQUESTED,
+    IDL_S_MONITORING_COND,
     IDL_S_NO_SCHEMA
 };
 
@@ -154,7 +154,7 @@ static struct vlog_rate_limit semantic_rl = VLOG_RATE_LIMIT_INIT(1, 5);
 static void ovsdb_idl_clear(struct ovsdb_idl *);
 static void ovsdb_idl_send_schema_request(struct ovsdb_idl *);
 static void ovsdb_idl_send_monitor_request(struct ovsdb_idl *);
-static void ovsdb_idl_send_monitor2_request(struct ovsdb_idl *);
+static void ovsdb_idl_send_monitor_cond_request(struct ovsdb_idl *);
 static void ovsdb_idl_parse_update(struct ovsdb_idl *, const struct json *,
                                    enum ovsdb_update_version);
 static struct ovsdb_error *ovsdb_idl_parse_update__(struct ovsdb_idl *,
@@ -181,6 +181,7 @@ static struct ovsdb_idl_row *ovsdb_idl_row_create(struct ovsdb_idl_table *,
                                                   const struct uuid *);
 static void ovsdb_idl_row_destroy(struct ovsdb_idl_row *);
 static void ovsdb_idl_row_destroy_postprocess(struct ovsdb_idl *);
+static void ovsdb_idl_destroy_all_map_op_lists(struct ovsdb_idl_row *);
 
 static void ovsdb_idl_row_parse(struct ovsdb_idl_row *);
 static void ovsdb_idl_row_unparse(struct ovsdb_idl_row *);
@@ -191,6 +192,12 @@ static void ovsdb_idl_row_clear_arcs(struct ovsdb_idl_row *, bool destroy_dsts);
 static void ovsdb_idl_txn_abort_all(struct ovsdb_idl *);
 static bool ovsdb_idl_txn_process_reply(struct ovsdb_idl *,
                                         const struct jsonrpc_msg *msg);
+static bool ovsdb_idl_txn_extract_mutations(struct ovsdb_idl_row *,
+                                            struct json *);
+static void ovsdb_idl_txn_add_map_op(struct ovsdb_idl_row *,
+                                     const struct ovsdb_idl_column *,
+                                     struct ovsdb_datum *,
+                                     enum map_op_type);
 
 static void ovsdb_idl_send_lock_request(struct ovsdb_idl *);
 static void ovsdb_idl_send_unlock_request(struct ovsdb_idl *);
@@ -256,7 +263,7 @@ ovsdb_idl_create(const char *remote, const struct ovsdb_idl_class *class,
             shash_add_assert(&table->columns, column->name, column);
         }
         hmap_init(&table->rows);
-        list_init(&table->track_list);
+        ovs_list_init(&table->track_list);
         table->change_seqno[OVSDB_IDL_CHANGE_INSERT]
             = table->change_seqno[OVSDB_IDL_CHANGE_MODIFY]
             = table->change_seqno[OVSDB_IDL_CHANGE_DELETE] = 0;
@@ -272,6 +279,19 @@ ovsdb_idl_create(const char *remote, const struct ovsdb_idl_class *class,
     return idl;
 }
 
+/* Changes the remote and creates a new session. */
+void
+ovsdb_idl_set_remote(struct ovsdb_idl *idl, const char *remote,
+                     bool retry)
+{
+    if (idl) {
+        ovs_assert(!idl->txn);
+        jsonrpc_session_close(idl->session);
+        idl->session = jsonrpc_session_open(remote, retry);
+        idl->state_seqno = UINT_MAX;
+    }
+}
+
 /* Destroys 'idl' and all of the data structures that it manages. */
 void
 ovsdb_idl_destroy(struct ovsdb_idl *idl)
@@ -327,8 +347,8 @@ ovsdb_idl_clear(struct ovsdb_idl *idl)
             /* No need to do anything with dst_arcs: some node has those arcs
              * as forward arcs and will destroy them itself. */
 
-            if (!list_is_empty(&row->track_node)) {
-                list_remove(&row->track_node);
+            if (!ovs_list_is_empty(&row->track_node)) {
+                ovs_list_remove(&row->track_node);
             }
 
             ovsdb_idl_row_destroy(row);
@@ -393,20 +413,20 @@ ovsdb_idl_run(struct ovsdb_idl *idl)
             case IDL_S_SCHEMA_REQUESTED:
                 /* Reply to our "get_schema" request. */
                 idl->schema = json_clone(msg->result);
-                ovsdb_idl_send_monitor2_request(idl);
-                idl->state = IDL_S_MONITOR2_REQUESTED;
+                ovsdb_idl_send_monitor_cond_request(idl);
+                idl->state = IDL_S_MONITOR_COND_REQUESTED;
                 break;
 
             case IDL_S_MONITOR_REQUESTED:
-            case IDL_S_MONITOR2_REQUESTED:
-                /* Reply to our "monitor" or "monitor2" request. */
+            case IDL_S_MONITOR_COND_REQUESTED:
+                /* Reply to our "monitor" or "monitor_cond" request. */
                 idl->change_seqno++;
                 ovsdb_idl_clear(idl);
                 if (idl->state == IDL_S_MONITOR_REQUESTED) {
                     idl->state = IDL_S_MONITORING;
                     ovsdb_idl_parse_update(idl, msg->result, OVSDB_UPDATE);
-                } else { /* IDL_S_MONITOR2_REQUESTED. */
-                    idl->state = IDL_S_MONITORING2;
+                } else { /* IDL_S_MONITOR_COND_REQUESTED. */
+                    idl->state = IDL_S_MONITORING_COND;
                     ovsdb_idl_parse_update(idl, msg->result, OVSDB_UPDATE2);
                 }
 
@@ -417,7 +437,7 @@ ovsdb_idl_run(struct ovsdb_idl *idl)
                 break;
 
             case IDL_S_MONITORING:
-            case IDL_S_MONITORING2:
+            case IDL_S_MONITORING_COND:
             case IDL_S_NO_SCHEMA:
             default:
                 OVS_NOT_REACHED();
@@ -444,7 +464,7 @@ ovsdb_idl_run(struct ovsdb_idl *idl)
             /* Someone else stole our lock. */
             ovsdb_idl_parse_lock_notify(idl, msg->params, false);
         } else if (msg->type == JSONRPC_ERROR
-                   && idl->state == IDL_S_MONITOR2_REQUESTED
+                   && idl->state == IDL_S_MONITOR_COND_REQUESTED
                    && idl->request_id
                    && json_equal(idl->request_id, msg->id)) {
             if (msg->error && !strcmp(json_string(msg->error),
@@ -582,6 +602,15 @@ ovsdb_idl_get_last_error(const struct ovsdb_idl *idl)
         return 0;
     }
 }
+
+/* Sets the "probe interval" for 'idl->session' to 'probe_interval', in
+ * milliseconds.
+ */
+void
+ovsdb_idl_set_probe_interval(const struct ovsdb_idl *idl, int probe_interval)
+{
+    jsonrpc_session_set_probe_interval(idl->session, probe_interval);
+}
 \f
 static unsigned char *
 ovsdb_idl_get_mode(struct ovsdb_idl *idl,
@@ -782,8 +811,8 @@ ovsdb_idl_track_get_first(const struct ovsdb_idl *idl,
     struct ovsdb_idl_table *table
         = ovsdb_idl_table_from_class(idl, table_class);
 
-    if (!list_is_empty(&table->track_list)) {
-        return CONTAINER_OF(list_front(&table->track_list), struct ovsdb_idl_row, track_node);
+    if (!ovs_list_is_empty(&table->track_list)) {
+        return CONTAINER_OF(ovs_list_front(&table->track_list), struct ovsdb_idl_row, track_node);
     }
     return NULL;
 }
@@ -836,7 +865,7 @@ ovsdb_idl_track_clear(const struct ovsdb_idl *idl)
     for (i = 0; i < idl->class->n_tables; i++) {
         struct ovsdb_idl_table *table = &idl->tables[i];
 
-        if (!list_is_empty(&table->track_list)) {
+        if (!ovs_list_is_empty(&table->track_list)) {
             struct ovsdb_idl_row *row, *next;
 
             LIST_FOR_EACH_SAFE(row, next, track_node, &table->track_list) {
@@ -844,8 +873,8 @@ ovsdb_idl_track_clear(const struct ovsdb_idl *idl)
                     free(row->updated);
                     row->updated = NULL;
                 }
-                list_remove(&row->track_node);
-                list_init(&row->track_node);
+                ovs_list_remove(&row->track_node);
+                ovs_list_init(&row->track_node);
                 if (ovsdb_idl_row_is_orphan(row)) {
                     ovsdb_idl_row_clear_old(row);
                     free(row);
@@ -1037,9 +1066,9 @@ log_parse_update_error(struct ovsdb_error *error)
 }
 
 static void
-ovsdb_idl_send_monitor2_request(struct ovsdb_idl *idl)
+ovsdb_idl_send_monitor_cond_request(struct ovsdb_idl *idl)
 {
-    ovsdb_idl_send_monitor_request__(idl, "monitor2");
+    ovsdb_idl_send_monitor_request__(idl, "monitor_cond");
 }
 
 static void
@@ -1367,10 +1396,10 @@ ovsdb_idl_row_change__(struct ovsdb_idl_row *row, const struct json *row_json,
                         = row->table->change_seqno[change]
                         = row->table->idl->change_seqno + 1;
                     if (table->modes[column_idx] & OVSDB_IDL_TRACK) {
-                        if (!list_is_empty(&row->track_node)) {
-                            list_remove(&row->track_node);
+                        if (!ovs_list_is_empty(&row->track_node)) {
+                            ovs_list_remove(&row->track_node);
                         }
-                        list_push_back(&row->table->track_list,
+                        ovs_list_push_back(&row->table->track_list,
                                        &row->track_node);
                         if (!row->updated) {
                             row->updated = bitmap_allocate(class->n_columns);
@@ -1520,15 +1549,15 @@ ovsdb_idl_row_clear_arcs(struct ovsdb_idl_row *row, bool destroy_dsts)
      * freed.
      */
     LIST_FOR_EACH_SAFE (arc, next, src_node, &row->src_arcs) {
-        list_remove(&arc->dst_node);
+        ovs_list_remove(&arc->dst_node);
         if (destroy_dsts
             && ovsdb_idl_row_is_orphan(arc->dst)
-            && list_is_empty(&arc->dst->dst_arcs)) {
+            && ovs_list_is_empty(&arc->dst->dst_arcs)) {
             ovsdb_idl_row_destroy(arc->dst);
         }
         free(arc);
     }
-    list_init(&row->src_arcs);
+    ovs_list_init(&row->src_arcs);
 }
 
 /* Force nodes that reference 'row' to reparse. */
@@ -1561,10 +1590,10 @@ ovsdb_idl_row_create__(const struct ovsdb_idl_table_class *class)
 {
     struct ovsdb_idl_row *row = xzalloc(class->allocation_size);
     class->row_init(row);
-    list_init(&row->src_arcs);
-    list_init(&row->dst_arcs);
+    ovs_list_init(&row->src_arcs);
+    ovs_list_init(&row->dst_arcs);
     hmap_node_nullify(&row->txn_node);
-    list_init(&row->track_node);
+    ovs_list_init(&row->track_node);
     return row;
 }
 
@@ -1575,6 +1604,8 @@ ovsdb_idl_row_create(struct ovsdb_idl_table *table, const struct uuid *uuid)
     hmap_insert(&table->rows, &row->hmap_node, uuid_hash(uuid));
     row->uuid = *uuid;
     row->table = table;
+    row->map_op_written = NULL;
+    row->map_op_lists = NULL;
     return row;
 }
 
@@ -1584,14 +1615,37 @@ ovsdb_idl_row_destroy(struct ovsdb_idl_row *row)
     if (row) {
         ovsdb_idl_row_clear_old(row);
         hmap_remove(&row->table->rows, &row->hmap_node);
+        ovsdb_idl_destroy_all_map_op_lists(row);
         if (ovsdb_idl_track_is_set(row->table)) {
             row->change_seqno[OVSDB_IDL_CHANGE_DELETE]
                 = row->table->change_seqno[OVSDB_IDL_CHANGE_DELETE]
                 = row->table->idl->change_seqno + 1;
         }
-        if (list_is_empty(&row->track_node)) {
-            list_push_back(&row->table->track_list, &row->track_node);
+        if (!ovs_list_is_empty(&row->track_node)) {
+            ovs_list_remove(&row->track_node);
         }
+        ovs_list_push_back(&row->table->track_list, &row->track_node);
+    }
+}
+
+static void
+ovsdb_idl_destroy_all_map_op_lists(struct ovsdb_idl_row *row)
+{
+    if (row->map_op_written) {
+        /* Clear Map Operation Lists */
+        size_t idx, n_columns;
+        const struct ovsdb_idl_column *columns;
+        const struct ovsdb_type *type;
+        n_columns = row->table->class->n_columns;
+        columns = row->table->class->columns;
+        BITMAP_FOR_EACH_1 (idx, n_columns, row->map_op_written) {
+            type = &columns[idx].type;
+            map_op_list_destroy(row->map_op_lists[idx], type);
+        }
+        free(row->map_op_lists);
+        bitmap_free(row->map_op_written);
+        row->map_op_lists = NULL;
+        row->map_op_written = NULL;
     }
 }
 
@@ -1603,12 +1657,12 @@ ovsdb_idl_row_destroy_postprocess(struct ovsdb_idl *idl)
     for (i = 0; i < idl->class->n_tables; i++) {
         struct ovsdb_idl_table *table = &idl->tables[i];
 
-        if (!list_is_empty(&table->track_list)) {
+        if (!ovs_list_is_empty(&table->track_list)) {
             struct ovsdb_idl_row *row, *next;
 
             LIST_FOR_EACH_SAFE(row, next, track_node, &table->track_list) {
                 if (!ovsdb_idl_track_is_set(row->table)) {
-                    list_remove(&row->track_node);
+                    ovs_list_remove(&row->track_node);
                     free(row);
                 }
             }
@@ -1639,7 +1693,7 @@ ovsdb_idl_delete_row(struct ovsdb_idl_row *row)
     ovsdb_idl_row_unparse(row);
     ovsdb_idl_row_clear_arcs(row, true);
     ovsdb_idl_row_clear_old(row);
-    if (list_is_empty(&row->dst_arcs)) {
+    if (ovs_list_is_empty(&row->dst_arcs)) {
         ovsdb_idl_row_destroy(row);
     } else {
         ovsdb_idl_row_reparse_backrefs(row);
@@ -1692,7 +1746,7 @@ may_add_arc(const struct ovsdb_idl_row *src, const struct ovsdb_idl_row *dst)
      * at 'src', since we add all of the arcs from a given source in a clump
      * (in a single call to ovsdb_idl_row_parse()) and new arcs are always
      * added at the front of the dst_arcs list. */
-    if (list_is_empty(&dst->dst_arcs)) {
+    if (ovs_list_is_empty(&dst->dst_arcs)) {
         return true;
     }
     arc = CONTAINER_OF(dst->dst_arcs.next, struct ovsdb_idl_arc, dst_node);
@@ -1741,8 +1795,8 @@ ovsdb_idl_get_row_arc(struct ovsdb_idl_row *src,
             /* The arc *must* be added at the front of the dst_arcs list.  See
              * ovsdb_idl_row_reparse_backrefs() for details. */
             arc = xmalloc(sizeof *arc);
-            list_push_front(&src->src_arcs, &arc->src_node);
-            list_push_front(&dst->dst_arcs, &arc->dst_node);
+            ovs_list_push_front(&src->src_arcs, &arc->src_node);
+            ovs_list_push_front(&dst->dst_arcs, &arc->dst_node);
             arc->src = src;
             arc->dst = dst;
         }
@@ -2122,6 +2176,7 @@ ovsdb_idl_txn_disassemble(struct ovsdb_idl_txn *txn)
     txn->idl->txn = NULL;
 
     HMAP_FOR_EACH_SAFE (row, next, txn_node, &txn->txn_rows) {
+        ovsdb_idl_destroy_all_map_op_lists(row);
         if (row->old) {
             if (row->written) {
                 ovsdb_idl_row_unparse(row);
@@ -2150,6 +2205,124 @@ ovsdb_idl_txn_disassemble(struct ovsdb_idl_txn *txn)
     hmap_init(&txn->txn_rows);
 }
 
+static bool
+ovsdb_idl_txn_extract_mutations(struct ovsdb_idl_row *row,
+                                struct json *mutations)
+{
+    const struct ovsdb_idl_table_class *class = row->table->class;
+    size_t idx;
+    bool any_mutations = false;
+
+    BITMAP_FOR_EACH_1(idx, class->n_columns, row->map_op_written) {
+        struct map_op_list *map_op_list;
+        const struct ovsdb_idl_column *column;
+        const struct ovsdb_datum *old_datum;
+        enum ovsdb_atomic_type key_type, value_type;
+        struct json *mutation, *map, *col_name, *mutator;
+        struct json *del_set, *ins_map;
+        bool any_del, any_ins;
+
+        map_op_list = row->map_op_lists[idx];
+        column = &class->columns[idx];
+        key_type = column->type.key.type;
+        value_type = column->type.value.type;
+
+        /* Get the value to be changed */
+        if (row->new && row->written && bitmap_is_set(row->written,idx)) {
+            old_datum = &row->new[idx];
+        } else if (row->old != NULL) {
+            old_datum = &row->old[idx];
+        } else {
+            old_datum = ovsdb_datum_default(&column->type);
+        }
+
+        del_set = json_array_create_empty();
+        ins_map = json_array_create_empty();
+        any_del = false;
+        any_ins = false;
+
+        for (struct map_op *map_op = map_op_list_first(map_op_list); map_op;
+             map_op = map_op_list_next(map_op_list, map_op)) {
+
+            if (map_op_type(map_op) == MAP_OP_UPDATE) {
+                /* Find out if value really changed. */
+                struct ovsdb_datum *new_datum;
+                unsigned int pos;
+                new_datum = map_op_datum(map_op);
+                pos = ovsdb_datum_find_key(old_datum,
+                                           &new_datum->keys[0],
+                                           key_type);
+                if (ovsdb_atom_equals(&new_datum->values[0],
+                                      &old_datum->values[pos],
+                                      value_type)) {
+                    /* No change in value. Move on to next update. */
+                    continue;
+                }
+            } else if (map_op_type(map_op) == MAP_OP_DELETE){
+                /* Verify that there is a key to delete. */
+                unsigned int pos;
+                pos = ovsdb_datum_find_key(old_datum,
+                                           &map_op_datum(map_op)->keys[0],
+                                           key_type);
+                if (pos == UINT_MAX) {
+                    /* No key to delete.  Move on to next update. */
+                    VLOG_WARN("Trying to delete a key that doesn't "
+                              "exist in the map.");
+                    continue;
+                }
+            }
+
+            if (map_op_type(map_op) == MAP_OP_INSERT) {
+                map = json_array_create_2(
+                    ovsdb_atom_to_json(&map_op_datum(map_op)->keys[0],
+                                       key_type),
+                    ovsdb_atom_to_json(&map_op_datum(map_op)->values[0],
+                                       value_type));
+                json_array_add(ins_map, map);
+                any_ins = true;
+            } else { /* MAP_OP_UPDATE or MAP_OP_DELETE */
+                map = ovsdb_atom_to_json(&map_op_datum(map_op)->keys[0],
+                                         key_type);
+                json_array_add(del_set, map);
+                any_del = true;
+            }
+
+            /* Generate an additional insert mutate for updates. */
+            if (map_op_type(map_op) == MAP_OP_UPDATE) {
+                map = json_array_create_2(
+                    ovsdb_atom_to_json(&map_op_datum(map_op)->keys[0],
+                                       key_type),
+                    ovsdb_atom_to_json(&map_op_datum(map_op)->values[0],
+                                       value_type));
+                json_array_add(ins_map, map);
+                any_ins = true;
+            }
+        }
+
+        if (any_del) {
+            col_name = json_string_create(column->name);
+            mutator = json_string_create("delete");
+            map = json_array_create_2(json_string_create("set"), del_set);
+            mutation = json_array_create_3(col_name, mutator, map);
+            json_array_add(mutations, mutation);
+            any_mutations = true;
+        } else {
+            json_destroy(del_set);
+        }
+        if (any_ins) {
+            col_name = json_string_create(column->name);
+            mutator = json_string_create("insert");
+            map = json_array_create_2(json_string_create("map"), ins_map);
+            mutation = json_array_create_3(col_name, mutator, map);
+            json_array_add(mutations, mutation);
+            any_mutations = true;
+        } else {
+            json_destroy(ins_map);
+        }
+    }
+    return any_mutations;
+}
+
 /* Attempts to commit 'txn'.  Returns the status of the commit operation, one
  * of the following TXN_* constants:
  *
@@ -2336,6 +2509,28 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn)
                 json_destroy(op);
             }
         }
+
+        /* Add mutate operation, for partial map updates. */
+        if (row->map_op_written) {
+            struct json *op, *mutations;
+            bool any_mutations;
+
+            op = json_object_create();
+            json_object_put_string(op, "op", "mutate");
+            json_object_put_string(op, "table", class->name);
+            json_object_put(op, "where", where_uuid_equals(&row->uuid));
+            mutations = json_array_create_empty();
+            any_mutations = ovsdb_idl_txn_extract_mutations(row, mutations);
+            json_object_put(op, "mutations", mutations);
+
+            if (any_mutations) {
+                op = substitute_uuids(op, txn);
+                json_array_add(operations, op);
+                any_updates = true;
+            } else {
+                json_destroy(op);
+            }
+        }
     }
 
     /* Add increment. */
@@ -3059,7 +3254,7 @@ ovsdb_idl_update_has_lock(struct ovsdb_idl *idl, bool new_has_lock)
 {
     if (new_has_lock && !idl->has_lock) {
         if (idl->state == IDL_S_MONITORING ||
-            idl->state == IDL_S_MONITORING2) {
+            idl->state == IDL_S_MONITORING_COND) {
             idl->change_seqno++;
         } else {
             /* We're setting up a session, so don't signal that the database
@@ -3144,6 +3339,120 @@ ovsdb_idl_parse_lock_notify(struct ovsdb_idl *idl,
     }
 }
 
+/* Inserts a new Map Operation into current transaction. */
+static void
+ovsdb_idl_txn_add_map_op(struct ovsdb_idl_row *row,
+                         const struct ovsdb_idl_column *column,
+                         struct ovsdb_datum *datum,
+                         enum map_op_type op_type)
+{
+    const struct ovsdb_idl_table_class *class;
+    size_t column_idx;
+    struct map_op *map_op;
+
+    class = row->table->class;
+    column_idx = column - class->columns;
+
+    /* Check if a map operation list exists for this column. */
+    if (!row->map_op_written) {
+        row->map_op_written = bitmap_allocate(class->n_columns);
+        row->map_op_lists = xzalloc(class->n_columns *
+                                    sizeof *row->map_op_lists);
+    }
+    if (!row->map_op_lists[column_idx]) {
+        row->map_op_lists[column_idx] = map_op_list_create();
+    }
+
+    /* Add a map operation to the corresponding list. */
+    map_op = map_op_create(datum, op_type);
+    bitmap_set1(row->map_op_written, column_idx);
+    map_op_list_add(row->map_op_lists[column_idx], map_op, &column->type);
+
+    /* Add this row to transaction's list of rows. */
+    if (hmap_node_is_null(&row->txn_node)) {
+        hmap_insert(&row->table->idl->txn->txn_rows, &row->txn_node,
+                    uuid_hash(&row->uuid));
+    }
+}
+
+static bool
+is_valid_partial_update(const struct ovsdb_idl_row *row,
+                        const struct ovsdb_idl_column *column,
+                        struct ovsdb_datum *datum)
+{
+    /* Verify that this column is being monitored. */
+    unsigned int column_idx = column - row->table->class->columns;
+    if (!(row->table->modes[column_idx] & OVSDB_IDL_MONITOR)) {
+        VLOG_WARN("cannot partially update non-monitored column");
+        return false;
+    }
+
+    /* Verify that the update affects a single element. */
+    if (datum->n != 1) {
+        VLOG_WARN("invalid datum for partial update");
+        return false;
+    }
+
+    return true;
+}
+
+/* Inserts the key-value specified in 'datum' into the map in 'column' in
+ * 'row_'. If the key already exist in 'column', then it's value is updated
+ * with the value in 'datum'. The key-value in 'datum' must be of the same type
+ * as the keys-values in 'column'. This function takes ownership of 'datum'.
+ *
+ * Usually this function is used indirectly through one of the "update"
+ * functions generated by vswitch-idl. */
+void
+ovsdb_idl_txn_write_partial_map(const struct ovsdb_idl_row *row_,
+                                const struct ovsdb_idl_column *column,
+                                struct ovsdb_datum *datum)
+{
+    struct ovsdb_idl_row *row = CONST_CAST(struct ovsdb_idl_row *, row_);
+    enum ovsdb_atomic_type key_type;
+    enum map_op_type op_type;
+    unsigned int pos;
+    const struct ovsdb_datum *old_datum;
+
+    if (!is_valid_partial_update(row, column, datum)) {
+        ovsdb_datum_destroy(datum, &column->type);
+        free(datum);
+        return;
+    }
+
+    /* Find out if this is an insert or an update. */
+    key_type = column->type.key.type;
+    old_datum = ovsdb_idl_read(row, column);
+    pos = ovsdb_datum_find_key(old_datum, &datum->keys[0], key_type);
+    op_type = pos == UINT_MAX ? MAP_OP_INSERT : MAP_OP_UPDATE;
+
+    ovsdb_idl_txn_add_map_op(row, column, datum, op_type);
+}
+
+/* Deletes the key specified in 'datum' from the map in 'column' in 'row_'.
+ * The key in 'datum' must be of the same type as the keys in 'column'.
+ * The value in 'datum' must be NULL. This function takes ownership of
+ * 'datum'.
+ *
+ * Usually this function is used indirectly through one of the "update"
+ * functions generated by vswitch-idl. */
+void
+ovsdb_idl_txn_delete_partial_map(const struct ovsdb_idl_row *row_,
+                                 const struct ovsdb_idl_column *column,
+                                 struct ovsdb_datum *datum)
+{
+    struct ovsdb_idl_row *row = CONST_CAST(struct ovsdb_idl_row *, row_);
+
+    if (!is_valid_partial_update(row, column, datum)) {
+        struct ovsdb_type type_ = column->type;
+        type_.value.type = OVSDB_TYPE_VOID;
+        ovsdb_datum_destroy(datum, &type_);
+        free(datum);
+        return;
+    }
+    ovsdb_idl_txn_add_map_op(row, column, datum, MAP_OP_DELETE);
+}
+
 void
 ovsdb_idl_loop_destroy(struct ovsdb_idl_loop *loop)
 {