fstests.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] generic: test overwriting file with mmap on a full filesystem
@ 2025-07-09  8:53 fdmanana
  2025-07-10  7:29 ` Zorro Lang
  2025-07-10 17:03 ` [PATCH v2] " fdmanana
  0 siblings, 2 replies; 14+ messages in thread
From: fdmanana @ 2025-07-09  8:53 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Filipe Manana

From: Filipe Manana <fdmanana@suse.com>

Test that overwriting a file with mmap when the filesystem has no more
space available for data allocation works. The motivation here is to check
that NOCOW mode of a COW filesystem (such as btrfs) works as expected.

This currently fails with btrfs but it's fixed by a kernel patch that has
the subject:

   btrfs: fix -ENOSPC mmap write failure on NOCOW files/extents

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 tests/generic/211     | 58 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/211.out |  6 +++++
 2 files changed, 64 insertions(+)
 create mode 100755 tests/generic/211
 create mode 100644 tests/generic/211.out

diff --git a/tests/generic/211 b/tests/generic/211
new file mode 100755
index 00000000..c77508fe
--- /dev/null
+++ b/tests/generic/211
@@ -0,0 +1,58 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2025 SUSE Linux Products GmbH.  All Rights Reserved.
+#
+# FS QA Test 211
+#
+# Test that overwriting a file with mmap when the filesystem has no more space
+# available for data allocation works. The motivation here is to check that
+# NOCOW mode of a COW filesystem (such as btrfs) works as expected.
+#
+. ./common/preamble
+_begin_fstest auto quick rw mmap
+
+. ./common/filter
+
+_require_scratch
+
+[ "$FSTYP" = "btrfs" ] && _fixed_by_kernel_commit xxxxxxxxxxxx \
+	"btrfs: fix -ENOSPC mmap write failure on NOCOW files/extents"
+
+# Use a 512M fs so that it's fast to fill it with data but not too small such
+# that on btrfs it results in a fs with mixed block groups - we want to have
+# dedicated block groups for data and metadata, so that after filling all the
+# data block groups we can do a NOCOW write with mmap (if we have enough free
+# metadata space available).
+fs_size=$(_small_fs_size_mb 512)
+_scratch_mkfs_sized $((fs_size * 1024 * 1024)) >>$seqres.full 2>&1 || \
+	_fail "mkfs failed"
+_scratch_mount
+
+touch $SCRATCH_MNT/foobar
+
+# Set the file to NOCOW mode on btrfs, which must be done while the file is
+# empty, otherwise it fails.
+if [ $FSTYP == "btrfs" ]; then
+	_require_chattr C
+	$CHATTR_PROG +C $SCRATCH_MNT/foobar
+fi
+
+# Add initial data to the file we will later overwrite with mmap.
+$XFS_IO_PROG -c "pwrite -S 0xab 0 1M" $SCRATCH_MNT/foobar | _filter_xfs_io
+
+# Now fill all the remaining space with data.
+blksz=$(_get_block_size $SCRATCH_MNT)
+dd if=/dev/zero of=$SCRATCH_MNT/filler bs=$blksz >>$seqres.full 2>&1
+
+# Overwrite the file with a mmap write. Should succeed.
+$XFS_IO_PROG -c "mmap -w 0 1M"        \
+	     -c "mwrite -S 0xcd 0 1M" \
+	     -c "munmap"              \
+	     $SCRATCH_MNT/foobar
+
+# Cycle mount and dump the file's content. We expect to see the new data.
+_scratch_cycle_mount
+_hexdump $SCRATCH_MNT/foobar
+
+# success, all done
+_exit 0
diff --git a/tests/generic/211.out b/tests/generic/211.out
new file mode 100644
index 00000000..71cdf0f8
--- /dev/null
+++ b/tests/generic/211.out
@@ -0,0 +1,6 @@
+QA output created by 211
+wrote 1048576/1048576 bytes at offset 0
+XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+000000 cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd  >................<
+*
+100000
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-07-23  5:48 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-09  8:53 [PATCH] generic: test overwriting file with mmap on a full filesystem fdmanana
2025-07-10  7:29 ` Zorro Lang
2025-07-10  7:45   ` Qu Wenruo
2025-07-10 11:47   ` Filipe Manana
2025-07-10 16:07     ` Zorro Lang
2025-07-10 17:02       ` Filipe Manana
2025-07-10 17:03 ` [PATCH v2] " fdmanana
2025-07-10 18:24   ` Zorro Lang
2025-07-10 22:00   ` Qu Wenruo
2025-07-22  6:55   ` Christoph Hellwig
2025-07-22  7:50     ` Johannes Thumshirn
2025-07-22  8:16       ` hch
2025-07-22 10:27     ` Filipe Manana
2025-07-23  5:48       ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).