4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
34 #include "spdk/stdinc.h"
37 #include "spdk/event.h"
39 static char g_path
[256];
40 static bool g_unaffinitize_thread
= false;
48 bdev_svc_parse_arg(int ch
, char *arg
)
53 bdev_svc_start(void *arg1
, void *arg2
)
56 int shm_id
= (intptr_t)arg1
;
58 if (g_unaffinitize_thread
) {
59 spdk_unaffinitize_thread();
62 snprintf(g_path
, sizeof(g_path
), "/var/run/spdk_bdev%d", shm_id
);
63 fd
= open(g_path
, O_CREAT
| O_EXCL
| O_RDWR
, S_IFREG
);
65 fprintf(stderr
, "could not create sentinel file %s\n", g_path
);
72 bdev_svc_shutdown(void)
79 main(int argc
, char **argv
)
82 struct spdk_app_opts opts
= {};
84 /* default value in opts structure */
85 spdk_app_opts_init(&opts
);
87 opts
.name
= "bdev_svc";
88 opts
.shutdown_cb
= bdev_svc_shutdown
;
89 opts
.max_delay_us
= 1000 * 1000;
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
) {
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.
103 if (opts
.reactor_mask
== NULL
) {
104 g_unaffinitize_thread
= true;
107 rc
= spdk_app_start(&opts
, bdev_svc_start
, (void *)(intptr_t)opts
.shm_id
, NULL
);