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 : 64 : free_rpc_construct_zone_block(struct rpc_construct_zone_block *req)
26 : : {
27 : 64 : free(req->name);
28 : 64 : free(req->base_bdev);
29 : 64 : }
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 : 64 : rpc_zone_block_create(struct spdk_jsonrpc_request *request,
40 : : const struct spdk_json_val *params)
41 : : {
42 : 64 : struct rpc_construct_zone_block req = {};
43 : : struct spdk_json_write_ctx *w;
44 : : int rc;
45 : :
46 [ - + ]: 64 : 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 : 64 : rc = vbdev_zone_block_create(req.base_bdev, req.name, req.zone_capacity,
56 : : req.optimal_open_zones);
57 [ + + ]: 64 : if (rc) {
58 : 16 : SPDK_ERRLOG("Failed to create block zoned vbdev: %s", spdk_strerror(-rc));
59 : 16 : 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 : 16 : goto cleanup;
63 : : }
64 : :
65 : 48 : w = spdk_jsonrpc_begin_result(request);
66 : 48 : spdk_json_write_string(w, req.name);
67 : 48 : spdk_jsonrpc_end_result(request, w);
68 : :
69 : 64 : cleanup:
70 : 64 : free_rpc_construct_zone_block(&req);
71 : 64 : }
72 : 2322 : 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 : 48 : free_rpc_delete_zone_block(struct rpc_delete_zone_block *req)
80 : : {
81 : 48 : free(req->name);
82 : 48 : }
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 : 48 : _rpc_delete_zone_block_cb(void *cb_ctx, int rc)
90 : : {
91 : 48 : struct spdk_jsonrpc_request *request = cb_ctx;
92 : :
93 [ + - ]: 48 : if (rc == 0) {
94 : 48 : spdk_jsonrpc_send_bool_response(request, true);
95 : : } else {
96 : 0 : spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
97 : : }
98 : 48 : }
99 : :
100 : : static void
101 : 48 : rpc_zone_block_delete(struct spdk_jsonrpc_request *request,
102 : : const struct spdk_json_val *params)
103 : : {
104 : 48 : struct rpc_delete_zone_block attrs = {};
105 : :
106 [ - + ]: 48 : 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 : 48 : vbdev_zone_block_delete(attrs.name, _rpc_delete_zone_block_cb, request);
116 : :
117 : 48 : cleanup:
118 : 48 : free_rpc_delete_zone_block(&attrs);
119 : 48 : }
120 : 2322 : SPDK_RPC_REGISTER("bdev_zone_block_delete", rpc_zone_block_delete, SPDK_RPC_RUNTIME)
|