LCOV - code coverage report
Current view: top level - module/bdev/aio - bdev_aio_rpc.c (source / functions) Hit Total Coverage
Test: ut_cov_unit.info Lines: 0 66 0.0 %
Date: 2024-07-11 13:15:21 Functions: 0 10 0.0 %

          Line data    Source code
       1             : /*   SPDX-License-Identifier: BSD-3-Clause
       2             :  *   Copyright (C) 2016 Intel Corporation.
       3             :  *   All rights reserved.
       4             :  */
       5             : 
       6             : #include "bdev_aio.h"
       7             : #include "spdk/rpc.h"
       8             : #include "spdk/util.h"
       9             : #include "spdk/string.h"
      10             : #include "spdk/log.h"
      11             : 
      12             : struct rpc_construct_aio {
      13             :         char *name;
      14             :         char *filename;
      15             :         uint32_t block_size;
      16             :         bool readonly;
      17             :         bool fallocate;
      18             : };
      19             : 
      20             : struct rpc_construct_aio_ctx {
      21             :         struct rpc_construct_aio req;
      22             :         struct spdk_jsonrpc_request *request;
      23             : };
      24             : 
      25             : static void
      26           0 : free_rpc_construct_aio(struct rpc_construct_aio_ctx *ctx)
      27             : {
      28           0 :         free(ctx->req.name);
      29           0 :         free(ctx->req.filename);
      30           0 :         free(ctx);
      31           0 : }
      32             : 
      33             : static const struct spdk_json_object_decoder rpc_construct_aio_decoders[] = {
      34             :         {"name", offsetof(struct rpc_construct_aio, name), spdk_json_decode_string},
      35             :         {"filename", offsetof(struct rpc_construct_aio, filename), spdk_json_decode_string},
      36             :         {"block_size", offsetof(struct rpc_construct_aio, block_size), spdk_json_decode_uint32, true},
      37             :         {"readonly", offsetof(struct rpc_construct_aio, readonly), spdk_json_decode_bool, true},
      38             :         {"fallocate", offsetof(struct rpc_construct_aio, fallocate), spdk_json_decode_bool, true},
      39             : };
      40             : 
      41             : static void
      42           0 : rpc_bdev_aio_create_cb(void *cb_arg)
      43             : {
      44           0 :         struct rpc_construct_aio_ctx *ctx = cb_arg;
      45           0 :         struct spdk_jsonrpc_request *request = ctx->request;
      46             :         struct spdk_json_write_ctx *w;
      47             : 
      48           0 :         w = spdk_jsonrpc_begin_result(request);
      49           0 :         spdk_json_write_string(w, ctx->req.name);
      50           0 :         spdk_jsonrpc_end_result(request, w);
      51           0 :         free_rpc_construct_aio(ctx);
      52           0 : }
      53             : 
      54             : static void
      55           0 : rpc_bdev_aio_create(struct spdk_jsonrpc_request *request,
      56             :                     const struct spdk_json_val *params)
      57             : {
      58             :         struct rpc_construct_aio_ctx *ctx;
      59             :         int rc;
      60             : 
      61           0 :         ctx = calloc(1, sizeof(*ctx));
      62           0 :         if (!ctx) {
      63           0 :                 spdk_jsonrpc_send_error_response(request, -ENOMEM, spdk_strerror(ENOMEM));
      64           0 :                 return;
      65             :         }
      66             : 
      67           0 :         if (spdk_json_decode_object(params, rpc_construct_aio_decoders,
      68             :                                     SPDK_COUNTOF(rpc_construct_aio_decoders),
      69           0 :                                     &ctx->req)) {
      70           0 :                 SPDK_ERRLOG("spdk_json_decode_object failed\n");
      71           0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
      72             :                                                  "spdk_json_decode_object failed");
      73           0 :                 free_rpc_construct_aio(ctx);
      74           0 :                 return;
      75             :         }
      76             : 
      77           0 :         ctx->request = request;
      78           0 :         rc = create_aio_bdev(ctx->req.name, ctx->req.filename, ctx->req.block_size,
      79           0 :                              ctx->req.readonly, ctx->req.fallocate);
      80           0 :         if (rc) {
      81           0 :                 spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
      82           0 :                 free_rpc_construct_aio(ctx);
      83           0 :                 return;
      84             :         }
      85             : 
      86           0 :         spdk_bdev_wait_for_examine(rpc_bdev_aio_create_cb, ctx);
      87             : }
      88           0 : SPDK_RPC_REGISTER("bdev_aio_create", rpc_bdev_aio_create, SPDK_RPC_RUNTIME)
      89             : 
      90             : struct rpc_rescan_aio {
      91             :         char *name;
      92             : };
      93             : 
      94             : static const struct spdk_json_object_decoder rpc_rescan_aio_decoders[] = {
      95             :         {"name", offsetof(struct rpc_rescan_aio, name), spdk_json_decode_string},
      96             : };
      97             : 
      98             : static void
      99           0 : rpc_bdev_aio_rescan(struct spdk_jsonrpc_request *request,
     100             :                     const struct spdk_json_val *params)
     101             : {
     102           0 :         struct rpc_rescan_aio req = {NULL};
     103             :         int bdeverrno;
     104             : 
     105           0 :         if (spdk_json_decode_object(params, rpc_rescan_aio_decoders,
     106             :                                     SPDK_COUNTOF(rpc_rescan_aio_decoders),
     107             :                                     &req)) {
     108           0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
     109             :                                                  "spdk_json_decode_object failed");
     110           0 :                 goto cleanup;
     111             :         }
     112             : 
     113           0 :         bdeverrno = bdev_aio_rescan(req.name);
     114           0 :         if (bdeverrno) {
     115           0 :                 spdk_jsonrpc_send_error_response(request, bdeverrno,
     116             :                                                  spdk_strerror(-bdeverrno));
     117           0 :                 goto cleanup;
     118             :         }
     119             : 
     120           0 :         spdk_jsonrpc_send_bool_response(request, true);
     121           0 : cleanup:
     122           0 :         free(req.name);
     123           0 : }
     124           0 : SPDK_RPC_REGISTER("bdev_aio_rescan", rpc_bdev_aio_rescan, SPDK_RPC_RUNTIME)
     125             : 
     126             : struct rpc_delete_aio {
     127             :         char *name;
     128             : };
     129             : 
     130             : static void
     131           0 : free_rpc_delete_aio(struct rpc_delete_aio *r)
     132             : {
     133           0 :         free(r->name);
     134           0 : }
     135             : 
     136             : static const struct spdk_json_object_decoder rpc_delete_aio_decoders[] = {
     137             :         {"name", offsetof(struct rpc_delete_aio, name), spdk_json_decode_string},
     138             : };
     139             : 
     140             : static void
     141           0 : _rpc_bdev_aio_delete_cb(void *cb_arg, int bdeverrno)
     142             : {
     143           0 :         struct spdk_jsonrpc_request *request = cb_arg;
     144             : 
     145           0 :         if (bdeverrno == 0) {
     146           0 :                 spdk_jsonrpc_send_bool_response(request, true);
     147             :         } else {
     148           0 :                 spdk_jsonrpc_send_error_response(request, bdeverrno, spdk_strerror(-bdeverrno));
     149             :         }
     150           0 : }
     151             : 
     152             : static void
     153           0 : rpc_bdev_aio_delete(struct spdk_jsonrpc_request *request,
     154             :                     const struct spdk_json_val *params)
     155             : {
     156           0 :         struct rpc_delete_aio req = {NULL};
     157             : 
     158           0 :         if (spdk_json_decode_object(params, rpc_delete_aio_decoders,
     159             :                                     SPDK_COUNTOF(rpc_delete_aio_decoders),
     160             :                                     &req)) {
     161           0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
     162             :                                                  "spdk_json_decode_object failed");
     163           0 :                 goto cleanup;
     164             :         }
     165             : 
     166           0 :         bdev_aio_delete(req.name, _rpc_bdev_aio_delete_cb, request);
     167             : 
     168           0 : cleanup:
     169           0 :         free_rpc_delete_aio(&req);
     170           0 : }
     171           0 : SPDK_RPC_REGISTER("bdev_aio_delete", rpc_bdev_aio_delete, SPDK_RPC_RUNTIME)

Generated by: LCOV version 1.15