Skip to content

Commit af6505e

Browse files
axboebrauner
authored andcommitted
fs: add RWF_DONTCACHE iocb and FOP_DONTCACHE file_operations flag
If a file system supports uncached buffered IO, it may set FOP_DONTCACHE and enable support for RWF_DONTCACHE. If RWF_DONTCACHE is attempted without the file system supporting it, it'll get errored with -EOPNOTSUPP. Signed-off-by: Jens Axboe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 40384c8 commit af6505e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

include/linux/fs.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ struct readahead_control;
322322
#define IOCB_NOWAIT (__force int) RWF_NOWAIT
323323
#define IOCB_APPEND (__force int) RWF_APPEND
324324
#define IOCB_ATOMIC (__force int) RWF_ATOMIC
325+
#define IOCB_DONTCACHE (__force int) RWF_DONTCACHE
325326

326327
/* non-RWF related bits - start at 16 */
327328
#define IOCB_EVENTFD (1 << 16)
@@ -356,7 +357,8 @@ struct readahead_control;
356357
{ IOCB_SYNC, "SYNC" }, \
357358
{ IOCB_NOWAIT, "NOWAIT" }, \
358359
{ IOCB_APPEND, "APPEND" }, \
359-
{ IOCB_ATOMIC, "ATOMIC"}, \
360+
{ IOCB_ATOMIC, "ATOMIC" }, \
361+
{ IOCB_DONTCACHE, "DONTCACHE" }, \
360362
{ IOCB_EVENTFD, "EVENTFD"}, \
361363
{ IOCB_DIRECT, "DIRECT" }, \
362364
{ IOCB_WRITE, "WRITE" }, \
@@ -2127,6 +2129,8 @@ struct file_operations {
21272129
#define FOP_UNSIGNED_OFFSET ((__force fop_flags_t)(1 << 5))
21282130
/* Supports asynchronous lock callbacks */
21292131
#define FOP_ASYNC_LOCK ((__force fop_flags_t)(1 << 6))
2132+
/* File system supports uncached read/write buffered IO */
2133+
#define FOP_DONTCACHE ((__force fop_flags_t)(1 << 7))
21302134

21312135
/* Wrap a directory iterator that needs exclusive inode access */
21322136
int wrap_directory_iterator(struct file *, struct dir_context *,
@@ -3614,6 +3618,14 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags,
36143618
if (!(ki->ki_filp->f_mode & FMODE_CAN_ATOMIC_WRITE))
36153619
return -EOPNOTSUPP;
36163620
}
3621+
if (flags & RWF_DONTCACHE) {
3622+
/* file system must support it */
3623+
if (!(ki->ki_filp->f_op->fop_flags & FOP_DONTCACHE))
3624+
return -EOPNOTSUPP;
3625+
/* DAX mappings not supported */
3626+
if (IS_DAX(ki->ki_filp->f_mapping->host))
3627+
return -EOPNOTSUPP;
3628+
}
36173629
kiocb_flags |= (__force int) (flags & RWF_SUPPORTED);
36183630
if (flags & RWF_SYNC)
36193631
kiocb_flags |= IOCB_DSYNC;

include/uapi/linux/fs.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,13 @@ typedef int __bitwise __kernel_rwf_t;
332332
/* Atomic Write */
333333
#define RWF_ATOMIC ((__force __kernel_rwf_t)0x00000040)
334334

335+
/* buffered IO that drops the cache after reading or writing data */
336+
#define RWF_DONTCACHE ((__force __kernel_rwf_t)0x00000080)
337+
335338
/* mask of flags supported by the kernel */
336339
#define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\
337-
RWF_APPEND | RWF_NOAPPEND | RWF_ATOMIC)
340+
RWF_APPEND | RWF_NOAPPEND | RWF_ATOMIC |\
341+
RWF_DONTCACHE)
338342

339343
#define PROCFS_IOCTL_MAGIC 'f'
340344

0 commit comments

Comments
 (0)