btrfs: fix racy access to discard_ctl data
authorPavel Begunkov <asml.silence@gmail.com>
Sun, 6 Dec 2020 15:56:21 +0000 (15:56 +0000)
committerDavid Sterba <dsterba@suse.com>
Fri, 18 Dec 2020 13:59:53 +0000 (14:59 +0100)
commit1ea2872fc6f2aaee0a4b4f1578b83ffd9f55c6a7
tree7aed7e743d59c9efb9e1b2430918426b2bedbd28
parentea9ed87c73e87e044b2c58d658eb4ba5216bc488
btrfs: fix racy access to discard_ctl data

Because only one discard worker may be running at any given point, it
could have been safe to modify ->prev_discard, etc. without
synchronization, if not for @override flag in
btrfs_discard_schedule_work() and delayed_work_pending() returning false
while workfn is running.

That may lead to torn reads of u64 for some architectures, but that's
not a big problem as only slightly affects the discard rate.

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