1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (C) 2016 Intel Corporation.
3 * All rights reserved.
4 */
5
6 #include "spdk/stdinc.h"
7
8 #include "spdk/env.h"
9 #include "spdk/event.h"
10 #include "iscsi/iscsi.h"
11 #include "spdk/log.h"
12
13 static int g_daemon_mode = 0;
14
15 static void
iscsi_usage(void)16 iscsi_usage(void)
17 {
18 printf(" -b run iscsi target background, the default is foreground\n");
19 }
20
21 static void
spdk_startup(void * arg1)22 spdk_startup(void *arg1)
23 {
24 if (getenv("MEMZONE_DUMP") != NULL) {
25 spdk_memzone_dump(stdout);
26 fflush(stdout);
27 }
28 }
29
30 static int
iscsi_parse_arg(int ch,char * arg)31 iscsi_parse_arg(int ch, char *arg)
32 {
33 switch (ch) {
34 case 'b':
35 g_daemon_mode = 1;
36 break;
37 default:
38 return -EINVAL;
39 }
40 return 0;
41 }
42
43 int
main(int argc,char ** argv)44 main(int argc, char **argv)
45 {
46 int rc;
47 struct spdk_app_opts opts = {};
48
49 spdk_app_opts_init(&opts, sizeof(opts));
50 opts.name = "iscsi";
51 if ((rc = spdk_app_parse_args(argc, argv, &opts, "b", NULL,
52 iscsi_parse_arg, iscsi_usage)) !=
53 SPDK_APP_PARSE_ARGS_SUCCESS) {
54 exit(rc);
55 }
56
57 if (g_daemon_mode) {
58 if (daemon(1, 0) < 0) {
59 SPDK_ERRLOG("Start iscsi target daemon failed.\n");
60 exit(EXIT_FAILURE);
61 }
62 }
63
64 opts.shutdown_cb = NULL;
65
66 /* Blocks until the application is exiting */
67 rc = spdk_app_start(&opts, spdk_startup, NULL);
68 if (rc) {
69 SPDK_ERRLOG("Start iscsi target daemon: spdk_app_start() retn non-zero\n");
70 }
71
72 spdk_app_fini();
73
74 return rc;
75 }
76