Message ID | 20230506113914.23419-1-frank.li@vivo.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [f2fs-dev,1/2] f2fs: move the conditional statement after holding the inode lock in f2fs_move_file_range() | expand |
Le 06/05/2023 à 13:39, Yangtao Li a écrit : > For judging the inode flag state, the inode lock must be held. > BTW, add compressd file check and to avoid 'if' nesting. > > Fixes: 4dd6f977fc77 ("f2fs: support an ioctl to move a range of data blocks") > Signed-off-by: Yangtao Li <frank.li@vivo.com> > --- > fs/f2fs/file.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > index 78aa8cff4b41..850e745ecf88 100644 > --- a/fs/f2fs/file.c > +++ b/fs/f2fs/file.c > @@ -2790,9 +2790,6 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, > if (!S_ISREG(src->i_mode) || !S_ISREG(dst->i_mode)) > return -EINVAL; > > - if (IS_ENCRYPTED(src) || IS_ENCRYPTED(dst)) > - return -EOPNOTSUPP; > - > if (pos_out < 0 || pos_in < 0) > return -EINVAL; > > @@ -2804,12 +2801,17 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, > } > > inode_lock(src); > - if (src != dst) { > + if (src != dst && !inode_trylock(dst)) { > ret = -EBUSY; > - if (!inode_trylock(dst)) > - goto out; > + goto out; > } > > + if (IS_ENCRYPTED(src) || IS_ENCRYPTED(dst)) > + return -EOPNOTSUPP; ret = -EOPNOTSUPP; goto out_unlock; ? > + > + if (f2fs_compressed_file(src) || f2fs_compressed_file(dst)) > + return -EOPNOTSUPP; Same CJ > + > ret = -EINVAL; > if (pos_in + len > src->i_size || pos_in + len < pos_in) > goto out_unlock;
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 78aa8cff4b41..850e745ecf88 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2790,9 +2790,6 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, if (!S_ISREG(src->i_mode) || !S_ISREG(dst->i_mode)) return -EINVAL; - if (IS_ENCRYPTED(src) || IS_ENCRYPTED(dst)) - return -EOPNOTSUPP; - if (pos_out < 0 || pos_in < 0) return -EINVAL; @@ -2804,12 +2801,17 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, } inode_lock(src); - if (src != dst) { + if (src != dst && !inode_trylock(dst)) { ret = -EBUSY; - if (!inode_trylock(dst)) - goto out; + goto out; } + if (IS_ENCRYPTED(src) || IS_ENCRYPTED(dst)) + return -EOPNOTSUPP; + + if (f2fs_compressed_file(src) || f2fs_compressed_file(dst)) + return -EOPNOTSUPP; + ret = -EINVAL; if (pos_in + len > src->i_size || pos_in + len < pos_in) goto out_unlock;
For judging the inode flag state, the inode lock must be held. BTW, add compressd file check and to avoid 'if' nesting. Fixes: 4dd6f977fc77 ("f2fs: support an ioctl to move a range of data blocks") Signed-off-by: Yangtao Li <frank.li@vivo.com> --- fs/f2fs/file.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)