LCOV - code coverage report
Current view: top level - spdk/app/spdk_tgt - spdk_tgt.c (source / functions) Hit Total Coverage
Test: Combined Lines: 18 39 46.2 %
Date: 2024-07-15 13:34:03 Functions: 3 5 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 21 23.8 %

           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                 :        579 : spdk_tgt_started(void *arg1)
      67                 :            : {
      68         [ -  + ]:        579 :         if (g_pid_path) {
      69                 :          0 :                 spdk_tgt_save_pid(g_pid_path);
      70                 :            :         }
      71                 :            : 
      72   [ -  +  -  + ]:        579 :         if (getenv("MEMZONE_DUMP") != NULL) {
      73                 :          0 :                 spdk_memzone_dump(stdout);
      74                 :          0 :                 fflush(stdout);
      75                 :            :         }
      76                 :        579 : }
      77                 :            : 
      78                 :            : int
      79                 :        657 : main(int argc, char **argv)
      80                 :            : {
      81                 :        657 :         struct spdk_app_opts opts = {};
      82                 :            :         int rc;
      83                 :            : 
      84                 :        657 :         spdk_app_opts_init(&opts, sizeof(opts));
      85                 :        657 :         opts.name = "spdk_tgt";
      86         [ -  + ]:        657 :         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                 :        657 :         rc = spdk_app_start(&opts, spdk_tgt_started, NULL);
      93                 :        657 :         spdk_app_fini();
      94                 :            : 
      95                 :        657 :         return rc;
      96                 :            : }

Generated by: LCOV version 1.14