diff --git a/doc/jsonrpc.md b/doc/jsonrpc.md index b853dfdc2..461278695 100644 --- a/doc/jsonrpc.md +++ b/doc/jsonrpc.md @@ -7467,6 +7467,45 @@ Example response: } ~~~ +## sock_set_default_impl {#rpc_sock_set_default_impl} + +Set the default sock implementation. + +### Parameters + +Name | Optional | Type | Description +----------------------- | -------- | ----------- | ----------- +impl_name | Required | string | Name of socket implementation, e.g. posix + +### Response + +True if the default socket layer configuration was set successfully. + +### Example + +Example request: + +~~~ +{ + "jsonrpc": "2.0", + "method": "sock_set_default_impl", + "id": 1, + "params": { + "impl_name": "posix" + } +} +~~~ + +Example response: + +~~~ +{ + "jsonrpc": "2.0", + "id": 1, + "result": true +} +~~~ + # Miscellaneous RPC commands ## bdev_nvme_send_cmd {#rpc_bdev_nvme_send_cmd} diff --git a/lib/sock/sock.c b/lib/sock/sock.c index 0b744e472..c99c4ecd5 100644 --- a/lib/sock/sock.c +++ b/lib/sock/sock.c @@ -803,6 +803,15 @@ spdk_sock_write_config_json(struct spdk_json_write_ctx *w) spdk_json_write_array_begin(w); + if (g_default_impl) { + spdk_json_write_object_begin(w); + spdk_json_write_named_string(w, "method", "sock_set_default_impl"); + spdk_json_write_named_object_begin(w, "params"); + spdk_json_write_named_string(w, "impl_name", g_default_impl->name); + spdk_json_write_object_end(w); + spdk_json_write_object_end(w); + } + STAILQ_FOREACH(impl, &g_net_impls, link) { if (!impl->get_opts) { continue; diff --git a/lib/sock/sock_rpc.c b/lib/sock/sock_rpc.c index c4e3e653e..ae434d525 100644 --- a/lib/sock/sock_rpc.c +++ b/lib/sock/sock_rpc.c @@ -170,3 +170,35 @@ rpc_sock_impl_set_options(struct spdk_jsonrpc_request *request, free(opts.impl_name); } SPDK_RPC_REGISTER("sock_impl_set_options", rpc_sock_impl_set_options, SPDK_RPC_STARTUP) + +static void +rpc_sock_set_default_impl(struct spdk_jsonrpc_request *request, + const struct spdk_json_val *params) +{ + char *impl_name = NULL; + struct spdk_json_write_ctx *w; + int rc; + + /* Reuse get_opts decoder */ + if (spdk_json_decode_object(params, rpc_sock_impl_get_opts_decoders, + SPDK_COUNTOF(rpc_sock_impl_get_opts_decoders), &impl_name)) { + SPDK_ERRLOG("spdk_json_decode_object() failed\n"); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + "Invalid parameters"); + return; + } + + rc = spdk_sock_set_default_impl(impl_name); + if (rc) { + free(impl_name); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + "Invalid parameters"); + return; + } + + w = spdk_jsonrpc_begin_result(request); + spdk_json_write_bool(w, true); + spdk_jsonrpc_end_result(request, w); + free(impl_name); +} +SPDK_RPC_REGISTER("sock_set_default_impl", rpc_sock_set_default_impl, SPDK_RPC_STARTUP) diff --git a/scripts/rpc.py b/scripts/rpc.py index 0abefd189..12a55ae7e 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -2567,6 +2567,14 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse p.set_defaults(func=sock_impl_set_options, enable_recv_pipe=None, enable_zerocopy_send=None, enable_quickack=None, enable_placement_id=None) + def sock_set_default_impl(args): + print_json(rpc.sock.sock_set_default_impl(args.client, + impl_name=args.impl)) + + p = subparsers.add_parser('sock_set_default_impl', help="""Set the default sock implementation""") + p.add_argument('-i', '--impl', help='Socket implementation name, e.g. posix', required=True) + p.set_defaults(func=sock_set_default_impl) + def check_called_name(name): if name in deprecated_aliases: print("{} is deprecated, use {} instead.".format(name, deprecated_aliases[name]), file=sys.stderr) diff --git a/scripts/rpc/sock.py b/scripts/rpc/sock.py index 94f9b8293..f606cc170 100644 --- a/scripts/rpc/sock.py +++ b/scripts/rpc/sock.py @@ -47,3 +47,16 @@ def sock_impl_set_options(client, params['enable_placement_id'] = enable_placement_id return client.call('sock_impl_set_options', params) + + +def sock_set_default_impl(client, impl_name=None): + """Set the default socket implementation. + + Args: + impl_name: name of socket implementation, e.g. posix + """ + params = {} + + params['impl_name'] = impl_name + + return client.call('sock_set_default_impl', params) diff --git a/test/json_config/config_filter.py b/test/json_config/config_filter.py index cde2e24f9..6c6d2748c 100755 --- a/test/json_config/config_filter.py +++ b/test/json_config/config_filter.py @@ -32,6 +32,7 @@ def filter_methods(do_remove_global_rpcs): 'bdev_nvme_set_options', 'bdev_nvme_set_hotplug', 'sock_impl_set_options', + 'sock_set_default_impl', ] data = json.loads(sys.stdin.read())