LCOV - code coverage report
Current view: top level - spdk/lib/vhost - vhost_rpc.c (source / functions) Hit Total Coverage
Test: Combined Lines: 219 277 79.1 %
Date: 2024-07-15 11:06:12 Functions: 31 32 96.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 43 98 43.9 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2017 Intel Corporation. All rights reserved.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/stdinc.h"
       7                 :            : 
       8                 :            : #include "spdk/log.h"
       9                 :            : #include "spdk/rpc.h"
      10                 :            : #include "spdk/util.h"
      11                 :            : #include "spdk/string.h"
      12                 :            : #include "spdk/env.h"
      13                 :            : #include "spdk/scsi.h"
      14                 :            : #include "spdk/vhost.h"
      15                 :            : #include "vhost_internal.h"
      16                 :            : #include "spdk/bdev.h"
      17                 :            : 
      18                 :            : struct rpc_vhost_scsi_ctrlr {
      19                 :            :         char *ctrlr;
      20                 :            :         char *cpumask;
      21                 :            :         bool delay;
      22                 :            : };
      23                 :            : 
      24                 :            : static void
      25                 :         24 : free_rpc_vhost_scsi_ctrlr(struct rpc_vhost_scsi_ctrlr *req)
      26                 :            : {
      27                 :         24 :         free(req->ctrlr);
      28                 :         24 :         free(req->cpumask);
      29                 :         24 : }
      30                 :            : 
      31                 :            : static const struct spdk_json_object_decoder rpc_vhost_create_scsi_ctrlr[] = {
      32                 :            :         {"ctrlr", offsetof(struct rpc_vhost_scsi_ctrlr, ctrlr), spdk_json_decode_string },
      33                 :            :         {"cpumask", offsetof(struct rpc_vhost_scsi_ctrlr, cpumask), spdk_json_decode_string, true},
      34                 :            :         {"delay", offsetof(struct rpc_vhost_scsi_ctrlr, delay), spdk_json_decode_bool, true},
      35                 :            : };
      36                 :            : 
      37                 :            : static void
      38                 :         24 : rpc_vhost_create_scsi_controller(struct spdk_jsonrpc_request *request,
      39                 :            :                                  const struct spdk_json_val *params)
      40                 :            : {
      41                 :         24 :         struct rpc_vhost_scsi_ctrlr req = {0};
      42                 :            :         int rc;
      43                 :            : 
      44         [ -  + ]:         24 :         if (spdk_json_decode_object(params, rpc_vhost_create_scsi_ctrlr,
      45                 :            :                                     SPDK_COUNTOF(rpc_vhost_create_scsi_ctrlr),
      46                 :            :                                     &req)) {
      47   [ #  #  #  # ]:          0 :                 SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
      48                 :          0 :                 rc = -EINVAL;
      49                 :          0 :                 goto invalid;
      50                 :            :         }
      51                 :            : 
      52   [ -  +  +  + ]:         24 :         if (req.delay) {
      53                 :          7 :                 rc = spdk_vhost_scsi_dev_construct_no_start(req.ctrlr, req.cpumask);
      54                 :            :         } else {
      55                 :         17 :                 rc = spdk_vhost_scsi_dev_construct(req.ctrlr, req.cpumask);
      56                 :            :         }
      57         [ +  + ]:         24 :         if (rc < 0) {
      58                 :          3 :                 goto invalid;
      59                 :            :         }
      60                 :            : 
      61                 :         21 :         free_rpc_vhost_scsi_ctrlr(&req);
      62                 :            : 
      63                 :         21 :         spdk_jsonrpc_send_bool_response(request, true);
      64                 :         21 :         return;
      65                 :            : 
      66                 :          3 : invalid:
      67                 :          3 :         free_rpc_vhost_scsi_ctrlr(&req);
      68                 :          3 :         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
      69                 :            :                                          spdk_strerror(-rc));
      70                 :            : }
      71                 :        689 : SPDK_RPC_REGISTER("vhost_create_scsi_controller", rpc_vhost_create_scsi_controller,
      72                 :            :                   SPDK_RPC_RUNTIME)
      73                 :            : 
      74                 :            : struct rpc_start_vhost_scsi_ctrlr {
      75                 :            :         char *ctrlr;
      76                 :            : };
      77                 :            : 
      78                 :            : static void
      79                 :          7 : free_rpc_start_vhost_scsi_ctrlr(struct rpc_start_vhost_scsi_ctrlr *req)
      80                 :            : {
      81                 :          7 :         free(req->ctrlr);
      82                 :          7 : }
      83                 :            : 
      84                 :            : static const struct spdk_json_object_decoder rpc_start_vhost_scsi_ctrlr_decoder[] = {
      85                 :            :         {"ctrlr", offsetof(struct rpc_start_vhost_scsi_ctrlr, ctrlr), spdk_json_decode_string },
      86                 :            : };
      87                 :            : 
      88                 :            : static void
      89                 :          7 : rpc_vhost_start_scsi_controller(struct spdk_jsonrpc_request *request,
      90                 :            :                                 const struct spdk_json_val *params)
      91                 :            : {
      92                 :          7 :         struct rpc_start_vhost_scsi_ctrlr req = {0};
      93                 :            :         int rc;
      94                 :            : 
      95         [ -  + ]:          7 :         if (spdk_json_decode_object(params, rpc_start_vhost_scsi_ctrlr_decoder,
      96                 :            :                                     SPDK_COUNTOF(rpc_start_vhost_scsi_ctrlr_decoder),
      97                 :            :                                     &req)) {
      98   [ #  #  #  # ]:          0 :                 SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
      99                 :          0 :                 rc = -EINVAL;
     100                 :          0 :                 goto invalid;
     101                 :            :         }
     102                 :            : 
     103                 :          7 :         rc = vhost_scsi_controller_start(req.ctrlr);
     104         [ -  + ]:          7 :         if (rc < 0) {
     105                 :          0 :                 goto invalid;
     106                 :            :         }
     107                 :            : 
     108                 :          7 :         free_rpc_start_vhost_scsi_ctrlr(&req);
     109                 :            : 
     110                 :          7 :         spdk_jsonrpc_send_bool_response(request, true);
     111                 :          7 :         return;
     112                 :            : 
     113                 :          0 : invalid:
     114                 :          0 :         free_rpc_start_vhost_scsi_ctrlr(&req);
     115                 :          0 :         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
     116                 :            :                                          spdk_strerror(-rc));
     117                 :            : }
     118                 :        689 : SPDK_RPC_REGISTER("vhost_start_scsi_controller", rpc_vhost_start_scsi_controller,
     119                 :            :                   SPDK_RPC_RUNTIME)
     120                 :            : 
     121                 :            : struct rpc_vhost_scsi_ctrlr_add_target {
     122                 :            :         char *ctrlr;
     123                 :            :         int32_t scsi_target_num;
     124                 :            :         char *bdev_name;
     125                 :            : };
     126                 :            : 
     127                 :            : static void
     128                 :         47 : free_rpc_vhost_scsi_ctrlr_add_target(struct rpc_vhost_scsi_ctrlr_add_target *req)
     129                 :            : {
     130                 :         47 :         free(req->ctrlr);
     131                 :         47 :         free(req->bdev_name);
     132                 :         47 : }
     133                 :            : 
     134                 :            : static const struct spdk_json_object_decoder rpc_vhost_scsi_ctrlr_add_target[] = {
     135                 :            :         {"ctrlr", offsetof(struct rpc_vhost_scsi_ctrlr_add_target, ctrlr), spdk_json_decode_string },
     136                 :            :         {"scsi_target_num", offsetof(struct rpc_vhost_scsi_ctrlr_add_target, scsi_target_num), spdk_json_decode_int32},
     137                 :            :         {"bdev_name", offsetof(struct rpc_vhost_scsi_ctrlr_add_target, bdev_name), spdk_json_decode_string },
     138                 :            : };
     139                 :            : 
     140                 :            : static void
     141                 :         47 : rpc_vhost_scsi_controller_add_target(struct spdk_jsonrpc_request *request,
     142                 :            :                                      const struct spdk_json_val *params)
     143                 :            : {
     144                 :         47 :         struct rpc_vhost_scsi_ctrlr_add_target req = {0};
     145                 :            :         struct spdk_json_write_ctx *w;
     146                 :            :         struct spdk_vhost_dev *vdev;
     147                 :            :         int rc;
     148                 :            : 
     149         [ -  + ]:         47 :         if (spdk_json_decode_object(params, rpc_vhost_scsi_ctrlr_add_target,
     150                 :            :                                     SPDK_COUNTOF(rpc_vhost_scsi_ctrlr_add_target),
     151                 :            :                                     &req)) {
     152   [ #  #  #  # ]:          0 :                 SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
     153                 :          0 :                 rc = -EINVAL;
     154                 :          0 :                 goto invalid;
     155                 :            :         }
     156                 :            : 
     157                 :         47 :         spdk_vhost_lock();
     158                 :         47 :         vdev = spdk_vhost_dev_find(req.ctrlr);
     159         [ +  + ]:         47 :         if (vdev == NULL) {
     160                 :          1 :                 spdk_vhost_unlock();
     161                 :          1 :                 rc = -ENODEV;
     162                 :          1 :                 goto invalid;
     163                 :            :         }
     164                 :            : 
     165                 :         46 :         rc = spdk_vhost_scsi_dev_add_tgt(vdev, req.scsi_target_num, req.bdev_name);
     166                 :         46 :         spdk_vhost_unlock();
     167         [ +  + ]:         46 :         if (rc < 0) {
     168                 :          4 :                 goto invalid;
     169                 :            :         }
     170                 :            : 
     171                 :         42 :         free_rpc_vhost_scsi_ctrlr_add_target(&req);
     172                 :            : 
     173                 :         42 :         w = spdk_jsonrpc_begin_result(request);
     174                 :         42 :         spdk_json_write_int32(w, rc);
     175                 :         42 :         spdk_jsonrpc_end_result(request, w);
     176                 :         42 :         return;
     177                 :            : 
     178                 :          5 : invalid:
     179                 :          5 :         free_rpc_vhost_scsi_ctrlr_add_target(&req);
     180                 :          5 :         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
     181                 :            :                                          spdk_strerror(-rc));
     182                 :            : }
     183                 :        689 : SPDK_RPC_REGISTER("vhost_scsi_controller_add_target", rpc_vhost_scsi_controller_add_target,
     184                 :            :                   SPDK_RPC_RUNTIME)
     185                 :            : 
     186                 :            : struct rpc_remove_vhost_scsi_ctrlr_target {
     187                 :            :         char *ctrlr;
     188                 :            :         uint32_t scsi_target_num;
     189                 :            : };
     190                 :            : 
     191                 :            : static void
     192                 :         32 : free_rpc_remove_vhost_scsi_ctrlr_target(struct rpc_remove_vhost_scsi_ctrlr_target *req)
     193                 :            : {
     194                 :         32 :         free(req->ctrlr);
     195                 :         32 : }
     196                 :            : 
     197                 :            : static const struct spdk_json_object_decoder rpc_vhost_remove_target[] = {
     198                 :            :         {"ctrlr", offsetof(struct rpc_remove_vhost_scsi_ctrlr_target, ctrlr), spdk_json_decode_string },
     199                 :            :         {"scsi_target_num", offsetof(struct rpc_remove_vhost_scsi_ctrlr_target, scsi_target_num), spdk_json_decode_uint32},
     200                 :            : };
     201                 :            : 
     202                 :            : static int
     203                 :         28 : rpc_vhost_scsi_controller_remove_target_finish_cb(struct spdk_vhost_dev *vdev, void *arg)
     204                 :            : {
     205                 :         28 :         struct spdk_jsonrpc_request *request = arg;
     206                 :            : 
     207                 :         28 :         spdk_jsonrpc_send_bool_response(request, true);
     208                 :         28 :         return 0;
     209                 :            : }
     210                 :            : 
     211                 :            : static void
     212                 :         32 : rpc_vhost_scsi_controller_remove_target(struct spdk_jsonrpc_request *request,
     213                 :            :                                         const struct spdk_json_val *params)
     214                 :            : {
     215                 :         32 :         struct rpc_remove_vhost_scsi_ctrlr_target req = {0};
     216                 :            :         struct spdk_vhost_dev *vdev;
     217                 :            :         int rc;
     218                 :            : 
     219         [ -  + ]:         32 :         if (spdk_json_decode_object(params, rpc_vhost_remove_target,
     220                 :            :                                     SPDK_COUNTOF(rpc_vhost_remove_target),
     221                 :            :                                     &req)) {
     222   [ #  #  #  # ]:          0 :                 SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
     223                 :          0 :                 rc = -EINVAL;
     224                 :          0 :                 goto invalid;
     225                 :            :         }
     226                 :            : 
     227                 :         32 :         spdk_vhost_lock();
     228                 :         32 :         vdev = spdk_vhost_dev_find(req.ctrlr);
     229         [ +  + ]:         32 :         if (vdev == NULL) {
     230                 :          1 :                 spdk_vhost_unlock();
     231                 :          1 :                 rc = -ENODEV;
     232                 :          1 :                 goto invalid;
     233                 :            :         }
     234                 :            : 
     235                 :         31 :         rc = spdk_vhost_scsi_dev_remove_tgt(vdev, req.scsi_target_num,
     236                 :            :                                             rpc_vhost_scsi_controller_remove_target_finish_cb,
     237                 :            :                                             request);
     238                 :         31 :         spdk_vhost_unlock();
     239         [ +  + ]:         31 :         if (rc < 0) {
     240                 :          3 :                 goto invalid;
     241                 :            :         }
     242                 :            : 
     243                 :         28 :         free_rpc_remove_vhost_scsi_ctrlr_target(&req);
     244                 :         28 :         return;
     245                 :            : 
     246                 :          4 : invalid:
     247                 :          4 :         free_rpc_remove_vhost_scsi_ctrlr_target(&req);
     248                 :          4 :         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
     249                 :            :                                          spdk_strerror(-rc));
     250                 :            : }
     251                 :            : 
     252                 :        689 : SPDK_RPC_REGISTER("vhost_scsi_controller_remove_target",
     253                 :            :                   rpc_vhost_scsi_controller_remove_target, SPDK_RPC_RUNTIME)
     254                 :            : 
     255                 :            : struct rpc_vhost_blk_ctrlr {
     256                 :            :         char *ctrlr;
     257                 :            :         char *dev_name;
     258                 :            :         char *cpumask;
     259                 :            :         char *transport;
     260                 :            : };
     261                 :            : 
     262                 :            : static const struct spdk_json_object_decoder rpc_construct_vhost_blk_ctrlr[] = {
     263                 :            :         {"ctrlr", offsetof(struct rpc_vhost_blk_ctrlr, ctrlr), spdk_json_decode_string },
     264                 :            :         {"dev_name", offsetof(struct rpc_vhost_blk_ctrlr, dev_name), spdk_json_decode_string },
     265                 :            :         {"cpumask", offsetof(struct rpc_vhost_blk_ctrlr, cpumask), spdk_json_decode_string, true},
     266                 :            :         {"transport", offsetof(struct rpc_vhost_blk_ctrlr, transport), spdk_json_decode_string, true},
     267                 :            : };
     268                 :            : 
     269                 :            : static void
     270                 :         29 : free_rpc_vhost_blk_ctrlr(struct rpc_vhost_blk_ctrlr *req)
     271                 :            : {
     272                 :         29 :         free(req->ctrlr);
     273                 :         29 :         free(req->dev_name);
     274                 :         29 :         free(req->cpumask);
     275                 :         29 :         free(req->transport);
     276                 :         29 : }
     277                 :            : 
     278                 :            : static void
     279                 :         29 : rpc_vhost_create_blk_controller(struct spdk_jsonrpc_request *request,
     280                 :            :                                 const struct spdk_json_val *params)
     281                 :            : {
     282                 :         29 :         struct rpc_vhost_blk_ctrlr req = {0};
     283                 :            :         int rc;
     284                 :            : 
     285         [ -  + ]:         29 :         if (spdk_json_decode_object_relaxed(params, rpc_construct_vhost_blk_ctrlr,
     286                 :            :                                             SPDK_COUNTOF(rpc_construct_vhost_blk_ctrlr),
     287                 :            :                                             &req)) {
     288   [ #  #  #  # ]:          0 :                 SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
     289                 :          0 :                 rc = -EINVAL;
     290                 :          0 :                 goto invalid;
     291                 :            :         }
     292                 :            : 
     293                 :         29 :         rc = spdk_vhost_blk_construct(req.ctrlr, req.cpumask, req.dev_name, req.transport, params);
     294         [ +  + ]:         29 :         if (rc < 0) {
     295                 :          5 :                 goto invalid;
     296                 :            :         }
     297                 :            : 
     298                 :         24 :         free_rpc_vhost_blk_ctrlr(&req);
     299                 :            : 
     300                 :         24 :         spdk_jsonrpc_send_bool_response(request, true);
     301                 :         24 :         return;
     302                 :            : 
     303                 :          5 : invalid:
     304                 :          5 :         free_rpc_vhost_blk_ctrlr(&req);
     305                 :          5 :         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
     306                 :            :                                          spdk_strerror(-rc));
     307                 :            : 
     308                 :            : }
     309                 :        689 : SPDK_RPC_REGISTER("vhost_create_blk_controller", rpc_vhost_create_blk_controller,
     310                 :            :                   SPDK_RPC_RUNTIME)
     311                 :            : 
     312                 :            : struct rpc_delete_vhost_ctrlr {
     313                 :            :         char *ctrlr;
     314                 :            : };
     315                 :            : 
     316                 :            : static const struct spdk_json_object_decoder rpc_delete_vhost_ctrlr_decoder[] = {
     317                 :            :         {"ctrlr", offsetof(struct rpc_delete_vhost_ctrlr, ctrlr), spdk_json_decode_string },
     318                 :            : };
     319                 :            : 
     320                 :            : static void
     321                 :         30 : free_rpc_delete_vhost_ctrlr(struct rpc_delete_vhost_ctrlr *req)
     322                 :            : {
     323                 :         30 :         free(req->ctrlr);
     324                 :         30 : }
     325                 :            : 
     326                 :            : static void
     327                 :         30 : rpc_vhost_delete_controller(struct spdk_jsonrpc_request *request,
     328                 :            :                             const struct spdk_json_val *params)
     329                 :            : {
     330                 :         30 :         struct rpc_delete_vhost_ctrlr req = {0};
     331                 :            :         struct spdk_vhost_dev *vdev;
     332                 :            :         int rc;
     333                 :            : 
     334         [ -  + ]:         30 :         if (spdk_json_decode_object(params, rpc_delete_vhost_ctrlr_decoder,
     335                 :            :                                     SPDK_COUNTOF(rpc_delete_vhost_ctrlr_decoder), &req)) {
     336   [ #  #  #  # ]:          0 :                 SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
     337                 :          0 :                 rc = -EINVAL;
     338                 :          0 :                 goto invalid;
     339                 :            :         }
     340                 :            : 
     341                 :         30 :         spdk_vhost_lock();
     342                 :         30 :         vdev = spdk_vhost_dev_find(req.ctrlr);
     343         [ +  + ]:         30 :         if (vdev == NULL) {
     344                 :          2 :                 spdk_vhost_unlock();
     345                 :          2 :                 rc = -ENODEV;
     346                 :          2 :                 goto invalid;
     347                 :            :         }
     348                 :         28 :         spdk_vhost_unlock();
     349                 :            : 
     350                 :         28 :         rc = spdk_vhost_dev_remove(vdev);
     351         [ -  + ]:         28 :         if (rc < 0) {
     352                 :          0 :                 goto invalid;
     353                 :            :         }
     354                 :            : 
     355                 :         28 :         free_rpc_delete_vhost_ctrlr(&req);
     356                 :            : 
     357                 :         28 :         spdk_jsonrpc_send_bool_response(request, true);
     358                 :         28 :         return;
     359                 :            : 
     360                 :          2 : invalid:
     361                 :          2 :         free_rpc_delete_vhost_ctrlr(&req);
     362                 :          2 :         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
     363                 :            :                                          spdk_strerror(-rc));
     364                 :            : 
     365                 :            : }
     366                 :        689 : SPDK_RPC_REGISTER("vhost_delete_controller", rpc_vhost_delete_controller, SPDK_RPC_RUNTIME)
     367                 :            : 
     368                 :            : struct rpc_get_vhost_ctrlrs {
     369                 :            :         char *name;
     370                 :            : };
     371                 :            : 
     372                 :            : static void
     373                 :        824 : _rpc_get_vhost_controller(struct spdk_json_write_ctx *w, struct spdk_vhost_dev *vdev)
     374                 :            : {
     375                 :        763 :         uint32_t delay_base_us, iops_threshold;
     376                 :            : 
     377                 :        824 :         spdk_vhost_get_coalescing(vdev, &delay_base_us, &iops_threshold);
     378                 :            : 
     379                 :        824 :         spdk_json_write_object_begin(w);
     380                 :            : 
     381                 :        824 :         spdk_json_write_named_string(w, "ctrlr", spdk_vhost_dev_get_name(vdev));
     382                 :        824 :         spdk_json_write_named_string_fmt(w, "cpumask", "0x%s",
     383                 :            :                                          spdk_cpuset_fmt(spdk_thread_get_cpumask(vdev->thread)));
     384                 :        824 :         spdk_json_write_named_uint32(w, "delay_base_us", delay_base_us);
     385                 :        824 :         spdk_json_write_named_uint32(w, "iops_threshold", iops_threshold);
     386                 :        824 :         spdk_json_write_named_string(w, "socket", vdev->path);
     387                 :        824 :         spdk_json_write_named_array_begin(w, "sessions");
     388                 :        824 :         vhost_session_info_json(vdev, w);
     389                 :        824 :         spdk_json_write_array_end(w);
     390                 :            : 
     391                 :        824 :         spdk_json_write_named_object_begin(w, "backend_specific");
     392                 :        824 :         vhost_dump_info_json(vdev, w);
     393                 :        824 :         spdk_json_write_object_end(w);
     394                 :            : 
     395                 :        824 :         spdk_json_write_object_end(w);
     396                 :        824 : }
     397                 :            : 
     398                 :            : static const struct spdk_json_object_decoder rpc_get_vhost_ctrlrs_decoders[] = {
     399                 :            :         {"name", offsetof(struct rpc_get_vhost_ctrlrs, name), spdk_json_decode_string, true},
     400                 :            : };
     401                 :            : 
     402                 :            : static void
     403                 :        690 : free_rpc_get_vhost_ctrlrs(struct rpc_get_vhost_ctrlrs *req)
     404                 :            : {
     405                 :        690 :         free(req->name);
     406                 :        690 : }
     407                 :            : 
     408                 :            : static void
     409                 :        690 : rpc_vhost_get_controllers(struct spdk_jsonrpc_request *request,
     410                 :            :                           const struct spdk_json_val *params)
     411                 :            : {
     412                 :        690 :         struct rpc_get_vhost_ctrlrs req = {0};
     413                 :            :         struct spdk_json_write_ctx *w;
     414                 :            :         struct spdk_vhost_dev *vdev;
     415                 :            :         int rc;
     416                 :            : 
     417   [ +  +  -  + ]:        690 :         if (params && spdk_json_decode_object(params, rpc_get_vhost_ctrlrs_decoders,
     418                 :            :                                               SPDK_COUNTOF(rpc_get_vhost_ctrlrs_decoders), &req)) {
     419                 :          0 :                 SPDK_ERRLOG("spdk_json_decode_object failed\n");
     420                 :          0 :                 rc = -EINVAL;
     421                 :          0 :                 goto invalid;
     422                 :            :         }
     423                 :            : 
     424                 :        690 :         spdk_vhost_lock();
     425         [ +  + ]:        690 :         if (req.name != NULL) {
     426                 :         11 :                 vdev = spdk_vhost_dev_find(req.name);
     427         [ +  + ]:         11 :                 if (vdev == NULL) {
     428                 :          3 :                         spdk_vhost_unlock();
     429                 :          3 :                         rc = -ENODEV;
     430                 :          3 :                         goto invalid;
     431                 :            :                 }
     432                 :            : 
     433                 :          8 :                 free_rpc_get_vhost_ctrlrs(&req);
     434                 :            : 
     435                 :          8 :                 w = spdk_jsonrpc_begin_result(request);
     436                 :          8 :                 spdk_json_write_array_begin(w);
     437                 :            : 
     438                 :          8 :                 _rpc_get_vhost_controller(w, vdev);
     439                 :          8 :                 spdk_vhost_unlock();
     440                 :            : 
     441                 :          8 :                 spdk_json_write_array_end(w);
     442                 :          8 :                 spdk_jsonrpc_end_result(request, w);
     443                 :        234 :                 return;
     444                 :            :         }
     445                 :            : 
     446                 :        679 :         free_rpc_get_vhost_ctrlrs(&req);
     447                 :            : 
     448                 :        679 :         w = spdk_jsonrpc_begin_result(request);
     449                 :        679 :         spdk_json_write_array_begin(w);
     450                 :            : 
     451                 :        679 :         vdev = spdk_vhost_dev_next(NULL);
     452         [ +  + ]:       1495 :         while (vdev != NULL) {
     453                 :        816 :                 _rpc_get_vhost_controller(w, vdev);
     454                 :        816 :                 vdev = spdk_vhost_dev_next(vdev);
     455                 :            :         }
     456                 :        679 :         spdk_vhost_unlock();
     457                 :            : 
     458                 :        679 :         spdk_json_write_array_end(w);
     459                 :        679 :         spdk_jsonrpc_end_result(request, w);
     460                 :        679 :         return;
     461                 :            : 
     462                 :          3 : invalid:
     463                 :          3 :         free_rpc_get_vhost_ctrlrs(&req);
     464                 :          3 :         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
     465                 :            :                                          spdk_strerror(-rc));
     466                 :            : }
     467                 :        689 : SPDK_RPC_REGISTER("vhost_get_controllers", rpc_vhost_get_controllers, SPDK_RPC_RUNTIME)
     468                 :            : 
     469                 :            : 
     470                 :            : struct rpc_vhost_ctrlr_coalescing {
     471                 :            :         char *ctrlr;
     472                 :            :         uint32_t delay_base_us;
     473                 :            :         uint32_t iops_threshold;
     474                 :            : };
     475                 :            : 
     476                 :            : static const struct spdk_json_object_decoder rpc_set_vhost_ctrlr_coalescing[] = {
     477                 :            :         {"ctrlr", offsetof(struct rpc_vhost_ctrlr_coalescing, ctrlr), spdk_json_decode_string },
     478                 :            :         {"delay_base_us", offsetof(struct rpc_vhost_ctrlr_coalescing, delay_base_us), spdk_json_decode_uint32},
     479                 :            :         {"iops_threshold", offsetof(struct rpc_vhost_ctrlr_coalescing, iops_threshold), spdk_json_decode_uint32},
     480                 :            : };
     481                 :            : 
     482                 :            : static void
     483                 :          9 : free_rpc_set_vhost_controllers_event_coalescing(struct rpc_vhost_ctrlr_coalescing *req)
     484                 :            : {
     485                 :          9 :         free(req->ctrlr);
     486                 :          9 : }
     487                 :            : 
     488                 :            : static void
     489                 :          9 : rpc_vhost_controller_set_coalescing(struct spdk_jsonrpc_request *request,
     490                 :            :                                     const struct spdk_json_val *params)
     491                 :            : {
     492                 :          9 :         struct rpc_vhost_ctrlr_coalescing req = {0};
     493                 :            :         struct spdk_vhost_dev *vdev;
     494                 :            :         int rc;
     495                 :            : 
     496         [ +  + ]:          9 :         if (spdk_json_decode_object(params, rpc_set_vhost_ctrlr_coalescing,
     497                 :            :                                     SPDK_COUNTOF(rpc_set_vhost_ctrlr_coalescing), &req)) {
     498   [ -  +  -  + ]:          1 :                 SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
     499                 :          1 :                 rc = -EINVAL;
     500                 :          1 :                 goto invalid;
     501                 :            :         }
     502                 :            : 
     503                 :          8 :         spdk_vhost_lock();
     504                 :          8 :         vdev = spdk_vhost_dev_find(req.ctrlr);
     505         [ +  + ]:          8 :         if (vdev == NULL) {
     506                 :          1 :                 spdk_vhost_unlock();
     507                 :          1 :                 rc = -ENODEV;
     508                 :          1 :                 goto invalid;
     509                 :            :         }
     510                 :            : 
     511                 :          7 :         rc = spdk_vhost_set_coalescing(vdev, req.delay_base_us, req.iops_threshold);
     512                 :          7 :         spdk_vhost_unlock();
     513         [ -  + ]:          7 :         if (rc) {
     514                 :          0 :                 goto invalid;
     515                 :            :         }
     516                 :            : 
     517                 :          7 :         free_rpc_set_vhost_controllers_event_coalescing(&req);
     518                 :            : 
     519                 :          7 :         spdk_jsonrpc_send_bool_response(request, true);
     520                 :          7 :         return;
     521                 :            : 
     522                 :          2 : invalid:
     523                 :          2 :         free_rpc_set_vhost_controllers_event_coalescing(&req);
     524                 :          2 :         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
     525                 :            :                                          spdk_strerror(-rc));
     526                 :            : }
     527                 :        689 : SPDK_RPC_REGISTER("vhost_controller_set_coalescing", rpc_vhost_controller_set_coalescing,
     528                 :            :                   SPDK_RPC_RUNTIME)
     529                 :            : 
     530                 :            : struct rpc_get_transport {
     531                 :            :         char *name;
     532                 :            : };
     533                 :            : 
     534                 :            : static const struct spdk_json_object_decoder rpc_get_transport_decoders[] = {
     535                 :            :         {"name", offsetof(struct rpc_get_transport, name), spdk_json_decode_string, true},
     536                 :            : };
     537                 :            : 
     538                 :            : static void
     539                 :          0 : rpc_virtio_blk_get_transports(struct spdk_jsonrpc_request *request,
     540                 :            :                               const struct spdk_json_val *params)
     541                 :            : {
     542                 :          0 :         struct rpc_get_transport req = { 0 };
     543                 :            :         struct spdk_json_write_ctx *w;
     544                 :          0 :         struct spdk_virtio_blk_transport *transport = NULL;
     545                 :            : 
     546         [ #  # ]:          0 :         if (params) {
     547         [ #  # ]:          0 :                 if (spdk_json_decode_object(params, rpc_get_transport_decoders,
     548                 :            :                                             SPDK_COUNTOF(rpc_get_transport_decoders),
     549                 :            :                                             &req)) {
     550                 :          0 :                         SPDK_ERRLOG("spdk_json_decode_object failed\n");
     551                 :          0 :                         spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
     552                 :          0 :                         return;
     553                 :            :                 }
     554                 :            :         }
     555                 :            : 
     556         [ #  # ]:          0 :         if (req.name) {
     557                 :          0 :                 transport = virtio_blk_tgt_get_transport(req.name);
     558         [ #  # ]:          0 :                 if (transport == NULL) {
     559                 :          0 :                         SPDK_ERRLOG("transport '%s' does not exist\n", req.name);
     560                 :          0 :                         spdk_jsonrpc_send_error_response(request, -ENODEV, spdk_strerror(ENODEV));
     561                 :          0 :                         free(req.name);
     562                 :          0 :                         return;
     563                 :            :                 }
     564                 :            :         }
     565                 :            : 
     566                 :          0 :         w = spdk_jsonrpc_begin_result(request);
     567                 :          0 :         spdk_json_write_array_begin(w);
     568                 :            : 
     569         [ #  # ]:          0 :         if (transport) {
     570                 :          0 :                 virtio_blk_transport_dump_opts(transport, w);
     571                 :            :         } else {
     572         [ #  # ]:          0 :                 for (transport = virtio_blk_transport_get_first(); transport != NULL;
     573                 :          0 :                      transport = virtio_blk_transport_get_next(transport)) {
     574                 :          0 :                         virtio_blk_transport_dump_opts(transport, w);
     575                 :            :                 }
     576                 :            :         }
     577                 :            : 
     578                 :          0 :         spdk_json_write_array_end(w);
     579                 :          0 :         spdk_jsonrpc_end_result(request, w);
     580                 :          0 :         free(req.name);
     581                 :            : }
     582                 :        689 : SPDK_RPC_REGISTER("virtio_blk_get_transports", rpc_virtio_blk_get_transports, SPDK_RPC_RUNTIME)
     583                 :            : 
     584                 :            : struct rpc_virtio_blk_create_transport {
     585                 :            :         char *name;
     586                 :            : };
     587                 :            : 
     588                 :            : static const struct spdk_json_object_decoder rpc_create_virtio_blk_transport[] = {
     589                 :            :         {"name", offsetof(struct rpc_virtio_blk_create_transport, name), spdk_json_decode_string},
     590                 :            : };
     591                 :            : 
     592                 :            : static void
     593                 :          1 : free_rpc_virtio_blk_create_transport(struct rpc_virtio_blk_create_transport *req)
     594                 :            : {
     595                 :          1 :         free(req->name);
     596                 :          1 : }
     597                 :            : 
     598                 :            : static void
     599                 :          1 : rpc_virtio_blk_create_transport(struct spdk_jsonrpc_request *request,
     600                 :            :                                 const struct spdk_json_val *params)
     601                 :            : {
     602                 :          1 :         struct rpc_virtio_blk_create_transport req = {0};
     603                 :            :         int rc;
     604                 :            : 
     605         [ -  + ]:          1 :         if (spdk_json_decode_object_relaxed(params, rpc_create_virtio_blk_transport,
     606                 :            :                                             SPDK_COUNTOF(rpc_create_virtio_blk_transport), &req)) {
     607   [ #  #  #  # ]:          0 :                 SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
     608                 :          0 :                 rc = -EINVAL;
     609                 :          0 :                 goto invalid;
     610                 :            :         }
     611                 :            : 
     612                 :          1 :         spdk_vhost_lock();
     613                 :          1 :         rc = virtio_blk_transport_create(req.name, params);
     614                 :          1 :         spdk_vhost_unlock();
     615         [ +  - ]:          1 :         if (rc != 0) {
     616                 :          1 :                 goto invalid;
     617                 :            :         }
     618                 :            : 
     619                 :          0 :         free_rpc_virtio_blk_create_transport(&req);
     620                 :          0 :         spdk_jsonrpc_send_bool_response(request, true);
     621                 :          0 :         return;
     622                 :            : 
     623                 :          1 : invalid:
     624                 :          1 :         free_rpc_virtio_blk_create_transport(&req);
     625                 :          1 :         spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
     626                 :            : }
     627                 :        689 : SPDK_RPC_REGISTER("virtio_blk_create_transport", rpc_virtio_blk_create_transport,
     628                 :            :                   SPDK_RPC_RUNTIME)
     629                 :            : 
     630                 :        689 : SPDK_LOG_REGISTER_COMPONENT(vhost_rpc)

Generated by: LCOV version 1.14