LCOV - code coverage report
Current view: top level - spdk/examples/nvmf/nvmf - nvmf.c (source / functions) Hit Total Coverage
Test: Combined Lines: 309 424 72.9 %
Date: 2024-07-13 15:09:50 Functions: 32 33 97.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 138 325 42.5 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2019 Intel Corporation. All rights reserved.
       3                 :            :  *   Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/stdinc.h"
       7                 :            : 
       8                 :            : #include "spdk/env.h"
       9                 :            : #include "spdk/event.h"
      10                 :            : #include "spdk/init.h"
      11                 :            : #include "spdk/string.h"
      12                 :            : #include "spdk/thread.h"
      13                 :            : #include "spdk/bdev.h"
      14                 :            : #include "spdk/rpc.h"
      15                 :            : #include "spdk/nvmf.h"
      16                 :            : #include "spdk/likely.h"
      17                 :            : 
      18                 :            : #include "spdk_internal/event.h"
      19                 :            : 
      20                 :            : #define NVMF_DEFAULT_SUBSYSTEMS         32
      21                 :            : #define NVMF_GETOPT_STRING "g:i:m:n:p:r:s:u:h"
      22                 :            : 
      23                 :            : static const char *g_rpc_addr = SPDK_DEFAULT_RPC_ADDR;
      24                 :            : 
      25                 :            : enum nvmf_target_state {
      26                 :            :         NVMF_INIT_SUBSYSTEM = 0,
      27                 :            :         NVMF_INIT_TARGET,
      28                 :            :         NVMF_INIT_POLL_GROUPS,
      29                 :            :         NVMF_INIT_START_SUBSYSTEMS,
      30                 :            :         NVMF_RUNNING,
      31                 :            :         NVMF_FINI_STOP_SUBSYSTEMS,
      32                 :            :         NVMF_FINI_POLL_GROUPS,
      33                 :            :         NVMF_FINI_TARGET,
      34                 :            :         NVMF_FINI_SUBSYSTEM,
      35                 :            : };
      36                 :            : 
      37                 :            : struct nvmf_lw_thread {
      38                 :            :         TAILQ_ENTRY(nvmf_lw_thread) link;
      39                 :            :         bool resched;
      40                 :            : };
      41                 :            : 
      42                 :            : struct nvmf_reactor {
      43                 :            :         uint32_t core;
      44                 :            : 
      45                 :            :         struct spdk_ring                *threads;
      46                 :            :         TAILQ_ENTRY(nvmf_reactor)       link;
      47                 :            : };
      48                 :            : 
      49                 :            : struct nvmf_target_poll_group {
      50                 :            :         struct spdk_nvmf_poll_group             *group;
      51                 :            :         struct spdk_thread                      *thread;
      52                 :            : 
      53                 :            :         TAILQ_ENTRY(nvmf_target_poll_group)     link;
      54                 :            : };
      55                 :            : 
      56                 :            : struct nvmf_target {
      57                 :            :         struct spdk_nvmf_tgt    *tgt;
      58                 :            : 
      59                 :            :         int max_subsystems;
      60                 :            : };
      61                 :            : 
      62                 :            : TAILQ_HEAD(, nvmf_reactor) g_reactors = TAILQ_HEAD_INITIALIZER(g_reactors);
      63                 :            : TAILQ_HEAD(, nvmf_target_poll_group) g_poll_groups = TAILQ_HEAD_INITIALIZER(g_poll_groups);
      64                 :            : static uint32_t g_num_poll_groups = 0;
      65                 :            : 
      66                 :            : static struct nvmf_reactor *g_main_reactor = NULL;
      67                 :            : static struct nvmf_reactor *g_next_reactor = NULL;
      68                 :            : static struct spdk_thread *g_init_thread = NULL;
      69                 :            : static struct spdk_thread *g_fini_thread = NULL;
      70                 :            : static struct nvmf_target g_nvmf_tgt = {
      71                 :            :         .max_subsystems = NVMF_DEFAULT_SUBSYSTEMS,
      72                 :            : };
      73                 :            : 
      74                 :            : static struct nvmf_target_poll_group *g_next_pg = NULL;
      75                 :            : static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
      76                 :            : static bool g_reactors_exit = false;
      77                 :            : static enum nvmf_target_state g_target_state;
      78                 :            : static bool g_intr_received = false;
      79                 :            : 
      80                 :            : static uint32_t g_migrate_pg_period_us = 0;
      81                 :            : static struct spdk_poller *g_migrate_pg_poller = NULL;
      82                 :            : 
      83                 :            : static void nvmf_target_advance_state(void);
      84                 :            : static int nvmf_schedule_spdk_thread(struct spdk_thread *thread);
      85                 :            : 
      86                 :            : static void
      87                 :          0 : usage(char *program_name)
      88                 :            : {
      89         [ #  # ]:          0 :         printf("%s options", program_name);
      90                 :          0 :         printf("\n");
      91         [ #  # ]:          0 :         printf("\t[-g period of round robin poll group migration (us) (default: 0 (disabled))]\n");
      92         [ #  # ]:          0 :         printf("\t[-h show this usage]\n");
      93         [ #  # ]:          0 :         printf("\t[-i shared memory ID (optional)]\n");
      94         [ #  # ]:          0 :         printf("\t[-m core mask for DPDK]\n");
      95         [ #  # ]:          0 :         printf("\t[-n max subsystems for target(default: 32)]\n");
      96         [ #  # ]:          0 :         printf("\t[-r RPC listen address (default /var/tmp/spdk.sock)]\n");
      97         [ #  # ]:          0 :         printf("\t[-s memory size in MB for DPDK (default: 0MB)]\n");
      98         [ #  # ]:          0 :         printf("\t[-u disable PCI access]\n");
      99         [ #  # ]:          0 :         printf("\t[--no-huge SPDK is run without hugepages]\n");
     100                 :          0 : }
     101                 :            : 
     102                 :            : static const struct option g_nvmf_cmdline_opts[] = {
     103                 :            : #define NVMF_NO_HUGE        257
     104                 :            :         {"no-huge",                   no_argument,    NULL, NVMF_NO_HUGE},
     105                 :            :         {0, 0, 0, 0}
     106                 :            : };
     107                 :            : 
     108                 :            : static int
     109                 :          4 : parse_args(int argc, char **argv, struct spdk_env_opts *opts)
     110                 :            : {
     111                 :          0 :         int op, opt_index;
     112                 :            :         long int value;
     113                 :            : 
     114   [ -  +  -  +  :         16 :         while ((op = getopt_long(argc, argv, NVMF_GETOPT_STRING, g_nvmf_cmdline_opts, &opt_index)) != -1) {
                   +  + ]
     115   [ +  +  +  -  :         12 :                 switch (op) {
          -  -  -  -  -  
                      - ]
     116                 :          4 :                 case 'g':
     117                 :          4 :                         value = spdk_strtol(optarg, 10);
     118         [ -  + ]:          4 :                         if (value < 0) {
     119   [ #  #  #  # ]:          0 :                                 fprintf(stderr, "converting a string to integer failed\n");
     120                 :          0 :                                 return -EINVAL;
     121                 :            :                         }
     122                 :          4 :                         g_migrate_pg_period_us = value;
     123                 :          4 :                         break;
     124                 :          4 :                 case 'i':
     125                 :          4 :                         value = spdk_strtol(optarg, 10);
     126         [ -  + ]:          4 :                         if (value < 0) {
     127   [ #  #  #  # ]:          0 :                                 fprintf(stderr, "converting a string to integer failed\n");
     128                 :          0 :                                 return -EINVAL;
     129                 :            :                         }
     130                 :          4 :                         opts->shm_id = value;
     131                 :          4 :                         break;
     132                 :          4 :                 case 'm':
     133                 :          4 :                         opts->core_mask = optarg;
     134                 :          4 :                         break;
     135                 :          0 :                 case 'n':
     136                 :          0 :                         g_nvmf_tgt.max_subsystems = spdk_strtol(optarg, 10);
     137         [ #  # ]:          0 :                         if (g_nvmf_tgt.max_subsystems < 0) {
     138   [ #  #  #  # ]:          0 :                                 fprintf(stderr, "converting a string to integer failed\n");
     139                 :          0 :                                 return -EINVAL;
     140                 :            :                         }
     141                 :          0 :                         break;
     142                 :          0 :                 case 'r':
     143                 :          0 :                         g_rpc_addr = optarg;
     144                 :          0 :                         break;
     145                 :          0 :                 case 's':
     146                 :          0 :                         value = spdk_strtol(optarg, 10);
     147         [ #  # ]:          0 :                         if (value < 0) {
     148   [ #  #  #  # ]:          0 :                                 fprintf(stderr, "converting a string to integer failed\n");
     149                 :          0 :                                 return -EINVAL;
     150                 :            :                         }
     151                 :          0 :                         opts->mem_size = value;
     152                 :          0 :                         break;
     153                 :          0 :                 case 'u':
     154                 :          0 :                         opts->no_pci = true;
     155                 :          0 :                         break;
     156                 :          0 :                 case 'h':
     157                 :          0 :                         usage(argv[0]);
     158                 :          0 :                         exit(EXIT_SUCCESS);
     159                 :          0 :                 case NVMF_NO_HUGE:
     160                 :          0 :                         opts->no_huge = true;
     161                 :          0 :                         break;
     162                 :          0 :                 default:
     163                 :          0 :                         usage(argv[0]);
     164                 :          0 :                         return 1;
     165                 :            :                 }
     166                 :            :         }
     167                 :            : 
     168                 :          4 :         return 0;
     169                 :            : }
     170                 :            : 
     171                 :            : static int
     172                 :         16 : nvmf_reactor_run(void *arg)
     173                 :            : {
     174                 :         16 :         struct nvmf_reactor *nvmf_reactor = arg;
     175                 :          0 :         struct nvmf_lw_thread *lw_thread;
     176                 :            :         struct spdk_thread *thread;
     177                 :            : 
     178                 :            :         /* run all the lightweight threads in this nvmf_reactor by FIFO. */
     179                 :            :         do {
     180         [ +  + ]:   67785788 :                 if (spdk_ring_dequeue(nvmf_reactor->threads, (void **)&lw_thread, 1)) {
     181                 :   18541798 :                         thread = spdk_thread_get_from_ctx(lw_thread);
     182                 :            : 
     183                 :   18541798 :                         spdk_thread_poll(thread, 0, 0);
     184                 :            : 
     185   [ +  +  +  + ]:   18541798 :                         if (spdk_unlikely(spdk_thread_is_exited(thread) &&
     186                 :            :                                           spdk_thread_is_idle(thread))) {
     187                 :         12 :                                 spdk_thread_destroy(thread);
     188   [ -  +  +  + ]:   18541786 :                         } else if (spdk_unlikely(lw_thread->resched)) {
     189                 :      15735 :                                 lw_thread->resched = false;
     190                 :      15735 :                                 nvmf_schedule_spdk_thread(thread);
     191                 :            :                         } else {
     192                 :   18526051 :                                 spdk_ring_enqueue(nvmf_reactor->threads, (void **)&lw_thread, 1, NULL);
     193                 :            :                         }
     194                 :            :                 }
     195   [ -  +  +  + ]:   67785788 :         } while (!g_reactors_exit);
     196                 :            : 
     197                 :            :         /* free all the lightweight threads */
     198         [ +  + ]:         28 :         while (spdk_ring_dequeue(nvmf_reactor->threads, (void **)&lw_thread, 1)) {
     199                 :         12 :                 thread = spdk_thread_get_from_ctx(lw_thread);
     200                 :         12 :                 spdk_set_thread(thread);
     201                 :            : 
     202         [ +  + ]:         12 :                 if (spdk_thread_is_exited(thread)) {
     203                 :          8 :                         spdk_thread_destroy(thread);
     204                 :            :                 } else {
     205                 :            :                         /* This thread is not exited yet, and may need to communicate with other threads
     206                 :            :                          * to be exited. So mark it as exiting, and check again after traversing other threads.
     207                 :            :                          */
     208                 :          4 :                         spdk_thread_exit(thread);
     209                 :          4 :                         spdk_thread_poll(thread, 0, 0);
     210                 :          4 :                         spdk_ring_enqueue(nvmf_reactor->threads, (void **)&lw_thread, 1, NULL);
     211                 :            :                 }
     212                 :            :         }
     213                 :            : 
     214                 :         16 :         return 0;
     215                 :            : }
     216                 :            : 
     217                 :            : static int
     218                 :      15755 : nvmf_schedule_spdk_thread(struct spdk_thread *thread)
     219                 :            : {
     220                 :            :         struct nvmf_reactor *nvmf_reactor;
     221                 :          0 :         struct nvmf_lw_thread *lw_thread;
     222                 :            :         struct spdk_cpuset *cpumask;
     223                 :            :         uint32_t i;
     224                 :            : 
     225                 :            :         /* Lightweight threads may have a requested cpumask.
     226                 :            :          * This is a request only - the scheduler does not have to honor it.
     227                 :            :          * For this scheduler implementation, each reactor is pinned to
     228                 :            :          * a particular core so honoring the request is reasonably easy.
     229                 :            :          */
     230                 :      15755 :         cpumask = spdk_thread_get_cpumask(thread);
     231                 :            : 
     232                 :      15755 :         lw_thread = spdk_thread_get_ctx(thread);
     233         [ -  + ]:      15755 :         assert(lw_thread != NULL);
     234         [ -  + ]:      15755 :         memset(lw_thread, 0, sizeof(*lw_thread));
     235                 :            : 
     236                 :            :         /* assign lightweight threads to nvmf reactor(core)
     237                 :            :          * Here we use the mutex.The way the actual SPDK event framework
     238                 :            :          * solves this is by using internal rings for messages between reactors
     239                 :            :          */
     240         [ -  + ]:      15755 :         pthread_mutex_lock(&g_mutex);
     241         [ +  - ]:      34671 :         for (i = 0; i < spdk_env_get_core_count(); i++) {
     242         [ +  + ]:      34671 :                 if (g_next_reactor == NULL) {
     243                 :       8665 :                         g_next_reactor = TAILQ_FIRST(&g_reactors);
     244                 :            :                 }
     245                 :      34671 :                 nvmf_reactor = g_next_reactor;
     246                 :      34671 :                 g_next_reactor = TAILQ_NEXT(g_next_reactor, link);
     247                 :            : 
     248                 :            :                 /* each spdk_thread has the core affinity */
     249         [ +  + ]:      34671 :                 if (spdk_cpuset_get_cpu(cpumask, nvmf_reactor->core)) {
     250                 :      15755 :                         spdk_ring_enqueue(nvmf_reactor->threads, (void **)&lw_thread, 1, NULL);
     251                 :      15755 :                         break;
     252                 :            :                 }
     253                 :            :         }
     254         [ -  + ]:      15755 :         pthread_mutex_unlock(&g_mutex);
     255                 :            : 
     256         [ -  + ]:      15755 :         if (i == spdk_env_get_core_count()) {
     257   [ #  #  #  # ]:          0 :                 fprintf(stderr, "failed to schedule spdk thread\n");
     258                 :          0 :                 return -1;
     259                 :            :         }
     260                 :      15755 :         return 0;
     261                 :            : }
     262                 :            : 
     263                 :            : static void
     264                 :      15760 : nvmf_request_spdk_thread_reschedule(struct spdk_thread *thread)
     265                 :            : {
     266                 :            :         struct nvmf_lw_thread *lw_thread;
     267                 :            : 
     268         [ -  + ]:      15760 :         assert(thread == spdk_get_thread());
     269                 :            : 
     270                 :      15760 :         lw_thread = spdk_thread_get_ctx(thread);
     271                 :            : 
     272         [ -  + ]:      15760 :         assert(lw_thread != NULL);
     273                 :            : 
     274                 :      15760 :         lw_thread->resched = true;
     275                 :      15760 : }
     276                 :            : 
     277                 :            : static int
     278                 :      15780 : nvmf_reactor_thread_op(struct spdk_thread *thread, enum spdk_thread_op op)
     279                 :            : {
     280      [ +  +  - ]:      15780 :         switch (op) {
     281                 :         20 :         case SPDK_THREAD_OP_NEW:
     282                 :         20 :                 return nvmf_schedule_spdk_thread(thread);
     283                 :      15760 :         case SPDK_THREAD_OP_RESCHED:
     284                 :      15760 :                 nvmf_request_spdk_thread_reschedule(thread);
     285                 :      15760 :                 return 0;
     286                 :          0 :         default:
     287                 :          0 :                 return -ENOTSUP;
     288                 :            :         }
     289                 :            : }
     290                 :            : 
     291                 :            : static bool
     292                 :      15780 : nvmf_reactor_thread_op_supported(enum spdk_thread_op op)
     293                 :            : {
     294         [ +  - ]:      15780 :         switch (op) {
     295                 :      15780 :         case SPDK_THREAD_OP_NEW:
     296                 :            :         case SPDK_THREAD_OP_RESCHED:
     297                 :      15780 :                 return true;
     298                 :          0 :         default:
     299                 :          0 :                 return false;
     300                 :            :         }
     301                 :            : }
     302                 :            : 
     303                 :            : static int
     304                 :          4 : nvmf_init_threads(void)
     305                 :            : {
     306                 :            :         int rc;
     307                 :            :         uint32_t i;
     308                 :          0 :         char thread_name[32];
     309                 :            :         struct nvmf_reactor *nvmf_reactor;
     310                 :          0 :         struct spdk_cpuset cpumask;
     311                 :          4 :         uint32_t main_core = spdk_env_get_current_core();
     312                 :            : 
     313                 :            :         /* Whenever SPDK creates a new lightweight thread it will call
     314                 :            :          * nvmf_schedule_spdk_thread asking for the application to begin
     315                 :            :          * polling it via spdk_thread_poll(). Each lightweight thread in
     316                 :            :          * SPDK optionally allocates extra memory to be used by the application
     317                 :            :          * framework. The size of the extra memory allocated is the second parameter.
     318                 :            :          */
     319                 :          4 :         spdk_thread_lib_init_ext(nvmf_reactor_thread_op, nvmf_reactor_thread_op_supported,
     320                 :            :                                  sizeof(struct nvmf_lw_thread), SPDK_DEFAULT_MSG_MEMPOOL_SIZE);
     321                 :            : 
     322                 :            :         /* Spawn one system thread per CPU core. The system thread is called a reactor.
     323                 :            :          * SPDK will spawn lightweight threads that must be mapped to reactors in
     324                 :            :          * nvmf_schedule_spdk_thread. Using a single system thread per CPU core is a
     325                 :            :          * choice unique to this application. SPDK itself does not require this specific
     326                 :            :          * threading model. For example, another viable threading model would be
     327                 :            :          * dynamically scheduling the lightweight threads onto a thread pool using a
     328                 :            :          * work queue.
     329                 :            :          */
     330         [ +  + ]:         20 :         SPDK_ENV_FOREACH_CORE(i) {
     331                 :         16 :                 nvmf_reactor = calloc(1, sizeof(struct nvmf_reactor));
     332         [ -  + ]:         16 :                 if (!nvmf_reactor) {
     333   [ #  #  #  # ]:          0 :                         fprintf(stderr, "failed to alloc nvmf reactor\n");
     334                 :          0 :                         rc = -ENOMEM;
     335                 :          0 :                         goto err_exit;
     336                 :            :                 }
     337                 :            : 
     338                 :         16 :                 nvmf_reactor->core = i;
     339                 :            : 
     340                 :         16 :                 nvmf_reactor->threads = spdk_ring_create(SPDK_RING_TYPE_MP_SC, 1024, SPDK_ENV_SOCKET_ID_ANY);
     341         [ -  + ]:         16 :                 if (!nvmf_reactor->threads) {
     342   [ #  #  #  # ]:          0 :                         fprintf(stderr, "failed to alloc ring\n");
     343                 :          0 :                         free(nvmf_reactor);
     344                 :          0 :                         rc = -ENOMEM;
     345                 :          0 :                         goto err_exit;
     346                 :            :                 }
     347                 :            : 
     348                 :         16 :                 TAILQ_INSERT_TAIL(&g_reactors, nvmf_reactor, link);
     349                 :            : 
     350         [ +  + ]:         16 :                 if (i == main_core) {
     351                 :          4 :                         g_main_reactor = nvmf_reactor;
     352                 :          4 :                         g_next_reactor = g_main_reactor;
     353                 :            :                 } else {
     354                 :         12 :                         rc = spdk_env_thread_launch_pinned(i,
     355                 :            :                                                            nvmf_reactor_run,
     356                 :            :                                                            nvmf_reactor);
     357         [ -  + ]:         12 :                         if (rc) {
     358   [ #  #  #  # ]:          0 :                                 fprintf(stderr, "failed to pin reactor launch\n");
     359                 :          0 :                                 goto err_exit;
     360                 :            :                         }
     361                 :            :                 }
     362                 :            :         }
     363                 :            : 
     364                 :            :         /* Spawn a lightweight thread only on the current core to manage this application. */
     365                 :          4 :         spdk_cpuset_zero(&cpumask);
     366                 :          4 :         spdk_cpuset_set_cpu(&cpumask, main_core, true);
     367         [ -  + ]:          4 :         snprintf(thread_name, sizeof(thread_name), "nvmf_main_thread");
     368                 :          4 :         g_init_thread = spdk_thread_create(thread_name, &cpumask);
     369         [ -  + ]:          4 :         if (!g_init_thread) {
     370   [ #  #  #  # ]:          0 :                 fprintf(stderr, "failed to create spdk thread\n");
     371                 :          0 :                 return -1;
     372                 :            :         }
     373                 :            : 
     374   [ -  +  -  + ]:          4 :         fprintf(stdout, "nvmf threads initialize successfully\n");
     375                 :          4 :         return 0;
     376                 :            : 
     377                 :          0 : err_exit:
     378                 :          0 :         return rc;
     379                 :            : }
     380                 :            : 
     381                 :            : static void
     382                 :          4 : nvmf_destroy_threads(void)
     383                 :            : {
     384                 :            :         struct nvmf_reactor *nvmf_reactor, *tmp;
     385                 :            : 
     386         [ +  + ]:         20 :         TAILQ_FOREACH_SAFE(nvmf_reactor, &g_reactors, link, tmp) {
     387                 :         16 :                 spdk_ring_free(nvmf_reactor->threads);
     388                 :         16 :                 free(nvmf_reactor);
     389                 :            :         }
     390                 :            : 
     391         [ -  + ]:          4 :         pthread_mutex_destroy(&g_mutex);
     392                 :          4 :         spdk_thread_lib_fini();
     393   [ -  +  -  + ]:          4 :         fprintf(stdout, "nvmf threads destroy successfully\n");
     394                 :          4 : }
     395                 :            : 
     396                 :            : static void
     397                 :          4 : nvmf_tgt_destroy_done(void *ctx, int status)
     398                 :            : {
     399   [ -  +  -  + ]:          4 :         fprintf(stdout, "destroyed the nvmf target service\n");
     400                 :            : 
     401                 :          4 :         g_target_state = NVMF_FINI_SUBSYSTEM;
     402                 :          4 :         nvmf_target_advance_state();
     403                 :          4 : }
     404                 :            : 
     405                 :            : static void
     406                 :          4 : nvmf_destroy_nvmf_tgt(void)
     407                 :            : {
     408         [ +  - ]:          4 :         if (g_nvmf_tgt.tgt) {
     409                 :          4 :                 spdk_nvmf_tgt_destroy(g_nvmf_tgt.tgt, nvmf_tgt_destroy_done, NULL);
     410                 :            :         } else {
     411                 :          0 :                 g_target_state = NVMF_FINI_SUBSYSTEM;
     412                 :            :         }
     413                 :          4 : }
     414                 :            : 
     415                 :            : static void
     416                 :          4 : nvmf_create_nvmf_tgt(void)
     417                 :            : {
     418                 :            :         struct spdk_nvmf_subsystem *subsystem;
     419                 :          4 :         struct spdk_nvmf_target_opts tgt_opts = {};
     420                 :            : 
     421                 :          4 :         tgt_opts.max_subsystems = g_nvmf_tgt.max_subsystems;
     422         [ -  + ]:          4 :         snprintf(tgt_opts.name, sizeof(tgt_opts.name), "%s", "nvmf_example");
     423                 :            :         /* Construct the default NVMe-oF target
     424                 :            :          * An NVMe-oF target is a collection of subsystems, namespace, and poll
     425                 :            :          * groups, and defines the scope of the NVMe-oF discovery service.
     426                 :            :          */
     427                 :          4 :         g_nvmf_tgt.tgt = spdk_nvmf_tgt_create(&tgt_opts);
     428         [ -  + ]:          4 :         if (g_nvmf_tgt.tgt == NULL) {
     429   [ #  #  #  # ]:          0 :                 fprintf(stderr, "spdk_nvmf_tgt_create() failed\n");
     430                 :          0 :                 goto error;
     431                 :            :         }
     432                 :            : 
     433                 :            :         /* Create and add discovery subsystem to the NVMe-oF target.
     434                 :            :          * NVMe-oF defines a discovery mechanism that a host uses to determine
     435                 :            :          * the NVM subsystems that expose namespaces that the host may access.
     436                 :            :          * It provides a host with following capabilities:
     437                 :            :          *      1,The ability to discover a list of NVM subsystems with namespaces
     438                 :            :          *        that are accessible to the host.
     439                 :            :          *      2,The ability to discover multiple paths to an NVM subsystem.
     440                 :            :          *      3,The ability to discover controllers that are statically configured.
     441                 :            :          */
     442                 :          4 :         subsystem = spdk_nvmf_subsystem_create(g_nvmf_tgt.tgt, SPDK_NVMF_DISCOVERY_NQN,
     443                 :            :                                                SPDK_NVMF_SUBTYPE_DISCOVERY_CURRENT, 0);
     444         [ -  + ]:          4 :         if (subsystem == NULL) {
     445   [ #  #  #  # ]:          0 :                 fprintf(stderr, "failed to create discovery nvmf library subsystem\n");
     446                 :          0 :                 goto error;
     447                 :            :         }
     448                 :            : 
     449                 :            :         /* Allow any host to access the discovery subsystem */
     450                 :          4 :         spdk_nvmf_subsystem_set_allow_any_host(subsystem, true);
     451                 :            : 
     452   [ -  +  -  + ]:          4 :         fprintf(stdout, "created a nvmf target service\n");
     453                 :            : 
     454                 :          4 :         g_target_state = NVMF_INIT_POLL_GROUPS;
     455                 :          4 :         return;
     456                 :            : 
     457                 :          0 : error:
     458                 :          0 :         g_target_state = NVMF_FINI_TARGET;
     459                 :            : }
     460                 :            : 
     461                 :            : static void
     462                 :          8 : nvmf_tgt_subsystem_stop_next(struct spdk_nvmf_subsystem *subsystem,
     463                 :            :                              void *cb_arg, int status)
     464                 :            : {
     465                 :            :         int rc;
     466                 :            : 
     467                 :          8 :         subsystem = spdk_nvmf_subsystem_get_next(subsystem);
     468         [ +  + ]:          8 :         if (subsystem) {
     469                 :          4 :                 rc = spdk_nvmf_subsystem_stop(subsystem,
     470                 :            :                                               nvmf_tgt_subsystem_stop_next,
     471                 :            :                                               cb_arg);
     472         [ -  + ]:          4 :                 if (rc) {
     473                 :          0 :                         nvmf_tgt_subsystem_stop_next(subsystem, cb_arg, 0);
     474   [ #  #  #  # ]:          0 :                         fprintf(stderr, "Unable to stop NVMe-oF subsystem. Trying others.\n");
     475                 :            :                 }
     476                 :          4 :                 return;
     477                 :            :         }
     478                 :            : 
     479   [ -  +  -  + ]:          4 :         fprintf(stdout, "all subsystems of target stopped\n");
     480                 :            : 
     481                 :          4 :         g_target_state = NVMF_FINI_POLL_GROUPS;
     482                 :          4 :         nvmf_target_advance_state();
     483                 :            : }
     484                 :            : 
     485                 :            : static void
     486                 :          4 : nvmf_tgt_stop_subsystems(struct nvmf_target *nvmf_tgt)
     487                 :            : {
     488                 :            :         struct spdk_nvmf_subsystem *subsystem;
     489                 :            :         int rc;
     490                 :            : 
     491                 :          4 :         subsystem = spdk_nvmf_subsystem_get_first(nvmf_tgt->tgt);
     492         [ +  - ]:          4 :         if (spdk_likely(subsystem)) {
     493                 :          4 :                 rc = spdk_nvmf_subsystem_stop(subsystem,
     494                 :            :                                               nvmf_tgt_subsystem_stop_next,
     495                 :            :                                               NULL);
     496         [ -  + ]:          4 :                 if (rc) {
     497                 :          0 :                         nvmf_tgt_subsystem_stop_next(subsystem, NULL, 0);
     498         [ #  # ]:          0 :                         fprintf(stderr, "Unable to stop NVMe-oF subsystem. Trying others.\n");
     499                 :            :                 }
     500                 :            :         } else {
     501                 :          0 :                 g_target_state = NVMF_FINI_POLL_GROUPS;
     502                 :            :         }
     503                 :          4 : }
     504                 :            : 
     505                 :            : static void
     506                 :          4 : nvmf_tgt_subsystem_start_next(struct spdk_nvmf_subsystem *subsystem,
     507                 :            :                               void *cb_arg, int status)
     508                 :            : {
     509                 :            :         int rc;
     510                 :            : 
     511                 :          4 :         subsystem = spdk_nvmf_subsystem_get_next(subsystem);
     512         [ -  + ]:          4 :         if (subsystem) {
     513                 :          0 :                 rc = spdk_nvmf_subsystem_start(subsystem, nvmf_tgt_subsystem_start_next,
     514                 :            :                                                cb_arg);
     515         [ #  # ]:          0 :                 if (rc) {
     516                 :          0 :                         g_target_state = NVMF_FINI_STOP_SUBSYSTEMS;
     517   [ #  #  #  # ]:          0 :                         fprintf(stderr, "Unable to start NVMe-oF subsystem. shutting down app.\n");
     518                 :          0 :                         nvmf_target_advance_state();
     519                 :            :                 }
     520                 :          0 :                 return;
     521                 :            :         }
     522                 :            : 
     523   [ -  +  -  + ]:          4 :         fprintf(stdout, "all subsystems of target started\n");
     524                 :            : 
     525                 :          4 :         g_target_state = NVMF_RUNNING;
     526                 :          4 :         nvmf_target_advance_state();
     527                 :            : }
     528                 :            : 
     529                 :            : static void
     530                 :          4 : nvmf_tgt_start_subsystems(struct nvmf_target *nvmf_tgt)
     531                 :            : {
     532                 :            :         struct spdk_nvmf_subsystem *subsystem;
     533                 :            :         int rc;
     534                 :            : 
     535                 :            :         /* Subsystem is the NVM subsystem which is a combine of namespaces
     536                 :            :          * except the discovery subsystem which is used for discovery service.
     537                 :            :          * It also controls the hosts that means the subsystem determines whether
     538                 :            :          * the host can access this subsystem.
     539                 :            :          */
     540                 :          4 :         subsystem = spdk_nvmf_subsystem_get_first(nvmf_tgt->tgt);
     541         [ +  - ]:          4 :         if (spdk_likely(subsystem)) {
     542                 :            :                 /* In SPDK there are three states in subsystem: Inactive, Active, Paused.
     543                 :            :                  * Start subsystem means make it from inactive to active that means
     544                 :            :                  * subsystem start to work or it can be accessed.
     545                 :            :                  */
     546                 :          4 :                 rc = spdk_nvmf_subsystem_start(subsystem,
     547                 :            :                                                nvmf_tgt_subsystem_start_next,
     548                 :            :                                                NULL);
     549         [ -  + ]:          4 :                 if (rc) {
     550         [ #  # ]:          0 :                         fprintf(stderr, "Unable to start NVMe-oF subsystem. shutting down app.\n");
     551                 :          0 :                         g_target_state = NVMF_FINI_STOP_SUBSYSTEMS;
     552                 :            :                 }
     553                 :            :         } else {
     554                 :          0 :                 g_target_state = NVMF_RUNNING;
     555                 :            :         }
     556                 :          4 : }
     557                 :            : 
     558                 :            : static void
     559                 :         16 : nvmf_tgt_create_poll_groups_done(void *ctx)
     560                 :            : {
     561                 :         16 :         struct nvmf_target_poll_group *pg = ctx;
     562                 :            : 
     563         [ +  + ]:         16 :         if (!g_next_pg) {
     564                 :          4 :                 g_next_pg = pg;
     565                 :            :         }
     566                 :            : 
     567                 :         16 :         TAILQ_INSERT_TAIL(&g_poll_groups, pg, link);
     568                 :            : 
     569         [ -  + ]:         16 :         assert(g_num_poll_groups < spdk_env_get_core_count());
     570                 :            : 
     571         [ +  + ]:         16 :         if (++g_num_poll_groups == spdk_env_get_core_count()) {
     572   [ -  +  -  + ]:          4 :                 fprintf(stdout, "create targets's poll groups done\n");
     573                 :            : 
     574                 :          4 :                 g_target_state = NVMF_INIT_START_SUBSYSTEMS;
     575                 :          4 :                 nvmf_target_advance_state();
     576                 :            :         }
     577                 :         16 : }
     578                 :            : 
     579                 :            : static void
     580                 :         16 : nvmf_tgt_create_poll_group(void *ctx)
     581                 :            : {
     582                 :            :         struct nvmf_target_poll_group *pg;
     583                 :            : 
     584                 :         16 :         pg = calloc(1, sizeof(struct nvmf_target_poll_group));
     585         [ -  + ]:         16 :         if (!pg) {
     586   [ #  #  #  # ]:          0 :                 fprintf(stderr, "failed to allocate poll group\n");
     587                 :          0 :                 assert(false);
     588                 :            :                 return;
     589                 :            :         }
     590                 :            : 
     591                 :         16 :         pg->thread = spdk_get_thread();
     592                 :         16 :         pg->group = spdk_nvmf_poll_group_create(g_nvmf_tgt.tgt);
     593         [ -  + ]:         16 :         if (!pg->group) {
     594   [ #  #  #  # ]:          0 :                 fprintf(stderr, "failed to create poll group of the target\n");
     595                 :          0 :                 free(pg);
     596                 :          0 :                 assert(false);
     597                 :            :                 return;
     598                 :            :         }
     599                 :            : 
     600                 :         16 :         spdk_thread_send_msg(g_init_thread, nvmf_tgt_create_poll_groups_done, pg);
     601                 :            : }
     602                 :            : 
     603                 :            : /* Create a lightweight thread per poll group instead of assuming a pool of lightweight
     604                 :            :  * threads already exist at start up time. A poll group is a collection of unrelated NVMe-oF
     605                 :            :  * connections. Each poll group is only accessed from the associated lightweight thread.
     606                 :            :  */
     607                 :            : static void
     608                 :          4 : nvmf_poll_groups_create(void)
     609                 :            : {
     610                 :          4 :         struct spdk_cpuset tmp_cpumask = {};
     611                 :            :         uint32_t i;
     612                 :          0 :         char thread_name[32];
     613                 :            :         struct spdk_thread *thread;
     614                 :            : 
     615         [ -  + ]:          4 :         assert(g_init_thread != NULL);
     616                 :            : 
     617         [ +  + ]:         20 :         SPDK_ENV_FOREACH_CORE(i) {
     618                 :         16 :                 spdk_cpuset_zero(&tmp_cpumask);
     619                 :         16 :                 spdk_cpuset_set_cpu(&tmp_cpumask, i, true);
     620         [ -  + ]:         16 :                 snprintf(thread_name, sizeof(thread_name), "nvmf_tgt_poll_group_%u", i);
     621                 :            : 
     622                 :         16 :                 thread = spdk_thread_create(thread_name, &tmp_cpumask);
     623         [ -  + ]:         16 :                 assert(thread != NULL);
     624                 :            : 
     625                 :         16 :                 spdk_thread_send_msg(thread, nvmf_tgt_create_poll_group, NULL);
     626                 :            :         }
     627                 :          4 : }
     628                 :            : 
     629                 :            : static void
     630                 :         16 : _nvmf_tgt_destroy_poll_groups_done(void *ctx)
     631                 :            : {
     632         [ -  + ]:         16 :         assert(g_num_poll_groups > 0);
     633                 :            : 
     634         [ +  + ]:         16 :         if (--g_num_poll_groups == 0) {
     635   [ -  +  -  + ]:          4 :                 fprintf(stdout, "destroy targets's poll groups done\n");
     636                 :            : 
     637                 :          4 :                 g_target_state = NVMF_FINI_TARGET;
     638                 :          4 :                 nvmf_target_advance_state();
     639                 :            :         }
     640                 :         16 : }
     641                 :            : 
     642                 :            : static void
     643                 :         16 : nvmf_tgt_destroy_poll_groups_done(void *cb_arg, int status)
     644                 :            : {
     645                 :         16 :         struct nvmf_target_poll_group *pg = cb_arg;
     646                 :            : 
     647                 :         16 :         free(pg);
     648                 :            : 
     649                 :         16 :         spdk_thread_send_msg(g_fini_thread, _nvmf_tgt_destroy_poll_groups_done, NULL);
     650                 :            : 
     651                 :         16 :         spdk_thread_exit(spdk_get_thread());
     652                 :         16 : }
     653                 :            : 
     654                 :            : static void
     655                 :         16 : nvmf_tgt_destroy_poll_group(void *ctx)
     656                 :            : {
     657                 :         16 :         struct nvmf_target_poll_group *pg = ctx;
     658                 :            : 
     659                 :         16 :         spdk_nvmf_poll_group_destroy(pg->group, nvmf_tgt_destroy_poll_groups_done, pg);
     660                 :         16 : }
     661                 :            : 
     662                 :            : static void
     663                 :          4 : nvmf_poll_groups_destroy(void)
     664                 :            : {
     665                 :            :         struct nvmf_target_poll_group *pg, *tmp;
     666                 :            : 
     667                 :          4 :         g_fini_thread = spdk_get_thread();
     668         [ -  + ]:          4 :         assert(g_fini_thread != NULL);
     669                 :            : 
     670         [ +  + ]:         20 :         TAILQ_FOREACH_SAFE(pg, &g_poll_groups, link, tmp) {
     671         [ +  + ]:         16 :                 TAILQ_REMOVE(&g_poll_groups, pg, link);
     672                 :         16 :                 spdk_thread_send_msg(pg->thread, nvmf_tgt_destroy_poll_group, pg);
     673                 :            :         }
     674                 :          4 : }
     675                 :            : 
     676                 :            : static void
     677                 :          4 : nvmf_subsystem_fini_done(void *cb_arg)
     678                 :            : {
     679   [ -  +  -  + ]:          4 :         fprintf(stdout, "bdev subsystem finish successfully\n");
     680                 :          4 :         spdk_rpc_finish();
     681                 :          4 :         g_reactors_exit = true;
     682                 :          4 : }
     683                 :            : 
     684                 :            : static void
     685                 :          4 : nvmf_subsystem_init_done(int rc, void *cb_arg)
     686                 :            : {
     687   [ -  +  -  + ]:          4 :         fprintf(stdout, "bdev subsystem init successfully\n");
     688                 :            : 
     689                 :          4 :         rc = spdk_rpc_initialize(g_rpc_addr, NULL);
     690         [ -  + ]:          4 :         if (rc) {
     691                 :          0 :                 spdk_app_stop(rc);
     692                 :          0 :                 return;
     693                 :            :         }
     694                 :            : 
     695                 :          4 :         spdk_rpc_set_state(SPDK_RPC_RUNTIME);
     696                 :            : 
     697                 :          4 :         g_target_state = NVMF_INIT_TARGET;
     698                 :          4 :         nvmf_target_advance_state();
     699                 :            : }
     700                 :            : 
     701                 :            : static void
     702                 :      15760 : migrate_poll_group_by_rr(void *ctx)
     703                 :            : {
     704                 :            :         uint32_t current_core, next_core;
     705                 :      15760 :         struct spdk_cpuset cpumask = {};
     706                 :            : 
     707                 :      15760 :         current_core = spdk_env_get_current_core();
     708                 :      15760 :         next_core = spdk_env_get_next_core(current_core);
     709         [ +  + ]:      15760 :         if (next_core == UINT32_MAX) {
     710                 :       3940 :                 next_core = spdk_env_get_first_core();
     711                 :            :         }
     712                 :            : 
     713                 :      15760 :         spdk_cpuset_set_cpu(&cpumask, next_core, true);
     714                 :            : 
     715                 :      15760 :         spdk_thread_set_cpumask(&cpumask);
     716                 :      15760 : }
     717                 :            : 
     718                 :            : static int
     719                 :       3940 : migrate_poll_groups_by_rr(void *ctx)
     720                 :            : {
     721                 :            :         struct nvmf_target_poll_group *pg;
     722                 :            : 
     723         [ +  + ]:      19700 :         TAILQ_FOREACH(pg, &g_poll_groups, link) {
     724                 :      15760 :                 spdk_thread_send_msg(pg->thread, migrate_poll_group_by_rr, NULL);
     725                 :            :         }
     726                 :            : 
     727                 :       3940 :         return SPDK_POLLER_BUSY;
     728                 :            : }
     729                 :            : 
     730                 :            : static void
     731                 :         32 : nvmf_target_advance_state(void)
     732                 :            : {
     733                 :            :         enum nvmf_target_state prev_state;
     734                 :            : 
     735                 :            :         do {
     736                 :         36 :                 prev_state = g_target_state;
     737                 :            : 
     738   [ +  +  +  +  :         36 :                 switch (g_target_state) {
          +  +  +  +  +  
                      - ]
     739                 :          4 :                 case NVMF_INIT_SUBSYSTEM:
     740                 :            :                         /* initialize the bdev layer */
     741                 :          4 :                         spdk_subsystem_init(nvmf_subsystem_init_done, NULL);
     742                 :          4 :                         return;
     743                 :          4 :                 case NVMF_INIT_TARGET:
     744                 :          4 :                         nvmf_create_nvmf_tgt();
     745                 :          4 :                         break;
     746                 :          4 :                 case NVMF_INIT_POLL_GROUPS:
     747                 :          4 :                         nvmf_poll_groups_create();
     748                 :          4 :                         break;
     749                 :          4 :                 case NVMF_INIT_START_SUBSYSTEMS:
     750                 :          4 :                         nvmf_tgt_start_subsystems(&g_nvmf_tgt);
     751                 :          4 :                         break;
     752                 :          4 :                 case NVMF_RUNNING:
     753   [ -  +  -  + ]:          4 :                         fprintf(stdout, "nvmf target is running\n");
     754         [ +  - ]:          4 :                         if (g_migrate_pg_period_us != 0) {
     755                 :          4 :                                 g_migrate_pg_poller = SPDK_POLLER_REGISTER(migrate_poll_groups_by_rr, NULL,
     756                 :            :                                                       g_migrate_pg_period_us);
     757                 :            :                         }
     758                 :          4 :                         break;
     759                 :          4 :                 case NVMF_FINI_STOP_SUBSYSTEMS:
     760                 :          4 :                         spdk_poller_unregister(&g_migrate_pg_poller);
     761                 :          4 :                         nvmf_tgt_stop_subsystems(&g_nvmf_tgt);
     762                 :          4 :                         break;
     763                 :          4 :                 case NVMF_FINI_POLL_GROUPS:
     764                 :          4 :                         nvmf_poll_groups_destroy();
     765                 :          4 :                         break;
     766                 :          4 :                 case NVMF_FINI_TARGET:
     767                 :          4 :                         nvmf_destroy_nvmf_tgt();
     768                 :          4 :                         break;
     769                 :          4 :                 case NVMF_FINI_SUBSYSTEM:
     770                 :          4 :                         spdk_subsystem_fini(nvmf_subsystem_fini_done, NULL);
     771                 :          4 :                         break;
     772                 :            :                 }
     773         [ +  + ]:         32 :         } while (g_target_state != prev_state);
     774                 :            : }
     775                 :            : 
     776                 :            : static void
     777                 :          4 : nvmf_target_app_start(void *arg)
     778                 :            : {
     779                 :          4 :         g_target_state = NVMF_INIT_SUBSYSTEM;
     780                 :          4 :         nvmf_target_advance_state();
     781                 :          4 : }
     782                 :            : 
     783                 :            : static void
     784                 :          4 : _nvmf_shutdown_cb(void *ctx)
     785                 :            : {
     786                 :            :         /* Still in initialization state, defer shutdown operation */
     787         [ -  + ]:          4 :         if (g_target_state < NVMF_RUNNING) {
     788                 :          0 :                 spdk_thread_send_msg(spdk_get_thread(), _nvmf_shutdown_cb, NULL);
     789                 :          0 :                 return;
     790         [ -  + ]:          4 :         } else if (g_target_state > NVMF_RUNNING) {
     791                 :            :                 /* Already in Shutdown status, ignore the signal */
     792                 :          0 :                 return;
     793                 :            :         }
     794                 :            : 
     795                 :          4 :         g_target_state = NVMF_FINI_STOP_SUBSYSTEMS;
     796                 :          4 :         nvmf_target_advance_state();
     797                 :            : }
     798                 :            : 
     799                 :            : static void
     800                 :          4 : nvmf_shutdown_cb(int signo)
     801                 :            : {
     802   [ -  +  +  - ]:          4 :         if (!g_intr_received) {
     803                 :          4 :                 g_intr_received = true;
     804                 :          4 :                 spdk_thread_send_msg(g_init_thread, _nvmf_shutdown_cb, NULL);
     805                 :            :         }
     806                 :          4 : }
     807                 :            : 
     808                 :            : static int
     809                 :          4 : nvmf_setup_signal_handlers(void)
     810                 :            : {
     811                 :          0 :         struct sigaction        sigact;
     812                 :          0 :         sigset_t                sigmask;
     813                 :          4 :         int                     signals[] = {SIGINT, SIGTERM};
     814                 :          4 :         int                     num_signals = sizeof(signals) / sizeof(int);
     815                 :            :         int                     rc, i;
     816                 :            : 
     817                 :          4 :         rc = sigemptyset(&sigmask);
     818         [ -  + ]:          4 :         if (rc) {
     819         [ #  # ]:          0 :                 fprintf(stderr, "errno:%d--failed to empty signal set\n", errno);
     820                 :          0 :                 return rc;
     821                 :            :         }
     822                 :          4 :         memset(&sigact, 0, sizeof(sigact));
     823                 :          4 :         rc = sigemptyset(&sigact.sa_mask);
     824         [ -  + ]:          4 :         if (rc) {
     825         [ #  # ]:          0 :                 fprintf(stderr, "errno:%d--failed to empty signal set\n", errno);
     826                 :          0 :                 return rc;
     827                 :            :         }
     828                 :            : 
     829                 :            :         /* Install the same handler for SIGINT and SIGTERM */
     830                 :          4 :         sigact.sa_handler = nvmf_shutdown_cb;
     831                 :            : 
     832         [ +  + ]:         12 :         for (i = 0; i < num_signals; i++) {
     833                 :          8 :                 rc = sigaction(signals[i], &sigact, NULL);
     834         [ -  + ]:          8 :                 if (rc < 0) {
     835         [ #  # ]:          0 :                         fprintf(stderr, "errno:%d--sigaction() failed\n", errno);
     836                 :          0 :                         return rc;
     837                 :            :                 }
     838                 :          8 :                 rc = sigaddset(&sigmask, signals[i]);
     839         [ -  + ]:          8 :                 if (rc) {
     840         [ #  # ]:          0 :                         fprintf(stderr, "errno:%d--failed to add set\n", errno);
     841                 :          0 :                         return rc;
     842                 :            :                 }
     843                 :            :         }
     844                 :            : 
     845                 :          4 :         pthread_sigmask(SIG_UNBLOCK, &sigmask, NULL);
     846                 :            : 
     847                 :          4 :         return 0;
     848                 :            : }
     849                 :            : 
     850                 :            : int
     851                 :          4 : main(int argc, char **argv)
     852                 :            : {
     853                 :            :         int rc;
     854                 :          0 :         struct spdk_env_opts opts;
     855                 :            : 
     856                 :          4 :         spdk_env_opts_init(&opts);
     857                 :          4 :         opts.name = "nvmf-example";
     858                 :            : 
     859                 :          4 :         rc = parse_args(argc, argv, &opts);
     860         [ -  + ]:          4 :         if (rc != 0) {
     861                 :          0 :                 return rc;
     862                 :            :         }
     863                 :            : 
     864         [ -  + ]:          4 :         if (spdk_env_init(&opts) < 0) {
     865   [ #  #  #  # ]:          0 :                 fprintf(stderr, "unable to initialize SPDK env\n");
     866                 :          0 :                 return -EINVAL;
     867                 :            :         }
     868                 :            : 
     869                 :            :         /* Initialize the threads */
     870                 :          4 :         rc = nvmf_init_threads();
     871         [ -  + ]:          4 :         assert(rc == 0);
     872                 :            : 
     873                 :            :         /* Send a message to the thread assigned to the main reactor
     874                 :            :          * that continues initialization. This is how we bootstrap the
     875                 :            :          * program so that all code from here on is running on an SPDK thread.
     876                 :            :          */
     877         [ -  + ]:          4 :         assert(g_init_thread != NULL);
     878                 :            : 
     879                 :          4 :         rc = nvmf_setup_signal_handlers();
     880         [ -  + ]:          4 :         assert(rc == 0);
     881                 :            : 
     882                 :          4 :         spdk_thread_send_msg(g_init_thread, nvmf_target_app_start, NULL);
     883                 :            : 
     884                 :          4 :         nvmf_reactor_run(g_main_reactor);
     885                 :            : 
     886                 :          4 :         spdk_env_thread_wait_all();
     887                 :          4 :         nvmf_destroy_threads();
     888                 :            : 
     889                 :          4 :         spdk_env_fini();
     890                 :            : 
     891                 :          4 :         return rc;
     892                 :            : }

Generated by: LCOV version 1.14