All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wake Liu via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: Wake Liu <wakel@google.com>
Subject: [LTP] [PATCH] tse_swap: Fill swapfile with zeroes on exFAT
Date: Tue, 10 Nov 2026 11:21:00 +0000	[thread overview]
Message-ID: <20261110112100.1594353-1-wakel@google.com> (raw)

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


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2026-11-10 11:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 11:21 Wake Liu via ltp [this message]
2026-11-10 13:05 ` [LTP] tse_swap: Fill swapfile with zeroes on exFAT linuxtestproject.agent
2026-11-11  6:18 ` [LTP] [PATCH] " Wake Liu via ltp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261110112100.1594353-1-wakel@google.com \
    --to=ltp@lists.linux.it \
    --cc=wakel@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.