]>
Commit | Line | Data |
---|---|---|
8420c7ad | 1 | /* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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" |
8a777cf6 | 35 | #include "fatal-signal.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" |
0d085684 | 41 | #include "simap.h" |
fe55ad15 | 42 | #include "stream-ssl.h" |
76343538 | 43 | #include "stream.h" |
064af421 BP |
44 | #include "svec.h" |
45 | #include "timeval.h" | |
46 | #include "unixctl.h" | |
47 | #include "util.h" | |
4a1f523f | 48 | #include "openvswitch/vconn.h" |
e6211adc | 49 | #include "openvswitch/vlog.h" |
eaa67ba8 | 50 | #include "lib/vswitch-idl.h" |
8a9562d2 | 51 | #include "lib/netdev-dpdk.h" |
064af421 | 52 | |
d98e6007 | 53 | VLOG_DEFINE_THIS_MODULE(vswitchd); |
064af421 | 54 | |
908ff19a BP |
55 | /* --mlockall: If set, locks all process memory into physical RAM, preventing |
56 | * the kernel from paging any of its memory to disk. */ | |
57 | static bool want_mlockall; | |
58 | ||
9e15c889 BP |
59 | static unixctl_cb_func ovs_vswitchd_exit; |
60 | ||
3542148e | 61 | static char *parse_options(int argc, char *argv[], char **unixctl_path); |
cab50449 | 62 | OVS_NO_RETURN static void usage(void); |
064af421 BP |
63 | |
64 | int | |
65 | main(int argc, char *argv[]) | |
66 | { | |
3542148e | 67 | char *unixctl_path = NULL; |
064af421 | 68 | struct unixctl_server *unixctl; |
80df177a | 69 | char *remote; |
c5187f17 | 70 | bool exiting; |
064af421 BP |
71 | int retval; |
72 | ||
73 | set_program_name(argv[0]); | |
8a9562d2 | 74 | retval = dpdk_init(argc,argv); |
7d1ced01 CL |
75 | if (retval < 0) { |
76 | return retval; | |
77 | } | |
78 | ||
8a9562d2 PS |
79 | argc -= retval; |
80 | argv += retval; | |
81 | ||
5f383751 | 82 | ovs_cmdl_proctitle_init(argc, argv); |
42dd41ef | 83 | service_start(&argc, &argv); |
3542148e | 84 | remote = parse_options(argc, argv, &unixctl_path); |
8a777cf6 | 85 | fatal_ignore_sigpipe(); |
bd76d25d | 86 | ovsrec_init(); |
064af421 | 87 | |
e91b927d | 88 | daemonize_start(true); |
064af421 | 89 | |
908ff19a BP |
90 | if (want_mlockall) { |
91 | #ifdef HAVE_MLOCKALL | |
92 | if (mlockall(MCL_CURRENT | MCL_FUTURE)) { | |
10a89ef0 | 93 | VLOG_ERR("mlockall failed: %s", ovs_strerror(errno)); |
908ff19a BP |
94 | } |
95 | #else | |
96 | VLOG_ERR("mlockall not supported on this system"); | |
97 | #endif | |
98 | } | |
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) { | |
0d085684 BP |
111 | memory_run(); |
112 | if (memory_should_report()) { | |
113 | struct simap usage; | |
114 | ||
115 | simap_init(&usage); | |
116 | bridge_get_memory_usage(&usage); | |
117 | memory_report(&usage); | |
118 | simap_destroy(&usage); | |
119 | } | |
c5187f17 | 120 | bridge_run(); |
064af421 | 121 | unixctl_server_run(unixctl); |
8b61709d | 122 | netdev_run(); |
064af421 | 123 | |
0d085684 | 124 | memory_wait(); |
c5187f17 | 125 | bridge_wait(); |
064af421 | 126 | unixctl_server_wait(unixctl); |
8b61709d | 127 | netdev_wait(); |
6d37aaf1 BP |
128 | if (exiting) { |
129 | poll_immediate_wake(); | |
130 | } | |
064af421 | 131 | poll_block(); |
42dd41ef GS |
132 | if (should_service_stop()) { |
133 | exiting = true; | |
134 | } | |
064af421 | 135 | } |
ee45ad81 BP |
136 | bridge_exit(); |
137 | unixctl_server_destroy(unixctl); | |
42dd41ef | 138 | service_stop(); |
064af421 BP |
139 | |
140 | return 0; | |
141 | } | |
142 | ||
80df177a | 143 | static char * |
3542148e | 144 | parse_options(int argc, char *argv[], char **unixctl_pathp) |
064af421 BP |
145 | { |
146 | enum { | |
147 | OPT_PEER_CA_CERT = UCHAR_MAX + 1, | |
86a06318 | 148 | OPT_MLOCKALL, |
3542148e | 149 | OPT_UNIXCTL, |
064af421 | 150 | VLOG_OPTION_ENUMS, |
614c4892 | 151 | OPT_BOOTSTRAP_CA_CERT, |
8274ae95 | 152 | OPT_ENABLE_DUMMY, |
579a77e0 | 153 | OPT_DISABLE_SYSTEM, |
8a9562d2 PS |
154 | DAEMON_OPTION_ENUMS, |
155 | OPT_DPDK, | |
064af421 | 156 | }; |
07fc4ed3 | 157 | static const struct option long_options[] = { |
e3c17733 BP |
158 | {"help", no_argument, NULL, 'h'}, |
159 | {"version", no_argument, NULL, 'V'}, | |
160 | {"mlockall", no_argument, NULL, OPT_MLOCKALL}, | |
3542148e | 161 | {"unixctl", required_argument, NULL, OPT_UNIXCTL}, |
064af421 BP |
162 | DAEMON_LONG_OPTIONS, |
163 | VLOG_LONG_OPTIONS, | |
bf8f2167 | 164 | STREAM_SSL_LONG_OPTIONS, |
e3c17733 BP |
165 | {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT}, |
166 | {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT}, | |
0cbfe35d | 167 | {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY}, |
579a77e0 | 168 | {"disable-system", no_argument, NULL, OPT_DISABLE_SYSTEM}, |
8a9562d2 | 169 | {"dpdk", required_argument, NULL, OPT_DPDK}, |
e3c17733 | 170 | {NULL, 0, NULL, 0}, |
064af421 | 171 | }; |
5f383751 | 172 | char *short_options = ovs_cmdl_long_options_to_short_options(long_options); |
064af421 BP |
173 | |
174 | for (;;) { | |
175 | int c; | |
176 | ||
177 | c = getopt_long(argc, argv, short_options, long_options, NULL); | |
178 | if (c == -1) { | |
179 | break; | |
180 | } | |
181 | ||
182 | switch (c) { | |
064af421 BP |
183 | case 'h': |
184 | usage(); | |
185 | ||
186 | case 'V': | |
11b06842 | 187 | ovs_print_version(0, 0); |
064af421 BP |
188 | exit(EXIT_SUCCESS); |
189 | ||
86a06318 | 190 | case OPT_MLOCKALL: |
908ff19a | 191 | want_mlockall = true; |
86a06318 BP |
192 | break; |
193 | ||
3542148e AL |
194 | case OPT_UNIXCTL: |
195 | *unixctl_pathp = optarg; | |
196 | break; | |
197 | ||
064af421 BP |
198 | VLOG_OPTION_HANDLERS |
199 | DAEMON_OPTION_HANDLERS | |
fe55ad15 BP |
200 | STREAM_SSL_OPTION_HANDLERS |
201 | ||
064af421 | 202 | case OPT_PEER_CA_CERT: |
fe55ad15 | 203 | stream_ssl_set_peer_ca_cert_file(optarg); |
064af421 | 204 | break; |
6f61c75b BP |
205 | |
206 | case OPT_BOOTSTRAP_CA_CERT: | |
207 | stream_ssl_set_ca_cert_file(optarg, true); | |
208 | break; | |
064af421 | 209 | |
614c4892 | 210 | case OPT_ENABLE_DUMMY: |
8420c7ad | 211 | dummy_enable(optarg); |
614c4892 BP |
212 | break; |
213 | ||
579a77e0 EJ |
214 | case OPT_DISABLE_SYSTEM: |
215 | dp_blacklist_provider("system"); | |
216 | break; | |
217 | ||
064af421 BP |
218 | case '?': |
219 | exit(EXIT_FAILURE); | |
220 | ||
8a9562d2 | 221 | case OPT_DPDK: |
e03f0d03 | 222 | ovs_fatal(0, "--dpdk must be given at beginning of command line."); |
8a9562d2 PS |
223 | break; |
224 | ||
064af421 BP |
225 | default: |
226 | abort(); | |
227 | } | |
228 | } | |
229 | free(short_options); | |
230 | ||
231 | argc -= optind; | |
232 | argv += optind; | |
233 | ||
80df177a BP |
234 | switch (argc) { |
235 | case 0: | |
236 | return xasprintf("unix:%s/db.sock", ovs_rundir()); | |
237 | ||
238 | case 1: | |
239 | return xstrdup(argv[0]); | |
240 | ||
241 | default: | |
242 | VLOG_FATAL("at most one non-option argument accepted; " | |
279c9e03 | 243 | "use --help for usage"); |
064af421 | 244 | } |
064af421 BP |
245 | } |
246 | ||
247 | static void | |
248 | usage(void) | |
249 | { | |
f30f26be | 250 | printf("%s: Open vSwitch daemon\n" |
80df177a BP |
251 | "usage: %s [OPTIONS] [DATABASE]\n" |
252 | "where DATABASE is a socket on which ovsdb-server is listening\n" | |
253 | " (default: \"unix:%s/db.sock\").\n", | |
254 | program_name, program_name, ovs_rundir()); | |
9467fe62 | 255 | stream_usage("DATABASE", true, false, true); |
064af421 BP |
256 | daemon_usage(); |
257 | vlog_usage(); | |
d1279464 | 258 | printf("\nDPDK options:\n" |
7d1ced01 CL |
259 | " --dpdk [VHOST] [DPDK] Initialize DPDK datapath.\n" |
260 | " where DPDK are options for initializing DPDK lib and VHOST is\n" | |
261 | #ifdef VHOST_CUSE | |
262 | " option to override default character device name used for\n" | |
263 | " for use with userspace vHost\n" | |
264 | " -cuse_dev_name NAME\n" | |
265 | #else | |
266 | " option to override default directory where vhost-user\n" | |
267 | " sockets are created.\n" | |
268 | " -vhost_sock_dir DIR\n" | |
269 | #endif | |
270 | ); | |
0b8b6f71 | 271 | printf("\nOther options:\n" |
58397e6c KT |
272 | " --unixctl=SOCKET override default control socket name\n" |
273 | " -h, --help display this help message\n" | |
274 | " -V, --version display version information\n"); | |
064af421 BP |
275 | exit(EXIT_SUCCESS); |
276 | } | |
9e15c889 BP |
277 | |
278 | static void | |
0e15264f BP |
279 | ovs_vswitchd_exit(struct unixctl_conn *conn, int argc OVS_UNUSED, |
280 | const char *argv[] OVS_UNUSED, void *exiting_) | |
9e15c889 BP |
281 | { |
282 | bool *exiting = exiting_; | |
283 | *exiting = true; | |
bde9f75d | 284 | unixctl_command_reply(conn, NULL); |
9e15c889 | 285 | } |