The scrub progress ioctl is copying the scrub progress stats without
acquiring the spinlock that protects it and a concurrent scrub can be
updating the stats at the same time which can lead to load tearing
issues. So take the spinlock when copying the progress stats.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
(cherry picked from btrfs for-next commit
ab268571b210d4d49c5f03e96189c3b760989c3a)
if (dev) {
mutex_lock(&fs_info->scrub_lock);
sctx = dev->scrub_ctx;
- if (sctx)
+ if (sctx) {
+ spin_lock(&sctx->stat_lock);
memcpy(progress, &sctx->stat, sizeof(*progress));
+ spin_unlock(&sctx->stat_lock);
+ }
mutex_unlock(&fs_info->scrub_lock);
}
mutex_unlock(&fs_info->fs_devices->device_list_mutex);