LCOV - code coverage report
Current view: top level - spdk/test/app/bdev_svc - bdev_svc.c (source / functions) Hit Total Coverage
Test: Combined Lines: 26 33 78.8 %
Date: 2024-07-12 06:37:40 Functions: 3 5 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 20 45.0 %

           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/env.h"
       9                 :            : #include "spdk/event.h"
      10                 :            : 
      11                 :            : static char g_path[256];
      12                 :            : static bool g_unaffinitize_thread = false;
      13                 :            : 
      14                 :            : static void
      15                 :          0 : bdev_svc_usage(void)
      16                 :            : {
      17                 :          0 : }
      18                 :            : 
      19                 :            : static int
      20                 :          0 : bdev_svc_parse_arg(int ch, char *arg)
      21                 :            : {
      22                 :          0 :         return 0;
      23                 :            : }
      24                 :            : 
      25                 :            : static void
      26                 :        220 : bdev_svc_start(void *arg1)
      27                 :            : {
      28                 :            :         int fd;
      29                 :        220 :         int shm_id = (intptr_t)arg1;
      30                 :            : 
      31   [ +  +  +  - ]:        220 :         if (g_unaffinitize_thread) {
      32                 :        220 :                 spdk_unaffinitize_thread();
      33                 :            :         }
      34                 :            : 
      35         [ -  + ]:        220 :         snprintf(g_path, sizeof(g_path), "/var/run/spdk_bdev%d", shm_id);
      36         [ -  + ]:        220 :         fd = open(g_path, O_CREAT | O_EXCL | O_RDWR, S_IFREG);
      37         [ -  + ]:        220 :         if (fd < 0) {
      38   [ #  #  #  # ]:          0 :                 fprintf(stderr, "could not create sentinel file %s\n", g_path);
      39                 :          0 :                 exit(1);
      40                 :            :         }
      41                 :        220 :         close(fd);
      42                 :        220 : }
      43                 :            : 
      44                 :            : static void
      45                 :        220 : bdev_svc_shutdown(void)
      46                 :            : {
      47         [ -  + ]:        220 :         unlink(g_path);
      48                 :        220 :         spdk_app_stop(0);
      49                 :        220 : }
      50                 :            : 
      51                 :            : int
      52                 :        220 : main(int argc, char **argv)
      53                 :            : {
      54                 :            :         int rc;
      55                 :        220 :         struct spdk_app_opts opts = {};
      56                 :        220 :         const char *reactor_mask = "0x1";
      57                 :            : 
      58                 :            :         /* default value in opts structure */
      59                 :        220 :         spdk_app_opts_init(&opts, sizeof(opts));
      60                 :            : 
      61                 :        220 :         opts.name = "bdev_svc";
      62                 :        220 :         opts.reactor_mask = reactor_mask;
      63                 :        220 :         opts.shutdown_cb = bdev_svc_shutdown;
      64                 :            : 
      65         [ -  + ]:        220 :         if ((rc = spdk_app_parse_args(argc, argv, &opts, "", NULL,
      66                 :            :                                       bdev_svc_parse_arg, bdev_svc_usage)) !=
      67                 :            :             SPDK_APP_PARSE_ARGS_SUCCESS) {
      68                 :          0 :                 exit(rc);
      69                 :            :         }
      70                 :            : 
      71                 :            :         /* User did not specify a reactor mask.  Test scripts may do this when using
      72                 :            :          *  bdev_svc as a primary process to speed up nvme test programs by running
      73                 :            :          *  them as secondary processes.  In that case, we will unaffinitize the thread
      74                 :            :          *  in the bdev_svc_start routine, which will allow the scheduler to move this
      75                 :            :          *  thread so it doesn't conflict with pinned threads in the secondary processes.
      76                 :            :          */
      77         [ +  - ]:        220 :         if (opts.reactor_mask == reactor_mask) {
      78                 :        220 :                 g_unaffinitize_thread = true;
      79                 :            :         }
      80                 :            : 
      81                 :        220 :         rc = spdk_app_start(&opts, bdev_svc_start, (void *)(intptr_t)opts.shm_id);
      82                 :            : 
      83                 :        220 :         spdk_app_fini();
      84                 :            : 
      85                 :        220 :         return rc;
      86                 :            : }

Generated by: LCOV version 1.14