linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: make sure f2fs_gc returns consistent errno
@ 2017-05-09 11:37 Weichao Guo
  2017-05-09 15:25 ` Chao Yu
  0 siblings, 1 reply; 3+ messages in thread
From: Weichao Guo @ 2017-05-09 11:37 UTC (permalink / raw)
  To: jaegeuk; +Cc: Weichao Guo, linux-f2fs-devel

By default, f2fs_gc returns -EINVAL in general error cases, e.g., no victim
was selected. However, the default errno may be overwritten in two cases:
gc_more and BG_GC -> FG_GC. We should return consistent errno in such cases.

Signed-off-by: Weichao Guo <guoweichao@huawei.com>
---
 fs/f2fs/gc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 0265221..32c9463 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -965,6 +965,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
 
 	cpc.reason = __get_cp_reason(sbi);
 gc_more:
+	ret = -EINVAL;
 	if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE)))
 		goto stop;
 	if (unlikely(f2fs_cp_error(sbi))) {
@@ -982,6 +983,8 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
 			ret = write_checkpoint(sbi, &cpc);
 			if (ret)
 				goto stop;
+			else
+				ret = -EINVAL;
 		}
 		if (has_not_enough_free_secs(sbi, 0, 0))
 			gc_type = FG_GC;
-- 
2.10.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH] f2fs: make sure f2fs_gc returns consistent errno
  2017-05-09 11:37 [PATCH] f2fs: make sure f2fs_gc returns consistent errno Weichao Guo
@ 2017-05-09 15:25 ` Chao Yu
  2017-05-10 12:14   ` 答复: " guoweichao
  0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2017-05-09 15:25 UTC (permalink / raw)
  To: Weichao Guo, jaegeuk; +Cc: linux-f2fs-devel

On 2017/5/9 19:37, Weichao Guo wrote:
> By default, f2fs_gc returns -EINVAL in general error cases, e.g., no victim
> was selected. However, the default errno may be overwritten in two cases:
> gc_more and BG_GC -> FG_GC. We should return consistent errno in such cases.

How about clean up this patch as below, which always set return value
before jumping to 'stop' tag.

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index ac2f74e40eea..6906a284c98d 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -957,7 +957,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
 {
 	int gc_type = sync ? FG_GC : BG_GC;
 	int sec_freed = 0;
-	int ret = -EINVAL;
+	int ret;
 	struct cp_control cpc;
 	unsigned int init_segno = segno;
 	struct gc_inode_list gc_list = {
@@ -967,8 +967,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,

 	cpc.reason = __get_cp_reason(sbi);
 gc_more:
-	if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE)))
+	if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE))) {
+		ret = -EINVAL;
 		goto stop;
+	}
 	if (unlikely(f2fs_cp_error(sbi))) {
 		ret = -EIO;
 		goto stop;
@@ -989,6 +991,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
 			gc_type = FG_GC;
 	}

+	ret = -EINVAL;
 	/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
 	if (gc_type == BG_GC && !background)
 		goto stop;

Thanks,

> 
> Signed-off-by: Weichao Guo <guoweichao@huawei.com>
> ---
>  fs/f2fs/gc.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> index 0265221..32c9463 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -965,6 +965,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
>  
>  	cpc.reason = __get_cp_reason(sbi);
>  gc_more:
> +	ret = -EINVAL;
>  	if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE)))
>  		goto stop;
>  	if (unlikely(f2fs_cp_error(sbi))) {
> @@ -982,6 +983,8 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
>  			ret = write_checkpoint(sbi, &cpc);
>  			if (ret)
>  				goto stop;
> +			else
> +				ret = -EINVAL;
>  		}
>  		if (has_not_enough_free_secs(sbi, 0, 0))
>  			gc_type = FG_GC;
> 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* 答复:  [PATCH] f2fs: make sure f2fs_gc returns consistent errno
  2017-05-09 15:25 ` Chao Yu
@ 2017-05-10 12:14   ` guoweichao
  0 siblings, 0 replies; 3+ messages in thread
From: guoweichao @ 2017-05-10 12:14 UTC (permalink / raw)
  To: Chao Yu, jaegeuk@kernel.org; +Cc: linux-f2fs-devel@lists.sourceforge.net

Agree, I will send a new verison of this patch.

-----邮件原件-----
发件人: Chao Yu [mailto:chao@kernel.org] 
发送时间: 2017年5月9日 23:26
收件人: guoweichao; jaegeuk@kernel.org
抄送: linux-f2fs-devel@lists.sourceforge.net
主题: Re: [f2fs-dev] [PATCH] f2fs: make sure f2fs_gc returns consistent errno

On 2017/5/9 19:37, Weichao Guo wrote:
> By default, f2fs_gc returns -EINVAL in general error cases, e.g., no 
> victim was selected. However, the default errno may be overwritten in two cases:
> gc_more and BG_GC -> FG_GC. We should return consistent errno in such cases.

How about clean up this patch as below, which always set return value before jumping to 'stop' tag.

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index ac2f74e40eea..6906a284c98d 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -957,7 +957,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,  {
 	int gc_type = sync ? FG_GC : BG_GC;
 	int sec_freed = 0;
-	int ret = -EINVAL;
+	int ret;
 	struct cp_control cpc;
 	unsigned int init_segno = segno;
 	struct gc_inode_list gc_list = {
@@ -967,8 +967,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,

 	cpc.reason = __get_cp_reason(sbi);
 gc_more:
-	if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE)))
+	if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE))) {
+		ret = -EINVAL;
 		goto stop;
+	}
 	if (unlikely(f2fs_cp_error(sbi))) {
 		ret = -EIO;
 		goto stop;
@@ -989,6 +991,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
 			gc_type = FG_GC;
 	}

+	ret = -EINVAL;
 	/* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
 	if (gc_type == BG_GC && !background)
 		goto stop;

Thanks,

> 
> Signed-off-by: Weichao Guo <guoweichao@huawei.com>
> ---
>  fs/f2fs/gc.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 0265221..32c9463 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -965,6 +965,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
>  
>  	cpc.reason = __get_cp_reason(sbi);
>  gc_more:
> +	ret = -EINVAL;
>  	if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE)))
>  		goto stop;
>  	if (unlikely(f2fs_cp_error(sbi))) {
> @@ -982,6 +983,8 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
>  			ret = write_checkpoint(sbi, &cpc);
>  			if (ret)
>  				goto stop;
> +			else
> +				ret = -EINVAL;
>  		}
>  		if (has_not_enough_free_secs(sbi, 0, 0))
>  			gc_type = FG_GC;
> 
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
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] 3+ messages in thread

end of thread, other threads:[~2017-05-10 12:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-09 11:37 [PATCH] f2fs: make sure f2fs_gc returns consistent errno Weichao Guo
2017-05-09 15:25 ` Chao Yu
2017-05-10 12:14   ` 答复: " guoweichao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).