ublk selftests: add --no_ublk_fixed_fd for not using registered ublk char device
authorMing Lei <ming.lei@redhat.com>
Wed, 27 Aug 2025 12:16:00 +0000 (20:16 +0800)
committerJens Axboe <axboe@kernel.dk>
Thu, 28 Aug 2025 13:56:57 +0000 (07:56 -0600)
commit9b2785ea8592f239836405de023c75c4f3f5ce00
tree6b090b91045ba0556d4cfefbfdf909ed8353b3de
parentc5c5eb24ed6177fc0ef4bb75fc18d07a99c1d3f0
ublk selftests: add --no_ublk_fixed_fd for not using registered ublk char device

Add a new command line option --no_ublk_fixed_fd that excludes the ublk
control device (/dev/ublkcN) from io_uring's registered files array.
When this option is used, only backing files are registered starting
from index 1, while the ublk control device is accessed using its raw
file descriptor.

Add ublk_get_registered_fd() helper function that returns the appropriate
file descriptor for use with io_uring operations.

Key optimizations implemented:
- Cache UBLKS_Q_NO_UBLK_FIXED_FD flag in ublk_queue.flags to avoid
  reading dev->no_ublk_fixed_fd in fast path
- Cache ublk char device fd in ublk_queue.ublk_fd for fast access
- Update ublk_get_registered_fd() to use ublk_queue * parameter
- Update io_uring_prep_buf_register/unregister() to use ublk_queue *
- Replace ublk_device * access with ublk_queue * access in fast paths

Also pass --no_ublk_fixed_fd to test_stress_04.sh for covering
plain ublk char device mode.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20250827121602.2619736-3-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
tools/testing/selftests/ublk/file_backed.c
tools/testing/selftests/ublk/kublk.c
tools/testing/selftests/ublk/kublk.h
tools/testing/selftests/ublk/null.c
tools/testing/selftests/ublk/stripe.c
tools/testing/selftests/ublk/test_stress_04.sh