Commit fe22b505 authored by Krzysztof Karas's avatar Krzysztof Karas Committed by Tomasz Zawadzki
Browse files

sock: add sock_get_default_impl RPC



Default socket implementation may be set without explicitly calling
`sock_set_default_impl` RPC (POSIX impl is registered as default),
but we currently have no way of letting user know what type of
implementation is the default one via RPC.
Considering above and that we already have `set` option, we should
add `sock_get_default_impl`, so users can check the socket impl.

Fixes #3280

Change-Id: I50145770a74874f3e19f1f5685c9717bcb82672e
Signed-off-by: default avatarKrzysztof Karas <krzysztof.karas@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22140


Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent abd932d6
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -12196,6 +12196,42 @@ Example response:
}
~~~

### sock_get_default_impl {#rpc_sock_get_default_impl}

Get the name of the default sock implementation.

#### Parameters

This function has no parameters.

#### Response

The name of the current default socket implementation.

#### Example

Example request:

~~~json
{
  "jsonrpc": "2.0",
  "method": "sock_get_default_impl",
  "id": 1
}
~~~

Example response:

~~~json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "impl_name": "posix"
  }
}
~~~

## Miscellaneous RPC commands

### bdev_nvme_send_cmd {#rpc_bdev_nvme_send_cmd}
+28 −0
Original line number Diff line number Diff line
@@ -191,3 +191,31 @@ rpc_sock_set_default_impl(struct spdk_jsonrpc_request *request,
	free(impl_name);
}
SPDK_RPC_REGISTER("sock_set_default_impl", rpc_sock_set_default_impl, SPDK_RPC_STARTUP)

static void
rpc_sock_get_default_impl(struct spdk_jsonrpc_request *request,
			  const struct spdk_json_val *params)
{
	const char *impl_name = spdk_sock_get_default_impl();
	struct spdk_json_write_ctx *w;

	if (params) {
		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
						 "sock_get_default_impl requires no parameters");
		return;
	}

	if (!impl_name) {
		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
						 "No registered socket implementations found");
		return;
	}

	w = spdk_jsonrpc_begin_result(request);
	spdk_json_write_object_begin(w);
	spdk_json_write_named_string(w, "impl_name", impl_name);
	spdk_json_write_object_end(w);
	spdk_jsonrpc_end_result(request, w);
}
SPDK_RPC_REGISTER("sock_get_default_impl", rpc_sock_get_default_impl,
		  SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
+6 −0
Original line number Diff line number Diff line
@@ -81,3 +81,9 @@ def sock_set_default_impl(client, impl_name=None):
    params['impl_name'] = impl_name

    return client.call('sock_set_default_impl', params)


def sock_get_default_impl(client):
    "Get the default socket implementation name."

    return client.call('sock_get_default_impl')
+6 −0
Original line number Diff line number Diff line
@@ -3519,6 +3519,12 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
    p.add_argument('-i', '--impl', help='Socket implementation name, e.g. posix', required=True)
    p.set_defaults(func=sock_set_default_impl)

    def sock_get_default_impl(args):
        print_json(rpc.sock.sock_get_default_impl(args.client))

    p = subparsers.add_parser('sock_get_default_impl', help="Get the default sock implementation name")
    p.set_defaults(func=sock_get_default_impl)

    def framework_get_pci_devices(args):
        def splitbuf(buf, step):
            return [buf[i:i+step] for i in range(0, len(buf), step)]