ovsdb: Raise the jsonrpc server session limit
[cascardo/ovs.git] / ovsdb / ovsdb-server.c
index a85a672..d5277b1 100644 (file)
@@ -26,7 +26,6 @@
 #include "command-line.h"
 #include "daemon.h"
 #include "dirs.h"
-#include "dummy.h"
 #include "dynamic-string.h"
 #include "fatal-signal.h"
 #include "file.h"
@@ -54,7 +53,7 @@
 #include "trigger.h"
 #include "util.h"
 #include "unixctl.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
 
 VLOG_DEFINE_THIS_MODULE(ovsdb_server);
 
@@ -93,11 +92,12 @@ static unixctl_cb_func ovsdb_server_remove_database;
 static unixctl_cb_func ovsdb_server_list_databases;
 
 static char *open_db(struct server_config *config, const char *filename);
+static void close_db(struct db *db);
 
 static void parse_options(int *argc, char **argvp[],
                           struct sset *remotes, char **unixctl_pathp,
                           char **run_command);
-static void usage(void) NO_RETURN;
+OVS_NO_RETURN static void usage(void);
 
 static char *reconfigure_remotes(struct ovsdb_jsonrpc_server *,
                                  const struct shash *all_dbs,
@@ -115,6 +115,83 @@ static void save_config(struct server_config *);
 static void load_config(FILE *config_file, struct sset *remotes,
                         struct sset *db_filenames);
 
+static void
+main_loop(struct ovsdb_jsonrpc_server *jsonrpc, struct shash *all_dbs,
+          struct unixctl_server *unixctl, struct sset *remotes,
+          struct process *run_process, bool *exiting)
+{
+    char *remotes_error, *ssl_error;
+    struct shash_node *node;
+    long long int status_timer = LLONG_MIN;
+
+    *exiting = false;
+    ssl_error = NULL;
+    remotes_error = NULL;
+    while (!*exiting) {
+        memory_run();
+        if (memory_should_report()) {
+            struct simap usage;
+
+            simap_init(&usage);
+            ovsdb_jsonrpc_server_get_memory_usage(jsonrpc, &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);
+        }
+
+        /* Run unixctl_server_run() before reconfigure_remotes() because
+         * ovsdb-server/add-remote and ovsdb-server/remove-remote can change
+         * the set of remotes that reconfigure_remotes() uses. */
+        unixctl_server_run(unixctl);
+
+        report_error_if_changed(
+            reconfigure_remotes(jsonrpc, all_dbs, remotes),
+            &remotes_error);
+        report_error_if_changed(reconfigure_ssl(all_dbs), &ssl_error);
+        ovsdb_jsonrpc_server_run(jsonrpc);
+
+        SHASH_FOR_EACH(node, all_dbs) {
+            struct db *db = node->data;
+            ovsdb_trigger_run(db->db, time_msec());
+        }
+        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, all_dbs);
+        }
+
+        memory_wait();
+        ovsdb_jsonrpc_server_wait(jsonrpc);
+        unixctl_server_wait(unixctl);
+        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);
+        }
+        if (*exiting) {
+            poll_immediate_wake();
+        }
+        poll_timer_wait_until(status_timer);
+        poll_block();
+        if (should_service_stop()) {
+            *exiting = true;
+        }
+    }
+
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -127,12 +204,10 @@ main(int argc, char *argv[])
     struct process *run_process;
     bool exiting;
     int retval;
-    long long int status_timer = LLONG_MIN;
     FILE *config_tmpfile;
     struct server_config server_config;
     struct shash all_dbs;
-    struct shash_node *node;
-    char *remotes_error, *ssl_error;
+    struct shash_node *node, *next;
     char *error;
     int i;
 
@@ -244,77 +319,16 @@ main(int argc, char *argv[])
     unixctl_command_register("ovsdb-server/list-dbs", "", 0, 0,
                              ovsdb_server_list_databases, &all_dbs);
 
-    exiting = false;
-    ssl_error = NULL;
-    remotes_error = NULL;
-    while (!exiting) {
-        memory_run();
-        if (memory_should_report()) {
-            struct simap usage;
-
-            simap_init(&usage);
-            ovsdb_jsonrpc_server_get_memory_usage(jsonrpc, &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);
-        }
-
-        /* Run unixctl_server_run() before reconfigure_remotes() because
-         * ovsdb-server/add-remote and ovsdb-server/remove-remote can change
-         * the set of remotes that reconfigure_remotes() uses. */
-        unixctl_server_run(unixctl);
+    main_loop(jsonrpc, &all_dbs, unixctl, &remotes, run_process, &exiting);
 
-        report_error_if_changed(
-            reconfigure_remotes(jsonrpc, &all_dbs, &remotes),
-            &remotes_error);
-        report_error_if_changed(reconfigure_ssl(&all_dbs), &ssl_error);
-        ovsdb_jsonrpc_server_run(jsonrpc);
-
-        SHASH_FOR_EACH(node, &all_dbs) {
-            struct db *db = node->data;
-            ovsdb_trigger_run(db->db, time_msec());
-        }
-        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, &all_dbs);
-        }
-
-        memory_wait();
-        ovsdb_jsonrpc_server_wait(jsonrpc);
-        unixctl_server_wait(unixctl);
-        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);
-        }
-        if (exiting) {
-            poll_immediate_wake();
-        }
-        poll_timer_wait_until(status_timer);
-        poll_block();
-        if (should_service_stop()) {
-            exiting = true;
-        }
-    }
     ovsdb_jsonrpc_server_destroy(jsonrpc);
-    SHASH_FOR_EACH(node, &all_dbs) {
+    SHASH_FOR_EACH_SAFE(node, next, &all_dbs) {
         struct db *db = node->data;
-        ovsdb_destroy(db->db);
+        close_db(db);
+        shash_delete(&all_dbs, node);
     }
     sset_destroy(&remotes);
+    sset_destroy(&db_filenames);
     unixctl_server_destroy(unixctl);
 
     if (run_process && process_exited(run_process)) {
@@ -359,6 +373,14 @@ is_already_open(struct server_config *config OVS_UNUSED,
     return false;
 }
 
+static void
+close_db(struct db *db)
+{
+    ovsdb_destroy(db->db);
+    free(db->filename);
+    free(db);
+}
+
 static char *
 open_db(struct server_config *config, const char *filename)
 {
@@ -387,9 +409,7 @@ open_db(struct server_config *config, const char *filename)
     }
 
     ovsdb_error_destroy(db_error);
-    ovsdb_destroy(db->db);
-    free(db->filename);
-    free(db);
+    close_db(db);
     return error;
 }
 
@@ -408,7 +428,7 @@ find_db(const struct shash *all_dbs, const char *db_name)
     return NULL;
 }
 
-static char * WARN_UNUSED_RESULT
+static char * OVS_WARN_UNUSED_RESULT
 parse_db_column__(const struct shash *all_dbs,
                   const char *name_, char *name,
                   const struct db **dbp,
@@ -462,7 +482,7 @@ parse_db_column__(const struct shash *all_dbs,
 
 /* Returns NULL if successful, otherwise a malloc()'d string describing the
  * error. */
-static char * WARN_UNUSED_RESULT
+static char * OVS_WARN_UNUSED_RESULT
 parse_db_column(const struct shash *all_dbs,
                 const char *name_,
                 const struct db **dbp,
@@ -478,7 +498,7 @@ parse_db_column(const struct shash *all_dbs,
 
 /* Returns NULL if successful, otherwise a malloc()'d string describing the
  * error. */
-static char * WARN_UNUSED_RESULT
+static char * OVS_WARN_UNUSED_RESULT
 parse_db_string_column(const struct shash *all_dbs,
                        const char *name,
                        const struct db **dbp,
@@ -519,6 +539,7 @@ query_db_string(const struct shash *all_dbs, const char *name,
                                         &db, &table, &column);
         if (retval) {
             ds_put_format(errors, "%s\n", retval);
+            free(retval);
             return NULL;
         }
 
@@ -1164,10 +1185,8 @@ ovsdb_server_remove_database(struct unixctl_conn *conn, int argc OVS_UNUSED,
     ok = ovsdb_jsonrpc_server_remove_db(config->jsonrpc, db->db);
     ovs_assert(ok);
 
-    ovsdb_destroy(db->db);
+    close_db(db);
     shash_delete(config->all_dbs, node);
-    free(db->filename);
-    free(db);
 
     save_config(config);
     unixctl_command_reply(conn, NULL);
@@ -1204,7 +1223,6 @@ parse_options(int *argcp, char **argvp[],
         OPT_UNIXCTL,
         OPT_RUN,
         OPT_BOOTSTRAP_CA_CERT,
-        OPT_ENABLE_DUMMY,
         VLOG_OPTION_ENUMS,
         DAEMON_OPTION_ENUMS
     };
@@ -1222,7 +1240,6 @@ parse_options(int *argcp, char **argvp[],
         {"private-key", required_argument, NULL, 'p'},
         {"certificate", required_argument, NULL, 'c'},
         {"ca-cert",     required_argument, NULL, 'C'},
-        {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY},
         {NULL, 0, NULL, 0},
     };
     char *short_options = long_options_to_short_options(long_options);
@@ -1279,10 +1296,6 @@ parse_options(int *argcp, char **argvp[],
             bootstrap_ca_cert = true;
             break;
 
-        case OPT_ENABLE_DUMMY:
-            dummy_enable(optarg && !strcmp(optarg, "override"));
-            break;
-
         case '?':
             exit(EXIT_FAILURE);