Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C) 2016 Intel Corporation. All rights reserved.
3 : : * Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
4 : : * Copyright (c) 2021, 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5 : : */
6 : :
7 : : #include "spdk/stdinc.h"
8 : : #include "spdk/version.h"
9 : :
10 : : #include "spdk_internal/event.h"
11 : :
12 : : #include "spdk/assert.h"
13 : : #include "spdk/env.h"
14 : : #include "spdk/init.h"
15 : : #include "spdk/log.h"
16 : : #include "spdk/thread.h"
17 : : #include "spdk/trace.h"
18 : : #include "spdk/string.h"
19 : : #include "spdk/scheduler.h"
20 : : #include "spdk/rpc.h"
21 : : #include "spdk/util.h"
22 : :
23 : : #define SPDK_APP_DEFAULT_LOG_LEVEL SPDK_LOG_NOTICE
24 : : #define SPDK_APP_DEFAULT_LOG_PRINT_LEVEL SPDK_LOG_INFO
25 : : #define SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES SPDK_DEFAULT_NUM_TRACE_ENTRIES
26 : :
27 : : #define SPDK_APP_DPDK_DEFAULT_MEM_SIZE -1
28 : : #define SPDK_APP_DPDK_DEFAULT_MAIN_CORE -1
29 : : #define SPDK_APP_DPDK_DEFAULT_MEM_CHANNEL -1
30 : : #define SPDK_APP_DPDK_DEFAULT_CORE_MASK "0x1"
31 : : #define SPDK_APP_DPDK_DEFAULT_BASE_VIRTADDR 0x200000000000
32 : : #define SPDK_APP_DEFAULT_CORE_LIMIT 0x140000000 /* 5 GiB */
33 : :
34 : : /* For core counts <= 63, the message memory pool size is set to
35 : : * SPDK_DEFAULT_MSG_MEMPOOL_SIZE.
36 : : * For core counts > 63, the message memory pool size is dependend on
37 : : * number of cores. Per core, it is calculated as SPDK_MSG_MEMPOOL_CACHE_SIZE
38 : : * multiplied by factor of 4 to have space for multiple spdk threads running
39 : : * on single core (e.g iscsi + nvmf + vhost ). */
40 : : #define SPDK_APP_PER_CORE_MSG_MEMPOOL_SIZE (4 * SPDK_MSG_MEMPOOL_CACHE_SIZE)
41 : :
42 : : #define MAX_CPU_CORES 128
43 : :
44 : : struct spdk_app {
45 : : const char *json_config_file;
46 : : bool json_config_ignore_errors;
47 : : bool stopped;
48 : : const char *rpc_addr;
49 : : const char **rpc_allowlist;
50 : : FILE *rpc_log_file;
51 : : enum spdk_log_level rpc_log_level;
52 : : int shm_id;
53 : : spdk_app_shutdown_cb shutdown_cb;
54 : : int rc;
55 : : };
56 : :
57 : : static struct spdk_app g_spdk_app;
58 : : static spdk_msg_fn g_start_fn = NULL;
59 : : static void *g_start_arg = NULL;
60 : : static bool g_delay_subsystem_init = false;
61 : : static bool g_shutdown_sig_received = false;
62 : : static char *g_executable_name;
63 : : static struct spdk_app_opts g_default_opts;
64 : : static bool g_disable_cpumask_locks = false;
65 : :
66 : : static int g_core_locks[MAX_CPU_CORES];
67 : :
68 : : int
69 : 0 : spdk_app_get_shm_id(void)
70 : : {
71 : 0 : return g_spdk_app.shm_id;
72 : : }
73 : :
74 : : /* append one empty option to indicate the end of the array */
75 : : static const struct option g_cmdline_options[] = {
76 : : #define CONFIG_FILE_OPT_IDX 'c'
77 : : {"config", required_argument, NULL, CONFIG_FILE_OPT_IDX},
78 : : #define LIMIT_COREDUMP_OPT_IDX 'd'
79 : : {"limit-coredump", no_argument, NULL, LIMIT_COREDUMP_OPT_IDX},
80 : : #define TPOINT_GROUP_OPT_IDX 'e'
81 : : {"tpoint-group", required_argument, NULL, TPOINT_GROUP_OPT_IDX},
82 : : #define SINGLE_FILE_SEGMENTS_OPT_IDX 'g'
83 : : {"single-file-segments", no_argument, NULL, SINGLE_FILE_SEGMENTS_OPT_IDX},
84 : : #define HELP_OPT_IDX 'h'
85 : : {"help", no_argument, NULL, HELP_OPT_IDX},
86 : : #define SHM_ID_OPT_IDX 'i'
87 : : {"shm-id", required_argument, NULL, SHM_ID_OPT_IDX},
88 : : #define CPUMASK_OPT_IDX 'm'
89 : : {"cpumask", required_argument, NULL, CPUMASK_OPT_IDX},
90 : : #define MEM_CHANNELS_OPT_IDX 'n'
91 : : {"mem-channels", required_argument, NULL, MEM_CHANNELS_OPT_IDX},
92 : : #define MAIN_CORE_OPT_IDX 'p'
93 : : {"main-core", required_argument, NULL, MAIN_CORE_OPT_IDX},
94 : : {"master-core", required_argument, NULL, MAIN_CORE_OPT_IDX}, /* deprecated */
95 : : #define RPC_SOCKET_OPT_IDX 'r'
96 : : {"rpc-socket", required_argument, NULL, RPC_SOCKET_OPT_IDX},
97 : : #define MEM_SIZE_OPT_IDX 's'
98 : : {"mem-size", required_argument, NULL, MEM_SIZE_OPT_IDX},
99 : : #define NO_PCI_OPT_IDX 'u'
100 : : {"no-pci", no_argument, NULL, NO_PCI_OPT_IDX},
101 : : #define VERSION_OPT_IDX 'v'
102 : : {"version", no_argument, NULL, VERSION_OPT_IDX},
103 : : #define PCI_BLOCKED_OPT_IDX 'B'
104 : : {"pci-blocked", required_argument, NULL, PCI_BLOCKED_OPT_IDX},
105 : : {"pci-blacklist", required_argument, NULL, PCI_BLOCKED_OPT_IDX}, /* deprecated */
106 : : #define LOGFLAG_OPT_IDX 'L'
107 : : {"logflag", required_argument, NULL, LOGFLAG_OPT_IDX},
108 : : #define HUGE_UNLINK_OPT_IDX 'R'
109 : : {"huge-unlink", no_argument, NULL, HUGE_UNLINK_OPT_IDX},
110 : : #define PCI_ALLOWED_OPT_IDX 'A'
111 : : {"pci-allowed", required_argument, NULL, PCI_ALLOWED_OPT_IDX},
112 : : #define PCI_WHITELIST_OPT_IDX 'W'
113 : : {"pci-whitelist", required_argument, NULL, PCI_WHITELIST_OPT_IDX}, /* deprecated */
114 : : #define INTERRUPT_MODE_OPT_IDX 256
115 : : {"interrupt-mode", no_argument, NULL, INTERRUPT_MODE_OPT_IDX},
116 : : #define SILENCE_NOTICELOG_OPT_IDX 257
117 : : {"silence-noticelog", no_argument, NULL, SILENCE_NOTICELOG_OPT_IDX},
118 : : #define WAIT_FOR_RPC_OPT_IDX 258
119 : : {"wait-for-rpc", no_argument, NULL, WAIT_FOR_RPC_OPT_IDX},
120 : : #define HUGE_DIR_OPT_IDX 259
121 : : {"huge-dir", required_argument, NULL, HUGE_DIR_OPT_IDX},
122 : : #define NUM_TRACE_ENTRIES_OPT_IDX 260
123 : : {"num-trace-entries", required_argument, NULL, NUM_TRACE_ENTRIES_OPT_IDX},
124 : : #define MAX_REACTOR_DELAY_OPT_IDX 261
125 : : {"max-delay", required_argument, NULL, MAX_REACTOR_DELAY_OPT_IDX},
126 : : #define JSON_CONFIG_OPT_IDX 262
127 : : {"json", required_argument, NULL, JSON_CONFIG_OPT_IDX},
128 : : #define JSON_CONFIG_IGNORE_INIT_ERRORS_IDX 263
129 : : {"json-ignore-init-errors", no_argument, NULL, JSON_CONFIG_IGNORE_INIT_ERRORS_IDX},
130 : : #define IOVA_MODE_OPT_IDX 264
131 : : {"iova-mode", required_argument, NULL, IOVA_MODE_OPT_IDX},
132 : : #define BASE_VIRTADDR_OPT_IDX 265
133 : : {"base-virtaddr", required_argument, NULL, BASE_VIRTADDR_OPT_IDX},
134 : : #define ENV_CONTEXT_OPT_IDX 266
135 : : {"env-context", required_argument, NULL, ENV_CONTEXT_OPT_IDX},
136 : : #define DISABLE_CPUMASK_LOCKS_OPT_IDX 267
137 : : {"disable-cpumask-locks", no_argument, NULL, DISABLE_CPUMASK_LOCKS_OPT_IDX},
138 : : #define RPCS_ALLOWED_OPT_IDX 268
139 : : {"rpcs-allowed", required_argument, NULL, RPCS_ALLOWED_OPT_IDX},
140 : : #define ENV_VF_TOKEN_OPT_IDX 269
141 : : {"vfio-vf-token", required_argument, NULL, ENV_VF_TOKEN_OPT_IDX},
142 : : #define MSG_MEMPOOL_SIZE_OPT_IDX 270
143 : : {"msg-mempool-size", required_argument, NULL, MSG_MEMPOOL_SIZE_OPT_IDX},
144 : : #define LCORES_OPT_IDX 271
145 : : {"lcores", required_argument, NULL, LCORES_OPT_IDX},
146 : : #define NO_HUGE_OPT_IDX 272
147 : : {"no-huge", no_argument, NULL, NO_HUGE_OPT_IDX},
148 : : };
149 : :
150 : : static void
151 : 1303 : app_start_shutdown(void *ctx)
152 : : {
153 [ + + ]: 1303 : if (g_spdk_app.shutdown_cb) {
154 : 489 : g_spdk_app.shutdown_cb();
155 : 489 : g_spdk_app.shutdown_cb = NULL;
156 : : } else {
157 : 814 : spdk_app_stop(0);
158 : : }
159 : 1303 : }
160 : :
161 : : void
162 : 1303 : spdk_app_start_shutdown(void)
163 : : {
164 : 1303 : spdk_thread_send_critical_msg(spdk_thread_get_app_thread(), app_start_shutdown);
165 : 1303 : }
166 : :
167 : : static void
168 : 1298 : __shutdown_signal(int signo)
169 : : {
170 [ + + + - ]: 1298 : if (!g_shutdown_sig_received) {
171 : 1298 : g_shutdown_sig_received = true;
172 : 1298 : spdk_app_start_shutdown();
173 : : }
174 : 1298 : }
175 : :
176 : : static int
177 : 3108 : app_opts_validate(const char *app_opts)
178 : : {
179 : 3108 : int i = 0, j;
180 : :
181 [ + + ]: 44011 : for (i = 0; app_opts[i] != '\0'; i++) {
182 : : /* ignore getopt control characters */
183 [ + + + - : 40907 : if (app_opts[i] == ':' || app_opts[i] == '+' || app_opts[i] == '-') {
- + ]
184 : 18197 : continue;
185 : : }
186 : :
187 [ + + ]: 703890 : for (j = 0; SPDK_APP_GETOPT_STRING[j] != '\0'; j++) {
188 [ + + ]: 681184 : if (app_opts[i] == SPDK_APP_GETOPT_STRING[j]) {
189 : 4 : return app_opts[i];
190 : : }
191 : : }
192 : : }
193 : 3104 : return 0;
194 : : }
195 : :
196 : : static void
197 : 3098 : calculate_mempool_size(struct spdk_app_opts *opts,
198 : : struct spdk_app_opts *opts_user)
199 : : {
200 : 3098 : uint32_t core_count = spdk_env_get_core_count();
201 : :
202 [ + - ]: 3098 : if (!opts_user->msg_mempool_size) {
203 : : /* The user didn't specify msg_mempool_size, so let's calculate it.
204 : : Set the default (SPDK_DEFAULT_MSG_MEMPOOL_SIZE) if less than
205 : : 64 cores, and use 4k per core otherwise */
206 : 3098 : opts->msg_mempool_size = spdk_max(SPDK_DEFAULT_MSG_MEMPOOL_SIZE,
207 : : core_count * SPDK_APP_PER_CORE_MSG_MEMPOOL_SIZE);
208 : : } else {
209 : 0 : opts->msg_mempool_size = opts_user->msg_mempool_size;
210 : : }
211 : 3098 : }
212 : :
213 : : void
214 : 6256 : spdk_app_opts_init(struct spdk_app_opts *opts, size_t opts_size)
215 : : {
216 [ - + ]: 6256 : if (!opts) {
217 : 0 : SPDK_ERRLOG("opts should not be NULL\n");
218 : 0 : return;
219 : : }
220 : :
221 [ - + ]: 6256 : if (!opts_size) {
222 : 0 : SPDK_ERRLOG("opts_size should not be zero value\n");
223 : 0 : return;
224 : : }
225 : :
226 [ - + ]: 6256 : memset(opts, 0, opts_size);
227 : 6256 : opts->opts_size = opts_size;
228 : :
229 : : #define SET_FIELD(field, value) \
230 : : if (offsetof(struct spdk_app_opts, field) + sizeof(opts->field) <= opts_size) { \
231 : : opts->field = value; \
232 : : } \
233 : :
234 [ + - ]: 6256 : SET_FIELD(enable_coredump, true);
235 [ + - ]: 6256 : SET_FIELD(shm_id, -1);
236 [ + - ]: 6256 : SET_FIELD(mem_size, SPDK_APP_DPDK_DEFAULT_MEM_SIZE);
237 [ + - ]: 6256 : SET_FIELD(main_core, SPDK_APP_DPDK_DEFAULT_MAIN_CORE);
238 [ + - ]: 6256 : SET_FIELD(mem_channel, SPDK_APP_DPDK_DEFAULT_MEM_CHANNEL);
239 [ + - ]: 6256 : SET_FIELD(base_virtaddr, SPDK_APP_DPDK_DEFAULT_BASE_VIRTADDR);
240 [ + - ]: 6256 : SET_FIELD(print_level, SPDK_APP_DEFAULT_LOG_PRINT_LEVEL);
241 [ + - ]: 6256 : SET_FIELD(rpc_addr, SPDK_DEFAULT_RPC_ADDR);
242 [ + - ]: 6256 : SET_FIELD(num_entries, SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES);
243 [ + - ]: 6256 : SET_FIELD(delay_subsystem_init, false);
244 [ + - ]: 6256 : SET_FIELD(disable_signal_handlers, false);
245 [ + - ]: 6256 : SET_FIELD(interrupt_mode, false);
246 : : /* Don't set msg_mempool_size here, it is set or calculated later */
247 [ + - ]: 6256 : SET_FIELD(rpc_allowlist, NULL);
248 [ + - ]: 6256 : SET_FIELD(rpc_log_file, NULL);
249 [ + - ]: 6256 : SET_FIELD(rpc_log_level, SPDK_LOG_DISABLED);
250 : : #undef SET_FIELD
251 : : }
252 : :
253 : : static int
254 : 3058 : app_setup_signal_handlers(struct spdk_app_opts *opts)
255 : : {
256 : 1351 : struct sigaction sigact;
257 : 1351 : sigset_t sigmask;
258 : : int rc;
259 : :
260 [ - + ]: 3058 : sigemptyset(&sigmask);
261 [ - + ]: 3058 : memset(&sigact, 0, sizeof(sigact));
262 [ - + ]: 3058 : sigemptyset(&sigact.sa_mask);
263 : :
264 : 3058 : sigact.sa_handler = SIG_IGN;
265 : 3058 : rc = sigaction(SIGPIPE, &sigact, NULL);
266 [ - + ]: 3058 : if (rc < 0) {
267 : 0 : SPDK_ERRLOG("sigaction(SIGPIPE) failed\n");
268 : 0 : return rc;
269 : : }
270 : :
271 : : /* Install the same handler for SIGINT and SIGTERM */
272 : 3058 : g_shutdown_sig_received = false;
273 : 3058 : sigact.sa_handler = __shutdown_signal;
274 : 3058 : rc = sigaction(SIGINT, &sigact, NULL);
275 [ - + ]: 3058 : if (rc < 0) {
276 : 0 : SPDK_ERRLOG("sigaction(SIGINT) failed\n");
277 : 0 : return rc;
278 : : }
279 [ - + ]: 3058 : sigaddset(&sigmask, SIGINT);
280 : :
281 : 3058 : rc = sigaction(SIGTERM, &sigact, NULL);
282 [ - + ]: 3058 : if (rc < 0) {
283 : 0 : SPDK_ERRLOG("sigaction(SIGTERM) failed\n");
284 : 0 : return rc;
285 : : }
286 [ - + ]: 3058 : sigaddset(&sigmask, SIGTERM);
287 : :
288 : 3058 : pthread_sigmask(SIG_UNBLOCK, &sigmask, NULL);
289 : :
290 : 3058 : return 0;
291 : : }
292 : :
293 : : static void
294 : 3005 : app_start_application(void)
295 : : {
296 [ - + ]: 3005 : assert(spdk_thread_is_app_thread(NULL));
297 : :
298 : 3005 : g_start_fn(g_start_arg);
299 : 3005 : }
300 : :
301 : : static void
302 : 2895 : app_start_rpc(int rc, void *arg1)
303 : : {
304 : 1303 : struct spdk_rpc_opts opts;
305 : :
306 [ + + ]: 2895 : if (rc) {
307 : 53 : spdk_app_stop(rc);
308 : 53 : return;
309 : : }
310 : :
311 : 2842 : spdk_rpc_set_allowlist(g_spdk_app.rpc_allowlist);
312 : :
313 : 2842 : opts.size = SPDK_SIZEOF(&opts, log_level);
314 : 2842 : opts.log_file = g_spdk_app.rpc_log_file;
315 : 2842 : opts.log_level = g_spdk_app.rpc_log_level;
316 : :
317 : 2842 : rc = spdk_rpc_initialize(g_spdk_app.rpc_addr, &opts);
318 [ - + ]: 2842 : if (rc) {
319 : 0 : spdk_app_stop(rc);
320 : 0 : return;
321 : : }
322 : :
323 [ + + + - ]: 2842 : if (!g_delay_subsystem_init) {
324 : 2842 : spdk_rpc_set_state(SPDK_RPC_RUNTIME);
325 : 2842 : app_start_application();
326 : : }
327 : : }
328 : :
329 : : static int
330 : 8 : app_opts_add_pci_addr(struct spdk_app_opts *opts, struct spdk_pci_addr **list, char *bdf)
331 : : {
332 : 8 : struct spdk_pci_addr *tmp = *list;
333 : 8 : size_t i = opts->num_pci_addr;
334 : :
335 : 8 : tmp = realloc(tmp, sizeof(*tmp) * (i + 1));
336 [ - + ]: 8 : if (tmp == NULL) {
337 : 0 : SPDK_ERRLOG("realloc error\n");
338 : 0 : return -ENOMEM;
339 : : }
340 : :
341 : 8 : *list = tmp;
342 [ - + ]: 8 : if (spdk_pci_addr_parse(*list + i, bdf) < 0) {
343 : 0 : SPDK_ERRLOG("Invalid address %s\n", bdf);
344 : 0 : return -EINVAL;
345 : : }
346 : :
347 : 8 : opts->num_pci_addr++;
348 : 8 : return 0;
349 : : }
350 : :
351 : : static int
352 : 3098 : app_setup_env(struct spdk_app_opts *opts)
353 : : {
354 : 3098 : struct spdk_env_opts env_opts = {};
355 : : int rc;
356 : :
357 [ + + ]: 3098 : if (opts == NULL) {
358 : 60 : rc = spdk_env_init(NULL);
359 [ - + ]: 60 : if (rc != 0) {
360 : 0 : SPDK_ERRLOG("Unable to reinitialize SPDK env\n");
361 : : }
362 : :
363 : 60 : return rc;
364 : : }
365 : :
366 : 3038 : spdk_env_opts_init(&env_opts);
367 : :
368 : 3038 : env_opts.name = opts->name;
369 : 3038 : env_opts.core_mask = opts->reactor_mask;
370 : 3038 : env_opts.lcore_map = opts->lcore_map;
371 : 3038 : env_opts.shm_id = opts->shm_id;
372 : 3038 : env_opts.mem_channel = opts->mem_channel;
373 : 3038 : env_opts.main_core = opts->main_core;
374 : 3038 : env_opts.mem_size = opts->mem_size;
375 [ - + ]: 3038 : env_opts.hugepage_single_segments = opts->hugepage_single_segments;
376 [ - + ]: 3038 : env_opts.unlink_hugepage = opts->unlink_hugepage;
377 : 3038 : env_opts.hugedir = opts->hugedir;
378 [ - + ]: 3038 : env_opts.no_pci = opts->no_pci;
379 : 3038 : env_opts.num_pci_addr = opts->num_pci_addr;
380 : 3038 : env_opts.pci_blocked = opts->pci_blocked;
381 : 3038 : env_opts.pci_allowed = opts->pci_allowed;
382 : 3038 : env_opts.base_virtaddr = opts->base_virtaddr;
383 : 3038 : env_opts.env_context = opts->env_context;
384 : 3038 : env_opts.iova_mode = opts->iova_mode;
385 : 3038 : env_opts.vf_token = opts->vf_token;
386 [ - + ]: 3038 : env_opts.no_huge = opts->no_huge;
387 : :
388 : 3038 : rc = spdk_env_init(&env_opts);
389 : 3038 : free(env_opts.pci_blocked);
390 : 3038 : free(env_opts.pci_allowed);
391 : :
392 [ - + ]: 3038 : if (rc < 0) {
393 : 0 : SPDK_ERRLOG("Unable to initialize SPDK env\n");
394 : : }
395 : :
396 : 3038 : return rc;
397 : : }
398 : :
399 : : static int
400 : 3058 : app_setup_trace(struct spdk_app_opts *opts)
401 : : {
402 : 1351 : char shm_name[64];
403 : 3058 : uint64_t tpoint_group_mask, tpoint_mask = -1ULL;
404 : 3058 : char *end = NULL, *tpoint_group_mask_str, *tpoint_group_str = NULL;
405 : : char *tp_g_str, *tpoint_group, *tpoints;
406 : 3058 : bool error_found = false;
407 : : uint64_t group_id;
408 : :
409 [ + + ]: 3058 : if (opts->shm_id >= 0) {
410 : 376 : snprintf(shm_name, sizeof(shm_name), "/%s_trace.%d", opts->name, opts->shm_id);
411 : : } else {
412 : 2682 : snprintf(shm_name, sizeof(shm_name), "/%s_trace.pid%d", opts->name, (int)getpid());
413 : : }
414 : :
415 [ - + ]: 3058 : if (spdk_trace_init(shm_name, opts->num_entries, 0) != 0) {
416 : 0 : return -1;
417 : : }
418 : :
419 [ + + ]: 3058 : if (opts->tpoint_group_mask == NULL) {
420 : 2812 : return 0;
421 : : }
422 : :
423 [ - + ]: 246 : tpoint_group_mask_str = strdup(opts->tpoint_group_mask);
424 [ - + ]: 246 : if (tpoint_group_mask_str == NULL) {
425 : 0 : SPDK_ERRLOG("Unable to get string of tpoint group mask from opts.\n");
426 : 0 : return -1;
427 : : }
428 : : /* Save a pointer to the original value of the tpoint group mask string
429 : : * to free later, because spdk_strsepq() modifies given char*. */
430 : 246 : tp_g_str = tpoint_group_mask_str;
431 [ + + ]: 492 : while ((tpoint_group_str = spdk_strsepq(&tpoint_group_mask_str, ",")) != NULL) {
432 [ - + - + ]: 246 : if (strchr(tpoint_group_str, ':')) {
433 : : /* Get the tpoint group mask */
434 : 0 : tpoint_group = spdk_strsepq(&tpoint_group_str, ":");
435 : : /* Get the tpoint mask inside that group */
436 : 0 : tpoints = spdk_strsepq(&tpoint_group_str, ":");
437 : :
438 : 0 : errno = 0;
439 [ # # ]: 0 : tpoint_group_mask = strtoull(tpoint_group, &end, 16);
440 [ # # # # ]: 0 : if (*end != '\0' || errno) {
441 : 0 : tpoint_group_mask = spdk_trace_create_tpoint_group_mask(tpoint_group);
442 [ # # ]: 0 : if (tpoint_group_mask == 0) {
443 : 0 : error_found = true;
444 : 0 : break;
445 : : }
446 : : }
447 : : /* Check if tpoint group mask has only one bit set.
448 : : * This is to avoid enabling individual tpoints in
449 : : * more than one tracepoint group at once. */
450 [ # # ]: 0 : if (!spdk_u64_is_pow2(tpoint_group_mask)) {
451 : 0 : SPDK_ERRLOG("Tpoint group mask: %s contains multiple tpoint groups.\n", tpoint_group);
452 : 0 : SPDK_ERRLOG("This is not supported, to prevent from activating tpoints by mistake.\n");
453 : 0 : error_found = true;
454 : 0 : break;
455 : : }
456 : :
457 : 0 : errno = 0;
458 [ # # ]: 0 : tpoint_mask = strtoull(tpoints, &end, 16);
459 [ # # # # ]: 0 : if (*end != '\0' || errno) {
460 : 0 : error_found = true;
461 : 0 : break;
462 : : }
463 : : } else {
464 : 246 : errno = 0;
465 [ - + ]: 246 : tpoint_group_mask = strtoull(tpoint_group_str, &end, 16);
466 [ + + - + ]: 246 : if (*end != '\0' || errno) {
467 : 24 : tpoint_group_mask = spdk_trace_create_tpoint_group_mask(tpoint_group_str);
468 [ - + ]: 24 : if (tpoint_group_mask == 0) {
469 : 0 : error_found = true;
470 : 0 : break;
471 : : }
472 : : }
473 : 246 : tpoint_mask = -1ULL;
474 : : }
475 : :
476 [ + + ]: 4182 : for (group_id = 0; group_id < SPDK_TRACE_MAX_GROUP_ID; ++group_id) {
477 [ + + + + ]: 3936 : if (tpoint_group_mask & (1 << group_id)) {
478 : 3521 : spdk_trace_set_tpoints(group_id, tpoint_mask);
479 : : }
480 : : }
481 : : }
482 : :
483 [ - + ]: 246 : if (error_found) {
484 : 0 : SPDK_ERRLOG("invalid tpoint mask %s\n", opts->tpoint_group_mask);
485 : 0 : free(tp_g_str);
486 : 0 : return -1;
487 : : } else {
488 : 246 : SPDK_NOTICELOG("Tracepoint Group Mask %s specified.\n", opts->tpoint_group_mask);
489 [ + + + + ]: 246 : SPDK_NOTICELOG("Use 'spdk_trace -s %s %s %d' to capture a snapshot of events at runtime.\n",
490 : : opts->name,
491 : : opts->shm_id >= 0 ? "-i" : "-p",
492 : : opts->shm_id >= 0 ? opts->shm_id : getpid());
493 : : #if defined(__linux__)
494 : 246 : SPDK_NOTICELOG("Or copy /dev/shm%s for offline analysis/debug.\n", shm_name);
495 : : #endif
496 : : }
497 : 246 : free(tp_g_str);
498 : :
499 : 246 : return 0;
500 : : }
501 : :
502 : : static void
503 : 3058 : bootstrap_fn(void *arg1)
504 : : {
505 : 1351 : struct spdk_rpc_opts opts;
506 : : int rc;
507 : :
508 [ + + ]: 3058 : if (g_spdk_app.json_config_file) {
509 : 1521 : g_delay_subsystem_init = false;
510 : 1521 : spdk_subsystem_init_from_json_config(g_spdk_app.json_config_file, g_spdk_app.rpc_addr,
511 : : app_start_rpc,
512 [ - + ]: 1521 : NULL, !g_spdk_app.json_config_ignore_errors);
513 : : } else {
514 [ + + + + ]: 1537 : if (!g_delay_subsystem_init) {
515 : 1374 : spdk_subsystem_init(app_start_rpc, NULL);
516 : : } else {
517 : 163 : spdk_rpc_set_allowlist(g_spdk_app.rpc_allowlist);
518 : :
519 : 163 : opts.size = SPDK_SIZEOF(&opts, log_level);
520 : 163 : opts.log_file = g_spdk_app.rpc_log_file;
521 : 163 : opts.log_level = g_spdk_app.rpc_log_level;
522 : :
523 : 163 : rc = spdk_rpc_initialize(g_spdk_app.rpc_addr, &opts);
524 [ - + ]: 163 : if (rc) {
525 : 0 : spdk_app_stop(rc);
526 : 0 : return;
527 : : }
528 : : }
529 : : }
530 : : }
531 : :
532 : : static void
533 : 3098 : app_copy_opts(struct spdk_app_opts *opts, struct spdk_app_opts *opts_user, size_t opts_size)
534 : : {
535 : 3098 : spdk_app_opts_init(opts, sizeof(*opts));
536 : 3098 : opts->opts_size = opts_size;
537 : :
538 : : #define SET_FIELD(field) \
539 : : if (offsetof(struct spdk_app_opts, field) + sizeof(opts->field) <= (opts->opts_size)) { \
540 : : opts->field = opts_user->field; \
541 : : } \
542 : :
543 [ + - ]: 3098 : SET_FIELD(name);
544 [ + - ]: 3098 : SET_FIELD(json_config_file);
545 [ + - - + ]: 3098 : SET_FIELD(json_config_ignore_errors);
546 [ + - ]: 3098 : SET_FIELD(rpc_addr);
547 [ + - ]: 3098 : SET_FIELD(reactor_mask);
548 [ + - ]: 3098 : SET_FIELD(lcore_map);
549 [ + - ]: 3098 : SET_FIELD(tpoint_group_mask);
550 [ + - ]: 3098 : SET_FIELD(shm_id);
551 [ + - ]: 3098 : SET_FIELD(shutdown_cb);
552 [ + - - + ]: 3098 : SET_FIELD(enable_coredump);
553 [ + - ]: 3098 : SET_FIELD(mem_channel);
554 [ + - ]: 3098 : SET_FIELD(main_core);
555 [ + - ]: 3098 : SET_FIELD(mem_size);
556 [ + - - + ]: 3098 : SET_FIELD(no_pci);
557 [ + - - + ]: 3098 : SET_FIELD(hugepage_single_segments);
558 [ + - - + ]: 3098 : SET_FIELD(unlink_hugepage);
559 [ + - - + ]: 3098 : SET_FIELD(no_huge);
560 [ + - ]: 3098 : SET_FIELD(hugedir);
561 [ + - ]: 3098 : SET_FIELD(print_level);
562 [ + - ]: 3098 : SET_FIELD(num_pci_addr);
563 [ + - ]: 3098 : SET_FIELD(pci_blocked);
564 [ + - ]: 3098 : SET_FIELD(pci_allowed);
565 [ + - ]: 3098 : SET_FIELD(iova_mode);
566 [ + - - + ]: 3098 : SET_FIELD(delay_subsystem_init);
567 [ + - ]: 3098 : SET_FIELD(num_entries);
568 [ + - ]: 3098 : SET_FIELD(env_context);
569 [ + - ]: 3098 : SET_FIELD(log);
570 [ + - ]: 3098 : SET_FIELD(base_virtaddr);
571 [ + - - + ]: 3098 : SET_FIELD(disable_signal_handlers);
572 [ + - - + ]: 3098 : SET_FIELD(interrupt_mode);
573 [ + - ]: 3098 : SET_FIELD(msg_mempool_size);
574 [ + - ]: 3098 : SET_FIELD(rpc_allowlist);
575 [ + - ]: 3098 : SET_FIELD(vf_token);
576 [ + - ]: 3098 : SET_FIELD(rpc_log_file);
577 [ + - ]: 3098 : SET_FIELD(rpc_log_level);
578 : :
579 : : /* You should not remove this statement, but need to update the assert statement
580 : : * if you add a new field, and also add a corresponding SET_FIELD statement */
581 : : SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 236, "Incorrect size");
582 : :
583 : : #undef SET_FIELD
584 : 3098 : }
585 : :
586 : : static int
587 : 3178 : unclaim_cpu_cores(uint32_t *failed_core)
588 : : {
589 : 1405 : char core_name[40];
590 : : uint32_t i;
591 : : int rc;
592 : :
593 [ + + ]: 409327 : for (i = 0; i < MAX_CPU_CORES; i++) {
594 [ + + ]: 406154 : if (g_core_locks[i] != -1) {
595 : 4329 : snprintf(core_name, sizeof(core_name), "/var/tmp/spdk_cpu_lock_%03d", i);
596 : 4329 : rc = close(g_core_locks[i]);
597 [ - + ]: 4329 : if (rc) {
598 : 0 : SPDK_ERRLOG("Failed to close lock fd for core %d, errno: %d\n", i, errno);
599 : 0 : goto error;
600 : : }
601 : :
602 : 4329 : g_core_locks[i] = -1;
603 : 4329 : rc = unlink(core_name);
604 [ + + ]: 4329 : if (rc) {
605 : 5 : SPDK_ERRLOG("Failed to unlink lock fd for core %d, errno: %d\n", i, errno);
606 : 5 : goto error;
607 : : }
608 : : }
609 : : }
610 : :
611 : 3173 : return 0;
612 : :
613 : 5 : error:
614 [ - + ]: 5 : if (failed_core != NULL) {
615 : : /* Set number of core we failed to claim. */
616 : 0 : *failed_core = i;
617 : : }
618 : 5 : return -1;
619 : : }
620 : :
621 : : static int
622 : 3075 : claim_cpu_cores(uint32_t *failed_core)
623 : : {
624 : 1360 : char core_name[40];
625 : : int core_fd, pid;
626 : : int *core_map;
627 : : uint32_t core;
628 : :
629 : 3075 : struct flock core_lock = {
630 : : .l_type = F_WRLCK,
631 : : .l_whence = SEEK_SET,
632 : : .l_start = 0,
633 : : .l_len = 0,
634 : : };
635 : :
636 [ + + ]: 7419 : SPDK_ENV_FOREACH_CORE(core) {
637 [ - + ]: 4404 : if (g_core_locks[core] != -1) {
638 : : /* If this core is locked already, do not try lock it again. */
639 : 0 : continue;
640 : : }
641 : :
642 : 4404 : snprintf(core_name, sizeof(core_name), "/var/tmp/spdk_cpu_lock_%03d", core);
643 : 4404 : core_fd = open(core_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
644 [ - + ]: 4404 : if (core_fd == -1) {
645 : 0 : SPDK_ERRLOG("Could not open %s (%s).\n", core_name, spdk_strerror(errno));
646 : : /* Return number of core we failed to claim. */
647 : 0 : goto error;
648 : : }
649 : :
650 [ - + ]: 4404 : if (ftruncate(core_fd, sizeof(int)) != 0) {
651 : 0 : SPDK_ERRLOG("Could not truncate %s (%s).\n", core_name, spdk_strerror(errno));
652 : 0 : close(core_fd);
653 : 0 : goto error;
654 : : }
655 : :
656 : 4404 : core_map = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, core_fd, 0);
657 [ - + ]: 4404 : if (core_map == MAP_FAILED) {
658 : 0 : SPDK_ERRLOG("Could not mmap core %s (%s).\n", core_name, spdk_strerror(errno));
659 : 0 : close(core_fd);
660 : 0 : goto error;
661 : : }
662 : :
663 [ + + ]: 4404 : if (fcntl(core_fd, F_SETLK, &core_lock) != 0) {
664 : 60 : pid = *core_map;
665 : 60 : SPDK_ERRLOG("Cannot create lock on core %" PRIu32 ", probably process %d has claimed it.\n",
666 : : core, pid);
667 : 60 : munmap(core_map, sizeof(int));
668 : 60 : close(core_fd);
669 : 60 : goto error;
670 : : }
671 : :
672 : : /* We write the PID to the core lock file so that other processes trying
673 : : * to claim the same core will know what process is holding the lock. */
674 : 4344 : *core_map = (int)getpid();
675 : 4344 : munmap(core_map, sizeof(int));
676 : 4344 : g_core_locks[core] = core_fd;
677 : : /* Keep core_fd open to maintain the lock. */
678 : : }
679 : :
680 : 3015 : return 0;
681 : :
682 : 60 : error:
683 [ + + ]: 60 : if (failed_core != NULL) {
684 : : /* Set number of core we failed to claim. */
685 : 20 : *failed_core = core;
686 : : }
687 : 60 : unclaim_cpu_cores(NULL);
688 : 60 : return -1;
689 : : }
690 : :
691 : : int
692 : 3098 : spdk_app_start(struct spdk_app_opts *opts_user, spdk_msg_fn start_fn,
693 : : void *arg1)
694 : : {
695 : : int rc;
696 : : char *tty;
697 : 3098 : struct spdk_cpuset tmp_cpumask = {};
698 : : static bool g_env_was_setup = false;
699 : 3098 : struct spdk_app_opts opts_local = {};
700 : 3098 : struct spdk_app_opts *opts = &opts_local;
701 : : uint32_t i;
702 : :
703 [ - + ]: 3098 : if (!opts_user) {
704 : 0 : SPDK_ERRLOG("opts_user should not be NULL\n");
705 : 0 : return 1;
706 : : }
707 : :
708 [ - + ]: 3098 : if (!opts_user->opts_size) {
709 : 0 : SPDK_ERRLOG("The opts_size in opts_user structure should not be zero value\n");
710 : 0 : return 1;
711 : : }
712 : :
713 [ - + ]: 3098 : if (opts_user->name == NULL) {
714 : 0 : SPDK_ERRLOG("spdk_app_opts::name not specified\n");
715 : 0 : return 1;
716 : : }
717 : :
718 : 3098 : app_copy_opts(opts, opts_user, opts_user->opts_size);
719 : :
720 [ - + ]: 3098 : if (!start_fn) {
721 : 0 : SPDK_ERRLOG("start_fn should not be NULL\n");
722 : 0 : return 1;
723 : : }
724 : :
725 [ + - + + ]: 3098 : if (!(opts->lcore_map || opts->reactor_mask)) {
726 : : /* Set default CPU mask */
727 : 538 : opts->reactor_mask = SPDK_APP_DPDK_DEFAULT_CORE_MASK;
728 : : }
729 : :
730 : 3098 : tty = ttyname(STDERR_FILENO);
731 [ + - - + ]: 6196 : if (opts->print_level > SPDK_LOG_WARN &&
732 [ - - ]: 3098 : isatty(STDERR_FILENO) &&
733 : 0 : tty &&
734 [ # # # # ]: 0 : !strncmp(tty, "/dev/tty", strlen("/dev/tty"))) {
735 : 0 : printf("Warning: printing stderr to console terminal without -q option specified.\n");
736 : 0 : printf("Suggest using --silence-noticelog to disable logging to stderr and\n");
737 : 0 : printf("monitor syslog, or redirect stderr to a file.\n");
738 : 0 : printf("(Delaying for 10 seconds...)\n");
739 : 0 : sleep(10);
740 : : }
741 : :
742 : 3098 : spdk_log_set_print_level(opts->print_level);
743 : :
744 : : #ifndef SPDK_NO_RLIMIT
745 [ + + + - ]: 3098 : if (opts->enable_coredump) {
746 : 1369 : struct rlimit core_limits;
747 : :
748 : 3098 : core_limits.rlim_cur = core_limits.rlim_max = SPDK_APP_DEFAULT_CORE_LIMIT;
749 : 3098 : setrlimit(RLIMIT_CORE, &core_limits);
750 : : }
751 : : #endif
752 : :
753 [ - + + + ]: 3098 : if (opts->interrupt_mode) {
754 : 1 : spdk_interrupt_mode_enable();
755 : : }
756 : :
757 : 3098 : memset(&g_spdk_app, 0, sizeof(g_spdk_app));
758 : 3098 : g_spdk_app.json_config_file = opts->json_config_file;
759 [ - + ]: 3098 : g_spdk_app.json_config_ignore_errors = opts->json_config_ignore_errors;
760 : 3098 : g_spdk_app.rpc_addr = opts->rpc_addr;
761 : 3098 : g_spdk_app.rpc_allowlist = opts->rpc_allowlist;
762 : 3098 : g_spdk_app.rpc_log_file = opts->rpc_log_file;
763 : 3098 : g_spdk_app.rpc_log_level = opts->rpc_log_level;
764 : 3098 : g_spdk_app.shm_id = opts->shm_id;
765 : 3098 : g_spdk_app.shutdown_cb = opts->shutdown_cb;
766 : 3098 : g_spdk_app.rc = 0;
767 : 3098 : g_spdk_app.stopped = false;
768 : :
769 : 3098 : spdk_log_set_level(SPDK_APP_DEFAULT_LOG_LEVEL);
770 : :
771 : : /* Pass NULL to app_setup_env if SPDK app has been set up, in order to
772 : : * indicate that this is a reinitialization.
773 : : */
774 [ + + + + : 3098 : if (app_setup_env(g_env_was_setup ? NULL : opts) < 0) {
- + ]
775 : 0 : return 1;
776 : : }
777 : :
778 : : /* Calculate mempool size now that the env layer has configured the core count
779 : : * for the application */
780 : 3098 : calculate_mempool_size(opts, opts_user);
781 : :
782 : 3098 : spdk_log_open(opts->log);
783 : :
784 : : /* Initialize each lock to -1 to indicate "empty" status */
785 [ + + ]: 399642 : for (i = 0; i < MAX_CPU_CORES; i++) {
786 : 396544 : g_core_locks[i] = -1;
787 : : }
788 : :
789 [ + + + + ]: 3098 : if (!g_disable_cpumask_locks) {
790 [ + + ]: 3015 : if (claim_cpu_cores(NULL)) {
791 : 40 : SPDK_ERRLOG("Unable to acquire lock on assigned core mask - exiting.\n");
792 : 40 : return 1;
793 : : }
794 : : } else {
795 : 83 : SPDK_NOTICELOG("CPU core locks deactivated.\n");
796 : : }
797 : :
798 : 3058 : SPDK_NOTICELOG("Total cores available: %d\n", spdk_env_get_core_count());
799 : :
800 [ - + ]: 3058 : if ((rc = spdk_reactors_init(opts->msg_mempool_size)) != 0) {
801 : 0 : SPDK_ERRLOG("Reactor Initialization failed: rc = %d\n", rc);
802 : 0 : return 1;
803 : : }
804 : :
805 : 3058 : spdk_cpuset_set_cpu(&tmp_cpumask, spdk_env_get_current_core(), true);
806 : :
807 : : /* Now that the reactors have been initialized, we can create the app thread. */
808 : 3058 : spdk_thread_create("app_thread", &tmp_cpumask);
809 [ - + ]: 3058 : if (!spdk_thread_get_app_thread()) {
810 : 0 : SPDK_ERRLOG("Unable to create an spdk_thread for initialization\n");
811 : 0 : return 1;
812 : : }
813 : :
814 : : /*
815 : : * Disable and ignore trace setup if setting num_entries
816 : : * to be 0.
817 : : *
818 : : * Note the call to app_setup_trace() is located here
819 : : * ahead of app_setup_signal_handlers().
820 : : * That's because there is not an easy/direct clean
821 : : * way of unwinding alloc'd resources that can occur
822 : : * in app_setup_signal_handlers().
823 : : */
824 [ + - - + ]: 3058 : if (opts->num_entries != 0 && app_setup_trace(opts) != 0) {
825 : 0 : return 1;
826 : : }
827 : :
828 [ + + + + : 3058 : if (!opts->disable_signal_handlers && app_setup_signal_handlers(opts) != 0) {
- + ]
829 : 0 : return 1;
830 : : }
831 : :
832 [ - + ]: 3058 : g_delay_subsystem_init = opts->delay_subsystem_init;
833 : 3058 : g_start_fn = start_fn;
834 : 3058 : g_start_arg = arg1;
835 : :
836 : 3058 : spdk_thread_send_msg(spdk_thread_get_app_thread(), bootstrap_fn, NULL);
837 : :
838 : : /* This blocks until spdk_app_stop is called */
839 : 3058 : spdk_reactors_start();
840 : :
841 : 3058 : g_env_was_setup = true;
842 : :
843 : 3058 : return g_spdk_app.rc;
844 : : }
845 : :
846 : : void
847 : 3098 : spdk_app_fini(void)
848 : : {
849 : 3098 : spdk_trace_cleanup();
850 : 3098 : spdk_reactors_fini();
851 : 3098 : spdk_env_fini();
852 : 3098 : spdk_log_close();
853 : 3098 : unclaim_cpu_cores(NULL);
854 : 3098 : }
855 : :
856 : : static void
857 : 3058 : subsystem_fini_done(void *arg1)
858 : : {
859 : 3058 : spdk_rpc_finish();
860 : 3058 : spdk_reactors_stop(NULL);
861 : 3058 : }
862 : :
863 : : static void
864 : 3312 : _start_subsystem_fini(void *arg1)
865 : : {
866 [ + + + + ]: 3312 : if (g_scheduling_in_progress) {
867 : 254 : spdk_thread_send_msg(spdk_thread_get_app_thread(), _start_subsystem_fini, NULL);
868 : 254 : return;
869 : : }
870 : :
871 : 3058 : spdk_subsystem_fini(subsystem_fini_done, NULL);
872 : : }
873 : :
874 : : static int
875 : 12054 : log_deprecation_hits(void *ctx, struct spdk_deprecation *dep)
876 : : {
877 : 12054 : uint64_t hits = spdk_deprecation_get_hits(dep);
878 : :
879 [ + + ]: 12054 : if (hits == 0) {
880 : 12013 : return 0;
881 : : }
882 : :
883 : 41 : SPDK_WARNLOG("%s: deprecation '%s' scheduled for removal in %s hit %" PRIu64 " times\n",
884 : : spdk_deprecation_get_tag(dep), spdk_deprecation_get_description(dep),
885 : : spdk_deprecation_get_remove_release(dep), hits);
886 : 41 : return 0;
887 : : }
888 : :
889 : : static void
890 : 3058 : app_stop(void *arg1)
891 : : {
892 [ + - ]: 3058 : if (g_spdk_app.rc == 0) {
893 : 3058 : g_spdk_app.rc = (int)(intptr_t)arg1;
894 : : }
895 : :
896 [ - + - + ]: 3058 : if (g_spdk_app.stopped) {
897 : 0 : SPDK_NOTICELOG("spdk_app_stop called twice\n");
898 : 0 : return;
899 : : }
900 : :
901 : 3058 : g_spdk_app.stopped = true;
902 : 3058 : spdk_log_for_each_deprecation(NULL, log_deprecation_hits);
903 : 3058 : _start_subsystem_fini(NULL);
904 : : }
905 : :
906 : : void
907 : 3058 : spdk_app_stop(int rc)
908 : : {
909 [ + + ]: 3058 : if (rc) {
910 : 179 : SPDK_WARNLOG("spdk_app_stop'd on non-zero\n");
911 : : }
912 : :
913 : : /*
914 : : * We want to run spdk_subsystem_fini() from the same thread where spdk_subsystem_init()
915 : : * was called.
916 : : */
917 : 3058 : spdk_thread_send_msg(spdk_thread_get_app_thread(), app_stop, (void *)(intptr_t)rc);
918 : 3058 : }
919 : :
920 : : static void
921 : 42 : usage(void (*app_usage)(void))
922 : : {
923 [ - + ]: 42 : printf("%s [options]\n", g_executable_name);
924 [ - + ]: 42 : printf("options:\n");
925 [ - + ]: 42 : printf(" -c, --config <config> JSON config file (default %s)\n",
926 [ - + ]: 42 : g_default_opts.json_config_file != NULL ? g_default_opts.json_config_file : "none");
927 [ - + ]: 42 : printf(" --json <config> JSON config file (default %s)\n",
928 [ - + ]: 42 : g_default_opts.json_config_file != NULL ? g_default_opts.json_config_file : "none");
929 [ - + ]: 42 : printf(" --json-ignore-init-errors\n");
930 [ - + ]: 42 : printf(" don't exit on invalid config entry\n");
931 [ - + ]: 42 : printf(" -d, --limit-coredump do not set max coredump size to RLIM_INFINITY\n");
932 [ - + ]: 42 : printf(" -g, --single-file-segments\n");
933 [ - + ]: 42 : printf(" force creating just one hugetlbfs file\n");
934 [ - + ]: 42 : printf(" -h, --help show this usage\n");
935 [ - + ]: 42 : printf(" -i, --shm-id <id> shared memory ID (optional)\n");
936 [ - + ]: 42 : printf(" -m, --cpumask <mask or list> core mask (like 0xF) or core list of '[]' embraced (like [0,1,10]) for DPDK\n");
937 [ - + ]: 42 : printf(" --lcores <list> lcore to CPU mapping list. The list is in the format:\n");
938 [ - + ]: 42 : printf(" <lcores[@CPUs]>[<,lcores[@CPUs]>...]\n");
939 [ - + ]: 42 : printf(" lcores and cpus list are grouped by '(' and ')', e.g '--lcores \"(5-7)@(10-12)\"'\n");
940 [ - + ]: 42 : printf(" Within the group, '-' is used for range separator,\n");
941 [ - + ]: 42 : printf(" ',' is used for single number separator.\n");
942 [ - + ]: 42 : printf(" '( )' can be omitted for single element group,\n");
943 [ - + ]: 42 : printf(" '@' can be omitted if cpus and lcores have the same value\n");
944 [ - + ]: 42 : printf(" -n, --mem-channels <num> channel number of memory channels used for DPDK\n");
945 [ - + ]: 42 : printf(" -p, --main-core <id> main (primary) core for DPDK\n");
946 [ - + ]: 42 : printf(" -r, --rpc-socket <path> RPC listen address (default %s)\n", SPDK_DEFAULT_RPC_ADDR);
947 [ - + ]: 42 : printf(" -s, --mem-size <size> memory size in MB for DPDK (default: ");
948 : : #ifndef __linux__
949 : : if (g_default_opts.mem_size <= 0) {
950 : : printf("all hugepage memory)\n");
951 : : } else
952 : : #endif
953 : : {
954 [ - + ]: 42 : printf("%dMB)\n", g_default_opts.mem_size >= 0 ? g_default_opts.mem_size : 0);
955 : : }
956 [ - + ]: 42 : printf(" --disable-cpumask-locks Disable CPU core lock files.\n");
957 [ - + ]: 42 : printf(" --silence-noticelog disable notice level logging to stderr\n");
958 [ - + ]: 42 : printf(" --msg-mempool-size <size> global message memory pool size in count (default: %d)\n",
959 : : SPDK_DEFAULT_MSG_MEMPOOL_SIZE);
960 [ - + ]: 42 : printf(" -u, --no-pci disable PCI access\n");
961 [ - + ]: 42 : printf(" --wait-for-rpc wait for RPCs to initialize subsystems\n");
962 [ - + ]: 42 : printf(" --max-delay <num> maximum reactor delay (in microseconds)\n");
963 [ - + ]: 42 : printf(" -B, --pci-blocked <bdf> pci addr to block (can be used more than once)\n");
964 [ - + ]: 42 : printf(" -A, --pci-allowed <bdf> pci addr to allow (-B and -A cannot be used at the same time)\n");
965 [ - + ]: 42 : printf(" -R, --huge-unlink unlink huge files after initialization\n");
966 [ - + ]: 42 : printf(" -v, --version print SPDK version\n");
967 [ - + ]: 42 : printf(" --huge-dir <path> use a specific hugetlbfs mount to reserve memory from\n");
968 [ - + ]: 42 : printf(" --iova-mode <pa/va> set IOVA mode ('pa' for IOVA_PA and 'va' for IOVA_VA)\n");
969 [ - + ]: 42 : printf(" --base-virtaddr <addr> the base virtual address for DPDK (default: 0x200000000000)\n");
970 [ - + ]: 42 : printf(" --num-trace-entries <num> number of trace entries for each core, must be power of 2, setting 0 to disable trace (default %d)\n",
971 : : SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES);
972 [ - + ]: 42 : printf(" Tracepoints vary in size and can use more than one trace entry.\n");
973 [ - + ]: 42 : printf(" --rpcs-allowed comma-separated list of permitted RPCS\n");
974 [ - + ]: 42 : printf(" --env-context Opaque context for use of the env implementation\n");
975 [ - + ]: 42 : printf(" --vfio-vf-token VF token (UUID) shared between SR-IOV PF and VFs for vfio_pci driver\n");
976 [ - + ]: 42 : printf(" --no-huge run without using hugepages\n");
977 : 42 : spdk_log_usage(stdout, "-L");
978 : 42 : spdk_trace_mask_usage(stdout, "-e");
979 [ - + ]: 42 : printf(" --interrupt-mode set app to interrupt mode (Warning: CPU usage will be reduced only if all pollers in the app support interrupt mode)\n");
980 [ + + ]: 42 : if (app_usage) {
981 : 30 : app_usage();
982 : : }
983 : 42 : }
984 : :
985 : : spdk_app_parse_args_rvals_t
986 : 3108 : spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts,
987 : : const char *app_getopt_str, const struct option *app_long_opts,
988 : : int (*app_parse)(int ch, char *arg),
989 : : void (*app_usage)(void))
990 : : {
991 : 1400 : int ch, rc, opt_idx, global_long_opts_len, app_long_opts_len;
992 : : struct option *cmdline_options;
993 : 3108 : char *cmdline_short_opts = NULL;
994 : 3108 : char *shm_id_str = NULL;
995 : 3108 : enum spdk_app_parse_args_rvals retval = SPDK_APP_PARSE_ARGS_FAIL;
996 : : long int tmp;
997 : :
998 : 3108 : memcpy(&g_default_opts, opts, sizeof(g_default_opts));
999 : :
1000 [ + + - + : 3108 : if (opts->json_config_file && access(opts->json_config_file, R_OK) != 0) {
- + ]
1001 : 0 : SPDK_WARNLOG("Can't read JSON configuration file '%s'\n", opts->json_config_file);
1002 : 0 : opts->json_config_file = NULL;
1003 : : }
1004 : :
1005 [ + + ]: 3108 : if (app_long_opts == NULL) {
1006 : 2583 : app_long_opts_len = 0;
1007 : : } else {
1008 : 525 : for (app_long_opts_len = 0;
1009 [ + + ]: 7302 : app_long_opts[app_long_opts_len].name != NULL;
1010 : 6777 : app_long_opts_len++);
1011 : : }
1012 : :
1013 : 3108 : global_long_opts_len = SPDK_COUNTOF(g_cmdline_options);
1014 : :
1015 : 3108 : cmdline_options = calloc(global_long_opts_len + app_long_opts_len + 1, sizeof(*cmdline_options));
1016 [ - + ]: 3108 : if (!cmdline_options) {
1017 : 0 : SPDK_ERRLOG("Out of memory\n");
1018 : 0 : return SPDK_APP_PARSE_ARGS_FAIL;
1019 : : }
1020 : :
1021 [ - + - + ]: 3108 : memcpy(&cmdline_options[0], g_cmdline_options, sizeof(g_cmdline_options));
1022 [ + + ]: 3108 : if (app_long_opts) {
1023 [ - + - + ]: 525 : memcpy(&cmdline_options[global_long_opts_len], app_long_opts,
1024 : : app_long_opts_len * sizeof(*app_long_opts));
1025 : : }
1026 : :
1027 [ + - ]: 3108 : if (app_getopt_str != NULL) {
1028 : 3108 : ch = app_opts_validate(app_getopt_str);
1029 [ + + ]: 3108 : if (ch) {
1030 : 4 : SPDK_ERRLOG("Duplicated option '%c' between app-specific command line parameter and generic spdk opts.\n",
1031 : : ch);
1032 : 4 : goto out;
1033 : : }
1034 : :
1035 [ - + ]: 3104 : if (!app_parse) {
1036 : 0 : SPDK_ERRLOG("Parse function is required when app-specific command line parameters are provided.\n");
1037 : 0 : goto out;
1038 : : }
1039 : : }
1040 : :
1041 : 3104 : cmdline_short_opts = spdk_sprintf_alloc("%s%s", app_getopt_str, SPDK_APP_GETOPT_STRING);
1042 [ - + ]: 3104 : if (!cmdline_short_opts) {
1043 : 0 : SPDK_ERRLOG("Out of memory\n");
1044 : 0 : goto out;
1045 : : }
1046 : :
1047 : 3104 : g_executable_name = argv[0];
1048 : :
1049 [ + + - + : 15186 : while ((ch = getopt_long(argc, argv, cmdline_short_opts, cmdline_options, &opt_idx)) != -1) {
+ + ]
1050 [ + - + + : 12170 : switch (ch) {
+ + + + -
+ - + - +
+ - + + +
+ + + + -
- - - + -
- + - + -
+ + ]
1051 : 1586 : case CONFIG_FILE_OPT_IDX:
1052 : : case JSON_CONFIG_OPT_IDX:
1053 : 1586 : opts->json_config_file = optarg;
1054 : 1586 : break;
1055 : 0 : case JSON_CONFIG_IGNORE_INIT_ERRORS_IDX:
1056 : 0 : opts->json_config_ignore_errors = true;
1057 : 0 : break;
1058 : 21 : case LIMIT_COREDUMP_OPT_IDX:
1059 : 21 : opts->enable_coredump = false;
1060 : 21 : break;
1061 : 242 : case TPOINT_GROUP_OPT_IDX:
1062 : 242 : opts->tpoint_group_mask = optarg;
1063 : 242 : break;
1064 : 34 : case SINGLE_FILE_SEGMENTS_OPT_IDX:
1065 : 34 : opts->hugepage_single_segments = true;
1066 : 34 : break;
1067 : 22 : case HELP_OPT_IDX:
1068 : 22 : usage(app_usage);
1069 : 22 : retval = SPDK_APP_PARSE_ARGS_HELP;
1070 : 22 : goto out;
1071 : 370 : case SHM_ID_OPT_IDX:
1072 : 370 : shm_id_str = optarg;
1073 : : /* a negative shm-id disables shared configuration file */
1074 [ - + ]: 370 : if (optarg[0] == '-') {
1075 : 0 : shm_id_str++;
1076 : : }
1077 : : /* check if the positive value of provided shm_id can be parsed as
1078 : : * an integer
1079 : : */
1080 : 370 : opts->shm_id = spdk_strtol(shm_id_str, 0);
1081 [ - + ]: 370 : if (opts->shm_id < 0) {
1082 : 0 : SPDK_ERRLOG("Invalid shared memory ID %s\n", optarg);
1083 : 0 : goto out;
1084 : : }
1085 [ - + ]: 370 : if (optarg[0] == '-') {
1086 : 0 : opts->shm_id = -opts->shm_id;
1087 : : }
1088 : 370 : break;
1089 : 975 : case CPUMASK_OPT_IDX:
1090 [ - + ]: 975 : if (opts->lcore_map) {
1091 : 0 : SPDK_ERRLOG("lcore map and core mask can't be set simultaneously\n");
1092 : 0 : goto out;
1093 : : }
1094 : 975 : opts->reactor_mask = optarg;
1095 : 975 : break;
1096 : 0 : case LCORES_OPT_IDX:
1097 [ # # ]: 0 : if (opts->reactor_mask) {
1098 : 0 : SPDK_ERRLOG("lcore map and core mask can't be set simultaneously\n");
1099 : 0 : goto out;
1100 : : }
1101 : 0 : opts->lcore_map = optarg;
1102 : 0 : break;
1103 : 83 : case DISABLE_CPUMASK_LOCKS_OPT_IDX:
1104 : 83 : g_disable_cpumask_locks = true;
1105 : 83 : break;
1106 : 0 : case MEM_CHANNELS_OPT_IDX:
1107 : 0 : opts->mem_channel = spdk_strtol(optarg, 0);
1108 [ # # ]: 0 : if (opts->mem_channel < 0) {
1109 : 0 : SPDK_ERRLOG("Invalid memory channel %s\n", optarg);
1110 : 0 : goto out;
1111 : : }
1112 : 0 : break;
1113 : 73 : case MAIN_CORE_OPT_IDX:
1114 : 73 : opts->main_core = spdk_strtol(optarg, 0);
1115 [ + + ]: 73 : if (opts->main_core < 0) {
1116 : 4 : SPDK_ERRLOG("Invalid main core %s\n", optarg);
1117 : 4 : goto out;
1118 : : }
1119 : 69 : break;
1120 : 0 : case SILENCE_NOTICELOG_OPT_IDX:
1121 : 0 : opts->print_level = SPDK_LOG_WARN;
1122 : 0 : break;
1123 : 594 : case RPC_SOCKET_OPT_IDX:
1124 : 594 : opts->rpc_addr = optarg;
1125 : 594 : break;
1126 : 121 : case MEM_SIZE_OPT_IDX: {
1127 : 40 : uint64_t mem_size_mb;
1128 : 40 : bool mem_size_has_prefix;
1129 : :
1130 : 121 : rc = spdk_parse_capacity(optarg, &mem_size_mb, &mem_size_has_prefix);
1131 [ - + ]: 121 : if (rc != 0) {
1132 : 0 : SPDK_ERRLOG("invalid memory pool size `-s %s`\n", optarg);
1133 : 0 : usage(app_usage);
1134 : 0 : goto out;
1135 : : }
1136 : :
1137 [ - + - + ]: 121 : if (mem_size_has_prefix) {
1138 : : /* the mem size is in MB by default, so if a prefix was
1139 : : * specified, we need to manually convert to MB.
1140 : : */
1141 : 0 : mem_size_mb /= 1024 * 1024;
1142 : : }
1143 : :
1144 [ - + ]: 121 : if (mem_size_mb > INT_MAX) {
1145 : 0 : SPDK_ERRLOG("invalid memory pool size `-s %s`\n", optarg);
1146 : 0 : usage(app_usage);
1147 : 0 : goto out;
1148 : : }
1149 : :
1150 : 121 : opts->mem_size = (int) mem_size_mb;
1151 : 121 : break;
1152 : : }
1153 : 0 : case MSG_MEMPOOL_SIZE_OPT_IDX:
1154 : 0 : tmp = spdk_strtol(optarg, 10);
1155 [ # # ]: 0 : if (tmp <= 0) {
1156 : 0 : SPDK_ERRLOG("Invalid message memory pool size %s\n", optarg);
1157 : 0 : goto out;
1158 : : }
1159 : :
1160 : 0 : opts->msg_mempool_size = (size_t)tmp;
1161 : 0 : break;
1162 : :
1163 : 6 : case NO_PCI_OPT_IDX:
1164 : 6 : opts->no_pci = true;
1165 : 6 : break;
1166 : 163 : case WAIT_FOR_RPC_OPT_IDX:
1167 : 163 : opts->delay_subsystem_init = true;
1168 : 163 : break;
1169 : 8 : case PCI_BLOCKED_OPT_IDX:
1170 [ - + ]: 8 : if (opts->pci_allowed) {
1171 : 0 : free(opts->pci_allowed);
1172 : 0 : opts->pci_allowed = NULL;
1173 : 0 : SPDK_ERRLOG("-B and -A cannot be used at the same time\n");
1174 : 0 : usage(app_usage);
1175 : 0 : goto out;
1176 : : }
1177 : :
1178 : 8 : rc = app_opts_add_pci_addr(opts, &opts->pci_blocked, optarg);
1179 [ - + ]: 8 : if (rc != 0) {
1180 : 0 : free(opts->pci_blocked);
1181 : 0 : opts->pci_blocked = NULL;
1182 : 0 : goto out;
1183 : : }
1184 : 8 : break;
1185 : :
1186 : 6 : case NO_HUGE_OPT_IDX:
1187 : 6 : opts->no_huge = true;
1188 : 6 : break;
1189 : :
1190 : 202 : case LOGFLAG_OPT_IDX:
1191 : 202 : rc = spdk_log_set_flag(optarg);
1192 [ - + ]: 202 : if (rc < 0) {
1193 : 0 : SPDK_ERRLOG("unknown flag: %s\n", optarg);
1194 : 0 : usage(app_usage);
1195 : 0 : goto out;
1196 : : }
1197 : : #ifdef DEBUG
1198 : 202 : opts->print_level = SPDK_LOG_DEBUG;
1199 : : #endif
1200 : 202 : break;
1201 : 1 : case HUGE_UNLINK_OPT_IDX:
1202 : 1 : opts->unlink_hugepage = true;
1203 : 1 : break;
1204 : 4 : case PCI_WHITELIST_OPT_IDX:
1205 : 4 : SPDK_WARNLOG("-W/--pci-whitelist is deprecated. Use -A/--pci-allowed.\n");
1206 : : /* fallthrough */
1207 : 4 : case PCI_ALLOWED_OPT_IDX:
1208 [ + - ]: 4 : if (opts->pci_blocked) {
1209 : 4 : free(opts->pci_blocked);
1210 : 4 : opts->pci_blocked = NULL;
1211 : 4 : SPDK_ERRLOG("-B and -W cannot be used at the same time\n");
1212 : 4 : usage(app_usage);
1213 : 4 : goto out;
1214 : : }
1215 : :
1216 : 0 : rc = app_opts_add_pci_addr(opts, &opts->pci_allowed, optarg);
1217 [ # # ]: 0 : if (rc != 0) {
1218 : 0 : free(opts->pci_allowed);
1219 : 0 : opts->pci_allowed = NULL;
1220 : 0 : goto out;
1221 : : }
1222 : 0 : break;
1223 : 0 : case BASE_VIRTADDR_OPT_IDX:
1224 : 0 : tmp = spdk_strtoll(optarg, 0);
1225 [ # # ]: 0 : if (tmp <= 0) {
1226 : 0 : SPDK_ERRLOG("Invalid base-virtaddr %s\n", optarg);
1227 : 0 : usage(app_usage);
1228 : 0 : goto out;
1229 : : }
1230 : 0 : opts->base_virtaddr = (uint64_t)tmp;
1231 : 0 : break;
1232 : 0 : case HUGE_DIR_OPT_IDX:
1233 : 0 : opts->hugedir = optarg;
1234 : 0 : break;
1235 : 0 : case IOVA_MODE_OPT_IDX:
1236 : 0 : opts->iova_mode = optarg;
1237 : 0 : break;
1238 : 2 : case NUM_TRACE_ENTRIES_OPT_IDX:
1239 : 2 : tmp = spdk_strtoll(optarg, 0);
1240 [ - + ]: 2 : if (tmp < 0) {
1241 : 0 : SPDK_ERRLOG("Invalid num-trace-entries %s\n", optarg);
1242 : 0 : usage(app_usage);
1243 : 0 : goto out;
1244 : : }
1245 : 2 : opts->num_entries = (uint64_t)tmp;
1246 [ + - - + ]: 2 : if (opts->num_entries > 0 && opts->num_entries & (opts->num_entries - 1)) {
1247 : 0 : SPDK_ERRLOG("num-trace-entries must be power of 2\n");
1248 : 0 : usage(app_usage);
1249 : 0 : goto out;
1250 : : }
1251 : 2 : break;
1252 : 0 : case MAX_REACTOR_DELAY_OPT_IDX:
1253 : 0 : SPDK_ERRLOG("Deprecation warning: The maximum allowed latency parameter is no longer supported.\n");
1254 : 0 : break;
1255 : 0 : case ENV_CONTEXT_OPT_IDX:
1256 : 0 : opts->env_context = optarg;
1257 : 0 : break;
1258 : 21 : case RPCS_ALLOWED_OPT_IDX:
1259 : 21 : opts->rpc_allowlist = (const char **)spdk_strarray_from_string(optarg, ",");
1260 [ - + ]: 21 : if (opts->rpc_allowlist == NULL) {
1261 : 0 : SPDK_ERRLOG("Invalid --rpcs-allowed argument\n");
1262 : 0 : usage(app_usage);
1263 : 0 : goto out;
1264 : : }
1265 : 21 : break;
1266 : 0 : case ENV_VF_TOKEN_OPT_IDX:
1267 : 0 : opts->vf_token = optarg;
1268 : 0 : break;
1269 : 1 : case INTERRUPT_MODE_OPT_IDX:
1270 : 1 : opts->interrupt_mode = true;
1271 : 1 : break;
1272 : 0 : case VERSION_OPT_IDX:
1273 [ # # ]: 0 : printf(SPDK_VERSION_STRING"\n");
1274 : 0 : retval = SPDK_APP_PARSE_ARGS_HELP;
1275 : 0 : goto out;
1276 : 16 : case '?':
1277 : : /*
1278 : : * In the event getopt() above detects an option
1279 : : * in argv that is NOT in the getopt_str,
1280 : : * getopt() will return a '?' indicating failure.
1281 : : */
1282 : 16 : usage(app_usage);
1283 : 16 : goto out;
1284 : 7619 : default:
1285 [ - + ]: 7619 : if (!app_parse) {
1286 : 0 : SPDK_ERRLOG("Unsupported app-specific command line parameter '%c'.\n", ch);
1287 : 0 : goto out;
1288 : : }
1289 : :
1290 : 7619 : rc = app_parse(ch, optarg);
1291 [ + + ]: 7619 : if (rc) {
1292 : 42 : SPDK_ERRLOG("Parsing app-specific command line parameter '%c' failed: %d\n", ch, rc);
1293 : 42 : goto out;
1294 : : }
1295 : : }
1296 : : }
1297 : :
1298 [ + + - + : 3016 : if (opts->json_config_file && opts->delay_subsystem_init) {
- + ]
1299 : 0 : SPDK_ERRLOG("JSON configuration file can't be used together with --wait-for-rpc.\n");
1300 : 0 : goto out;
1301 : : }
1302 : :
1303 : 3016 : retval = SPDK_APP_PARSE_ARGS_SUCCESS;
1304 : 3108 : out:
1305 [ + + ]: 3108 : if (retval != SPDK_APP_PARSE_ARGS_SUCCESS) {
1306 : 92 : free(opts->pci_blocked);
1307 : 92 : opts->pci_blocked = NULL;
1308 : 92 : free(opts->pci_allowed);
1309 : 92 : opts->pci_allowed = NULL;
1310 : 92 : spdk_strarray_free((char **)opts->rpc_allowlist);
1311 : 92 : opts->rpc_allowlist = NULL;
1312 : : }
1313 : 3108 : free(cmdline_short_opts);
1314 : 3108 : free(cmdline_options);
1315 : 3108 : return retval;
1316 : : }
1317 : :
1318 : : void
1319 : 0 : spdk_app_usage(void)
1320 : : {
1321 [ # # ]: 0 : if (g_executable_name == NULL) {
1322 : 0 : SPDK_ERRLOG("%s not valid before calling spdk_app_parse_args()\n", __func__);
1323 : 0 : return;
1324 : : }
1325 : :
1326 : 0 : usage(NULL);
1327 : : }
1328 : :
1329 : : static void
1330 : 163 : rpc_framework_start_init_cpl(int rc, void *arg1)
1331 : : {
1332 : 163 : struct spdk_jsonrpc_request *request = arg1;
1333 : :
1334 [ - + ]: 163 : assert(spdk_thread_is_app_thread(NULL));
1335 : :
1336 [ - + ]: 163 : if (rc) {
1337 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
1338 : : "framework_initialization failed");
1339 : 0 : return;
1340 : : }
1341 : :
1342 : 163 : spdk_rpc_set_state(SPDK_RPC_RUNTIME);
1343 : 163 : app_start_application();
1344 : :
1345 : 163 : spdk_jsonrpc_send_bool_response(request, true);
1346 : : }
1347 : :
1348 : : static void
1349 : 163 : rpc_framework_start_init(struct spdk_jsonrpc_request *request,
1350 : : const struct spdk_json_val *params)
1351 : : {
1352 [ - + ]: 163 : if (params != NULL) {
1353 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
1354 : : "framework_start_init requires no parameters");
1355 : 0 : return;
1356 : : }
1357 : :
1358 : 163 : spdk_subsystem_init(rpc_framework_start_init_cpl, request);
1359 : : }
1360 : 3213 : SPDK_RPC_REGISTER("framework_start_init", rpc_framework_start_init, SPDK_RPC_STARTUP)
1361 : :
1362 : : struct subsystem_init_poller_ctx {
1363 : : struct spdk_poller *init_poller;
1364 : : struct spdk_jsonrpc_request *request;
1365 : : };
1366 : :
1367 : : static int
1368 : 408056 : rpc_subsystem_init_poller_ctx(void *ctx)
1369 : : {
1370 : 408056 : struct subsystem_init_poller_ctx *poller_ctx = ctx;
1371 : :
1372 [ + + ]: 408056 : if (spdk_rpc_get_state() == SPDK_RPC_RUNTIME) {
1373 : 2 : spdk_jsonrpc_send_bool_response(poller_ctx->request, true);
1374 : 2 : spdk_poller_unregister(&poller_ctx->init_poller);
1375 : 2 : free(poller_ctx);
1376 : : }
1377 : :
1378 : 408056 : return SPDK_POLLER_BUSY;
1379 : : }
1380 : :
1381 : : static void
1382 : 11 : rpc_framework_wait_init(struct spdk_jsonrpc_request *request,
1383 : : const struct spdk_json_val *params)
1384 : : {
1385 : : struct subsystem_init_poller_ctx *ctx;
1386 : :
1387 [ + + ]: 11 : if (spdk_rpc_get_state() == SPDK_RPC_RUNTIME) {
1388 : 9 : spdk_jsonrpc_send_bool_response(request, true);
1389 : : } else {
1390 : 2 : ctx = malloc(sizeof(struct subsystem_init_poller_ctx));
1391 [ - + ]: 2 : if (ctx == NULL) {
1392 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
1393 : : "Unable to allocate memory for the request context\n");
1394 : 0 : return;
1395 : : }
1396 : 2 : ctx->request = request;
1397 : 2 : ctx->init_poller = SPDK_POLLER_REGISTER(rpc_subsystem_init_poller_ctx, ctx, 0);
1398 : : }
1399 : : }
1400 : 3213 : SPDK_RPC_REGISTER("framework_wait_init", rpc_framework_wait_init,
1401 : : SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
1402 : :
1403 : : static void
1404 : 20 : rpc_framework_disable_cpumask_locks(struct spdk_jsonrpc_request *request,
1405 : : const struct spdk_json_val *params)
1406 : : {
1407 : 9 : char msg[128];
1408 : : int rc;
1409 : 9 : uint32_t failed_core;
1410 : :
1411 [ - + ]: 20 : if (params != NULL) {
1412 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
1413 : : "framework_disable_cpumask_locks"
1414 : : "requires no arguments");
1415 : 0 : return;
1416 : : }
1417 : :
1418 : 20 : rc = unclaim_cpu_cores(&failed_core);
1419 [ - + ]: 20 : if (rc) {
1420 [ # # ]: 0 : snprintf(msg, sizeof(msg), "Failed to unclaim CPU core: %" PRIu32, failed_core);
1421 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, msg);
1422 : 0 : return;
1423 : : }
1424 : :
1425 : 20 : spdk_jsonrpc_send_bool_response(request, true);
1426 : : }
1427 : 3213 : SPDK_RPC_REGISTER("framework_disable_cpumask_locks", rpc_framework_disable_cpumask_locks,
1428 : : SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
1429 : :
1430 : : static void
1431 : 60 : rpc_framework_enable_cpumask_locks(struct spdk_jsonrpc_request *request,
1432 : : const struct spdk_json_val *params)
1433 : : {
1434 : 27 : char msg[128];
1435 : : int rc;
1436 : 27 : uint32_t failed_core;
1437 : :
1438 [ - + ]: 60 : if (params != NULL) {
1439 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
1440 : : "framework_enable_cpumask_locks"
1441 : : "requires no arguments");
1442 : 11 : return;
1443 : : }
1444 : :
1445 : 60 : rc = claim_cpu_cores(&failed_core);
1446 [ + + ]: 60 : if (rc) {
1447 [ - + ]: 20 : snprintf(msg, sizeof(msg), "Failed to claim CPU core: %" PRIu32, failed_core);
1448 : 20 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, msg);
1449 : 20 : return;
1450 : : }
1451 : :
1452 : 40 : spdk_jsonrpc_send_bool_response(request, true);
1453 : : }
1454 : 3213 : SPDK_RPC_REGISTER("framework_enable_cpumask_locks", rpc_framework_enable_cpumask_locks,
1455 : : SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
|