LCOV - code coverage report
Current view: top level - spdk/lib/event - app.c (source / functions) Hit Total Coverage
Test: Combined Lines: 649 866 74.9 %
Date: 2024-07-12 14:52:44 Functions: 40 42 95.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 386 665 58.0 %

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

Generated by: LCOV version 1.14