]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/lib/bdev/crypto/vbdev_crypto_rpc.c
bump version to 15.2.11-pve1
[ceph.git] / ceph / src / spdk / lib / bdev / crypto / vbdev_crypto_rpc.c
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include "vbdev_crypto.h"
35
36 /* Structure to hold the parameters for this RPC method. */
37 struct rpc_construct_crypto {
38 char *base_bdev_name;
39 char *name;
40 char *crypto_pmd;
41 char *key;
42 };
43
44 /* Free the allocated memory resource after the RPC handling. */
45 static void
46 free_rpc_construct_crypto(struct rpc_construct_crypto *r)
47 {
48 free(r->base_bdev_name);
49 free(r->name);
50 free(r->crypto_pmd);
51 free(r->key);
52 }
53
54 /* Structure to decode the input parameters for this RPC method. */
55 static const struct spdk_json_object_decoder rpc_construct_crypto_decoders[] = {
56 {"base_bdev_name", offsetof(struct rpc_construct_crypto, base_bdev_name), spdk_json_decode_string},
57 {"name", offsetof(struct rpc_construct_crypto, name), spdk_json_decode_string},
58 {"crypto_pmd", offsetof(struct rpc_construct_crypto, crypto_pmd), spdk_json_decode_string},
59 {"key", offsetof(struct rpc_construct_crypto, key), spdk_json_decode_string},
60 };
61
62 /* Decode the parameters for this RPC method and properly construct the crypto
63 * device. Error status returned in the failed cases.
64 */
65 static void
66 spdk_rpc_construct_crypto_bdev(struct spdk_jsonrpc_request *request,
67 const struct spdk_json_val *params)
68 {
69 struct rpc_construct_crypto req = {NULL};
70 struct spdk_json_write_ctx *w;
71 int rc;
72
73 if (spdk_json_decode_object(params, rpc_construct_crypto_decoders,
74 SPDK_COUNTOF(rpc_construct_crypto_decoders),
75 &req)) {
76 SPDK_DEBUGLOG(SPDK_LOG_VBDEV_crypto, "spdk_json_decode_object failed\n");
77 goto invalid;
78 }
79
80 rc = create_crypto_disk(req.base_bdev_name, req.name,
81 req.crypto_pmd, req.key);
82 if (rc != 0) {
83 goto invalid;
84 }
85
86 w = spdk_jsonrpc_begin_result(request);
87 if (w == NULL) {
88 free_rpc_construct_crypto(&req);
89 return;
90 }
91
92 spdk_json_write_string(w, req.name);
93 spdk_jsonrpc_end_result(request, w);
94 free_rpc_construct_crypto(&req);
95 return;
96
97 invalid:
98 free_rpc_construct_crypto(&req);
99 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
100 }
101 SPDK_RPC_REGISTER("construct_crypto_bdev", spdk_rpc_construct_crypto_bdev, SPDK_RPC_RUNTIME)
102
103 struct rpc_delete_crypto {
104 char *name;
105 };
106
107 static void
108 free_rpc_delete_crypto(struct rpc_delete_crypto *req)
109 {
110 free(req->name);
111 }
112
113 static const struct spdk_json_object_decoder rpc_delete_crypto_decoders[] = {
114 {"name", offsetof(struct rpc_delete_crypto, name), spdk_json_decode_string},
115 };
116
117 static void
118 _spdk_rpc_delete_crypto_bdev_cb(void *cb_arg, int bdeverrno)
119 {
120 struct spdk_jsonrpc_request *request = cb_arg;
121 struct spdk_json_write_ctx *w;
122
123 w = spdk_jsonrpc_begin_result(request);
124 if (w == NULL) {
125 return;
126 }
127
128 spdk_json_write_bool(w, bdeverrno == 0);
129 spdk_jsonrpc_end_result(request, w);
130 }
131
132 static void
133 spdk_rpc_delete_crypto_bdev(struct spdk_jsonrpc_request *request,
134 const struct spdk_json_val *params)
135 {
136 struct rpc_delete_crypto req = {NULL};
137 struct spdk_bdev *bdev;
138 int rc;
139
140 if (spdk_json_decode_object(params, rpc_delete_crypto_decoders,
141 SPDK_COUNTOF(rpc_delete_crypto_decoders),
142 &req)) {
143 rc = -EINVAL;
144 goto invalid;
145 }
146
147 bdev = spdk_bdev_get_by_name(req.name);
148 if (bdev == NULL) {
149 rc = -ENODEV;
150 goto invalid;
151 }
152
153 delete_crypto_disk(bdev, _spdk_rpc_delete_crypto_bdev_cb, request);
154
155 free_rpc_delete_crypto(&req);
156
157 return;
158
159 invalid:
160 free_rpc_delete_crypto(&req);
161 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, spdk_strerror(-rc));
162 }
163 SPDK_RPC_REGISTER("delete_crypto_bdev", spdk_rpc_delete_crypto_bdev, SPDK_RPC_RUNTIME)