[Top] [All Lists]

[PATCH 1/2] vfs: add FALLOC_FL_ZERO_RANGE to fallocate

To: linux-kernel@xxxxxxxxxxxxxxx
Subject: [PATCH 1/2] vfs: add FALLOC_FL_ZERO_RANGE to fallocate
From: Paolo Bonzini <pbonzini@xxxxxxxxxx>
Date: Tue, 12 Jun 2012 17:36:03 +0200
Cc: linux-fsdevel@xxxxxxxxxxxxxxx, xfs@xxxxxxxxxxx, Al Viro <viro@xxxxxxxxxxxxxxxxxx>
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=9g4h1eOxJQye+2AoE83rSqIXEVvSRQBovMhbsJ4v6Q4=; b=0yLjxJa1ld4BN+Iqm+cXHJL2J6fEri93R2yzwlRWt0LB9bQEg0fOMOS5H3AxVxgs5k y6ztdxFG/8+7DtUH+7bDAipf4rAQUYB0CctvrQF5xv1pdM+7z1xBh8db6oVxOUjgYxG9 QIyt2OwVWjFBqzYBAMvVK2mvCBx4/8kKsPRrct/zYtFxgvMAtkB37NiSQnNubxGtzAbJ XqDrE0tPteE4bAZ5LOhWIU4VXoOtB+zQRLc8G7qlN4nmNmtxmec/q4wMtwZO8Yl5WUvu og1xivdtaeUBp97BnADFAPB+4c52BBJNgQHrW1rrZzz7ymLN0Y2Wdqwt2qyGAoRgPROZ nRmw==
In-reply-to: <1339515364-17374-1-git-send-email-pbonzini@xxxxxxxxxx>
References: <1339515364-17374-1-git-send-email-pbonzini@xxxxxxxxxx>
Sender: Paolo Bonzini <paolo.bonzini@xxxxxxxxx>
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.

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@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
 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 */
+                    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__

<Prev in Thread] Current Thread [Next in Thread>