2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2016 Intel Corporation.
|
2016-08-03 21:37:16 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2016-10-03 21:26:07 +00:00
|
|
|
#include "spdk/env.h"
|
2016-08-03 21:37:16 +00:00
|
|
|
#include "spdk/event.h"
|
|
|
|
#include "iscsi/iscsi.h"
|
|
|
|
#include "spdk/log.h"
|
|
|
|
|
2017-11-06 16:58:29 +00:00
|
|
|
static int g_daemon_mode = 0;
|
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
static void
|
2017-11-09 20:20:56 +00:00
|
|
|
iscsi_usage(void)
|
2016-08-03 21:37:16 +00:00
|
|
|
{
|
2018-07-31 13:26:44 +00:00
|
|
|
printf(" -b run iscsi target background, the default is foreground\n");
|
2017-11-06 17:23:34 +00:00
|
|
|
}
|
|
|
|
|
2016-08-03 21:37:16 +00:00
|
|
|
static void
|
2019-03-04 20:52:59 +00:00
|
|
|
spdk_startup(void *arg1)
|
2016-08-03 21:37:16 +00:00
|
|
|
{
|
|
|
|
if (getenv("MEMZONE_DUMP") != NULL) {
|
2016-10-03 21:26:07 +00:00
|
|
|
spdk_memzone_dump(stdout);
|
2016-08-03 21:37:16 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 19:40:06 +00:00
|
|
|
static int
|
2017-11-09 20:20:56 +00:00
|
|
|
iscsi_parse_arg(int ch, char *arg)
|
2016-08-03 21:37:16 +00:00
|
|
|
{
|
2017-11-09 20:20:56 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 'b':
|
|
|
|
g_daemon_mode = 1;
|
|
|
|
break;
|
|
|
|
default:
|
2019-01-21 14:56:47 +00:00
|
|
|
return -EINVAL;
|
2016-08-03 21:37:16 +00:00
|
|
|
}
|
2019-01-08 19:40:06 +00:00
|
|
|
return 0;
|
2017-11-06 16:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct spdk_app_opts opts = {};
|
|
|
|
|
2020-11-30 11:38:37 +00:00
|
|
|
spdk_app_opts_init(&opts, sizeof(opts));
|
2017-11-06 16:58:29 +00:00
|
|
|
opts.name = "iscsi";
|
2018-07-31 13:26:44 +00:00
|
|
|
if ((rc = spdk_app_parse_args(argc, argv, &opts, "b", NULL,
|
2018-02-22 23:50:51 +00:00
|
|
|
iscsi_parse_arg, iscsi_usage)) !=
|
|
|
|
SPDK_APP_PARSE_ARGS_SUCCESS) {
|
|
|
|
exit(rc);
|
|
|
|
}
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2017-11-06 16:58:29 +00:00
|
|
|
if (g_daemon_mode) {
|
2016-12-07 00:15:19 +00:00
|
|
|
if (daemon(1, 0) < 0) {
|
2019-01-19 18:42:34 +00:00
|
|
|
SPDK_ERRLOG("Start iscsi target daemon failed.\n");
|
2016-12-07 00:15:19 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-10 17:02:00 +00:00
|
|
|
opts.shutdown_cb = NULL;
|
2016-08-03 21:37:16 +00:00
|
|
|
|
|
|
|
/* Blocks until the application is exiting */
|
2019-02-28 21:42:07 +00:00
|
|
|
rc = spdk_app_start(&opts, spdk_startup, NULL);
|
2018-02-22 23:50:51 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Start iscsi target daemon: spdk_app_start() retn non-zero\n");
|
|
|
|
}
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2017-10-05 14:15:17 +00:00
|
|
|
spdk_app_fini();
|
2016-08-03 21:37:16 +00:00
|
|
|
|
2017-10-05 14:15:17 +00:00
|
|
|
return rc;
|
2016-08-03 21:37:16 +00:00
|
|
|
}
|