]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | */ | |
7c673cae | 33 | |
11fdf7f2 | 34 | #include "spdk/stdinc.h" |
7c673cae | 35 | |
11fdf7f2 TL |
36 | #include "spdk/env.h" |
37 | #include "spdk/event.h" | |
38 | ||
39 | static char g_path[256]; | |
40 | static bool g_unaffinitize_thread = false; | |
7c673cae FG |
41 | |
42 | static void | |
11fdf7f2 | 43 | bdev_svc_usage(void) |
7c673cae | 44 | { |
7c673cae FG |
45 | } |
46 | ||
9f95a23c | 47 | static int |
11fdf7f2 | 48 | bdev_svc_parse_arg(int ch, char *arg) |
7c673cae | 49 | { |
9f95a23c | 50 | return 0; |
7c673cae FG |
51 | } |
52 | ||
53 | static void | |
9f95a23c | 54 | bdev_svc_start(void *arg1) |
7c673cae | 55 | { |
11fdf7f2 TL |
56 | int fd; |
57 | int shm_id = (intptr_t)arg1; | |
7c673cae | 58 | |
11fdf7f2 TL |
59 | if (g_unaffinitize_thread) { |
60 | spdk_unaffinitize_thread(); | |
7c673cae FG |
61 | } |
62 | ||
11fdf7f2 TL |
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); | |
7c673cae | 68 | } |
11fdf7f2 TL |
69 | close(fd); |
70 | } | |
7c673cae | 71 | |
11fdf7f2 TL |
72 | static void |
73 | bdev_svc_shutdown(void) | |
74 | { | |
75 | unlink(g_path); | |
76 | spdk_app_stop(0); | |
7c673cae FG |
77 | } |
78 | ||
11fdf7f2 TL |
79 | int |
80 | main(int argc, char **argv) | |
7c673cae | 81 | { |
11fdf7f2 | 82 | int rc; |
7c673cae FG |
83 | struct spdk_app_opts opts = {}; |
84 | ||
11fdf7f2 TL |
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; | |
11fdf7f2 TL |
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); | |
7c673cae FG |
95 | } |
96 | ||
11fdf7f2 TL |
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 | } | |
7c673cae | 106 | |
9f95a23c | 107 | rc = spdk_app_start(&opts, bdev_svc_start, (void *)(intptr_t)opts.shm_id); |
7c673cae | 108 | |
7c673cae FG |
109 | spdk_app_fini(); |
110 | ||
11fdf7f2 | 111 | return rc; |
7c673cae | 112 | } |