1 /*- 2 * BSD LICENSE 3 * 4 * Copyright (c) Intel Corporation. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name of Intel Corporation nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include "spdk/stdinc.h" 35 36 #include "spdk/env.h" 37 #include "spdk/event.h" 38 39 static char g_path[256]; 40 static bool g_unaffinitize_thread = false; 41 42 static void 43 bdev_svc_usage(void) 44 { 45 } 46 47 static int 48 bdev_svc_parse_arg(int ch, char *arg) 49 { 50 return 0; 51 } 52 53 static void 54 bdev_svc_start(void *arg1) 55 { 56 int fd; 57 int shm_id = (intptr_t)arg1; 58 59 if (g_unaffinitize_thread) { 60 spdk_unaffinitize_thread(); 61 } 62 63 snprintf(g_path, sizeof(g_path), "/var/run/spdk_bdev%d", shm_id); 64 fd = open(g_path, O_CREAT | O_EXCL | O_RDWR, S_IFREG); 65 if (fd < 0) { 66 fprintf(stderr, "could not create sentinel file %s\n", g_path); 67 exit(1); 68 } 69 close(fd); 70 } 71 72 static void 73 bdev_svc_shutdown(void) 74 { 75 unlink(g_path); 76 spdk_app_stop(0); 77 } 78 79 int 80 main(int argc, char **argv) 81 { 82 int rc; 83 struct spdk_app_opts opts = {}; 84 85 /* default value in opts structure */ 86 spdk_app_opts_init(&opts); 87 88 opts.name = "bdev_svc"; 89 opts.shutdown_cb = bdev_svc_shutdown; 90 91 if ((rc = spdk_app_parse_args(argc, argv, &opts, "", NULL, 92 bdev_svc_parse_arg, bdev_svc_usage)) != 93 SPDK_APP_PARSE_ARGS_SUCCESS) { 94 exit(rc); 95 } 96 97 /* User did not specify a reactor mask. Test scripts may do this when using 98 * bdev_svc as a primary process to speed up nvme test programs by running 99 * them as secondary processes. In that case, we will unaffinitize the thread 100 * in the bdev_svc_start routine, which will allow the scheduler to move this 101 * thread so it doesn't conflict with pinned threads in the secondary processes. 102 */ 103 if (opts.reactor_mask == NULL) { 104 g_unaffinitize_thread = true; 105 } 106 107 rc = spdk_app_start(&opts, bdev_svc_start, (void *)(intptr_t)opts.shm_id); 108 109 spdk_app_fini(); 110 111 return rc; 112 } 113