At btrfs_wait_ordered_extents(), there's no point in updating the counters
after locking the root's ordered extent lock, as the counters are local.
So change this to update the counters before taking the lock.
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
                btrfs_queue_work(fs_info->flush_workers, &ordered->flush_work);
 
                cond_resched();
-               spin_lock(&root->ordered_extent_lock);
                if (nr != U64_MAX)
                        nr--;
                count++;
+               spin_lock(&root->ordered_extent_lock);
        }
        list_splice_tail(&skipped, &root->ordered_extents);
        list_splice_tail(&splice, &root->ordered_extents);