Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (C) 2017 Intel Corporation. 3 : : * All rights reserved. 4 : : */ 5 : : 6 : : #include "spdk/stdinc.h" 7 : : 8 : : #include "spdk/env.h" 9 : : #include "spdk/event.h" 10 : : 11 : : static char g_path[256]; 12 : : static bool g_unaffinitize_thread = false; 13 : : 14 : : static void 15 : 0 : bdev_svc_usage(void) 16 : : { 17 : 0 : } 18 : : 19 : : static int 20 : 0 : bdev_svc_parse_arg(int ch, char *arg) 21 : : { 22 : 0 : return 0; 23 : : } 24 : : 25 : : static void 26 : 215 : bdev_svc_start(void *arg1) 27 : : { 28 : : int fd; 29 : 215 : int shm_id = (intptr_t)arg1; 30 : : 31 [ + + + - ]: 215 : if (g_unaffinitize_thread) { 32 : 215 : spdk_unaffinitize_thread(); 33 : : } 34 : : 35 [ - + ]: 215 : snprintf(g_path, sizeof(g_path), "/var/run/spdk_bdev%d", shm_id); 36 [ - + ]: 215 : fd = open(g_path, O_CREAT | O_EXCL | O_RDWR, S_IFREG); 37 [ - + ]: 215 : if (fd < 0) { 38 [ # # # # ]: 0 : fprintf(stderr, "could not create sentinel file %s\n", g_path); 39 : 0 : exit(1); 40 : : } 41 : 215 : close(fd); 42 : 215 : } 43 : : 44 : : static void 45 : 215 : bdev_svc_shutdown(void) 46 : : { 47 [ - + ]: 215 : unlink(g_path); 48 : 215 : spdk_app_stop(0); 49 : 215 : } 50 : : 51 : : int 52 : 215 : main(int argc, char **argv) 53 : : { 54 : : int rc; 55 : 215 : struct spdk_app_opts opts = {}; 56 : 215 : const char *reactor_mask = "0x1"; 57 : : 58 : : /* default value in opts structure */ 59 : 215 : spdk_app_opts_init(&opts, sizeof(opts)); 60 : : 61 : 215 : opts.name = "bdev_svc"; 62 : 215 : opts.reactor_mask = reactor_mask; 63 : 215 : opts.shutdown_cb = bdev_svc_shutdown; 64 : : 65 [ - + ]: 215 : if ((rc = spdk_app_parse_args(argc, argv, &opts, "", NULL, 66 : : bdev_svc_parse_arg, bdev_svc_usage)) != 67 : : SPDK_APP_PARSE_ARGS_SUCCESS) { 68 : 0 : exit(rc); 69 : : } 70 : : 71 : : /* User did not specify a reactor mask. Test scripts may do this when using 72 : : * bdev_svc as a primary process to speed up nvme test programs by running 73 : : * them as secondary processes. In that case, we will unaffinitize the thread 74 : : * in the bdev_svc_start routine, which will allow the scheduler to move this 75 : : * thread so it doesn't conflict with pinned threads in the secondary processes. 76 : : */ 77 [ + - ]: 215 : if (opts.reactor_mask == reactor_mask) { 78 : 215 : g_unaffinitize_thread = true; 79 : : } 80 : : 81 : 215 : rc = spdk_app_start(&opts, bdev_svc_start, (void *)(intptr_t)opts.shm_id); 82 : : 83 : 215 : spdk_app_fini(); 84 : : 85 : 215 : return rc; 86 : : }