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 12 enum vbdev_error_type { 13 VBDEV_IO_FAILURE = 1, 14 VBDEV_IO_PENDING, 15 VBDEV_IO_CORRUPT_DATA, 16 }; 17 18 typedef void (*spdk_delete_error_complete)(void *cb_arg, int bdeverrno); 19 20 /** 21 * Create a vbdev on the base bdev to inject error into it. 22 * 23 * \param base_bdev_name Name of the base bdev. 24 * \return 0 on success or negative on failure. 25 */ 26 int vbdev_error_create(const char *base_bdev_name); 27 28 /** 29 * Delete vbdev used to inject errors. 30 * 31 * \param error_vbdev_name Name of the error vbdev. 32 * \param cb_fn Function to call after deletion. 33 * \param cb_arg Arguments to pass to cb_fn. 34 */ 35 void vbdev_error_delete(const char *error_vbdev_name, spdk_delete_error_complete cb_fn, 36 void *cb_arg); 37 38 struct vbdev_error_inject_opts { 39 uint32_t io_type; 40 uint32_t error_type; 41 uint32_t error_num; 42 uint64_t corrupt_offset; 43 uint8_t corrupt_value; 44 }; 45 46 /** 47 * Inject error to the base bdev. Users can specify which IO type error is injected, 48 * what type of error is injected, and how many errors are injected. 49 * 50 * \param name Name of the base bdev into which error is injected. 51 * \param opts Options for error injection. 52 */ 53 int vbdev_error_inject_error(char *name, const struct vbdev_error_inject_opts *opts); 54 55 #endif /* SPDK_VBDEV_ERROR_H */ 56