btrfs: count extents before taking inode's spinlock when reserving metadata
[linux-2.6-microblaze.git] / fs / btrfs / delalloc-space.c
index 7ddb1d1..427abaf 100644 (file)
@@ -358,8 +358,8 @@ int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes,
         * racing with an ordered completion or some such that would think it
         * needs to free the reservation we just made.
         */
-       spin_lock(&inode->lock);
        nr_extents = count_max_extents(fs_info, num_bytes);
+       spin_lock(&inode->lock);
        btrfs_mod_outstanding_extents(inode, nr_extents);
        inode->csum_bytes += disk_num_bytes;
        btrfs_calculate_inode_block_rsv_size(fs_info, inode);