[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250318072318.3502037-1-yi.zhang@huaweicloud.com>
Date: Tue, 18 Mar 2025 15:23:18 +0800
From: Zhang Yi <yi.zhang@...weicloud.com>
To: linux-fsdevel@...r.kernel.org,
linux-ext4@...r.kernel.org,
linux-block@...r.kernel.org,
dm-devel@...ts.linux.dev,
linux-nvme@...ts.infradead.org,
linux-scsi@...r.kernel.org
Cc: linux-xfs@...r.kernel.org,
linux-kernel@...r.kernel.org,
hch@....de,
tytso@....edu,
djwong@...nel.org,
john.g.garry@...cle.com,
bmarzins@...hat.com,
chaitanyak@...dia.com,
shinichiro.kawasaki@....com,
yi.zhang@...wei.com,
yi.zhang@...weicloud.com,
chengzhihao1@...wei.com,
yukuai3@...wei.com,
yangerkun@...wei.com
Subject: [PATCH xfsprogs] xfs_io: add FALLOC_FL_WRITE_ZEROES support
From: Zhang Yi <yi.zhang@...wei.com>
The Linux kernel is planning to support FALLOC_FL_WRITE_ZEROES in
fallocate(2). Add FALLOC_FL_ZERO_RANGE support to fallocate utility by
introducing a new 'fwzero' command to xfs_io.
Signed-off-by: Zhang Yi <yi.zhang@...wei.com>
---
io/prealloc.c | 36 ++++++++++++++++++++++++++++++++++++
man/man8/xfs_io.8 | 5 +++++
2 files changed, 41 insertions(+)
diff --git a/io/prealloc.c b/io/prealloc.c
index 8e968c9f..9d126229 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;
+
+ 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 writing zeroes");
+ add_command(&fwzero_cmd);
}
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index 59d5ddc5..718f018c 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -538,6 +538,11 @@ 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 writing zeroes.
+.TP
.BI zero " offset length"
Call xfsctl with
.B XFS_IOC_ZERO_RANGE
--
2.46.1
Powered by blists - more mailing lists