xref: /spdk/module/bdev/error/vbdev_error.h (revision 45a053c5777494f4e8ce4bc1191c9de3920377f7)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2017 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #ifndef SPDK_VBDEV_ERROR_H
7 #define SPDK_VBDEV_ERROR_H
8 
9 #include "spdk/stdinc.h"
10 #include "spdk/bdev.h"
11 #include "spdk/uuid.h"
12 
13 enum vbdev_error_type {
14 	VBDEV_IO_FAILURE = 1,
15 	VBDEV_IO_PENDING,
16 	VBDEV_IO_CORRUPT_DATA,
17 	VBDEV_IO_NOMEM,
18 };
19 
20 typedef void (*spdk_delete_error_complete)(void *cb_arg, int bdeverrno);
21 
22 /**
23  * Create a vbdev on the base bdev to inject error into it.
24  *
25  * \param base_bdev_name Name of the base bdev.
26  * \param uuid Optional UUID to assign to the bdev.
27  * \return 0 on success or negative on failure.
28  */
29 int vbdev_error_create(const char *base_bdev_name, const struct spdk_uuid *uuid);
30 
31 /**
32  * Delete vbdev used to inject errors.
33  *
34  * \param error_vbdev_name Name of the error vbdev.
35  * \param cb_fn Function to call after deletion.
36  * \param cb_arg Arguments to pass to cb_fn.
37  */
38 void vbdev_error_delete(const char *error_vbdev_name, spdk_delete_error_complete cb_fn,
39 			void *cb_arg);
40 
41 struct vbdev_error_inject_opts {
42 	uint32_t io_type;
43 	uint32_t error_type;
44 	uint32_t error_num;
45 	uint64_t error_qd;
46 	uint64_t corrupt_offset;
47 	uint8_t corrupt_value;
48 };
49 
50 /**
51  * Inject error to the base bdev. Users can specify which IO type error is injected,
52  * what type of error is injected, and how many errors are injected.
53  *
54  * \param name Name of the base bdev into which error is injected.
55  * \param opts Options for error injection.
56  */
57 int vbdev_error_inject_error(char *name, const struct vbdev_error_inject_opts *opts);
58 
59 #endif /* SPDK_VBDEV_ERROR_H */
60