2016-06-15 17:30:29 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
2019-11-12 14:00:53 +00:00
|
|
|
* Copyright (c) Intel Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
|
2016-06-15 17:30:29 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2018-01-23 23:52:44 +00:00
|
|
|
#include <sys/file.h>
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-06-15 17:30:29 +00:00
|
|
|
|
|
|
|
#include "spdk/queue.h"
|
|
|
|
#include "spdk/rpc.h"
|
2016-08-18 19:52:48 +00:00
|
|
|
#include "spdk/env.h"
|
2016-06-15 17:30:29 +00:00
|
|
|
#include "spdk/log.h"
|
2017-02-01 18:14:03 +00:00
|
|
|
#include "spdk/string.h"
|
2018-05-04 01:39:27 +00:00
|
|
|
#include "spdk/util.h"
|
2019-03-21 22:02:04 +00:00
|
|
|
#include "spdk/version.h"
|
2016-06-15 17:30:29 +00:00
|
|
|
|
2016-12-13 23:22:11 +00:00
|
|
|
static struct sockaddr_un g_rpc_listen_addr_unix = {};
|
2018-08-30 05:59:59 +00:00
|
|
|
static char g_rpc_lock_path[sizeof(g_rpc_listen_addr_unix.sun_path) + sizeof(".lock")];
|
2018-01-23 23:52:44 +00:00
|
|
|
static int g_rpc_lock_fd = -1;
|
2016-12-13 23:22:11 +00:00
|
|
|
|
2016-06-15 17:30:29 +00:00
|
|
|
static struct spdk_jsonrpc_server *g_jsonrpc_server = NULL;
|
2018-05-02 04:28:57 +00:00
|
|
|
static uint32_t g_rpc_state;
|
2019-10-25 23:04:51 +00:00
|
|
|
static bool g_rpcs_correct = true;
|
2016-06-15 17:30:29 +00:00
|
|
|
|
|
|
|
struct spdk_rpc_method {
|
|
|
|
const char *name;
|
|
|
|
spdk_rpc_method_handler func;
|
|
|
|
SLIST_ENTRY(spdk_rpc_method) slist;
|
2018-05-02 04:28:57 +00:00
|
|
|
uint32_t state_mask;
|
2019-05-03 20:20:42 +00:00
|
|
|
bool is_deprecated;
|
|
|
|
struct spdk_rpc_method *is_alias_of;
|
|
|
|
bool deprecation_warning_printed;
|
2016-06-15 17:30:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static SLIST_HEAD(, spdk_rpc_method) g_rpc_methods = SLIST_HEAD_INITIALIZER(g_rpc_methods);
|
|
|
|
|
2018-05-02 04:28:57 +00:00
|
|
|
void
|
|
|
|
spdk_rpc_set_state(uint32_t state)
|
|
|
|
{
|
|
|
|
g_rpc_state = state;
|
|
|
|
}
|
|
|
|
|
2018-11-08 20:24:10 +00:00
|
|
|
uint32_t
|
|
|
|
spdk_rpc_get_state(void)
|
|
|
|
{
|
|
|
|
return g_rpc_state;
|
|
|
|
}
|
|
|
|
|
2019-05-03 20:28:43 +00:00
|
|
|
static struct spdk_rpc_method *
|
|
|
|
_get_rpc_method(const struct spdk_json_val *method)
|
|
|
|
{
|
|
|
|
struct spdk_rpc_method *m;
|
|
|
|
|
|
|
|
SLIST_FOREACH(m, &g_rpc_methods, slist) {
|
|
|
|
if (spdk_json_strequal(method, m->name)) {
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-05-03 20:34:51 +00:00
|
|
|
static struct spdk_rpc_method *
|
|
|
|
_get_rpc_method_raw(const char *method)
|
|
|
|
{
|
|
|
|
struct spdk_json_val method_val;
|
|
|
|
|
|
|
|
method_val.type = SPDK_JSON_VAL_STRING;
|
|
|
|
method_val.len = strlen(method);
|
|
|
|
method_val.start = (char *)method;
|
|
|
|
|
|
|
|
return _get_rpc_method(&method_val);
|
|
|
|
}
|
|
|
|
|
2016-06-15 17:30:29 +00:00
|
|
|
static void
|
2020-05-09 23:14:30 +00:00
|
|
|
jsonrpc_handler(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *method,
|
|
|
|
const struct spdk_json_val *params)
|
2016-06-15 17:30:29 +00:00
|
|
|
{
|
|
|
|
struct spdk_rpc_method *m;
|
|
|
|
|
2016-08-18 16:45:50 +00:00
|
|
|
assert(method != NULL);
|
2016-06-15 17:30:29 +00:00
|
|
|
|
2019-05-03 20:28:43 +00:00
|
|
|
m = _get_rpc_method(method);
|
|
|
|
if (m == NULL) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_METHOD_NOT_FOUND, "Method not found");
|
|
|
|
return;
|
2016-06-15 17:30:29 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 20:20:42 +00:00
|
|
|
if (m->is_alias_of != NULL) {
|
|
|
|
if (m->is_deprecated && !m->deprecation_warning_printed) {
|
|
|
|
SPDK_WARNLOG("RPC method %s is deprecated. Use %s instead.\n", m->name, m->is_alias_of->name);
|
|
|
|
m->deprecation_warning_printed = true;
|
|
|
|
}
|
|
|
|
m = m->is_alias_of;
|
|
|
|
}
|
|
|
|
|
2019-05-03 20:28:43 +00:00
|
|
|
if ((m->state_mask & g_rpc_state) == g_rpc_state) {
|
|
|
|
m->func(request, params);
|
|
|
|
} else {
|
2020-07-29 20:49:31 +00:00
|
|
|
if (g_rpc_state == SPDK_RPC_STARTUP) {
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request,
|
|
|
|
SPDK_JSONRPC_ERROR_INVALID_STATE,
|
|
|
|
"Method may only be called after "
|
|
|
|
"framework is initialized "
|
|
|
|
"using framework_start_init RPC.");
|
|
|
|
} else {
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request,
|
|
|
|
SPDK_JSONRPC_ERROR_INVALID_STATE,
|
|
|
|
"Method may only be called before "
|
|
|
|
"framework is initialized. "
|
|
|
|
"Use --wait-for-rpc command line "
|
|
|
|
"parameter and then issue this RPC "
|
|
|
|
"before the framework_start_init RPC.");
|
|
|
|
}
|
2019-05-03 20:28:43 +00:00
|
|
|
}
|
2016-06-15 17:30:29 +00:00
|
|
|
}
|
|
|
|
|
2017-06-15 21:48:48 +00:00
|
|
|
int
|
|
|
|
spdk_rpc_listen(const char *listen_addr)
|
2016-06-15 17:30:29 +00:00
|
|
|
{
|
2020-02-06 09:46:12 +00:00
|
|
|
int rc;
|
2016-06-15 17:30:29 +00:00
|
|
|
|
2016-12-13 23:22:11 +00:00
|
|
|
memset(&g_rpc_listen_addr_unix, 0, sizeof(g_rpc_listen_addr_unix));
|
|
|
|
|
2020-02-06 09:46:12 +00:00
|
|
|
g_rpc_listen_addr_unix.sun_family = AF_UNIX;
|
|
|
|
rc = snprintf(g_rpc_listen_addr_unix.sun_path,
|
|
|
|
sizeof(g_rpc_listen_addr_unix.sun_path),
|
|
|
|
"%s", listen_addr);
|
|
|
|
if (rc < 0 || (size_t)rc >= sizeof(g_rpc_listen_addr_unix.sun_path)) {
|
|
|
|
SPDK_ERRLOG("RPC Listen address Unix socket path too long\n");
|
|
|
|
g_rpc_listen_addr_unix.sun_path[0] = '\0';
|
|
|
|
return -1;
|
|
|
|
}
|
2016-12-13 23:22:11 +00:00
|
|
|
|
2020-02-06 09:46:12 +00:00
|
|
|
rc = snprintf(g_rpc_lock_path, sizeof(g_rpc_lock_path), "%s.lock",
|
|
|
|
g_rpc_listen_addr_unix.sun_path);
|
|
|
|
if (rc < 0 || (size_t)rc >= sizeof(g_rpc_lock_path)) {
|
|
|
|
SPDK_ERRLOG("RPC lock path too long\n");
|
|
|
|
g_rpc_listen_addr_unix.sun_path[0] = '\0';
|
|
|
|
g_rpc_lock_path[0] = '\0';
|
|
|
|
return -1;
|
|
|
|
}
|
2016-12-13 23:22:11 +00:00
|
|
|
|
2020-02-06 09:46:12 +00:00
|
|
|
g_rpc_lock_fd = open(g_rpc_lock_path, O_RDONLY | O_CREAT, 0600);
|
|
|
|
if (g_rpc_lock_fd == -1) {
|
|
|
|
SPDK_ERRLOG("Cannot open lock file %s: %s\n",
|
|
|
|
g_rpc_lock_path, spdk_strerror(errno));
|
|
|
|
g_rpc_listen_addr_unix.sun_path[0] = '\0';
|
|
|
|
g_rpc_lock_path[0] = '\0';
|
|
|
|
return -1;
|
|
|
|
}
|
2016-12-13 23:22:11 +00:00
|
|
|
|
2020-02-06 09:46:12 +00:00
|
|
|
rc = flock(g_rpc_lock_fd, LOCK_EX | LOCK_NB);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("RPC Unix domain socket path %s in use. Specify another.\n",
|
|
|
|
g_rpc_listen_addr_unix.sun_path);
|
|
|
|
g_rpc_listen_addr_unix.sun_path[0] = '\0';
|
|
|
|
g_rpc_lock_path[0] = '\0';
|
|
|
|
return -1;
|
2016-12-13 23:22:11 +00:00
|
|
|
}
|
2016-12-13 23:12:27 +00:00
|
|
|
|
2020-02-06 09:46:12 +00:00
|
|
|
/*
|
|
|
|
* Since we acquired the lock, it is safe to delete the Unix socket file
|
|
|
|
* if it still exists from a previous process.
|
|
|
|
*/
|
|
|
|
unlink(g_rpc_listen_addr_unix.sun_path);
|
|
|
|
|
|
|
|
g_jsonrpc_server = spdk_jsonrpc_server_listen(AF_UNIX, 0,
|
|
|
|
(struct sockaddr *)&g_rpc_listen_addr_unix,
|
|
|
|
sizeof(g_rpc_listen_addr_unix),
|
|
|
|
jsonrpc_handler);
|
2016-06-15 17:30:29 +00:00
|
|
|
if (g_jsonrpc_server == NULL) {
|
|
|
|
SPDK_ERRLOG("spdk_jsonrpc_server_listen() failed\n");
|
2020-02-06 09:46:12 +00:00
|
|
|
close(g_rpc_lock_fd);
|
|
|
|
g_rpc_lock_fd = -1;
|
|
|
|
unlink(g_rpc_lock_path);
|
|
|
|
g_rpc_lock_path[0] = '\0';
|
2017-06-15 21:48:48 +00:00
|
|
|
return -1;
|
2016-06-15 17:30:29 +00:00
|
|
|
}
|
|
|
|
|
2017-06-15 21:48:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_rpc_accept(void)
|
|
|
|
{
|
|
|
|
spdk_jsonrpc_server_poll(g_jsonrpc_server);
|
2016-06-15 17:30:29 +00:00
|
|
|
}
|
|
|
|
|
2017-06-15 21:48:48 +00:00
|
|
|
void
|
2018-05-02 04:28:57 +00:00
|
|
|
spdk_rpc_register_method(const char *method, spdk_rpc_method_handler func, uint32_t state_mask)
|
2016-06-15 17:30:29 +00:00
|
|
|
{
|
2017-06-15 21:48:48 +00:00
|
|
|
struct spdk_rpc_method *m;
|
2017-05-23 04:31:24 +00:00
|
|
|
|
2019-05-03 20:34:51 +00:00
|
|
|
m = _get_rpc_method_raw(method);
|
|
|
|
if (m != NULL) {
|
2019-10-25 23:04:51 +00:00
|
|
|
SPDK_ERRLOG("duplicate RPC %s registered...\n", method);
|
|
|
|
g_rpcs_correct = false;
|
2019-05-03 20:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-15 21:48:48 +00:00
|
|
|
m = calloc(1, sizeof(struct spdk_rpc_method));
|
|
|
|
assert(m != NULL);
|
|
|
|
|
|
|
|
m->name = strdup(method);
|
|
|
|
assert(m->name != NULL);
|
|
|
|
|
|
|
|
m->func = func;
|
2018-05-02 04:28:57 +00:00
|
|
|
m->state_mask = state_mask;
|
2017-06-15 21:48:48 +00:00
|
|
|
|
|
|
|
/* TODO: use a hash table or sorted list */
|
2019-05-03 20:20:42 +00:00
|
|
|
SLIST_INSERT_HEAD(&g_rpc_methods, m, slist);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_rpc_register_alias_deprecated(const char *method, const char *alias)
|
|
|
|
{
|
|
|
|
struct spdk_rpc_method *m, *base;
|
|
|
|
|
|
|
|
base = _get_rpc_method_raw(method);
|
|
|
|
if (base == NULL) {
|
|
|
|
SPDK_ERRLOG("cannot create alias %s - method %s does not exist\n",
|
|
|
|
alias, method);
|
2019-10-25 23:04:51 +00:00
|
|
|
g_rpcs_correct = false;
|
2019-05-03 20:20:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base->is_alias_of != NULL) {
|
|
|
|
SPDK_ERRLOG("cannot create alias %s of alias %s\n", alias, method);
|
2019-10-25 23:04:51 +00:00
|
|
|
g_rpcs_correct = false;
|
2019-05-03 20:20:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m = calloc(1, sizeof(struct spdk_rpc_method));
|
|
|
|
assert(m != NULL);
|
|
|
|
|
|
|
|
m->name = strdup(alias);
|
|
|
|
assert(m->name != NULL);
|
|
|
|
|
|
|
|
m->is_alias_of = base;
|
|
|
|
m->is_deprecated = true;
|
2019-08-19 12:14:37 +00:00
|
|
|
m->state_mask = base->state_mask;
|
2019-05-03 20:20:42 +00:00
|
|
|
|
|
|
|
/* TODO: use a hash table or sorted list */
|
2017-06-15 21:48:48 +00:00
|
|
|
SLIST_INSERT_HEAD(&g_rpc_methods, m, slist);
|
2016-06-15 17:30:29 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 23:04:51 +00:00
|
|
|
bool
|
|
|
|
spdk_rpc_verify_methods(void)
|
|
|
|
{
|
|
|
|
return g_rpcs_correct;
|
|
|
|
}
|
|
|
|
|
2018-10-23 16:44:24 +00:00
|
|
|
int
|
|
|
|
spdk_rpc_is_method_allowed(const char *method, uint32_t state_mask)
|
|
|
|
{
|
|
|
|
struct spdk_rpc_method *m;
|
|
|
|
|
|
|
|
SLIST_FOREACH(m, &g_rpc_methods, slist) {
|
|
|
|
if (strcmp(m->name, method) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m->state_mask & state_mask) == state_mask) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2017-06-15 21:48:48 +00:00
|
|
|
void
|
|
|
|
spdk_rpc_close(void)
|
2016-09-26 22:08:21 +00:00
|
|
|
{
|
2017-02-23 21:09:24 +00:00
|
|
|
if (g_jsonrpc_server) {
|
2017-11-20 21:13:43 +00:00
|
|
|
if (g_rpc_listen_addr_unix.sun_path[0]) {
|
|
|
|
/* Delete the Unix socket file */
|
|
|
|
unlink(g_rpc_listen_addr_unix.sun_path);
|
2019-11-27 19:15:22 +00:00
|
|
|
g_rpc_listen_addr_unix.sun_path[0] = '\0';
|
2017-11-20 21:13:43 +00:00
|
|
|
}
|
|
|
|
|
2017-02-23 21:09:24 +00:00
|
|
|
spdk_jsonrpc_server_shutdown(g_jsonrpc_server);
|
2017-11-28 17:58:42 +00:00
|
|
|
g_jsonrpc_server = NULL;
|
2018-01-23 23:52:44 +00:00
|
|
|
|
|
|
|
if (g_rpc_lock_fd != -1) {
|
|
|
|
close(g_rpc_lock_fd);
|
|
|
|
g_rpc_lock_fd = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_rpc_lock_path[0]) {
|
|
|
|
unlink(g_rpc_lock_path);
|
|
|
|
g_rpc_lock_path[0] = '\0';
|
|
|
|
}
|
2017-02-23 21:09:24 +00:00
|
|
|
}
|
2016-06-15 17:30:29 +00:00
|
|
|
}
|
2017-07-19 23:20:01 +00:00
|
|
|
|
2019-05-03 20:59:01 +00:00
|
|
|
struct rpc_get_methods {
|
2018-05-04 01:39:27 +00:00
|
|
|
bool current;
|
2019-08-19 12:14:37 +00:00
|
|
|
bool include_aliases;
|
2018-05-04 01:39:27 +00:00
|
|
|
};
|
|
|
|
|
2019-05-03 20:59:01 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_get_methods_decoders[] = {
|
|
|
|
{"current", offsetof(struct rpc_get_methods, current), spdk_json_decode_bool, true},
|
2019-08-19 12:14:37 +00:00
|
|
|
{"include_aliases", offsetof(struct rpc_get_methods, include_aliases), spdk_json_decode_bool, true},
|
2018-05-04 01:39:27 +00:00
|
|
|
};
|
2017-07-19 23:20:01 +00:00
|
|
|
|
|
|
|
static void
|
2020-05-09 23:14:30 +00:00
|
|
|
rpc_get_methods(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
|
2017-07-19 23:20:01 +00:00
|
|
|
{
|
2019-05-03 20:59:01 +00:00
|
|
|
struct rpc_get_methods req = {};
|
2017-07-19 23:20:01 +00:00
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
struct spdk_rpc_method *m;
|
|
|
|
|
|
|
|
if (params != NULL) {
|
2019-05-03 20:59:01 +00:00
|
|
|
if (spdk_json_decode_object(params, rpc_get_methods_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_get_methods_decoders), &req)) {
|
2018-05-04 01:39:27 +00:00
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
return;
|
|
|
|
}
|
2017-07-19 23:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
spdk_json_write_array_begin(w);
|
|
|
|
SLIST_FOREACH(m, &g_rpc_methods, slist) {
|
2019-08-19 12:14:37 +00:00
|
|
|
if (m->is_alias_of != NULL && !req.include_aliases) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-04 01:39:27 +00:00
|
|
|
if (req.current && ((m->state_mask & g_rpc_state) != g_rpc_state)) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-07-19 23:20:01 +00:00
|
|
|
spdk_json_write_string(w, m->name);
|
|
|
|
}
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
2020-05-09 23:14:30 +00:00
|
|
|
SPDK_RPC_REGISTER("rpc_get_methods", rpc_get_methods, SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
|
2019-05-03 20:59:01 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(rpc_get_methods, get_rpc_methods)
|
2019-03-21 22:02:04 +00:00
|
|
|
|
|
|
|
static void
|
2020-05-09 23:14:30 +00:00
|
|
|
rpc_spdk_get_version(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
|
2019-03-21 22:02:04 +00:00
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
if (params != NULL) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
2019-09-19 21:32:01 +00:00
|
|
|
"spdk_get_version method requires no parameters");
|
2019-05-21 09:48:14 +00:00
|
|
|
return;
|
2019-03-21 22:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
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);
|
2019-11-12 14:00:53 +00:00
|
|
|
#ifdef SPDK_GIT_COMMIT
|
|
|
|
spdk_json_write_named_string_fmt(w, "commit", "%s", SPDK_GIT_COMMIT_STRING);
|
|
|
|
#endif
|
2019-03-21 22:02:04 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
2020-05-09 23:14:30 +00:00
|
|
|
SPDK_RPC_REGISTER("spdk_get_version", rpc_spdk_get_version,
|
2019-05-06 03:54:05 +00:00
|
|
|
SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
|
2019-09-19 21:32:01 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(spdk_get_version, get_spdk_version)
|