Skip to contentSkip to conversation

fs: add RWF_APPEND

PATCH RESEND In review Jürg Billeter 3 participants 3 messages Sep 29, 2017 – Oct 1, 2017 VFS

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 fs: add RWF_APPEND

This is the per-I/O equivalent of O_APPEND to support atomic append operations on any open file.

If a file is opened with O_APPEND, pwrite() ignores the offset and always appends data to the end of the file. RWF_APPEND enables atomic append and pwrite() with offset on a single file descriptor.

---
 include/linux/fs.h      | 2 ++
 include/uapi/linux/fs.h | 6 +++++-
 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/fs.h +2 -0
index 339e73742e73..fee24eae7523 100644
@@ -3204,6 +3204,8 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags)
 		ki->ki_flags |= IOCB_DSYNC;
 	if (flags & RWF_SYNC)
 		ki->ki_flags |= (IOCB_DSYNC | IOCB_SYNC);
+	if (flags & RWF_APPEND)
+		ki->ki_flags |= IOCB_APPEND;
 	return 0;
 }
 
include/uapi/linux/fs.h +5 -1
index 56235dddea7d..ac145430bcd8 100644
@@ -376,7 +376,11 @@ typedef int __bitwise __kernel_rwf_t;
 /* per-IO, return -EAGAIN if operation would block */
 #define RWF_NOWAIT	((__force __kernel_rwf_t)0x00000008)
 
+/* per-IO O_APPEND */
+#define RWF_APPEND	((__force __kernel_rwf_t)0x00000010)
+
 /* mask of flags supported by the kernel */
-#define RWF_SUPPORTED	(RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT)
+#define RWF_SUPPORTED	(RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\
+			 RWF_APPEND)
 
 #endif /* _UAPI_LINUX_FS_H */
Signature · 1 line
2.14.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jürg Billeter

This is the per-I/O equivalent of O_APPEND to support atomic append operations on any open file.

If a file is opened with O_APPEND, pwrite() ignores the offset and always appends data to the end of the file. RWF_APPEND enables atomic append and pwrite() with offset on a single file descriptor.

I think similarly we can introduce RWF_DIRECT, though I am not sure if users would want to mix buffered writes and direct writes.

Quoted 37 lines
---
 include/linux/fs.h      | 2 ++
 include/uapi/linux/fs.h | 6 +++++-
 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/fs.h +2 -0
index 339e73742e73..fee24eae7523 100644
@@ -3204,6 +3204,8 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags)
 		ki->ki_flags |= IOCB_DSYNC;
 	if (flags & RWF_SYNC)
 		ki->ki_flags |= (IOCB_DSYNC | IOCB_SYNC);
+	if (flags & RWF_APPEND)
+		ki->ki_flags |= IOCB_APPEND;
 	return 0;
 }
 
include/uapi/linux/fs.h +5 -1
index 56235dddea7d..ac145430bcd8 100644
@@ -376,7 +376,11 @@ typedef int __bitwise __kernel_rwf_t;
 /* per-IO, return -EAGAIN if operation would block */
 #define RWF_NOWAIT	((__force __kernel_rwf_t)0x00000008)
 
+/* per-IO O_APPEND */
+#define RWF_APPEND	((__force __kernel_rwf_t)0x00000010)
+
 /* mask of flags supported by the kernel */
-#define RWF_SUPPORTED	(RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT)
+#define RWF_SUPPORTED	(RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\
+			 RWF_APPEND)
 
 #endif /* _UAPI_LINUX_FS_H */
Signature · 1 line
Goldwyn