Branch data Line data Source code
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 16 : 0 : iscsi_usage(void) 17 : : { 18 [ # # ]: 0 : printf(" -b run iscsi target background, the default is foreground\n"); 19 : 0 : } 20 : : 21 : : static void 22 : 22 : spdk_startup(void *arg1) 23 : : { 24 [ - + - + ]: 22 : if (getenv("MEMZONE_DUMP") != NULL) { 25 : 0 : spdk_memzone_dump(stdout); 26 : 0 : fflush(stdout); 27 : : } 28 : 22 : } 29 : : 30 : : static int 31 : 0 : iscsi_parse_arg(int ch, char *arg) 32 : : { 33 [ # # ]: 0 : switch (ch) { 34 : 0 : case 'b': 35 : 0 : g_daemon_mode = 1; 36 : 0 : break; 37 : 0 : default: 38 : 0 : return -EINVAL; 39 : : } 40 : 0 : return 0; 41 : : } 42 : : 43 : : int 44 : 22 : main(int argc, char **argv) 45 : : { 46 : : int rc; 47 : 22 : struct spdk_app_opts opts = {}; 48 : : 49 : 22 : spdk_app_opts_init(&opts, sizeof(opts)); 50 : 22 : opts.name = "iscsi"; 51 [ - + ]: 22 : if ((rc = spdk_app_parse_args(argc, argv, &opts, "b", NULL, 52 : : iscsi_parse_arg, iscsi_usage)) != 53 : : SPDK_APP_PARSE_ARGS_SUCCESS) { 54 : 0 : exit(rc); 55 : : } 56 : : 57 [ - + ]: 22 : if (g_daemon_mode) { 58 [ # # ]: 0 : if (daemon(1, 0) < 0) { 59 : 0 : SPDK_ERRLOG("Start iscsi target daemon failed.\n"); 60 : 0 : exit(EXIT_FAILURE); 61 : : } 62 : : } 63 : : 64 : 22 : opts.shutdown_cb = NULL; 65 : : 66 : : /* Blocks until the application is exiting */ 67 : 22 : rc = spdk_app_start(&opts, spdk_startup, NULL); 68 [ - + ]: 22 : if (rc) { 69 : 0 : SPDK_ERRLOG("Start iscsi target daemon: spdk_app_start() retn non-zero\n"); 70 : : } 71 : : 72 : 22 : spdk_app_fini(); 73 : : 74 : 22 : return rc; 75 : : }