Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 9a12a0df authored by Alessio Balsini's avatar Alessio Balsini Committed by Hridaya Prajapati
Browse files

BACKPORT: fs: align IOCB_* flags with RWF_* flags



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.

(cherry picked from commit ce71bfea207b4d7c21d36f24ec37618ffcea1da8)
Suggested-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Change-Id: Ib6316ae5cb3f8a14fabef5492e79783c9e6d3c4d
Signed-off-by: default avatarAlessio Balsini <balsini@google.com>
parent 27c94982
Loading
Loading
Loading
Loading
+26 −16
Original line number Diff line number Diff line
@@ -299,14 +299,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 << 19)
#define IOCB_NOIO		(1 << 20)

struct kiocb {
	struct file		*ki_filp;
@@ -3400,22 +3406,26 @@ static inline int iocb_flags(struct file *file)

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))
		return -EOPNOTSUPP;

	if (flags & RWF_NOWAIT) {
		if (!(ki->ki_filp->f_mode & FMODE_NOWAIT))
			return -EOPNOTSUPP;
		ki->ki_flags |= IOCB_NOWAIT;
		kiocb_flags |= IOCB_NOIO;
	}
	if (flags & RWF_HIPRI)
		ki->ki_flags |= IOCB_HIPRI;
	if (flags & RWF_DSYNC)
		ki->ki_flags |= IOCB_DSYNC;
	kiocb_flags |= (__force int)(flags & RWF_SUPPORTED);
	if (flags & RWF_SYNC)
		ki->ki_flags |= (IOCB_DSYNC | IOCB_SYNC);
	if (flags & RWF_APPEND)
		ki->ki_flags |= IOCB_APPEND;
		kiocb_flags |= IOCB_DSYNC;

	ki->ki_flags |= kiocb_flags;
	return 0;
}