summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2010-03-08 14:18:44 -0800
committerBen Pfaff <blp@nicira.com>2010-03-08 14:18:44 -0800
commite1c0e2d1730b884b2ecda1a41ec9661e8b9251e2 (patch)
treeb72ab016bf233aa90ff09e1befebdeef1c9e9a43
parent4787d6d7df196ff7463517423dfbdfd41bdceffe (diff)
downloadopenvswitch-e1c0e2d1730b884b2ecda1a41ec9661e8b9251e2.tar.gz
ovsdb-idl: Make ovsdb_idl_txn_add_comment() take a printf() format string.
All of the callers were calling xasprintf() and then passing the result to ovsdb_idl_txn_add_comment(), so this slightly simplifies the callers.
-rw-r--r--lib/ovsdb-idl.c13
-rw-r--r--lib/ovsdb-idl.h4
-rw-r--r--utilities/ovs-vsctl.c5
-rw-r--r--vswitchd/ovs-brcompatd.c29
4 files changed, 24 insertions, 27 deletions
diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index ba58895af..42c53b831 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -914,13 +914,22 @@ ovsdb_idl_txn_create(struct ovsdb_idl *idl)
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
diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
index 4c64585da..2aaaa71c9 100644
--- a/lib/ovsdb-idl.h
+++ b/lib/ovsdb-idl.h
@@ -18,6 +18,7 @@
#include <stdbool.h>
#include <stdint.h>
+#include "compiler.h"
struct json;
struct ovsdb_datum;
@@ -58,7 +59,8 @@ enum ovsdb_idl_txn_status {
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);
diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
index 4efb1d0f5..4ca737edc 100644
--- a/utilities/ovs-vsctl.c
+++ b/utilities/ovs-vsctl.c
@@ -2353,7 +2353,6 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
enum ovsdb_idl_txn_status status;
struct vsctl_command *c;
int64_t next_cfg = 0;
- char *comment;
char *error;
txn = the_idl_txn = ovsdb_idl_txn_create(idl);
@@ -2361,9 +2360,7 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
ovsdb_idl_txn_set_dry_run(txn);
}
- comment = xasprintf("ovs-vsctl: %s", args);
- ovsdb_idl_txn_add_comment(txn, comment);
- free(comment);
+ ovsdb_idl_txn_add_comment(txn, "ovs-vsctl: %s", args);
ovs = ovsrec_open_vswitch_first(idl);
if (!ovs) {
diff --git a/vswitchd/ovs-brcompatd.c b/vswitchd/ovs-brcompatd.c
index 6b6594797..b364b0b4f 100644
--- a/vswitchd/ovs-brcompatd.c
+++ b/vswitchd/ovs-brcompatd.c
@@ -463,7 +463,6 @@ add_bridge(struct ovsdb_idl *idl, const struct ovsrec_open_vswitch *ovs,
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);
@@ -492,9 +491,7 @@ add_bridge(struct ovsdb_idl *idl, const struct ovsrec_open_vswitch *ovs,
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);
@@ -582,7 +579,6 @@ del_bridge(struct ovsdb_idl *idl,
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) {
@@ -592,9 +588,7 @@ del_bridge(struct ovsdb_idl *idl,
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);
@@ -738,19 +732,17 @@ handle_port_cmd(struct ovsdb_idl *idl,
} 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));
@@ -1200,7 +1192,6 @@ rtnl_recv_update(struct ovsdb_idl *idl,
/* 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);
@@ -1214,11 +1205,9 @@ rtnl_recv_update(struct ovsdb_idl *idl,
}
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);