f2fs: fix to use per-inode maxbytes in f2fs_fiemap
PATCH 1/1 f2fs: fix to use per-inode maxbytes in f2fs_fiemap
F2FS inode may have different max size,
so change to use per-inode maxbytes.
--- fs/f2fs/data.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/f2fs/data.c +5 -0
@@ -1838,6 +1838,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,int ret =0 ;bool compr_cluster = false;unsigned int cluster_size =F2FS_I (inode)->i_cluster_size; +loff_t maxbytes;if (fieinfo->fi_flags &FIEMAP_FLAG_CACHE ) { ret =f2fs_precache_extents (inode);
@@ -1845,6 +1846,10 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,return ret; } + maxbytes =max_file_blocks (inode) <<F2FS_BLKSIZE_BITS ; +if (len > maxbytes || (maxbytes - len) < start) + len = maxbytes - start; + ret =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_XATTR );if (ret)return ret;
Signature · 9 lines
2.27.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 21 lines · Chengguang Xu
F2FS inode may have different max size,
so change to use per-inode maxbytes.Signed-off-by Chengguang Xu <[email protected]>--- fs/f2fs/data.c | 5 +++++ 1 file changed, 5 insertions(+)fs/f2fs/data.c +1
-0@@ -1838,6 +1838,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,int ret =0 ;bool compr_cluster = false;unsigned int cluster_size =F2FS_I (inode)->i_cluster_size; +loff_t maxbytes;if (fieinfo->fi_flags &FIEMAP_FLAG_CACHE ) { ret =f2fs_precache_extents (inode);
fs/f2fs/data.c int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · line 1851
Quoted 6 lines
fs/f2fs/data.c +3
-0@@ -1845,6 +1846,10 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,return ret; } + maxbytes =max_file_blocks (inode) <<F2FS_BLKSIZE_BITS ; +if (len > maxbytes || (maxbytes - len) < start) + len = maxbytes - start;
This should be checked under inode lock, otherwise the max filesize calculation can race with compress inode conversion.
Thanks,
fs/f2fs/data.c int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · line 1855
Quoted 5 lines
fs/f2fs/data.c +1
-0+ ret =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_XATTR );if (ret)return ret;
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
---- 在 星期四, 2021-02-25 09:24:51 Chao Yu <[email protected]> 撰写 ----
Quoted 25 lines · Chengguang Xu
Quoted 24 lines
F2FS inode may have different max size,
so change to use per-inode maxbytes.Signed-off-by Chengguang Xu <[email protected]>--- fs/f2fs/data.c | 5 +++++ 1 file changed, 5 insertions(+)fs/f2fs/data.c +1
-0@@ -1838,6 +1838,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,int ret =0 ;bool compr_cluster = false;unsigned int cluster_size =F2FS_I (inode)->i_cluster_size; +loff_t maxbytes;if (fieinfo->fi_flags &FIEMAP_FLAG_CACHE ) { ret =f2fs_precache_extents (inode);@@ -1845,6 +1846,10 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,return ret; }
Quoted 7 lines
fs/f2fs/data.c int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · line 1851
Quoted 3 lines
fs/f2fs/data.c +3
-0+ maxbytes =max_file_blocks (inode) <<F2FS_BLKSIZE_BITS ; +if (len > maxbytes || (maxbytes - len) < start) + len = maxbytes - start;This should be checked under inode lock, otherwise the max filesize calculation can race with compress inode conversion.
Thanks for your review. There are some other places also calling max_file_blocks() and f2fs_compressed_file(), so I'm wondering if we should add lock inside f2fs_compressed_file() to avoid race with compress inode conversion.
Thanks,
Chengguang
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 34 lines · Chengguang Xu
---- 在 星期四, 2021-02-25 09:24:51 Chao Yu <[email protected]> 撰写 ---- > On 2021/2/23 19:50, Chengguang Xu wrote: > > F2FS inode may have different max size, > > so change to use per-inode maxbytes. > > > > Signed-off-by: Chengguang Xu <[email protected]> > > --- > > fs/f2fs/data.c | 5 +++++ > > 1 file changed, 5 insertions(+) > > > > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > > index b9721c8f116c..b330c6a27b14 100644 > > --- a/fs/f2fs/data.c > > +++ b/fs/f2fs/data.c > > @@ -1838,6 +1838,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, > > int ret = 0; > > bool compr_cluster = false; > > unsigned int cluster_size = F2FS_I(inode)->i_cluster_size; > > + loff_t maxbytes; > > > > if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) { > > ret = f2fs_precache_extents(inode); > > @@ -1845,6 +1846,10 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, > > return ret; > > } > > > > + maxbytes = max_file_blocks(inode) << F2FS_BLKSIZE_BITS; > > + if (len > maxbytes || (maxbytes - len) < start) > > + len = maxbytes - start; > > This should be checked under inode lock, otherwise the max filesize calculation > can race with compress inode conversion. >
Quoted 1 line
Thanks for your review. There are some other places also calling
max_file_blocks()andf2fs_compressed_file(),
You mean sbi->max_file_blocks? I guess it should be replaced with max_inode_blocks().
Quoted 1 line
so I'm wondering if we should add lock inside
f2fs_compressed_file()to avoid race with compress inode conversion.
I think max_inode_blocks()'s caller should keep do the size check under inode lock rather than adding lock into f2fs_compressed_file().
Thanks,
Quoted 5 lines
Thanks,
Chengguang
.
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel