linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: extent-tree: Fix a bug that btrfs is unable to add pinned bytes
@ 2019-05-10  4:45 Qu Wenruo
  2019-05-13  2:37 ` Qu Wenruo
  2019-05-14 17:29 ` David Sterba
  0 siblings, 2 replies; 4+ messages in thread
From: Qu Wenruo @ 2019-05-10  4:45 UTC (permalink / raw)
  To: linux-btrfs; +Cc: kernel test robot

Commit ddf30cf03fb5 ("btrfs: extent-tree: Use btrfs_ref to refactor
add_pinned_bytes()") refactored add_pinned_bytes(), but during that
refactor, there are two callers which add the pinned bytes instead
of subtracting.

That refactor misses those two caller, causing incorrect pinned bytes
calculation and resulting unexpected ENOSPC error.

Fix it by adding a new parameter @sign to restore the original behavior.

Reported-by: kernel test robot <rong.a.chen@intel.com>
Fixes: ddf30cf03fb5 ("btrfs: extent-tree: Use btrfs_ref to refactor add_pinned_bytes()")
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/extent-tree.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index f79e477a378e..8592d31e321c 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -757,12 +757,14 @@ static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info,
 }
 
 static void add_pinned_bytes(struct btrfs_fs_info *fs_info,
-			     struct btrfs_ref *ref)
+			     struct btrfs_ref *ref, int sign)
 {
 	struct btrfs_space_info *space_info;
-	s64 num_bytes = -ref->len;
+	s64 num_bytes;
 	u64 flags;
 
+	ASSERT(sign == 1 || sign == -1);
+	num_bytes = sign * ref->len;
 	if (ref->type == BTRFS_REF_METADATA) {
 		if (ref->tree_ref.root == BTRFS_CHUNK_TREE_OBJECTID)
 			flags = BTRFS_BLOCK_GROUP_SYSTEM;
@@ -2063,7 +2065,7 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
 	btrfs_ref_tree_mod(fs_info, generic_ref);
 
 	if (ret == 0 && old_ref_mod < 0 && new_ref_mod >= 0)
-		add_pinned_bytes(fs_info, generic_ref);
+		add_pinned_bytes(fs_info, generic_ref, -1);
 
 	return ret;
 }
@@ -7190,7 +7192,7 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
 	}
 out:
 	if (pin)
-		add_pinned_bytes(fs_info, &generic_ref);
+		add_pinned_bytes(fs_info, &generic_ref, 1);
 
 	if (last_ref) {
 		/*
@@ -7238,7 +7240,7 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref)
 		btrfs_ref_tree_mod(fs_info, ref);
 
 	if (ret == 0 && old_ref_mod >= 0 && new_ref_mod < 0)
-		add_pinned_bytes(fs_info, ref);
+		add_pinned_bytes(fs_info, ref, 1);
 
 	return ret;
 }
-- 
2.21.0


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

* Re: [PATCH] btrfs: extent-tree: Fix a bug that btrfs is unable to add pinned bytes
  2019-05-10  4:45 [PATCH] btrfs: extent-tree: Fix a bug that btrfs is unable to add pinned bytes Qu Wenruo
@ 2019-05-13  2:37 ` Qu Wenruo
  2019-05-14 17:29 ` David Sterba
  1 sibling, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2019-05-13  2:37 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs; +Cc: kernel test robot


[-- Attachment #1.1: Type: text/plain, Size: 2552 bytes --]



On 2019/5/10 下午12:45, Qu Wenruo wrote:
> Commit ddf30cf03fb5 ("btrfs: extent-tree: Use btrfs_ref to refactor
> add_pinned_bytes()") refactored add_pinned_bytes(), but during that
> refactor, there are two callers which add the pinned bytes instead
> of subtracting.
> 
> That refactor misses those two caller, causing incorrect pinned bytes
> calculation and resulting unexpected ENOSPC error.
> 
> Fix it by adding a new parameter @sign to restore the original behavior.
> 
> Reported-by: kernel test robot <rong.a.chen@intel.com>
> Fixes: ddf30cf03fb5 ("btrfs: extent-tree: Use btrfs_ref to refactor add_pinned_bytes()")

Gentle ping.

This patch is needed to fix generic/108 and should reach current rc.

Thanks,
Qu

> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  fs/btrfs/extent-tree.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index f79e477a378e..8592d31e321c 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -757,12 +757,14 @@ static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info,
>  }
>  
>  static void add_pinned_bytes(struct btrfs_fs_info *fs_info,
> -			     struct btrfs_ref *ref)
> +			     struct btrfs_ref *ref, int sign)
>  {
>  	struct btrfs_space_info *space_info;
> -	s64 num_bytes = -ref->len;
> +	s64 num_bytes;
>  	u64 flags;
>  
> +	ASSERT(sign == 1 || sign == -1);
> +	num_bytes = sign * ref->len;
>  	if (ref->type == BTRFS_REF_METADATA) {
>  		if (ref->tree_ref.root == BTRFS_CHUNK_TREE_OBJECTID)
>  			flags = BTRFS_BLOCK_GROUP_SYSTEM;
> @@ -2063,7 +2065,7 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
>  	btrfs_ref_tree_mod(fs_info, generic_ref);
>  
>  	if (ret == 0 && old_ref_mod < 0 && new_ref_mod >= 0)
> -		add_pinned_bytes(fs_info, generic_ref);
> +		add_pinned_bytes(fs_info, generic_ref, -1);
>  
>  	return ret;
>  }
> @@ -7190,7 +7192,7 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
>  	}
>  out:
>  	if (pin)
> -		add_pinned_bytes(fs_info, &generic_ref);
> +		add_pinned_bytes(fs_info, &generic_ref, 1);
>  
>  	if (last_ref) {
>  		/*
> @@ -7238,7 +7240,7 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref)
>  		btrfs_ref_tree_mod(fs_info, ref);
>  
>  	if (ret == 0 && old_ref_mod >= 0 && new_ref_mod < 0)
> -		add_pinned_bytes(fs_info, ref);
> +		add_pinned_bytes(fs_info, ref, 1);
>  
>  	return ret;
>  }
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] btrfs: extent-tree: Fix a bug that btrfs is unable to add pinned bytes
  2019-05-10  4:45 [PATCH] btrfs: extent-tree: Fix a bug that btrfs is unable to add pinned bytes Qu Wenruo
  2019-05-13  2:37 ` Qu Wenruo
@ 2019-05-14 17:29 ` David Sterba
  2019-05-14 23:08   ` Qu Wenruo
  1 sibling, 1 reply; 4+ messages in thread
From: David Sterba @ 2019-05-14 17:29 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, kernel test robot

On Fri, May 10, 2019 at 12:45:05PM +0800, Qu Wenruo wrote:
> Commit ddf30cf03fb5 ("btrfs: extent-tree: Use btrfs_ref to refactor
> add_pinned_bytes()") refactored add_pinned_bytes(), but during that
> refactor, there are two callers which add the pinned bytes instead
> of subtracting.
> 
> That refactor misses those two caller, causing incorrect pinned bytes
> calculation and resulting unexpected ENOSPC error.
> 
> Fix it by adding a new parameter @sign to restore the original behavior.
> 
> Reported-by: kernel test robot <rong.a.chen@intel.com>
> Fixes: ddf30cf03fb5 ("btrfs: extent-tree: Use btrfs_ref to refactor add_pinned_bytes()")
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  fs/btrfs/extent-tree.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index f79e477a378e..8592d31e321c 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -757,12 +757,14 @@ static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info,
>  }
>  
>  static void add_pinned_bytes(struct btrfs_fs_info *fs_info,
> -			     struct btrfs_ref *ref)
> +			     struct btrfs_ref *ref, int sign)

This does not look like a good API, can it be done with a separate
function like sub_pinned_bytes?

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

* Re: [PATCH] btrfs: extent-tree: Fix a bug that btrfs is unable to add pinned bytes
  2019-05-14 17:29 ` David Sterba
@ 2019-05-14 23:08   ` Qu Wenruo
  0 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2019-05-14 23:08 UTC (permalink / raw)
  To: dsterba, Qu Wenruo, linux-btrfs, kernel test robot


[-- Attachment #1.1: Type: text/plain, Size: 1499 bytes --]



On 2019/5/15 上午1:29, David Sterba wrote:
> On Fri, May 10, 2019 at 12:45:05PM +0800, Qu Wenruo wrote:
>> Commit ddf30cf03fb5 ("btrfs: extent-tree: Use btrfs_ref to refactor
>> add_pinned_bytes()") refactored add_pinned_bytes(), but during that
>> refactor, there are two callers which add the pinned bytes instead
>> of subtracting.
>>
>> That refactor misses those two caller, causing incorrect pinned bytes
>> calculation and resulting unexpected ENOSPC error.
>>
>> Fix it by adding a new parameter @sign to restore the original behavior.
>>
>> Reported-by: kernel test robot <rong.a.chen@intel.com>
>> Fixes: ddf30cf03fb5 ("btrfs: extent-tree: Use btrfs_ref to refactor add_pinned_bytes()")
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>>  fs/btrfs/extent-tree.c | 12 +++++++-----
>>  1 file changed, 7 insertions(+), 5 deletions(-)
>>
>> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
>> index f79e477a378e..8592d31e321c 100644
>> --- a/fs/btrfs/extent-tree.c
>> +++ b/fs/btrfs/extent-tree.c
>> @@ -757,12 +757,14 @@ static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info,
>>  }
>>  
>>  static void add_pinned_bytes(struct btrfs_fs_info *fs_info,
>> -			     struct btrfs_ref *ref)
>> +			     struct btrfs_ref *ref, int sign)
> 
> This does not look like a good API, can it be done with a separate
> function like sub_pinned_bytes?
> 

No problem, indeed sub_pinned_bytes looks much better.

Thanks,
Qu


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2019-05-14 23:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-10  4:45 [PATCH] btrfs: extent-tree: Fix a bug that btrfs is unable to add pinned bytes Qu Wenruo
2019-05-13  2:37 ` Qu Wenruo
2019-05-14 17:29 ` David Sterba
2019-05-14 23:08   ` Qu Wenruo

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).