btrfs: test fsync after rename and link with cow and nocow writes
authorFilipe Manana <fdmanana@suse.com>
Tue, 27 Apr 2021 10:29:50 +0000 (11:29 +0100)
committerEryu Guan <guaneryu@gmail.com>
Sun, 9 May 2021 13:59:17 +0000 (21:59 +0800)
commit05dc92277171ef01f6a55ac193df8eb067c779b9
treea9404a213140e163777bbedfc3082066c41837d4
parent91c239fae9983d04cba4a3589eda4f474dce7f41
btrfs: test fsync after rename and link with cow and nocow writes

Test for fsync data loss after renaming a file or adding a hard link,
with a previous fsync of another file, as well as that mtime and ctime
are correct after a power failure. Test both with COW and NOCOW writes.

This currently fails differently on different kernels:

- For kernels older than 4.19 (<= 4.18) and kernels starting from 5.10,
  the NOCOW tests are expected to fail very often on the mtime and ctime
  checks.

  The data loss check has slim chances of failing on a virtualized
  environment, because the race that leads to the data loss is due to
  the fsync() returning after writeback of the data finishes and
  returning without issuing barriers (sending REQ_PREFLUSH to the
  device), as explained in the test's comments.

  For kernels between 4.19 (inclusive) and 5.9 (inclusive), it is not
  expected to fail.

- For the btrfs integration branch (misc-next), and what is currently in
  Linus' master branch (5.13 merge window changes), in addition to the
  failures mentioned before, the test should fail very often on the data
  loss and mtime/ctime checks for COW writes.

The issues are fixed by a patch for the kernel that has the following
subject:

  "btrfs: fix race leading to unpersisted data and metadata on fsync"

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/btrfs/236 [new file with mode: 0755]
tests/btrfs/236.out [new file with mode: 0644]
tests/btrfs/group