tools/testing/selftests/ublk/fault_inject.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/ublk/fault_inject.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/ublk/fault_inject.c- Extension
.c- Size
- 4228 bytes
- Lines
- 154
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kublk.h
Detected Declarations
struct fi_optsfunction ublk_fault_inject_tgt_initfunction ublk_fault_inject_pre_fetch_iofunction ublk_fault_inject_queue_iofunction ublk_fault_inject_tgt_io_donefunction ublk_fault_inject_cmd_linefunction ublk_fault_inject_usage
Annotated Snippet
struct fi_opts {
long long delay_ns;
bool die_during_fetch;
};
static int ublk_fault_inject_tgt_init(const struct dev_ctx *ctx,
struct ublk_dev *dev)
{
const struct ublksrv_ctrl_dev_info *info = &dev->dev_info;
unsigned long dev_size = 250UL << 30;
struct fi_opts *opts = NULL;
if (ctx->auto_zc_fallback) {
ublk_err("%s: not support auto_zc_fallback\n", __func__);
return -EINVAL;
}
dev->tgt.dev_size = dev_size;
dev->tgt.params = (struct ublk_params) {
.types = UBLK_PARAM_TYPE_BASIC,
.basic = {
.logical_bs_shift = 9,
.physical_bs_shift = 12,
.io_opt_shift = 12,
.io_min_shift = 9,
.max_sectors = info->max_io_buf_bytes >> 9,
.dev_sectors = dev_size >> 9,
},
};
ublk_set_integrity_params(ctx, &dev->tgt.params);
opts = calloc(1, sizeof(*opts));
if (!opts) {
ublk_err("%s: couldn't allocate memory for opts\n", __func__);
return -ENOMEM;
}
opts->delay_ns = ctx->fault_inject.delay_us * 1000;
opts->die_during_fetch = ctx->fault_inject.die_during_fetch;
dev->private_data = opts;
return 0;
}
static void ublk_fault_inject_pre_fetch_io(struct ublk_thread *t,
struct ublk_queue *q, int tag,
bool batch)
{
struct fi_opts *opts = q->dev->private_data;
if (!opts->die_during_fetch)
return;
/*
* Each queue fetches its IOs in increasing order of tags, so
* dying just before we're about to fetch tag 1 (regardless of
* what queue we're on) guarantees that we've fetched a nonempty
* proper subset of the tags on that queue.
*/
if (tag == 1) {
/*
* Ensure our commands are actually live in the kernel
* before we die.
*/
io_uring_submit(&t->ring);
raise(SIGKILL);
}
}
static int ublk_fault_inject_queue_io(struct ublk_thread *t,
struct ublk_queue *q, int tag)
{
const struct ublksrv_io_desc *iod = ublk_get_iod(q, tag);
struct io_uring_sqe *sqe;
struct fi_opts *opts = q->dev->private_data;
struct __kernel_timespec ts = {
.tv_nsec = opts->delay_ns,
};
ublk_io_alloc_sqes(t, &sqe, 1);
io_uring_prep_timeout(sqe, &ts, 1, 0);
sqe->user_data = build_user_data(tag, ublksrv_get_op(iod), 0, q->q_id, 1);
ublk_queued_tgt_io(t, q, tag, 1);
return 0;
}
static void ublk_fault_inject_tgt_io_done(struct ublk_thread *t,
struct ublk_queue *q,
Annotation
- Immediate include surface: `kublk.h`.
- Detected declarations: `struct fi_opts`, `function ublk_fault_inject_tgt_init`, `function ublk_fault_inject_pre_fetch_io`, `function ublk_fault_inject_queue_io`, `function ublk_fault_inject_tgt_io_done`, `function ublk_fault_inject_cmd_line`, `function ublk_fault_inject_usage`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.