Skip to content

Commit db5b5e8

Browse files
committed
ovl: use simpler function to convert iocb to rw flags
Overlayfs implements its own function to translate iocb flags into rw flags, so that they can be passed into another vfs call. With commit ce71bfe ("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>
1 parent 14ab6d4 commit db5b5e8

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

fs/overlayfs/file.c

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,12 @@ static void ovl_file_accessed(struct file *file)
263263
touch_atime(&file->f_path);
264264
}
265265

266-
static rwf_t ovl_iocb_to_rwf(int ifl)
266+
#define OVL_IOCB_MASK \
267+
(IOCB_NOWAIT | IOCB_HIPRI | IOCB_DSYNC | IOCB_SYNC)
268+
269+
static rwf_t iocb_to_rw_flags(int flags)
267270
{
268-
rwf_t flags = 0;
269-
270-
if (ifl & IOCB_NOWAIT)
271-
flags |= RWF_NOWAIT;
272-
if (ifl & IOCB_HIPRI)
273-
flags |= RWF_HIPRI;
274-
if (ifl & IOCB_DSYNC)
275-
flags |= RWF_DSYNC;
276-
if (ifl & IOCB_SYNC)
277-
flags |= RWF_SYNC;
278-
279-
return flags;
271+
return (__force rwf_t)(flags & OVL_IOCB_MASK);
280272
}
281273

282274
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)
334326

335327
old_cred = ovl_override_creds(file_inode(file)->i_sb);
336328
if (is_sync_kiocb(iocb)) {
337-
ret = vfs_iter_read(real.file, iter, &iocb->ki_pos,
338-
ovl_iocb_to_rwf(iocb->ki_flags));
329+
rwf_t rwf = iocb_to_rw_flags(iocb->ki_flags);
330+
331+
ret = vfs_iter_read(real.file, iter, &iocb->ki_pos, rwf);
339332
} else {
340333
struct ovl_aio_req *aio_req;
341334

@@ -401,9 +394,10 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
401394

402395
old_cred = ovl_override_creds(file_inode(file)->i_sb);
403396
if (is_sync_kiocb(iocb)) {
397+
rwf_t rwf = iocb_to_rw_flags(ifl);
398+
404399
file_start_write(real.file);
405-
ret = vfs_iter_write(real.file, iter, &iocb->ki_pos,
406-
ovl_iocb_to_rwf(ifl));
400+
ret = vfs_iter_write(real.file, iter, &iocb->ki_pos, rwf);
407401
file_end_write(real.file);
408402
/* Update size */
409403
ovl_copyattr(inode);

0 commit comments

Comments
 (0)