4 * Copyright (c) 2020 Mellanox Technologies LTD. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "spdk/sock.h"
36 #include "spdk/util.h"
37 #include "spdk/string.h"
39 #include "spdk_internal/log.h"
42 static const struct spdk_json_object_decoder rpc_sock_impl_get_opts_decoders
[] = {
43 { "impl_name", 0, spdk_json_decode_string
, false },
47 rpc_sock_impl_get_options(struct spdk_jsonrpc_request
*request
,
48 const struct spdk_json_val
*params
)
50 char *impl_name
= NULL
;
51 struct spdk_sock_impl_opts sock_opts
= {};
52 struct spdk_json_write_ctx
*w
;
56 if (spdk_json_decode_object(params
, rpc_sock_impl_get_opts_decoders
,
57 SPDK_COUNTOF(rpc_sock_impl_get_opts_decoders
), &impl_name
)) {
58 SPDK_ERRLOG("spdk_json_decode_object() failed\n");
59 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INVALID_PARAMS
,
60 "Invalid parameters");
64 len
= sizeof(sock_opts
);
65 rc
= spdk_sock_impl_get_opts(impl_name
, &sock_opts
, &len
);
67 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INVALID_PARAMS
,
68 "Invalid parameters");
72 w
= spdk_jsonrpc_begin_result(request
);
73 spdk_json_write_object_begin(w
);
74 spdk_json_write_named_uint32(w
, "recv_buf_size", sock_opts
.recv_buf_size
);
75 spdk_json_write_named_uint32(w
, "send_buf_size", sock_opts
.send_buf_size
);
76 spdk_json_write_named_bool(w
, "enable_recv_pipe", sock_opts
.enable_recv_pipe
);
77 spdk_json_write_named_bool(w
, "enable_zerocopy_send", sock_opts
.enable_zerocopy_send
);
78 spdk_json_write_object_end(w
);
79 spdk_jsonrpc_end_result(request
, w
);
82 SPDK_RPC_REGISTER("sock_impl_get_options", rpc_sock_impl_get_options
,
83 SPDK_RPC_STARTUP
| SPDK_RPC_RUNTIME
)
85 struct spdk_rpc_sock_impl_set_opts
{
87 struct spdk_sock_impl_opts sock_opts
;
90 static const struct spdk_json_object_decoder rpc_sock_impl_set_opts_decoders
[] = {
92 "impl_name", offsetof(struct spdk_rpc_sock_impl_set_opts
, impl_name
),
93 spdk_json_decode_string
, false
96 "recv_buf_size", offsetof(struct spdk_rpc_sock_impl_set_opts
, sock_opts
.recv_buf_size
),
97 spdk_json_decode_uint32
, true
100 "send_buf_size", offsetof(struct spdk_rpc_sock_impl_set_opts
, sock_opts
.send_buf_size
),
101 spdk_json_decode_uint32
, true
104 "enable_recv_pipe", offsetof(struct spdk_rpc_sock_impl_set_opts
, sock_opts
.enable_recv_pipe
),
105 spdk_json_decode_bool
, true
108 "enable_zerocopy_send", offsetof(struct spdk_rpc_sock_impl_set_opts
, sock_opts
.enable_zerocopy_send
),
109 spdk_json_decode_bool
, true
114 rpc_sock_impl_set_options(struct spdk_jsonrpc_request
*request
,
115 const struct spdk_json_val
*params
)
117 struct spdk_rpc_sock_impl_set_opts opts
= {};
118 struct spdk_json_write_ctx
*w
;
123 if (spdk_json_decode_object(params
, rpc_sock_impl_set_opts_decoders
,
124 SPDK_COUNTOF(rpc_sock_impl_set_opts_decoders
), &opts
)) {
125 SPDK_ERRLOG("spdk_json_decode_object() failed\n");
126 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INVALID_PARAMS
,
127 "Invalid parameters");
131 /* Retrieve default opts for requested socket implementation */
132 len
= sizeof(opts
.sock_opts
);
133 rc
= spdk_sock_impl_get_opts(opts
.impl_name
, &opts
.sock_opts
, &len
);
135 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INVALID_PARAMS
,
136 "Invalid parameters");
141 if (spdk_json_decode_object(params
, rpc_sock_impl_set_opts_decoders
,
142 SPDK_COUNTOF(rpc_sock_impl_set_opts_decoders
), &opts
)) {
143 SPDK_ERRLOG("spdk_json_decode_object() failed\n");
144 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INVALID_PARAMS
,
145 "Invalid parameters");
149 rc
= spdk_sock_impl_set_opts(opts
.impl_name
, &opts
.sock_opts
, sizeof(opts
.sock_opts
));
151 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INVALID_PARAMS
,
152 "Invalid parameters");
156 w
= spdk_jsonrpc_begin_result(request
);
157 spdk_json_write_bool(w
, true);
158 spdk_jsonrpc_end_result(request
, w
);
159 free(opts
.impl_name
);
161 SPDK_RPC_REGISTER("sock_impl_set_options", rpc_sock_impl_set_options
, SPDK_RPC_STARTUP
)