return txn;
}
+/* Appends 's', which is treated as a printf()-type format string, to the
+ * comments that will be passed to the OVSDB server when 'txn' is committed.
+ * (The comment will be committed to the OVSDB log, which "ovsdb-tool
+ * show-log" can print in a relatively human-readable form.) */
void
-ovsdb_idl_txn_add_comment(struct ovsdb_idl_txn *txn, const char *s)
+ovsdb_idl_txn_add_comment(struct ovsdb_idl_txn *txn, const char *s, ...)
{
+ va_list args;
+
if (txn->comment.length) {
ds_put_char(&txn->comment, '\n');
}
- ds_put_cstr(&txn->comment, s);
+
+ va_start(args, s);
+ ds_put_format_valist(&txn->comment, s, args);
+ va_end(args);
}
void
#include <stdbool.h>
#include <stdint.h>
+#include "compiler.h"
struct json;
struct ovsdb_datum;
const char *ovsdb_idl_txn_status_to_string(enum ovsdb_idl_txn_status);
struct ovsdb_idl_txn *ovsdb_idl_txn_create(struct ovsdb_idl *);
-void ovsdb_idl_txn_add_comment(struct ovsdb_idl_txn *, const char *);
+void ovsdb_idl_txn_add_comment(struct ovsdb_idl_txn *, const char *, ...)
+ PRINTF_FORMAT (2, 3);
void ovsdb_idl_txn_set_dry_run(struct ovsdb_idl_txn *);
void ovsdb_idl_txn_increment(struct ovsdb_idl_txn *, const char *table,
const char *column, const struct json *where);
struct ovsrec_port *port;
struct ovsrec_interface *iface;
struct ovsdb_idl_txn *txn;
- char *comment;
if (find_bridge(ovs, br_name)) {
VLOG_WARN("addbr %s: bridge %s exists", br_name, br_name);
txn = ovsdb_idl_txn_create(idl);
- comment = xasprintf("ovs-brcompatd: addbr %s", br_name);
- ovsdb_idl_txn_add_comment(txn, comment);
- free(comment);
+ ovsdb_idl_txn_add_comment(txn, "ovs-brcompatd: addbr %s", br_name);
iface = ovsrec_interface_insert(txn_from_openvswitch(ovs));
ovsrec_interface_set_name(iface, br_name);
struct ovsrec_bridge *br = find_bridge(ovs, br_name);
struct ovsrec_bridge **bridges;
struct ovsdb_idl_txn *txn;
- char *comment;
size_t i, n;
if (!br) {
txn = ovsdb_idl_txn_create(idl);
- comment = xasprintf("ovs-brcompatd: delbr %s", br_name);
- ovsdb_idl_txn_add_comment(txn, comment);
- free(comment);
+ ovsdb_idl_txn_add_comment(txn, "ovs-brcompatd: delbr %s", br_name);
del_port(br, br_name);
} else {
do {
struct ovsdb_idl_txn *txn = ovsdb_idl_txn_create(idl);
- char *comment;
if (add) {
- comment = xasprintf("ovs-brcompatd: add-if %s", port_name);
+ ovsdb_idl_txn_add_comment(txn, "ovs-brcompatd: add-if %s",
+ port_name);
add_port(ovs, br, port_name);
} else {
- comment = xasprintf("ovs-brcompatd: del-if %s", port_name);
+ ovsdb_idl_txn_add_comment(txn, "ovs-brcompatd: del-if %s",
+ port_name);
del_port(br, port_name);
}
- ovsdb_idl_txn_add_comment(txn, comment);
- free(comment);
-
error = commit_txn(txn, true);
VLOG_INFO_RL(&rl, "%s %s %s: %s",
cmd_name, br_name, port_name, strerror(error));
/* Network device is really gone. */
struct ovsdb_idl_txn *txn;
struct ovsrec_bridge *br;
- char *comment;
VLOG_INFO("network device %s destroyed, "
"removing from bridge %s", port_name, br_name);
}
txn = ovsdb_idl_txn_create(idl);
-
- comment = xasprintf("ovs-brcompatd: destroy port %s",
- port_name);
- ovsdb_idl_txn_add_comment(txn, comment);
- free(comment);
+ ovsdb_idl_txn_add_comment(txn,
+ "ovs-brcompatd: destroy port %s",
+ port_name);
del_port(br, port_name);
commit_txn(txn, false);