LCOV - code coverage report
Current view: top level - spdk/module/bdev/uring - bdev_uring_rpc.c (source / functions) Hit Total Coverage
Test: Combined Lines: 38 60 63.3 %
Date: 2024-07-10 23:02:33 Functions: 8 9 88.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 12 33.3 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2019 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "bdev_uring.h"
       7                 :            : #include "spdk/rpc.h"
       8                 :            : #include "spdk/util.h"
       9                 :            : #include "spdk/string.h"
      10                 :            : #include "spdk/log.h"
      11                 :            : 
      12                 :            : /* Structure to hold the parameters for this RPC method. */
      13                 :            : struct rpc_create_uring {
      14                 :            :         char *name;
      15                 :            :         char *filename;
      16                 :            :         uint32_t block_size;
      17                 :            :         struct spdk_uuid uuid;
      18                 :            : };
      19                 :            : 
      20                 :            : /* Free the allocated memory resource after the RPC handling. */
      21                 :            : static void
      22                 :         10 : free_rpc_create_uring(struct rpc_create_uring *r)
      23                 :            : {
      24                 :         10 :         free(r->name);
      25                 :         10 :         free(r->filename);
      26                 :         10 : }
      27                 :            : 
      28                 :            : /* Structure to decode the input parameters for this RPC method. */
      29                 :            : static const struct spdk_json_object_decoder rpc_create_uring_decoders[] = {
      30                 :            :         {"name", offsetof(struct rpc_create_uring, name), spdk_json_decode_string},
      31                 :            :         {"filename", offsetof(struct rpc_create_uring, filename), spdk_json_decode_string},
      32                 :            :         {"block_size", offsetof(struct rpc_create_uring, block_size), spdk_json_decode_uint32, true},
      33                 :            :         {"uuid", offsetof(struct rpc_create_uring, uuid), spdk_json_decode_uuid, true},
      34                 :            : };
      35                 :            : 
      36                 :            : /* Decode the parameters for this RPC method and properly create the uring
      37                 :            :  * device. Error status returned in the failed cases.
      38                 :            :  */
      39                 :            : static void
      40                 :         10 : rpc_bdev_uring_create(struct spdk_jsonrpc_request *request,
      41                 :            :                       const struct spdk_json_val *params)
      42                 :            : {
      43                 :         10 :         struct rpc_create_uring req = {};
      44                 :            :         struct spdk_json_write_ctx *w;
      45                 :            :         struct spdk_bdev *bdev;
      46                 :         10 :         struct bdev_uring_opts opts = {};
      47                 :            : 
      48         [ -  + ]:         10 :         if (spdk_json_decode_object(params, rpc_create_uring_decoders,
      49                 :            :                                     SPDK_COUNTOF(rpc_create_uring_decoders),
      50                 :            :                                     &req)) {
      51                 :          0 :                 SPDK_ERRLOG("spdk_json_decode_object failed\n");
      52                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
      53                 :            :                                                  "spdk_json_decode_object failed");
      54                 :          0 :                 goto cleanup;
      55                 :            :         }
      56                 :            : 
      57                 :         10 :         opts.block_size = req.block_size;
      58                 :         10 :         opts.filename = req.filename;
      59                 :         10 :         opts.name = req.name;
      60                 :         10 :         opts.uuid = req.uuid;
      61                 :            : 
      62                 :         10 :         bdev = create_uring_bdev(&opts);
      63         [ -  + ]:         10 :         if (!bdev) {
      64                 :          0 :                 SPDK_ERRLOG("Unable to create URING bdev from file %s\n", req.filename);
      65                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
      66                 :            :                                                  "Unable to create URING bdev.");
      67                 :          0 :                 goto cleanup;
      68                 :            :         }
      69                 :            : 
      70                 :         10 :         w = spdk_jsonrpc_begin_result(request);
      71                 :         10 :         spdk_json_write_string(w, req.name);
      72                 :         10 :         spdk_jsonrpc_end_result(request, w);
      73                 :            : 
      74                 :         10 : cleanup:
      75                 :         10 :         free_rpc_create_uring(&req);
      76                 :         10 : }
      77                 :        342 : SPDK_RPC_REGISTER("bdev_uring_create", rpc_bdev_uring_create, SPDK_RPC_RUNTIME)
      78                 :            : 
      79                 :            : struct rpc_rescan_uring {
      80                 :            :         char *name;
      81                 :            : };
      82                 :            : 
      83                 :            : static const struct spdk_json_object_decoder rpc_rescan_uring_decoders[] = {
      84                 :            :         {"name", offsetof(struct rpc_rescan_uring, name), spdk_json_decode_string},
      85                 :            : };
      86                 :            : 
      87                 :            : static void
      88                 :          0 : rpc_bdev_uring_rescan(struct spdk_jsonrpc_request *request,
      89                 :            :                       const struct spdk_json_val *params)
      90                 :            : {
      91                 :          0 :         struct rpc_rescan_uring req = {NULL};
      92                 :            :         int bdeverrno;
      93                 :            : 
      94         [ #  # ]:          0 :         if (spdk_json_decode_object(params, rpc_rescan_uring_decoders,
      95                 :            :                                     SPDK_COUNTOF(rpc_rescan_uring_decoders),
      96                 :            :                                     &req)) {
      97                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
      98                 :            :                                                  "spdk_json_decode_object failed");
      99                 :          0 :                 goto cleanup;
     100                 :            :         }
     101                 :            : 
     102                 :          0 :         bdeverrno = bdev_uring_rescan(req.name);
     103         [ #  # ]:          0 :         if (bdeverrno) {
     104                 :          0 :                 spdk_jsonrpc_send_error_response(request, bdeverrno,
     105                 :            :                                                  spdk_strerror(-bdeverrno));
     106                 :          0 :                 goto cleanup;
     107                 :            :         }
     108                 :            : 
     109                 :          0 :         spdk_jsonrpc_send_bool_response(request, true);
     110                 :          0 : cleanup:
     111                 :          0 :         free(req.name);
     112                 :          0 : }
     113                 :        342 : SPDK_RPC_REGISTER("bdev_uring_rescan", rpc_bdev_uring_rescan, SPDK_RPC_RUNTIME)
     114                 :            : 
     115                 :            : struct rpc_delete_uring {
     116                 :            :         char *name;
     117                 :            : };
     118                 :            : 
     119                 :            : static void
     120                 :          4 : free_rpc_delete_uring(struct rpc_delete_uring *req)
     121                 :            : {
     122                 :          4 :         free(req->name);
     123                 :          4 : }
     124                 :            : 
     125                 :            : static const struct spdk_json_object_decoder rpc_delete_uring_decoders[] = {
     126                 :            :         {"name", offsetof(struct rpc_delete_uring, name), spdk_json_decode_string},
     127                 :            : };
     128                 :            : 
     129                 :            : static void
     130                 :          4 : _rpc_bdev_uring_delete_cb(void *cb_arg, int bdeverrno)
     131                 :            : {
     132                 :          4 :         struct spdk_jsonrpc_request *request = cb_arg;
     133                 :            : 
     134         [ +  - ]:          4 :         if (bdeverrno == 0) {
     135                 :          4 :                 spdk_jsonrpc_send_bool_response(request, true);
     136                 :            :         } else {
     137                 :          0 :                 spdk_jsonrpc_send_error_response(request, bdeverrno, spdk_strerror(-bdeverrno));
     138                 :            :         }
     139                 :            : 
     140                 :          4 : }
     141                 :            : 
     142                 :            : static void
     143                 :          4 : rpc_bdev_uring_delete(struct spdk_jsonrpc_request *request,
     144                 :            :                       const struct spdk_json_val *params)
     145                 :            : {
     146                 :          4 :         struct rpc_delete_uring req = {NULL};
     147                 :            : 
     148         [ -  + ]:          4 :         if (spdk_json_decode_object(params, rpc_delete_uring_decoders,
     149                 :            :                                     SPDK_COUNTOF(rpc_delete_uring_decoders),
     150                 :            :                                     &req)) {
     151                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
     152                 :            :                                                  "spdk_json_decode_object failed");
     153                 :          0 :                 goto cleanup;
     154                 :            :         }
     155                 :            : 
     156                 :          4 :         delete_uring_bdev(req.name, _rpc_bdev_uring_delete_cb, request);
     157                 :            : 
     158                 :          4 : cleanup:
     159                 :          4 :         free_rpc_delete_uring(&req);
     160                 :          4 : }
     161                 :        342 : SPDK_RPC_REGISTER("bdev_uring_delete", rpc_bdev_uring_delete, SPDK_RPC_RUNTIME)

Generated by: LCOV version 1.14