From: "Darrick J. Wong" <djwong@kernel.org>
To: Zhang Yi <yi.zhang@huaweicloud.com>
Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org,
dm-devel@lists.linux.dev, linux-nvme@lists.infradead.org,
linux-scsi@vger.kernel.org, linux-xfs@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
hch@lst.de, tytso@mit.edu, bmarzins@redhat.com,
chaitanyak@nvidia.com, shinichiro.kawasaki@wdc.com,
brauner@kernel.org, martin.petersen@oracle.com,
yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com,
yangerkun@huawei.com
Subject: Re: [PATCH xfsprogs v2] xfs_io: add FALLOC_FL_WRITE_ZEROES support
Date: Thu, 14 Aug 2025 09:54:30 -0700 [thread overview]
Message-ID: <20250814165430.GR7942@frogsfrogsfrogs> (raw)
In-Reply-To: <20250813024250.2504126-1-yi.zhang@huaweicloud.com>
On Wed, Aug 13, 2025 at 10:42:50AM +0800, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
>
> The Linux kernel (since version 6.17) supports FALLOC_FL_WRITE_ZEROES in
> fallocate(2). Add support for FALLOC_FL_WRITE_ZEROES support to the
> fallocate utility by introducing a new 'fwzero' command in the xfs_io
> tool.
>
> Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=278c7d9b5e0c
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
> ---
> v1->v2:
> - Minor description modification to align with the kernel.
>
> io/prealloc.c | 36 ++++++++++++++++++++++++++++++++++++
> man/man8/xfs_io.8 | 6 ++++++
> 2 files changed, 42 insertions(+)
>
> diff --git a/io/prealloc.c b/io/prealloc.c
> index 8e968c9f..9a64bf53 100644
> --- a/io/prealloc.c
> +++ b/io/prealloc.c
> @@ -30,6 +30,10 @@
> #define FALLOC_FL_UNSHARE_RANGE 0x40
> #endif
>
> +#ifndef FALLOC_FL_WRITE_ZEROES
> +#define FALLOC_FL_WRITE_ZEROES 0x80
> +#endif
> +
> static cmdinfo_t allocsp_cmd;
> static cmdinfo_t freesp_cmd;
> static cmdinfo_t resvsp_cmd;
> @@ -41,6 +45,7 @@ static cmdinfo_t fcollapse_cmd;
> static cmdinfo_t finsert_cmd;
> static cmdinfo_t fzero_cmd;
> static cmdinfo_t funshare_cmd;
> +static cmdinfo_t fwzero_cmd;
>
> static int
> offset_length(
> @@ -377,6 +382,27 @@ funshare_f(
> return 0;
> }
>
> +static int
> +fwzero_f(
> + int argc,
> + char **argv)
> +{
> + xfs_flock64_t segment;
> + int mode = FALLOC_FL_WRITE_ZEROES;
Shouldn't this take a -k to add FALLOC_FL_KEEP_SIZE like fzero?
(The code otherwise looks fine to me)
--D
> +
> + if (!offset_length(argv[1], argv[2], &segment)) {
> + exitcode = 1;
> + return 0;
> + }
> +
> + if (fallocate(file->fd, mode, segment.l_start, segment.l_len)) {
> + perror("fallocate");
> + exitcode = 1;
> + return 0;
> + }
> + return 0;
> +}
> +
> void
> prealloc_init(void)
> {
> @@ -489,4 +515,14 @@ prealloc_init(void)
> funshare_cmd.oneline =
> _("unshares shared blocks within the range");
> add_command(&funshare_cmd);
> +
> + fwzero_cmd.name = "fwzero";
> + fwzero_cmd.cfunc = fwzero_f;
> + fwzero_cmd.argmin = 2;
> + fwzero_cmd.argmax = 2;
> + fwzero_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
> + fwzero_cmd.args = _("off len");
> + fwzero_cmd.oneline =
> + _("zeroes space and eliminates holes by allocating and submitting write zeroes");
> + add_command(&fwzero_cmd);
> }
> diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
> index b0dcfdb7..0a673322 100644
> --- a/man/man8/xfs_io.8
> +++ b/man/man8/xfs_io.8
> @@ -550,6 +550,12 @@ With the
> .B -k
> option, use the FALLOC_FL_KEEP_SIZE flag as well.
> .TP
> +.BI fwzero " offset length"
> +Call fallocate with FALLOC_FL_WRITE_ZEROES flag as described in the
> +.BR fallocate (2)
> +manual page to allocate and zero blocks within the range by submitting write
> +zeroes.
> +.TP
> .BI zero " offset length"
> Call xfsctl with
> .B XFS_IOC_ZERO_RANGE
> --
> 2.39.2
>
>
next prev parent reply other threads:[~2025-08-14 16:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-13 2:42 [PATCH xfsprogs v2] xfs_io: add FALLOC_FL_WRITE_ZEROES support Zhang Yi
2025-08-14 16:54 ` Darrick J. Wong [this message]
2025-08-15 9:59 ` Zhang Yi
2025-08-15 14:42 ` Darrick J. Wong
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=20250814165430.GR7942@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=bmarzins@redhat.com \
--cc=brauner@kernel.org \
--cc=chaitanyak@nvidia.com \
--cc=chengzhihao1@huawei.com \
--cc=dm-devel@lists.linux.dev \
--cc=hch@lst.de \
--cc=linux-api@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=shinichiro.kawasaki@wdc.com \
--cc=tytso@mit.edu \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yi.zhang@huaweicloud.com \
--cc=yukuai3@huawei.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;
as well as URLs for NNTP newsgroup(s).