diff mbox

[01/22] btrfs: add btrfs_delete_ref_head helper

Message ID 20180719145006.17532-1-josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show

Commit Message

Josef Bacik July 19, 2018, 2:49 p.m. UTC
From: Josef Bacik <jbacik@fb.com>

We do this dance in cleanup_ref_head and check_ref_cleanup, unify it
into a helper and cleanup the calling functions.

Signed-off-by: Josef Bacik <jbacik@fb.com>
---
 fs/btrfs/delayed-ref.c | 14 ++++++++++++++
 fs/btrfs/delayed-ref.h |  3 ++-
 fs/btrfs/extent-tree.c | 24 ++++--------------------
 3 files changed, 20 insertions(+), 21 deletions(-)

Comments

David Sterba July 19, 2018, 4:08 p.m. UTC | #1
Please send cover letter for patchsets with more than 1 patch.
Especially for a patchset with 20+ patches that does not seem to be
doing anything trivial.

What problem does this fix, what's the overall idea behind the approach,
what workload can trigger that etc.

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Josef Bacik July 19, 2018, 4:12 p.m. UTC | #2
On Thu, Jul 19, 2018 at 06:08:21PM +0200, David Sterba wrote:
> Please send cover letter for patchsets with more than 1 patch.
> Especially for a patchset with 20+ patches that does not seem to be
> doing anything trivial.
> 
> What problem does this fix, what's the overall idea behind the approach,
> what workload can trigger that etc.

They are just fixes, there's no large over-arching theme, hence no cover letter,

Josef
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba July 19, 2018, 4:36 p.m. UTC | #3
On Thu, Jul 19, 2018 at 12:12:52PM -0400, Josef Bacik wrote:
> On Thu, Jul 19, 2018 at 06:08:21PM +0200, David Sterba wrote:
> > Please send cover letter for patchsets with more than 1 patch.
> > Especially for a patchset with 20+ patches that does not seem to be
> > doing anything trivial.
> > 
> > What problem does this fix, what's the overall idea behind the approach,
> > what workload can trigger that etc.
> 
> They are just fixes, there's no large over-arching theme, hence no cover letter,

Cover letter is a single point where I can address the whole patchset,
like that it's added to for-next or merged, or report bugs. Also you are
going to write what are the changes between the revisions.

The initial text does not need to be long if there's really nothing big
behind, but please state that in advance. This sets the expectations
before one is going through the patches.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Nikolay Borisov July 20, 2018, 1:11 p.m. UTC | #4
On 19.07.2018 17:49, Josef Bacik wrote:
> From: Josef Bacik <jbacik@fb.com>
> 
> We do this dance in cleanup_ref_head and check_ref_cleanup, unify it
> into a helper and cleanup the calling functions.
> 
> Signed-off-by: Josef Bacik <jbacik@fb.com>
> ---
>  fs/btrfs/delayed-ref.c | 14 ++++++++++++++
>  fs/btrfs/delayed-ref.h |  3 ++-
>  fs/btrfs/extent-tree.c | 24 ++++--------------------
>  3 files changed, 20 insertions(+), 21 deletions(-)
> 
> diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
> index 03dec673d12a..e1b322d651dd 100644
> --- a/fs/btrfs/delayed-ref.c
> +++ b/fs/btrfs/delayed-ref.c
> @@ -393,6 +393,20 @@ btrfs_select_ref_head(struct btrfs_trans_handle *trans)
>  	return head;
>  }
>  
> +void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs,
> +			   struct btrfs_delayed_ref_head *head)
> +{
> +	lockdep_assert_held(&delayed_refs->lock);
> +	lockdep_assert_held(&head->lock);
> +
> +	rb_erase(&head->href_node, &delayed_refs->href_root);
> +	RB_CLEAR_NODE(&head->href_node);
> +	atomic_dec(&delayed_refs->num_entries);
> +	delayed_refs->num_heads--;
> +	if (head->processing == 0)
> +		delayed_refs->num_heads_ready--;
> +}
> +
>  /*
>   * Helper to insert the ref_node to the tail or merge with tail.
>   *
> diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
> index ea1aecb6a50d..36318182e4ec 100644
> --- a/fs/btrfs/delayed-ref.h
> +++ b/fs/btrfs/delayed-ref.h
> @@ -263,7 +263,8 @@ static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head)
>  {
>  	mutex_unlock(&head->mutex);
>  }
> -
> +void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs,
> +			   struct btrfs_delayed_ref_head *head);
>  
>  struct btrfs_delayed_ref_head *
>  btrfs_select_ref_head(struct btrfs_trans_handle *trans);
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 3d9fe58c0080..ccaccd78534e 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -2577,12 +2577,9 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans,
>  		spin_unlock(&delayed_refs->lock);
>  		return 1;
>  	}
> -	delayed_refs->num_heads--;
> -	rb_erase(&head->href_node, &delayed_refs->href_root);
> -	RB_CLEAR_NODE(&head->href_node);
> -	spin_unlock(&head->lock);
> +	btrfs_delete_ref_head(delayed_refs, head);
>  	spin_unlock(&delayed_refs->lock);
> -	atomic_dec(&delayed_refs->num_entries);
> +	spin_unlock(&head->lock);
>  
>  	trace_run_delayed_ref_head(fs_info, head, 0);
>  
> @@ -7122,22 +7119,9 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans,
>  	if (!mutex_trylock(&head->mutex))
>  		goto out;
>  
> -	/*
> -	 * at this point we have a head with no other entries.  Go
> -	 * ahead and process it.
> -	 */
> -	rb_erase(&head->href_node, &delayed_refs->href_root);
> -	RB_CLEAR_NODE(&head->href_node);
> -	atomic_dec(&delayed_refs->num_entries);
> -
> -	/*
> -	 * we don't take a ref on the node because we're removing it from the
> -	 * tree, so we just steal the ref the tree was holding.
> -	 */
> -	delayed_refs->num_heads--;
> -	if (head->processing == 0)
> -		delayed_refs->num_heads_ready--;

In cleanup_ref_head we don't have the num_heads_ready-- code so this is
not pure consolidation but changes the behavior to a certain extent. It
seems this patch is also fixing a bug w.r.t num_heads_ready counts if
so, this needs to be documented in the changelog.

> +	btrfs_delete_ref_head(delayed_refs, head);
>  	head->processing = 0;
> +
>  	spin_unlock(&head->lock);
>  	spin_unlock(&delayed_refs->lock);
>  
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Josef Bacik July 20, 2018, 2:18 p.m. UTC | #5
On Fri, Jul 20, 2018 at 04:11:29PM +0300, Nikolay Borisov wrote:
> 
> 
> On 19.07.2018 17:49, Josef Bacik wrote:
> > From: Josef Bacik <jbacik@fb.com>
> > 
> > We do this dance in cleanup_ref_head and check_ref_cleanup, unify it
> > into a helper and cleanup the calling functions.
> > 
> > Signed-off-by: Josef Bacik <jbacik@fb.com>
> > ---
> >  fs/btrfs/delayed-ref.c | 14 ++++++++++++++
> >  fs/btrfs/delayed-ref.h |  3 ++-
> >  fs/btrfs/extent-tree.c | 24 ++++--------------------
> >  3 files changed, 20 insertions(+), 21 deletions(-)
> > 
> > diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
> > index 03dec673d12a..e1b322d651dd 100644
> > --- a/fs/btrfs/delayed-ref.c
> > +++ b/fs/btrfs/delayed-ref.c
> > @@ -393,6 +393,20 @@ btrfs_select_ref_head(struct btrfs_trans_handle *trans)
> >  	return head;
> >  }
> >  
> > +void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs,
> > +			   struct btrfs_delayed_ref_head *head)
> > +{
> > +	lockdep_assert_held(&delayed_refs->lock);
> > +	lockdep_assert_held(&head->lock);
> > +
> > +	rb_erase(&head->href_node, &delayed_refs->href_root);
> > +	RB_CLEAR_NODE(&head->href_node);
> > +	atomic_dec(&delayed_refs->num_entries);
> > +	delayed_refs->num_heads--;
> > +	if (head->processing == 0)
> > +		delayed_refs->num_heads_ready--;
> > +}
> > +
> >  /*
> >   * Helper to insert the ref_node to the tail or merge with tail.
> >   *
> > diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
> > index ea1aecb6a50d..36318182e4ec 100644
> > --- a/fs/btrfs/delayed-ref.h
> > +++ b/fs/btrfs/delayed-ref.h
> > @@ -263,7 +263,8 @@ static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head)
> >  {
> >  	mutex_unlock(&head->mutex);
> >  }
> > -
> > +void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs,
> > +			   struct btrfs_delayed_ref_head *head);
> >  
> >  struct btrfs_delayed_ref_head *
> >  btrfs_select_ref_head(struct btrfs_trans_handle *trans);
> > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> > index 3d9fe58c0080..ccaccd78534e 100644
> > --- a/fs/btrfs/extent-tree.c
> > +++ b/fs/btrfs/extent-tree.c
> > @@ -2577,12 +2577,9 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans,
> >  		spin_unlock(&delayed_refs->lock);
> >  		return 1;
> >  	}
> > -	delayed_refs->num_heads--;
> > -	rb_erase(&head->href_node, &delayed_refs->href_root);
> > -	RB_CLEAR_NODE(&head->href_node);
> > -	spin_unlock(&head->lock);
> > +	btrfs_delete_ref_head(delayed_refs, head);
> >  	spin_unlock(&delayed_refs->lock);
> > -	atomic_dec(&delayed_refs->num_entries);
> > +	spin_unlock(&head->lock);
> >  
> >  	trace_run_delayed_ref_head(fs_info, head, 0);
> >  
> > @@ -7122,22 +7119,9 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans,
> >  	if (!mutex_trylock(&head->mutex))
> >  		goto out;
> >  
> > -	/*
> > -	 * at this point we have a head with no other entries.  Go
> > -	 * ahead and process it.
> > -	 */
> > -	rb_erase(&head->href_node, &delayed_refs->href_root);
> > -	RB_CLEAR_NODE(&head->href_node);
> > -	atomic_dec(&delayed_refs->num_entries);
> > -
> > -	/*
> > -	 * we don't take a ref on the node because we're removing it from the
> > -	 * tree, so we just steal the ref the tree was holding.
> > -	 */
> > -	delayed_refs->num_heads--;
> > -	if (head->processing == 0)
> > -		delayed_refs->num_heads_ready--;
> 
> In cleanup_ref_head we don't have the num_heads_ready-- code so this is
> not pure consolidation but changes the behavior to a certain extent. It
> seems this patch is also fixing a bug w.r.t num_heads_ready counts if
> so, this needs to be documented in the changelog.
> 

No it's not, because cleanup_ref_head is called when running delayed refs, so
head->processing == 1, which means there's no change.  Thanks,

Josef
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba July 20, 2018, 2:48 p.m. UTC | #6
On Thu, Jul 19, 2018 at 10:49:45AM -0400, Josef Bacik wrote:
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -2577,12 +2577,9 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans,
>  		spin_unlock(&delayed_refs->lock);
>  		return 1;
>  	}
> -	delayed_refs->num_heads--;
> -	rb_erase(&head->href_node, &delayed_refs->href_root);
> -	RB_CLEAR_NODE(&head->href_node);
> -	spin_unlock(&head->lock);
> +	btrfs_delete_ref_head(delayed_refs, head);
>  	spin_unlock(&delayed_refs->lock);
> -	atomic_dec(&delayed_refs->num_entries);
> +	spin_unlock(&head->lock);

The order of unlocks is reversed, the head is nested to the delayed
refs.

> @@ -7122,22 +7119,9 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans,
>  	if (!mutex_trylock(&head->mutex))
>  		goto out;
>  
> -	/*
> -	 * at this point we have a head with no other entries.  Go
> -	 * ahead and process it.
> -	 */
> -	rb_erase(&head->href_node, &delayed_refs->href_root);
> -	RB_CLEAR_NODE(&head->href_node);
> -	atomic_dec(&delayed_refs->num_entries);
> -
> -	/*
> -	 * we don't take a ref on the node because we're removing it from the
> -	 * tree, so we just steal the ref the tree was holding.
> -	 */
> -	delayed_refs->num_heads--;
> -	if (head->processing == 0)
> -		delayed_refs->num_heads_ready--;
> +	btrfs_delete_ref_head(delayed_refs, head);
>  	head->processing = 0;
> +
>  	spin_unlock(&head->lock);
>  	spin_unlock(&delayed_refs->lock);

The right order eg. here and everywhere else.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba July 20, 2018, 4:04 p.m. UTC | #7
fstests run in the sequence from btrfs/001, in qemu, 2G memory, warning
and crash at btrfs/124

btrfs/124		[22:58:39]
[10100.765898] run fstests btrfs/124 at 2018-07-19 22:58:39
...
[10110.113787] BTRFS: device fsid 8b6b700e-3346-4260-bb2e-c561ba4b9960 devid 1 transid 7 /dev/vdb
[10110.118673] BTRFS info (device vdb): allowing degraded mounts
[10110.120386] BTRFS info (device vdb): disk space caching is enabled
[10110.122070] BTRFS info (device vdb): has skinny extents
[10110.138082] BTRFS warning (device vdb): devid 2 uuid 1e933775-ded8-40fa-9b6a-6127afd4cc01 is missing
[10110.141411] BTRFS warning (device vdb): devid 2 uuid 1e933775-ded8-40fa-9b6a-6127afd4cc01 is missing
[10110.719342] WARNING: CPU: 3 PID: 28973 at fs/btrfs/extent-tree.c:6122 btrfs_trans_release_chunk_metadata+0x3f/0x50 [btrfs]
[10110.723171] Modules linked in: btrfs libcrc32c xor zstd_decompress zstd_compress xxhash raid6_pq dm_mod dax loop [last unloaded: libcrc32c]
[10110.727313] CPU: 3 PID: 28973 Comm: dd Not tainted 4.18.0-rc5-default+ #198
[10110.728504] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014
[10110.730236] RIP: 0010:btrfs_trans_release_chunk_metadata+0x3f/0x50 [btrfs]
[10110.734444] RSP: 0018:ffffb3edc08bfba0 EFLAGS: 00010202
[10110.735361] RAX: ffff9b68e5232dd8 RBX: ffff9b69315f98f0 RCX: 00000000000c0000
[10110.736539] RDX: ffff9b69315f9948 RSI: ffff9b68e52369d8 RDI: ffff9b69315f98f0
[10110.737721] RBP: ffff9b68e5236000 R08: 0000000000000001 R09: 0000000000000000
[10110.738849] R10: ffff9b691e93e4e0 R11: 0000000000000000 R12: ffff9b69359b0000
[10110.739966] R13: 0000000000000000 R14: 0000000000000201 R15: ffff9b6917e08528
[10110.741460] FS:  00007f15f5b14540(0000) GS:ffff9b693cc00000(0000) knlGS:0000000000000000
[10110.742795] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[10110.743679] CR2: 00007f15f5571690 CR3: 000000002d8a0000 CR4: 00000000000006e0
[10110.744692] Call Trace:
[10110.745096]  __btrfs_end_transaction+0x55/0x230 [btrfs]
[10110.745762]  btrfs_create+0xf2/0x1f0 [btrfs]
[10110.746564]  lookup_open+0x562/0x700
[10110.747216]  ? __wake_up_common_lock+0x63/0xc0
[10110.748021]  ? find_held_lock+0x34/0xa0
[10110.748737]  path_openat+0x653/0xf90
[10110.749411]  do_filp_open+0x93/0x100
[10110.750076]  ? _raw_spin_unlock+0x24/0x40
[10110.750793]  ? __alloc_fd+0xee/0x1d0
[10110.751438]  do_sys_open+0x186/0x210
[10110.752152]  do_syscall_64+0x5a/0x170
[10110.752774]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
[10110.753582] RIP: 0033:0x7f15f562090e
[10110.757116] RSP: 002b:00007ffea876ae20 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
[10110.758424] RAX: ffffffffffffffda RBX: 000055d6f74323e0 RCX: 00007f15f562090e
[10110.759523] RDX: 0000000000000241 RSI: 00007ffea876c286 RDI: 00000000ffffff9c
[10110.760501] RBP: 0000000000000001 R08: 00007ffea876c2a7 R09: 0000000000000000
[10110.761323] R10: 00000000000001b6 R11: 0000000000000246 R12: 0000000000000241
[10110.762400] R13: 00007ffea876c286 R14: 0000000000000001 R15: 00007ffea876b118
[10110.763533] irq event stamp: 2212
[10110.764139] hardirqs last  enabled at (2211): [<ffffffff9221b007>] slab_free_freelist_hook+0x97/0xe0
[10110.765566] hardirqs last disabled at (2212): [<ffffffff92800f9c>] error_entry+0x6c/0xc0
[10110.766932] softirqs last  enabled at (2006): [<ffffffff921c485e>] __set_page_dirty_nobuffers+0xfe/0x140
[10110.768464] softirqs last disabled at (2002): [<ffffffff921ddebe>] wb_wakeup_delayed+0x2e/0x70
[10110.769891] ---[ end trace 6fb571b51e7cab5c ]---
[10131.610680] assertion failed: list_empty(&block_group->bg_list), file: fs/btrfs/extent-tree.c, line: 10070
[10131.614113] ------------[ cut here ]------------
[10131.615675] kernel BUG at fs/btrfs/ctree.h:3472!
[10131.617376] invalid opcode: 0000 [#1] PREEMPT SMP
[10131.618968] CPU: 1 PID: 28975 Comm: umount Tainted: G        W         4.18.0-rc5-default+ #198
[10131.621170] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014
[10131.622672] RIP: 0010:assfail.constprop.84+0x18/0x1a [btrfs]
[10131.626514] RSP: 0018:ffffb3edc6bfbde0 EFLAGS: 00010246
[10131.627380] RAX: 000000000000005e RBX: ffff9b68e5232c00 RCX: 0000000000000006
[10131.628521] RDX: 0000000000000000 RSI: ffff9b68f9bcd9c8 RDI: 0000000000000246
[10131.629596] RBP: ffff9b69359b0000 R08: 00001016d930fc78 R09: 0000000000000000
[10131.630678] R10: 0000000000000000 R11: 0000000000000000 R12: ffff9b69359b0118
[10131.631754] R13: ffff9b69359b0168 R14: ffff9b68e5232d98 R15: dead000000000100
[10131.632823] FS:  00007fbc00b0dfc0(0000) GS:ffff9b693c800000(0000) knlGS:0000000000000000
[10131.634119] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[10131.635030] CR2: 00007fbc006e167e CR3: 0000000053e5c000 CR4: 00000000000006e0
[10131.636136] Call Trace:
[10131.636641]  btrfs_free_block_groups.cold.112+0x22/0x55 [btrfs]
[10131.637583]  close_ctree+0x159/0x330 [btrfs]
[10131.638292]  generic_shutdown_super+0x64/0x100
[10131.639031]  kill_anon_super+0xe/0x20
[10131.639663]  btrfs_kill_super+0x12/0xa0 [btrfs]
[10131.640408]  deactivate_locked_super+0x29/0x60
[10131.641159]  cleanup_mnt+0x3b/0x70
[10131.641764]  task_work_run+0x9b/0xd0
[10131.642406]  exit_to_usermode_loop+0xbd/0xc0
[10131.643124]  do_syscall_64+0x16c/0x170
[10131.643775]  entry_SYSCALL_64_after_hwframe+0x49/0xbe
[10131.644590] RIP: 0033:0x7fbc003d4d07
[10131.648070] RSP: 002b:00007fff6a865598 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6
[10131.649331] RAX: 0000000000000000 RBX: 0000557a82414970 RCX: 00007fbc003d4d07
[10131.650417] RDX: 0000000000000001 RSI: 0000000000000000 RDI: 0000557a82414b50
[10131.651486] RBP: 0000000000000000 R08: 0000557a82414b70 R09: 00007fff6a863e00
[10131.652439] R10: 0000000000000000 R11: 0000000000000246 R12: 00007fbc008f11c4
[10131.653253] R13: 0000557a82414b50 R14: 0000000000000000 R15: 00007fff6a865808
[10131.654063] Modules linked in: btrfs libcrc32c xor zstd_decompress zstd_compress xxhash raid6_pq dm_mod dax loop [last unloaded: libcrc32c]
[10131.655964] ---[ end trace 6fb571b51e7cab5d ]---
[10131.656787] RIP: 0010:assfail.constprop.84+0x18/0x1a [btrfs]
[10131.660454] RSP: 0018:ffffb3edc6bfbde0 EFLAGS: 00010246
[10131.661302] RAX: 000000000000005e RBX: ffff9b68e5232c00 RCX: 0000000000000006
[10131.662353] RDX: 0000000000000000 RSI: ffff9b68f9bcd9c8 RDI: 0000000000000246
[10131.663413] RBP: ffff9b69359b0000 R08: 00001016d930fc78 R09: 0000000000000000
[10131.664508] R10: 0000000000000000 R11: 0000000000000000 R12: ffff9b69359b0118
[10131.665627] R13: ffff9b69359b0168 R14: ffff9b68e5232d98 R15: dead000000000100
[10131.666723] FS:  00007fbc00b0dfc0(0000) GS:ffff9b693c800000(0000) knlGS:0000000000000000
[10131.668029] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[10131.668943] CR2: 00007fbc006e167e CR3: 0000000053e5c000 CR4: 00000000000006e0
[10132.375092] BTRFS: device fsid fec9b6db-bc92-4981-85fa-f965b2e44059 devid 1 transid 234 /dev/vda
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index 03dec673d12a..e1b322d651dd 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -393,6 +393,20 @@  btrfs_select_ref_head(struct btrfs_trans_handle *trans)
 	return head;
 }
 
+void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs,
+			   struct btrfs_delayed_ref_head *head)
+{
+	lockdep_assert_held(&delayed_refs->lock);
+	lockdep_assert_held(&head->lock);
+
+	rb_erase(&head->href_node, &delayed_refs->href_root);
+	RB_CLEAR_NODE(&head->href_node);
+	atomic_dec(&delayed_refs->num_entries);
+	delayed_refs->num_heads--;
+	if (head->processing == 0)
+		delayed_refs->num_heads_ready--;
+}
+
 /*
  * Helper to insert the ref_node to the tail or merge with tail.
  *
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
index ea1aecb6a50d..36318182e4ec 100644
--- a/fs/btrfs/delayed-ref.h
+++ b/fs/btrfs/delayed-ref.h
@@ -263,7 +263,8 @@  static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head)
 {
 	mutex_unlock(&head->mutex);
 }
-
+void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs,
+			   struct btrfs_delayed_ref_head *head);
 
 struct btrfs_delayed_ref_head *
 btrfs_select_ref_head(struct btrfs_trans_handle *trans);
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 3d9fe58c0080..ccaccd78534e 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2577,12 +2577,9 @@  static int cleanup_ref_head(struct btrfs_trans_handle *trans,
 		spin_unlock(&delayed_refs->lock);
 		return 1;
 	}
-	delayed_refs->num_heads--;
-	rb_erase(&head->href_node, &delayed_refs->href_root);
-	RB_CLEAR_NODE(&head->href_node);
-	spin_unlock(&head->lock);
+	btrfs_delete_ref_head(delayed_refs, head);
 	spin_unlock(&delayed_refs->lock);
-	atomic_dec(&delayed_refs->num_entries);
+	spin_unlock(&head->lock);
 
 	trace_run_delayed_ref_head(fs_info, head, 0);
 
@@ -7122,22 +7119,9 @@  static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans,
 	if (!mutex_trylock(&head->mutex))
 		goto out;
 
-	/*
-	 * at this point we have a head with no other entries.  Go
-	 * ahead and process it.
-	 */
-	rb_erase(&head->href_node, &delayed_refs->href_root);
-	RB_CLEAR_NODE(&head->href_node);
-	atomic_dec(&delayed_refs->num_entries);
-
-	/*
-	 * we don't take a ref on the node because we're removing it from the
-	 * tree, so we just steal the ref the tree was holding.
-	 */
-	delayed_refs->num_heads--;
-	if (head->processing == 0)
-		delayed_refs->num_heads_ready--;
+	btrfs_delete_ref_head(delayed_refs, head);
 	head->processing = 0;
+
 	spin_unlock(&head->lock);
 	spin_unlock(&delayed_refs->lock);