btrfs: fix async discard stall
authorPavel Begunkov <asml.silence@gmail.com>
Sun, 6 Dec 2020 15:56:20 +0000 (15:56 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 19 Jan 2021 17:27:24 +0000 (18:27 +0100)
commit33061bd104cbf6798738cf2f5608f18910d9f9da
tree74e5970bbdd91c10f2da8e06c2f619f817dd8a04
parentd18e04ce283a2aa28815a04d274157d27b1872cf
btrfs: fix async discard stall

[ Upstream commit ea9ed87c73e87e044b2c58d658eb4ba5216bc488 ]

Might happen that bg->discard_eligible_time was changed without
rescheduling, so btrfs_discard_workfn() wakes up earlier than that new
time, peek_discard_list() returns NULL, and all work halts and goes to
sleep without further rescheduling even there are block groups to
discard.

It happens pretty often, but not so visible from the userspace because
after some time it usually will be kicked off anyway by someone else
calling btrfs_discard_reschedule_work().

Fix it by continue rescheduling if block group discard lists are not
empty.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/discard.c