ovsdb: Report the number of connections for inbound Managers.
[sliver-openvswitch.git] / ovsdb / ovsdb-server.c
1 /* Copyright (c) 2009, 2010, 2011 Nicira Networks
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <config.h>
17
18 #include "ovsdb.h"
19
20 #include <errno.h>
21 #include <getopt.h>
22 #include <signal.h>
23 #include <unistd.h>
24
25 #include "column.h"
26 #include "command-line.h"
27 #include "daemon.h"
28 #include "dirs.h"
29 #include "file.h"
30 #include "json.h"
31 #include "jsonrpc.h"
32 #include "jsonrpc-server.h"
33 #include "leak-checker.h"
34 #include "list.h"
35 #include "ovsdb-data.h"
36 #include "ovsdb-types.h"
37 #include "ovsdb-error.h"
38 #include "poll-loop.h"
39 #include "process.h"
40 #include "row.h"
41 #include "stream-ssl.h"
42 #include "stream.h"
43 #include "stress.h"
44 #include "sset.h"
45 #include "table.h"
46 #include "timeval.h"
47 #include "transaction.h"
48 #include "trigger.h"
49 #include "util.h"
50 #include "unixctl.h"
51 #include "vlog.h"
52
53 VLOG_DEFINE_THIS_MODULE(ovsdb_server);
54
55 /* SSL configuration. */
56 static char *private_key_file;
57 static char *certificate_file;
58 static char *ca_cert_file;
59 static bool bootstrap_ca_cert;
60
61 static unixctl_cb_func ovsdb_server_exit;
62 static unixctl_cb_func ovsdb_server_compact;
63 static unixctl_cb_func ovsdb_server_reconnect;
64
65 static void parse_options(int argc, char *argv[], char **file_namep,
66                           struct sset *remotes, char **unixctl_pathp,
67                           char **run_command);
68 static void usage(void) NO_RETURN;
69
70 static void reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
71                                 const struct ovsdb *db, struct sset *remotes);
72
73 static void update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
74                                  const struct sset *remotes,
75                                  struct ovsdb *db);
76
77 int
78 main(int argc, char *argv[])
79 {
80     char *unixctl_path = NULL;
81     char *run_command = NULL;
82     struct unixctl_server *unixctl;
83     struct ovsdb_jsonrpc_server *jsonrpc;
84     struct sset remotes;
85     struct ovsdb_error *error;
86     struct ovsdb_file *file;
87     struct ovsdb *db;
88     struct process *run_process;
89     char *file_name;
90     bool exiting;
91     int retval;
92     long long int status_timer = LLONG_MIN;
93
94     proctitle_init(argc, argv);
95     set_program_name(argv[0]);
96     stress_init_command();
97     signal(SIGPIPE, SIG_IGN);
98     process_init();
99
100     parse_options(argc, argv, &file_name, &remotes, &unixctl_path,
101                   &run_command);
102
103     daemonize_start();
104
105     error = ovsdb_file_open(file_name, false, &db, &file);
106     if (error) {
107         ovs_fatal(0, "%s", ovsdb_error_to_string(error));
108     }
109     free(file_name);
110
111     jsonrpc = ovsdb_jsonrpc_server_create(db);
112     reconfigure_from_db(jsonrpc, db, &remotes);
113
114     retval = unixctl_server_create(unixctl_path, &unixctl);
115     if (retval) {
116         exit(EXIT_FAILURE);
117     }
118
119     if (run_command) {
120         char *run_argv[4];
121
122         run_argv[0] = "/bin/sh";
123         run_argv[1] = "-c";
124         run_argv[2] = run_command;
125         run_argv[3] = NULL;
126
127         retval = process_start(run_argv, NULL, 0, NULL, 0, &run_process);
128         if (retval) {
129             ovs_fatal(retval, "%s: process failed to start", run_command);
130         }
131     } else {
132         run_process = NULL;
133     }
134
135     daemonize_complete();
136
137     unixctl_command_register("exit", ovsdb_server_exit, &exiting);
138     unixctl_command_register("ovsdb-server/compact", ovsdb_server_compact,
139                              file);
140     unixctl_command_register("ovsdb-server/reconnect", ovsdb_server_reconnect,
141                              jsonrpc);
142
143     exiting = false;
144     while (!exiting) {
145         reconfigure_from_db(jsonrpc, db, &remotes);
146         ovsdb_jsonrpc_server_run(jsonrpc);
147         unixctl_server_run(unixctl);
148         ovsdb_trigger_run(db, time_msec());
149         if (run_process && process_exited(run_process)) {
150             exiting = true;
151         }
152
153         /* update Manager status(es) every 5 seconds */
154         if (time_msec() >= status_timer) {
155             status_timer = time_msec() + 5000;
156             update_remote_status(jsonrpc, &remotes, db);
157         }
158
159         ovsdb_jsonrpc_server_wait(jsonrpc);
160         unixctl_server_wait(unixctl);
161         ovsdb_trigger_wait(db, time_msec());
162         if (run_process) {
163             process_wait(run_process);
164         }
165         if (exiting) {
166             poll_immediate_wake();
167         }
168         poll_timer_wait_until(status_timer);
169         poll_block();
170     }
171     ovsdb_jsonrpc_server_destroy(jsonrpc);
172     ovsdb_destroy(db);
173     sset_destroy(&remotes);
174     unixctl_server_destroy(unixctl);
175
176     if (run_process && process_exited(run_process)) {
177         int status = process_status(run_process);
178         if (status) {
179             ovs_fatal(0, "%s: child exited, %s",
180                       run_command, process_status_msg(status));
181         }
182     }
183
184     return 0;
185 }
186
187 static void
188 parse_db_column(const struct ovsdb *db,
189                 const char *name_,
190                 const struct ovsdb_table **tablep,
191                 const struct ovsdb_column **columnp)
192 {
193     char *name, *table_name, *column_name;
194     const struct ovsdb_column *column;
195     const struct ovsdb_table *table;
196     char *save_ptr = NULL;
197
198     name = xstrdup(name_);
199     strtok_r(name, ":", &save_ptr); /* "db:" */
200     table_name = strtok_r(NULL, ",", &save_ptr);
201     column_name = strtok_r(NULL, ",", &save_ptr);
202     if (!table_name || !column_name) {
203         ovs_fatal(0, "\"%s\": invalid syntax", name_);
204     }
205
206     table = ovsdb_get_table(db, table_name);
207     if (!table) {
208         ovs_fatal(0, "\"%s\": no table named %s", name_, table_name);
209     }
210
211     column = ovsdb_table_schema_get_column(table->schema, column_name);
212     if (!column) {
213         ovs_fatal(0, "\"%s\": table \"%s\" has no column \"%s\"",
214                   name_, table_name, column_name);
215     }
216     free(name);
217
218     *columnp = column;
219     *tablep = table;
220 }
221
222 static void
223 parse_db_string_column(const struct ovsdb *db,
224                        const char *name,
225                        const struct ovsdb_table **tablep,
226                        const struct ovsdb_column **columnp)
227 {
228     const struct ovsdb_column *column;
229     const struct ovsdb_table *table;
230
231     parse_db_column(db, name, &table, &column);
232
233     if (column->type.key.type != OVSDB_TYPE_STRING
234         || column->type.value.type != OVSDB_TYPE_VOID) {
235         ovs_fatal(0, "\"%s\": table \"%s\" column \"%s\" is "
236                   "not string or set of strings",
237                   name, table->schema->name, column->name);
238     }
239
240     *columnp = column;
241     *tablep = table;
242 }
243
244 static OVS_UNUSED const char *
245 query_db_string(const struct ovsdb *db, const char *name)
246 {
247     if (!name || strncmp(name, "db:", 3)) {
248         return name;
249     } else {
250         const struct ovsdb_column *column;
251         const struct ovsdb_table *table;
252         const struct ovsdb_row *row;
253
254         parse_db_string_column(db, name, &table, &column);
255
256         HMAP_FOR_EACH (row, hmap_node, &table->rows) {
257             const struct ovsdb_datum *datum;
258             size_t i;
259
260             datum = &row->fields[column->index];
261             for (i = 0; i < datum->n; i++) {
262                 if (datum->keys[i].string[0]) {
263                     return datum->keys[i].string;
264                 }
265             }
266         }
267         return NULL;
268     }
269 }
270
271 static struct ovsdb_jsonrpc_options *
272 add_remote(struct shash *remotes, const char *target)
273 {
274     struct ovsdb_jsonrpc_options *options;
275
276     options = shash_find_data(remotes, target);
277     if (!options) {
278         options = ovsdb_jsonrpc_default_options();
279         shash_add(remotes, target, options);
280     }
281
282     return options;
283 }
284
285 static struct ovsdb_datum *
286 get_datum(struct ovsdb_row *row, const char *column_name,
287           const enum ovsdb_atomic_type key_type,
288           const enum ovsdb_atomic_type value_type,
289           const size_t n_max)
290 {
291     static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
292     const struct ovsdb_table_schema *schema = row->table->schema;
293     const struct ovsdb_column *column;
294
295     column = ovsdb_table_schema_get_column(schema, column_name);
296     if (!column) {
297         VLOG_DBG_RL(&rl, "Table `%s' has no `%s' column",
298                     schema->name, column_name);
299         return NULL;
300     }
301
302     if (column->type.key.type != key_type
303         || column->type.value.type != value_type
304         || column->type.n_max != n_max) {
305         if (!VLOG_DROP_DBG(&rl)) {
306             char *type_name = ovsdb_type_to_english(&column->type);
307             VLOG_DBG("Table `%s' column `%s' has type %s, not expected "
308                      "key type %s, value type %s, max elements %zd.",
309                      schema->name, column_name, type_name,
310                      ovsdb_atomic_type_to_string(key_type),
311                      ovsdb_atomic_type_to_string(value_type),
312                      n_max);
313             free(type_name);
314         }
315         return NULL;
316     }
317
318     return &row->fields[column->index];
319 }
320
321 static const union ovsdb_atom *
322 read_column(const struct ovsdb_row *row, const char *column_name,
323             enum ovsdb_atomic_type type)
324 {
325     const struct ovsdb_datum *datum;
326
327     datum = get_datum((struct ovsdb_row *) row, column_name, type, OVSDB_TYPE_VOID, 1);
328     return datum && datum->n ? datum->keys : NULL;
329 }
330
331 static bool
332 read_integer_column(const struct ovsdb_row *row, const char *column_name,
333                     long long int *integerp)
334 {
335     const union ovsdb_atom *atom;
336
337     atom = read_column(row, column_name, OVSDB_TYPE_INTEGER);
338     *integerp = atom ? atom->integer : 0;
339     return atom != NULL;
340 }
341
342 static bool
343 read_string_column(const struct ovsdb_row *row, const char *column_name,
344                    const char **stringp)
345 {
346     const union ovsdb_atom *atom;
347
348     atom = read_column(row, column_name, OVSDB_TYPE_STRING);
349     *stringp = atom ? atom->string : NULL;
350     return atom != NULL;
351 }
352
353 static void
354 write_bool_column(struct ovsdb_row *row, const char *column_name, bool value)
355 {
356     struct ovsdb_datum *datum = get_datum(row, column_name, OVSDB_TYPE_BOOLEAN,
357                                           OVSDB_TYPE_VOID, 1);
358
359     if (!datum) {
360         return;
361     }
362     datum->keys[0].boolean = value;
363 }
364
365 static void
366 write_string_string_column(struct ovsdb_row *row, const char *column_name,
367                            char **keys, char **values, size_t n)
368 {
369     const struct ovsdb_column *column;
370     struct ovsdb_datum *datum;
371     size_t i;
372
373     column = ovsdb_table_schema_get_column(row->table->schema, column_name);
374     datum = get_datum(row, column_name, OVSDB_TYPE_STRING, OVSDB_TYPE_STRING,
375                       UINT_MAX);
376     if (!datum) {
377         return;
378     }
379
380     /* Free existing data. */
381     ovsdb_datum_destroy(datum, &column->type);
382
383     /* Allocate space for new values. */
384     datum->n = n;
385     datum->keys = xmalloc(n * sizeof *datum->keys);
386     datum->values = xmalloc(n * sizeof *datum->values);
387
388     for (i = 0; i < n; ++i) {
389         datum->keys[i].string = keys[i];
390         datum->values[i].string = values[i];
391     }
392
393     /* Sort and check constraints. */
394     ovsdb_datum_sort_assert(datum, column->type.key.type);
395 }
396
397 /* Adds a remote and options to 'remotes', based on the Manager table row in
398  * 'row'. */
399 static void
400 add_manager_options(struct shash *remotes, const struct ovsdb_row *row)
401 {
402     static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
403     struct ovsdb_jsonrpc_options *options;
404     long long int max_backoff, probe_interval;
405     const char *target;
406
407     if (!read_string_column(row, "target", &target) || !target) {
408         VLOG_INFO_RL(&rl, "Table `%s' has missing or invalid `target' column",
409                      row->table->schema->name);
410         return;
411     }
412
413     options = add_remote(remotes, target);
414     if (read_integer_column(row, "max_backoff", &max_backoff)) {
415         options->max_backoff = max_backoff;
416     }
417     if (read_integer_column(row, "inactivity_probe", &probe_interval)) {
418         options->probe_interval = probe_interval;
419     }
420 }
421
422 static void
423 query_db_remotes(const char *name, const struct ovsdb *db,
424                  struct shash *remotes)
425 {
426     const struct ovsdb_column *column;
427     const struct ovsdb_table *table;
428     const struct ovsdb_row *row;
429
430     parse_db_column(db, name, &table, &column);
431
432     if (column->type.key.type == OVSDB_TYPE_STRING
433         && column->type.value.type == OVSDB_TYPE_VOID) {
434         HMAP_FOR_EACH (row, hmap_node, &table->rows) {
435             const struct ovsdb_datum *datum;
436             size_t i;
437
438             datum = &row->fields[column->index];
439             for (i = 0; i < datum->n; i++) {
440                 add_remote(remotes, datum->keys[i].string);
441             }
442         }
443     } else if (column->type.key.type == OVSDB_TYPE_UUID
444                && column->type.key.u.uuid.refTable
445                && column->type.value.type == OVSDB_TYPE_VOID) {
446         const struct ovsdb_table *ref_table = column->type.key.u.uuid.refTable;
447         HMAP_FOR_EACH (row, hmap_node, &table->rows) {
448             const struct ovsdb_datum *datum;
449             size_t i;
450
451             datum = &row->fields[column->index];
452             for (i = 0; i < datum->n; i++) {
453                 const struct ovsdb_row *ref_row;
454
455                 ref_row = ovsdb_table_get_row(ref_table, &datum->keys[i].uuid);
456                 if (ref_row) {
457                     add_manager_options(remotes, ref_row);
458                 }
459             }
460         }
461     }
462 }
463
464 static void
465 update_remote_row(const struct ovsdb_row *row, struct ovsdb_txn *txn,
466                   const struct ovsdb_jsonrpc_server *jsonrpc)
467 {
468     struct ovsdb_jsonrpc_remote_status status;
469     struct ovsdb_row *rw_row;
470     const char *target;
471     char *keys[8], *values[8];
472     size_t n = 0;
473
474     /* Get the "target" (protocol/host/port) spec. */
475     if (!read_string_column(row, "target", &target)) {
476         /* Bad remote spec or incorrect schema. */
477         return;
478     }
479     rw_row = ovsdb_txn_row_modify(txn, row);
480     ovsdb_jsonrpc_server_get_remote_status(jsonrpc, target, &status);
481
482     /* Update status information columns. */
483     write_bool_column(rw_row, "is_connected", status.is_connected);
484
485     if (status.state) {
486         keys[n] = xstrdup("state");
487         values[n++] = xstrdup(status.state);
488     }
489     if (status.sec_since_connect != UINT_MAX) {
490         keys[n] = xstrdup("sec_since_connect");
491         values[n++] = xasprintf("%u", status.sec_since_connect);
492     }
493     if (status.sec_since_disconnect != UINT_MAX) {
494         keys[n] = xstrdup("sec_since_disconnect");
495         values[n++] = xasprintf("%u", status.sec_since_disconnect);
496     }
497     if (status.last_error) {
498         keys[n] = xstrdup("last_error");
499         values[n++] =
500             xstrdup(ovs_retval_to_string(status.last_error));
501     }
502     if (status.n_connections > 1) {
503         keys[n] = xstrdup("n_connections");
504         values[n++] = xasprintf("%d", status.n_connections);
505     }
506     write_string_string_column(rw_row, "status", keys, values, n);
507 }
508
509 static void
510 update_remote_rows(const struct ovsdb *db, struct ovsdb_txn *txn,
511                    const char *remote_name,
512                    const struct ovsdb_jsonrpc_server *jsonrpc)
513 {
514     const struct ovsdb_table *table, *ref_table;
515     const struct ovsdb_column *column;
516     const struct ovsdb_row *row;
517
518     if (strncmp("db:", remote_name, 3)) {
519         return;
520     }
521
522     parse_db_column(db, remote_name, &table, &column);
523
524     if (column->type.key.type != OVSDB_TYPE_UUID
525         || !column->type.key.u.uuid.refTable
526         || column->type.value.type != OVSDB_TYPE_VOID) {
527         return;
528     }
529
530     ref_table = column->type.key.u.uuid.refTable;
531
532     HMAP_FOR_EACH (row, hmap_node, &table->rows) {
533         const struct ovsdb_datum *datum;
534         size_t i;
535
536         datum = &row->fields[column->index];
537         for (i = 0; i < datum->n; i++) {
538             const struct ovsdb_row *ref_row;
539
540             ref_row = ovsdb_table_get_row(ref_table, &datum->keys[i].uuid);
541             if (ref_row) {
542                 update_remote_row(ref_row, txn, jsonrpc);
543             }
544         }
545     }
546 }
547
548 static void
549 update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
550                      const struct sset *remotes, struct ovsdb *db)
551 {
552     static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
553     struct ovsdb_txn *txn;
554     const bool durable_txn = false;
555     struct ovsdb_error *error;
556     const char *remote;
557
558     txn = ovsdb_txn_create(db);
559
560     /* Iterate over --remote arguments given on command line. */
561     SSET_FOR_EACH (remote, remotes) {
562         update_remote_rows(db, txn, remote, jsonrpc);
563     }
564
565     error = ovsdb_txn_commit(txn, durable_txn);
566     if (error) {
567         VLOG_ERR_RL(&rl, "Failed to update remote status: %s",
568                     ovsdb_error_to_string(error));
569     }
570 }
571
572 /* Reconfigures ovsdb-server based on information in the database. */
573 static void
574 reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
575                     const struct ovsdb *db, struct sset *remotes)
576 {
577     struct shash resolved_remotes;
578     const char *name;
579
580     /* Configure remotes. */
581     shash_init(&resolved_remotes);
582     SSET_FOR_EACH (name, remotes) {
583         if (!strncmp(name, "db:", 3)) {
584             query_db_remotes(name, db, &resolved_remotes);
585         } else {
586             add_remote(&resolved_remotes, name);
587         }
588     }
589     ovsdb_jsonrpc_server_set_remotes(jsonrpc, &resolved_remotes);
590     shash_destroy_free_data(&resolved_remotes);
591
592     /* Configure SSL. */
593     stream_ssl_set_key_and_cert(query_db_string(db, private_key_file),
594                                 query_db_string(db, certificate_file));
595     stream_ssl_set_ca_cert_file(query_db_string(db, ca_cert_file),
596                                 bootstrap_ca_cert);
597 }
598
599 static void
600 ovsdb_server_exit(struct unixctl_conn *conn, const char *args OVS_UNUSED,
601                   void *exiting_)
602 {
603     bool *exiting = exiting_;
604     *exiting = true;
605     unixctl_command_reply(conn, 200, NULL);
606 }
607
608 static void
609 ovsdb_server_compact(struct unixctl_conn *conn, const char *args OVS_UNUSED,
610                      void *file_)
611 {
612     struct ovsdb_file *file = file_;
613     struct ovsdb_error *error;
614
615     VLOG_INFO("compacting database by user request");
616     error = ovsdb_file_compact(file);
617     if (!error) {
618         unixctl_command_reply(conn, 200, NULL);
619     } else {
620         char *s = ovsdb_error_to_string(error);
621         ovsdb_error_destroy(error);
622         unixctl_command_reply(conn, 503, s);
623         free(s);
624     }
625 }
626
627 /* "ovsdb-server/reconnect": makes ovsdb-server drop all of its JSON-RPC
628  * connections and reconnect. */
629 static void
630 ovsdb_server_reconnect(struct unixctl_conn *conn, const char *args OVS_UNUSED,
631                        void *jsonrpc_)
632 {
633     struct ovsdb_jsonrpc_server *jsonrpc = jsonrpc_;
634
635     ovsdb_jsonrpc_server_reconnect(jsonrpc);
636     unixctl_command_reply(conn, 200, NULL);
637 }
638
639 static void
640 parse_options(int argc, char *argv[], char **file_namep,
641               struct sset *remotes, char **unixctl_pathp,
642               char **run_command)
643 {
644     enum {
645         OPT_DUMMY = UCHAR_MAX + 1,
646         OPT_REMOTE,
647         OPT_UNIXCTL,
648         OPT_RUN,
649         OPT_BOOTSTRAP_CA_CERT,
650         VLOG_OPTION_ENUMS,
651         LEAK_CHECKER_OPTION_ENUMS,
652         DAEMON_OPTION_ENUMS
653     };
654     static struct option long_options[] = {
655         {"remote",      required_argument, NULL, OPT_REMOTE},
656         {"unixctl",     required_argument, NULL, OPT_UNIXCTL},
657         {"run",         required_argument, NULL, OPT_RUN},
658         {"help",        no_argument, NULL, 'h'},
659         {"version",     no_argument, NULL, 'V'},
660         DAEMON_LONG_OPTIONS,
661         VLOG_LONG_OPTIONS,
662         LEAK_CHECKER_LONG_OPTIONS,
663         {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
664         {"private-key", required_argument, NULL, 'p'},
665         {"certificate", required_argument, NULL, 'c'},
666         {"ca-cert",     required_argument, NULL, 'C'},
667         {NULL, 0, NULL, 0},
668     };
669     char *short_options = long_options_to_short_options(long_options);
670
671     sset_init(remotes);
672     for (;;) {
673         int c;
674
675         c = getopt_long(argc, argv, short_options, long_options, NULL);
676         if (c == -1) {
677             break;
678         }
679
680         switch (c) {
681         case OPT_REMOTE:
682             sset_add(remotes, optarg);
683             break;
684
685         case OPT_UNIXCTL:
686             *unixctl_pathp = optarg;
687             break;
688
689         case OPT_RUN:
690             *run_command = optarg;
691             break;
692
693         case 'h':
694             usage();
695
696         case 'V':
697             OVS_PRINT_VERSION(0, 0);
698             exit(EXIT_SUCCESS);
699
700         VLOG_OPTION_HANDLERS
701         DAEMON_OPTION_HANDLERS
702         LEAK_CHECKER_OPTION_HANDLERS
703
704         case 'p':
705             private_key_file = optarg;
706             break;
707
708         case 'c':
709             certificate_file = optarg;
710             break;
711
712         case 'C':
713             ca_cert_file = optarg;
714             bootstrap_ca_cert = false;
715             break;
716
717         case OPT_BOOTSTRAP_CA_CERT:
718             ca_cert_file = optarg;
719             bootstrap_ca_cert = true;
720             break;
721
722         case '?':
723             exit(EXIT_FAILURE);
724
725         default:
726             abort();
727         }
728     }
729     free(short_options);
730
731     argc -= optind;
732     argv += optind;
733
734     switch (argc) {
735     case 0:
736         *file_namep = xasprintf("%s/openvswitch/conf.db", ovs_sysconfdir());
737         break;
738
739     case 1:
740         *file_namep = xstrdup(argv[0]);
741         break;
742
743     default:
744         ovs_fatal(0, "database file is only non-option argument; "
745                 "use --help for usage");
746     }
747 }
748
749 static void
750 usage(void)
751 {
752     printf("%s: Open vSwitch database server\n"
753            "usage: %s [OPTIONS] DATABASE\n"
754            "where DATABASE is a database file in ovsdb format.\n",
755            program_name, program_name);
756     printf("\nJSON-RPC options (may be specified any number of times):\n"
757            "  --remote=REMOTE         connect or listen to REMOTE\n");
758     stream_usage("JSON-RPC", true, true, true);
759     daemon_usage();
760     vlog_usage();
761     printf("\nOther options:\n"
762            "  --run COMMAND           run COMMAND as subprocess then exit\n"
763            "  --unixctl=SOCKET        override default control socket name\n"
764            "  -h, --help              display this help message\n"
765            "  -V, --version           display version information\n");
766     leak_checker_usage();
767     exit(EXIT_SUCCESS);
768 }