]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/app/bdev_svc/bdev_svc.c
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / spdk / test / app / bdev_svc / bdev_svc.c
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 void
48 bdev_svc_parse_arg(int ch, char *arg)
49 {
50 }
51
52 static void
53 bdev_svc_start(void *arg1, void *arg2)
54 {
55 int fd;
56 int shm_id = (intptr_t)arg1;
57
58 if (g_unaffinitize_thread) {
59 spdk_unaffinitize_thread();
60 }
61
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);
64 if (fd < 0) {
65 fprintf(stderr, "could not create sentinel file %s\n", g_path);
66 exit(1);
67 }
68 close(fd);
69 }
70
71 static void
72 bdev_svc_shutdown(void)
73 {
74 unlink(g_path);
75 spdk_app_stop(0);
76 }
77
78 int
79 main(int argc, char **argv)
80 {
81 int rc;
82 struct spdk_app_opts opts = {};
83
84 /* default value in opts structure */
85 spdk_app_opts_init(&opts);
86
87 opts.name = "bdev_svc";
88 opts.shutdown_cb = bdev_svc_shutdown;
89 opts.max_delay_us = 1000 * 1000;
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, NULL);
108
109 spdk_app_fini();
110
111 return rc;
112 }