diff options
author | Ming Lei <ming.lei@redhat.com> | 2025-03-01 00:19:14 +0800 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2025-02-28 09:28:08 -0700 |
commit | 6aecda00b7d1e187c31e702d607d2b51bbcddbcc (patch) | |
tree | 9400b018336915cc93ddb88c1ccb3e04aa27c06f /tools/testing/selftests/ublk/null.c | |
parent | ed9f3112a8a8f6e6919d3b9da2651fa302df7be3 (diff) |
selftests: ublk: add kernel selftests for ublk
Both ublk driver and userspace heavily depends on io_uring subsystem,
and tools/testing/selftests/ should be the best place for holding this
cross-subsystem tests.
Add basic read/write IO test over this ublk null disk, and make sure ublk
working.
More tests will be added.
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20250228161919.2869102-2-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'tools/testing/selftests/ublk/null.c')
-rw-r--r-- | tools/testing/selftests/ublk/null.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/testing/selftests/ublk/null.c b/tools/testing/selftests/ublk/null.c new file mode 100644 index 000000000000..b6ef16a8f514 --- /dev/null +++ b/tools/testing/selftests/ublk/null.c @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include "kublk.h" + +static int ublk_null_tgt_init(struct ublk_dev *dev) +{ + const struct ublksrv_ctrl_dev_info *info = &dev->dev_info; + unsigned long dev_size = 250UL << 30; + + 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, + }, + }; + + return 0; +} + +static int ublk_null_queue_io(struct ublk_queue *q, int tag) +{ + const struct ublksrv_io_desc *iod = ublk_get_iod(q, tag); + + ublk_complete_io(q, tag, iod->nr_sectors << 9); + return 0; +} + +const struct ublk_tgt_ops null_tgt_ops = { + .name = "null", + .init_tgt = ublk_null_tgt_init, + .queue_io = ublk_null_queue_io, +}; |