]> www.infradead.org Git - users/hch/misc.git/commitdiff
fs: add a FMODE_ flag to indicate IOCB_HAS_METADATA availability
authorChristoph Hellwig <hch@lst.de>
Tue, 19 Aug 2025 08:25:00 +0000 (10:25 +0200)
committerChristian Brauner <brauner@kernel.org>
Wed, 20 Aug 2025 09:12:58 +0000 (11:12 +0200)
Currently the kernel will happily route io_uring requests with metadata
to file operations that don't support it.  Add a FMODE_ flag to guard
that.

Fixes: 4de2ce04c862 ("fs: introduce IOCB_HAS_METADATA for metadata")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/20250819082517.2038819-2-hch@lst.de
Signed-off-by: Christian Brauner <brauner@kernel.org>
block/fops.c
include/linux/fs.h
io_uring/rw.c

index 82451ac8ff25dd5a8540f1684d621d9b788e29ff..08e7c21bd9f103987d2be42077a7855c8ad4ac27 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/init.h>
 #include <linux/mm.h>
 #include <linux/blkdev.h>
+#include <linux/blk-integrity.h>
 #include <linux/buffer_head.h>
 #include <linux/mpage.h>
 #include <linux/uio.h>
@@ -687,6 +688,8 @@ static int blkdev_open(struct inode *inode, struct file *filp)
 
        if (bdev_can_atomic_write(bdev))
                filp->f_mode |= FMODE_CAN_ATOMIC_WRITE;
+       if (blk_get_integrity(bdev->bd_disk))
+               filp->f_mode |= FMODE_HAS_METADATA;
 
        ret = bdev_open(bdev, mode, filp->private_data, NULL, filp);
        if (ret)
index d7ab4f96d7051f23246c1a16a2d09b1ffcd2d5de..601d036a6c78ef4cb47dc77a38ab658fdc203208 100644 (file)
@@ -149,7 +149,8 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
 /* Expect random access pattern */
 #define FMODE_RANDOM           ((__force fmode_t)(1 << 12))
 
-/* FMODE_* bit 13 */
+/* Supports IOCB_HAS_METADATA */
+#define FMODE_HAS_METADATA     ((__force fmode_t)(1 << 13))
 
 /* File is opened with O_PATH; almost nothing can be done with it */
 #define FMODE_PATH             ((__force fmode_t)(1 << 14))
index 52a5b950b2e5e923bc629ca8724610a7cb559762..af5a54b5db12338e53b9cc3ff31c1c7ac162eb28 100644 (file)
@@ -886,6 +886,9 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
        if (req->flags & REQ_F_HAS_METADATA) {
                struct io_async_rw *io = req->async_data;
 
+               if (!(file->f_mode & FMODE_HAS_METADATA))
+                       return -EINVAL;
+
                /*
                 * We have a union of meta fields with wpq used for buffered-io
                 * in io_async_rw, so fail it here.