All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Herbolt <lukas@herbolt.com>
To: linux-xfs@vger.kernel.org
Cc: cem@kernel.org, hch@infradead.org, djwong@kernel.org,
	pankaj.raghav@linux.dev, Pankaj Raghav <p.raghav@samsung.com>,
	Lukas Herbolt <lukas@herbolt.com>
Subject: [PATCH v12 2/2] xfs: add FALLOC_FL_WRITE_ZEROES to XFS code base
Date: Tue, 10 Mar 2026 20:42:46 +0100	[thread overview]
Message-ID: <20260310194245.848034-2-lukas@herbolt.com> (raw)

Add support for FALLOC_FL_WRITE_ZEROES if the underlying device
enable the unmap write zeroes operation.

Co-developed-by: Pankaj Raghav <p.raghav@samsung.com>
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
Signed-off-by: Lukas Herbolt <lukas@herbolt.com>
---
 v12 changes:
	split from xfs_falloc_zero_range() into separate function
 fs/xfs/xfs_file.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index fd049a1fc9c6..ede7be05d83e 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -1318,6 +1318,49 @@ xfs_falloc_zero_range(
 	return xfs_falloc_setsize(file, new_size);
 }
 
+static int
+xfs_falloc_write_zero_range(
+	struct file		*file,
+	int			mode,
+	loff_t			offset,
+	loff_t			len,
+	struct xfs_zone_alloc_ctx *ac)
+{
+	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
+	unsigned int		blksize = i_blocksize(inode);
+	loff_t			new_size = 0;
+	int			error;
+
+	if (xfs_is_always_cow_inode(ip) ||
+	    !bdev_write_zeroes_unmap_sectors(
+		    xfs_inode_buftarg(ip)->bt_bdev))
+		return -EOPNOTSUPP;
+
+	trace_xfs_zero_file_space(ip);
+
+	error = xfs_falloc_newsize(file, mode, offset, len, &new_size);
+	if (error)
+		return error;
+
+	error = xfs_free_file_space(ip, offset, len, ac);
+	if (error)
+		return error;
+
+	len = round_up(offset + len, blksize) - round_down(offset, blksize);
+	offset = round_down(offset, blksize);
+	error = xfs_alloc_file_space(ip, offset, len, XFS_BMAPI_PREALLOC);
+	if (error)
+		return error;
+
+	error = xfs_falloc_setsize(file, new_size);
+	if (error)
+		return error;
+
+	return xfs_alloc_file_space(ip, offset, len,
+			XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO);
+}
+
 static int
 xfs_falloc_unshare_range(
 	struct file		*file,
@@ -1377,7 +1420,7 @@ xfs_falloc_allocate_range(
 		(FALLOC_FL_ALLOCATE_RANGE | FALLOC_FL_KEEP_SIZE |	\
 		 FALLOC_FL_PUNCH_HOLE |	FALLOC_FL_COLLAPSE_RANGE |	\
 		 FALLOC_FL_ZERO_RANGE |	FALLOC_FL_INSERT_RANGE |	\
-		 FALLOC_FL_UNSHARE_RANGE)
+		 FALLOC_FL_UNSHARE_RANGE | FALLOC_FL_WRITE_ZEROES)
 
 STATIC long
 __xfs_file_fallocate(
@@ -1423,6 +1466,10 @@ __xfs_file_fallocate(
 	case FALLOC_FL_ZERO_RANGE:
 		error = xfs_falloc_zero_range(file, mode, offset, len, ac);
 		break;
+	case FALLOC_FL_WRITE_ZEROES:
+		error = xfs_falloc_write_zero_range(file, mode, offset,
+				len, ac);
+		break;
 	case FALLOC_FL_UNSHARE_RANGE:
 		error = xfs_falloc_unshare_range(file, mode, offset, len);
 		break;
-- 
2.53.0


             reply	other threads:[~2026-03-10 19:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10 19:42 Lukas Herbolt [this message]
2026-03-10 20:52 ` [PATCH v12 2/2] xfs: add FALLOC_FL_WRITE_ZEROES to XFS code base Darrick J. Wong
2026-03-11  0:19 ` Dave Chinner

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=20260310194245.848034-2-lukas@herbolt.com \
    --to=lukas@herbolt.com \
    --cc=cem@kernel.org \
    --cc=djwong@kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=p.raghav@samsung.com \
    --cc=pankaj.raghav@linux.dev \
    /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.