diff --git a/CHANGELOG.md b/CHANGELOG.md index b767456a1..9b705a868 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,10 @@ spdk_env_fini() and spdk_env_dpdk_post_fini() were added to release any resource allocated by spdk_env_init() or spdk_env_dpdk_post_init() respectively. It is expected that common usage of those functions is to call them just before terminating the process. +### rpc + +New `get_spdk_version` RPC method is introduced to get version info of the running SPDK application. + ## v19.01: ### ocf bdev diff --git a/doc/jsonrpc.md b/doc/jsonrpc.md index 725780bde..26c61f288 100644 --- a/doc/jsonrpc.md +++ b/doc/jsonrpc.md @@ -5074,3 +5074,43 @@ Example response: } ~~~ + +## get_spdk_version {#rpc_get_spdk_version} + +Get the version info of the running SPDK application. + +### Parameters + +This method has no parameters. + +### Response + +The response is the version number including major version number, minor version number, patch level number and suffix string. + +### Example + +Example request: +~~ +{ + "jsonrpc": "2.0", + "id": 1, + "method": "get_spdk_version" +} +~~ + +Example response: +~~ +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "version": "19.04-pre", + "fields" : { + "major": 19, + "minor": 4, + "patch": 0, + "suffix": "-pre" + } + } +} +~~ diff --git a/lib/rpc/rpc.c b/lib/rpc/rpc.c index ea8175df0..15beac286 100644 --- a/lib/rpc/rpc.c +++ b/lib/rpc/rpc.c @@ -41,6 +41,7 @@ #include "spdk/log.h" #include "spdk/string.h" #include "spdk/util.h" +#include "spdk/version.h" #define RPC_DEFAULT_PORT "5260" @@ -309,3 +310,38 @@ spdk_rpc_get_rpc_methods(struct spdk_jsonrpc_request *request, spdk_jsonrpc_end_result(request, w); } SPDK_RPC_REGISTER("get_rpc_methods", spdk_rpc_get_rpc_methods, SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME) + +static void +spdk_rpc_get_version(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params) +{ + struct spdk_json_write_ctx *w; + + if (params != NULL) { + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + "get_spdk_version method requires no parameters"); + } + + w = spdk_jsonrpc_begin_result(request); + if (w == NULL) { + return; + } + + spdk_json_write_object_begin(w); + + spdk_json_write_named_string_fmt(w, "version", "%s", SPDK_VERSION_STRING); + + spdk_json_write_named_object_begin(w, "fields"); + spdk_json_write_named_uint32(w, "major", SPDK_VERSION_MAJOR); + spdk_json_write_named_uint32(w, "minor", SPDK_VERSION_MINOR); + + spdk_json_write_named_uint32(w, "patch", SPDK_VERSION_PATCH); + + spdk_json_write_named_string_fmt(w, "suffix", "%s", SPDK_VERSION_SUFFIX); + + spdk_json_write_object_end(w); + + spdk_json_write_object_end(w); + + spdk_jsonrpc_end_result(request, w); +} +SPDK_RPC_REGISTER("get_spdk_version", spdk_rpc_get_version, SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME) diff --git a/scripts/rpc.py b/scripts/rpc.py index ac1035239..8f1d678d3 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -54,6 +54,12 @@ if __name__ == "__main__": p.add_argument('-c', '--current', help='Get list of RPC methods only callable in the current state.', action='store_true') p.set_defaults(func=get_rpc_methods) + def get_spdk_version(args): + print(rpc.get_spdk_version(args.client)) + + p = subparsers.add_parser('get_spdk_version', help='Get SPDK version') + p.set_defaults(func=get_spdk_version) + def save_config(args): rpc.save_config(args.client, sys.stdout, diff --git a/scripts/rpc/__init__.py b/scripts/rpc/__init__.py index f7e92f707..3b65af317 100644 --- a/scripts/rpc/__init__.py +++ b/scripts/rpc/__init__.py @@ -41,6 +41,11 @@ def get_rpc_methods(client, current=None): return client.call('get_rpc_methods', params) +def get_spdk_version(client): + """Get SPDK version""" + return client.call('get_spdk_version') + + def _json_dump(config, fd, indent): if indent is None: indent = 2