Re: [PATCH 01/35] btrfs: add btrfs_delete_ref_head helper

Josef Bacik
2018-08-31T18:20:45Z

On Fri, Aug 31, 2018 at 10:57:45AM +0300, Nikolay Borisov wrote:
>
>
> On 30.08.2018 20:41, 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 62ff545ba1f7..3a9e4ac21794 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 d9f2a4ebd5db..7769177b489e 100644
> > --- a/fs/btrfs/delayed-ref.h
> > +++ b/fs/btrfs/delayed-ref.h
> > @@ -261,7 +261,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 f77226d8020a..6799950fa057 100644
> > --- a/fs/btrfs/extent-tree.c
> > +++ b/fs/btrfs/extent-tree.c
> > @@ -2492,12 +2492,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);
> >
>
> Again, the feedback of reversed lock-order is not addressed:
>
> https://www.spinics.net/lists/linux-btrfs/msg80482.html
>

Oops, I'll fix this.

Josef