Linux Test Project
 help / color / mirror / Atom feed
From: Brian Mak via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: Brian Mak <bmak@nvidia.com>
Subject: [LTP] [PATCH 2/2] tse_swap: Fill swapfile with zeroes on ntfs3
Date: Fri, 20 Nov 2026 16:36:53 -0800	[thread overview]
Message-ID: <20261121003653.179935-3-bmak@nvidia.com> (raw)
In-Reply-To: <20261121003653.179935-1-bmak@nvidia.com>

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


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

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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21  0:36 [LTP] [PATCH 0/2] ntfs3: Add magic and fix swapfile creation Brian Mak via ltp
2026-11-21  0:36 ` [LTP] [PATCH 1/2] lib: Add ntfs3 magic Brian Mak via ltp
2026-11-23 12:27   ` Cyril Hrubis
2026-11-21  0:36 ` Brian Mak via ltp [this message]
2026-11-23 12:16   ` [LTP] [PATCH 2/2] tse_swap: Fill swapfile with zeroes on ntfs3 Cyril Hrubis

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=20261121003653.179935-3-bmak@nvidia.com \
    --to=ltp@lists.linux.it \
    --cc=bmak@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox