]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/app/iscsi_tgt/iscsi_tgt.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / spdk / app / iscsi_tgt / iscsi_tgt.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 <inttypes.h>
35 #include <stdint.h>
36 #include <stdlib.h>
37
38 #include <rte_config.h>
39 #include <rte_lcore.h>
40
41 #include "spdk/env.h"
42 #include "spdk/event.h"
43 #include "iscsi/iscsi.h"
44 #include "spdk/log.h"
45 #include "spdk/net.h"
46
47 static void
48 spdk_sigusr1(int signo __attribute__((__unused__)))
49 {
50 char *config_str = NULL;
51 if (spdk_app_get_running_config(&config_str, "iscsi.conf") < 0)
52 fprintf(stderr, "Error getting config\n");
53 else {
54 fprintf(stdout, "============================\n");
55 fprintf(stdout, " iSCSI target running config\n");
56 fprintf(stdout, "=============================\n");
57 fprintf(stdout, "%s", config_str);
58 }
59 free(config_str);
60 }
61
62 static void
63 usage(char *executable_name)
64 {
65 struct spdk_app_opts opts;
66
67 spdk_app_opts_init(&opts);
68
69 printf("%s [options]\n", executable_name);
70 printf("options:\n");
71 printf(" -c config config file (default %s)\n", SPDK_ISCSI_DEFAULT_CONFIG);
72 printf(" -e mask tracepoint group mask for spdk trace buffers (default 0x0)\n");
73 printf(" -m mask core mask for DPDK\n");
74 printf(" -i shared memory ID (optional)\n");
75 printf(" -l facility use specific syslog facility (default %s)\n",
76 opts.log_facility);
77 printf(" -n channel number of memory channels used for DPDK\n");
78 printf(" -p core master (primary) core for DPDK\n");
79 printf(" -s size memory size in MB for DPDK\n");
80 spdk_tracelog_usage(stdout, "-t");
81 printf(" -H show this usage\n");
82 printf(" -b run iscsi target background, the default is foreground\n");
83 printf(" -d disable coredump file enabling\n");
84 printf(" -q disable notice level logging to stderr\n");
85 }
86
87 static void
88 spdk_startup(void *arg1, void *arg2)
89 {
90 if (getenv("MEMZONE_DUMP") != NULL) {
91 spdk_memzone_dump(stdout);
92 fflush(stdout);
93 }
94 }
95
96 int
97 main(int argc, char **argv)
98 {
99 int ch;
100 int rc, app_rc;
101 int daemon_mode = 0;
102 struct spdk_app_opts opts = {};
103
104 /* default value in opts structure */
105 spdk_app_opts_init(&opts);
106
107 opts.config_file = SPDK_ISCSI_DEFAULT_CONFIG;
108 opts.name = "iscsi";
109
110 while ((ch = getopt(argc, argv, "bc:de:i:l:m:n:p:qs:t:H")) != -1) {
111 switch (ch) {
112 case 'd':
113 opts.enable_coredump = false;
114 break;
115 case 'c':
116 opts.config_file = optarg;
117 break;
118 case 'i':
119 opts.shm_id = atoi(optarg);
120 break;
121 case 'l':
122 opts.log_facility = optarg;
123 break;
124 case 't':
125 rc = spdk_log_set_trace_flag(optarg);
126 if (rc < 0) {
127 fprintf(stderr, "unknown flag\n");
128 usage(argv[0]);
129 exit(EXIT_FAILURE);
130 }
131 #ifndef DEBUG
132 fprintf(stderr, "%s must be built with CONFIG_DEBUG=y for -t flag\n",
133 argv[0]);
134 usage(argv[0]);
135 exit(EXIT_FAILURE);
136 #endif
137 break;
138 case 'e':
139 opts.tpoint_group_mask = optarg;
140 break;
141 case 'q':
142 spdk_g_notice_stderr_flag = 0;
143 break;
144 case 'm':
145 opts.reactor_mask = optarg;
146 break;
147 case 'n':
148 opts.dpdk_mem_channel = atoi(optarg);
149 break;
150 case 'p':
151 opts.dpdk_master_core = atoi(optarg);
152 break;
153 case 's':
154 opts.dpdk_mem_size = atoi(optarg);
155 break;
156 case 'b':
157 daemon_mode = 1;
158 break;
159 case 'H':
160 default:
161 usage(argv[0]);
162 exit(EXIT_SUCCESS);
163 }
164 }
165
166 if (daemon_mode) {
167 if (daemon(1, 0) < 0) {
168 SPDK_ERRLOG("Start iscsi target daemon faild.\n");
169 exit(EXIT_FAILURE);
170 }
171 }
172
173 if (spdk_g_notice_stderr_flag == 1 &&
174 isatty(STDERR_FILENO) &&
175 !strncmp(ttyname(STDERR_FILENO), "/dev/tty", strlen("/dev/tty"))) {
176 printf("Warning: printing stderr to console terminal without -q option specified.\n");
177 printf("Suggest using -q to disable logging to stderr and monitor syslog, or\n");
178 printf("redirect stderr to a file.\n");
179 printf("(Delaying for 10 seconds...)\n");
180 sleep(10);
181 }
182
183 optind = 1; /* reset the optind */
184
185 opts.shutdown_cb = spdk_iscsi_shutdown;
186 opts.usr1_handler = spdk_sigusr1;
187 spdk_app_init(&opts);
188
189 printf("Total cores available: %d\n", rte_lcore_count());
190 printf("Using net framework %s\n", spdk_net_framework_get_name());
191 /* Blocks until the application is exiting */
192 app_rc = spdk_app_start(spdk_startup, NULL, NULL);
193
194 rc = spdk_app_fini();
195
196 return app_rc ? app_rc : rc;
197 }