Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (C) 2018 Intel Corporation. 3 : : * All rights reserved. 4 : : */ 5 : : 6 : : #include "spdk/stdinc.h" 7 : : 8 : : #include "spdk/config.h" 9 : : #include "spdk/env.h" 10 : : #include "spdk/event.h" 11 : : #include "spdk/vhost.h" 12 : : 13 : : #ifdef SPDK_CONFIG_VHOST 14 : : #define SPDK_VHOST_OPTS "S:" 15 : : #else 16 : : #define SPDK_VHOST_OPTS 17 : : #endif 18 : : 19 : : static const char *g_pid_path = NULL; 20 : : static const char g_spdk_tgt_get_opts_string[] = "f:" SPDK_VHOST_OPTS; 21 : : 22 : : static void 23 : 0 : spdk_tgt_usage(void) 24 : : { 25 [ # # ]: 0 : printf(" -f <file> pidfile save pid to file under given path\n"); 26 : : #ifdef SPDK_CONFIG_VHOST 27 [ # # ]: 0 : printf(" -S <path> directory where to create vhost sockets (default: pwd)\n"); 28 : : #endif 29 : 0 : } 30 : : 31 : : static void 32 : 0 : spdk_tgt_save_pid(const char *pid_path) 33 : : { 34 : : FILE *pid_file; 35 : : 36 : 0 : pid_file = fopen(pid_path, "w"); 37 [ # # ]: 0 : if (pid_file == NULL) { 38 [ # # ]: 0 : fprintf(stderr, "Couldn't create pid file '%s': %s\n", pid_path, strerror(errno)); 39 : 0 : exit(EXIT_FAILURE); 40 : : } 41 : : 42 [ # # ]: 0 : fprintf(pid_file, "%d\n", getpid()); 43 : 0 : fclose(pid_file); 44 : 0 : } 45 : : 46 : : 47 : : static int 48 : 8 : spdk_tgt_parse_arg(int ch, char *arg) 49 : : { 50 [ - + - ]: 8 : switch (ch) { 51 : 0 : case 'f': 52 : 0 : g_pid_path = arg; 53 : 0 : break; 54 : : #ifdef SPDK_CONFIG_VHOST 55 : 8 : case 'S': 56 : 8 : spdk_vhost_set_socket_path(arg); 57 : 8 : break; 58 : : #endif 59 : 0 : default: 60 : 0 : return -EINVAL; 61 : : } 62 : 8 : return 0; 63 : : } 64 : : 65 : : static void 66 : 535 : spdk_tgt_started(void *arg1) 67 : : { 68 [ - + ]: 535 : if (g_pid_path) { 69 : 0 : spdk_tgt_save_pid(g_pid_path); 70 : : } 71 : : 72 [ - + - + ]: 535 : if (getenv("MEMZONE_DUMP") != NULL) { 73 : 0 : spdk_memzone_dump(stdout); 74 : 0 : fflush(stdout); 75 : : } 76 : 535 : } 77 : : 78 : : int 79 : 607 : main(int argc, char **argv) 80 : : { 81 : 607 : struct spdk_app_opts opts = {}; 82 : : int rc; 83 : : 84 : 607 : spdk_app_opts_init(&opts, sizeof(opts)); 85 : 607 : opts.name = "spdk_tgt"; 86 [ - + ]: 607 : if ((rc = spdk_app_parse_args(argc, argv, &opts, g_spdk_tgt_get_opts_string, 87 : : NULL, spdk_tgt_parse_arg, spdk_tgt_usage)) != 88 : : SPDK_APP_PARSE_ARGS_SUCCESS) { 89 : 0 : return rc; 90 : : } 91 : : 92 : 607 : rc = spdk_app_start(&opts, spdk_tgt_started, NULL); 93 : 607 : spdk_app_fini(); 94 : : 95 : 607 : return rc; 96 : : }