public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: xfs@oss.sgi.com
Subject: [PATCH] xfsprogs: Add support for XFS_IOC_ZERO_RANGE
Date: Tue,  3 Aug 2010 16:18:44 +1000	[thread overview]
Message-ID: <1280816324-29984-1-git-send-email-david@fromorbit.com> (raw)

From: Dave Chinner <dchinner@redhat.com>

Add xfs_io support for XFS_IOC_ZERO_RANGE and document the ioctl
parameter in the xfsctl(3) man page.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 include/xfs_fs.h  |    1 +
 io/prealloc.c     |   29 +++++++++++++++++++++++++++++
 man/man3/xfsctl.3 |   18 ++++++++++++++++++
 3 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/include/xfs_fs.h b/include/xfs_fs.h
index 2376abb..74e7274 100644
--- a/include/xfs_fs.h
+++ b/include/xfs_fs.h
@@ -458,6 +458,7 @@ typedef struct xfs_handle {
 /*	XFS_IOC_SETBIOSIZE ---- deprecated 46	   */
 /*	XFS_IOC_GETBIOSIZE ---- deprecated 47	   */
 #define XFS_IOC_GETBMAPX	_IOWR('X', 56, struct getbmap)
+#define XFS_IOC_ZERO_RANGE	_IOW ('X', 57, struct xfs_flock64)
 
 /*
  * ioctl commands that replace IRIX syssgi()'s
diff --git a/io/prealloc.c b/io/prealloc.c
index 5f6b029..c8b7df6 100644
--- a/io/prealloc.c
+++ b/io/prealloc.c
@@ -29,6 +29,7 @@ static cmdinfo_t allocsp_cmd;
 static cmdinfo_t freesp_cmd;
 static cmdinfo_t resvsp_cmd;
 static cmdinfo_t unresvsp_cmd;
+static cmdinfo_t zero_cmd;
 #if defined(HAVE_FALLOCATE)
 static cmdinfo_t falloc_cmd;
 #endif
@@ -125,6 +126,24 @@ unresvsp_f(
 	return 0;
 }
 
+static int
+zero_f(
+	int		argc,
+	char		**argv)
+{
+	xfs_flock64_t	segment;
+
+	if (!offset_length(argv[1], argv[2], &segment))
+		return 0;
+
+	if (xfsctl(file->name, file->fd, XFS_IOC_ZERO_RANGE, &segment) < 0) {
+		perror("XFS_IOC_ZERO_RANGE");
+		return 0;
+	}
+	return 0;
+}
+
+
 #if defined (HAVE_FALLOCATE)
 static int
 fallocate_f(
@@ -196,10 +215,20 @@ prealloc_init(void)
 	unresvsp_cmd.oneline =
 		_("frees reserved space associated with part of a file");
 
+	zero_cmd.name = _("zero");
+	zero_cmd.cfunc = zero_f;
+	zero_cmd.argmin = 2;
+	zero_cmd.argmax = 2;
+	zero_cmd.flags = CMD_NOMAP_OK;
+	zero_cmd.args = _("off len");
+	zero_cmd.oneline =
+		_("Converts the given range of a file to allocated zeros");
+
 	add_command(&allocsp_cmd);
 	add_command(&freesp_cmd);
 	add_command(&resvsp_cmd);
 	add_command(&unresvsp_cmd);
+	add_command(&zero_cmd);
 
 #if defined (HAVE_FALLOCATE)
 	falloc_cmd.name = _("falloc");
diff --git a/man/man3/xfsctl.3 b/man/man3/xfsctl.3
index 64e18df..784b3e0 100644
--- a/man/man3/xfsctl.3
+++ b/man/man3/xfsctl.3
@@ -338,6 +338,24 @@ in the final argument.
 Partial filesystem blocks are zeroed, and whole filesystem blocks are
 removed from the file.  The file size does not change.
 
+.TP
+.B XFS_IOC_ZERO_RANGE
+This command is used to convert a range of a file to zeros without issuing data
+IO.
+A range of bytes is specified using a pointer to a variable of type
+.B xfs_flock64_t
+in the final argument.
+Blocks are preallocated for regions that span holes in the file, and the entire
+range is converted to unwritten extents.
+This operation is a fast method of overwriting any from the range specified
+with zeros without removing any blocks or having to write zeros to disk.
+Any subsequent read in the given range will return zeros until new data is
+written.
+This functionality requires filesystems to support unwritten extents.
+If
+.BR xfs_info (8)
+reports unwritten=1, then the filesystem was made to flag unwritten extents.
+
 .\" .TP
 .\" .B XFS_IOC_GETBIOSIZE
 .\" This command gets information about the preferred buffered I/O
-- 
1.7.1

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

             reply	other threads:[~2010-08-03  6:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-03  6:18 Dave Chinner [this message]
2010-08-03 18:55 ` [PATCH] xfsprogs: Add support for XFS_IOC_ZERO_RANGE Christoph Hellwig

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=1280816324-29984-1-git-send-email-david@fromorbit.com \
    --to=david@fromorbit.com \
    --cc=xfs@oss.sgi.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