summaryrefslogtreecommitdiffstats
path: root/block/fops.c
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2024-09-11 17:34:41 +0100
committerJens Axboe <axboe@kernel.dk>2024-09-11 10:45:28 -0600
commit50c52250e2d74b098465841163c18f4b4e9ad430 (patch)
tree7bc88aef197bb8ad7279b522e21b6b516f2e0173 /block/fops.c
parent7a07210bbcb35c0075830bb94b5321978164cb60 (diff)
downloadlinux-50c52250e2d74b098465841163c18f4b4e9ad430.tar.gz
linux-50c52250e2d74b098465841163c18f4b4e9ad430.tar.bz2
linux-50c52250e2d74b098465841163c18f4b4e9ad430.zip
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>
Diffstat (limited to 'block/fops.c')
-rw-r--r--block/fops.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/block/fops.c b/block/fops.c
index 9825c1713a49..8154b10b5abf 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -17,6 +17,7 @@
#include <linux/fs.h>
#include <linux/iomap.h>
#include <linux/module.h>
+#include <linux/io_uring/cmd.h>
#include "blk.h"
static inline struct inode *bdev_file_inode(struct file *file)
@@ -873,6 +874,7 @@ const struct file_operations def_blk_fops = {
.splice_read = filemap_splice_read,
.splice_write = iter_file_splice_write,
.fallocate = blkdev_fallocate,
+ .uring_cmd = blkdev_uring_cmd,
.fop_flags = FOP_BUFFER_RASYNC,
};