#include "compiler.h"
#include "dirs.h"
#include "dynamic-string.h"
+#include "json.h"
#include "ovsdb-idl.h"
#include "poll-loop.h"
#include "svec.h"
/* --dry-run: Do not commit any changes. */
static bool dry_run;
+/* --no-wait: Wait for ovs-vswitchd to reload its configuration? */
+static bool wait_for_reload = true;
+
/* --timeout: Time to wait for a connection to 'db'. */
static int timeout = 5;
break;
case OPT_NO_WAIT:
- /* XXX not yet implemented */
+ wait_for_reload = false;
break;
case OPT_DRY_RUN:
const struct ovsrec_open_vswitch *ovs,
struct ds *output);
+static struct json *
+where_uuid_equals(const struct uuid *uuid)
+{
+ return
+ json_array_create_1(
+ json_array_create_3(
+ json_string_create("_uuid"),
+ json_string_create("=="),
+ json_array_create_2(
+ json_string_create("uuid"),
+ json_string_create_nocopy(
+ xasprintf(UUID_FMT, UUID_ARGS(uuid))))));
+}
+
static void
do_vsctl(int argc, char *argv[], struct ovsdb_idl *idl)
{
const struct ovsrec_open_vswitch *ovs;
enum ovsdb_idl_txn_status status;
struct ds comment, *output;
+ int64_t next_cfg;
int n_output;
int i, start;
ovs = ovsrec_open_vswitch_insert(txn);
}
+ if (wait_for_reload) {
+ struct json *where = where_uuid_equals(&ovs->header_.uuid);
+ ovsdb_idl_txn_increment(txn, "Open_vSwitch", "next_cfg",
+ where);
+ json_destroy(where);
+ }
+
output = xmalloc(argc * sizeof *output);
n_output = 0;
for (start = i = 0; i <= argc; i++) {
ovsdb_idl_txn_wait(txn);
poll_block();
}
+ if (wait_for_reload && status == TXN_SUCCESS) {
+ next_cfg = ovsdb_idl_txn_get_increment_new_value(txn);
+ }
ovsdb_idl_txn_destroy(txn);
switch (status) {
/* Should not happen--we never call ovsdb_idl_txn_abort(). */
vsctl_fatal("transaction aborted");
+ case TXN_UNCHANGED:
case TXN_SUCCESS:
break;
fputs(ds_cstr(ds), stdout);
}
}
+
+ if (wait_for_reload && status != TXN_UNCHANGED) {
+ for (;;) {
+ const struct ovsrec_open_vswitch *ovs;
+
+ ovsdb_idl_run(idl);
+ OVSREC_OPEN_VSWITCH_FOR_EACH (ovs, idl) {
+ if (ovs->cur_cfg >= next_cfg) {
+ goto done;
+ }
+ }
+ ovsdb_idl_wait(idl);
+ poll_block();
+ }
+ done: ;
+ }
+
exit(EXIT_SUCCESS);
}