]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 "blockdev_rbd.h" | |
35 | #include "spdk/rpc.h" | |
36 | #include "spdk/util.h" | |
37 | ||
38 | #include "spdk_internal/log.h" | |
39 | ||
40 | struct rpc_construct_rbd { | |
41 | char *pool_name; | |
42 | char *rbd_name; | |
43 | uint32_t block_size; | |
44 | }; | |
45 | ||
46 | static void | |
47 | free_rpc_construct_rbd(struct rpc_construct_rbd *req) | |
48 | { | |
49 | free(req->pool_name); | |
50 | free(req->rbd_name); | |
51 | } | |
52 | ||
53 | static const struct spdk_json_object_decoder rpc_construct_rbd_decoders[] = { | |
54 | {"pool_name", offsetof(struct rpc_construct_rbd, pool_name), spdk_json_decode_string}, | |
55 | {"rbd_name", offsetof(struct rpc_construct_rbd, rbd_name), spdk_json_decode_string}, | |
56 | {"block_size", offsetof(struct rpc_construct_rbd, block_size), spdk_json_decode_uint32}, | |
57 | }; | |
58 | ||
59 | static void | |
60 | spdk_rpc_construct_rbd_bdev(struct spdk_jsonrpc_server_conn *conn, | |
61 | const struct spdk_json_val *params, | |
62 | const struct spdk_json_val *id) | |
63 | { | |
64 | struct rpc_construct_rbd req = {}; | |
65 | struct spdk_json_write_ctx *w; | |
66 | struct spdk_bdev *bdev; | |
67 | ||
68 | if (spdk_json_decode_object(params, rpc_construct_rbd_decoders, | |
69 | SPDK_COUNTOF(rpc_construct_rbd_decoders), | |
70 | &req)) { | |
71 | SPDK_TRACELOG(SPDK_TRACE_DEBUG, "spdk_json_decode_object failed\n"); | |
72 | goto invalid; | |
73 | } | |
74 | ||
75 | bdev = spdk_bdev_rbd_create(req.pool_name, req.rbd_name, req.block_size); | |
76 | if (bdev == NULL) { | |
77 | goto invalid; | |
78 | } | |
79 | ||
80 | free_rpc_construct_rbd(&req); | |
81 | ||
82 | if (id == NULL) { | |
83 | return; | |
84 | } | |
85 | ||
86 | w = spdk_jsonrpc_begin_result(conn, id); | |
87 | spdk_json_write_array_begin(w); | |
88 | spdk_json_write_string(w, bdev->name); | |
89 | spdk_json_write_array_end(w); | |
90 | spdk_jsonrpc_end_result(conn, w); | |
91 | return; | |
92 | ||
93 | invalid: | |
94 | spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters"); | |
95 | free_rpc_construct_rbd(&req); | |
96 | } | |
97 | SPDK_RPC_REGISTER("construct_rbd_bdev", spdk_rpc_construct_rbd_bdev) |