bdev/error: Use custom JSON decoders for bdev_error_injection_error
This is a small clean up. Use custom JSON decoders for the io_type and error_type parameters in the bdev_error_injection_error RPC. Signed-off-by: Shuhei Matsumoto <smatsumoto@nvidia.com> Change-Id: I528fe4a31fac7eddb8ec33594b90e107d71693be Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15024 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com> Reviewed-by: Krzysztof Karas <krzysztof.karas@intel.com>
This commit is contained in:
parent
95e4ddce51
commit
972013e29d
@ -11,37 +11,46 @@
|
|||||||
#include "spdk/log.h"
|
#include "spdk/log.h"
|
||||||
#include "vbdev_error.h"
|
#include "vbdev_error.h"
|
||||||
|
|
||||||
#define ERROR_BDEV_IO_TYPE_INVALID (SPDK_BDEV_IO_TYPE_RESET + 1)
|
static int
|
||||||
#define ERROR_BDEV_ERROR_TYPE_INVALID (VBDEV_IO_PENDING + 1)
|
rpc_error_bdev_decode_io_type(const struct spdk_json_val *val, void *out)
|
||||||
|
|
||||||
static uint32_t
|
|
||||||
rpc_error_bdev_io_type_parse(char *name)
|
|
||||||
{
|
{
|
||||||
if (strcmp(name, "read") == 0) {
|
uint32_t *io_type = out;
|
||||||
return SPDK_BDEV_IO_TYPE_READ;
|
|
||||||
} else if (strcmp(name, "write") == 0) {
|
if (spdk_json_strequal(val, "read") == true) {
|
||||||
return SPDK_BDEV_IO_TYPE_WRITE;
|
*io_type = SPDK_BDEV_IO_TYPE_READ;
|
||||||
} else if (strcmp(name, "flush") == 0) {
|
} else if (spdk_json_strequal(val, "write") == true) {
|
||||||
return SPDK_BDEV_IO_TYPE_FLUSH;
|
*io_type = SPDK_BDEV_IO_TYPE_WRITE;
|
||||||
} else if (strcmp(name, "unmap") == 0) {
|
} else if (spdk_json_strequal(val, "flush") == true) {
|
||||||
return SPDK_BDEV_IO_TYPE_UNMAP;
|
*io_type = SPDK_BDEV_IO_TYPE_FLUSH;
|
||||||
} else if (strcmp(name, "all") == 0) {
|
} else if (spdk_json_strequal(val, "unmap") == true) {
|
||||||
return 0xffffffff;
|
*io_type = SPDK_BDEV_IO_TYPE_UNMAP;
|
||||||
} else if (strcmp(name, "clear") == 0) {
|
} else if (spdk_json_strequal(val, "all") == true) {
|
||||||
|
*io_type = 0xffffffff;
|
||||||
|
} else if (spdk_json_strequal(val, "clear") == true) {
|
||||||
|
*io_type = 0;
|
||||||
|
} else {
|
||||||
|
SPDK_NOTICELOG("Invalid parameter value: io_type\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return ERROR_BDEV_IO_TYPE_INVALID;
|
|
||||||
|
static int
|
||||||
|
rpc_error_bdev_decode_error_type(const struct spdk_json_val *val, void *out)
|
||||||
|
{
|
||||||
|
uint32_t *error_type = out;
|
||||||
|
|
||||||
|
if (spdk_json_strequal(val, "failure") == true) {
|
||||||
|
*error_type = VBDEV_IO_FAILURE;
|
||||||
|
} else if (spdk_json_strequal(val, "pending") == true) {
|
||||||
|
*error_type = VBDEV_IO_PENDING;
|
||||||
|
} else {
|
||||||
|
SPDK_NOTICELOG("Invalid parameter value: error_type\n");
|
||||||
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
return 0;
|
||||||
rpc_error_bdev_error_type_parse(char *name)
|
|
||||||
{
|
|
||||||
if (strcmp(name, "failure") == 0) {
|
|
||||||
return VBDEV_IO_FAILURE;
|
|
||||||
} else if (strcmp(name, "pending") == 0) {
|
|
||||||
return VBDEV_IO_PENDING;
|
|
||||||
}
|
|
||||||
return ERROR_BDEV_ERROR_TYPE_INVALID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct rpc_bdev_error_create {
|
struct rpc_bdev_error_create {
|
||||||
@ -136,15 +145,15 @@ SPDK_RPC_REGISTER("bdev_error_delete", rpc_bdev_error_delete, SPDK_RPC_RUNTIME)
|
|||||||
|
|
||||||
struct rpc_error_information {
|
struct rpc_error_information {
|
||||||
char *name;
|
char *name;
|
||||||
char *io_type;
|
uint32_t io_type;
|
||||||
char *error_type;
|
uint32_t error_type;
|
||||||
uint32_t num;
|
uint32_t num;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct spdk_json_object_decoder rpc_error_information_decoders[] = {
|
static const struct spdk_json_object_decoder rpc_error_information_decoders[] = {
|
||||||
{"name", offsetof(struct rpc_error_information, name), spdk_json_decode_string},
|
{"name", offsetof(struct rpc_error_information, name), spdk_json_decode_string},
|
||||||
{"io_type", offsetof(struct rpc_error_information, io_type), spdk_json_decode_string},
|
{"io_type", offsetof(struct rpc_error_information, io_type), rpc_error_bdev_decode_io_type},
|
||||||
{"error_type", offsetof(struct rpc_error_information, error_type), spdk_json_decode_string},
|
{"error_type", offsetof(struct rpc_error_information, error_type), rpc_error_bdev_decode_error_type},
|
||||||
{"num", offsetof(struct rpc_error_information, num), spdk_json_decode_uint32, true},
|
{"num", offsetof(struct rpc_error_information, num), spdk_json_decode_uint32, true},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -152,8 +161,6 @@ static void
|
|||||||
free_rpc_error_information(struct rpc_error_information *p)
|
free_rpc_error_information(struct rpc_error_information *p)
|
||||||
{
|
{
|
||||||
free(p->name);
|
free(p->name);
|
||||||
free(p->io_type);
|
|
||||||
free(p->error_type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -161,8 +168,6 @@ rpc_bdev_error_inject_error(struct spdk_jsonrpc_request *request,
|
|||||||
const struct spdk_json_val *params)
|
const struct spdk_json_val *params)
|
||||||
{
|
{
|
||||||
struct rpc_error_information req = {.num = 1};
|
struct rpc_error_information req = {.num = 1};
|
||||||
uint32_t io_type;
|
|
||||||
uint32_t error_type;
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (spdk_json_decode_object(params, rpc_error_information_decoders,
|
if (spdk_json_decode_object(params, rpc_error_information_decoders,
|
||||||
@ -174,21 +179,7 @@ rpc_bdev_error_inject_error(struct spdk_jsonrpc_request *request,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
io_type = rpc_error_bdev_io_type_parse(req.io_type);
|
rc = vbdev_error_inject_error(req.name, req.io_type, req.error_type, req.num);
|
||||||
if (io_type == ERROR_BDEV_IO_TYPE_INVALID) {
|
|
||||||
spdk_jsonrpc_send_error_response(request, -EINVAL,
|
|
||||||
"Unexpected io_type value");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_type = rpc_error_bdev_error_type_parse(req.error_type);
|
|
||||||
if (error_type == ERROR_BDEV_ERROR_TYPE_INVALID) {
|
|
||||||
spdk_jsonrpc_send_error_response(request, -EINVAL,
|
|
||||||
"Unexpected error_type value");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = vbdev_error_inject_error(req.name, io_type, error_type, req.num);
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
|
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
Loading…
Reference in New Issue
Block a user