LCOV - code coverage report
Current view: top level - spdk/module/bdev/malloc - bdev_malloc_rpc.c (source / functions) Hit Total Coverage
Test: Combined Lines: 32 43 74.4 %
Date: 2024-08-12 07:19:58 Functions: 7 7 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 16 25.0 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2016 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  *   Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
       5                 :            :  */
       6                 :            : 
       7                 :            : #include "bdev_malloc.h"
       8                 :            : #include "spdk/rpc.h"
       9                 :            : #include "spdk/string.h"
      10                 :            : #include "spdk/log.h"
      11                 :            : 
      12                 :            : static void
      13                 :       1867 : free_rpc_construct_malloc(struct malloc_bdev_opts *r)
      14                 :            : {
      15                 :       1867 :         free(r->name);
      16                 :       1867 : }
      17                 :            : 
      18                 :            : static const struct spdk_json_object_decoder rpc_construct_malloc_decoders[] = {
      19                 :            :         {"name", offsetof(struct malloc_bdev_opts, name), spdk_json_decode_string, true},
      20                 :            :         {"uuid", offsetof(struct malloc_bdev_opts, uuid), spdk_json_decode_uuid, true},
      21                 :            :         {"num_blocks", offsetof(struct malloc_bdev_opts, num_blocks), spdk_json_decode_uint64},
      22                 :            :         {"block_size", offsetof(struct malloc_bdev_opts, block_size), spdk_json_decode_uint32},
      23                 :            :         {"physical_block_size", offsetof(struct malloc_bdev_opts, physical_block_size), spdk_json_decode_uint32, true},
      24                 :            :         {"optimal_io_boundary", offsetof(struct malloc_bdev_opts, optimal_io_boundary), spdk_json_decode_uint32, true},
      25                 :            :         {"md_size", offsetof(struct malloc_bdev_opts, md_size), spdk_json_decode_uint32, true},
      26                 :            :         {"md_interleave", offsetof(struct malloc_bdev_opts, md_interleave), spdk_json_decode_bool, true},
      27                 :            :         {"dif_type", offsetof(struct malloc_bdev_opts, dif_type), spdk_json_decode_int32, true},
      28                 :            :         {"dif_is_head_of_md", offsetof(struct malloc_bdev_opts, dif_is_head_of_md), spdk_json_decode_bool, true},
      29                 :            :         {"dif_pi_format", offsetof(struct malloc_bdev_opts, dif_pi_format), spdk_json_decode_uint32, true},
      30                 :            : };
      31                 :            : 
      32                 :            : static void
      33                 :       1867 : rpc_bdev_malloc_create(struct spdk_jsonrpc_request *request,
      34                 :            :                        const struct spdk_json_val *params)
      35                 :            : {
      36                 :       1867 :         struct malloc_bdev_opts req = {NULL};
      37                 :            :         struct spdk_json_write_ctx *w;
      38                 :        992 :         struct spdk_bdev *bdev;
      39                 :       1867 :         int rc = 0;
      40                 :            : 
      41         [ -  + ]:       1867 :         if (spdk_json_decode_object(params, rpc_construct_malloc_decoders,
      42                 :            :                                     SPDK_COUNTOF(rpc_construct_malloc_decoders),
      43                 :            :                                     &req)) {
      44   [ #  #  #  # ]:          0 :                 SPDK_DEBUGLOG(bdev_malloc, "spdk_json_decode_object failed\n");
      45                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
      46                 :            :                                                  "spdk_json_decode_object failed");
      47                 :          0 :                 goto cleanup;
      48                 :            :         }
      49                 :            : 
      50                 :       1867 :         rc = create_malloc_disk(&bdev, &req);
      51         [ -  + ]:       1867 :         if (rc) {
      52                 :          0 :                 spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
      53                 :          0 :                 goto cleanup;
      54                 :            :         }
      55                 :            : 
      56                 :       1867 :         free_rpc_construct_malloc(&req);
      57                 :            : 
      58                 :       1867 :         w = spdk_jsonrpc_begin_result(request);
      59                 :       1867 :         spdk_json_write_string(w, spdk_bdev_get_name(bdev));
      60                 :       1867 :         spdk_jsonrpc_end_result(request, w);
      61                 :       1867 :         return;
      62                 :            : 
      63                 :          0 : cleanup:
      64                 :          0 :         free_rpc_construct_malloc(&req);
      65                 :            : }
      66                 :       2026 : SPDK_RPC_REGISTER("bdev_malloc_create", rpc_bdev_malloc_create, SPDK_RPC_RUNTIME)
      67                 :            : 
      68                 :            : struct rpc_delete_malloc {
      69                 :            :         char *name;
      70                 :            : };
      71                 :            : 
      72                 :            : static void
      73                 :        433 : free_rpc_delete_malloc(struct rpc_delete_malloc *r)
      74                 :            : {
      75                 :        433 :         free(r->name);
      76                 :        433 : }
      77                 :            : 
      78                 :            : static const struct spdk_json_object_decoder rpc_delete_malloc_decoders[] = {
      79                 :            :         {"name", offsetof(struct rpc_delete_malloc, name), spdk_json_decode_string},
      80                 :            : };
      81                 :            : 
      82                 :            : static void
      83                 :        433 : rpc_bdev_malloc_delete_cb(void *cb_arg, int bdeverrno)
      84                 :            : {
      85                 :        433 :         struct spdk_jsonrpc_request *request = cb_arg;
      86                 :            : 
      87         [ +  - ]:        433 :         if (bdeverrno == 0) {
      88                 :        433 :                 spdk_jsonrpc_send_bool_response(request, true);
      89                 :            :         } else {
      90                 :          0 :                 spdk_jsonrpc_send_error_response(request, bdeverrno, spdk_strerror(-bdeverrno));
      91                 :            :         }
      92                 :        433 : }
      93                 :            : 
      94                 :            : static void
      95                 :        433 : rpc_bdev_malloc_delete(struct spdk_jsonrpc_request *request,
      96                 :            :                        const struct spdk_json_val *params)
      97                 :            : {
      98                 :        433 :         struct rpc_delete_malloc req = {NULL};
      99                 :            : 
     100         [ -  + ]:        433 :         if (spdk_json_decode_object(params, rpc_delete_malloc_decoders,
     101                 :            :                                     SPDK_COUNTOF(rpc_delete_malloc_decoders),
     102                 :            :                                     &req)) {
     103   [ #  #  #  # ]:          0 :                 SPDK_DEBUGLOG(bdev_malloc, "spdk_json_decode_object failed\n");
     104                 :          0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
     105                 :            :                                                  "spdk_json_decode_object failed");
     106                 :          0 :                 goto cleanup;
     107                 :            :         }
     108                 :            : 
     109                 :        433 :         delete_malloc_disk(req.name, rpc_bdev_malloc_delete_cb, request);
     110                 :            : 
     111                 :        433 : cleanup:
     112                 :        433 :         free_rpc_delete_malloc(&req);
     113                 :        433 : }
     114                 :       2026 : SPDK_RPC_REGISTER("bdev_malloc_delete", rpc_bdev_malloc_delete, SPDK_RPC_RUNTIME)

Generated by: LCOV version 1.14