jsonrpc: modify API to pass request to handler
This will enable asynchronous request handling in a future patch, and it also removes the need for the RPC handlers to know about request id and the JSON-RPC rules about notification-only requests. Change-Id: I25aaa8e48bff8d5594ffcccecb61842b1e31ec3c Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-on: https://review.gerrithub.io/368225 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
26d6770f1c
commit
2bdec64fbf
@ -146,24 +146,23 @@ dump_nvmf_subsystem(struct spdk_json_write_ctx *w, struct nvmf_tgt_subsystem *tg
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_rpc_get_nvmf_subsystems(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_get_nvmf_subsystems(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct nvmf_tgt_subsystem *tgt_subsystem;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"get_nvmf_subsystems requires no parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
tgt_subsystem = nvmf_tgt_subsystem_first();
|
||||
while (tgt_subsystem) {
|
||||
@ -171,7 +170,7 @@ spdk_rpc_get_nvmf_subsystems(struct spdk_jsonrpc_server_conn *conn,
|
||||
tgt_subsystem = nvmf_tgt_subsystem_next(tgt_subsystem);
|
||||
}
|
||||
spdk_json_write_array_end(w);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
SPDK_RPC_REGISTER("get_nvmf_subsystems", spdk_rpc_get_nvmf_subsystems)
|
||||
|
||||
@ -310,9 +309,8 @@ static const struct spdk_json_object_decoder rpc_subsystem_decoders[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_construct_nvmf_subsystem(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_construct_nvmf_subsystem(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_subsystem req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -338,13 +336,17 @@ spdk_rpc_construct_nvmf_subsystem(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_subsystem(&req);
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_subsystem(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_nvmf_subsystem", spdk_rpc_construct_nvmf_subsystem)
|
||||
@ -364,9 +366,8 @@ static const struct spdk_json_object_decoder rpc_delete_subsystem_decoders[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_delete_nvmf_subsystem(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_delete_nvmf_subsystem(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_delete_subsystem req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -390,17 +391,17 @@ spdk_rpc_delete_nvmf_subsystem(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_delete_subsystem(&req);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_delete_subsystem(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("delete_nvmf_subsystem", spdk_rpc_delete_nvmf_subsystem)
|
||||
|
@ -50,7 +50,7 @@
|
||||
#define SPDK_JSONRPC_ERROR_INTERNAL_ERROR -32603
|
||||
|
||||
struct spdk_jsonrpc_server;
|
||||
struct spdk_jsonrpc_server_conn;
|
||||
struct spdk_jsonrpc_request;
|
||||
|
||||
/**
|
||||
* User callback to handle a single JSON-RPC request.
|
||||
@ -59,10 +59,9 @@ struct spdk_jsonrpc_server_conn;
|
||||
* spdk_jsonrpc_send_error_response().
|
||||
*/
|
||||
typedef void (*spdk_jsonrpc_handle_request_fn)(
|
||||
struct spdk_jsonrpc_server_conn *conn,
|
||||
struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *method,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id);
|
||||
const struct spdk_json_val *params);
|
||||
|
||||
struct spdk_jsonrpc_server *spdk_jsonrpc_server_listen(int domain, int protocol,
|
||||
struct sockaddr *listen_addr, socklen_t addrlen, spdk_jsonrpc_handle_request_fn handle_request);
|
||||
@ -71,11 +70,37 @@ int spdk_jsonrpc_server_poll(struct spdk_jsonrpc_server *server);
|
||||
|
||||
void spdk_jsonrpc_server_shutdown(struct spdk_jsonrpc_server *server);
|
||||
|
||||
struct spdk_json_write_ctx *spdk_jsonrpc_begin_result(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *id);
|
||||
void spdk_jsonrpc_end_result(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_write_ctx *w);
|
||||
/**
|
||||
* Begin building a response to a JSON-RPC request.
|
||||
*
|
||||
* \param request JSON-RPC request to respond to.
|
||||
* \return JSON write context to write the response object to, or NULL if no response is necessary.
|
||||
*
|
||||
* If this function returns non-NULL, the user must call spdk_jsonrpc_end_result() on the request
|
||||
* after writing the desired response object to the spdk_json_write_ctx.
|
||||
*/
|
||||
struct spdk_json_write_ctx *spdk_jsonrpc_begin_result(struct spdk_jsonrpc_request *request);
|
||||
|
||||
void spdk_jsonrpc_send_error_response(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *id, int error_code, const char *msg);
|
||||
/**
|
||||
* Complete and send a JSON-RPC response.
|
||||
*
|
||||
* \param request Request to complete the response for.
|
||||
* \param w JSON write context returned from spdk_jsonrpc_begin_result().
|
||||
*/
|
||||
void spdk_jsonrpc_end_result(struct spdk_jsonrpc_request *request, struct spdk_json_write_ctx *w);
|
||||
|
||||
/**
|
||||
* Send an error response to a JSON-RPC request.
|
||||
*
|
||||
* \param request JSON-RPC request to respond to.
|
||||
* \param error_code Integer error code to return (may be one of the SPDK_JSONRPC_ERROR_ errors,
|
||||
* or a custom error code).
|
||||
* \param msg String error message to return.
|
||||
*
|
||||
* This is shorthand for spdk_jsonrpc_begin_result() + spdk_jsonrpc_end_result() with an error
|
||||
* object.
|
||||
*/
|
||||
void spdk_jsonrpc_send_error_response(struct spdk_jsonrpc_request *request,
|
||||
int error_code, const char *msg);
|
||||
|
||||
#endif
|
||||
|
@ -42,9 +42,8 @@ int spdk_rpc_listen(const char *listen_addr);
|
||||
void spdk_rpc_accept(void);
|
||||
void spdk_rpc_close(void);
|
||||
|
||||
typedef void (*spdk_rpc_method_handler)(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id);
|
||||
typedef void (*spdk_rpc_method_handler)(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params);
|
||||
|
||||
void spdk_rpc_register_method(const char *method, spdk_rpc_method_handler func);
|
||||
|
||||
|
@ -55,9 +55,8 @@ static const struct spdk_json_object_decoder rpc_construct_aio_decoders[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_construct_aio_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_construct_aio_bdev(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_construct_aio req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -77,19 +76,19 @@ spdk_rpc_construct_aio_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_construct_aio(&req);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
spdk_json_write_string(w, spdk_bdev_get_name(bdev));
|
||||
spdk_json_write_array_end(w);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_construct_aio(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_aio_bdev", spdk_rpc_construct_aio_bdev)
|
||||
|
@ -77,9 +77,8 @@ static const struct spdk_json_object_decoder rpc_construct_error_bdev_decoders[]
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_construct_error_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_construct_error_bdev(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_construct_error_bdev req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -103,21 +102,21 @@ spdk_rpc_construct_error_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
free_rpc_construct_error_bdev(&req);
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
|
||||
free_rpc_construct_error_bdev(&req);
|
||||
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_construct_error_bdev(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_error_bdev", spdk_rpc_construct_error_bdev)
|
||||
@ -142,9 +141,8 @@ free_rpc_error_information(struct rpc_error_information *p)
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_rpc_bdev_inject_error(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_bdev_inject_error(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_error_information req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -170,17 +168,17 @@ spdk_rpc_bdev_inject_error(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_error_information(&req);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_error_information(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("bdev_inject_error", spdk_rpc_bdev_inject_error)
|
||||
|
@ -48,9 +48,8 @@ static const struct spdk_json_object_decoder rpc_construct_malloc_decoders[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_construct_malloc_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_construct_malloc_bdev(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_construct_malloc req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -68,18 +67,18 @@ spdk_rpc_construct_malloc_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
spdk_json_write_string(w, spdk_bdev_get_name(bdev));
|
||||
spdk_json_write_array_end(w);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_malloc_bdev", spdk_rpc_construct_malloc_bdev)
|
||||
|
@ -52,9 +52,8 @@ static const struct spdk_json_object_decoder rpc_construct_null_decoders[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_construct_null_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_construct_null_bdev(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_construct_null req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -72,21 +71,21 @@ spdk_rpc_construct_null_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
free(req.name);
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
spdk_json_write_string(w, bdev->name);
|
||||
spdk_json_write_array_end(w);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
free(req.name);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free(req.name);
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_null_bdev", spdk_rpc_construct_null_bdev)
|
||||
|
@ -74,9 +74,8 @@ static const struct spdk_json_object_decoder rpc_construct_nvme_decoders[] = {
|
||||
#define NVME_MAX_BLOCKDEVS_PER_RPC 32
|
||||
|
||||
static void
|
||||
spdk_rpc_construct_nvme_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_construct_nvme_bdev(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_construct_nvme req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -127,25 +126,25 @@ spdk_rpc_construct_nvme_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
free_rpc_construct_nvme(&req);
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
for (i = 0; i < count; i++) {
|
||||
spdk_json_write_string(w, names[i]);
|
||||
}
|
||||
spdk_json_write_array_end(w);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
|
||||
free_rpc_construct_nvme(&req);
|
||||
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_construct_nvme(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_nvme_bdev", spdk_rpc_construct_nvme_bdev)
|
||||
|
@ -57,9 +57,8 @@ static const struct spdk_json_object_decoder rpc_construct_rbd_decoders[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_construct_rbd_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_construct_rbd_bdev(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_construct_rbd req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -79,19 +78,19 @@ spdk_rpc_construct_rbd_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_construct_rbd(&req);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
spdk_json_write_string(w, spdk_bdev_get_name(bdev));
|
||||
spdk_json_write_array_end(w);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_construct_rbd(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_rbd_bdev", spdk_rpc_construct_rbd_bdev)
|
||||
|
@ -37,24 +37,23 @@
|
||||
#include "spdk_internal/bdev.h"
|
||||
|
||||
static void
|
||||
spdk_rpc_get_bdevs(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_get_bdevs(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_bdev *bdev;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"get_bdevs requires no parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
|
||||
for (bdev = spdk_bdev_first(); bdev != NULL; bdev = spdk_bdev_next(bdev)) {
|
||||
@ -87,7 +86,7 @@ spdk_rpc_get_bdevs(struct spdk_jsonrpc_server_conn *conn,
|
||||
}
|
||||
spdk_json_write_array_end(w);
|
||||
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
SPDK_RPC_REGISTER("get_bdevs", spdk_rpc_get_bdevs)
|
||||
|
||||
@ -107,9 +106,8 @@ static const struct spdk_json_object_decoder rpc_delete_bdev_decoders[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_delete_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_delete_bdev(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_delete_bdev req = {};
|
||||
struct spdk_bdev *bdev;
|
||||
@ -137,17 +135,17 @@ spdk_rpc_delete_bdev(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_delete_bdev(&req);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_delete_bdev(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("delete_bdev", spdk_rpc_delete_bdev)
|
||||
|
@ -53,9 +53,8 @@ static const struct spdk_json_object_decoder rpc_kill_instance_decoders[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_kill_instance(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_kill_instance(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
static const struct {
|
||||
const char *signal_string;
|
||||
@ -96,17 +95,16 @@ spdk_rpc_kill_instance(struct spdk_jsonrpc_server_conn *conn,
|
||||
kill(getpid(), signals[i].signal);
|
||||
free_rpc_kill_instance(&req);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_kill_instance(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("kill_instance", spdk_rpc_kill_instance)
|
||||
|
@ -44,25 +44,24 @@
|
||||
#include "spdk_internal/log.h"
|
||||
|
||||
static void
|
||||
spdk_rpc_get_initiator_groups(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_get_initiator_groups(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_iscsi_init_grp *ig;
|
||||
int i;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"get_initiator_groups requires no parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
|
||||
TAILQ_FOREACH(ig, &g_spdk_iscsi.ig_head, tailq) {
|
||||
@ -90,7 +89,7 @@ spdk_rpc_get_initiator_groups(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
spdk_json_write_array_end(w);
|
||||
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
SPDK_RPC_REGISTER("get_initiator_groups", spdk_rpc_get_initiator_groups)
|
||||
|
||||
@ -162,9 +161,8 @@ static const struct spdk_json_object_decoder rpc_initiator_group_decoders[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_add_initiator_group(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_add_initiator_group(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_initiator_group req = {};
|
||||
size_t i;
|
||||
@ -215,17 +213,17 @@ spdk_rpc_add_initiator_group(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_initiator_group(&req);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
if (initiators) {
|
||||
for (i = 0; i < req.initiator_list.num_initiators; i++) {
|
||||
free(initiators[i]);
|
||||
@ -251,9 +249,8 @@ static const struct spdk_json_object_decoder rpc_delete_initiator_group_decoders
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_delete_initiator_group(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_delete_initiator_group(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_delete_initiator_group req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -277,24 +274,23 @@ spdk_rpc_delete_initiator_group(struct spdk_jsonrpc_server_conn *conn,
|
||||
spdk_iscsi_tgt_node_delete_map(NULL, ig);
|
||||
spdk_iscsi_init_grp_release(ig);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
}
|
||||
SPDK_RPC_REGISTER("delete_initiator_group", spdk_rpc_delete_initiator_group)
|
||||
|
||||
static void
|
||||
spdk_rpc_get_target_nodes(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_get_target_nodes(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_iscsi_globals *iscsi = &g_spdk_iscsi;
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -302,16 +298,16 @@ spdk_rpc_get_target_nodes(struct spdk_jsonrpc_server_conn *conn,
|
||||
int i, maxlun;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"get_target_nodes requires no parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
|
||||
for (tgt_idx = 0 ; tgt_idx < MAX_ISCSI_TARGET_NODE; tgt_idx++) {
|
||||
@ -383,7 +379,7 @@ spdk_rpc_get_target_nodes(struct spdk_jsonrpc_server_conn *conn,
|
||||
}
|
||||
spdk_json_write_array_end(w);
|
||||
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
SPDK_RPC_REGISTER("get_target_nodes", spdk_rpc_get_target_nodes)
|
||||
|
||||
@ -495,9 +491,8 @@ static const struct spdk_json_object_decoder rpc_target_node_decoders[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_construct_target_node(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_construct_target_node(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_target_node req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -546,17 +541,17 @@ spdk_rpc_construct_target_node(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_target_node(&req);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_target_node(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_target_node", spdk_rpc_construct_target_node)
|
||||
@ -576,9 +571,8 @@ static const struct spdk_json_object_decoder rpc_delete_target_node_decoders[] =
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_delete_target_node(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_delete_target_node(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_delete_target_node req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -602,41 +596,40 @@ spdk_rpc_delete_target_node(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_delete_target_node(&req);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_delete_target_node(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("delete_target_node", spdk_rpc_delete_target_node)
|
||||
|
||||
static void
|
||||
spdk_rpc_get_portal_groups(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_get_portal_groups(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_iscsi_portal_grp *pg;
|
||||
struct spdk_iscsi_portal *portal;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"get_portal_groups requires no parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
|
||||
TAILQ_FOREACH(pg, &g_spdk_iscsi.pg_head, tailq) {
|
||||
@ -662,7 +655,7 @@ spdk_rpc_get_portal_groups(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
spdk_json_write_array_end(w);
|
||||
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
SPDK_RPC_REGISTER("get_portal_groups", spdk_rpc_get_portal_groups)
|
||||
|
||||
@ -737,9 +730,8 @@ static const struct spdk_json_object_decoder rpc_portal_group_decoders[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_add_portal_group(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_add_portal_group(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_portal_group req = {};
|
||||
struct spdk_iscsi_portal *portal_list[MAX_PORTAL] = {};
|
||||
@ -772,13 +764,13 @@ spdk_rpc_add_portal_group(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
out:
|
||||
if (rc == 0) {
|
||||
if (id != NULL) {
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w != NULL) {
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
} else {
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
|
||||
for (i = 0; i < req.portal_list.num_portals; i++) {
|
||||
spdk_iscsi_portal_destroy(portal_list[i]);
|
||||
@ -797,9 +789,8 @@ static const struct spdk_json_object_decoder rpc_delete_portal_group_decoders[]
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_delete_portal_group(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_delete_portal_group(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_delete_portal_group req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -824,24 +815,23 @@ spdk_rpc_delete_portal_group(struct spdk_jsonrpc_server_conn *conn,
|
||||
spdk_iscsi_tgt_node_delete_map(pg, NULL);
|
||||
spdk_iscsi_portal_grp_release(pg);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
}
|
||||
SPDK_RPC_REGISTER("delete_portal_group", spdk_rpc_delete_portal_group)
|
||||
|
||||
static void
|
||||
spdk_rpc_get_iscsi_connections(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_get_iscsi_connections(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_iscsi_conn *conns = g_conns_array;
|
||||
@ -849,16 +839,16 @@ spdk_rpc_get_iscsi_connections(struct spdk_jsonrpc_server_conn *conn,
|
||||
uint16_t tsih;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"get_iscsi_connections requires no parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
|
||||
for (i = 0; i < MAX_ISCSI_CONNECTIONS; i++) {
|
||||
@ -909,6 +899,6 @@ spdk_rpc_get_iscsi_connections(struct spdk_jsonrpc_server_conn *conn,
|
||||
}
|
||||
spdk_json_write_array_end(w);
|
||||
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
SPDK_RPC_REGISTER("get_iscsi_connections", spdk_rpc_get_iscsi_connections)
|
||||
|
@ -45,6 +45,11 @@
|
||||
#define SPDK_JSONRPC_MAX_CONNS 64
|
||||
#define SPDK_JSONRPC_MAX_VALUES 1024
|
||||
|
||||
struct spdk_jsonrpc_request {
|
||||
struct spdk_jsonrpc_server_conn *conn;
|
||||
const struct spdk_json_val *id;
|
||||
};
|
||||
|
||||
struct spdk_jsonrpc_server_conn {
|
||||
struct spdk_jsonrpc_server *server;
|
||||
int sockfd;
|
||||
@ -67,14 +72,10 @@ struct spdk_jsonrpc_server {
|
||||
|
||||
/* jsonrpc_server_tcp */
|
||||
int spdk_jsonrpc_server_write_cb(void *cb_ctx, const void *data, size_t size);
|
||||
void spdk_jsonrpc_server_handle_request(struct spdk_jsonrpc_server_conn *conn,
|
||||
void spdk_jsonrpc_server_handle_request(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *method,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id);
|
||||
void spdk_jsonrpc_server_handle_error(struct spdk_jsonrpc_server_conn *conn, int error,
|
||||
const struct spdk_json_val *method,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id);
|
||||
const struct spdk_json_val *params);
|
||||
void spdk_jsonrpc_server_handle_error(struct spdk_jsonrpc_request *request, int error);
|
||||
|
||||
/* jsonrpc_server */
|
||||
int spdk_jsonrpc_parse_request(struct spdk_jsonrpc_server_conn *conn, void *json, size_t size);
|
||||
|
@ -63,6 +63,10 @@ parse_single_request(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_val
|
||||
{
|
||||
bool invalid = false;
|
||||
struct jsonrpc_request req = {};
|
||||
struct spdk_jsonrpc_request request;
|
||||
|
||||
request.conn = conn;
|
||||
request.id = NULL;
|
||||
|
||||
if (spdk_json_decode_object(values, jsonrpc_request_decoders,
|
||||
SPDK_COUNTOF(jsonrpc_request_decoders),
|
||||
@ -87,6 +91,8 @@ parse_single_request(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_val
|
||||
req.id->type != SPDK_JSON_VAL_NULL) {
|
||||
req.id = NULL;
|
||||
invalid = true;
|
||||
} else {
|
||||
request.id = req.id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,10 +106,9 @@ parse_single_request(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_val
|
||||
|
||||
done:
|
||||
if (invalid) {
|
||||
spdk_jsonrpc_server_handle_error(conn, SPDK_JSONRPC_ERROR_INVALID_REQUEST, req.method, req.params,
|
||||
req.id);
|
||||
spdk_jsonrpc_server_handle_error(&request, SPDK_JSONRPC_ERROR_INVALID_REQUEST);
|
||||
} else {
|
||||
spdk_jsonrpc_server_handle_request(conn, req.method, req.params, req.id);
|
||||
spdk_jsonrpc_server_handle_request(&request, req.method, req.params);
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,9 +123,16 @@ parse_batch_request(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_val
|
||||
|
||||
assert(conn->json_writer == NULL);
|
||||
|
||||
|
||||
if (num_values == 0) {
|
||||
struct spdk_jsonrpc_request error_request;
|
||||
|
||||
SPDK_TRACELOG(SPDK_TRACE_RPC, "empty batch array not allowed");
|
||||
spdk_jsonrpc_server_handle_error(conn, SPDK_JSONRPC_ERROR_INVALID_REQUEST, NULL, NULL, NULL);
|
||||
|
||||
/* Build a request with id = NULL since we don't have a valid request ID */
|
||||
error_request.conn = conn;
|
||||
error_request.id = NULL;
|
||||
spdk_jsonrpc_server_handle_error(&error_request, SPDK_JSONRPC_ERROR_INVALID_REQUEST);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -145,11 +157,16 @@ parse_batch_request(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_val
|
||||
int
|
||||
spdk_jsonrpc_parse_request(struct spdk_jsonrpc_server_conn *conn, void *json, size_t size)
|
||||
{
|
||||
struct spdk_jsonrpc_request error_request;
|
||||
ssize_t rc;
|
||||
void *end = NULL;
|
||||
|
||||
assert(conn->json_writer == NULL);
|
||||
|
||||
/* Build a request with id = NULL since we don't have a valid request ID */
|
||||
error_request.conn = conn;
|
||||
error_request.id = NULL;
|
||||
|
||||
conn->batch = false;
|
||||
|
||||
/* Check to see if we have received a full JSON value. */
|
||||
@ -158,7 +175,7 @@ spdk_jsonrpc_parse_request(struct spdk_jsonrpc_server_conn *conn, void *json, si
|
||||
return 0;
|
||||
} else if (rc < 0 || rc > SPDK_JSONRPC_MAX_VALUES) {
|
||||
SPDK_TRACELOG(SPDK_TRACE_RPC, "JSON parse error\n");
|
||||
spdk_jsonrpc_server_handle_error(conn, SPDK_JSONRPC_ERROR_PARSE_ERROR, NULL, NULL, NULL);
|
||||
spdk_jsonrpc_server_handle_error(&error_request, SPDK_JSONRPC_ERROR_PARSE_ERROR);
|
||||
|
||||
/*
|
||||
* Can't recover from parse error (no guaranteed resync point in streaming JSON).
|
||||
@ -172,7 +189,7 @@ spdk_jsonrpc_parse_request(struct spdk_jsonrpc_server_conn *conn, void *json, si
|
||||
SPDK_JSON_PARSE_FLAG_DECODE_IN_PLACE);
|
||||
if (rc < 0 || rc > SPDK_JSONRPC_MAX_VALUES) {
|
||||
SPDK_TRACELOG(SPDK_TRACE_RPC, "JSON parse error on second pass\n");
|
||||
spdk_jsonrpc_server_handle_error(conn, SPDK_JSONRPC_ERROR_PARSE_ERROR, NULL, NULL, NULL);
|
||||
spdk_jsonrpc_server_handle_error(&error_request, SPDK_JSONRPC_ERROR_PARSE_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -185,7 +202,7 @@ spdk_jsonrpc_parse_request(struct spdk_jsonrpc_server_conn *conn, void *json, si
|
||||
parse_batch_request(conn, conn->values);
|
||||
} else {
|
||||
SPDK_TRACELOG(SPDK_TRACE_RPC, "top-level JSON value was not array or object\n");
|
||||
spdk_jsonrpc_server_handle_error(conn, SPDK_JSONRPC_ERROR_INVALID_REQUEST, NULL, NULL, NULL);
|
||||
spdk_jsonrpc_server_handle_error(&error_request, SPDK_JSONRPC_ERROR_INVALID_REQUEST);
|
||||
}
|
||||
|
||||
return end - json;
|
||||
@ -229,11 +246,11 @@ end_response(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_write_ctx *
|
||||
}
|
||||
|
||||
struct spdk_json_write_ctx *
|
||||
spdk_jsonrpc_begin_result(struct spdk_jsonrpc_server_conn *conn, const struct spdk_json_val *id)
|
||||
spdk_jsonrpc_begin_result(struct spdk_jsonrpc_request *request)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
|
||||
w = begin_response(conn, id);
|
||||
w = begin_response(request->conn, request->id);
|
||||
if (w == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@ -244,29 +261,30 @@ spdk_jsonrpc_begin_result(struct spdk_jsonrpc_server_conn *conn, const struct sp
|
||||
}
|
||||
|
||||
void
|
||||
spdk_jsonrpc_end_result(struct spdk_jsonrpc_server_conn *conn, struct spdk_json_write_ctx *w)
|
||||
spdk_jsonrpc_end_result(struct spdk_jsonrpc_request *request, struct spdk_json_write_ctx *w)
|
||||
{
|
||||
assert(w != NULL);
|
||||
assert(w == conn->json_writer);
|
||||
assert(w == request->conn->json_writer);
|
||||
|
||||
end_response(conn, w);
|
||||
end_response(request->conn, w);
|
||||
}
|
||||
|
||||
void
|
||||
spdk_jsonrpc_send_error_response(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *id,
|
||||
spdk_jsonrpc_send_error_response(struct spdk_jsonrpc_request *request,
|
||||
int error_code, const char *msg)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_json_val v_null;
|
||||
const struct spdk_json_val *id;
|
||||
|
||||
id = request->id;
|
||||
if (id == NULL) {
|
||||
/* For error responses, if id is missing, explicitly respond with "id": null. */
|
||||
v_null.type = SPDK_JSON_VAL_NULL;
|
||||
id = &v_null;
|
||||
}
|
||||
|
||||
w = begin_response(conn, id);
|
||||
w = begin_response(request->conn, id);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -279,7 +297,7 @@ spdk_jsonrpc_send_error_response(struct spdk_jsonrpc_server_conn *conn,
|
||||
spdk_json_write_string(w, msg);
|
||||
spdk_json_write_object_end(w);
|
||||
|
||||
end_response(conn, w);
|
||||
end_response(request->conn, w);
|
||||
}
|
||||
|
||||
SPDK_LOG_REGISTER_TRACE_FLAG("rpc", SPDK_TRACE_RPC)
|
||||
|
@ -180,17 +180,14 @@ spdk_jsonrpc_server_write_cb(void *cb_ctx, const void *data, size_t size)
|
||||
}
|
||||
|
||||
void
|
||||
spdk_jsonrpc_server_handle_request(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *method, const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_jsonrpc_server_handle_request(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *method, const struct spdk_json_val *params)
|
||||
{
|
||||
conn->server->handle_request(conn, method, params, id);
|
||||
request->conn->server->handle_request(request, method, params);
|
||||
}
|
||||
|
||||
void
|
||||
spdk_jsonrpc_server_handle_error(struct spdk_jsonrpc_server_conn *conn, int error,
|
||||
const struct spdk_json_val *method, const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_jsonrpc_server_handle_error(struct spdk_jsonrpc_request *request, int error)
|
||||
{
|
||||
const char *msg;
|
||||
|
||||
@ -220,7 +217,7 @@ spdk_jsonrpc_server_handle_error(struct spdk_jsonrpc_server_conn *conn, int erro
|
||||
break;
|
||||
}
|
||||
|
||||
spdk_jsonrpc_send_error_response(conn, id, error, msg);
|
||||
spdk_jsonrpc_send_error_response(request, error, msg);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -51,9 +51,8 @@ static const struct spdk_json_object_decoder rpc_trace_flag_decoders[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_set_trace_flag(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_set_trace_flag(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_trace_flag req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -72,25 +71,24 @@ spdk_rpc_set_trace_flag(struct spdk_jsonrpc_server_conn *conn,
|
||||
spdk_log_set_trace_flag(req.flag);
|
||||
free_rpc_trace_flag(&req);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_trace_flag(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("set_trace_flag", spdk_rpc_set_trace_flag)
|
||||
|
||||
static void
|
||||
spdk_rpc_clear_trace_flag(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_clear_trace_flag(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_trace_flag req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -109,48 +107,47 @@ spdk_rpc_clear_trace_flag(struct spdk_jsonrpc_server_conn *conn,
|
||||
spdk_log_clear_trace_flag(req.flag);
|
||||
free_rpc_trace_flag(&req);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_trace_flag(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("clear_trace_flag", spdk_rpc_clear_trace_flag)
|
||||
|
||||
static void
|
||||
spdk_rpc_get_trace_flags(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_get_trace_flags(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_trace_flag *flag;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"get_trace_flags requires no parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
flag = spdk_log_get_first_trace_flag();
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_object_begin(w);
|
||||
flag = spdk_log_get_first_trace_flag();
|
||||
while (flag) {
|
||||
spdk_json_write_name(w, flag->name);
|
||||
spdk_json_write_bool(w, flag->enabled);
|
||||
flag = spdk_log_get_next_trace_flag(flag);
|
||||
}
|
||||
spdk_json_write_object_end(w);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
SPDK_RPC_REGISTER("get_trace_flags", spdk_rpc_get_trace_flags)
|
||||
|
@ -56,9 +56,8 @@ static const struct spdk_json_object_decoder rpc_ip_address_decoders[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_add_ip_address(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_add_ip_address(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_ip_address req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -76,25 +75,24 @@ spdk_rpc_add_ip_address(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_ip_address(&req);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_ip_address(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("add_ip_address", spdk_rpc_add_ip_address)
|
||||
|
||||
static void
|
||||
spdk_rpc_delete_ip_address(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_delete_ip_address(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_ip_address req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -112,25 +110,24 @@ spdk_rpc_delete_ip_address(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_ip_address(&req);
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
||||
free_rpc_ip_address(&req);
|
||||
}
|
||||
SPDK_RPC_REGISTER("delete_ip_address", spdk_rpc_delete_ip_address)
|
||||
|
||||
static void
|
||||
spdk_rpc_get_interfaces(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_get_interfaces(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
TAILQ_HEAD(, spdk_interface) *interface_head = spdk_interface_get_list();
|
||||
@ -140,16 +137,16 @@ spdk_rpc_get_interfaces(struct spdk_jsonrpc_server_conn *conn,
|
||||
uint32_t i;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"get_interfaces requires no parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
|
||||
TAILQ_FOREACH(ifc, interface_head, tailq) {
|
||||
@ -174,6 +171,6 @@ spdk_rpc_get_interfaces(struct spdk_jsonrpc_server_conn *conn,
|
||||
}
|
||||
spdk_json_write_array_end(w);
|
||||
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
SPDK_RPC_REGISTER("get_interfaces", spdk_rpc_get_interfaces)
|
||||
|
@ -54,11 +54,9 @@ struct spdk_rpc_method {
|
||||
static SLIST_HEAD(, spdk_rpc_method) g_rpc_methods = SLIST_HEAD_INITIALIZER(g_rpc_methods);
|
||||
|
||||
static void
|
||||
spdk_jsonrpc_handler(
|
||||
struct spdk_jsonrpc_server_conn *conn,
|
||||
spdk_jsonrpc_handler(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *method,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_rpc_method *m;
|
||||
|
||||
@ -66,12 +64,12 @@ spdk_jsonrpc_handler(
|
||||
|
||||
SLIST_FOREACH(m, &g_rpc_methods, slist) {
|
||||
if (spdk_json_strequal(method, m->name)) {
|
||||
m->func(conn, params, id);
|
||||
m->func(request, params);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_METHOD_NOT_FOUND, "Method not found");
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_METHOD_NOT_FOUND, "Method not found");
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -38,24 +38,23 @@
|
||||
#include "spdk/util.h"
|
||||
|
||||
static void
|
||||
spdk_rpc_get_luns(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_get_luns(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_lun_db_entry *current;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"get_luns requires no parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
|
||||
current = spdk_scsi_lun_list_head;
|
||||
@ -74,30 +73,29 @@ spdk_rpc_get_luns(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
spdk_json_write_array_end(w);
|
||||
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
SPDK_RPC_REGISTER("get_luns", spdk_rpc_get_luns)
|
||||
|
||||
static void
|
||||
spdk_rpc_get_scsi_devices(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_get_scsi_devices(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_scsi_dev *devs = spdk_scsi_dev_get_list();
|
||||
int i;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"get_scsi_devices requires no parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
|
||||
for (i = 0; i < SPDK_SCSI_MAX_DEVS; i++) {
|
||||
@ -119,6 +117,6 @@ spdk_rpc_get_scsi_devices(struct spdk_jsonrpc_server_conn *conn,
|
||||
}
|
||||
spdk_json_write_array_end(w);
|
||||
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
SPDK_RPC_REGISTER("get_scsi_devices", spdk_rpc_get_scsi_devices)
|
||||
|
@ -77,9 +77,8 @@ json_scsi_dev_write(struct spdk_json_write_ctx *ctx, struct spdk_scsi_dev *dev)
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_rpc_get_vhost_scsi_controllers(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_get_vhost_scsi_controllers(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_vhost_dev *vdev = NULL;
|
||||
@ -87,16 +86,16 @@ spdk_rpc_get_vhost_scsi_controllers(struct spdk_jsonrpc_server_conn *conn,
|
||||
uint32_t i;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"get_vhost_scsi_controllers requires no parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
while ((vdev = spdk_vhost_dev_next(vdev)) != NULL) {
|
||||
if (vdev->type != SPDK_VHOST_DEV_T_SCSI) {
|
||||
@ -131,7 +130,7 @@ spdk_rpc_get_vhost_scsi_controllers(struct spdk_jsonrpc_server_conn *conn,
|
||||
spdk_json_write_object_end(w); // ctrl
|
||||
}
|
||||
spdk_json_write_array_end(w);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
}
|
||||
SPDK_RPC_REGISTER("get_vhost_scsi_controllers", spdk_rpc_get_vhost_scsi_controllers)
|
||||
@ -154,9 +153,8 @@ static const struct spdk_json_object_decoder rpc_construct_vhost_ctrlr[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_construct_vhost_scsi_controller(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_construct_vhost_scsi_controller(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_vhost_scsi_ctrlr req = {0};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -184,15 +182,18 @@ spdk_rpc_construct_vhost_scsi_controller(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_vhost_scsi_ctrlr(&req);
|
||||
|
||||
if (id != NULL) {
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
}
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
free_rpc_vhost_scsi_ctrlr(&req);
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_vhost_scsi_controller", spdk_rpc_construct_vhost_scsi_controller)
|
||||
|
||||
@ -211,9 +212,8 @@ static const struct spdk_json_object_decoder rpc_remove_vhost_ctrlr[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_remove_vhost_scsi_controller(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_remove_vhost_scsi_controller(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_remove_vhost_scsi_ctrlr req = {NULL};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -240,16 +240,18 @@ spdk_rpc_remove_vhost_scsi_controller(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_remove_vhost_scsi_ctrlr(&req);
|
||||
|
||||
if (id != NULL) {
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
free_rpc_remove_vhost_scsi_ctrlr(&req);
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
}
|
||||
SPDK_RPC_REGISTER("remove_vhost_scsi_controller", spdk_rpc_remove_vhost_scsi_controller)
|
||||
|
||||
@ -274,9 +276,8 @@ static const struct spdk_json_object_decoder rpc_vhost_add_lun[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_add_vhost_scsi_lun(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_add_vhost_scsi_lun(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_add_vhost_scsi_ctrlr_lun req = {0};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -297,16 +298,18 @@ spdk_rpc_add_vhost_scsi_lun(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_add_vhost_scsi_ctrlr_lun(&req);
|
||||
|
||||
if (id != NULL) {
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
free_rpc_add_vhost_scsi_ctrlr_lun(&req);
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
}
|
||||
SPDK_RPC_REGISTER("add_vhost_scsi_lun", spdk_rpc_add_vhost_scsi_lun)
|
||||
|
||||
@ -327,9 +330,8 @@ static const struct spdk_json_object_decoder rpc_vhost_remove_dev[] = {
|
||||
};
|
||||
|
||||
static void
|
||||
spdk_rpc_remove_vhost_scsi_dev(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_remove_vhost_scsi_dev(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_remove_vhost_scsi_ctrlr_dev req = {0};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -356,16 +358,18 @@ spdk_rpc_remove_vhost_scsi_dev(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_remove_vhost_scsi_ctrlr_dev(&req);
|
||||
|
||||
if (id != NULL) {
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
free_rpc_remove_vhost_scsi_ctrlr_dev(&req);
|
||||
spdk_jsonrpc_send_error_response(conn, id, SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
}
|
||||
SPDK_RPC_REGISTER("remove_vhost_scsi_dev", spdk_rpc_remove_vhost_scsi_dev)
|
||||
|
||||
@ -392,9 +396,8 @@ free_rpc_vhost_blk_ctrlr(struct rpc_vhost_blk_ctrlr *req)
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_rpc_construct_vhost_blk_controller(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_construct_vhost_blk_controller(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_vhost_blk_ctrlr req = {0};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -422,16 +425,18 @@ spdk_rpc_construct_vhost_blk_controller(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_vhost_blk_ctrlr(&req);
|
||||
|
||||
if (id != NULL) {
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
free_rpc_vhost_blk_ctrlr(&req);
|
||||
spdk_jsonrpc_send_error_response(conn, id,
|
||||
spdk_jsonrpc_send_error_response(request,
|
||||
SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
|
||||
}
|
||||
@ -452,9 +457,8 @@ free_rpc_remove_vhost_blk_ctrlr(struct rpc_remove_vhost_blk_ctrlr *req)
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_rpc_remove_vhost_blk_controller(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_remove_vhost_blk_controller(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_remove_vhost_blk_ctrlr req = {NULL};
|
||||
struct spdk_json_write_ctx *w;
|
||||
@ -480,42 +484,43 @@ spdk_rpc_remove_vhost_blk_controller(struct spdk_jsonrpc_server_conn *conn,
|
||||
|
||||
free_rpc_remove_vhost_blk_ctrlr(&req);
|
||||
|
||||
if (id != NULL) {
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_json_write_bool(w, true);
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
return;
|
||||
|
||||
invalid:
|
||||
free_rpc_remove_vhost_blk_ctrlr(&req);
|
||||
spdk_jsonrpc_send_error_response(conn, id,
|
||||
spdk_jsonrpc_send_error_response(request,
|
||||
SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
|
||||
}
|
||||
SPDK_RPC_REGISTER("remove_vhost_blk_controller", spdk_rpc_remove_vhost_blk_controller)
|
||||
|
||||
static void
|
||||
spdk_rpc_get_vhost_blk_controllers(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_rpc_get_vhost_blk_controllers(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_vhost_dev *vdev = NULL;
|
||||
struct spdk_bdev *bdev;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(conn, id,
|
||||
spdk_jsonrpc_send_error_response(request,
|
||||
SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"get_vhost_block_controllers requires no parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == NULL) {
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(conn, id);
|
||||
spdk_json_write_array_begin(w);
|
||||
while ((vdev = spdk_vhost_dev_next(vdev)) != NULL) {
|
||||
if (vdev->type != SPDK_VHOST_DEV_T_BLK)
|
||||
@ -541,8 +546,6 @@ spdk_rpc_get_vhost_blk_controllers(struct spdk_jsonrpc_server_conn *conn,
|
||||
spdk_json_write_object_end(w);
|
||||
}
|
||||
spdk_json_write_array_end(w);
|
||||
spdk_jsonrpc_end_result(conn, w);
|
||||
|
||||
return;
|
||||
spdk_jsonrpc_end_result(request, w);
|
||||
}
|
||||
SPDK_RPC_REGISTER("get_vhost_blk_controllers", spdk_rpc_get_vhost_blk_controllers)
|
||||
|
@ -143,9 +143,10 @@ static size_t g_num_reqs;
|
||||
g_params++
|
||||
|
||||
static void
|
||||
ut_handle(struct spdk_jsonrpc_server_conn *conn, int error, const struct spdk_json_val *method,
|
||||
const struct spdk_json_val *params, const struct spdk_json_val *id)
|
||||
ut_handle(struct spdk_jsonrpc_request *request, int error, const struct spdk_json_val *method,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
const struct spdk_json_val *id = request->id;
|
||||
struct req *r;
|
||||
|
||||
SPDK_CU_ASSERT_FATAL(g_num_reqs != MAX_REQS);
|
||||
@ -177,19 +178,16 @@ ut_handle(struct spdk_jsonrpc_server_conn *conn, int error, const struct spdk_js
|
||||
}
|
||||
|
||||
void
|
||||
spdk_jsonrpc_server_handle_error(struct spdk_jsonrpc_server_conn *conn, int error,
|
||||
const struct spdk_json_val *method, const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_jsonrpc_server_handle_error(struct spdk_jsonrpc_request *request, int error)
|
||||
{
|
||||
ut_handle(conn, error, method, params, id);
|
||||
ut_handle(request, error, NULL, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
spdk_jsonrpc_server_handle_request(struct spdk_jsonrpc_server_conn *conn,
|
||||
const struct spdk_json_val *method, const struct spdk_json_val *params,
|
||||
const struct spdk_json_val *id)
|
||||
spdk_jsonrpc_server_handle_request(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *method, const struct spdk_json_val *params)
|
||||
{
|
||||
ut_handle(conn, 0, method, params, id);
|
||||
ut_handle(request, 0, method, params);
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
Reference in New Issue
Block a user