Branch data Line data Source code
1 : : /* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
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 <errno.h>
19 : : #include <getopt.h>
20 : : #include <limits.h>
21 : : #include <signal.h>
22 : : #include <stdlib.h>
23 : : #include <string.h>
24 : : #ifdef HAVE_MLOCKALL
25 : : #include <sys/mman.h>
26 : : #endif
27 : :
28 : : #include "bridge.h"
29 : : #include "command-line.h"
30 : : #include "compiler.h"
31 : : #include "daemon.h"
32 : : #include "dirs.h"
33 : : #include "dpif.h"
34 : : #include "dummy.h"
35 : : #include "fatal-signal.h"
36 : : #include "memory.h"
37 : : #include "netdev.h"
38 : : #include "openflow/openflow.h"
39 : : #include "ovsdb-idl.h"
40 : : #include "poll-loop.h"
41 : : #include "simap.h"
42 : : #include "stream-ssl.h"
43 : : #include "stream.h"
44 : : #include "svec.h"
45 : : #include "timeval.h"
46 : : #include "unixctl.h"
47 : : #include "util.h"
48 : : #include "openvswitch/vconn.h"
49 : : #include "openvswitch/vlog.h"
50 : : #include "lib/vswitch-idl.h"
51 : :
52 : 1288 : VLOG_DEFINE_THIS_MODULE(vswitchd);
53 : :
54 : : /* --mlockall: If set, locks all process memory into physical RAM, preventing
55 : : * the kernel from paging any of its memory to disk. */
56 : : static bool want_mlockall;
57 : :
58 : : static unixctl_cb_func ovs_vswitchd_exit;
59 : :
60 : : static char *parse_options(int argc, char *argv[], char **unixctl_path);
61 : : OVS_NO_RETURN static void usage(void);
62 : :
63 : : int
64 : 644 : main(int argc, char *argv[])
65 : : {
66 : 644 : char *unixctl_path = NULL;
67 : : struct unixctl_server *unixctl;
68 : : char *remote;
69 : : bool exiting;
70 : : int retval;
71 : :
72 : 644 : set_program_name(argv[0]);
73 : :
74 : 644 : ovs_cmdl_proctitle_init(argc, argv);
75 : 644 : service_start(&argc, &argv);
76 : 644 : remote = parse_options(argc, argv, &unixctl_path);
77 : 639 : fatal_ignore_sigpipe();
78 : 639 : ovsrec_init();
79 : :
80 : 639 : daemonize_start(true);
81 : :
82 [ - + ]: 617 : if (want_mlockall) {
83 : : #ifdef HAVE_MLOCKALL
84 [ # # ]: 0 : if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
85 [ # # ]: 0 : VLOG_ERR("mlockall failed: %s", ovs_strerror(errno));
86 : : }
87 : : #else
88 : : VLOG_ERR("mlockall not supported on this system");
89 : : #endif
90 : : }
91 : :
92 : 617 : retval = unixctl_server_create(unixctl_path, &unixctl);
93 [ - + ]: 617 : if (retval) {
94 : 0 : exit(EXIT_FAILURE);
95 : : }
96 : 617 : unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit, &exiting);
97 : :
98 : 617 : bridge_init(remote);
99 : 617 : free(remote);
100 : :
101 : 617 : exiting = false;
102 [ + + ]: 105791 : while (!exiting) {
103 : 105174 : memory_run();
104 [ + + ]: 105174 : if (memory_should_report()) {
105 : : struct simap usage;
106 : :
107 : 73 : simap_init(&usage);
108 : 73 : bridge_get_memory_usage(&usage);
109 : 73 : memory_report(&usage);
110 : 73 : simap_destroy(&usage);
111 : : }
112 : 105174 : bridge_run();
113 : 105174 : unixctl_server_run(unixctl);
114 : 105174 : netdev_run();
115 : :
116 : 105174 : memory_wait();
117 : 105174 : bridge_wait();
118 : 105174 : unixctl_server_wait(unixctl);
119 : 105174 : netdev_wait();
120 [ + + ]: 105174 : if (exiting) {
121 : 617 : poll_immediate_wake();
122 : : }
123 : 105174 : poll_block();
124 [ - + ]: 105174 : if (should_service_stop()) {
125 : 0 : exiting = true;
126 : : }
127 : : }
128 : 617 : bridge_exit();
129 : 617 : unixctl_server_destroy(unixctl);
130 : 617 : service_stop();
131 : :
132 : 617 : return 0;
133 : : }
134 : :
135 : : static char *
136 : 644 : parse_options(int argc, char *argv[], char **unixctl_pathp)
137 : : {
138 : : enum {
139 : : OPT_PEER_CA_CERT = UCHAR_MAX + 1,
140 : : OPT_MLOCKALL,
141 : : OPT_UNIXCTL,
142 : : VLOG_OPTION_ENUMS,
143 : : OPT_BOOTSTRAP_CA_CERT,
144 : : OPT_ENABLE_DUMMY,
145 : : OPT_DISABLE_SYSTEM,
146 : : DAEMON_OPTION_ENUMS,
147 : : OPT_DPDK,
148 : : OPT_DUMMY_NUMA,
149 : : };
150 : : static const struct option long_options[] = {
151 : : {"help", no_argument, NULL, 'h'},
152 : : {"version", no_argument, NULL, 'V'},
153 : : {"mlockall", no_argument, NULL, OPT_MLOCKALL},
154 : : {"unixctl", required_argument, NULL, OPT_UNIXCTL},
155 : : DAEMON_LONG_OPTIONS,
156 : : VLOG_LONG_OPTIONS,
157 : : STREAM_SSL_LONG_OPTIONS,
158 : : {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
159 : : {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
160 : : {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY},
161 : : {"disable-system", no_argument, NULL, OPT_DISABLE_SYSTEM},
162 : : {"dpdk", optional_argument, NULL, OPT_DPDK},
163 : : {"dummy-numa", required_argument, NULL, OPT_DUMMY_NUMA},
164 : : {NULL, 0, NULL, 0},
165 : : };
166 : 644 : char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
167 : :
168 : : for (;;) {
169 : : int c;
170 : :
171 : 6230 : c = getopt_long(argc, argv, short_options, long_options, NULL);
172 [ + + ]: 6230 : if (c == -1) {
173 : 639 : break;
174 : : }
175 : :
176 [ - + - + : 5591 : switch (c) {
+ + - - +
- + + - -
- - - - -
- + + - -
+ - ]
177 : : case 'h':
178 : 0 : usage();
179 : :
180 : : case 'V':
181 : 5 : ovs_print_version(0, 0);
182 : 5 : exit(EXIT_SUCCESS);
183 : :
184 : : case OPT_MLOCKALL:
185 : 0 : want_mlockall = true;
186 : 0 : break;
187 : :
188 : : case OPT_UNIXCTL:
189 : 3 : *unixctl_pathp = optarg;
190 : 3 : break;
191 : :
192 : 2613 : VLOG_OPTION_HANDLERS
193 : 1911 : DAEMON_OPTION_HANDLERS
194 : 0 : STREAM_SSL_OPTION_HANDLERS
195 : :
196 : : case OPT_PEER_CA_CERT:
197 : 0 : stream_ssl_set_peer_ca_cert_file(optarg);
198 : 0 : break;
199 : :
200 : : case OPT_BOOTSTRAP_CA_CERT:
201 : 0 : stream_ssl_set_ca_cert_file(optarg, true);
202 : 0 : break;
203 : :
204 : : case OPT_ENABLE_DUMMY:
205 : 543 : dummy_enable(optarg);
206 : 543 : break;
207 : :
208 : : case OPT_DISABLE_SYSTEM:
209 : 497 : dp_blacklist_provider("system");
210 : 497 : break;
211 : :
212 : : case '?':
213 : 0 : exit(EXIT_FAILURE);
214 : :
215 : : case OPT_DPDK:
216 : 0 : ovs_fatal(0, "Using --dpdk to configure DPDK is not supported.");
217 : : break;
218 : :
219 : : case OPT_DUMMY_NUMA:
220 : 19 : ovs_numa_set_dummy(optarg);
221 : 19 : break;
222 : :
223 : : default:
224 : 0 : abort();
225 : : }
226 : 5586 : }
227 : 639 : free(short_options);
228 : :
229 : 639 : argc -= optind;
230 : 639 : argv += optind;
231 : :
232 [ + + - ]: 639 : switch (argc) {
233 : : case 0:
234 : 638 : return xasprintf("unix:%s/db.sock", ovs_rundir());
235 : :
236 : : case 1:
237 : 1 : return xstrdup(argv[0]);
238 : :
239 : : default:
240 : 0 : VLOG_FATAL("at most one non-option argument accepted; "
241 : : "use --help for usage");
242 : : }
243 : : }
244 : :
245 : : static void
246 : 0 : usage(void)
247 : : {
248 : 0 : printf("%s: Open vSwitch daemon\n"
249 : : "usage: %s [OPTIONS] [DATABASE]\n"
250 : : "where DATABASE is a socket on which ovsdb-server is listening\n"
251 : : " (default: \"unix:%s/db.sock\").\n",
252 : : program_name, program_name, ovs_rundir());
253 : 0 : stream_usage("DATABASE", true, false, true);
254 : 0 : daemon_usage();
255 : 0 : vlog_usage();
256 : 0 : printf("\nDPDK options:\n"
257 : : "Configuration of DPDK via command-line is removed from this\n"
258 : : "version of Open vSwitch. DPDK is configured through ovsdb.\n"
259 : : );
260 : 0 : printf("\nOther options:\n"
261 : : " --unixctl=SOCKET override default control socket name\n"
262 : : " -h, --help display this help message\n"
263 : : " -V, --version display version information\n");
264 : 0 : exit(EXIT_SUCCESS);
265 : : }
266 : :
267 : : static void
268 : 617 : ovs_vswitchd_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
269 : : const char *argv[] OVS_UNUSED, void *exiting_)
270 : : {
271 : 617 : bool *exiting = exiting_;
272 : 617 : *exiting = true;
273 : 617 : unixctl_command_reply(conn, NULL);
274 : 617 : }
|