All of lore.kernel.org
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs: fix to use per-inode maxbytes in f2fs_fiemap
@ 2021-02-23 11:50 Chengguang Xu
  2021-02-25  1:24 ` Chao Yu
  0 siblings, 1 reply; 4+ messages in thread
From: Chengguang Xu @ 2021-02-23 11:50 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: Chengguang Xu, linux-f2fs-devel

F2FS inode may have different max size,
so change to use per-inode maxbytes.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 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;
+
 	ret = fiemap_prep(inode, fieinfo, start, &len, FIEMAP_FLAG_XATTR);
 	if (ret)
 		return ret;
-- 
2.27.0




_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: fix to use per-inode maxbytes in f2fs_fiemap
  2021-02-23 11:50 [f2fs-dev] [PATCH] f2fs: fix to use per-inode maxbytes in f2fs_fiemap Chengguang Xu
@ 2021-02-25  1:24 ` Chao Yu
  2021-02-26  2:20   ` Chengguang Xu
  0 siblings, 1 reply; 4+ messages in thread
From: Chao Yu @ 2021-02-25  1:24 UTC (permalink / raw)
  To: Chengguang Xu; +Cc: jaegeuk, linux-f2fs-devel

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 <cgxu519@mykernel.net>
> ---
>   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.

Thanks,

> +
>   	ret = fiemap_prep(inode, fieinfo, start, &len, FIEMAP_FLAG_XATTR);
>   	if (ret)
>   		return ret;
> 


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: fix to use per-inode maxbytes in f2fs_fiemap
  2021-02-25  1:24 ` Chao Yu
@ 2021-02-26  2:20   ` Chengguang Xu
  2021-02-26  8:09     ` Chao Yu
  0 siblings, 1 reply; 4+ messages in thread
From: Chengguang Xu @ 2021-02-26  2:20 UTC (permalink / raw)
  To: Chao Yu; +Cc: jaegeuk, linux-f2fs-devel

 ---- 在 星期四, 2021-02-25 09:24:51 Chao Yu <yuchao0@huawei.com> 撰写 ----
 > 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 <cgxu519@mykernel.net>
 > > ---
 > >   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.
 > 

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
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: fix to use per-inode maxbytes in f2fs_fiemap
  2021-02-26  2:20   ` Chengguang Xu
@ 2021-02-26  8:09     ` Chao Yu
  0 siblings, 0 replies; 4+ messages in thread
From: Chao Yu @ 2021-02-26  8:09 UTC (permalink / raw)
  To: cgxu519; +Cc: jaegeuk, linux-f2fs-devel

On 2021/2/26 10:20, Chengguang Xu wrote:
>   ---- 在 星期四, 2021-02-25 09:24:51 Chao Yu <yuchao0@huawei.com> 撰写 ----
>   > 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 <cgxu519@mykernel.net>
>   > > ---
>   > >   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.
>   >
> 
> Thanks for your review. There are some other places also calling max_file_blocks() and f2fs_compressed_file(),

You mean sbi->max_file_blocks? I guess it should be replaced with max_inode_blocks().

> 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,

> 
> Thanks,
> Chengguang
> .
> 


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-26  8:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-23 11:50 [f2fs-dev] [PATCH] f2fs: fix to use per-inode maxbytes in f2fs_fiemap Chengguang Xu
2021-02-25  1:24 ` Chao Yu
2021-02-26  2:20   ` Chengguang Xu
2021-02-26  8:09     ` Chao Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.