LCOV - code coverage report
Current view: top level - spdk/app/vhost - vhost.c (source / functions) Hit Total Coverage
Test: Combined Lines: 17 36 47.2 %
Date: 2024-07-15 01:59:39 Functions: 3 5 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 17 17.6 %

           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                 :          0 : vhost_usage(void)
      16                 :            : {
      17         [ #  # ]:          0 :         printf(" -f <path>                 save pid to file under given path\n");
      18         [ #  # ]:          0 :         printf(" -S <path>                 directory where to create vhost sockets (default: pwd)\n");
      19                 :          0 : }
      20                 :            : 
      21                 :            : static void
      22                 :          0 : save_pid(const char *pid_path)
      23                 :            : {
      24                 :            :         FILE *pid_file;
      25                 :            : 
      26                 :          0 :         pid_file = fopen(pid_path, "w");
      27         [ #  # ]:          0 :         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         [ #  # ]:          0 :         fprintf(pid_file, "%d\n", getpid());
      33                 :          0 :         fclose(pid_file);
      34                 :          0 : }
      35                 :            : 
      36                 :            : static int
      37                 :          2 : vhost_parse_arg(int ch, char *arg)
      38                 :            : {
      39      [ -  +  - ]:          2 :         switch (ch) {
      40                 :          0 :         case 'f':
      41                 :          0 :                 g_pid_path = arg;
      42                 :          0 :                 break;
      43                 :          2 :         case 'S':
      44                 :          2 :                 spdk_vhost_set_socket_path(arg);
      45                 :          2 :                 break;
      46                 :          0 :         default:
      47                 :          0 :                 return -EINVAL;
      48                 :            :         }
      49                 :          2 :         return 0;
      50                 :            : }
      51                 :            : 
      52                 :            : static void
      53                 :          4 : vhost_started(void *arg1)
      54                 :            : {
      55                 :          4 : }
      56                 :            : 
      57                 :            : int
      58                 :          4 : main(int argc, char *argv[])
      59                 :            : {
      60                 :          4 :         struct spdk_app_opts opts = {};
      61                 :            :         int rc;
      62                 :            : 
      63                 :          4 :         spdk_app_opts_init(&opts, sizeof(opts));
      64                 :          4 :         opts.name = "vhost";
      65                 :            : 
      66         [ -  + ]:          4 :         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                 :          0 :                 exit(rc);
      70                 :            :         }
      71                 :            : 
      72         [ -  + ]:          4 :         if (g_pid_path) {
      73                 :          0 :                 save_pid(g_pid_path);
      74                 :            :         }
      75                 :            : 
      76                 :            :         /* Blocks until the application is exiting */
      77                 :          4 :         rc = spdk_app_start(&opts, vhost_started, NULL);
      78                 :            : 
      79                 :          4 :         spdk_app_fini();
      80                 :            : 
      81                 :          4 :         return rc;
      82                 :            : }

Generated by: LCOV version 1.14