]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ovl: use simpler function to convert iocb to rw flags
authorAmir Goldstein <amir73il@gmail.com>
Wed, 6 Sep 2023 07:52:13 +0000 (10:52 +0300)
committerAmir Goldstein <amir73il@gmail.com>
Mon, 30 Oct 2023 22:12:54 +0000 (00:12 +0200)
Overlayfs implements its own function to translate iocb flags into rw
flags, so that they can be passed into another vfs call.

With commit ce71bfea207b4 ("fs: align IOCB_* flags with RWF_* flags")
Jens created a 1:1 matching between the iocb flags and rw flags,
simplifying the conversion.

Signed-off-by: Alessio Balsini <balsini@android.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
fs/overlayfs/file.c

index ec3671ca140c3f5af926fd74268d2a3a653f7574..4dccef12a33a8e90bc10e9f87660cf650cc157f2 100644 (file)
@@ -263,20 +263,12 @@ static void ovl_file_accessed(struct file *file)
        touch_atime(&file->f_path);
 }
 
-static rwf_t ovl_iocb_to_rwf(int ifl)
+#define OVL_IOCB_MASK \
+       (IOCB_NOWAIT | IOCB_HIPRI | IOCB_DSYNC | IOCB_SYNC)
+
+static rwf_t iocb_to_rw_flags(int flags)
 {
-       rwf_t flags = 0;
-
-       if (ifl & IOCB_NOWAIT)
-               flags |= RWF_NOWAIT;
-       if (ifl & IOCB_HIPRI)
-               flags |= RWF_HIPRI;
-       if (ifl & IOCB_DSYNC)
-               flags |= RWF_DSYNC;
-       if (ifl & IOCB_SYNC)
-               flags |= RWF_SYNC;
-
-       return flags;
+       return (__force rwf_t)(flags & OVL_IOCB_MASK);
 }
 
 static inline void ovl_aio_put(struct ovl_aio_req *aio_req)
@@ -334,8 +326,9 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 
        old_cred = ovl_override_creds(file_inode(file)->i_sb);
        if (is_sync_kiocb(iocb)) {
-               ret = vfs_iter_read(real.file, iter, &iocb->ki_pos,
-                                   ovl_iocb_to_rwf(iocb->ki_flags));
+               rwf_t rwf = iocb_to_rw_flags(iocb->ki_flags);
+
+               ret = vfs_iter_read(real.file, iter, &iocb->ki_pos, rwf);
        } else {
                struct ovl_aio_req *aio_req;
 
@@ -401,9 +394,10 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
 
        old_cred = ovl_override_creds(file_inode(file)->i_sb);
        if (is_sync_kiocb(iocb)) {
+               rwf_t rwf = iocb_to_rw_flags(ifl);
+
                file_start_write(real.file);
-               ret = vfs_iter_write(real.file, iter, &iocb->ki_pos,
-                                    ovl_iocb_to_rwf(ifl));
+               ret = vfs_iter_write(real.file, iter, &iocb->ki_pos, rwf);
                file_end_write(real.file);
                /* Update size */
                ovl_copyattr(inode);