bdev/error: Consolidate params for injection into a options structure

This will make it easier to add more parameters for error injection.

Signed-off-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
Change-Id: Ie5b22c31b5ba9d8c256d369213fa8fb4b985fa26
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15025
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:
Shuhei Matsumoto 2022-10-18 03:35:46 +09:00 committed by Tomasz Zawadzki
parent 972013e29d
commit ffee98ddd9
3 changed files with 21 additions and 19 deletions

View File

@ -72,7 +72,7 @@ dummy_bdev_event_cb(enum spdk_bdev_event_type type, struct spdk_bdev *bdev, void
} }
int int
vbdev_error_inject_error(char *name, uint32_t io_type, uint32_t error_type, uint32_t error_num) vbdev_error_inject_error(char *name, const struct vbdev_error_inject_opts *opts)
{ {
struct spdk_bdev_desc *desc; struct spdk_bdev_desc *desc;
struct spdk_bdev *bdev; struct spdk_bdev *bdev;
@ -105,18 +105,18 @@ vbdev_error_inject_error(char *name, uint32_t io_type, uint32_t error_type, uint
goto exit; goto exit;
} }
if (0xffffffff == io_type) { if (0xffffffff == opts->io_type) {
for (i = 0; i < SPDK_COUNTOF(error_disk->error_vector); i++) { for (i = 0; i < SPDK_COUNTOF(error_disk->error_vector); i++) {
error_disk->error_vector[i].error_type = error_type; error_disk->error_vector[i].error_type = opts->error_type;
error_disk->error_vector[i].error_num = error_num; error_disk->error_vector[i].error_num = opts->error_num;
} }
} else if (0 == io_type) { } else if (0 == opts->io_type) {
for (i = 0; i < SPDK_COUNTOF(error_disk->error_vector); i++) { for (i = 0; i < SPDK_COUNTOF(error_disk->error_vector); i++) {
error_disk->error_vector[i].error_num = 0; error_disk->error_vector[i].error_num = 0;
} }
} else { } else {
error_disk->error_vector[io_type].error_type = error_type; error_disk->error_vector[opts->io_type].error_type = opts->error_type;
error_disk->error_vector[io_type].error_num = error_num; error_disk->error_vector[opts->io_type].error_num = opts->error_num;
} }
exit: exit:

View File

@ -34,15 +34,19 @@ int vbdev_error_create(const char *base_bdev_name);
void vbdev_error_delete(const char *error_vbdev_name, spdk_delete_error_complete cb_fn, void vbdev_error_delete(const char *error_vbdev_name, spdk_delete_error_complete cb_fn,
void *cb_arg); void *cb_arg);
struct vbdev_error_inject_opts {
uint32_t io_type;
uint32_t error_type;
uint32_t error_num;
};
/** /**
* Inject error to the base bdev. Users can specify which IO type error is injected, * Inject error to the base bdev. Users can specify which IO type error is injected,
* what type of error is injected, and how many errors are injected. * what type of error is injected, and how many errors are injected.
* *
* \param name Name of the base bdev into which error is injected. * \param name Name of the base bdev into which error is injected.
* \param io_type IO type into which error is injected. * \param opts Options for error injection.
* \param error_num Count of injected errors
*/ */
int vbdev_error_inject_error(char *name, uint32_t io_type, uint32_t error_type, int vbdev_error_inject_error(char *name, const struct vbdev_error_inject_opts *opts);
uint32_t error_num);
#endif /* SPDK_VBDEV_ERROR_H */ #endif /* SPDK_VBDEV_ERROR_H */

View File

@ -145,16 +145,14 @@ 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;
uint32_t io_type; struct vbdev_error_inject_opts opts;
uint32_t error_type;
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), rpc_error_bdev_decode_io_type}, {"io_type", offsetof(struct rpc_error_information, opts.io_type), rpc_error_bdev_decode_io_type},
{"error_type", offsetof(struct rpc_error_information, error_type), rpc_error_bdev_decode_error_type}, {"error_type", offsetof(struct rpc_error_information, opts.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, opts.error_num), spdk_json_decode_uint32, true},
}; };
static void static void
@ -167,7 +165,7 @@ static void
rpc_bdev_error_inject_error(struct spdk_jsonrpc_request *request, 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 = {.opts.error_num = 1};
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,
@ -179,7 +177,7 @@ rpc_bdev_error_inject_error(struct spdk_jsonrpc_request *request,
goto cleanup; goto cleanup;
} }
rc = vbdev_error_inject_error(req.name, req.io_type, req.error_type, req.num); rc = vbdev_error_inject_error(req.name, &req.opts);
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;