4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
34 #include "vbdev_crypto.h"
36 /* Structure to hold the parameters for this RPC method. */
37 struct rpc_construct_crypto
{
44 /* Free the allocated memory resource after the RPC handling. */
46 free_rpc_construct_crypto(struct rpc_construct_crypto
*r
)
48 free(r
->base_bdev_name
);
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
},
62 /* Decode the parameters for this RPC method and properly construct the crypto
63 * device. Error status returned in the failed cases.
66 spdk_rpc_construct_crypto_bdev(struct spdk_jsonrpc_request
*request
,
67 const struct spdk_json_val
*params
)
69 struct rpc_construct_crypto req
= {NULL
};
70 struct spdk_json_write_ctx
*w
;
73 if (spdk_json_decode_object(params
, rpc_construct_crypto_decoders
,
74 SPDK_COUNTOF(rpc_construct_crypto_decoders
),
76 SPDK_DEBUGLOG(SPDK_LOG_VBDEV_crypto
, "spdk_json_decode_object failed\n");
80 rc
= create_crypto_disk(req
.base_bdev_name
, req
.name
,
81 req
.crypto_pmd
, req
.key
);
86 w
= spdk_jsonrpc_begin_result(request
);
88 free_rpc_construct_crypto(&req
);
92 spdk_json_write_string(w
, req
.name
);
93 spdk_jsonrpc_end_result(request
, w
);
94 free_rpc_construct_crypto(&req
);
98 free_rpc_construct_crypto(&req
);
99 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INVALID_PARAMS
, "Invalid parameters");
101 SPDK_RPC_REGISTER("construct_crypto_bdev", spdk_rpc_construct_crypto_bdev
, SPDK_RPC_RUNTIME
)
103 struct rpc_delete_crypto
{
108 free_rpc_delete_crypto(struct rpc_delete_crypto
*req
)
113 static const struct spdk_json_object_decoder rpc_delete_crypto_decoders
[] = {
114 {"name", offsetof(struct rpc_delete_crypto
, name
), spdk_json_decode_string
},
118 _spdk_rpc_delete_crypto_bdev_cb(void *cb_arg
, int bdeverrno
)
120 struct spdk_jsonrpc_request
*request
= cb_arg
;
121 struct spdk_json_write_ctx
*w
;
123 w
= spdk_jsonrpc_begin_result(request
);
128 spdk_json_write_bool(w
, bdeverrno
== 0);
129 spdk_jsonrpc_end_result(request
, w
);
133 spdk_rpc_delete_crypto_bdev(struct spdk_jsonrpc_request
*request
,
134 const struct spdk_json_val
*params
)
136 struct rpc_delete_crypto req
= {NULL
};
137 struct spdk_bdev
*bdev
;
140 if (spdk_json_decode_object(params
, rpc_delete_crypto_decoders
,
141 SPDK_COUNTOF(rpc_delete_crypto_decoders
),
147 bdev
= spdk_bdev_get_by_name(req
.name
);
153 delete_crypto_disk(bdev
, _spdk_rpc_delete_crypto_bdev_cb
, request
);
155 free_rpc_delete_crypto(&req
);
160 free_rpc_delete_crypto(&req
);
161 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INVALID_PARAMS
, spdk_strerror(-rc
));
163 SPDK_RPC_REGISTER("delete_crypto_bdev", spdk_rpc_delete_crypto_bdev
, SPDK_RPC_RUNTIME
)