[LTP] [PATCH 2/2] tse_swap: Fill swapfile with zeroes on ntfs3
Brian Mak
bmak@nvidia.com
Sat Nov 21 01:36:53 CET 2026
On ntfs3, fallocate() allocates clusters but does not change the valid
data length.
ntfs3 has no ->swap_activate(), so swapon() maps the file with
generic_swapfile_activate() and ->bmap(). Since ntfs3 was converted to
iomap in v7.0, ntfs_bmap() calls iomap_bmap(), which only returns a
block number for IOMAP_MAPPED extents, while ntfs3 reports the range
beyond the valid data length as IOMAP_UNWRITTEN. swapon() therefore
rejects the file, and swapon01-03 and swapoff01-02 fail on ntfs3 with:
swapon: swapfile has holes
tse_swap.c:228: TFAIL: swapon() on unknown failed: EINVAL (22)
Fill the swapfile with zeroes on ntfs3, as is already done for old XFS,
so that the whole file is written before mkswap and swapon().
Signed-off-by: Brian Mak <bmak@nvidia.com>
---
libs/swap/tse_swap.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libs/swap/tse_swap.c b/libs/swap/tse_swap.c
index ae3c19313..a19e97556 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,11 @@ 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 (specific to old XFS and ntfs3)
+ */
+ fs_type = tst_fs_type(swapfile);
+ if (fs_type == TST_XFS_MAGIC || fs_type == TST_NTFS3_MAGIC) {
if (tst_fill_file(swapfile, 0, blk_size, blocks) != 0)
tst_brk_(file, lineno, TBROK, "Failed to fill swapfile");
}
--
2.53.0
More information about the ltp
mailing list