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