]> git.ipfire.org Git - thirdparty/linux.git/commit
btrfs: scrub: respect the read-only flag during repair
authorQu Wenruo <wqu@suse.com>
Tue, 6 Jun 2023 02:05:04 +0000 (10:05 +0800)
committerDavid Sterba <dsterba@suse.com>
Thu, 8 Jun 2023 11:56:38 +0000 (13:56 +0200)
commit1f2030ff6e4958780af9e65a22c39fa8082f292b
tree1a528ac17ed2a1607d904030dbf37a9d12956d67
parent981a37bab5e5f16137266d3f00cf2bd018af36ef
btrfs: scrub: respect the read-only flag during repair

[BUG]
With recent scrub rework, the scrub operation no longer respects the
read-only flag passed by "-r" option of "btrfs scrub start" command.

  # mkfs.btrfs -f -d raid1 $dev1 $dev2
  # mount $dev1 $mnt
  # xfs_io -f -d -c "pwrite -b 128K -S 0xaa 0 128k" $mnt/file
  # sync
  # xfs_io -c "pwrite -S 0xff $phy1 64k" $dev1
  # xfs_io -c "pwrite -S 0xff $((phy2 + 65536)) 64k" $dev2
  # mount $dev1 $mnt -o ro
  # btrfs scrub start -BrRd $mnt
  Scrub device $dev1 (id 1) done
  Scrub started:    Tue Jun  6 09:59:14 2023
  Status:           finished
  Duration:         0:00:00
         [...]
   corrected_errors: 16 <<< Still has corrupted sectors
   last_physical: 1372585984

  Scrub device $dev2 (id 2) done
  Scrub started:    Tue Jun  6 09:59:14 2023
  Status:           finished
  Duration:         0:00:00
         [...]
   corrected_errors: 16 <<< Still has corrupted sectors
   last_physical: 1351614464

  # btrfs scrub start -BrRd $mnt
  Scrub device $dev1 (id 1) done
  Scrub started:    Tue Jun  6 10:00:17 2023
  Status:           finished
  Duration:         0:00:00
         [...]
   corrected_errors: 0 <<< No more errors
   last_physical: 1372585984

  Scrub device $dev2 (id 2) done
         [...]
   corrected_errors: 0 <<< No more errors
   last_physical: 1372585984

[CAUSE]
In the newly reworked scrub code, repair is always submitted no matter
if we're doing a read-only scrub.

[FIX]
Fix it by skipping the write submission if the scrub is a read-only one.

Unfortunately for the report part, even for a read-only scrub we will
still report it as corrected errors, as we know it's repairable, even we
won't really submit the write.

Fixes: e02ee89baa66 ("btrfs: scrub: switch scrub_simple_mirror() to scrub_stripe infrastructure")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/scrub.c