ovsdb-server: Make database name mandatory when specifying db paths.
[sliver-openvswitch.git] / ovsdb / ovsdb-server.c
index a8daf1f..919575a 100644 (file)
@@ -32,7 +32,6 @@
 #include "json.h"
 #include "jsonrpc.h"
 #include "jsonrpc-server.h"
-#include "leak-checker.h"
 #include "list.h"
 #include "memory.h"
 #include "ovsdb.h"
@@ -43,6 +42,7 @@
 #include "process.h"
 #include "row.h"
 #include "simap.h"
+#include "shash.h"
 #include "stream-ssl.h"
 #include "stream.h"
 #include "stress.h"
@@ -79,25 +79,36 @@ static unixctl_cb_func ovsdb_server_reconnect;
 
 struct add_remote_aux {
     struct sset *remotes;
-    struct db *dbs;
-    size_t n_dbs;
+    struct shash *all_dbs;
+    FILE *config_tmpfile;
 };
 static unixctl_cb_func ovsdb_server_add_remote;
+
+struct remove_remote_aux {
+    struct sset *remotes;
+    FILE *config_tmpfile;
+};
 static unixctl_cb_func ovsdb_server_remove_remote;
 static unixctl_cb_func ovsdb_server_list_remotes;
 
+static void open_db(struct ovsdb_jsonrpc_server *jsonrpc,
+                    struct db *db, struct shash *all_dbs);
+
 static void parse_options(int *argc, char **argvp[],
                           struct sset *remotes, char **unixctl_pathp,
                           char **run_command);
 static void usage(void) NO_RETURN;
 
 static void reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
-                                const struct db dbs[], size_t n_dbs,
+                                const struct shash *all_dbs,
                                 struct sset *remotes);
 
 static void update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
                                  const struct sset *remotes,
-                                 struct db dbs[], size_t n_dbs);
+                                 struct shash *all_dbs);
+
+static void save_config(FILE *config_file, const struct sset *);
+static void load_config(FILE *config_file, struct sset *);
 
 int
 main(int argc, char *argv[])
@@ -112,9 +123,11 @@ main(int argc, char *argv[])
     int retval;
     long long int status_timer = LLONG_MIN;
     struct add_remote_aux add_remote_aux;
+    struct remove_remote_aux remove_remote_aux;
+    FILE *config_tmpfile;
 
-    struct db *dbs;
-    int n_dbs;
+    struct shash all_dbs;
+    struct shash_node *node;
     int i;
 
     proctitle_init(argc, argv);
@@ -125,36 +138,38 @@ main(int argc, char *argv[])
 
     parse_options(&argc, &argv, &remotes, &unixctl_path, &run_command);
 
+    /* Create and initialize 'config_tmpfile' as a temporary file to hold
+     * ovsdb-server's most basic configuration, and then save our initial
+     * configuration to it.  When --monitor is used, this preserves the effects
+     * of ovs-appctl commands such as ovsdb-server/add-remote (which saves the
+     * new configuration) across crashes. */
+    config_tmpfile = tmpfile();
+    if (!config_tmpfile) {
+        ovs_fatal(errno, "failed to create temporary file");
+    }
+    save_config(config_tmpfile, &remotes);
+
     daemonize_start();
 
-    n_dbs = MAX(1, argc);
-    dbs = xcalloc(n_dbs + 1, sizeof *dbs);
+    /* Load the saved config. */
+    load_config(config_tmpfile, &remotes);
+
+    shash_init(&all_dbs);
+    jsonrpc = ovsdb_jsonrpc_server_create();
+
     if (argc > 0) {
         for (i = 0; i < argc; i++) {
-            dbs[i].filename = argv[i];
-        }
+            struct db *db = xzalloc(sizeof *db);
+            db->filename = argv[i];
+            open_db(jsonrpc, db, &all_dbs);
+         }
     } else {
-        dbs[0].filename = xasprintf("%s/conf.db", ovs_dbdir());
+        struct db *db = xzalloc(sizeof *db);
+        db->filename = xasprintf("%s/conf.db", ovs_dbdir());
+        open_db(jsonrpc, db, &all_dbs);
     }
 
-    for (i = 0; i < n_dbs; i++) {
-        struct ovsdb_error *error;
-
-        error = ovsdb_file_open(dbs[i].filename, false,
-                                &dbs[i].db, &dbs[i].file);
-        if (error) {
-            ovs_fatal(0, "%s", ovsdb_error_to_string(error));
-        }
-    }
-
-    jsonrpc = ovsdb_jsonrpc_server_create();
-    for (i = 0; i < n_dbs; i++) {
-        if (!ovsdb_jsonrpc_server_add_db(jsonrpc, dbs[i].db)) {
-            ovs_fatal(0, "%s: duplicate database name",
-                      dbs[i].db->schema->name);
-        }
-    }
-    reconfigure_from_db(jsonrpc, dbs, n_dbs, &remotes);
+    reconfigure_from_db(jsonrpc, &all_dbs, &remotes);
 
     retval = unixctl_server_create(unixctl_path, &unixctl);
     if (retval) {
@@ -169,7 +184,7 @@ main(int argc, char *argv[])
         run_argv[2] = run_command;
         run_argv[3] = NULL;
 
-        retval = process_start(run_argv, NULL, 0, NULL, 0, &run_process);
+        retval = process_start(run_argv, &run_process);
         if (retval) {
             ovs_fatal(retval, "%s: process failed to start", run_command);
         }
@@ -188,32 +203,35 @@ main(int argc, char *argv[])
 
     unixctl_command_register("exit", "", 0, 0, ovsdb_server_exit, &exiting);
     unixctl_command_register("ovsdb-server/compact", "", 0, 1,
-                             ovsdb_server_compact, dbs);
+                             ovsdb_server_compact, &all_dbs);
     unixctl_command_register("ovsdb-server/reconnect", "", 0, 0,
                              ovsdb_server_reconnect, jsonrpc);
 
     add_remote_aux.remotes = &remotes;
-    add_remote_aux.dbs = dbs;
-    add_remote_aux.n_dbs = n_dbs;
+    add_remote_aux.all_dbs = &all_dbs;
+    add_remote_aux.config_tmpfile = config_tmpfile;
     unixctl_command_register("ovsdb-server/add-remote", "REMOTE", 1, 1,
                              ovsdb_server_add_remote, &add_remote_aux);
+
+    remove_remote_aux.remotes = &remotes;
+    remove_remote_aux.config_tmpfile = config_tmpfile;
     unixctl_command_register("ovsdb-server/remove-remote", "REMOTE", 1, 1,
-                             ovsdb_server_remove_remote, &remotes);
+                             ovsdb_server_remove_remote, &remove_remote_aux);
+
     unixctl_command_register("ovsdb-server/list-remotes", "", 0, 0,
                              ovsdb_server_list_remotes, &remotes);
 
     exiting = false;
     while (!exiting) {
-        int i;
-
         memory_run();
         if (memory_should_report()) {
             struct simap usage;
 
             simap_init(&usage);
             ovsdb_jsonrpc_server_get_memory_usage(jsonrpc, &usage);
-            for (i = 0; i < n_dbs; i++) {
-                ovsdb_get_memory_usage(dbs[i].db, &usage);
+            SHASH_FOR_EACH(node, &all_dbs) {
+                struct db *db = node->data;
+                ovsdb_get_memory_usage(db->db, &usage);
             }
             memory_report(&usage);
             simap_destroy(&usage);
@@ -224,27 +242,32 @@ main(int argc, char *argv[])
          * the set of remotes that reconfigure_from_db() uses. */
         unixctl_server_run(unixctl);
 
-        reconfigure_from_db(jsonrpc, dbs, n_dbs, &remotes);
+        reconfigure_from_db(jsonrpc, &all_dbs, &remotes);
         ovsdb_jsonrpc_server_run(jsonrpc);
 
-        for (i = 0; i < n_dbs; i++) {
-            ovsdb_trigger_run(dbs[i].db, time_msec());
+        SHASH_FOR_EACH(node, &all_dbs) {
+            struct db *db = node->data;
+            ovsdb_trigger_run(db->db, time_msec());
         }
-        if (run_process && process_exited(run_process)) {
-            exiting = true;
+        if (run_process) {
+            process_run();
+            if (process_exited(run_process)) {
+                exiting = true;
+            }
         }
 
         /* update Manager status(es) every 5 seconds */
         if (time_msec() >= status_timer) {
             status_timer = time_msec() + 5000;
-            update_remote_status(jsonrpc, &remotes, dbs, n_dbs);
+            update_remote_status(jsonrpc, &remotes, &all_dbs);
         }
 
         memory_wait();
         ovsdb_jsonrpc_server_wait(jsonrpc);
         unixctl_server_wait(unixctl);
-        for (i = 0; i < n_dbs; i++) {
-            ovsdb_trigger_wait(dbs[i].db, time_msec());
+        SHASH_FOR_EACH(node, &all_dbs) {
+            struct db *db = node->data;
+            ovsdb_trigger_wait(db->db, time_msec());
         }
         if (run_process) {
             process_wait(run_process);
@@ -256,8 +279,9 @@ main(int argc, char *argv[])
         poll_block();
     }
     ovsdb_jsonrpc_server_destroy(jsonrpc);
-    for (i = 0; i < n_dbs; i++) {
-        ovsdb_destroy(dbs[i].db);
+    SHASH_FOR_EACH(node, &all_dbs) {
+        struct db *db = node->data;
+        ovsdb_destroy(db->db);
     }
     sset_destroy(&remotes);
     unixctl_server_destroy(unixctl);
@@ -273,14 +297,35 @@ main(int argc, char *argv[])
     return 0;
 }
 
+static void
+open_db(struct ovsdb_jsonrpc_server *jsonrpc, struct db *db,
+        struct shash *all_dbs)
+{
+    struct ovsdb_error *error;
+
+    error = ovsdb_file_open(db->filename, false,
+                            &db->db, &db->file);
+    if (error) {
+        ovs_fatal(0, "%s", ovsdb_error_to_string(error));
+    }
+
+    if (!ovsdb_jsonrpc_server_add_db(jsonrpc, db->db)) {
+        ovs_fatal(0, "%s: duplicate database name",
+                  db->db->schema->name);
+    }
+
+    shash_add(all_dbs, db->filename, db);
+}
+
 static const struct db *
-find_db(const struct db dbs[], size_t n_dbs, const char *db_name)
+find_db(const struct shash *all_dbs, const char *db_name)
 {
-    size_t i;
+    struct shash_node *node;
 
-    for (i = 0; i < n_dbs; i++) {
-        if (!strcmp(dbs[i].db->schema->name, db_name)) {
-            return &dbs[i];
+    SHASH_FOR_EACH(node, all_dbs) {
+        struct db *db = node->data;
+        if (!strcmp(db->db->schema->name, db_name)) {
+            return db;
         }
     }
 
@@ -288,13 +333,13 @@ find_db(const struct db dbs[], size_t n_dbs, const char *db_name)
 }
 
 static char * WARN_UNUSED_RESULT
-parse_db_column__(const struct db dbs[], size_t n_dbs,
+parse_db_column__(const struct shash *all_dbs,
                   const char *name_, char *name,
                   const struct db **dbp,
                   const struct ovsdb_table **tablep,
                   const struct ovsdb_column **columnp)
 {
-    const char *table_name, *column_name;
+    const char *db_name, *table_name, *column_name;
     const struct ovsdb_column *column;
     const struct ovsdb_table *table;
     const char *tokens[3];
@@ -309,28 +354,17 @@ parse_db_column__(const struct db dbs[], size_t n_dbs,
     tokens[0] = strtok_r(NULL, ",", &save_ptr);
     tokens[1] = strtok_r(NULL, ",", &save_ptr);
     tokens[2] = strtok_r(NULL, ",", &save_ptr);
-    if (!tokens[0] || !tokens[1]) {
+    if (!tokens[0] || !tokens[1] || !tokens[2]) {
         return xasprintf("\"%s\": invalid syntax", name_);
     }
-    if (tokens[2]) {
-        const char *db_name = tokens[0];
-        table_name = tokens[1];
-        column_name = tokens[2];
-
-        db = find_db(dbs, n_dbs, tokens[0]);
-        if (!db) {
-            return xasprintf("\"%s\": no database named %s", name_, db_name);
-        }
-    } else {
-        if (n_dbs > 1) {
-            return xasprintf("\"%s\": database name must be specified "
-                             "(because multiple databases are configured)",
-                             name_);
-        }
 
-        table_name = tokens[0];
-        column_name = tokens[1];
-        db = &dbs[0];
+    db_name = tokens[0];
+    table_name = tokens[1];
+    column_name = tokens[2];
+
+    db = find_db(all_dbs, tokens[0]);
+    if (!db) {
+        return xasprintf("\"%s\": no database named %s", name_, db_name);
     }
 
     table = ovsdb_get_table(db->db, table_name);
@@ -353,14 +387,14 @@ parse_db_column__(const struct db dbs[], size_t n_dbs,
 /* Returns NULL if successful, otherwise a malloc()'d string describing the
  * error. */
 static char * WARN_UNUSED_RESULT
-parse_db_column(const struct db dbs[], size_t n_dbs,
+parse_db_column(const struct shash *all_dbs,
                 const char *name_,
                 const struct db **dbp,
                 const struct ovsdb_table **tablep,
                 const struct ovsdb_column **columnp)
 {
     char *name = xstrdup(name_);
-    char *retval = parse_db_column__(dbs, n_dbs, name_, name,
+    char *retval = parse_db_column__(all_dbs, name_, name,
                                      dbp, tablep, columnp);
     free(name);
     return retval;
@@ -369,7 +403,7 @@ parse_db_column(const struct db dbs[], size_t n_dbs,
 /* Returns NULL if successful, otherwise a malloc()'d string describing the
  * error. */
 static char * WARN_UNUSED_RESULT
-parse_db_string_column(const struct db dbs[], size_t n_dbs,
+parse_db_string_column(const struct shash *all_dbs,
                        const char *name,
                        const struct db **dbp,
                        const struct ovsdb_table **tablep,
@@ -377,7 +411,7 @@ parse_db_string_column(const struct db dbs[], size_t n_dbs,
 {
     char *retval;
 
-    retval = parse_db_column(dbs, n_dbs, name, dbp, tablep, columnp);
+    retval = parse_db_column(all_dbs, name, dbp, tablep, columnp);
     if (retval) {
         return retval;
     }
@@ -393,7 +427,7 @@ parse_db_string_column(const struct db dbs[], size_t n_dbs,
 }
 
 static OVS_UNUSED const char *
-query_db_string(const struct db dbs[], size_t n_dbs, const char *name)
+query_db_string(const struct shash *all_dbs, const char *name)
 {
     if (!name || strncmp(name, "db:", 3)) {
         return name;
@@ -404,7 +438,7 @@ query_db_string(const struct db dbs[], size_t n_dbs, const char *name)
         const struct db *db;
         char *retval;
 
-        retval = parse_db_string_column(dbs, n_dbs, name,
+        retval = parse_db_string_column(all_dbs, name,
                                         &db, &table, &column);
         if (retval) {
             ovs_fatal(0, "%s", retval);
@@ -631,7 +665,7 @@ add_manager_options(struct shash *remotes, const struct ovsdb_row *row)
 }
 
 static void
-query_db_remotes(const char *name, const struct db dbs[], size_t n_dbs,
+query_db_remotes(const char *name, const struct shash *all_dbs,
                  struct shash *remotes)
 {
     const struct ovsdb_column *column;
@@ -640,7 +674,7 @@ query_db_remotes(const char *name, const struct db dbs[], size_t n_dbs,
     const struct db *db;
     char *retval;
 
-    retval = parse_db_column(dbs, n_dbs, name, &db, &table, &column);
+    retval = parse_db_column(all_dbs, name, &db, &table, &column);
     if (retval) {
         ovs_fatal(0, "%s", retval);
     }
@@ -741,7 +775,7 @@ update_remote_row(const struct ovsdb_row *row, struct ovsdb_txn *txn,
 }
 
 static void
-update_remote_rows(const struct db dbs[], size_t n_dbs,
+update_remote_rows(const struct shash *all_dbs,
                    const char *remote_name,
                    const struct ovsdb_jsonrpc_server *jsonrpc)
 {
@@ -755,7 +789,7 @@ update_remote_rows(const struct db dbs[], size_t n_dbs,
         return;
     }
 
-    retval = parse_db_column(dbs, n_dbs, remote_name, &db, &table, &column);
+    retval = parse_db_column(all_dbs, remote_name, &db, &table, &column);
     if (retval) {
         ovs_fatal(0, "%s", retval);
     }
@@ -787,23 +821,27 @@ update_remote_rows(const struct db dbs[], size_t n_dbs,
 static void
 update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
                      const struct sset *remotes,
-                     struct db dbs[], size_t n_dbs)
+                     struct shash *all_dbs)
 {
     static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
     const char *remote;
-    size_t i;
+    struct db *db;
+    struct shash_node *node;
 
-    for (i = 0; i < n_dbs; i++) {
-        dbs[i].txn = ovsdb_txn_create(dbs[i].db);
+    SHASH_FOR_EACH(node, all_dbs) {
+        db = node->data;
+        db->txn = ovsdb_txn_create(db->db);
     }
 
     /* Iterate over --remote arguments given on command line. */
     SSET_FOR_EACH (remote, remotes) {
-        update_remote_rows(dbs, n_dbs, remote, jsonrpc);
+        update_remote_rows(all_dbs, remote, jsonrpc);
     }
 
-    for (i = 0; i < n_dbs; i++) {
-        struct ovsdb_error *error = ovsdb_txn_commit(dbs[i].txn, false);
+    SHASH_FOR_EACH(node, all_dbs) {
+        struct ovsdb_error *error;
+        db = node->data;
+        error = ovsdb_txn_commit(db->txn, false);
         if (error) {
             VLOG_ERR_RL(&rl, "Failed to update remote status: %s",
                         ovsdb_error_to_string(error));
@@ -815,7 +853,7 @@ update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
 /* Reconfigures ovsdb-server based on information in the database. */
 static void
 reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
-                    const struct db dbs[], size_t n_dbs, struct sset *remotes)
+                    const struct shash *all_dbs, struct sset *remotes)
 {
     struct shash resolved_remotes;
     const char *name;
@@ -824,7 +862,7 @@ reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
     shash_init(&resolved_remotes);
     SSET_FOR_EACH (name, remotes) {
         if (!strncmp(name, "db:", 3)) {
-            query_db_remotes(name, dbs, n_dbs, &resolved_remotes);
+            query_db_remotes(name, all_dbs, &resolved_remotes);
         } else {
             add_remote(&resolved_remotes, name);
         }
@@ -833,9 +871,9 @@ reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
     shash_destroy_free_data(&resolved_remotes);
 
     /* Configure SSL. */
-    stream_ssl_set_key_and_cert(query_db_string(dbs, n_dbs, private_key_file),
-                                query_db_string(dbs, n_dbs, certificate_file));
-    stream_ssl_set_ca_cert_file(query_db_string(dbs, n_dbs, ca_cert_file),
+    stream_ssl_set_key_and_cert(query_db_string(all_dbs, private_key_file),
+                                query_db_string(all_dbs, certificate_file));
+    stream_ssl_set_ca_cert_file(query_db_string(all_dbs, ca_cert_file),
                                 bootstrap_ca_cert);
 }
 
@@ -853,14 +891,18 @@ static void
 ovsdb_server_compact(struct unixctl_conn *conn, int argc,
                      const char *argv[], void *dbs_)
 {
-    struct db *dbs = dbs_;
+    struct shash *all_dbs = dbs_;
     struct ds reply;
     struct db *db;
+    struct shash_node *node;
     int n = 0;
 
     ds_init(&reply);
-    for (db = dbs; db->filename != NULL; db++) {
-        const char *name = db->db->schema->name;
+    SHASH_FOR_EACH(node, all_dbs) {
+        const char *name;
+
+        db = node->data;
+        name = db->db->schema->name;
 
         if (argc < 2 || !strcmp(argv[1], name)) {
             struct ovsdb_error *error;
@@ -916,10 +958,12 @@ ovsdb_server_add_remote(struct unixctl_conn *conn, int argc OVS_UNUSED,
 
     retval = (strncmp("db:", remote, 3)
               ? NULL
-              : parse_db_column(aux->dbs, aux->n_dbs, remote,
+              : parse_db_column(aux->all_dbs, remote,
                                 &db, &table, &column));
     if (!retval) {
-        sset_add(aux->remotes, remote);
+        if (sset_add(aux->remotes, remote)) {
+            save_config(aux->config_tmpfile, aux->remotes);
+        }
         unixctl_command_reply(conn, NULL);
     } else {
         unixctl_command_reply_error(conn, retval);
@@ -931,14 +975,15 @@ ovsdb_server_add_remote(struct unixctl_conn *conn, int argc OVS_UNUSED,
  * that ovsdb-server services. */
 static void
 ovsdb_server_remove_remote(struct unixctl_conn *conn, int argc OVS_UNUSED,
-                           const char *argv[], void *remotes_)
+                           const char *argv[], void *aux_)
 {
-    struct sset *remotes = remotes_;
+    struct remove_remote_aux *aux = aux_;
     struct sset_node *node;
 
-    node = sset_find(remotes, argv[1]);
+    node = sset_find(aux->remotes, argv[1]);
     if (node) {
-        sset_delete(remotes, node);
+        sset_delete(aux->remotes, node);
+        save_config(aux->config_tmpfile, aux->remotes);
         unixctl_command_reply(conn, NULL);
     } else {
         unixctl_command_reply_error(conn, "no such remote");
@@ -977,10 +1022,9 @@ parse_options(int *argcp, char **argvp[],
         OPT_BOOTSTRAP_CA_CERT,
         OPT_ENABLE_DUMMY,
         VLOG_OPTION_ENUMS,
-        LEAK_CHECKER_OPTION_ENUMS,
         DAEMON_OPTION_ENUMS
     };
-    static struct option long_options[] = {
+    static const struct option long_options[] = {
         {"remote",      required_argument, NULL, OPT_REMOTE},
         {"unixctl",     required_argument, NULL, OPT_UNIXCTL},
         {"run",         required_argument, NULL, OPT_RUN},
@@ -988,7 +1032,6 @@ parse_options(int *argcp, char **argvp[],
         {"version",     no_argument, NULL, 'V'},
         DAEMON_LONG_OPTIONS,
         VLOG_LONG_OPTIONS,
-        LEAK_CHECKER_LONG_OPTIONS,
         {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
         {"private-key", required_argument, NULL, 'p'},
         {"certificate", required_argument, NULL, 'c'},
@@ -1031,7 +1074,6 @@ parse_options(int *argcp, char **argvp[],
 
         VLOG_OPTION_HANDLERS
         DAEMON_OPTION_HANDLERS
-        LEAK_CHECKER_OPTION_HANDLERS
 
         case 'p':
             private_key_file = optarg;
@@ -1086,6 +1128,58 @@ usage(void)
            "  --unixctl=SOCKET        override default control socket name\n"
            "  -h, --help              display this help message\n"
            "  -V, --version           display version information\n");
-    leak_checker_usage();
     exit(EXIT_SUCCESS);
 }
+\f
+/* Truncates and replaces the contents of 'config_file' by a representation
+ * of 'remotes'. */
+static void
+save_config(FILE *config_file, const struct sset *remotes)
+{
+    const char *remote;
+    struct json *json;
+    char *s;
+
+    if (ftruncate(fileno(config_file), 0) == -1) {
+        VLOG_FATAL("failed to truncate temporary file (%s)", strerror(errno));
+    }
+
+    json = json_array_create_empty();
+    SSET_FOR_EACH (remote, remotes) {
+        json_array_add(json, json_string_create(remote));
+    }
+    s = json_to_string(json, 0);
+    json_destroy(json);
+
+    if (fseek(config_file, 0, SEEK_SET) != 0
+        || fputs(s, config_file) == EOF
+        || fflush(config_file) == EOF) {
+        VLOG_FATAL("failed to write temporary file (%s)", strerror(errno));
+    }
+    free(s);
+}
+
+/* Clears and replaces 'remotes' by a configuration read from 'config_file',
+ * which must have been previously written by save_config(). */
+static void
+load_config(FILE *config_file, struct sset *remotes)
+{
+    struct json *json;
+    size_t i;
+
+    sset_clear(remotes);
+
+    if (fseek(config_file, 0, SEEK_SET) != 0) {
+        VLOG_FATAL("seek failed in temporary file (%s)", strerror(errno));
+    }
+    json = json_from_stream(config_file);
+    if (json->type == JSON_STRING) {
+        VLOG_FATAL("reading json failed (%s)", json_string(json));
+    }
+    ovs_assert(json->type == JSON_ARRAY);
+    for (i = 0; i < json->u.array.n; i++) {
+        const struct json *remote = json->u.array.elems[i];
+        sset_add(remotes, json_string(remote));
+    }
+    json_destroy(json);
+}