1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 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 bdev_svc_usage(void) 16 { 17 } 18 19 static int 20 bdev_svc_parse_arg(int ch, char *arg) 21 { 22 return 0; 23 } 24 25 static void 26 bdev_svc_start(void *arg1) 27 { 28 int fd; 29 int shm_id = (intptr_t)arg1; 30 31 if (g_unaffinitize_thread) { 32 spdk_unaffinitize_thread(); 33 } 34 35 snprintf(g_path, sizeof(g_path), "/var/run/spdk_bdev%d", shm_id); 36 fd = open(g_path, O_CREAT | O_EXCL | O_RDWR, S_IFREG); 37 if (fd < 0) { 38 fprintf(stderr, "could not create sentinel file %s\n", g_path); 39 exit(1); 40 } 41 close(fd); 42 } 43 44 static void 45 bdev_svc_shutdown(void) 46 { 47 unlink(g_path); 48 spdk_app_stop(0); 49 } 50 51 int 52 main(int argc, char **argv) 53 { 54 int rc; 55 struct spdk_app_opts opts = {}; 56 const char *reactor_mask = "0x1"; 57 58 /* default value in opts structure */ 59 spdk_app_opts_init(&opts, sizeof(opts)); 60 61 opts.name = "bdev_svc"; 62 opts.reactor_mask = reactor_mask; 63 opts.shutdown_cb = bdev_svc_shutdown; 64 65 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 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 if (opts.reactor_mask == reactor_mask) { 78 g_unaffinitize_thread = true; 79 } 80 81 rc = spdk_app_start(&opts, bdev_svc_start, (void *)(intptr_t)opts.shm_id); 82 83 spdk_app_fini(); 84 85 return rc; 86 } 87