Merge tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
[firefly-linux-kernel-4.4.55.git] / fs / btrfs / free-space-cache.c
index 030847bf7cec803e36485e0999b7309d941877ef..d6c03f7f136b359c534668a38f9e9a72d299eb66 100644 (file)
@@ -2966,8 +2966,8 @@ static int do_trimming(struct btrfs_block_group_cache *block_group,
        spin_unlock(&block_group->lock);
        spin_unlock(&space_info->lock);
 
-       ret = btrfs_error_discard_extent(fs_info->extent_root,
-                                        start, bytes, &trimmed);
+       ret = btrfs_discard_extent(fs_info->extent_root,
+                                  start, bytes, &trimmed);
        if (!ret)
                *total_trimmed += trimmed;
 
@@ -3185,16 +3185,18 @@ out:
 
                spin_unlock(&block_group->lock);
 
+               lock_chunks(block_group->fs_info->chunk_root);
                em_tree = &block_group->fs_info->mapping_tree.map_tree;
                write_lock(&em_tree->lock);
                em = lookup_extent_mapping(em_tree, block_group->key.objectid,
                                           1);
                BUG_ON(!em); /* logic error, can't happen */
+               /*
+                * remove_extent_mapping() will delete us from the pinned_chunks
+                * list, which is protected by the chunk mutex.
+                */
                remove_extent_mapping(em_tree, em);
                write_unlock(&em_tree->lock);
-
-               lock_chunks(block_group->fs_info->chunk_root);
-               list_del_init(&em->list);
                unlock_chunks(block_group->fs_info->chunk_root);
 
                /* once for us and once for the tree */