Skip to content

Commit d072148

Browse files
Christoph Hellwigbrauner
authored andcommitted
fs: add a FMODE_ flag to indicate IOCB_HAS_METADATA availability
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: 4de2ce0 ("fs: introduce IOCB_HAS_METADATA for metadata") Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent b19a97d commit d072148

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

block/fops.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/init.h>
88
#include <linux/mm.h>
99
#include <linux/blkdev.h>
10+
#include <linux/blk-integrity.h>
1011
#include <linux/buffer_head.h>
1112
#include <linux/mpage.h>
1213
#include <linux/uio.h>
@@ -687,6 +688,8 @@ static int blkdev_open(struct inode *inode, struct file *filp)
687688

688689
if (bdev_can_atomic_write(bdev))
689690
filp->f_mode |= FMODE_CAN_ATOMIC_WRITE;
691+
if (blk_get_integrity(bdev->bd_disk))
692+
filp->f_mode |= FMODE_HAS_METADATA;
690693

691694
ret = bdev_open(bdev, mode, filp->private_data, NULL, filp);
692695
if (ret)

include/linux/fs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
149149
/* Expect random access pattern */
150150
#define FMODE_RANDOM ((__force fmode_t)(1 << 12))
151151

152-
/* FMODE_* bit 13 */
152+
/* Supports IOCB_HAS_METADATA */
153+
#define FMODE_HAS_METADATA ((__force fmode_t)(1 << 13))
153154

154155
/* File is opened with O_PATH; almost nothing can be done with it */
155156
#define FMODE_PATH ((__force fmode_t)(1 << 14))

io_uring/rw.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,9 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
886886
if (req->flags & REQ_F_HAS_METADATA) {
887887
struct io_async_rw *io = req->async_data;
888888

889+
if (!(file->f_mode & FMODE_HAS_METADATA))
890+
return -EINVAL;
891+
889892
/*
890893
* We have a union of meta fields with wpq used for buffered-io
891894
* in io_async_rw, so fail it here.

0 commit comments

Comments
 (0)