btrfs: do not shorten unpin len for caching block groups
authorJosef Bacik <josef@toxicpanda.com>
Fri, 23 Oct 2020 13:58:04 +0000 (09:58 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 30 Dec 2020 10:54:13 +0000 (11:54 +0100)
commit56d1654dc2fe1deaabf0a11b24cbe429951da855
treec99b681ea11d68a1008c018c91d340a2a4a460e2
parented5e2515a3d679d1e31b9c7927096a361aa52bf6
btrfs: do not shorten unpin len for caching block groups

commit 9076dbd5ee837c3882fc42891c14cecd0354a849 upstream.

While fixing up our ->last_byte_to_unpin locking I noticed that we will
shorten len based on ->last_byte_to_unpin if we're caching when we're
adding back the free space.  This is correct for the free space, as we
cannot unpin more than ->last_byte_to_unpin, however we use len to
adjust the ->bytes_pinned counters and such, which need to track the
actual pinned usage.  This could result in
WARN_ON(space_info->bytes_pinned) triggering at unmount time.

Fix this by using a local variable for the amount to add to free space
cache, and leave len untouched in this case.

CC: stable@vger.kernel.org # 5.4+
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/extent-tree.c