LCOV - code coverage report
Current view: top level - spdk/app/vhost - vhost.c (source / functions) Hit Total Coverage
Test: Combined Lines: 32 36 88.9 %
Date: 2024-07-11 13:28:34 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 17 58.8 %

           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                 :         20 : vhost_parse_arg(int ch, char *arg)
      38                 :            : {
      39      [ +  +  - ]:         20 :         switch (ch) {
      40                 :          1 :         case 'f':
      41                 :          1 :                 g_pid_path = arg;
      42                 :          1 :                 break;
      43                 :         19 :         case 'S':
      44                 :         19 :                 spdk_vhost_set_socket_path(arg);
      45                 :         19 :                 break;
      46                 :          0 :         default:
      47                 :          0 :                 return -EINVAL;
      48                 :            :         }
      49                 :         20 :         return 0;
      50                 :            : }
      51                 :            : 
      52                 :            : static void
      53                 :         21 : vhost_started(void *arg1)
      54                 :            : {
      55                 :         21 : }
      56                 :            : 
      57                 :            : int
      58                 :         25 : main(int argc, char *argv[])
      59                 :            : {
      60                 :         25 :         struct spdk_app_opts opts = {};
      61                 :            :         int rc;
      62                 :            : 
      63                 :         25 :         spdk_app_opts_init(&opts, sizeof(opts));
      64                 :         25 :         opts.name = "vhost";
      65                 :            : 
      66         [ +  + ]:         25 :         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         [ +  + ]:         22 :         if (g_pid_path) {
      73                 :          1 :                 save_pid(g_pid_path);
      74                 :            :         }
      75                 :            : 
      76                 :            :         /* Blocks until the application is exiting */
      77                 :         22 :         rc = spdk_app_start(&opts, vhost_started, NULL);
      78                 :            : 
      79                 :         22 :         spdk_app_fini();
      80                 :            : 
      81                 :         22 :         return rc;
      82                 :            : }

Generated by: LCOV version 1.14