LCOV - code coverage report
Current view: top level - spdk/lib/event - app.c (source / functions) Hit Total Coverage
Test: Combined Lines: 709 958 74.0 %
Date: 2024-11-15 11:55:20 Functions: 39 42 92.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1106 2158 51.3 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2016 Intel Corporation. All rights reserved.
       3                 :            :  *   Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
       4                 :            :  *   Copyright (c) 2021, 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
       5                 :            :  */
       6                 :            : 
       7                 :            : #include "spdk/stdinc.h"
       8                 :            : #include "spdk/version.h"
       9                 :            : 
      10                 :            : #include "spdk_internal/event.h"
      11                 :            : 
      12                 :            : #include "spdk/assert.h"
      13                 :            : #include "spdk/env.h"
      14                 :            : #include "spdk/init.h"
      15                 :            : #include "spdk/log.h"
      16                 :            : #include "spdk/thread.h"
      17                 :            : #include "spdk/trace.h"
      18                 :            : #include "spdk/string.h"
      19                 :            : #include "spdk/scheduler.h"
      20                 :            : #include "spdk/rpc.h"
      21                 :            : #include "spdk/util.h"
      22                 :            : #include "spdk/file.h"
      23                 :            : #include "spdk/config.h"
      24                 :            : #include "event_internal.h"
      25                 :            : 
      26                 :            : #define SPDK_APP_DEFAULT_LOG_LEVEL              SPDK_LOG_NOTICE
      27                 :            : #define SPDK_APP_DEFAULT_LOG_PRINT_LEVEL        SPDK_LOG_INFO
      28                 :            : #define SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES      SPDK_DEFAULT_NUM_TRACE_ENTRIES
      29                 :            : 
      30                 :            : #define SPDK_APP_DPDK_DEFAULT_MEM_SIZE          -1
      31                 :            : #define SPDK_APP_DPDK_DEFAULT_MAIN_CORE         -1
      32                 :            : #define SPDK_APP_DPDK_DEFAULT_MEM_CHANNEL       -1
      33                 :            : #define SPDK_APP_DPDK_DEFAULT_CORE_MASK         "0x1"
      34                 :            : #define SPDK_APP_DPDK_DEFAULT_BASE_VIRTADDR     0x200000000000
      35                 :            : #define SPDK_APP_DEFAULT_CORE_LIMIT             0x140000000 /* 5 GiB */
      36                 :            : 
      37                 :            : /* For core counts <= 63, the message memory pool size is set to
      38                 :            :  * SPDK_DEFAULT_MSG_MEMPOOL_SIZE.
      39                 :            :  * For core counts > 63, the message memory pool size is depended on
      40                 :            :  * number of cores. Per core, it is calculated as SPDK_MSG_MEMPOOL_CACHE_SIZE
      41                 :            :  * multiplied by factor of 4 to have space for multiple spdk threads running
      42                 :            :  * on single core (e.g  iscsi + nvmf + vhost ). */
      43                 :            : #define SPDK_APP_PER_CORE_MSG_MEMPOOL_SIZE      (4 * SPDK_MSG_MEMPOOL_CACHE_SIZE)
      44                 :            : 
      45                 :            : struct spdk_app {
      46                 :            :         void                            *json_data;
      47                 :            :         size_t                          json_data_size;
      48                 :            :         bool                            json_config_ignore_errors;
      49                 :            :         bool                            stopped;
      50                 :            :         const char                      *rpc_addr;
      51                 :            :         const char                      **rpc_allowlist;
      52                 :            :         FILE                            *rpc_log_file;
      53                 :            :         enum spdk_log_level             rpc_log_level;
      54                 :            :         int                             shm_id;
      55                 :            :         spdk_app_shutdown_cb            shutdown_cb;
      56                 :            :         int                             rc;
      57                 :            : };
      58                 :            : 
      59                 :            : static struct spdk_app g_spdk_app;
      60                 :            : static spdk_msg_fn g_start_fn = NULL;
      61                 :            : static void *g_start_arg = NULL;
      62                 :            : static bool g_delay_subsystem_init = false;
      63                 :            : static bool g_shutdown_sig_received = false;
      64                 :            : static char *g_executable_name;
      65                 :            : static struct spdk_app_opts g_default_opts;
      66                 :            : static int g_core_locks[SPDK_CONFIG_MAX_LCORES];
      67                 :            : 
      68                 :            : static struct {
      69                 :            :         uint64_t irq;
      70                 :            :         uint64_t usr;
      71                 :            :         uint64_t sys;
      72                 :            : } g_initial_stat[SPDK_CONFIG_MAX_LCORES];
      73                 :            : 
      74                 :            : int
      75                 :          0 : spdk_app_get_shm_id(void)
      76                 :            : {
      77         [ #  # ]:          0 :         return g_spdk_app.shm_id;
      78                 :            : }
      79                 :            : 
      80                 :            : /* append one empty option to indicate the end of the array */
      81                 :            : static const struct option g_cmdline_options[] = {
      82                 :            : #define CONFIG_FILE_OPT_IDX     'c'
      83                 :            :         {"config",                    required_argument,      NULL, CONFIG_FILE_OPT_IDX},
      84                 :            : #define LIMIT_COREDUMP_OPT_IDX 'd'
      85                 :            :         {"limit-coredump",            no_argument,            NULL, LIMIT_COREDUMP_OPT_IDX},
      86                 :            : #define TPOINT_GROUP_OPT_IDX 'e'
      87                 :            :         {"tpoint-group",              required_argument,      NULL, TPOINT_GROUP_OPT_IDX},
      88                 :            : #define SINGLE_FILE_SEGMENTS_OPT_IDX 'g'
      89                 :            :         {"single-file-segments",      no_argument,            NULL, SINGLE_FILE_SEGMENTS_OPT_IDX},
      90                 :            : #define HELP_OPT_IDX            'h'
      91                 :            :         {"help",                      no_argument,            NULL, HELP_OPT_IDX},
      92                 :            : #define SHM_ID_OPT_IDX          'i'
      93                 :            :         {"shm-id",                    required_argument,      NULL, SHM_ID_OPT_IDX},
      94                 :            : #define CPUMASK_OPT_IDX         'm'
      95                 :            :         {"cpumask",                   required_argument,      NULL, CPUMASK_OPT_IDX},
      96                 :            : #define MEM_CHANNELS_OPT_IDX    'n'
      97                 :            :         {"mem-channels",              required_argument,      NULL, MEM_CHANNELS_OPT_IDX},
      98                 :            : #define MAIN_CORE_OPT_IDX       'p'
      99                 :            :         {"main-core",                 required_argument,      NULL, MAIN_CORE_OPT_IDX},
     100                 :            : #define RPC_SOCKET_OPT_IDX      'r'
     101                 :            :         {"rpc-socket",                        required_argument,      NULL, RPC_SOCKET_OPT_IDX},
     102                 :            : #define MEM_SIZE_OPT_IDX        's'
     103                 :            :         {"mem-size",                  required_argument,      NULL, MEM_SIZE_OPT_IDX},
     104                 :            : #define NO_PCI_OPT_IDX          'u'
     105                 :            :         {"no-pci",                    no_argument,            NULL, NO_PCI_OPT_IDX},
     106                 :            : #define VERSION_OPT_IDX         'v'
     107                 :            :         {"version",                   no_argument,            NULL, VERSION_OPT_IDX},
     108                 :            : #define PCI_BLOCKED_OPT_IDX     'B'
     109                 :            :         {"pci-blocked",                       required_argument,      NULL, PCI_BLOCKED_OPT_IDX},
     110                 :            : #define LOGFLAG_OPT_IDX         'L'
     111                 :            :         {"logflag",                   required_argument,      NULL, LOGFLAG_OPT_IDX},
     112                 :            : #define HUGE_UNLINK_OPT_IDX     'R'
     113                 :            :         {"huge-unlink",                       no_argument,            NULL, HUGE_UNLINK_OPT_IDX},
     114                 :            : #define PCI_ALLOWED_OPT_IDX     'A'
     115                 :            :         {"pci-allowed",                       required_argument,      NULL, PCI_ALLOWED_OPT_IDX},
     116                 :            : #define INTERRUPT_MODE_OPT_IDX 256
     117                 :            :         {"interrupt-mode",            no_argument,            NULL, INTERRUPT_MODE_OPT_IDX},
     118                 :            : #define SILENCE_NOTICELOG_OPT_IDX 257
     119                 :            :         {"silence-noticelog",         no_argument,            NULL, SILENCE_NOTICELOG_OPT_IDX},
     120                 :            : #define WAIT_FOR_RPC_OPT_IDX    258
     121                 :            :         {"wait-for-rpc",              no_argument,            NULL, WAIT_FOR_RPC_OPT_IDX},
     122                 :            : #define HUGE_DIR_OPT_IDX        259
     123                 :            :         {"huge-dir",                  required_argument,      NULL, HUGE_DIR_OPT_IDX},
     124                 :            : #define NUM_TRACE_ENTRIES_OPT_IDX       260
     125                 :            :         {"num-trace-entries",         required_argument,      NULL, NUM_TRACE_ENTRIES_OPT_IDX},
     126                 :            : #define JSON_CONFIG_OPT_IDX             262
     127                 :            :         {"json",                      required_argument,      NULL, JSON_CONFIG_OPT_IDX},
     128                 :            : #define JSON_CONFIG_IGNORE_INIT_ERRORS_IDX      263
     129                 :            :         {"json-ignore-init-errors",   no_argument,            NULL, JSON_CONFIG_IGNORE_INIT_ERRORS_IDX},
     130                 :            : #define IOVA_MODE_OPT_IDX       264
     131                 :            :         {"iova-mode",                 required_argument,      NULL, IOVA_MODE_OPT_IDX},
     132                 :            : #define BASE_VIRTADDR_OPT_IDX   265
     133                 :            :         {"base-virtaddr",             required_argument,      NULL, BASE_VIRTADDR_OPT_IDX},
     134                 :            : #define ENV_CONTEXT_OPT_IDX     266
     135                 :            :         {"env-context",                       required_argument,      NULL, ENV_CONTEXT_OPT_IDX},
     136                 :            : #define DISABLE_CPUMASK_LOCKS_OPT_IDX   267
     137                 :            :         {"disable-cpumask-locks",     no_argument,            NULL, DISABLE_CPUMASK_LOCKS_OPT_IDX},
     138                 :            : #define RPCS_ALLOWED_OPT_IDX    268
     139                 :            :         {"rpcs-allowed",              required_argument,      NULL, RPCS_ALLOWED_OPT_IDX},
     140                 :            : #define ENV_VF_TOKEN_OPT_IDX 269
     141                 :            :         {"vfio-vf-token",             required_argument,      NULL, ENV_VF_TOKEN_OPT_IDX},
     142                 :            : #define MSG_MEMPOOL_SIZE_OPT_IDX 270
     143                 :            :         {"msg-mempool-size",          required_argument,      NULL, MSG_MEMPOOL_SIZE_OPT_IDX},
     144                 :            : #define LCORES_OPT_IDX  271
     145                 :            :         {"lcores",                    required_argument,      NULL, LCORES_OPT_IDX},
     146                 :            : #define NO_HUGE_OPT_IDX 272
     147                 :            :         {"no-huge",                   no_argument,            NULL, NO_HUGE_OPT_IDX},
     148                 :            : #define NO_RPC_SERVER_OPT_IDX   273
     149                 :            :         {"no-rpc-server",             no_argument,            NULL, NO_RPC_SERVER_OPT_IDX},
     150                 :            : #define ENFORCE_NUMA_OPT_IDX 274
     151                 :            :         {"enforce-numa",              no_argument,            NULL, ENFORCE_NUMA_OPT_IDX},
     152                 :            : };
     153                 :            : 
     154                 :            : static int
     155                 :       3192 : parse_proc_stat(unsigned int core, uint64_t *user, uint64_t *sys, uint64_t *irq)
     156                 :            : {
     157                 :            :         FILE *f;
     158                 :       3192 :         uint64_t i, soft_irq, cpu = 0;
     159                 :       3192 :         int rc, found = 0;
     160                 :            : 
     161                 :       3192 :         f = fopen("/proc/stat", "r");
     162         [ +  + ]:       3192 :         if (!f) {
     163                 :         65 :                 return -1;
     164                 :            :         }
     165                 :            : 
     166         [ +  + ]:       8815 :         for (i = 0; i <= core + 1; i++) {
     167                 :            :                 /* scanf discards input with '*' in format,
     168                 :            :                  * cpu;user;nice;system;idle;iowait;irq;softirq;steal;guest;guest_nice */
     169   [ -  +  -  + ]:       9015 :                 rc = fscanf(f, "cpu%li %li %*i %li %*i %*i %li %li %*i %*i %*i\n",
     170                 :        200 :                             &cpu, user, sys, irq, &soft_irq);
     171         [ -  + ]:       8815 :                 if (rc != 5) {
     172                 :          0 :                         continue;
     173                 :            :                 }
     174                 :            : 
     175                 :            :                 /* some cores can be disabled, list may not be in order */
     176         [ +  + ]:       8815 :                 if (cpu == core) {
     177                 :       3127 :                         found = 1;
     178                 :       3127 :                         break;
     179                 :            :                 }
     180                 :        117 :         }
     181                 :            : 
     182         [ -  + ]:       3127 :         *irq += soft_irq;
     183                 :            : 
     184         [ -  + ]:       3127 :         fclose(f);
     185         [ +  - ]:       3127 :         return found ? 0 : -1;
     186                 :        148 : }
     187                 :            : 
     188                 :            : static int
     189                 :       3192 : init_proc_stat(unsigned int core)
     190                 :            : {
     191                 :       1175 :         uint64_t usr, sys, irq;
     192                 :            : 
     193         [ -  + ]:       3192 :         if (core >= SPDK_CONFIG_MAX_LCORES) {
     194                 :          0 :                 return -1;
     195                 :            :         }
     196                 :            : 
     197         [ +  + ]:       3192 :         if (parse_proc_stat(core, &usr, &sys, &irq) < 0) {
     198                 :         65 :                 return -1;
     199                 :            :         }
     200                 :            : 
     201   [ +  -  +  -  :       3127 :         g_initial_stat[core].irq = irq;
             +  -  +  - ]
     202   [ +  -  +  -  :       3127 :         g_initial_stat[core].usr = usr;
             +  -  +  - ]
     203   [ +  -  +  -  :       3127 :         g_initial_stat[core].sys = sys;
             +  -  +  - ]
     204                 :            : 
     205                 :       3127 :         return 0;
     206                 :        148 : }
     207                 :            : 
     208                 :            : int
     209                 :          0 : app_get_proc_stat(unsigned int core, uint64_t *usr, uint64_t *sys, uint64_t *irq)
     210                 :            : {
     211                 :          0 :         uint64_t _usr, _sys, _irq;
     212                 :            : 
     213         [ #  # ]:          0 :         if (core >= SPDK_CONFIG_MAX_LCORES) {
     214                 :          0 :                 return -1;
     215                 :            :         }
     216                 :            : 
     217         [ #  # ]:          0 :         if (parse_proc_stat(core, &_usr, &_sys, &_irq) < 0) {
     218                 :          0 :                 return -1;
     219                 :            :         }
     220                 :            : 
     221   [ #  #  #  #  :          0 :         *irq = _irq - g_initial_stat[core].irq;
          #  #  #  #  #  
                      # ]
     222   [ #  #  #  #  :          0 :         *usr = _usr - g_initial_stat[core].usr;
          #  #  #  #  #  
                      # ]
     223   [ #  #  #  #  :          0 :         *sys = _sys - g_initial_stat[core].sys;
          #  #  #  #  #  
                      # ]
     224                 :            : 
     225                 :          0 :         return 0;
     226                 :          0 : }
     227                 :            : 
     228                 :            : static void
     229                 :       1264 : app_start_shutdown(void *ctx)
     230                 :            : {
     231   [ +  +  +  + ]:       1264 :         if (g_spdk_app.shutdown_cb) {
     232   [ +  -  -  +  :        404 :                 g_spdk_app.shutdown_cb();
                   -  + ]
     233         [ +  - ]:        404 :                 g_spdk_app.shutdown_cb = NULL;
     234                 :         11 :         } else {
     235                 :        860 :                 spdk_app_stop(0);
     236                 :            :         }
     237                 :       1264 : }
     238                 :            : 
     239                 :            : void
     240                 :       1264 : spdk_app_start_shutdown(void)
     241                 :            : {
     242                 :       1264 :         spdk_thread_send_critical_msg(spdk_thread_get_app_thread(), app_start_shutdown);
     243                 :       1264 : }
     244                 :            : 
     245                 :            : static void
     246                 :       1259 : __shutdown_signal(int signo)
     247                 :            : {
     248   [ +  +  +  + ]:       1259 :         if (!g_shutdown_sig_received) {
     249                 :       1259 :                 g_shutdown_sig_received = true;
     250                 :       1259 :                 spdk_app_start_shutdown();
     251                 :         48 :         }
     252                 :       1259 : }
     253                 :            : 
     254                 :            : static int
     255                 :       2172 : app_opts_validate(const char *app_opts)
     256                 :            : {
     257                 :       2172 :         int i = 0, j;
     258                 :            : 
     259   [ +  +  +  -  :      20738 :         for (i = 0; app_opts[i] != '\0'; i++) {
             +  +  +  - ]
     260                 :            :                 /* ignore getopt control characters */
     261   [ +  +  +  -  :      18570 :                 if (app_opts[i] == ':' || app_opts[i] == '+' || app_opts[i] == '-') {
          +  +  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     262                 :       7353 :                         continue;
     263                 :            :                 }
     264                 :            : 
     265   [ +  +  +  -  :     347607 :                 for (j = 0; SPDK_APP_GETOPT_STRING[j] != '\0'; j++) {
          +  -  +  +  +  
                      - ]
     266   [ +  +  +  -  :     336394 :                         if (app_opts[i] == SPDK_APP_GETOPT_STRING[j]) {
          +  -  +  -  +  
                -  +  - ]
     267   [ #  #  #  # ]:          4 :                                 return app_opts[i];
     268                 :            :                         }
     269                 :      20520 :                 }
     270                 :        684 :         }
     271                 :       2168 :         return 0;
     272                 :        111 : }
     273                 :            : 
     274                 :            : static void
     275                 :       2207 : calculate_mempool_size(struct spdk_app_opts *opts,
     276                 :            :                        struct spdk_app_opts *opts_user)
     277                 :            : {
     278                 :       2207 :         uint32_t core_count = spdk_env_get_core_count();
     279                 :            : 
     280   [ +  +  +  -  :       2207 :         if (!opts_user->msg_mempool_size) {
                   -  + ]
     281                 :            :                 /* The user didn't specify msg_mempool_size, so let's calculate it.
     282                 :            :                    Set the default (SPDK_DEFAULT_MSG_MEMPOOL_SIZE) if less than
     283                 :            :                    64 cores, and use 4k per core otherwise */
     284   [ +  -  +  -  :       2207 :                 opts->msg_mempool_size = spdk_max(SPDK_DEFAULT_MSG_MEMPOOL_SIZE,
                   +  - ]
     285                 :            :                                                   core_count * SPDK_APP_PER_CORE_MSG_MEMPOOL_SIZE);
     286                 :        112 :         } else {
     287   [ #  #  #  #  :          0 :                 opts->msg_mempool_size = opts_user->msg_mempool_size;
             #  #  #  # ]
     288                 :            :         }
     289                 :       2207 : }
     290                 :            : 
     291                 :            : void
     292                 :       4450 : spdk_app_opts_init(struct spdk_app_opts *opts, size_t opts_size)
     293                 :            : {
     294         [ +  + ]:       4450 :         if (!opts) {
     295                 :          0 :                 SPDK_ERRLOG("opts should not be NULL\n");
     296                 :          0 :                 return;
     297                 :            :         }
     298                 :            : 
     299         [ +  + ]:       4450 :         if (!opts_size) {
     300                 :          0 :                 SPDK_ERRLOG("opts_size should not be zero value\n");
     301                 :          0 :                 return;
     302                 :            :         }
     303                 :            : 
     304         [ +  + ]:       4450 :         memset(opts, 0, opts_size);
     305   [ +  -  +  - ]:       4450 :         opts->opts_size = opts_size;
     306                 :            : 
     307                 :            : #define SET_FIELD(field, value) \
     308                 :            :         if (offsetof(struct spdk_app_opts, field) + sizeof(opts->field) <= opts_size) { \
     309                 :            :                 opts->field = value; \
     310                 :            :         } \
     311                 :            : 
     312   [ +  +  +  -  :       4450 :         SET_FIELD(enable_coredump, true);
                   +  - ]
     313   [ +  +  +  -  :       4450 :         SET_FIELD(shm_id, -1);
                   +  - ]
     314   [ +  +  +  -  :       4450 :         SET_FIELD(mem_size, SPDK_APP_DPDK_DEFAULT_MEM_SIZE);
                   +  - ]
     315   [ +  +  +  -  :       4450 :         SET_FIELD(main_core, SPDK_APP_DPDK_DEFAULT_MAIN_CORE);
                   +  - ]
     316   [ +  +  +  -  :       4450 :         SET_FIELD(mem_channel, SPDK_APP_DPDK_DEFAULT_MEM_CHANNEL);
                   +  - ]
     317   [ +  +  +  -  :       4450 :         SET_FIELD(base_virtaddr, SPDK_APP_DPDK_DEFAULT_BASE_VIRTADDR);
                   +  - ]
     318   [ +  +  +  -  :       4450 :         SET_FIELD(print_level, SPDK_APP_DEFAULT_LOG_PRINT_LEVEL);
                   +  - ]
     319   [ +  +  +  -  :       4450 :         SET_FIELD(rpc_addr, SPDK_DEFAULT_RPC_ADDR);
                   +  - ]
     320   [ +  +  +  -  :       4450 :         SET_FIELD(num_entries, SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES);
                   +  - ]
     321   [ +  +  +  -  :       4450 :         SET_FIELD(delay_subsystem_init, false);
                   +  - ]
     322   [ +  +  +  -  :       4450 :         SET_FIELD(disable_signal_handlers, false);
                   +  - ]
     323   [ +  +  +  -  :       4450 :         SET_FIELD(interrupt_mode, false);
                   +  - ]
     324   [ +  +  +  -  :       4450 :         SET_FIELD(enforce_numa, false);
                   +  - ]
     325                 :            :         /* Don't set msg_mempool_size here, it is set or calculated later */
     326   [ +  +  +  -  :       4450 :         SET_FIELD(rpc_allowlist, NULL);
                   +  - ]
     327   [ +  +  +  -  :       4450 :         SET_FIELD(rpc_log_file, NULL);
                   +  - ]
     328   [ +  +  +  -  :       4450 :         SET_FIELD(rpc_log_level, SPDK_LOG_DISABLED);
                   +  - ]
     329   [ +  +  +  -  :       4450 :         SET_FIELD(disable_cpumask_locks, false);
                   +  - ]
     330                 :            : #undef SET_FIELD
     331                 :        225 : }
     332                 :            : 
     333                 :            : static int
     334                 :       2169 : app_setup_signal_handlers(struct spdk_app_opts *opts)
     335                 :            : {
     336                 :        880 :         struct sigaction        sigact;
     337                 :        880 :         sigset_t                sigmask;
     338                 :            :         int                     rc;
     339                 :            : 
     340         [ +  + ]:       2169 :         sigemptyset(&sigmask);
     341         [ +  + ]:       2169 :         memset(&sigact, 0, sizeof(sigact));
     342         [ +  + ]:       2169 :         sigemptyset(&sigact.sa_mask);
     343                 :            : 
     344                 :       2169 :         sigact.sa_handler = SIG_IGN;
     345                 :       2169 :         rc = sigaction(SIGPIPE, &sigact, NULL);
     346         [ +  + ]:       2169 :         if (rc < 0) {
     347                 :          0 :                 SPDK_ERRLOG("sigaction(SIGPIPE) failed\n");
     348                 :          0 :                 return rc;
     349                 :            :         }
     350                 :            : 
     351                 :            :         /* Install the same handler for SIGINT and SIGTERM */
     352                 :       2169 :         g_shutdown_sig_received = false;
     353                 :       2169 :         sigact.sa_handler = __shutdown_signal;
     354                 :       2169 :         rc = sigaction(SIGINT, &sigact, NULL);
     355         [ +  + ]:       2169 :         if (rc < 0) {
     356                 :          0 :                 SPDK_ERRLOG("sigaction(SIGINT) failed\n");
     357                 :          0 :                 return rc;
     358                 :            :         }
     359         [ +  + ]:       2169 :         sigaddset(&sigmask, SIGINT);
     360                 :            : 
     361                 :       2169 :         rc = sigaction(SIGTERM, &sigact, NULL);
     362         [ +  + ]:       2169 :         if (rc < 0) {
     363                 :          0 :                 SPDK_ERRLOG("sigaction(SIGTERM) failed\n");
     364                 :          0 :                 return rc;
     365                 :            :         }
     366         [ +  + ]:       2169 :         sigaddset(&sigmask, SIGTERM);
     367                 :            : 
     368                 :       2169 :         pthread_sigmask(SIG_UNBLOCK, &sigmask, NULL);
     369                 :            : 
     370                 :       2169 :         return 0;
     371                 :        110 : }
     372                 :            : 
     373                 :            : static void
     374                 :       2099 : app_start_application(int rc, void *arg1)
     375                 :            : {
     376   [ +  +  #  # ]:       2099 :         assert(spdk_thread_is_app_thread(NULL));
     377                 :            : 
     378         [ -  + ]:       2099 :         if (rc) {
     379                 :          0 :                 SPDK_ERRLOG("Failed to load subsystems for RUNTIME state with code: %d\n", rc);
     380                 :          0 :                 spdk_app_stop(rc);
     381                 :          0 :                 return;
     382                 :            :         }
     383                 :            : 
     384   [ +  +  +  + ]:       2099 :         if (g_spdk_app.rpc_addr) {
     385         [ +  - ]:       1244 :                 spdk_rpc_server_resume(g_spdk_app.rpc_addr);
     386                 :         52 :         }
     387                 :            : 
     388   [ -  +  +  - ]:       2099 :         g_start_fn(g_start_arg);
     389                 :        105 : }
     390                 :            : 
     391                 :            : static void
     392                 :       2099 : app_subsystem_init_done(int rc, void *arg1)
     393                 :            : {
     394         [ -  + ]:       2099 :         if (rc) {
     395                 :          0 :                 SPDK_ERRLOG("Subsystem initialization failed with code: %d\n", rc);
     396                 :          0 :                 spdk_app_stop(rc);
     397                 :          0 :                 return;
     398                 :            :         }
     399                 :            : 
     400         [ +  - ]:       2099 :         spdk_rpc_set_allowlist(g_spdk_app.rpc_allowlist);
     401                 :       2099 :         spdk_rpc_set_state(SPDK_RPC_RUNTIME);
     402                 :            : 
     403         [ +  + ]:       2099 :         if (g_spdk_app.json_data) {
     404                 :            :                 /* Load SPDK_RPC_RUNTIME RPCs from config file */
     405   [ +  +  #  # ]:        655 :                 assert(spdk_rpc_get_state() == SPDK_RPC_RUNTIME);
     406         [ +  - ]:        706 :                 spdk_subsystem_load_config(g_spdk_app.json_data, g_spdk_app.json_data_size,
     407                 :            :                                            app_start_application, NULL,
     408   [ +  +  +  - ]:        655 :                                            !g_spdk_app.json_config_ignore_errors);
     409                 :        655 :                 free(g_spdk_app.json_data);
     410                 :        655 :                 g_spdk_app.json_data = NULL;
     411                 :         51 :         } else {
     412                 :       1444 :                 app_start_application(0, NULL);
     413                 :            :         }
     414                 :        105 : }
     415                 :            : 
     416                 :            : static void
     417                 :       2168 : app_do_spdk_subsystem_init(int rc, void *arg1)
     418                 :            : {
     419                 :        879 :         struct spdk_rpc_opts opts;
     420                 :            : 
     421         [ +  + ]:       2168 :         if (rc) {
     422                 :         49 :                 spdk_app_stop(rc);
     423                 :        170 :                 return;
     424                 :            :         }
     425                 :            : 
     426   [ +  +  +  + ]:       2119 :         if (g_spdk_app.rpc_addr) {
     427                 :       1264 :                 opts.size = SPDK_SIZEOF(&opts, log_level);
     428   [ +  -  +  - ]:       1264 :                 opts.log_file = g_spdk_app.rpc_log_file;
     429   [ +  -  +  - ]:       1264 :                 opts.log_level = g_spdk_app.rpc_log_level;
     430                 :            : 
     431         [ +  - ]:       1264 :                 rc = spdk_rpc_initialize(g_spdk_app.rpc_addr, &opts);
     432         [ +  + ]:       1264 :                 if (rc) {
     433                 :         20 :                         spdk_app_stop(rc);
     434                 :         20 :                         return;
     435                 :            :                 }
     436   [ +  +  +  + ]:       1244 :                 if (g_delay_subsystem_init) {
     437                 :        141 :                         return;
     438                 :            :                 }
     439         [ -  + ]:       1103 :                 spdk_rpc_server_pause(g_spdk_app.rpc_addr);
     440                 :         49 :         } else {
     441   [ +  +  +  +  :        855 :                 SPDK_DEBUGLOG(app_rpc, "RPC server not started\n");
                   +  - ]
     442                 :            :         }
     443                 :       1958 :         spdk_subsystem_init(app_subsystem_init_done, NULL);
     444                 :        110 : }
     445                 :            : 
     446                 :            : static int
     447                 :          8 : app_opts_add_pci_addr(struct spdk_app_opts *opts, struct spdk_pci_addr **list, char *bdf)
     448                 :            : {
     449         [ #  # ]:          8 :         struct spdk_pci_addr *tmp = *list;
     450   [ #  #  #  # ]:          8 :         size_t i = opts->num_pci_addr;
     451                 :            : 
     452                 :          8 :         tmp = realloc(tmp, sizeof(*tmp) * (i + 1));
     453         [ +  + ]:          8 :         if (tmp == NULL) {
     454                 :          0 :                 SPDK_ERRLOG("realloc error\n");
     455                 :          0 :                 return -ENOMEM;
     456                 :            :         }
     457                 :            : 
     458         [ #  # ]:          8 :         *list = tmp;
     459   [ -  +  #  #  :          8 :         if (spdk_pci_addr_parse(*list + i, bdf) < 0) {
                   #  # ]
     460                 :          0 :                 SPDK_ERRLOG("Invalid address %s\n", bdf);
     461                 :          0 :                 return -EINVAL;
     462                 :            :         }
     463                 :            : 
     464         [ #  # ]:          8 :         opts->num_pci_addr++;
     465                 :          8 :         return 0;
     466                 :          2 : }
     467                 :            : 
     468                 :            : static int
     469                 :       2207 : app_setup_env(struct spdk_app_opts *opts)
     470                 :            : {
     471                 :       2207 :         struct spdk_env_opts env_opts = {};
     472                 :            :         int rc;
     473                 :            : 
     474         [ +  + ]:       2207 :         if (opts == NULL) {
     475                 :         60 :                 rc = spdk_env_init(NULL);
     476         [ -  + ]:         60 :                 if (rc != 0) {
     477                 :          0 :                         SPDK_ERRLOG("Unable to reinitialize SPDK env\n");
     478                 :          0 :                 }
     479                 :            : 
     480                 :         60 :                 return rc;
     481                 :            :         }
     482                 :            : 
     483         [ +  - ]:       2147 :         env_opts.opts_size = sizeof(env_opts);
     484                 :       2147 :         spdk_env_opts_init(&env_opts);
     485                 :            : 
     486   [ +  -  +  - ]:       2147 :         env_opts.name = opts->name;
     487   [ +  -  +  -  :       2147 :         env_opts.core_mask = opts->reactor_mask;
                   +  - ]
     488   [ +  -  +  -  :       2147 :         env_opts.lcore_map = opts->lcore_map;
                   +  - ]
     489   [ +  -  +  -  :       2147 :         env_opts.shm_id = opts->shm_id;
                   +  - ]
     490   [ +  -  +  -  :       2147 :         env_opts.mem_channel = opts->mem_channel;
                   +  - ]
     491   [ +  -  +  -  :       2147 :         env_opts.main_core = opts->main_core;
                   +  - ]
     492   [ +  -  +  -  :       2147 :         env_opts.mem_size = opts->mem_size;
                   +  - ]
     493   [ +  +  +  -  :       2147 :         env_opts.hugepage_single_segments = opts->hugepage_single_segments;
                   +  - ]
     494   [ +  +  +  -  :       2147 :         env_opts.unlink_hugepage = opts->unlink_hugepage;
             +  -  +  - ]
     495   [ +  -  +  -  :       2147 :         env_opts.hugedir = opts->hugedir;
                   +  - ]
     496   [ +  +  +  -  :       2147 :         env_opts.no_pci = opts->no_pci;
             +  -  +  - ]
     497   [ +  -  +  -  :       2147 :         env_opts.num_pci_addr = opts->num_pci_addr;
                   +  - ]
     498   [ +  -  +  -  :       2147 :         env_opts.pci_blocked = opts->pci_blocked;
                   +  - ]
     499   [ +  -  +  -  :       2147 :         env_opts.pci_allowed = opts->pci_allowed;
                   +  - ]
     500   [ +  -  +  -  :       2147 :         env_opts.base_virtaddr = opts->base_virtaddr;
                   +  - ]
     501   [ +  -  +  -  :       2147 :         env_opts.env_context = opts->env_context;
                   +  - ]
     502   [ +  -  +  -  :       2147 :         env_opts.iova_mode = opts->iova_mode;
                   +  - ]
     503   [ +  -  +  -  :       2147 :         env_opts.vf_token = opts->vf_token;
                   +  - ]
     504   [ +  +  +  -  :       2147 :         env_opts.no_huge = opts->no_huge;
                   +  - ]
     505   [ +  +  +  -  :       2147 :         env_opts.enforce_numa = opts->enforce_numa;
             +  -  +  - ]
     506                 :            : 
     507                 :       2147 :         rc = spdk_env_init(&env_opts);
     508         [ +  - ]:       2147 :         free(env_opts.pci_blocked);
     509         [ +  - ]:       2147 :         free(env_opts.pci_allowed);
     510                 :            : 
     511         [ +  + ]:       2147 :         if (rc < 0) {
     512                 :          0 :                 SPDK_ERRLOG("Unable to initialize SPDK env\n");
     513         [ #  # ]:          0 :                 if (getuid() != 0) {
     514                 :          0 :                         SPDK_ERRLOG("You may need to run as root\n");
     515                 :          0 :                 }
     516                 :          0 :         }
     517                 :            : 
     518                 :       2147 :         return rc;
     519                 :        112 : }
     520                 :            : 
     521                 :            : static int
     522                 :       2169 : app_setup_trace(struct spdk_app_opts *opts)
     523                 :            : {
     524                 :        880 :         char            shm_name[64];
     525                 :       2169 :         uint64_t        tpoint_group_mask, tpoint_mask = -1ULL;
     526                 :       2169 :         char            *end = NULL, *tpoint_group_mask_str, *tpoint_group_str = NULL;
     527                 :            :         char            *tp_g_str, *tpoint_group, *tpoints;
     528                 :       2169 :         bool            error_found = false;
     529                 :            :         uint64_t        group_id;
     530                 :            : 
     531   [ +  +  +  -  :       2169 :         if (opts->shm_id >= 0) {
                   -  + ]
     532   [ #  #  #  # ]:        322 :                 snprintf(shm_name, sizeof(shm_name), "/%s%s%d", opts->name,
     533   [ #  #  #  # ]:          0 :                          SPDK_TRACE_SHM_NAME_BASE, opts->shm_id);
     534                 :          0 :         } else {
     535   [ +  -  +  - ]:       1892 :                 snprintf(shm_name, sizeof(shm_name), "/%s%spid%d", opts->name,
     536                 :       1847 :                          SPDK_TRACE_SHM_NAME_BASE, (int)getpid());
     537                 :            :         }
     538                 :            : 
     539   [ +  +  +  -  :       2169 :         if (spdk_trace_init(shm_name, opts->num_entries, 0) != 0) {
                   -  + ]
     540                 :          0 :                 return -1;
     541                 :            :         }
     542                 :            : 
     543   [ +  +  +  -  :       2169 :         if (opts->tpoint_group_mask == NULL) {
                   +  + ]
     544                 :       1903 :                 return 0;
     545                 :            :         }
     546                 :            : 
     547   [ +  +  +  -  :        266 :         tpoint_group_mask_str = strdup(opts->tpoint_group_mask);
                   +  - ]
     548         [ +  + ]:        266 :         if (tpoint_group_mask_str == NULL) {
     549                 :          0 :                 SPDK_ERRLOG("Unable to get string of tpoint group mask from opts.\n");
     550                 :          0 :                 return -1;
     551                 :            :         }
     552                 :            :         /* Save a pointer to the original value of the tpoint group mask string
     553                 :            :          * to free later, because spdk_strsepq() modifies given char*. */
     554                 :        266 :         tp_g_str = tpoint_group_mask_str;
     555         [ +  + ]:        532 :         while ((tpoint_group_str = spdk_strsepq(&tpoint_group_mask_str, ",")) != NULL) {
     556   [ +  +  -  + ]:        266 :                 if (strchr(tpoint_group_str, ':')) {
     557                 :            :                         /* Get the tpoint group mask */
     558                 :          0 :                         tpoint_group = spdk_strsepq(&tpoint_group_str, ":");
     559                 :            :                         /* Get the tpoint mask inside that group */
     560                 :          0 :                         tpoints = spdk_strsepq(&tpoint_group_str, ":");
     561                 :            : 
     562         [ #  # ]:          0 :                         errno = 0;
     563         [ #  # ]:          0 :                         tpoint_group_mask = strtoull(tpoint_group, &end, 16);
     564   [ #  #  #  #  :          0 :                         if (*end != '\0' || errno) {
             #  #  #  # ]
     565                 :          0 :                                 tpoint_group_mask = spdk_trace_create_tpoint_group_mask(tpoint_group);
     566         [ #  # ]:          0 :                                 if (tpoint_group_mask == 0) {
     567                 :          0 :                                         error_found = true;
     568                 :          0 :                                         break;
     569                 :            :                                 }
     570                 :          0 :                         }
     571                 :            :                         /* Check if tpoint group mask has only one bit set.
     572                 :            :                          * This is to avoid enabling individual tpoints in
     573                 :            :                          * more than one tracepoint group at once. */
     574         [ #  # ]:          0 :                         if (!spdk_u64_is_pow2(tpoint_group_mask)) {
     575                 :          0 :                                 SPDK_ERRLOG("Tpoint group mask: %s contains multiple tpoint groups.\n", tpoint_group);
     576                 :          0 :                                 SPDK_ERRLOG("This is not supported, to prevent from activating tpoints by mistake.\n");
     577                 :          0 :                                 error_found = true;
     578                 :          0 :                                 break;
     579                 :            :                         }
     580                 :            : 
     581         [ #  # ]:          0 :                         errno = 0;
     582         [ #  # ]:          0 :                         tpoint_mask = strtoull(tpoints, &end, 16);
     583   [ #  #  #  #  :          0 :                         if (*end != '\0' || errno) {
             #  #  #  # ]
     584                 :          0 :                                 error_found = true;
     585                 :          0 :                                 break;
     586                 :            :                         }
     587                 :          0 :                 } else {
     588         [ +  - ]:        266 :                         errno = 0;
     589         [ +  + ]:        266 :                         tpoint_group_mask = strtoull(tpoint_group_str, &end, 16);
     590   [ +  +  -  +  :        266 :                         if (*end != '\0' || errno) {
             #  #  #  # ]
     591                 :         24 :                                 tpoint_group_mask = spdk_trace_create_tpoint_group_mask(tpoint_group_str);
     592         [ +  + ]:         24 :                                 if (tpoint_group_mask == 0) {
     593                 :          0 :                                         error_found = true;
     594                 :          0 :                                         break;
     595                 :            :                                 }
     596                 :          2 :                         }
     597                 :        266 :                         tpoint_mask = -1ULL;
     598                 :            :                 }
     599                 :            : 
     600         [ +  + ]:       5586 :                 for (group_id = 0; group_id < SPDK_TRACE_MAX_GROUP_ID; ++group_id) {
     601   [ +  +  +  +  :       5320 :                         if (tpoint_group_mask & (1 << group_id)) {
                   +  + ]
     602                 :       3849 :                                 spdk_trace_set_tpoints(group_id, tpoint_mask);
     603                 :          2 :                         }
     604                 :         40 :                 }
     605                 :            :         }
     606                 :            : 
     607   [ +  +  -  + ]:        266 :         if (error_found) {
     608   [ #  #  #  # ]:          0 :                 SPDK_ERRLOG("invalid tpoint mask %s\n", opts->tpoint_group_mask);
     609                 :          0 :                 free(tp_g_str);
     610                 :          0 :                 return -1;
     611                 :            :         } else {
     612   [ +  -  +  - ]:        266 :                 SPDK_NOTICELOG("Tracepoint Group Mask %s specified.\n", opts->tpoint_group_mask);
     613   [ +  +  +  +  :        266 :                 SPDK_NOTICELOG("Use 'spdk_trace -s %s %s %d' to capture a snapshot of events at runtime.\n",
          +  -  +  -  +  
          -  +  -  -  +  
             #  #  #  # ]
     614                 :            :                                opts->name,
     615                 :            :                                opts->shm_id >= 0 ? "-i" : "-p",
     616                 :            :                                opts->shm_id >= 0 ? opts->shm_id : getpid());
     617                 :            : #if defined(__linux__)
     618                 :        265 :                 SPDK_NOTICELOG("'spdk_trace' without parameters will also work if this is the only\n");
     619                 :        265 :                 SPDK_NOTICELOG("SPDK application currently running.\n");
     620                 :        265 :                 SPDK_NOTICELOG("Or copy /dev/shm%s for offline analysis/debug.\n", shm_name);
     621                 :            : #endif
     622                 :            :         }
     623                 :        266 :         free(tp_g_str);
     624                 :            : 
     625                 :        266 :         return 0;
     626                 :        110 : }
     627                 :            : 
     628                 :            : static void
     629                 :       2168 : bootstrap_fn(void *arg1)
     630                 :            : {
     631         [ +  - ]:       2168 :         spdk_rpc_set_allowlist(g_spdk_app.rpc_allowlist);
     632                 :            : 
     633         [ +  + ]:       2168 :         if (g_spdk_app.json_data) {
     634                 :            :                 /* Load SPDK_RPC_STARTUP RPCs from config file */
     635   [ +  +  #  # ]:        704 :                 assert(spdk_rpc_get_state() == SPDK_RPC_STARTUP);
     636         [ +  - ]:        759 :                 spdk_subsystem_load_config(g_spdk_app.json_data, g_spdk_app.json_data_size,
     637                 :            :                                            app_do_spdk_subsystem_init, NULL,
     638   [ +  +  +  - ]:        704 :                                            !g_spdk_app.json_config_ignore_errors);
     639                 :         55 :         } else {
     640                 :       1464 :                 app_do_spdk_subsystem_init(0, NULL);
     641                 :            :         }
     642                 :       2168 : }
     643                 :            : 
     644                 :            : static void
     645                 :       2228 : app_copy_opts(struct spdk_app_opts *opts, struct spdk_app_opts *opts_user, size_t opts_size)
     646                 :            : {
     647                 :       2228 :         spdk_app_opts_init(opts, sizeof(*opts));
     648   [ +  -  +  - ]:       2228 :         opts->opts_size = opts_size;
     649                 :            : 
     650                 :            : #define SET_FIELD(field) \
     651                 :            :         if (offsetof(struct spdk_app_opts, field) + sizeof(opts->field) <= (opts->opts_size)) { \
     652                 :            :                 opts->field = opts_user->field; \
     653                 :            :         } \
     654                 :            : 
     655   [ +  +  +  -  :       2228 :         SET_FIELD(name);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     656   [ +  +  +  -  :       2228 :         SET_FIELD(json_config_file);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     657   [ +  +  +  +  :       2228 :         SET_FIELD(json_config_ignore_errors);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
     658   [ +  +  +  -  :       2228 :         SET_FIELD(rpc_addr);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     659   [ +  +  +  -  :       2228 :         SET_FIELD(reactor_mask);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     660   [ +  +  +  -  :       2228 :         SET_FIELD(lcore_map);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     661   [ +  +  +  -  :       2228 :         SET_FIELD(tpoint_group_mask);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     662   [ +  +  +  -  :       2228 :         SET_FIELD(shm_id);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     663   [ +  +  +  -  :       2228 :         SET_FIELD(shutdown_cb);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     664   [ +  +  +  +  :       2228 :         SET_FIELD(enable_coredump);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
     665   [ +  +  +  -  :       2228 :         SET_FIELD(mem_channel);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     666   [ +  +  +  -  :       2228 :         SET_FIELD(main_core);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     667   [ +  +  +  -  :       2228 :         SET_FIELD(mem_size);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     668   [ +  +  +  +  :       2228 :         SET_FIELD(no_pci);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
     669   [ +  +  +  +  :       2228 :         SET_FIELD(hugepage_single_segments);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
     670   [ +  +  +  +  :       2228 :         SET_FIELD(unlink_hugepage);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
     671   [ +  +  +  +  :       2228 :         SET_FIELD(no_huge);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
     672   [ +  +  +  -  :       2228 :         SET_FIELD(hugedir);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     673   [ +  +  +  -  :       2228 :         SET_FIELD(print_level);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     674   [ +  +  +  -  :       2228 :         SET_FIELD(num_pci_addr);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     675   [ +  +  +  -  :       2228 :         SET_FIELD(pci_blocked);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     676   [ +  +  +  -  :       2228 :         SET_FIELD(pci_allowed);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     677   [ +  +  +  -  :       2228 :         SET_FIELD(iova_mode);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     678   [ +  +  +  +  :       2228 :         SET_FIELD(delay_subsystem_init);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
     679   [ +  +  +  -  :       2228 :         SET_FIELD(num_entries);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     680   [ +  +  +  -  :       2228 :         SET_FIELD(env_context);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     681   [ +  +  +  -  :       2228 :         SET_FIELD(log);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     682   [ +  +  +  -  :       2228 :         SET_FIELD(base_virtaddr);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     683   [ +  +  +  +  :       2228 :         SET_FIELD(disable_signal_handlers);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
     684   [ +  +  +  +  :       2228 :         SET_FIELD(interrupt_mode);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
     685   [ +  +  +  +  :       2228 :         SET_FIELD(enforce_numa);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
     686   [ +  +  +  -  :       2228 :         SET_FIELD(msg_mempool_size);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     687   [ +  +  +  -  :       2228 :         SET_FIELD(rpc_allowlist);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     688   [ +  +  +  -  :       2228 :         SET_FIELD(vf_token);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     689   [ +  +  +  -  :       2228 :         SET_FIELD(rpc_log_file);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     690   [ +  +  +  -  :       2228 :         SET_FIELD(rpc_log_level);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     691   [ +  +  +  -  :       2228 :         SET_FIELD(json_data);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     692   [ +  +  +  -  :       2228 :         SET_FIELD(json_data_size);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
     693   [ +  +  +  +  :       2228 :         SET_FIELD(disable_cpumask_locks);
          -  +  +  -  +  
          -  +  -  +  -  
                   +  - ]
     694                 :            : 
     695                 :            :         /* You should not remove this statement, but need to update the assert statement
     696                 :            :          * if you add a new field, and also add a corresponding SET_FIELD statement */
     697                 :            :         SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 253, "Incorrect size");
     698                 :            : 
     699                 :            : #undef SET_FIELD
     700                 :       2228 : }
     701                 :            : 
     702                 :            : static int
     703                 :       2304 : unclaim_cpu_cores(uint32_t *failed_core)
     704                 :            : {
     705                 :        943 :         char core_name[40];
     706                 :            :         uint32_t i;
     707                 :            :         int rc;
     708                 :            : 
     709         [ +  + ]:     296454 :         for (i = 0; i < SPDK_CONFIG_MAX_LCORES; i++) {
     710   [ +  +  +  +  :     294156 :                 if (g_core_locks[i] != -1 && g_core_locks[i] != 0) {
          +  -  +  +  +  
          -  +  -  +  -  
                   +  + ]
     711                 :       3089 :                         snprintf(core_name, sizeof(core_name), "/var/tmp/spdk_cpu_lock_%03d", i);
     712   [ +  -  +  -  :       3089 :                         rc = close(g_core_locks[i]);
                   +  - ]
     713         [ +  + ]:       3089 :                         if (rc) {
     714         [ #  # ]:          0 :                                 SPDK_ERRLOG("Failed to close lock fd for core %d, errno: %d\n", i, errno);
     715                 :          0 :                                 goto error;
     716                 :            :                         }
     717                 :            : 
     718   [ +  -  +  -  :       3089 :                         g_core_locks[i] = -1;
                   +  - ]
     719         [ +  - ]:       3089 :                         rc = unlink(core_name);
     720         [ +  + ]:       3089 :                         if (rc) {
     721         [ #  # ]:          6 :                                 SPDK_ERRLOG("Failed to unlink lock fd for core %d, errno: %d\n", i, errno);
     722                 :          6 :                                 goto error;
     723                 :            :                         }
     724                 :        144 :                 }
     725                 :      15104 :         }
     726                 :            : 
     727                 :       2298 :         return 0;
     728                 :            : 
     729                 :          6 : error:
     730         [ -  + ]:          6 :         if (failed_core != NULL) {
     731                 :            :                 /* Set number of core we failed to claim. */
     732         [ #  # ]:          0 :                 *failed_core = i;
     733                 :          0 :         }
     734                 :          6 :         return -1;
     735                 :        118 : }
     736                 :            : 
     737                 :            : static int
     738                 :       2185 : claim_cpu_cores(uint32_t *failed_core)
     739                 :            : {
     740                 :        889 :         char core_name[40];
     741                 :            :         int core_fd, pid;
     742                 :            :         int *core_map;
     743                 :            :         uint32_t core;
     744                 :            : 
     745                 :       2185 :         struct flock core_lock = {
     746                 :            :                 .l_type = F_WRLCK,
     747                 :            :                 .l_whence = SEEK_SET,
     748                 :            :                 .l_start = 0,
     749                 :            :                 .l_len = 0,
     750                 :            :         };
     751                 :            : 
     752         [ +  + ]:       5292 :         SPDK_ENV_FOREACH_CORE(core) {
     753   [ +  +  +  -  :       3164 :                 if (g_core_locks[core] != -1) {
             +  -  -  + ]
     754                 :            :                         /* If this core is locked already, do not try lock it again. */
     755                 :          0 :                         continue;
     756                 :            :                 }
     757                 :            : 
     758                 :       3164 :                 snprintf(core_name, sizeof(core_name), "/var/tmp/spdk_cpu_lock_%03d", core);
     759         [ +  - ]:       3164 :                 core_fd = open(core_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
     760         [ +  + ]:       3164 :                 if (core_fd == -1) {
     761         [ #  # ]:          0 :                         SPDK_ERRLOG("Could not open %s (%s).\n", core_name, spdk_strerror(errno));
     762                 :            :                         /* Return number of core we failed to claim. */
     763                 :          0 :                         goto error;
     764                 :            :                 }
     765                 :            : 
     766         [ +  + ]:       3164 :                 if (ftruncate(core_fd, sizeof(int)) != 0) {
     767         [ #  # ]:          0 :                         SPDK_ERRLOG("Could not truncate %s (%s).\n", core_name, spdk_strerror(errno));
     768                 :          0 :                         close(core_fd);
     769                 :          0 :                         goto error;
     770                 :            :                 }
     771                 :            : 
     772                 :       3164 :                 core_map = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, core_fd, 0);
     773         [ +  + ]:       3164 :                 if (core_map == MAP_FAILED) {
     774         [ #  # ]:          0 :                         SPDK_ERRLOG("Could not mmap core %s (%s).\n", core_name, spdk_strerror(errno));
     775                 :          0 :                         close(core_fd);
     776                 :          0 :                         goto error;
     777                 :            :                 }
     778                 :            : 
     779         [ +  + ]:       3164 :                 if (fcntl(core_fd, F_SETLK, &core_lock) != 0) {
     780         [ -  + ]:         57 :                         pid = *core_map;
     781                 :         57 :                         SPDK_ERRLOG("Cannot create lock on core %" PRIu32 ", probably process %d has claimed it.\n",
     782                 :            :                                     core, pid);
     783                 :         57 :                         munmap(core_map, sizeof(int));
     784                 :         57 :                         close(core_fd);
     785                 :         57 :                         goto error;
     786                 :            :                 }
     787                 :            : 
     788                 :            :                 /* We write the PID to the core lock file so that other processes trying
     789                 :            :                 * to claim the same core will know what process is holding the lock. */
     790         [ +  - ]:       3107 :                 *core_map = (int)getpid();
     791                 :       3107 :                 munmap(core_map, sizeof(int));
     792   [ +  -  +  -  :       3107 :                 g_core_locks[core] = core_fd;
                   +  - ]
     793                 :            :                 /* Keep core_fd open to maintain the lock. */
     794                 :        144 :         }
     795                 :            : 
     796                 :       2128 :         return 0;
     797                 :            : 
     798                 :         54 : error:
     799         [ +  + ]:         57 :         if (failed_core != NULL) {
     800                 :            :                 /* Set number of core we failed to claim. */
     801         [ +  - ]:         19 :                 *failed_core = core;
     802                 :          1 :         }
     803                 :         57 :         unclaim_cpu_cores(NULL);
     804                 :         57 :         return -1;
     805                 :        111 : }
     806                 :            : 
     807                 :            : int
     808                 :       2228 : spdk_app_start(struct spdk_app_opts *opts_user, spdk_msg_fn start_fn,
     809                 :            :                void *arg1)
     810                 :            : {
     811                 :            :         int                     rc;
     812                 :            :         char                    *tty;
     813                 :       2228 :         struct spdk_cpuset      tmp_cpumask = {};
     814                 :            :         static bool             g_env_was_setup = false;
     815                 :       2228 :         struct spdk_app_opts opts_local = {};
     816                 :       2228 :         struct spdk_app_opts *opts = &opts_local;
     817                 :            :         uint32_t i, core;
     818                 :            : 
     819         [ +  + ]:       2228 :         if (!opts_user) {
     820                 :          0 :                 SPDK_ERRLOG("opts_user should not be NULL\n");
     821                 :          0 :                 return 1;
     822                 :            :         }
     823                 :            : 
     824   [ +  +  +  -  :       2228 :         if (!opts_user->opts_size) {
                   +  - ]
     825                 :          0 :                 SPDK_ERRLOG("The opts_size in opts_user structure should not be zero value\n");
     826                 :          0 :                 return 1;
     827                 :            :         }
     828                 :            : 
     829   [ +  +  +  -  :       2228 :         if (opts_user->name == NULL) {
                   +  - ]
     830                 :          0 :                 SPDK_ERRLOG("spdk_app_opts::name not specified\n");
     831                 :          0 :                 return 1;
     832                 :            :         }
     833                 :            : 
     834   [ +  -  +  - ]:       2228 :         app_copy_opts(opts, opts_user, opts_user->opts_size);
     835                 :            : 
     836         [ +  + ]:       2228 :         if (!start_fn) {
     837                 :          0 :                 SPDK_ERRLOG("start_fn should not be NULL\n");
     838                 :          0 :                 return 1;
     839                 :            :         }
     840                 :            : 
     841   [ +  +  +  +  :       2228 :         if (!opts->rpc_addr && opts->delay_subsystem_init) {
          +  +  +  -  +  
             -  +  -  +  
                      + ]
     842                 :         21 :                 SPDK_ERRLOG("Cannot use '--wait-for-rpc' if no RPC server is going to be started.\n");
     843                 :         21 :                 return 1;
     844                 :            :         }
     845                 :            : 
     846   [ +  -  +  +  :       2207 :         if (!(opts->lcore_map || opts->reactor_mask)) {
          +  -  +  -  +  
                -  +  + ]
     847                 :            :                 /* Set default CPU mask */
     848   [ +  -  +  - ]:        517 :                 opts->reactor_mask = SPDK_APP_DPDK_DEFAULT_CORE_MASK;
     849                 :         31 :         }
     850                 :            : 
     851                 :       2207 :         tty = ttyname(STDERR_FILENO);
     852   [ +  -  +  +  :       4302 :         if (opts->print_level > SPDK_LOG_WARN &&
             +  -  #  # ]
     853         [ -  + ]:       2207 :             isatty(STDERR_FILENO) &&
     854         [ #  # ]:          0 :             tty &&
     855   [ #  #  #  # ]:          0 :             !strncmp(tty, "/dev/tty", strlen("/dev/tty"))) {
     856                 :          0 :                 printf("Warning: printing stderr to console terminal without -q option specified.\n");
     857                 :          0 :                 printf("Suggest using --silence-noticelog to disable logging to stderr and\n");
     858                 :          0 :                 printf("monitor syslog, or redirect stderr to a file.\n");
     859                 :          0 :                 printf("(Delaying for 10 seconds...)\n");
     860                 :          0 :                 sleep(10);
     861                 :          0 :         }
     862                 :            : 
     863   [ +  -  +  - ]:       2207 :         spdk_log_set_print_level(opts->print_level);
     864                 :            : 
     865                 :            : #ifndef SPDK_NO_RLIMIT
     866   [ +  +  +  -  :       2207 :         if (opts->enable_coredump) {
             +  -  -  + ]
     867                 :        898 :                 struct rlimit core_limits;
     868                 :            : 
     869         [ +  - ]:       2207 :                 core_limits.rlim_cur = core_limits.rlim_max = SPDK_APP_DEFAULT_CORE_LIMIT;
     870         [ +  - ]:       2207 :                 setrlimit(RLIMIT_CORE, &core_limits);
     871                 :        112 :         }
     872                 :            : #endif
     873                 :            : 
     874   [ +  +  +  +  :       2207 :         if (opts->interrupt_mode) {
             +  -  +  - ]
     875                 :         28 :                 spdk_interrupt_mode_enable();
     876                 :          0 :         }
     877                 :            : 
     878         [ +  - ]:       2207 :         memset(&g_spdk_app, 0, sizeof(g_spdk_app));
     879                 :            : 
     880   [ +  +  +  -  :       2207 :         g_spdk_app.json_config_ignore_errors = opts->json_config_ignore_errors;
             +  -  +  - ]
     881   [ +  -  +  -  :       2207 :         g_spdk_app.rpc_addr = opts->rpc_addr;
                   +  - ]
     882   [ +  -  +  -  :       2207 :         g_spdk_app.rpc_allowlist = opts->rpc_allowlist;
                   +  - ]
     883   [ +  -  +  -  :       2207 :         g_spdk_app.rpc_log_file = opts->rpc_log_file;
                   +  - ]
     884   [ +  -  +  -  :       2207 :         g_spdk_app.rpc_log_level = opts->rpc_log_level;
                   +  - ]
     885   [ +  -  +  -  :       2207 :         g_spdk_app.shm_id = opts->shm_id;
                   +  - ]
     886   [ +  -  +  -  :       2207 :         g_spdk_app.shutdown_cb = opts->shutdown_cb;
                   +  - ]
     887         [ +  - ]:       2207 :         g_spdk_app.rc = 0;
     888                 :       2207 :         g_spdk_app.stopped = false;
     889                 :            : 
     890                 :       2207 :         spdk_log_set_level(SPDK_APP_DEFAULT_LOG_LEVEL);
     891                 :            : 
     892                 :            :         /* Pass NULL to app_setup_env if SPDK app has been set up, in order to
     893                 :            :          * indicate that this is a reinitialization.
     894                 :            :          */
     895   [ +  +  +  +  :       2207 :         if (app_setup_env(g_env_was_setup ? NULL : opts) < 0) {
                   +  + ]
     896                 :          0 :                 return 1;
     897                 :            :         }
     898                 :            : 
     899                 :            :         /* Calculate mempool size now that the env layer has configured the core count
     900                 :            :          * for the application */
     901                 :       2207 :         calculate_mempool_size(opts, opts_user);
     902                 :            : 
     903   [ +  -  +  - ]:       2207 :         spdk_log_open(opts->log);
     904                 :            : 
     905                 :            :         /* Initialize each lock to -1 to indicate "empty" status */
     906         [ +  + ]:     284703 :         for (i = 0; i < SPDK_CONFIG_MAX_LCORES; i++) {
     907   [ +  -  +  -  :     282496 :                 g_core_locks[i] = -1;
                   +  - ]
     908                 :      14336 :         }
     909                 :            : 
     910   [ +  +  +  +  :       2207 :         if (!opts->disable_cpumask_locks) {
             +  -  +  + ]
     911         [ +  + ]:       2128 :                 if (claim_cpu_cores(NULL)) {
     912                 :         38 :                         SPDK_ERRLOG("Unable to acquire lock on assigned core mask - exiting.\n");
     913                 :         38 :                         return 1;
     914                 :            :                 }
     915                 :        106 :         } else {
     916                 :         79 :                 SPDK_NOTICELOG("CPU core locks deactivated.\n");
     917                 :            :         }
     918                 :            : 
     919                 :       2169 :         SPDK_NOTICELOG("Total cores available: %d\n", spdk_env_get_core_count());
     920                 :            : 
     921   [ +  +  +  -  :       2169 :         if ((rc = spdk_reactors_init(opts->msg_mempool_size)) != 0) {
                   -  + ]
     922                 :          0 :                 SPDK_ERRLOG("Reactor Initialization failed: rc = %d\n", rc);
     923                 :          0 :                 return 1;
     924                 :            :         }
     925                 :            : 
     926                 :       2169 :         spdk_cpuset_set_cpu(&tmp_cpumask, spdk_env_get_current_core(), true);
     927                 :            : 
     928                 :            :         /*
     929                 :            :          * Disable and ignore trace setup if setting num_entries
     930                 :            :          * to be 0.
     931                 :            :          *
     932                 :            :          * Note the call to app_setup_trace() is located here
     933                 :            :          * ahead of app_setup_signal_handlers().
     934                 :            :          * That's because there is not an easy/direct clean
     935                 :            :          * way of unwinding alloc'd resources that can occur
     936                 :            :          * in app_setup_signal_handlers().
     937                 :            :          */
     938   [ +  -  +  +  :       2169 :         if (opts->num_entries != 0 && app_setup_trace(opts) != 0) {
             +  -  +  - ]
     939                 :          0 :                 return 1;
     940                 :            :         }
     941                 :            : 
     942                 :            :         /* Now that the reactors have been initialized, we can create the app thread. */
     943                 :       2169 :         spdk_thread_create("app_thread", &tmp_cpumask);
     944         [ +  + ]:       2169 :         if (!spdk_thread_get_app_thread()) {
     945                 :          0 :                 SPDK_ERRLOG("Unable to create an spdk_thread for initialization\n");
     946                 :          0 :                 return 1;
     947                 :            :         }
     948                 :            : 
     949         [ +  + ]:       5361 :         SPDK_ENV_FOREACH_CORE(core) {
     950                 :       3192 :                 rc = init_proc_stat(core);
     951         [ +  + ]:       3192 :                 if (rc) {
     952                 :         65 :                         SPDK_NOTICELOG("Unable to parse /proc/stat [core: %d].\n", core);
     953                 :         65 :                 }
     954                 :        148 :         }
     955                 :            : 
     956   [ +  +  +  +  :       2169 :         if (!opts->disable_signal_handlers && app_setup_signal_handlers(opts) != 0) {
          +  +  +  -  -  
                      + ]
     957                 :          0 :                 return 1;
     958                 :            :         }
     959                 :            : 
     960   [ +  +  +  -  :       2169 :         g_delay_subsystem_init = opts->delay_subsystem_init;
                   +  - ]
     961                 :       2169 :         g_start_fn = start_fn;
     962                 :       2169 :         g_start_arg = arg1;
     963                 :            : 
     964   [ +  +  +  -  :       2169 :         if (opts->json_config_file != NULL) {
                   +  + ]
     965   [ +  +  +  -  :        705 :                 if (opts->json_data) {
                   -  + ]
     966                 :          0 :                         SPDK_ERRLOG("App opts json_config_file and json_data are mutually exclusive\n");
     967                 :          0 :                         return 1;
     968                 :            :                 }
     969                 :            : 
     970   [ +  -  +  - ]:        705 :                 g_spdk_app.json_data = spdk_posix_file_load_from_name(opts->json_config_file,
     971                 :            :                                        &g_spdk_app.json_data_size);
     972         [ +  + ]:        705 :                 if (!g_spdk_app.json_data) {
     973   [ #  #  #  #  :          1 :                         SPDK_ERRLOG("Read JSON configuration file %s failed: %s\n",
                   #  # ]
     974                 :            :                                     opts->json_config_file, spdk_strerror(errno));
     975                 :          1 :                         return 1;
     976                 :            :                 }
     977   [ +  +  +  -  :       1519 :         } else if (opts->json_data) {
                   +  - ]
     978   [ #  #  #  # ]:          0 :                 g_spdk_app.json_data = calloc(1, opts->json_data_size);
     979         [ #  # ]:          0 :                 if (!g_spdk_app.json_data) {
     980                 :          0 :                         SPDK_ERRLOG("Failed to allocate JSON data buffer\n");
     981                 :          0 :                         return 1;
     982                 :            :                 }
     983                 :            : 
     984   [ #  #  #  #  :          0 :                 memcpy(g_spdk_app.json_data, opts->json_data, opts->json_data_size);
          #  #  #  #  #  
                #  #  # ]
     985   [ #  #  #  #  :          0 :                 g_spdk_app.json_data_size = opts->json_data_size;
                   #  # ]
     986                 :          0 :         }
     987                 :            : 
     988                 :       2168 :         spdk_thread_send_msg(spdk_thread_get_app_thread(), bootstrap_fn, NULL);
     989                 :            : 
     990                 :            :         /* This blocks until spdk_app_stop is called */
     991                 :       2168 :         spdk_reactors_start();
     992                 :            : 
     993                 :       2168 :         g_env_was_setup = true;
     994                 :            : 
     995         [ +  - ]:       2168 :         return g_spdk_app.rc;
     996                 :        114 : }
     997                 :            : 
     998                 :            : void
     999                 :       2228 : spdk_app_fini(void)
    1000                 :            : {
    1001                 :       2228 :         spdk_trace_cleanup();
    1002                 :       2228 :         spdk_reactors_fini();
    1003                 :       2228 :         spdk_env_fini();
    1004                 :       2228 :         spdk_log_close();
    1005                 :       2228 :         unclaim_cpu_cores(NULL);
    1006                 :       2228 : }
    1007                 :            : 
    1008                 :            : static void
    1009                 :       2168 : subsystem_fini_done(void *arg1)
    1010                 :            : {
    1011                 :       2168 :         spdk_rpc_finish();
    1012                 :       2168 :         spdk_reactors_stop(NULL);
    1013                 :       2168 : }
    1014                 :            : 
    1015                 :            : static void
    1016                 :       2747 : _start_subsystem_fini(void *arg1)
    1017                 :            : {
    1018   [ +  +  +  + ]:       2747 :         if (g_scheduling_in_progress) {
    1019                 :        579 :                 spdk_thread_send_msg(spdk_thread_get_app_thread(), _start_subsystem_fini, NULL);
    1020                 :        579 :                 return;
    1021                 :            :         }
    1022                 :            : 
    1023                 :       2168 :         spdk_subsystem_fini(subsystem_fini_done, NULL);
    1024                 :        111 : }
    1025                 :            : 
    1026                 :            : static int
    1027                 :      14509 : log_deprecation_hits(void *ctx, struct spdk_deprecation *dep)
    1028                 :            : {
    1029                 :      14509 :         uint64_t hits = spdk_deprecation_get_hits(dep);
    1030                 :            : 
    1031         [ +  - ]:      14509 :         if (hits == 0) {
    1032                 :      14509 :                 return 0;
    1033                 :            :         }
    1034                 :            : 
    1035                 :          0 :         SPDK_WARNLOG("%s: deprecation '%s' scheduled for removal in %s hit %" PRIu64 " times\n",
    1036                 :            :                      spdk_deprecation_get_tag(dep), spdk_deprecation_get_description(dep),
    1037                 :            :                      spdk_deprecation_get_remove_release(dep), hits);
    1038                 :          0 :         return 0;
    1039                 :        730 : }
    1040                 :            : 
    1041                 :            : static void
    1042                 :       2175 : app_stop(void *arg1)
    1043                 :            : {
    1044   [ +  +  +  - ]:       2175 :         if (g_spdk_app.rc == 0) {
    1045         [ +  - ]:       2168 :                 g_spdk_app.rc = (int)(intptr_t)arg1;
    1046                 :        110 :         }
    1047                 :            : 
    1048   [ +  +  +  + ]:       2175 :         if (g_spdk_app.stopped) {
    1049                 :          7 :                 SPDK_NOTICELOG("spdk_app_stop called twice\n");
    1050                 :          7 :                 return;
    1051                 :            :         }
    1052                 :            : 
    1053                 :       2168 :         free(g_spdk_app.json_data);
    1054                 :            : 
    1055                 :       2168 :         g_spdk_app.stopped = true;
    1056                 :       2168 :         spdk_log_for_each_deprecation(NULL, log_deprecation_hits);
    1057                 :       2168 :         _start_subsystem_fini(NULL);
    1058                 :        110 : }
    1059                 :            : 
    1060                 :            : void
    1061                 :       2175 : spdk_app_stop(int rc)
    1062                 :            : {
    1063         [ +  + ]:       2175 :         if (rc) {
    1064                 :        177 :                 SPDK_WARNLOG("spdk_app_stop'd on non-zero\n");
    1065                 :          6 :         }
    1066                 :            : 
    1067                 :            :         /*
    1068                 :            :          * We want to run spdk_subsystem_fini() from the same thread where spdk_subsystem_init()
    1069                 :            :          * was called.
    1070                 :            :          */
    1071                 :       2175 :         spdk_thread_send_msg(spdk_thread_get_app_thread(), app_stop, (void *)(intptr_t)rc);
    1072                 :       2175 : }
    1073                 :            : 
    1074                 :            : static void
    1075                 :         22 : usage_memory_size(void)
    1076                 :            : {
    1077                 :            : #ifndef __linux__
    1078         [ +  - ]:          3 :         if (g_default_opts.mem_size <= 0) {
    1079                 :          3 :                 printf("all hugepage memory)\n");
    1080                 :          3 :         } else
    1081                 :            : #endif
    1082                 :            :         {
    1083         [ -  + ]:         19 :                 printf("%dMB)\n", g_default_opts.mem_size >= 0 ? g_default_opts.mem_size : 0);
    1084                 :            :         }
    1085                 :         22 : }
    1086                 :            : 
    1087                 :            : static void
    1088                 :         22 : usage(void (*app_usage)(void))
    1089                 :            : {
    1090         [ -  + ]:         22 :         printf("%s [options]\n", g_executable_name);
    1091                 :            :         /* Keep entries inside categories roughly sorted by frequency of use. */
    1092         [ -  + ]:         22 :         printf("\nCPU options:\n");
    1093         [ -  + ]:         22 :         printf(" -m, --cpumask <mask or list>    core mask (like 0xF) or core list of '[]' embraced for DPDK\n");
    1094         [ -  + ]:         22 :         printf("                                 (like [0,1,10])\n");
    1095         [ -  + ]:         22 :         printf("     --lcores <list>       lcore to CPU mapping list. The list is in the format:\n");
    1096         [ -  + ]:         22 :         printf("                           <lcores[@CPUs]>[<,lcores[@CPUs]>...]\n");
    1097         [ -  + ]:         22 :         printf("                           lcores and cpus list are grouped by '(' and ')', e.g '--lcores \"(5-7)@(10-12)\"'\n");
    1098         [ -  + ]:         22 :         printf("                           Within the group, '-' is used for range separator,\n");
    1099         [ -  + ]:         22 :         printf("                           ',' is used for single number separator.\n");
    1100         [ -  + ]:         22 :         printf("                           '( )' can be omitted for single element group,\n");
    1101         [ -  + ]:         22 :         printf("                           '@' can be omitted if cpus and lcores have the same value\n");
    1102         [ -  + ]:         22 :         printf("     --disable-cpumask-locks    Disable CPU core lock files.\n");
    1103         [ -  + ]:         22 :         printf("     --interrupt-mode      set app to interrupt mode (Warning: CPU usage will be reduced only if all\n");
    1104         [ -  + ]:         22 :         printf("                           pollers in the app support interrupt mode)\n");
    1105         [ -  + ]:         22 :         printf(" -p, --main-core <id>      main (primary) core for DPDK\n");
    1106                 :            : 
    1107         [ -  + ]:         22 :         printf("\nConfiguration options:\n");
    1108         [ -  + ]:         22 :         printf(" -c, --config, --json  <config>     JSON config file\n");
    1109         [ -  + ]:         22 :         printf(" -r, --rpc-socket <path>   RPC listen address (default %s)\n", SPDK_DEFAULT_RPC_ADDR);
    1110         [ -  + ]:         22 :         printf("     --no-rpc-server       skip RPC server initialization. This option ignores '--rpc-socket' value.\n");
    1111         [ -  + ]:         22 :         printf("     --wait-for-rpc        wait for RPCs to initialize subsystems\n");
    1112         [ -  + ]:         22 :         printf("     --rpcs-allowed           comma-separated list of permitted RPCS\n");
    1113         [ -  + ]:         22 :         printf("     --json-ignore-init-errors    don't exit on invalid config entry\n");
    1114                 :            : 
    1115         [ -  + ]:         22 :         printf("\nMemory options:\n");
    1116         [ -  + ]:         22 :         printf("     --iova-mode <pa/va>   set IOVA mode ('pa' for IOVA_PA and 'va' for IOVA_VA)\n");
    1117         [ -  + ]:         22 :         printf("     --base-virtaddr <addr>      the base virtual address for DPDK (default: 0x200000000000)\n");
    1118         [ -  + ]:         22 :         printf("     --huge-dir <path>     use a specific hugetlbfs mount to reserve memory from\n");
    1119         [ -  + ]:         22 :         printf(" -R, --huge-unlink         unlink huge files after initialization\n");
    1120         [ -  + ]:         22 :         printf(" -n, --mem-channels <num>  number of memory channels used for DPDK\n");
    1121         [ -  + ]:         22 :         printf(" -s, --mem-size <size>     memory size in MB for DPDK (default: ");
    1122                 :         22 :         usage_memory_size();
    1123         [ -  + ]:         22 :         printf("     --msg-mempool-size <size>  global message memory pool size in count (default: %d)\n",
    1124                 :            :                SPDK_DEFAULT_MSG_MEMPOOL_SIZE);
    1125         [ -  + ]:         22 :         printf("     --no-huge             run without using hugepages\n");
    1126         [ -  + ]:         22 :         printf("     --enforce-numa        enforce NUMA allocations from the specified NUMA node\n");
    1127         [ -  + ]:         22 :         printf(" -i, --shm-id <id>         shared memory ID (optional)\n");
    1128         [ -  + ]:         22 :         printf(" -g, --single-file-segments   force creating just one hugetlbfs file\n");
    1129                 :            : 
    1130         [ -  + ]:         22 :         printf("\nPCI options:\n");
    1131         [ -  + ]:         22 :         printf(" -A, --pci-allowed <bdf>   pci addr to allow (-B and -A cannot be used at the same time)\n");
    1132         [ -  + ]:         22 :         printf(" -B, --pci-blocked <bdf>   pci addr to block (can be used more than once)\n");
    1133         [ -  + ]:         22 :         printf(" -u, --no-pci              disable PCI access\n");
    1134         [ -  + ]:         22 :         printf("     --vfio-vf-token       VF token (UUID) shared between SR-IOV PF and VFs for vfio_pci driver\n");
    1135                 :            : 
    1136         [ -  + ]:         22 :         printf("\nLog options:\n");
    1137                 :         22 :         spdk_log_usage(stdout, "-L");
    1138         [ -  + ]:         22 :         printf("     --silence-noticelog   disable notice level logging to stderr\n");
    1139                 :            : 
    1140         [ -  + ]:         22 :         printf("\nTrace options:\n");
    1141         [ -  + ]:         22 :         printf("     --num-trace-entries <num>   number of trace entries for each core, must be power of 2,\n");
    1142         [ -  + ]:         22 :         printf("                                 setting 0 to disable trace (default %d)\n",
    1143                 :            :                SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES);
    1144         [ -  + ]:         22 :         printf("                                 Tracepoints vary in size and can use more than one trace entry.\n");
    1145                 :         22 :         spdk_trace_mask_usage(stdout, "-e");
    1146                 :            : 
    1147         [ -  + ]:         22 :         printf("\nOther options:\n");
    1148         [ -  + ]:         22 :         printf(" -h, --help                show this usage\n");
    1149         [ -  + ]:         22 :         printf(" -v, --version             print SPDK version\n");
    1150         [ -  + ]:         22 :         printf(" -d, --limit-coredump      do not set max coredump size to RLIM_INFINITY\n");
    1151         [ -  + ]:         22 :         printf("     --env-context         Opaque context for use of the env implementation\n");
    1152                 :            : 
    1153         [ +  + ]:         22 :         if (app_usage) {
    1154         [ -  + ]:         10 :                 printf("\nApplication specific:\n");
    1155   [ #  #  #  # ]:         10 :                 app_usage();
    1156                 :          0 :         }
    1157                 :         22 : }
    1158                 :            : 
    1159                 :            : spdk_app_parse_args_rvals_t
    1160                 :       2172 : spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts,
    1161                 :            :                     const char *app_getopt_str, const struct option *app_long_opts,
    1162                 :            :                     int (*app_parse)(int ch, char *arg),
    1163                 :            :                     void (*app_usage)(void))
    1164                 :            : {
    1165                 :        895 :         int ch, rc, opt_idx, global_long_opts_len, app_long_opts_len;
    1166                 :            :         struct option *cmdline_options;
    1167                 :       2172 :         char *cmdline_short_opts = NULL;
    1168                 :       2172 :         char *shm_id_str = NULL;
    1169                 :       2172 :         enum spdk_app_parse_args_rvals retval = SPDK_APP_PARSE_ARGS_FAIL;
    1170                 :            :         long int tmp;
    1171                 :            : 
    1172   [ +  -  +  - ]:       2172 :         memcpy(&g_default_opts, opts, sizeof(g_default_opts));
    1173                 :            : 
    1174   [ +  +  +  +  :       2172 :         if (opts->json_config_file && access(opts->json_config_file, R_OK) != 0) {
          -  +  #  #  #  
             #  #  #  #  
                      # ]
    1175   [ #  #  #  # ]:          0 :                 SPDK_WARNLOG("Can't read JSON configuration file '%s'\n", opts->json_config_file);
    1176   [ #  #  #  # ]:          0 :                 opts->json_config_file = NULL;
    1177                 :          0 :         }
    1178                 :            : 
    1179         [ +  + ]:       2172 :         if (app_long_opts == NULL) {
    1180                 :       1702 :                 app_long_opts_len = 0;
    1181                 :        110 :         } else {
    1182         [ +  + ]:        471 :                 for (app_long_opts_len = 0;
    1183   [ +  +  #  #  :       6532 :                      app_long_opts[app_long_opts_len].name != NULL;
                   #  # ]
    1184         [ #  # ]:       6062 :                      app_long_opts_len++);
    1185                 :            :         }
    1186                 :            : 
    1187                 :       2172 :         global_long_opts_len = SPDK_COUNTOF(g_cmdline_options);
    1188                 :            : 
    1189   [ +  -  +  - ]:       2172 :         cmdline_options = calloc(global_long_opts_len + app_long_opts_len + 1, sizeof(*cmdline_options));
    1190         [ +  + ]:       2172 :         if (!cmdline_options) {
    1191                 :          0 :                 SPDK_ERRLOG("Out of memory\n");
    1192                 :          0 :                 return SPDK_APP_PARSE_ARGS_FAIL;
    1193                 :            :         }
    1194                 :            : 
    1195   [ +  +  +  +  :       2172 :         memcpy(&cmdline_options[0], g_cmdline_options, sizeof(g_cmdline_options));
                   +  - ]
    1196         [ +  + ]:       2172 :         if (app_long_opts) {
    1197   [ -  +  -  +  :        471 :                 memcpy(&cmdline_options[global_long_opts_len], app_long_opts,
             #  #  #  # ]
    1198                 :          1 :                        app_long_opts_len * sizeof(*app_long_opts));
    1199                 :          1 :         }
    1200                 :            : 
    1201         [ +  + ]:       2172 :         if (app_getopt_str != NULL) {
    1202                 :       2172 :                 ch = app_opts_validate(app_getopt_str);
    1203         [ +  + ]:       2172 :                 if (ch) {
    1204                 :          4 :                         SPDK_ERRLOG("Duplicated option '%c' between app-specific command line parameter and generic spdk opts.\n",
    1205                 :            :                                     ch);
    1206                 :          4 :                         goto out;
    1207                 :            :                 }
    1208                 :            : 
    1209         [ +  + ]:       2168 :                 if (!app_parse) {
    1210                 :          0 :                         SPDK_ERRLOG("Parse function is required when app-specific command line parameters are provided.\n");
    1211                 :          0 :                         goto out;
    1212                 :            :                 }
    1213                 :        110 :         }
    1214                 :            : 
    1215                 :       2168 :         cmdline_short_opts = spdk_sprintf_alloc("%s%s", app_getopt_str, SPDK_APP_GETOPT_STRING);
    1216         [ +  + ]:       2168 :         if (!cmdline_short_opts) {
    1217                 :          0 :                 SPDK_ERRLOG("Out of memory\n");
    1218                 :          0 :                 goto out;
    1219                 :            :         }
    1220                 :            : 
    1221   [ +  -  +  - ]:       2168 :         g_executable_name = argv[0];
    1222                 :            : 
    1223   [ +  +  +  +  :      10133 :         while ((ch = getopt_long(argc, argv, cmdline_short_opts, cmdline_options, &opt_idx)) != -1) {
                   +  + ]
    1224   [ +  +  +  +  :       7995 :                 switch (ch) {
          +  +  +  +  +  
          +  +  +  -  +  
          +  -  +  +  +  
          +  +  +  +  +  
          +  -  -  -  +  
          -  +  -  +  -  
                   +  + ]
    1225                 :        655 :                 case CONFIG_FILE_OPT_IDX:
    1226                 :            :                 case JSON_CONFIG_OPT_IDX:
    1227   [ +  -  +  - ]:        713 :                         opts->json_config_file = optarg;
    1228                 :        713 :                         break;
    1229                 :          0 :                 case JSON_CONFIG_IGNORE_INIT_ERRORS_IDX:
    1230   [ #  #  #  # ]:          0 :                         opts->json_config_ignore_errors = true;
    1231                 :          0 :                         break;
    1232                 :         16 :                 case LIMIT_COREDUMP_OPT_IDX:
    1233   [ #  #  #  # ]:         21 :                         opts->enable_coredump = false;
    1234                 :         21 :                         break;
    1235                 :        260 :                 case TPOINT_GROUP_OPT_IDX:
    1236   [ +  -  +  - ]:        262 :                         opts->tpoint_group_mask = optarg;
    1237                 :        262 :                         break;
    1238                 :         28 :                 case SINGLE_FILE_SEGMENTS_OPT_IDX:
    1239   [ #  #  #  # ]:         31 :                         opts->hugepage_single_segments = true;
    1240                 :         31 :                         break;
    1241                 :          3 :                 case HELP_OPT_IDX:
    1242                 :          3 :                         usage(app_usage);
    1243                 :          3 :                         retval = SPDK_APP_PARSE_ARGS_HELP;
    1244                 :          3 :                         goto out;
    1245                 :        317 :                 case SHM_ID_OPT_IDX:
    1246                 :        317 :                         shm_id_str = optarg;
    1247                 :            :                         /* a negative shm-id disables shared configuration file */
    1248   [ -  +  #  #  :        317 :                         if (optarg[0] == '-') {
                   #  # ]
    1249         [ #  # ]:          0 :                                 shm_id_str++;
    1250                 :          0 :                         }
    1251                 :            :                         /* check if the positive value of provided shm_id can be parsed as
    1252                 :            :                          * an integer
    1253                 :            :                          */
    1254   [ #  #  #  # ]:        317 :                         opts->shm_id = spdk_strtol(shm_id_str, 0);
    1255   [ -  +  #  #  :        317 :                         if (opts->shm_id < 0) {
                   #  # ]
    1256                 :          0 :                                 SPDK_ERRLOG("Invalid shared memory ID %s\n", optarg);
    1257                 :          0 :                                 goto out;
    1258                 :            :                         }
    1259   [ -  +  #  #  :        317 :                         if (optarg[0] == '-') {
                   #  # ]
    1260   [ #  #  #  #  :          0 :                                 opts->shm_id = -opts->shm_id;
          #  #  #  #  #  
                      # ]
    1261                 :          0 :                         }
    1262                 :        317 :                         break;
    1263                 :        976 :                 case CPUMASK_OPT_IDX:
    1264   [ +  +  +  -  :       1050 :                         if (opts->lcore_map) {
                   +  - ]
    1265                 :          0 :                                 SPDK_ERRLOG("lcore map and core mask can't be set simultaneously\n");
    1266                 :          0 :                                 goto out;
    1267                 :            :                         }
    1268   [ +  -  +  - ]:       1050 :                         opts->reactor_mask = optarg;
    1269                 :       1050 :                         break;
    1270                 :          0 :                 case LCORES_OPT_IDX:
    1271   [ #  #  #  #  :          0 :                         if (opts->reactor_mask) {
                   #  # ]
    1272                 :          0 :                                 SPDK_ERRLOG("lcore map and core mask can't be set simultaneously\n");
    1273                 :          0 :                                 goto out;
    1274                 :            :                         }
    1275   [ #  #  #  # ]:          0 :                         opts->lcore_map = optarg;
    1276                 :          0 :                         break;
    1277                 :         75 :                 case DISABLE_CPUMASK_LOCKS_OPT_IDX:
    1278   [ +  -  +  - ]:         79 :                         opts->disable_cpumask_locks = true;
    1279                 :         79 :                         break;
    1280                 :          0 :                 case MEM_CHANNELS_OPT_IDX:
    1281   [ #  #  #  # ]:          0 :                         opts->mem_channel = spdk_strtol(optarg, 0);
    1282   [ #  #  #  #  :          0 :                         if (opts->mem_channel < 0) {
                   #  # ]
    1283                 :          0 :                                 SPDK_ERRLOG("Invalid memory channel %s\n", optarg);
    1284                 :          0 :                                 goto out;
    1285                 :            :                         }
    1286                 :          0 :                         break;
    1287                 :         65 :                 case MAIN_CORE_OPT_IDX:
    1288   [ +  -  +  - ]:         71 :                         opts->main_core = spdk_strtol(optarg, 0);
    1289   [ +  +  +  -  :         71 :                         if (opts->main_core < 0) {
                   +  - ]
    1290                 :          4 :                                 SPDK_ERRLOG("Invalid main core %s\n", optarg);
    1291                 :          4 :                                 goto out;
    1292                 :            :                         }
    1293                 :         67 :                         break;
    1294                 :          0 :                 case SILENCE_NOTICELOG_OPT_IDX:
    1295   [ #  #  #  # ]:          0 :                         opts->print_level = SPDK_LOG_WARN;
    1296                 :          0 :                         break;
    1297                 :        378 :                 case RPC_SOCKET_OPT_IDX:
    1298   [ +  -  +  - ]:        397 :                         opts->rpc_addr = optarg;
    1299                 :        397 :                         break;
    1300                 :         57 :                 case NO_RPC_SERVER_OPT_IDX:
    1301   [ +  -  +  - ]:         63 :                         opts->rpc_addr = NULL;
    1302                 :         63 :                         break;
    1303                 :          0 :                 case ENFORCE_NUMA_OPT_IDX:
    1304   [ #  #  #  # ]:          0 :                         opts->enforce_numa = true;
    1305                 :          0 :                         break;
    1306                 :        118 :                 case MEM_SIZE_OPT_IDX: {
    1307                 :         35 :                         uint64_t mem_size_mb;
    1308                 :         35 :                         bool mem_size_has_prefix;
    1309                 :            : 
    1310                 :        156 :                         rc = spdk_parse_capacity(optarg, &mem_size_mb, &mem_size_has_prefix);
    1311         [ +  + ]:        156 :                         if (rc != 0) {
    1312                 :          0 :                                 SPDK_ERRLOG("invalid memory pool size `-s %s`\n", optarg);
    1313                 :          0 :                                 usage(app_usage);
    1314                 :          0 :                                 goto out;
    1315                 :            :                         }
    1316                 :            : 
    1317   [ +  +  +  + ]:        156 :                         if (mem_size_has_prefix) {
    1318                 :            :                                 /* the mem size is in MB by default, so if a prefix was
    1319                 :            :                                  * specified, we need to manually convert to MB.
    1320                 :            :                                  */
    1321         [ #  # ]:          0 :                                 mem_size_mb /= 1024 * 1024;
    1322                 :          0 :                         }
    1323                 :            : 
    1324         [ +  + ]:        156 :                         if (mem_size_mb > INT_MAX) {
    1325                 :          0 :                                 SPDK_ERRLOG("invalid memory pool size `-s %s`\n", optarg);
    1326                 :          0 :                                 usage(app_usage);
    1327                 :          0 :                                 goto out;
    1328                 :            :                         }
    1329                 :            : 
    1330   [ +  -  +  - ]:        156 :                         opts->mem_size = (int) mem_size_mb;
    1331                 :        156 :                         break;
    1332                 :            :                 }
    1333                 :          0 :                 case MSG_MEMPOOL_SIZE_OPT_IDX:
    1334                 :          0 :                         tmp = spdk_strtol(optarg, 10);
    1335         [ #  # ]:          0 :                         if (tmp <= 0) {
    1336                 :          0 :                                 SPDK_ERRLOG("Invalid message memory pool size %s\n", optarg);
    1337                 :          0 :                                 goto out;
    1338                 :            :                         }
    1339                 :            : 
    1340   [ #  #  #  # ]:          0 :                         opts->msg_mempool_size = (size_t)tmp;
    1341                 :          0 :                         break;
    1342                 :            : 
    1343                 :          4 :                 case NO_PCI_OPT_IDX:
    1344   [ #  #  #  # ]:          4 :                         opts->no_pci = true;
    1345                 :          4 :                         break;
    1346                 :        157 :                 case WAIT_FOR_RPC_OPT_IDX:
    1347   [ +  -  +  - ]:        162 :                         opts->delay_subsystem_init = true;
    1348                 :        162 :                         break;
    1349                 :          6 :                 case PCI_BLOCKED_OPT_IDX:
    1350   [ +  +  #  #  :          8 :                         if (opts->pci_allowed) {
                   #  # ]
    1351   [ #  #  #  # ]:          0 :                                 free(opts->pci_allowed);
    1352   [ #  #  #  # ]:          0 :                                 opts->pci_allowed = NULL;
    1353                 :          0 :                                 SPDK_ERRLOG("-B and -A cannot be used at the same time\n");
    1354                 :          0 :                                 usage(app_usage);
    1355                 :          0 :                                 goto out;
    1356                 :            :                         }
    1357                 :            : 
    1358         [ #  # ]:          8 :                         rc = app_opts_add_pci_addr(opts, &opts->pci_blocked, optarg);
    1359         [ +  + ]:          8 :                         if (rc != 0) {
    1360   [ #  #  #  # ]:          0 :                                 free(opts->pci_blocked);
    1361   [ #  #  #  # ]:          0 :                                 opts->pci_blocked = NULL;
    1362                 :          0 :                                 goto out;
    1363                 :            :                         }
    1364                 :          8 :                         break;
    1365                 :            : 
    1366                 :          6 :                 case NO_HUGE_OPT_IDX:
    1367   [ #  #  #  # ]:          6 :                         opts->no_huge = true;
    1368                 :          6 :                         break;
    1369                 :            : 
    1370                 :        107 :                 case LOGFLAG_OPT_IDX:
    1371                 :        107 :                         rc = spdk_log_set_flag(optarg);
    1372         [ -  + ]:        107 :                         if (rc < 0) {
    1373                 :          0 :                                 SPDK_ERRLOG("unknown flag: %s\n", optarg);
    1374                 :          0 :                                 usage(app_usage);
    1375                 :          0 :                                 goto out;
    1376                 :            :                         }
    1377                 :            : #ifdef DEBUG
    1378   [ #  #  #  # ]:        107 :                         opts->print_level = SPDK_LOG_DEBUG;
    1379                 :            : #endif
    1380                 :        107 :                         break;
    1381                 :          1 :                 case HUGE_UNLINK_OPT_IDX:
    1382   [ #  #  #  # ]:          1 :                         opts->unlink_hugepage = true;
    1383                 :          1 :                         break;
    1384                 :          3 :                 case PCI_ALLOWED_OPT_IDX:
    1385   [ +  +  #  #  :          4 :                         if (opts->pci_blocked) {
                   #  # ]
    1386   [ #  #  #  # ]:          4 :                                 free(opts->pci_blocked);
    1387   [ #  #  #  # ]:          4 :                                 opts->pci_blocked = NULL;
    1388                 :          4 :                                 SPDK_ERRLOG("-B and -W cannot be used at the same time\n");
    1389                 :          4 :                                 usage(app_usage);
    1390                 :          4 :                                 goto out;
    1391                 :            :                         }
    1392                 :            : 
    1393         [ #  # ]:          0 :                         rc = app_opts_add_pci_addr(opts, &opts->pci_allowed, optarg);
    1394         [ #  # ]:          0 :                         if (rc != 0) {
    1395   [ #  #  #  # ]:          0 :                                 free(opts->pci_allowed);
    1396   [ #  #  #  # ]:          0 :                                 opts->pci_allowed = NULL;
    1397                 :          0 :                                 goto out;
    1398                 :            :                         }
    1399                 :          0 :                         break;
    1400                 :          0 :                 case BASE_VIRTADDR_OPT_IDX:
    1401                 :          0 :                         tmp = spdk_strtoll(optarg, 0);
    1402         [ #  # ]:          0 :                         if (tmp <= 0) {
    1403                 :          0 :                                 SPDK_ERRLOG("Invalid base-virtaddr %s\n", optarg);
    1404                 :          0 :                                 usage(app_usage);
    1405                 :          0 :                                 goto out;
    1406                 :            :                         }
    1407   [ #  #  #  # ]:          0 :                         opts->base_virtaddr = (uint64_t)tmp;
    1408                 :          0 :                         break;
    1409                 :          0 :                 case HUGE_DIR_OPT_IDX:
    1410   [ #  #  #  # ]:          0 :                         opts->hugedir = optarg;
    1411                 :          0 :                         break;
    1412                 :          0 :                 case IOVA_MODE_OPT_IDX:
    1413   [ #  #  #  # ]:          0 :                         opts->iova_mode = optarg;
    1414                 :          0 :                         break;
    1415                 :          2 :                 case NUM_TRACE_ENTRIES_OPT_IDX:
    1416                 :          2 :                         tmp = spdk_strtoll(optarg, 0);
    1417         [ -  + ]:          2 :                         if (tmp < 0) {
    1418                 :          0 :                                 SPDK_ERRLOG("Invalid num-trace-entries %s\n", optarg);
    1419                 :          0 :                                 usage(app_usage);
    1420                 :          0 :                                 goto out;
    1421                 :            :                         }
    1422   [ #  #  #  # ]:          2 :                         opts->num_entries = (uint64_t)tmp;
    1423   [ +  -  -  +  :          2 :                         if (opts->num_entries > 0 && opts->num_entries & (opts->num_entries - 1)) {
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1424                 :          0 :                                 SPDK_ERRLOG("num-trace-entries must be power of 2\n");
    1425                 :          0 :                                 usage(app_usage);
    1426                 :          0 :                                 goto out;
    1427                 :            :                         }
    1428                 :          2 :                         break;
    1429                 :          0 :                 case ENV_CONTEXT_OPT_IDX:
    1430   [ #  #  #  # ]:          0 :                         opts->env_context = optarg;
    1431                 :          0 :                         break;
    1432                 :         19 :                 case RPCS_ALLOWED_OPT_IDX:
    1433   [ +  -  +  - ]:         21 :                         opts->rpc_allowlist = (const char **)spdk_strarray_from_string(optarg, ",");
    1434   [ +  +  +  -  :         21 :                         if (opts->rpc_allowlist == NULL) {
                   +  - ]
    1435                 :          0 :                                 SPDK_ERRLOG("Invalid --rpcs-allowed argument\n");
    1436                 :          0 :                                 usage(app_usage);
    1437                 :          0 :                                 goto out;
    1438                 :            :                         }
    1439                 :         21 :                         break;
    1440                 :          0 :                 case ENV_VF_TOKEN_OPT_IDX:
    1441   [ #  #  #  # ]:          0 :                         opts->vf_token = optarg;
    1442                 :          0 :                         break;
    1443                 :         28 :                 case INTERRUPT_MODE_OPT_IDX:
    1444   [ #  #  #  # ]:         28 :                         opts->interrupt_mode = true;
    1445                 :         28 :                         break;
    1446                 :          0 :                 case VERSION_OPT_IDX:
    1447         [ #  # ]:          0 :                         printf(SPDK_VERSION_STRING"\n");
    1448                 :          0 :                         retval = SPDK_APP_PARSE_ARGS_HELP;
    1449                 :          0 :                         goto out;
    1450                 :         13 :                 case '?':
    1451                 :            :                         /*
    1452                 :            :                          * In the event getopt() above detects an option
    1453                 :            :                          * in argv that is NOT in the getopt_str,
    1454                 :            :                          * getopt() will return a '?' indicating failure.
    1455                 :            :                          */
    1456                 :         15 :                         usage(app_usage);
    1457                 :         15 :                         goto out;
    1458                 :       4206 :                 default:
    1459         [ +  + ]:       4474 :                         if (!app_parse) {
    1460                 :          0 :                                 SPDK_ERRLOG("Unsupported app-specific command line parameter '%c'.\n", ch);
    1461                 :          0 :                                 goto out;
    1462                 :            :                         }
    1463                 :            : 
    1464   [ -  +  +  - ]:       4474 :                         rc = app_parse(ch, optarg);
    1465         [ +  + ]:       4474 :                         if (rc) {
    1466                 :          4 :                                 SPDK_ERRLOG("Parsing app-specific command line parameter '%c' failed: %d\n", ch, rc);
    1467                 :          4 :                                 goto out;
    1468                 :            :                         }
    1469                 :        268 :                 }
    1470                 :            :         }
    1471                 :            : 
    1472                 :       2138 :         retval = SPDK_APP_PARSE_ARGS_SUCCESS;
    1473                 :       2061 : out:
    1474         [ +  + ]:       2172 :         if (retval != SPDK_APP_PARSE_ARGS_SUCCESS) {
    1475   [ #  #  #  # ]:         34 :                 free(opts->pci_blocked);
    1476   [ #  #  #  # ]:         34 :                 opts->pci_blocked = NULL;
    1477   [ #  #  #  # ]:         34 :                 free(opts->pci_allowed);
    1478   [ #  #  #  # ]:         34 :                 opts->pci_allowed = NULL;
    1479   [ #  #  #  # ]:         34 :                 spdk_strarray_free((char **)opts->rpc_allowlist);
    1480   [ #  #  #  # ]:         34 :                 opts->rpc_allowlist = NULL;
    1481                 :          5 :         }
    1482                 :       2172 :         free(cmdline_short_opts);
    1483                 :       2172 :         free(cmdline_options);
    1484                 :       2172 :         return retval;
    1485                 :        111 : }
    1486                 :            : 
    1487                 :            : void
    1488                 :          0 : spdk_app_usage(void)
    1489                 :            : {
    1490         [ #  # ]:          0 :         if (g_executable_name == NULL) {
    1491                 :          0 :                 SPDK_ERRLOG("%s not valid before calling spdk_app_parse_args()\n", __func__);
    1492                 :          0 :                 return;
    1493                 :            :         }
    1494                 :            : 
    1495                 :          0 :         usage(NULL);
    1496                 :          0 : }
    1497                 :            : 
    1498                 :            : static void
    1499                 :        141 : rpc_framework_start_init_cpl(int rc, void *arg1)
    1500                 :            : {
    1501                 :        141 :         struct spdk_jsonrpc_request *request = arg1;
    1502                 :            : 
    1503   [ +  +  #  # ]:        141 :         assert(spdk_thread_is_app_thread(NULL));
    1504                 :            : 
    1505         [ -  + ]:        141 :         if (rc) {
    1506                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
    1507                 :            :                                                  "framework_initialization failed");
    1508                 :          0 :                 return;
    1509                 :            :         }
    1510                 :            : 
    1511                 :        141 :         app_subsystem_init_done(0, NULL);
    1512                 :            : 
    1513                 :        141 :         spdk_jsonrpc_send_bool_response(request, true);
    1514                 :          3 : }
    1515                 :            : 
    1516                 :            : static void
    1517                 :        141 : rpc_framework_start_init(struct spdk_jsonrpc_request *request,
    1518                 :            :                          const struct spdk_json_val *params)
    1519                 :            : {
    1520         [ -  + ]:        141 :         if (params != NULL) {
    1521                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
    1522                 :            :                                                  "framework_start_init requires no parameters");
    1523                 :          0 :                 return;
    1524                 :            :         }
    1525                 :            : 
    1526         [ +  - ]:        141 :         spdk_rpc_server_pause(g_spdk_app.rpc_addr);
    1527                 :        141 :         spdk_subsystem_init(rpc_framework_start_init_cpl, request);
    1528                 :          3 : }
    1529                 :       2275 : SPDK_RPC_REGISTER("framework_start_init", rpc_framework_start_init, SPDK_RPC_STARTUP)
    1530                 :            : 
    1531                 :            : struct subsystem_init_poller_ctx {
    1532                 :            :         struct spdk_poller *init_poller;
    1533                 :            :         struct spdk_jsonrpc_request *request;
    1534                 :            : };
    1535                 :            : 
    1536                 :            : static int
    1537                 :     439613 : rpc_subsystem_init_poller_ctx(void *ctx)
    1538                 :            : {
    1539                 :     439613 :         struct subsystem_init_poller_ctx *poller_ctx = ctx;
    1540                 :            : 
    1541         [ +  + ]:     439613 :         if (spdk_rpc_get_state() == SPDK_RPC_RUNTIME) {
    1542   [ #  #  #  # ]:          2 :                 spdk_jsonrpc_send_bool_response(poller_ctx->request, true);
    1543         [ #  # ]:          2 :                 spdk_poller_unregister(&poller_ctx->init_poller);
    1544                 :          2 :                 free(poller_ctx);
    1545                 :          0 :         }
    1546                 :            : 
    1547                 :     439613 :         return SPDK_POLLER_BUSY;
    1548                 :            : }
    1549                 :            : 
    1550                 :            : static void
    1551                 :         13 : rpc_framework_wait_init(struct spdk_jsonrpc_request *request,
    1552                 :            :                         const struct spdk_json_val *params)
    1553                 :            : {
    1554                 :            :         struct subsystem_init_poller_ctx *ctx;
    1555                 :            : 
    1556         [ +  + ]:         13 :         if (spdk_rpc_get_state() == SPDK_RPC_RUNTIME) {
    1557                 :         11 :                 spdk_jsonrpc_send_bool_response(request, true);
    1558                 :          0 :         } else {
    1559                 :          2 :                 ctx = malloc(sizeof(struct subsystem_init_poller_ctx));
    1560         [ -  + ]:          2 :                 if (ctx == NULL) {
    1561                 :          0 :                         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
    1562                 :            :                                                          "Unable to allocate memory for the request context\n");
    1563                 :          0 :                         return;
    1564                 :            :                 }
    1565   [ #  #  #  # ]:          2 :                 ctx->request = request;
    1566   [ #  #  #  # ]:          2 :                 ctx->init_poller = SPDK_POLLER_REGISTER(rpc_subsystem_init_poller_ctx, ctx, 0);
    1567                 :            :         }
    1568                 :          0 : }
    1569                 :       2275 : SPDK_RPC_REGISTER("framework_wait_init", rpc_framework_wait_init,
    1570                 :            :                   SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
    1571                 :            : 
    1572                 :            : static void
    1573                 :         19 : rpc_framework_disable_cpumask_locks(struct spdk_jsonrpc_request *request,
    1574                 :            :                                     const struct spdk_json_val *params)
    1575                 :            : {
    1576                 :          9 :         char msg[128];
    1577                 :            :         int rc;
    1578                 :          9 :         uint32_t failed_core;
    1579                 :            : 
    1580         [ -  + ]:         19 :         if (params != NULL) {
    1581                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
    1582                 :            :                                                  "framework_disable_cpumask_locks"
    1583                 :            :                                                  "requires no arguments");
    1584                 :          0 :                 return;
    1585                 :            :         }
    1586                 :            : 
    1587                 :         19 :         rc = unclaim_cpu_cores(&failed_core);
    1588         [ +  + ]:         19 :         if (rc) {
    1589         [ #  # ]:          0 :                 snprintf(msg, sizeof(msg), "Failed to unclaim CPU core: %" PRIu32, failed_core);
    1590                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, msg);
    1591                 :          0 :                 return;
    1592                 :            :         }
    1593                 :            : 
    1594                 :         19 :         spdk_jsonrpc_send_bool_response(request, true);
    1595                 :          1 : }
    1596                 :       2275 : SPDK_RPC_REGISTER("framework_disable_cpumask_locks", rpc_framework_disable_cpumask_locks,
    1597                 :            :                   SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
    1598                 :            : 
    1599                 :            : static void
    1600                 :         57 : rpc_framework_enable_cpumask_locks(struct spdk_jsonrpc_request *request,
    1601                 :            :                                    const struct spdk_json_val *params)
    1602                 :            : {
    1603                 :         27 :         char msg[128];
    1604                 :            :         int rc;
    1605                 :         27 :         uint32_t failed_core;
    1606                 :            : 
    1607         [ -  + ]:         57 :         if (params != NULL) {
    1608                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
    1609                 :            :                                                  "framework_enable_cpumask_locks"
    1610                 :            :                                                  "requires no arguments");
    1611                 :          9 :                 return;
    1612                 :            :         }
    1613                 :            : 
    1614                 :         57 :         rc = claim_cpu_cores(&failed_core);
    1615         [ +  + ]:         57 :         if (rc) {
    1616         [ -  + ]:         19 :                 snprintf(msg, sizeof(msg), "Failed to claim CPU core: %" PRIu32, failed_core);
    1617                 :         19 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, msg);
    1618                 :         19 :                 return;
    1619                 :            :         }
    1620                 :            : 
    1621                 :         38 :         spdk_jsonrpc_send_bool_response(request, true);
    1622                 :          3 : }
    1623                 :       2275 : SPDK_RPC_REGISTER("framework_enable_cpumask_locks", rpc_framework_enable_cpumask_locks,
    1624                 :            :                   SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)

Generated by: LCOV version 1.14