btrfs: Fix lock release order
authorNikolay Borisov <nborisov@suse.com>
Wed, 11 Apr 2018 08:21:18 +0000 (11:21 +0300)
committerDavid Sterba <dsterba@suse.com>
Mon, 28 May 2018 16:07:16 +0000 (18:07 +0200)
Locks should generally be released in the oppposite order they are
acquired. Generally lock acquisiton ordering is used to ensure
deadlocks don't happen. However, as becomes more complicated it's
best to also maintain proper unlock order so as to avoid possible dead
locks. This was found by code inspection and doesn't necessarily lead
to a deadlock scenario.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c

index 2f9432beb69c97a3207cbb34f6daa3483874f250..cd2f5220577fbb466c3926dd12222e899c94c5f4 100644 (file)
@@ -2597,8 +2597,8 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans,
        delayed_refs->num_heads--;
        rb_erase(&head->href_node, &delayed_refs->href_root);
        RB_CLEAR_NODE(&head->href_node);
-       spin_unlock(&delayed_refs->lock);
        spin_unlock(&head->lock);
+       spin_unlock(&delayed_refs->lock);
        atomic_dec(&delayed_refs->num_entries);
 
        trace_run_delayed_ref_head(fs_info, head, 0);