]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/lib/bdev/bdev_rpc.c
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / lib / 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;
f67539c2 45 bool bdev_auto_examine;
7c673cae
FG
46};
47
11fdf7f2
TL
48static const struct spdk_json_object_decoder rpc_set_bdev_opts_decoders[] = {
49 {"bdev_io_pool_size", offsetof(struct spdk_rpc_set_bdev_opts, bdev_io_pool_size), spdk_json_decode_uint32, true},
50 {"bdev_io_cache_size", offsetof(struct spdk_rpc_set_bdev_opts, bdev_io_cache_size), spdk_json_decode_uint32, true},
f67539c2 51 {"bdev_auto_examine", offsetof(struct spdk_rpc_set_bdev_opts, bdev_auto_examine), spdk_json_decode_bool, true},
7c673cae
FG
52};
53
54static void
f67539c2 55rpc_bdev_set_options(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
7c673cae 56{
11fdf7f2
TL
57 struct spdk_rpc_set_bdev_opts rpc_opts;
58 struct spdk_bdev_opts bdev_opts;
7c673cae 59 struct spdk_json_write_ctx *w;
11fdf7f2 60 int rc;
7c673cae 61
11fdf7f2
TL
62 rpc_opts.bdev_io_pool_size = UINT32_MAX;
63 rpc_opts.bdev_io_cache_size = UINT32_MAX;
f67539c2 64 rpc_opts.bdev_auto_examine = true;
7c673cae 65
11fdf7f2
TL
66 if (params != NULL) {
67 if (spdk_json_decode_object(params, rpc_set_bdev_opts_decoders,
68 SPDK_COUNTOF(rpc_set_bdev_opts_decoders), &rpc_opts)) {
69 SPDK_ERRLOG("spdk_json_decode_object() failed\n");
70 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
71 "Invalid parameters");
72 return;
73 }
7c673cae
FG
74 }
75
11fdf7f2
TL
76 spdk_bdev_get_opts(&bdev_opts);
77 if (rpc_opts.bdev_io_pool_size != UINT32_MAX) {
78 bdev_opts.bdev_io_pool_size = rpc_opts.bdev_io_pool_size;
79 }
80 if (rpc_opts.bdev_io_cache_size != UINT32_MAX) {
81 bdev_opts.bdev_io_cache_size = rpc_opts.bdev_io_cache_size;
82 }
f67539c2 83 bdev_opts.bdev_auto_examine = rpc_opts.bdev_auto_examine;
11fdf7f2 84 rc = spdk_bdev_set_opts(&bdev_opts);
7c673cae 85
11fdf7f2
TL
86 if (rc != 0) {
87 spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
88 "Pool size %" PRIu32 " too small for cache size %" PRIu32,
89 bdev_opts.bdev_io_pool_size, bdev_opts.bdev_io_cache_size);
7c673cae
FG
90 return;
91 }
92
11fdf7f2 93 w = spdk_jsonrpc_begin_result(request);
11fdf7f2
TL
94 spdk_json_write_bool(w, true);
95 spdk_jsonrpc_end_result(request, w);
7c673cae 96}
f67539c2
TL
97SPDK_RPC_REGISTER("bdev_set_options", rpc_bdev_set_options, SPDK_RPC_STARTUP)
98SPDK_RPC_REGISTER_ALIAS_DEPRECATED(bdev_set_options, set_bdev_options)