tse_swap: Fill swapfile with zeroes on exFAT
PATCH 1/1 tse_swap: Fill swapfile with zeroes on exFAT
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().
--- libs/swap/tse_swap.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
libs/swap/tse_swap.c +7 -2
@@ -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" ); }
Signature · 5 lines
2.56.0.506.g506a7eabc5-goog -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wake,
libs/swap/tse_swap.c int make_swapfile(const char *file, const int lineno, · line 189
Quoted 13 lines · Wake Liu
tse_swap: Fill swapfile with zeroes on exFATlibs/swap/tse_swap.c +6
-2-/* 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" ); }
The swapon() failure on fallocate()-preallocated exFAT swapfiles in v7.2 is a kernel regression that was fixed in v7.4 by kernel commit 4483ab85d1e0 ("exfat: map allocated extents for swap activation"), which suppresses IOMAP_REPORT during swap activation so preallocated blocks beyond valid_size are mapped as IOMAP_UNWRITTEN instead of IOMAP_HOLE. Filling the swapfile with zeroes on exFAT works around this kernel bug in LTP and masks the failure on kernels missing that fix, so this change should be dropped.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi,
Please drop this patch. As the review pointed out, the swapon() failure on preallocated exFAT swapfiles is a kernel regression fixed in v7.4-rc1 by commit 4483ab85d1e0 ("exfat: map allocated extents for swap activation"), so LTP should keep reporting it on kernels without that fix.
Sorry for the noise.
Thanks,
Wake
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp