fs: Separate out kiocb flags setup based on RWF_* flags
authorGoldwyn Rodrigues <rgoldwyn@suse.com>
Tue, 20 Jun 2017 12:05:40 +0000 (07:05 -0500)
committerJens Axboe <axboe@kernel.dk>
Tue, 20 Jun 2017 13:12:03 +0000 (07:12 -0600)
Also added RWF_SUPPORTED to encompass all flags.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/read_write.c
include/linux/fs.h
include/uapi/linux/fs.h

index 47c1d4484df9e6b69333215efc10d7a5db64210f..53c816c6112293b1ce4b2582f1dec7718ebba606 100644 (file)
@@ -678,16 +678,10 @@ static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter,
        struct kiocb kiocb;
        ssize_t ret;
 
-       if (flags & ~(RWF_HIPRI | RWF_DSYNC | RWF_SYNC))
-               return -EOPNOTSUPP;
-
        init_sync_kiocb(&kiocb, filp);
-       if (flags & RWF_HIPRI)
-               kiocb.ki_flags |= IOCB_HIPRI;
-       if (flags & RWF_DSYNC)
-               kiocb.ki_flags |= IOCB_DSYNC;
-       if (flags & RWF_SYNC)
-               kiocb.ki_flags |= (IOCB_DSYNC | IOCB_SYNC);
+       ret = kiocb_set_rw_flags(&kiocb, flags);
+       if (ret)
+               return ret;
        kiocb.ki_pos = *ppos;
 
        if (type == READ)
index 023f0324762b4ba39844cdd90c438ca80f4b539e..96a1a1fa54a944b7a108c94fbc234deb6878b28a 100644 (file)
@@ -3057,6 +3057,20 @@ static inline int iocb_flags(struct file *file)
        return res;
 }
 
+static inline int kiocb_set_rw_flags(struct kiocb *ki, int flags)
+{
+       if (unlikely(flags & ~RWF_SUPPORTED))
+               return -EOPNOTSUPP;
+
+       if (flags & RWF_HIPRI)
+               ki->ki_flags |= IOCB_HIPRI;
+       if (flags & RWF_DSYNC)
+               ki->ki_flags |= IOCB_DSYNC;
+       if (flags & RWF_SYNC)
+               ki->ki_flags |= (IOCB_DSYNC | IOCB_SYNC);
+       return 0;
+}
+
 static inline ino_t parent_ino(struct dentry *dentry)
 {
        ino_t res;
index 24e61a54feaaab505b2d2e74e5462a8638d0c897..937c3e39650a0ae3eefd422dba7a677e4646f486 100644 (file)
@@ -361,4 +361,6 @@ struct fscrypt_key {
 #define RWF_DSYNC                      0x00000002 /* per-IO O_DSYNC */
 #define RWF_SYNC                       0x00000004 /* per-IO O_SYNC */
 
+#define RWF_SUPPORTED                  (RWF_HIPRI | RWF_DSYNC | RWF_SYNC)
+
 #endif /* _UAPI_LINUX_FS_H */