Commit 89d9fe55 authored by Alexey Marchuk's avatar Alexey Marchuk Committed by Tomasz Zawadzki
Browse files

sock/rpc: Add sock_set_default_impl RPC call

parent 079f2d0a
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -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}
+9 −0
Original line number Diff line number Diff line
@@ -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;
+32 −0
Original line number Diff line number Diff line
@@ -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)
+8 −0
Original line number Diff line number Diff line
@@ -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)
+13 −0
Original line number Diff line number Diff line
@@ -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)
Loading