LCOV - code coverage report
Current view: top level - spdk/module/bdev/zone_block - vbdev_zone_block_rpc.c (source / functions) Hit Total Coverage
Test: Combined Lines: 35 42 83.3 %
Date: 2024-07-16 00:21:09 Functions: 7 7 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 8 62.5 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2019 Intel Corporation.
       3                 :            :  *   Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
       4                 :            :  *   All rights reserved.
       5                 :            :  */
       6                 :            : 
       7                 :            : #include "spdk/stdinc.h"
       8                 :            : 
       9                 :            : #include "vbdev_zone_block.h"
      10                 :            : 
      11                 :            : #include "spdk/util.h"
      12                 :            : #include "spdk/string.h"
      13                 :            : #include "spdk/rpc.h"
      14                 :            : 
      15                 :            : #include "spdk/log.h"
      16                 :            : 
      17                 :            : struct rpc_construct_zone_block {
      18                 :            :         char *name;
      19                 :            :         char *base_bdev;
      20                 :            :         uint64_t zone_capacity;
      21                 :            :         uint64_t optimal_open_zones;
      22                 :            : };
      23                 :            : 
      24                 :            : static void
      25                 :         48 : free_rpc_construct_zone_block(struct rpc_construct_zone_block *req)
      26                 :            : {
      27                 :         48 :         free(req->name);
      28                 :         48 :         free(req->base_bdev);
      29                 :         48 : }
      30                 :            : 
      31                 :            : static const struct spdk_json_object_decoder rpc_construct_zone_block_decoders[] = {
      32                 :            :         {"name", offsetof(struct rpc_construct_zone_block, name), spdk_json_decode_string},
      33                 :            :         {"base_bdev", offsetof(struct rpc_construct_zone_block, base_bdev), spdk_json_decode_string},
      34                 :            :         {"zone_capacity", offsetof(struct rpc_construct_zone_block, zone_capacity), spdk_json_decode_uint64},
      35                 :            :         {"optimal_open_zones", offsetof(struct rpc_construct_zone_block, optimal_open_zones), spdk_json_decode_uint64},
      36                 :            : };
      37                 :            : 
      38                 :            : static void
      39                 :         48 : rpc_zone_block_create(struct spdk_jsonrpc_request *request,
      40                 :            :                       const struct spdk_json_val *params)
      41                 :            : {
      42                 :         48 :         struct rpc_construct_zone_block req = {};
      43                 :            :         struct spdk_json_write_ctx *w;
      44                 :            :         int rc;
      45                 :            : 
      46         [ -  + ]:         48 :         if (spdk_json_decode_object(params, rpc_construct_zone_block_decoders,
      47                 :            :                                     SPDK_COUNTOF(rpc_construct_zone_block_decoders),
      48                 :            :                                     &req)) {
      49                 :          0 :                 SPDK_ERRLOG("Failed to decode block create parameters");
      50                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
      51                 :            :                                                  "Invalid parameters");
      52                 :          0 :                 goto cleanup;
      53                 :            :         }
      54                 :            : 
      55                 :         48 :         rc = vbdev_zone_block_create(req.base_bdev, req.name, req.zone_capacity,
      56                 :            :                                      req.optimal_open_zones);
      57         [ +  + ]:         48 :         if (rc) {
      58                 :         12 :                 SPDK_ERRLOG("Failed to create block zoned vbdev: %s", spdk_strerror(-rc));
      59                 :         12 :                 spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
      60                 :            :                                                      "Failed to create block zoned vbdev: %s",
      61                 :            :                                                      spdk_strerror(-rc));
      62                 :         12 :                 goto cleanup;
      63                 :            :         }
      64                 :            : 
      65                 :         36 :         w = spdk_jsonrpc_begin_result(request);
      66                 :         36 :         spdk_json_write_string(w, req.name);
      67                 :         36 :         spdk_jsonrpc_end_result(request, w);
      68                 :            : 
      69                 :         48 : cleanup:
      70                 :         48 :         free_rpc_construct_zone_block(&req);
      71                 :         48 : }
      72                 :       2051 : SPDK_RPC_REGISTER("bdev_zone_block_create", rpc_zone_block_create, SPDK_RPC_RUNTIME)
      73                 :            : 
      74                 :            : struct rpc_delete_zone_block {
      75                 :            :         char *name;
      76                 :            : };
      77                 :            : 
      78                 :            : static void
      79                 :         36 : free_rpc_delete_zone_block(struct rpc_delete_zone_block *req)
      80                 :            : {
      81                 :         36 :         free(req->name);
      82                 :         36 : }
      83                 :            : 
      84                 :            : static const struct spdk_json_object_decoder rpc_delete_zone_block_decoders[] = {
      85                 :            :         {"name", offsetof(struct rpc_delete_zone_block, name), spdk_json_decode_string},
      86                 :            : };
      87                 :            : 
      88                 :            : static void
      89                 :         36 : _rpc_delete_zone_block_cb(void *cb_ctx, int rc)
      90                 :            : {
      91                 :         36 :         struct spdk_jsonrpc_request *request = cb_ctx;
      92                 :            : 
      93         [ +  - ]:         36 :         if (rc == 0) {
      94                 :         36 :                 spdk_jsonrpc_send_bool_response(request, true);
      95                 :            :         } else {
      96                 :          0 :                 spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
      97                 :            :         }
      98                 :         36 : }
      99                 :            : 
     100                 :            : static void
     101                 :         36 : rpc_zone_block_delete(struct spdk_jsonrpc_request *request,
     102                 :            :                       const struct spdk_json_val *params)
     103                 :            : {
     104                 :         36 :         struct rpc_delete_zone_block attrs = {};
     105                 :            : 
     106         [ -  + ]:         36 :         if (spdk_json_decode_object(params, rpc_delete_zone_block_decoders,
     107                 :            :                                     SPDK_COUNTOF(rpc_delete_zone_block_decoders),
     108                 :            :                                     &attrs)) {
     109                 :          0 :                 SPDK_ERRLOG("Failed to decode block delete parameters");
     110                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
     111                 :            :                                                  "Invalid parameters");
     112                 :          0 :                 goto cleanup;
     113                 :            :         }
     114                 :            : 
     115                 :         36 :         vbdev_zone_block_delete(attrs.name, _rpc_delete_zone_block_cb, request);
     116                 :            : 
     117                 :         36 : cleanup:
     118                 :         36 :         free_rpc_delete_zone_block(&attrs);
     119                 :         36 : }
     120                 :       2051 : SPDK_RPC_REGISTER("bdev_zone_block_delete", rpc_zone_block_delete, SPDK_RPC_RUNTIME)

Generated by: LCOV version 1.14