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.
36 #include "spdk/util.h"
37 #include "spdk/string.h"
38 #include "spdk_internal/log.h"
40 struct rpc_construct_aio
{
47 free_rpc_construct_aio(struct rpc_construct_aio
*req
)
53 static const struct spdk_json_object_decoder rpc_construct_aio_decoders
[] = {
54 {"name", offsetof(struct rpc_construct_aio
, name
), spdk_json_decode_string
},
55 {"filename", offsetof(struct rpc_construct_aio
, filename
), spdk_json_decode_string
},
56 {"block_size", offsetof(struct rpc_construct_aio
, block_size
), spdk_json_decode_uint32
, true},
60 rpc_bdev_aio_create(struct spdk_jsonrpc_request
*request
,
61 const struct spdk_json_val
*params
)
63 struct rpc_construct_aio req
= {};
64 struct spdk_json_write_ctx
*w
;
67 if (spdk_json_decode_object(params
, rpc_construct_aio_decoders
,
68 SPDK_COUNTOF(rpc_construct_aio_decoders
),
70 SPDK_ERRLOG("spdk_json_decode_object failed\n");
71 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INTERNAL_ERROR
,
72 "spdk_json_decode_object failed");
76 rc
= create_aio_bdev(req
.name
, req
.filename
, req
.block_size
);
78 spdk_jsonrpc_send_error_response(request
, rc
, spdk_strerror(-rc
));
83 w
= spdk_jsonrpc_begin_result(request
);
84 spdk_json_write_string(w
, req
.name
);
85 spdk_jsonrpc_end_result(request
, w
);
88 free_rpc_construct_aio(&req
);
90 SPDK_RPC_REGISTER("bdev_aio_create", rpc_bdev_aio_create
, SPDK_RPC_RUNTIME
)
91 SPDK_RPC_REGISTER_ALIAS_DEPRECATED(bdev_aio_create
, construct_aio_bdev
)
93 struct rpc_delete_aio
{
98 free_rpc_delete_aio(struct rpc_delete_aio
*r
)
103 static const struct spdk_json_object_decoder rpc_delete_aio_decoders
[] = {
104 {"name", offsetof(struct rpc_delete_aio
, name
), spdk_json_decode_string
},
108 _rpc_bdev_aio_delete_cb(void *cb_arg
, int bdeverrno
)
110 struct spdk_jsonrpc_request
*request
= cb_arg
;
111 struct spdk_json_write_ctx
*w
= spdk_jsonrpc_begin_result(request
);
113 spdk_json_write_bool(w
, bdeverrno
== 0);
114 spdk_jsonrpc_end_result(request
, w
);
118 rpc_bdev_aio_delete(struct spdk_jsonrpc_request
*request
,
119 const struct spdk_json_val
*params
)
121 struct rpc_delete_aio req
= {NULL
};
122 struct spdk_bdev
*bdev
;
124 if (spdk_json_decode_object(params
, rpc_delete_aio_decoders
,
125 SPDK_COUNTOF(rpc_delete_aio_decoders
),
127 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INTERNAL_ERROR
,
128 "spdk_json_decode_object failed");
132 bdev
= spdk_bdev_get_by_name(req
.name
);
134 spdk_jsonrpc_send_error_response(request
, -ENODEV
, spdk_strerror(ENODEV
));
138 bdev_aio_delete(bdev
, _rpc_bdev_aio_delete_cb
, request
);
140 free_rpc_delete_aio(&req
);
145 free_rpc_delete_aio(&req
);
147 SPDK_RPC_REGISTER("bdev_aio_delete", rpc_bdev_aio_delete
, SPDK_RPC_RUNTIME
)
148 SPDK_RPC_REGISTER_ALIAS_DEPRECATED(bdev_aio_delete
, delete_aio_bdev
)