2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2017-03-17 06:10:32 +00:00
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
#include "spdk/string.h"
|
|
|
|
#include "spdk/rpc.h"
|
|
|
|
#include "spdk/util.h"
|
2018-06-15 14:06:38 +00:00
|
|
|
#include "spdk/string.h"
|
2020-10-06 16:16:26 +00:00
|
|
|
#include "spdk/log.h"
|
2017-03-17 06:10:32 +00:00
|
|
|
#include "vbdev_error.h"
|
|
|
|
|
2022-10-17 18:26:06 +00:00
|
|
|
static int
|
|
|
|
rpc_error_bdev_decode_io_type(const struct spdk_json_val *val, void *out)
|
2017-03-17 06:10:32 +00:00
|
|
|
{
|
2022-10-17 18:26:06 +00:00
|
|
|
uint32_t *io_type = out;
|
|
|
|
|
|
|
|
if (spdk_json_strequal(val, "read") == true) {
|
|
|
|
*io_type = SPDK_BDEV_IO_TYPE_READ;
|
|
|
|
} else if (spdk_json_strequal(val, "write") == true) {
|
|
|
|
*io_type = SPDK_BDEV_IO_TYPE_WRITE;
|
|
|
|
} else if (spdk_json_strequal(val, "flush") == true) {
|
|
|
|
*io_type = SPDK_BDEV_IO_TYPE_FLUSH;
|
|
|
|
} else if (spdk_json_strequal(val, "unmap") == true) {
|
|
|
|
*io_type = SPDK_BDEV_IO_TYPE_UNMAP;
|
|
|
|
} 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;
|
2017-03-17 06:10:32 +00:00
|
|
|
}
|
2022-10-17 18:26:06 +00:00
|
|
|
|
|
|
|
return 0;
|
2017-03-17 06:10:32 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 18:26:06 +00:00
|
|
|
static int
|
|
|
|
rpc_error_bdev_decode_error_type(const struct spdk_json_val *val, void *out)
|
2017-06-05 08:04:04 +00:00
|
|
|
{
|
2022-10-17 18:26:06 +00:00
|
|
|
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;
|
2017-06-05 08:04:04 +00:00
|
|
|
}
|
2022-10-17 18:26:06 +00:00
|
|
|
|
|
|
|
return 0;
|
2017-06-05 08:04:04 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 09:58:53 +00:00
|
|
|
struct rpc_bdev_error_create {
|
2017-03-17 06:10:32 +00:00
|
|
|
char *base_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2019-08-16 09:58:53 +00:00
|
|
|
free_rpc_bdev_error_create(struct rpc_bdev_error_create *req)
|
2017-03-17 06:10:32 +00:00
|
|
|
{
|
|
|
|
free(req->base_name);
|
|
|
|
}
|
|
|
|
|
2019-08-16 09:58:53 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_bdev_error_create_decoders[] = {
|
|
|
|
{"base_name", offsetof(struct rpc_bdev_error_create, base_name), spdk_json_decode_string},
|
2017-03-17 06:10:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-05-10 07:16:18 +00:00
|
|
|
rpc_bdev_error_create(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2017-03-17 06:10:32 +00:00
|
|
|
{
|
2019-08-16 09:58:53 +00:00
|
|
|
struct rpc_bdev_error_create req = {};
|
2019-07-12 08:30:34 +00:00
|
|
|
int rc = 0;
|
2017-03-17 06:10:32 +00:00
|
|
|
|
2019-08-16 09:58:53 +00:00
|
|
|
if (spdk_json_decode_object(params, rpc_bdev_error_create_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_bdev_error_create_decoders),
|
2017-03-17 06:10:32 +00:00
|
|
|
&req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
2019-07-12 08:30:34 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"spdk_json_decode_object failed");
|
|
|
|
goto cleanup;
|
2017-03-17 06:10:32 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 07:16:18 +00:00
|
|
|
rc = vbdev_error_create(req.base_name);
|
2019-07-12 08:30:34 +00:00
|
|
|
if (rc) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
|
|
|
|
goto cleanup;
|
2017-03-17 06:10:32 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2017-03-17 06:10:32 +00:00
|
|
|
|
2019-07-12 08:30:34 +00:00
|
|
|
cleanup:
|
2019-08-16 09:58:53 +00:00
|
|
|
free_rpc_bdev_error_create(&req);
|
2017-03-17 06:10:32 +00:00
|
|
|
}
|
2020-05-10 07:16:18 +00:00
|
|
|
SPDK_RPC_REGISTER("bdev_error_create", rpc_bdev_error_create, SPDK_RPC_RUNTIME)
|
2017-03-17 06:10:32 +00:00
|
|
|
|
2018-06-15 14:06:38 +00:00
|
|
|
struct rpc_delete_error {
|
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_delete_error(struct rpc_delete_error *r)
|
|
|
|
{
|
|
|
|
free(r->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_delete_error_decoders[] = {
|
|
|
|
{"name", offsetof(struct rpc_delete_error, name), spdk_json_decode_string},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-05-10 07:16:18 +00:00
|
|
|
rpc_bdev_error_delete_cb(void *cb_arg, int bdeverrno)
|
2018-06-15 14:06:38 +00:00
|
|
|
{
|
|
|
|
struct spdk_jsonrpc_request *request = cb_arg;
|
|
|
|
|
2022-03-29 12:02:58 +00:00
|
|
|
if (bdeverrno == 0) {
|
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
|
|
|
} else {
|
|
|
|
spdk_jsonrpc_send_error_response(request, bdeverrno, spdk_strerror(-bdeverrno));
|
|
|
|
}
|
2018-06-15 14:06:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-10 07:16:18 +00:00
|
|
|
rpc_bdev_error_delete(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-06-15 14:06:38 +00:00
|
|
|
{
|
|
|
|
struct rpc_delete_error req = {NULL};
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_delete_error_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_delete_error_decoders),
|
|
|
|
&req)) {
|
2019-07-12 08:30:34 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"spdk_json_decode_object failed");
|
|
|
|
goto cleanup;
|
2018-06-15 14:06:38 +00:00
|
|
|
}
|
|
|
|
|
2022-03-29 05:55:53 +00:00
|
|
|
vbdev_error_delete(req.name, rpc_bdev_error_delete_cb, request);
|
2018-06-15 14:06:38 +00:00
|
|
|
|
2019-07-12 08:30:34 +00:00
|
|
|
cleanup:
|
2018-06-15 14:06:38 +00:00
|
|
|
free_rpc_delete_error(&req);
|
|
|
|
}
|
2020-05-10 07:16:18 +00:00
|
|
|
SPDK_RPC_REGISTER("bdev_error_delete", rpc_bdev_error_delete, SPDK_RPC_RUNTIME)
|
2018-06-15 14:06:38 +00:00
|
|
|
|
2017-03-17 06:10:32 +00:00
|
|
|
struct rpc_error_information {
|
2017-06-05 07:09:36 +00:00
|
|
|
char *name;
|
2022-10-17 18:35:46 +00:00
|
|
|
struct vbdev_error_inject_opts opts;
|
2017-03-17 06:10:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_error_information_decoders[] = {
|
2017-06-05 07:09:36 +00:00
|
|
|
{"name", offsetof(struct rpc_error_information, name), spdk_json_decode_string},
|
2022-10-17 18:35:46 +00:00
|
|
|
{"io_type", offsetof(struct rpc_error_information, opts.io_type), rpc_error_bdev_decode_io_type},
|
|
|
|
{"error_type", offsetof(struct rpc_error_information, opts.error_type), rpc_error_bdev_decode_error_type},
|
|
|
|
{"num", offsetof(struct rpc_error_information, opts.error_num), spdk_json_decode_uint32, true},
|
2017-03-17 06:10:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_error_information(struct rpc_error_information *p)
|
|
|
|
{
|
2017-06-05 07:09:36 +00:00
|
|
|
free(p->name);
|
2017-03-17 06:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-10 07:16:18 +00:00
|
|
|
rpc_bdev_error_inject_error(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2017-03-17 06:10:32 +00:00
|
|
|
{
|
2022-10-17 18:35:46 +00:00
|
|
|
struct rpc_error_information req = {.opts.error_num = 1};
|
2019-07-12 08:30:34 +00:00
|
|
|
int rc = 0;
|
2017-03-17 06:10:32 +00:00
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_error_information_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_error_information_decoders),
|
|
|
|
&req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
2019-07-12 08:30:34 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"spdk_json_decode_object failed");
|
|
|
|
goto cleanup;
|
2017-03-17 06:10:32 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 18:35:46 +00:00
|
|
|
rc = vbdev_error_inject_error(req.name, &req.opts);
|
2019-07-12 08:30:34 +00:00
|
|
|
if (rc) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
|
|
|
|
goto cleanup;
|
2017-03-17 06:10:32 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 16:58:30 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
2017-03-17 06:10:32 +00:00
|
|
|
|
2019-07-12 08:30:34 +00:00
|
|
|
cleanup:
|
2017-03-17 06:10:32 +00:00
|
|
|
free_rpc_error_information(&req);
|
|
|
|
}
|
2020-05-10 07:16:18 +00:00
|
|
|
SPDK_RPC_REGISTER("bdev_error_inject_error", rpc_bdev_error_inject_error, SPDK_RPC_RUNTIME)
|