]> git.proxmox.com Git - ovs.git/blame - vswitchd/ovs-vswitchd.c
bridge: Fix remote_opstate bug recently introduced.
[ovs.git] / vswitchd / ovs-vswitchd.c
CommitLineData
e0edde6f 1/* Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
064af421 2 *
a14bc59f
BP
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:
064af421 6 *
a14bc59f 7 * http://www.apache.org/licenses/LICENSE-2.0
064af421 8 *
a14bc59f
BP
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.
064af421
BP
14 */
15
16#include <config.h>
17
064af421
BP
18#include <errno.h>
19#include <getopt.h>
20#include <limits.h>
21#include <signal.h>
22#include <stdlib.h>
23#include <string.h>
86a06318
BP
24#ifdef HAVE_MLOCKALL
25#include <sys/mman.h>
26#endif
064af421
BP
27
28#include "bridge.h"
064af421
BP
29#include "command-line.h"
30#include "compiler.h"
31#include "daemon.h"
80df177a 32#include "dirs.h"
579a77e0 33#include "dpif.h"
614c4892 34#include "dummy.h"
064af421 35#include "leak-checker.h"
0d085684 36#include "memory.h"
8b61709d 37#include "netdev.h"
3021ea60 38#include "openflow/openflow.h"
76343538 39#include "ovsdb-idl.h"
064af421 40#include "poll-loop.h"
064af421
BP
41#include "process.h"
42#include "signals.h"
0d085684 43#include "simap.h"
fe55ad15 44#include "stream-ssl.h"
76343538 45#include "stream.h"
cc01d0bb 46#include "stress.h"
064af421
BP
47#include "svec.h"
48#include "timeval.h"
49#include "unixctl.h"
50#include "util.h"
064af421 51#include "vconn.h"
5136ce49 52#include "vlog.h"
eaa67ba8 53#include "lib/vswitch-idl.h"
70e4e586 54#include "worker.h"
064af421 55
d98e6007 56VLOG_DEFINE_THIS_MODULE(vswitchd);
064af421 57
908ff19a
BP
58/* --mlockall: If set, locks all process memory into physical RAM, preventing
59 * the kernel from paging any of its memory to disk. */
60static bool want_mlockall;
61
9e15c889
BP
62static unixctl_cb_func ovs_vswitchd_exit;
63
3542148e 64static char *parse_options(int argc, char *argv[], char **unixctl_path);
064af421 65static void usage(void) NO_RETURN;
064af421
BP
66
67int
68main(int argc, char *argv[])
69{
3542148e 70 char *unixctl_path = NULL;
064af421
BP
71 struct unixctl_server *unixctl;
72 struct signal *sighup;
80df177a 73 char *remote;
c5187f17 74 bool exiting;
064af421
BP
75 int retval;
76
40f0707c 77 proctitle_init(argc, argv);
064af421 78 set_program_name(argv[0]);
cc01d0bb 79 stress_init_command();
3542148e 80 remote = parse_options(argc, argv, &unixctl_path);
064af421
BP
81 signal(SIGPIPE, SIG_IGN);
82 sighup = signal_register(SIGHUP);
83 process_init();
bd76d25d 84 ovsrec_init();
064af421 85
95440284 86 daemonize_start();
064af421 87
908ff19a
BP
88 if (want_mlockall) {
89#ifdef HAVE_MLOCKALL
90 if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
91 VLOG_ERR("mlockall failed: %s", strerror(errno));
92 }
93#else
94 VLOG_ERR("mlockall not supported on this system");
95#endif
96 }
97
70e4e586
BP
98 worker_start();
99
3542148e 100 retval = unixctl_server_create(unixctl_path, &unixctl);
064af421 101 if (retval) {
4d12270a 102 exit(EXIT_FAILURE);
064af421 103 }
0e15264f 104 unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit, &exiting);
064af421 105
c5187f17 106 bridge_init(remote);
80df177a
BP
107 free(remote);
108
9e15c889
BP
109 exiting = false;
110 while (!exiting) {
70e4e586 111 worker_run();
76343538 112 if (signal_poll(sighup)) {
064af421 113 vlog_reopen_log_file();
064af421 114 }
0d085684
BP
115 memory_run();
116 if (memory_should_report()) {
117 struct simap usage;
118
119 simap_init(&usage);
120 bridge_get_memory_usage(&usage);
121 memory_report(&usage);
122 simap_destroy(&usage);
123 }
5fcc0d00 124 bridge_run_fast();
c5187f17 125 bridge_run();
5fcc0d00 126 bridge_run_fast();
064af421 127 unixctl_server_run(unixctl);
8b61709d 128 netdev_run();
064af421 129
70e4e586 130 worker_wait();
064af421 131 signal_wait(sighup);
0d085684 132 memory_wait();
c5187f17 133 bridge_wait();
064af421 134 unixctl_server_wait(unixctl);
8b61709d 135 netdev_wait();
6d37aaf1
BP
136 if (exiting) {
137 poll_immediate_wake();
138 }
064af421
BP
139 poll_block();
140 }
ee45ad81
BP
141 bridge_exit();
142 unixctl_server_destroy(unixctl);
5a08f9b0 143 signal_unregister(sighup);
064af421
BP
144
145 return 0;
146}
147
80df177a 148static char *
3542148e 149parse_options(int argc, char *argv[], char **unixctl_pathp)
064af421
BP
150{
151 enum {
152 OPT_PEER_CA_CERT = UCHAR_MAX + 1,
86a06318 153 OPT_MLOCKALL,
3542148e 154 OPT_UNIXCTL,
064af421 155 VLOG_OPTION_ENUMS,
6f61c75b 156 LEAK_CHECKER_OPTION_ENUMS,
614c4892 157 OPT_BOOTSTRAP_CA_CERT,
8274ae95 158 OPT_ENABLE_DUMMY,
579a77e0 159 OPT_DISABLE_SYSTEM,
8274ae95 160 DAEMON_OPTION_ENUMS
064af421
BP
161 };
162 static struct option long_options[] = {
e3c17733
BP
163 {"help", no_argument, NULL, 'h'},
164 {"version", no_argument, NULL, 'V'},
165 {"mlockall", no_argument, NULL, OPT_MLOCKALL},
3542148e 166 {"unixctl", required_argument, NULL, OPT_UNIXCTL},
064af421
BP
167 DAEMON_LONG_OPTIONS,
168 VLOG_LONG_OPTIONS,
169 LEAK_CHECKER_LONG_OPTIONS,
bf8f2167 170 STREAM_SSL_LONG_OPTIONS,
e3c17733
BP
171 {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
172 {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
0cbfe35d 173 {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY},
579a77e0 174 {"disable-system", no_argument, NULL, OPT_DISABLE_SYSTEM},
e3c17733 175 {NULL, 0, NULL, 0},
064af421
BP
176 };
177 char *short_options = long_options_to_short_options(long_options);
064af421
BP
178
179 for (;;) {
180 int c;
181
182 c = getopt_long(argc, argv, short_options, long_options, NULL);
183 if (c == -1) {
184 break;
185 }
186
187 switch (c) {
064af421
BP
188 case 'h':
189 usage();
190
191 case 'V':
87ea5e5e 192 ovs_print_version(OFP10_VERSION, OFP10_VERSION);
064af421
BP
193 exit(EXIT_SUCCESS);
194
86a06318 195 case OPT_MLOCKALL:
908ff19a 196 want_mlockall = true;
86a06318
BP
197 break;
198
3542148e
AL
199 case OPT_UNIXCTL:
200 *unixctl_pathp = optarg;
201 break;
202
064af421
BP
203 VLOG_OPTION_HANDLERS
204 DAEMON_OPTION_HANDLERS
064af421 205 LEAK_CHECKER_OPTION_HANDLERS
fe55ad15
BP
206 STREAM_SSL_OPTION_HANDLERS
207
064af421 208 case OPT_PEER_CA_CERT:
fe55ad15 209 stream_ssl_set_peer_ca_cert_file(optarg);
064af421 210 break;
6f61c75b
BP
211
212 case OPT_BOOTSTRAP_CA_CERT:
213 stream_ssl_set_ca_cert_file(optarg, true);
214 break;
064af421 215
614c4892 216 case OPT_ENABLE_DUMMY:
0cbfe35d 217 dummy_enable(optarg && !strcmp(optarg, "override"));
614c4892
BP
218 break;
219
579a77e0
EJ
220 case OPT_DISABLE_SYSTEM:
221 dp_blacklist_provider("system");
222 break;
223
064af421
BP
224 case '?':
225 exit(EXIT_FAILURE);
226
227 default:
228 abort();
229 }
230 }
231 free(short_options);
232
233 argc -= optind;
234 argv += optind;
235
80df177a
BP
236 switch (argc) {
237 case 0:
238 return xasprintf("unix:%s/db.sock", ovs_rundir());
239
240 case 1:
241 return xstrdup(argv[0]);
242
243 default:
244 VLOG_FATAL("at most one non-option argument accepted; "
279c9e03 245 "use --help for usage");
064af421 246 }
064af421
BP
247}
248
249static void
250usage(void)
251{
f30f26be 252 printf("%s: Open vSwitch daemon\n"
80df177a
BP
253 "usage: %s [OPTIONS] [DATABASE]\n"
254 "where DATABASE is a socket on which ovsdb-server is listening\n"
255 " (default: \"unix:%s/db.sock\").\n",
256 program_name, program_name, ovs_rundir());
9467fe62 257 stream_usage("DATABASE", true, false, true);
064af421
BP
258 daemon_usage();
259 vlog_usage();
0b8b6f71 260 printf("\nOther options:\n"
3542148e 261 " --unixctl=SOCKET override default control socket name\n"
064af421
BP
262 " -h, --help display this help message\n"
263 " -V, --version display version information\n");
264 leak_checker_usage();
265 exit(EXIT_SUCCESS);
266}
9e15c889
BP
267
268static void
0e15264f
BP
269ovs_vswitchd_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
270 const char *argv[] OVS_UNUSED, void *exiting_)
9e15c889
BP
271{
272 bool *exiting = exiting_;
273 *exiting = true;
bde9f75d 274 unixctl_command_reply(conn, NULL);
9e15c889 275}