[LTP] [PATCH] tse_swap: Fill swapfile with zeroes on exFAT
Wake Liu
wakel@google.com
Tue Nov 10 12:21:00 CET 2026
Since commit bf1797960c20 ("exfat: add fallocate
FALLOC_FL_ALLOCATE_RANGE support") in v7.1, fallocate() succeeds on
exFAT. It only allocates clusters and leaves the valid data length
(VDL) unchanged, so tst_prealloc_size_fd() no longer falls back to
writing zeroes and the swapfile is left unwritten beyond the header
written by mkswap.
Since exFAT was converted to iomap in v7.2, swapon() maps the file via
iomap_swapfile_activate(), which queries the mapping with IOMAP_REPORT.
exFAT reports the range beyond the VDL as IOMAP_HOLE, so swapon()
rejects the file as having unallocated extents, and swapon01-03 and
swapoff01-02 fail on exFAT with:
tse_swap.c:228: TFAIL: swapon() on exfat failed: EINVAL (22)
This matches swapon(8), which notes that files preallocated with
fallocate(1) may be interpreted as files with holes depending on the
filesystem, and that writing the file with zeroes is the most portable
way to create a swap file.
Fill the swapfile with zeroes on exFAT, as is already done for old
XFS, so that the whole file is written before mkswap and swapon().
Signed-off-by: Wake Liu <wakel@google.com>
---
libs/swap/tse_swap.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/libs/swap/tse_swap.c b/libs/swap/tse_swap.c
index ae3c19313..1e40d0d62 100644
--- a/libs/swap/tse_swap.c
+++ b/libs/swap/tse_swap.c
@@ -145,6 +145,7 @@ int make_swapfile(const char *file, const int lineno,
unsigned int blocks = 0;
size_t pg_size = sysconf(_SC_PAGESIZE);
char mnt_path[PATH_MAX];
+ long fs_type;
safe_statvfs(file, lineno, ".", &fs_info);
@@ -177,8 +178,12 @@ int make_swapfile(const char *file, const int lineno,
if (prealloc_contiguous_file(swapfile, blk_size, blocks) != 0)
tst_brk_(file, lineno, TBROK, "Failed to create swapfile");
- /* Fill the file if needed (specific to old xfs filesystems) */
- if (tst_fs_type(swapfile) == TST_XFS_MAGIC) {
+ /*
+ * Fill the file if needed: swapon() rejects preallocated but
+ * unwritten blocks on old XFS and on exFAT.
+ */
+ fs_type = tst_fs_type(swapfile);
+ if (fs_type == TST_XFS_MAGIC || fs_type == TST_EXFAT_MAGIC) {
if (tst_fill_file(swapfile, 0, blk_size, blocks) != 0)
tst_brk_(file, lineno, TBROK, "Failed to fill swapfile");
}
--
2.56.0.506.g506a7eabc5-goog
More information about the ltp
mailing list