]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/lib/event/subsystems/bdev/bdev_rpc.c
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / lib / event / subsystems / bdev / bdev_rpc.c
CommitLineData
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
11fdf7f2
TL
34#include "spdk/bdev.h"
35
7c673cae
FG
36#include "spdk/rpc.h"
37#include "spdk/util.h"
11fdf7f2 38#include "spdk/string.h"
7c673cae
FG
39
40#include "spdk_internal/log.h"
41
11fdf7f2
TL
42struct spdk_rpc_set_bdev_opts {
43 uint32_t bdev_io_pool_size;
44 uint32_t bdev_io_cache_size;
7c673cae
FG
45};
46
11fdf7f2
TL
47static const struct spdk_json_object_decoder rpc_set_bdev_opts_decoders[] = {
48 {"bdev_io_pool_size", offsetof(struct spdk_rpc_set_bdev_opts, bdev_io_pool_size), spdk_json_decode_uint32, true},
49 {"bdev_io_cache_size", offsetof(struct spdk_rpc_set_bdev_opts, bdev_io_cache_size), spdk_json_decode_uint32, true},
7c673cae
FG
50};
51
52static void
9f95a23c 53spdk_rpc_set_bdev_options(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
7c673cae 54{
11fdf7f2
TL
55 struct spdk_rpc_set_bdev_opts rpc_opts;
56 struct spdk_bdev_opts bdev_opts;
7c673cae 57 struct spdk_json_write_ctx *w;
11fdf7f2 58 int rc;
7c673cae 59
11fdf7f2
TL
60 rpc_opts.bdev_io_pool_size = UINT32_MAX;
61 rpc_opts.bdev_io_cache_size = UINT32_MAX;
7c673cae 62
11fdf7f2
TL
63 if (params != NULL) {
64 if (spdk_json_decode_object(params, rpc_set_bdev_opts_decoders,
65 SPDK_COUNTOF(rpc_set_bdev_opts_decoders), &rpc_opts)) {
66 SPDK_ERRLOG("spdk_json_decode_object() failed\n");
67 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
68 "Invalid parameters");
69 return;
70 }
7c673cae
FG
71 }
72
11fdf7f2
TL
73 spdk_bdev_get_opts(&bdev_opts);
74 if (rpc_opts.bdev_io_pool_size != UINT32_MAX) {
75 bdev_opts.bdev_io_pool_size = rpc_opts.bdev_io_pool_size;
76 }
77 if (rpc_opts.bdev_io_cache_size != UINT32_MAX) {
78 bdev_opts.bdev_io_cache_size = rpc_opts.bdev_io_cache_size;
79 }
80 rc = spdk_bdev_set_opts(&bdev_opts);
7c673cae 81
11fdf7f2
TL
82 if (rc != 0) {
83 spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
84 "Pool size %" PRIu32 " too small for cache size %" PRIu32,
85 bdev_opts.bdev_io_pool_size, bdev_opts.bdev_io_cache_size);
7c673cae
FG
86 return;
87 }
88
11fdf7f2
TL
89 w = spdk_jsonrpc_begin_result(request);
90 if (w == NULL) {
91 return;
92 }
7c673cae 93
11fdf7f2
TL
94 spdk_json_write_bool(w, true);
95 spdk_jsonrpc_end_result(request, w);
7c673cae 96}
9f95a23c 97SPDK_RPC_REGISTER("set_bdev_options", spdk_rpc_set_bdev_options, SPDK_RPC_STARTUP)