X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ovsdb%2Ftransaction.c;h=45b208394267875d050b1abbcf3ecc8422b62c5a;hb=3da1c516ba4556970040747c9d4778b87986da52;hp=d5e3601678b3bf3ccd4599e32999ba8e734eabea;hpb=bd06962ad334fa4631b67905fc9f43f96a908915;p=openvswitch diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c index d5e36016..45b20839 100644 --- a/ovsdb/transaction.c +++ b/ovsdb/transaction.c @@ -19,6 +19,7 @@ #include +#include "dynamic-string.h" #include "hash.h" #include "hmap.h" #include "json.h" @@ -31,6 +32,7 @@ struct ovsdb_txn { struct ovsdb *db; struct hmap txn_tables; /* Contains "struct ovsdb_txn_table"s. */ + struct ds comment; }; /* A table modified by a transaction. */ @@ -65,6 +67,7 @@ ovsdb_txn_create(struct ovsdb *db) struct ovsdb_txn *txn = xmalloc(sizeof *txn); txn->db = db; hmap_init(&txn->txn_tables); + ds_init(&txn->comment); return txn; } @@ -82,6 +85,9 @@ ovsdb_txn_destroy(struct ovsdb_txn *txn, void (*cb)(struct ovsdb_txn_row *)) struct ovsdb_txn_row, hmap_node, &txn_table->txn_rows) { + if (txn_row->old) { + txn_row->old->txn_row = NULL; + } if (txn_row->new) { txn_row->new->txn_row = NULL; } @@ -93,6 +99,7 @@ ovsdb_txn_destroy(struct ovsdb_txn *txn, void (*cb)(struct ovsdb_txn_row *)) free(txn_table); } hmap_destroy(&txn->txn_tables); + ds_destroy(&txn->comment); free(txn); } @@ -281,3 +288,18 @@ ovsdb_txn_row_delete(struct ovsdb_txn *txn, const struct ovsdb_row *row_) ovsdb_row_destroy(row); } } + +void +ovsdb_txn_add_comment(struct ovsdb_txn *txn, const char *s) +{ + if (txn->comment.length) { + ds_put_char(&txn->comment, '\n'); + } + ds_put_cstr(&txn->comment, s); +} + +const char * +ovsdb_txn_get_comment(const struct ovsdb_txn *txn) +{ + return txn->comment.length ? ds_cstr_ro(&txn->comment) : NULL; +}