All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: check: change commit condition in fixup_extent_refs()
@ 2021-11-03 15:15 Sidong Yang
  2021-11-03 15:25 ` Nikolay Borisov
  0 siblings, 1 reply; 5+ messages in thread
From: Sidong Yang @ 2021-11-03 15:15 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Sidong Yang

This patch fixes potential bugs in fixup_extent_refs(). If
btrfs_start_transaction() fails in some way and returns error ptr, It
goes to out logic. But old code checkes whether it is null and it calls
commit. This patch solves the problem with change the condition to
checks if it is error by IS_ERR().

Issue: #409

Signed-off-by: Sidong Yang <realwakka@gmail.com>
---
 check/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/check/main.c b/check/main.c
index 235a9bab..ca858e07 100644
--- a/check/main.c
+++ b/check/main.c
@@ -7735,7 +7735,7 @@ static int fixup_extent_refs(struct cache_tree *extent_cache,
 			goto out;
 	}
 out:
-	if (trans) {
+	if (!IS_ERR(trans)) {
 		int err = btrfs_commit_transaction(trans, gfs_info->extent_root);
 
 		if (!ret)
-- 
2.25.1


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

* Re: [PATCH] btrfs-progs: check: change commit condition in fixup_extent_refs()
  2021-11-03 15:15 [PATCH] btrfs-progs: check: change commit condition in fixup_extent_refs() Sidong Yang
@ 2021-11-03 15:25 ` Nikolay Borisov
  2021-11-03 23:52   ` Sidong Yang
  0 siblings, 1 reply; 5+ messages in thread
From: Nikolay Borisov @ 2021-11-03 15:25 UTC (permalink / raw)
  To: Sidong Yang, linux-btrfs



On 3.11.21 г. 17:15, Sidong Yang wrote:
> This patch fixes potential bugs in fixup_extent_refs(). If
> btrfs_start_transaction() fails in some way and returns error ptr, It
> goes to out logic. But old code checkes whether it is null and it calls
> commit. This patch solves the problem with change the condition to
> checks if it is error by IS_ERR().
> 
> Issue: #409
> 
> Signed-off-by: Sidong Yang <realwakka@gmail.com>
> ---
>  check/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/check/main.c b/check/main.c
> index 235a9bab..ca858e07 100644
> --- a/check/main.c
> +++ b/check/main.c
> @@ -7735,7 +7735,7 @@ static int fixup_extent_refs(struct cache_tree *extent_cache,
>  			goto out;
>  	}
>  out:
> -	if (trans) {
> +	if (!IS_ERR(trans)) {

Actually I think we want to commit the transaction only if ret is not
error, otherwise we run the risk of committing partial changes to the fs.

>  		int err = btrfs_commit_transaction(trans, gfs_info->extent_root);
>  
>  		if (!ret)
> 

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

* Re: [PATCH] btrfs-progs: check: change commit condition in fixup_extent_refs()
  2021-11-03 15:25 ` Nikolay Borisov
@ 2021-11-03 23:52   ` Sidong Yang
  2021-11-04  7:50     ` Nikolay Borisov
  0 siblings, 1 reply; 5+ messages in thread
From: Sidong Yang @ 2021-11-03 23:52 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-btrfs

On Wed, Nov 03, 2021 at 05:25:38PM +0200, Nikolay Borisov wrote:
> 
> 
> On 3.11.21 г. 17:15, Sidong Yang wrote:
> > This patch fixes potential bugs in fixup_extent_refs(). If
> > btrfs_start_transaction() fails in some way and returns error ptr, It
> > goes to out logic. But old code checkes whether it is null and it calls
> > commit. This patch solves the problem with change the condition to
> > checks if it is error by IS_ERR().
> > 
> > Issue: #409
> > 
> > Signed-off-by: Sidong Yang <realwakka@gmail.com>
> > ---
> >  check/main.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/check/main.c b/check/main.c
> > index 235a9bab..ca858e07 100644
> > --- a/check/main.c
> > +++ b/check/main.c
> > @@ -7735,7 +7735,7 @@ static int fixup_extent_refs(struct cache_tree *extent_cache,
> >  			goto out;
> >  	}
> >  out:
> > -	if (trans) {
> > +	if (!IS_ERR(trans)) {
> 
> Actually I think we want to commit the transaction only if ret is not
> error, otherwise we run the risk of committing partial changes to the fs.

I agree. If ret is error, committing should not be happen. But I 
think it needs to check trans. 

I wonder that if ret is error but trans is okay, trans needs to be
aborted by calling btrfs_abort_transaction()?
> 
> >  		int err = btrfs_commit_transaction(trans, gfs_info->extent_root);
> >  
> >  		if (!ret)
> > 

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

* Re: [PATCH] btrfs-progs: check: change commit condition in fixup_extent_refs()
  2021-11-03 23:52   ` Sidong Yang
@ 2021-11-04  7:50     ` Nikolay Borisov
  2021-11-04 13:59       ` Sidong Yang
  0 siblings, 1 reply; 5+ messages in thread
From: Nikolay Borisov @ 2021-11-04  7:50 UTC (permalink / raw)
  To: Sidong Yang; +Cc: linux-btrfs



On 4.11.21 г. 1:52, Sidong Yang wrote:
> On Wed, Nov 03, 2021 at 05:25:38PM +0200, Nikolay Borisov wrote:
>>
>>
>> On 3.11.21 г. 17:15, Sidong Yang wrote:
>>> This patch fixes potential bugs in fixup_extent_refs(). If
>>> btrfs_start_transaction() fails in some way and returns error ptr, It
>>> goes to out logic. But old code checkes whether it is null and it calls
>>> commit. This patch solves the problem with change the condition to
>>> checks if it is error by IS_ERR().
>>>
>>> Issue: #409
>>>
>>> Signed-off-by: Sidong Yang <realwakka@gmail.com>
>>> ---
>>>  check/main.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/check/main.c b/check/main.c
>>> index 235a9bab..ca858e07 100644
>>> --- a/check/main.c
>>> +++ b/check/main.c
>>> @@ -7735,7 +7735,7 @@ static int fixup_extent_refs(struct cache_tree *extent_cache,
>>>  			goto out;
>>>  	}
>>>  out:
>>> -	if (trans) {
>>> +	if (!IS_ERR(trans)) {
>>
>> Actually I think we want to commit the transaction only if ret is not
>> error, otherwise we run the risk of committing partial changes to the fs.
> 
> I agree. If ret is error, committing should not be happen. But I 
> think it needs to check trans. 
> 
> I wonder that if ret is error but trans is okay, trans needs to be
> aborted by calling btrfs_abort_transaction()?

This is the general way errors are handled in kernel. Currently abort
trans in progs simply sets transaction_aborted = error and
commit_transaction checks if this is set and returns an EROFS. Every
failure site in this function should ideally have a
btrfs_abort_transaction, because in the future we probably want to add
code which would yield the exact call site where a transaction abort
occurred.



>>
>>>  		int err = btrfs_commit_transaction(trans, gfs_info->extent_root);
>>>  
>>>  		if (!ret)
>>>
> 

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

* Re: [PATCH] btrfs-progs: check: change commit condition in fixup_extent_refs()
  2021-11-04  7:50     ` Nikolay Borisov
@ 2021-11-04 13:59       ` Sidong Yang
  0 siblings, 0 replies; 5+ messages in thread
From: Sidong Yang @ 2021-11-04 13:59 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-btrfs

On Thu, Nov 04, 2021 at 09:50:33AM +0200, Nikolay Borisov wrote:
> 
> 
> On 4.11.21 г. 1:52, Sidong Yang wrote:
> > On Wed, Nov 03, 2021 at 05:25:38PM +0200, Nikolay Borisov wrote:
> >>
> >>
> >> On 3.11.21 г. 17:15, Sidong Yang wrote:
> >>> This patch fixes potential bugs in fixup_extent_refs(). If
> >>> btrfs_start_transaction() fails in some way and returns error ptr, It
> >>> goes to out logic. But old code checkes whether it is null and it calls
> >>> commit. This patch solves the problem with change the condition to
> >>> checks if it is error by IS_ERR().
> >>>
> >>> Issue: #409
> >>>
> >>> Signed-off-by: Sidong Yang <realwakka@gmail.com>
> >>> ---
> >>>  check/main.c | 2 +-
> >>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/check/main.c b/check/main.c
> >>> index 235a9bab..ca858e07 100644
> >>> --- a/check/main.c
> >>> +++ b/check/main.c
> >>> @@ -7735,7 +7735,7 @@ static int fixup_extent_refs(struct cache_tree *extent_cache,
> >>>  			goto out;
> >>>  	}
> >>>  out:
> >>> -	if (trans) {
> >>> +	if (!IS_ERR(trans)) {
> >>
> >> Actually I think we want to commit the transaction only if ret is not
> >> error, otherwise we run the risk of committing partial changes to the fs.
> > 
> > I agree. If ret is error, committing should not be happen. But I 
> > think it needs to check trans. 
> > 
> > I wonder that if ret is error but trans is okay, trans needs to be
> > aborted by calling btrfs_abort_transaction()?
> 
> This is the general way errors are handled in kernel. Currently abort
> trans in progs simply sets transaction_aborted = error and
> commit_transaction checks if this is set and returns an EROFS. Every
> failure site in this function should ideally have a
> btrfs_abort_transaction, because in the future we probably want to add
> code which would yield the exact call site where a transaction abort
> occurred.

Okay, Thanks for detailed description. I understood that we don't need
to call btrfs_abort_transaction() in the function.
I would write new version for this patch.

Thanks again for helping me.

Thanks,
Sidong

> 
> 
> 
> >>
> >>>  		int err = btrfs_commit_transaction(trans, gfs_info->extent_root);
> >>>  
> >>>  		if (!ret)
> >>>
> > 

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

end of thread, other threads:[~2021-11-04 13:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-03 15:15 [PATCH] btrfs-progs: check: change commit condition in fixup_extent_refs() Sidong Yang
2021-11-03 15:25 ` Nikolay Borisov
2021-11-03 23:52   ` Sidong Yang
2021-11-04  7:50     ` Nikolay Borisov
2021-11-04 13:59       ` Sidong Yang

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.