linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, xfs@oss.sgi.com,
	Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH 1/2] vfs: add FALLOC_FL_ZERO_RANGE to fallocate
Date: Tue, 12 Jun 2012 17:36:03 +0200	[thread overview]
Message-ID: <1339515364-17374-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1339515364-17374-1-git-send-email-pbonzini@redhat.com>

Add a new operation mode to fallocate, called FALLOC_FL_ZERO_RANGE.
It resembles the similarly named XFS ioctl.  Filesystems should
preallocate blocks for regions that span holes in the file, and convert
the entire range 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 xfs_info(8) reports unwritten=1, then the filesystem was made to
flag unwritten extents.  It is okay to report EOPNOTSUPP and let the
application deal with the outcome, but it is not okay to succeed or
report EOPNOTSUPP for the same inode depending on the other arguments.

FALLOC_FL_PUNCH_HOLE|FALLOC_FL_ZERO_RANGE is ruled out here, at the
vfs level, rather than leaving it to the filesystems.  This way, in the
future 0x6 could be used as a third mode.

Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 fs/open.c              |    8 +++++++-
 include/linux/falloc.h |    1 +
 2 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/fs/open.c b/fs/open.c
index d6c79a0..dd812b3 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -222,8 +222,14 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	if (offset < 0 || len <= 0)
 		return -EINVAL;
 
+	/* Punch hole and write-zeroes are mutually exclusive */
+	if ((mode & FALLOC_FL_PUNCH_HOLE) &&
+	    (mode & FALLOC_FL_ZERO_RANGE))
+		return -EINVAL;
+
 	/* Return error if mode is not supported */
-	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
+	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
+		     FALLOC_FL_ZERO_RANGE))
 		return -EOPNOTSUPP;
 
 	/* Punch hole must have keep size set */
diff --git a/include/linux/falloc.h b/include/linux/falloc.h
index 73e0b62..9aa9599 100644
--- a/include/linux/falloc.h
+++ b/include/linux/falloc.h
@@ -3,6 +3,7 @@
 
 #define FALLOC_FL_KEEP_SIZE	0x01 /* default is extend size */
 #define FALLOC_FL_PUNCH_HOLE	0x02 /* de-allocates range */
+#define FALLOC_FL_ZERO_RANGE	0x04 /* write zeroes */
 
 #ifdef __KERNEL__
 
-- 
1.7.1



  reply	other threads:[~2012-06-12 15:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-12 15:36 [PATCH 0/2] Add FALLOC_FL_ZERO_RANGE to fallocate Paolo Bonzini
2012-06-12 15:36 ` Paolo Bonzini [this message]
2012-06-13  1:55   ` [PATCH 1/2] vfs: add " Dave Chinner
2012-06-12 15:36 ` [PATCH 2/2] xfs: " Paolo Bonzini
2012-06-13  2:16   ` Dave Chinner
2012-06-13  6:24     ` Paolo Bonzini
2012-06-13 23:52       ` Dave Chinner
2012-06-13  1:35 ` [PATCH 0/2] Add " Dave Chinner
2012-06-13  3:30   ` Dave Chinner
2012-06-13  6:13     ` Paolo Bonzini
2012-06-13 23:51       ` Dave Chinner
2013-11-05 10:34       ` Christoph Hellwig
2013-11-05 10:36         ` Paolo Bonzini
2013-11-05 16:36           ` 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=1339515364-17374-2-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --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;
as well as URLs for NNTP newsgroup(s).