LCOV - code coverage report
Current view: top level - spdk/module/event/subsystems/nvmf - nvmf_rpc.c (source / functions) Hit Total Coverage
Test: Combined Lines: 55 102 53.9 %
Date: 2024-07-13 06:45:54 Functions: 8 10 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 21 52 40.4 %

           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) 2018-2019 Mellanox Technologies LTD. All rights reserved.
       4                 :            :  *   Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
       5                 :            :  */
       6                 :            : 
       7                 :            : #include "event_nvmf.h"
       8                 :            : 
       9                 :            : #include "spdk/rpc.h"
      10                 :            : #include "spdk/util.h"
      11                 :            : #include "spdk/cpuset.h"
      12                 :            : 
      13                 :            : static const struct spdk_json_object_decoder nvmf_rpc_subsystem_tgt_opts_decoder[] = {
      14                 :            :         {"max_subsystems", 0, spdk_json_decode_uint32, true}
      15                 :            : };
      16                 :            : 
      17                 :            : static void
      18                 :         20 : rpc_nvmf_set_max_subsystems(struct spdk_jsonrpc_request *request,
      19                 :            :                             const struct spdk_json_val *params)
      20                 :            : {
      21                 :         20 :         uint32_t max_subsystems = 0;
      22                 :            : 
      23         [ -  + ]:         20 :         if (g_spdk_nvmf_tgt_max_subsystems != 0) {
      24                 :          0 :                 SPDK_ERRLOG("this RPC must not be called more than once.\n");
      25                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
      26                 :            :                                                  "Must not call more than once");
      27                 :          0 :                 return;
      28                 :            :         }
      29                 :            : 
      30         [ +  - ]:         20 :         if (params != NULL) {
      31         [ -  + ]:         20 :                 if (spdk_json_decode_object(params, nvmf_rpc_subsystem_tgt_opts_decoder,
      32                 :            :                                             SPDK_COUNTOF(nvmf_rpc_subsystem_tgt_opts_decoder), &max_subsystems)) {
      33                 :          0 :                         SPDK_ERRLOG("spdk_json_decode_object() failed\n");
      34                 :          0 :                         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
      35                 :            :                                                          "Invalid parameters");
      36                 :          0 :                         return;
      37                 :            :                 }
      38                 :            :         }
      39                 :            : 
      40                 :         20 :         g_spdk_nvmf_tgt_max_subsystems = max_subsystems;
      41                 :            : 
      42                 :         20 :         spdk_jsonrpc_send_bool_response(request, true);
      43                 :            : }
      44                 :        774 : SPDK_RPC_REGISTER("nvmf_set_max_subsystems", rpc_nvmf_set_max_subsystems,
      45                 :            :                   SPDK_RPC_STARTUP)
      46                 :            : 
      47                 :            : static const struct spdk_json_object_decoder admin_passthru_decoder[] = {
      48                 :            :         {"identify_ctrlr", offsetof(struct spdk_nvmf_admin_passthru_conf, identify_ctrlr), spdk_json_decode_bool}
      49                 :            : };
      50                 :            : 
      51                 :            : static int
      52                 :         22 : decode_admin_passthru(const struct spdk_json_val *val, void *out)
      53                 :            : {
      54                 :         22 :         struct spdk_nvmf_admin_passthru_conf *req = (struct spdk_nvmf_admin_passthru_conf *)out;
      55                 :            : 
      56         [ -  + ]:         22 :         if (spdk_json_decode_object(val, admin_passthru_decoder,
      57                 :            :                                     SPDK_COUNTOF(admin_passthru_decoder),
      58                 :            :                                     req)) {
      59                 :          0 :                 SPDK_ERRLOG("spdk_json_decode_object failed\n");
      60                 :          0 :                 return -1;
      61                 :            :         }
      62                 :            : 
      63                 :         22 :         return 0;
      64                 :            : }
      65                 :            : 
      66                 :            : static int
      67                 :         21 : decode_discovery_filter(const struct spdk_json_val *val, void *out)
      68                 :            : {
      69                 :         21 :         enum spdk_nvmf_tgt_discovery_filter *_filter = (enum spdk_nvmf_tgt_discovery_filter *)out;
      70                 :         21 :         enum spdk_nvmf_tgt_discovery_filter filter = SPDK_NVMF_TGT_DISCOVERY_MATCH_ANY;
      71                 :         21 :         char *tokens = spdk_json_strdup(val);
      72                 :            :         char *tok;
      73                 :         21 :         int rc = -EINVAL;
      74                 :         21 :         bool all_specified = false;
      75                 :            : 
      76         [ -  + ]:         21 :         if (!tokens) {
      77                 :          0 :                 return -ENOMEM;
      78                 :            :         }
      79                 :            : 
      80                 :         21 :         tok = strtok(tokens, ",");
      81         [ +  + ]:         42 :         while (tok) {
      82   [ +  +  +  + ]:         21 :                 if (strncmp(tok, "match_any", 9) == 0) {
      83         [ -  + ]:         20 :                         if (filter != SPDK_NVMF_TGT_DISCOVERY_MATCH_ANY) {
      84                 :          0 :                                 goto out;
      85                 :            :                         }
      86                 :         20 :                         filter = SPDK_NVMF_TGT_DISCOVERY_MATCH_ANY;
      87                 :         20 :                         all_specified = true;
      88                 :            :                 } else {
      89         [ -  + ]:          1 :                         if (all_specified) {
      90                 :          0 :                                 goto out;
      91                 :            :                         }
      92   [ -  +  -  + ]:          1 :                         if (strncmp(tok, "transport", 9) == 0) {
      93                 :          0 :                                 filter |= SPDK_NVMF_TGT_DISCOVERY_MATCH_TRANSPORT_TYPE;
      94   [ -  +  +  - ]:          1 :                         } else if (strncmp(tok, "address", 7) == 0) {
      95                 :          1 :                                 filter |= SPDK_NVMF_TGT_DISCOVERY_MATCH_TRANSPORT_ADDRESS;
      96   [ #  #  #  # ]:          0 :                         } else if (strncmp(tok, "svcid", 5) == 0) {
      97                 :          0 :                                 filter |= SPDK_NVMF_TGT_DISCOVERY_MATCH_TRANSPORT_SVCID;
      98                 :            :                         } else {
      99                 :          0 :                                 SPDK_ERRLOG("Invalid value %s\n", tok);
     100                 :          0 :                                 goto out;
     101                 :            :                         }
     102                 :            :                 }
     103                 :            : 
     104                 :         21 :                 tok = strtok(NULL, ",");
     105                 :            :         }
     106                 :            : 
     107                 :         21 :         rc = 0;
     108                 :         21 :         *_filter = filter;
     109                 :            : 
     110                 :         21 : out:
     111                 :         21 :         free(tokens);
     112                 :            : 
     113                 :         21 :         return rc;
     114                 :            : }
     115                 :            : 
     116                 :            : static int
     117                 :          0 : nvmf_is_subset_of_env_core_mask(const struct spdk_cpuset *set)
     118                 :            : {
     119                 :          0 :         uint32_t i, tmp_counter = 0;
     120                 :            : 
     121         [ #  # ]:          0 :         SPDK_ENV_FOREACH_CORE(i) {
     122         [ #  # ]:          0 :                 if (spdk_cpuset_get_cpu(set, i)) {
     123                 :          0 :                         ++tmp_counter;
     124                 :            :                 }
     125                 :            :         }
     126                 :          0 :         return spdk_cpuset_count(set) - tmp_counter;
     127                 :            : }
     128                 :            : 
     129                 :            : static int
     130                 :          0 : nvmf_decode_poll_groups_mask(const struct spdk_json_val *val, void *out)
     131                 :            : {
     132                 :          0 :         char *mask = spdk_json_strdup(val);
     133                 :          0 :         int ret = -1;
     134                 :            : 
     135         [ #  # ]:          0 :         if (mask == NULL) {
     136                 :          0 :                 return -1;
     137                 :            :         }
     138                 :            : 
     139         [ #  # ]:          0 :         if (!(g_poll_groups_mask = spdk_cpuset_alloc())) {
     140                 :          0 :                 SPDK_ERRLOG("Unable to allocate a poll groups mask object in nvmf_decode_poll_groups_mask.\n");
     141                 :          0 :                 free(mask);
     142                 :          0 :                 return -1;
     143                 :            :         }
     144                 :            : 
     145                 :          0 :         ret = spdk_cpuset_parse(g_poll_groups_mask, mask);
     146                 :          0 :         free(mask);
     147         [ #  # ]:          0 :         if (ret == 0) {
     148         [ #  # ]:          0 :                 if (nvmf_is_subset_of_env_core_mask(g_poll_groups_mask) == 0) {
     149                 :          0 :                         return 0;
     150                 :            :                 } else {
     151                 :          0 :                         SPDK_ERRLOG("Poll groups cpumask 0x%s is out of range\n", spdk_cpuset_fmt(g_poll_groups_mask));
     152                 :            :                 }
     153                 :            :         } else {
     154                 :          0 :                 SPDK_ERRLOG("Invalid cpumask\n");
     155                 :            :         }
     156                 :            : 
     157                 :          0 :         spdk_cpuset_free(g_poll_groups_mask);
     158                 :          0 :         g_poll_groups_mask = NULL;
     159                 :          0 :         return -1;
     160                 :            : }
     161                 :            : 
     162                 :            : static const struct spdk_json_object_decoder nvmf_rpc_subsystem_tgt_conf_decoder[] = {
     163                 :            :         {"admin_cmd_passthru", offsetof(struct spdk_nvmf_tgt_conf, admin_passthru), decode_admin_passthru, true},
     164                 :            :         {"poll_groups_mask", 0, nvmf_decode_poll_groups_mask, true},
     165                 :            :         {"discovery_filter", offsetof(struct spdk_nvmf_tgt_conf, discovery_filter), decode_discovery_filter, true}
     166                 :            : };
     167                 :            : 
     168                 :            : static void
     169                 :         23 : rpc_nvmf_set_config(struct spdk_jsonrpc_request *request,
     170                 :            :                     const struct spdk_json_val *params)
     171                 :            : {
     172                 :          7 :         struct spdk_nvmf_tgt_conf conf;
     173                 :            : 
     174                 :         23 :         memcpy(&conf, &g_spdk_nvmf_tgt_conf, sizeof(conf));
     175                 :            : 
     176         [ +  - ]:         23 :         if (params != NULL) {
     177         [ -  + ]:         23 :                 if (spdk_json_decode_object(params, nvmf_rpc_subsystem_tgt_conf_decoder,
     178                 :            :                                             SPDK_COUNTOF(nvmf_rpc_subsystem_tgt_conf_decoder), &conf)) {
     179                 :          0 :                         SPDK_ERRLOG("spdk_json_decode_object() failed\n");
     180                 :          0 :                         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
     181                 :            :                                                          "Invalid parameters");
     182                 :          0 :                         return;
     183                 :            :                 }
     184                 :            :         }
     185                 :            : 
     186                 :         23 :         memcpy(&g_spdk_nvmf_tgt_conf, &conf, sizeof(conf));
     187                 :            : 
     188                 :         23 :         spdk_jsonrpc_send_bool_response(request, true);
     189                 :            : }
     190                 :        774 : SPDK_RPC_REGISTER("nvmf_set_config", rpc_nvmf_set_config, SPDK_RPC_STARTUP)
     191                 :            : 
     192                 :            : struct nvmf_rpc_set_crdt {
     193                 :            :         uint16_t crdt1;
     194                 :            :         uint16_t crdt2;
     195                 :            :         uint16_t crdt3;
     196                 :            : };
     197                 :            : 
     198                 :            : static const struct spdk_json_object_decoder rpc_set_crdt_opts_decoders[] = {
     199                 :            :         {"crdt1", offsetof(struct nvmf_rpc_set_crdt, crdt1), spdk_json_decode_uint16, true},
     200                 :            :         {"crdt2", offsetof(struct nvmf_rpc_set_crdt, crdt2), spdk_json_decode_uint16, true},
     201                 :            :         {"crdt3", offsetof(struct nvmf_rpc_set_crdt, crdt3), spdk_json_decode_uint16, true},
     202                 :            : };
     203                 :            : 
     204                 :            : static void
     205                 :         20 : rpc_nvmf_set_crdt(struct spdk_jsonrpc_request *request,
     206                 :            :                   const struct spdk_json_val *params)
     207                 :            : {
     208                 :          7 :         struct nvmf_rpc_set_crdt rpc_set_crdt;
     209                 :            : 
     210                 :         20 :         rpc_set_crdt.crdt1 = 0;
     211                 :         20 :         rpc_set_crdt.crdt2 = 0;
     212                 :         20 :         rpc_set_crdt.crdt3 = 0;
     213                 :            : 
     214         [ +  - ]:         20 :         if (params != NULL) {
     215         [ -  + ]:         20 :                 if (spdk_json_decode_object(params, rpc_set_crdt_opts_decoders,
     216                 :            :                                             SPDK_COUNTOF(rpc_set_crdt_opts_decoders), &rpc_set_crdt)) {
     217                 :          0 :                         SPDK_ERRLOG("spdk_json_decode_object() failed\n");
     218                 :          0 :                         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
     219                 :            :                                                          "Invalid parameters");
     220                 :          0 :                         return;
     221                 :            :                 }
     222                 :            :         }
     223                 :            : 
     224                 :         20 :         g_spdk_nvmf_tgt_crdt[0] = rpc_set_crdt.crdt1;
     225                 :         20 :         g_spdk_nvmf_tgt_crdt[1] = rpc_set_crdt.crdt2;
     226                 :         20 :         g_spdk_nvmf_tgt_crdt[2] = rpc_set_crdt.crdt3;
     227                 :            : 
     228                 :         20 :         spdk_jsonrpc_send_bool_response(request, true);
     229                 :            : }
     230                 :        774 : SPDK_RPC_REGISTER("nvmf_set_crdt", rpc_nvmf_set_crdt, SPDK_RPC_STARTUP)

Generated by: LCOV version 1.14