]> git.dujemihanovic.xyz Git - linux.git/commit
block: implement async io_uring discard cmd
authorPavel Begunkov <asml.silence@gmail.com>
Wed, 11 Sep 2024 16:34:41 +0000 (17:34 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 11 Sep 2024 16:45:28 +0000 (10:45 -0600)
commit50c52250e2d74b098465841163c18f4b4e9ad430
tree7bc88aef197bb8ad7279b522e21b6b516f2e0173
parent7a07210bbcb35c0075830bb94b5321978164cb60
block: implement async io_uring discard cmd

io_uring allows implementing custom file specific asynchronous
operations via the fops->uring_cmd callback, a.k.a. IORING_OP_URING_CMD
requests or just io_uring commands. Use it to add support for async
discards.

Normally, it first tries to queue up bios in a non-blocking context,
and if that fails, we'd retry from a blocking context by returning
-EAGAIN to the core io_uring. We always get the result from bios
asynchronously by setting a custom bi_end_io callback, at which point
we drag the request into the task context to either reissue or complete
it and post a completion to the user.

Unlike ioctl(BLKDISCARD) with stronger guarantees against races, we only
do a best effort attempt to invalidate page cache, and it can race with
any writes and reads and leave page cache stale. It's the same kind of
races we allow to direct writes.

Also, apart from cases where discarding is not allowed at all, e.g.
discards are not supported or the file/device is read only, the user
should assume that the sector range on disk is not valid anymore, even
when an error was returned to the user.

Suggested-by: Conrad Meyer <conradmeyer@meta.com>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/2b5210443e4fa0257934f73dfafcc18a77cd0e09.1726072086.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk.h
block/fops.c
block/ioctl.c
include/uapi/linux/blkdev.h [new file with mode: 0644]