linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: align IOCB_* flags with RWF_* flags
@ 2020-08-31 18:08 Jens Axboe
  2020-09-07 19:43 ` Jens Axboe
  2020-09-07 20:15 ` Matthew Wilcox
  0 siblings, 2 replies; 4+ messages in thread
From: Jens Axboe @ 2020-08-31 18:08 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel; +Cc: Alexander Viro, Jann Horn

We have a set of flags that are shared between the two and inherired
in kiocb_set_rw_flags(), but we check and set these individually.
Reorder the IOCB flags so that the bottom part of the space is synced
with the RWF flag space, and then we can do them all in one mask and
set operation.

The only exception is RWF_SYNC, which needs to mark IOCB_SYNC and
IOCB_DSYNC. Do that one separately.

This shaves 15 bytes of text from kiocb_set_rw_flags() for me.

Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 7519ae003a08..c82360600ae4 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -310,17 +310,20 @@ enum rw_hint {
 	WRITE_LIFE_EXTREME	= RWH_WRITE_LIFE_EXTREME,
 };
 
-#define IOCB_EVENTFD		(1 << 0)
-#define IOCB_APPEND		(1 << 1)
-#define IOCB_DIRECT		(1 << 2)
-#define IOCB_HIPRI		(1 << 3)
-#define IOCB_DSYNC		(1 << 4)
-#define IOCB_SYNC		(1 << 5)
-#define IOCB_WRITE		(1 << 6)
-#define IOCB_NOWAIT		(1 << 7)
+/* Match RWF_* bits to IOCB bits */
+#define IOCB_HIPRI		(__force int) RWF_HIPRI
+#define IOCB_DSYNC		(__force int) RWF_DSYNC
+#define IOCB_SYNC		(__force int) RWF_SYNC
+#define IOCB_NOWAIT		(__force int) RWF_NOWAIT
+#define IOCB_APPEND		(__force int) RWF_APPEND
+
+/* non-RWF related bits - start at 16 */
+#define IOCB_EVENTFD		(1 << 16)
+#define IOCB_DIRECT		(1 << 17)
+#define IOCB_WRITE		(1 << 18)
 /* iocb->ki_waitq is valid */
-#define IOCB_WAITQ		(1 << 8)
-#define IOCB_NOIO		(1 << 9)
+#define IOCB_WAITQ		(1 << 19)
+#define IOCB_NOIO		(1 << 20)
 
 struct kiocb {
 	struct file		*ki_filp;
@@ -3317,6 +3320,9 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags)
 {
 	int kiocb_flags = 0;
 
+	/* make sure there's no overlap between RWF and private IOCB flags */
+	BUILD_BUG_ON((__force int) RWF_SUPPORTED & IOCB_EVENTFD);
+
 	if (!flags)
 		return 0;
 	if (unlikely(flags & ~RWF_SUPPORTED))
@@ -3325,16 +3331,11 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags)
 	if (flags & RWF_NOWAIT) {
 		if (!(ki->ki_filp->f_mode & FMODE_NOWAIT))
 			return -EOPNOTSUPP;
-		kiocb_flags |= IOCB_NOWAIT | IOCB_NOIO;
+		kiocb_flags |= IOCB_NOIO;
 	}
-	if (flags & RWF_HIPRI)
-		kiocb_flags |= IOCB_HIPRI;
-	if (flags & RWF_DSYNC)
-		kiocb_flags |= IOCB_DSYNC;
+	kiocb_flags |= (__force int) (flags & RWF_SUPPORTED);
 	if (flags & RWF_SYNC)
-		kiocb_flags |= (IOCB_DSYNC | IOCB_SYNC);
-	if (flags & RWF_APPEND)
-		kiocb_flags |= IOCB_APPEND;
+		kiocb_flags |= IOCB_DSYNC;
 
 	ki->ki_flags |= kiocb_flags;
 	return 0;

-- 
Jens Axboe


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs: align IOCB_* flags with RWF_* flags
  2020-08-31 18:08 [PATCH] fs: align IOCB_* flags with RWF_* flags Jens Axboe
@ 2020-09-07 19:43 ` Jens Axboe
  2020-09-07 20:15 ` Matthew Wilcox
  1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2020-09-07 19:43 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel; +Cc: Alexander Viro, Jann Horn

On 8/31/20 12:08 PM, Jens Axboe wrote:
> We have a set of flags that are shared between the two and inherired
> in kiocb_set_rw_flags(), but we check and set these individually.
> Reorder the IOCB flags so that the bottom part of the space is synced
> with the RWF flag space, and then we can do them all in one mask and
> set operation.
> 
> The only exception is RWF_SYNC, which needs to mark IOCB_SYNC and
> IOCB_DSYNC. Do that one separately.
> 
> This shaves 15 bytes of text from kiocb_set_rw_flags() for me.

Al, are you OK with me queueing this one up? I'm fine either way,
obviously no dependencies for this one, just want to ensure it isn't
dropped.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs: align IOCB_* flags with RWF_* flags
  2020-08-31 18:08 [PATCH] fs: align IOCB_* flags with RWF_* flags Jens Axboe
  2020-09-07 19:43 ` Jens Axboe
@ 2020-09-07 20:15 ` Matthew Wilcox
  2020-09-08  2:12   ` Jens Axboe
  1 sibling, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2020-09-07 20:15 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-fsdevel, linux-kernel, Alexander Viro, Jann Horn

On Mon, Aug 31, 2020 at 12:08:10PM -0600, Jens Axboe wrote:
> We have a set of flags that are shared between the two and inherired
> in kiocb_set_rw_flags(), but we check and set these individually.
> Reorder the IOCB flags so that the bottom part of the space is synced
> with the RWF flag space, and then we can do them all in one mask and
> set operation.
> 
> The only exception is RWF_SYNC, which needs to mark IOCB_SYNC and
> IOCB_DSYNC. Do that one separately.
> 
> This shaves 15 bytes of text from kiocb_set_rw_flags() for me.
> 
> Signed-off-by: Jens Axboe <axboe@kernel.dk>

Suggested-by: Matthew Wilcox (Oracle) <willy@infradead.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs: align IOCB_* flags with RWF_* flags
  2020-09-07 20:15 ` Matthew Wilcox
@ 2020-09-08  2:12   ` Jens Axboe
  0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2020-09-08  2:12 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: linux-fsdevel, linux-kernel, Alexander Viro, Jann Horn

On 9/7/20 2:15 PM, Matthew Wilcox wrote:
> On Mon, Aug 31, 2020 at 12:08:10PM -0600, Jens Axboe wrote:
>> We have a set of flags that are shared between the two and inherired
>> in kiocb_set_rw_flags(), but we check and set these individually.
>> Reorder the IOCB flags so that the bottom part of the space is synced
>> with the RWF flag space, and then we can do them all in one mask and
>> set operation.
>>
>> The only exception is RWF_SYNC, which needs to mark IOCB_SYNC and
>> IOCB_DSYNC. Do that one separately.
>>
>> This shaves 15 bytes of text from kiocb_set_rw_flags() for me.
>>
>> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> 
> Suggested-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Added

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-08  2:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31 18:08 [PATCH] fs: align IOCB_* flags with RWF_* flags Jens Axboe
2020-09-07 19:43 ` Jens Axboe
2020-09-07 20:15 ` Matthew Wilcox
2020-09-08  2:12   ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).