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