generic: ensure that page is properly filled before write
authorJeff Layton <jlayton@kernel.org>
Fri, 2 Jul 2021 13:40:24 +0000 (09:40 -0400)
committerEryu Guan <guaneryu@gmail.com>
Sun, 4 Jul 2021 11:02:25 +0000 (19:02 +0800)
We had a broken optimization in cephfs and netfs lib that could
cause part of a page to be improperly zeroed-out when writing to an
offset that was beyond the EOF but in an existing page.

Add a simple test that would have caught this.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/generic/639 [new file with mode: 0755]
tests/generic/639.out [new file with mode: 0644]

diff --git a/tests/generic/639 b/tests/generic/639
new file mode 100755 (executable)
index 0000000..c30f764
--- /dev/null
@@ -0,0 +1,39 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2021, Jeff Layton <jlayton@redhat.com>
+#
+# FS QA Test No. 639
+#
+# Open a file and write a little data to it. Unmount (to clean out the cache)
+# and then mount again. Then write some data to it beyond the EOF and ensure
+# the result is correct.
+#
+# Prompted by a bug in ceph_write_begin that was fixed by commit 827a746f405d.
+#
+. ./common/preamble
+_begin_fstest auto quick rw
+
+# Import common functions.
+. ./common/filter
+
+# real QA test starts here
+_supported_fs generic
+_require_test
+
+testfile="$TEST_DIR/test_write_begin.$$"
+
+# write some data to file and fsync it out
+$XFS_IO_PROG -f -c "pwrite -q 0 32" $testfile
+
+# cycle the mount to clean out the pagecache
+_test_cycle_mount
+
+# now, write to the file (near the end)
+$XFS_IO_PROG -c "pwrite -q 32 32" $testfile
+
+# dump what we think is in there
+echo "The result should be 64 bytes filled with 0xcd:"
+hexdump -C $testfile
+
+status=0
+exit
diff --git a/tests/generic/639.out b/tests/generic/639.out
new file mode 100644 (file)
index 0000000..9bf0bac
--- /dev/null
@@ -0,0 +1,5 @@
+QA output created by 639
+The result should be 64 bytes filled with 0xcd:
+00000000  cd cd cd cd cd cd cd cd  cd cd cd cd cd cd cd cd  |................|
+*
+00000040