linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Chinner <dgc@sgi.com>
To: "Amit K. Arora" <aarora@linux.vnet.ibm.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-ext4@vger.kernel.org, xfs@oss.sgi.com, tytso@mit.edu,
	cmm@us.ibm.com, suparna@in.ibm.com, adilger@clusterfs.com,
	dgc@sgi.com, michael.kerrisk@gmx.net
Subject: [PATCH] xfs: implement fallocate V2
Date: Mon, 16 Jul 2007 15:37:51 +1000	[thread overview]
Message-ID: <20070716053751.GN12413810@sgi.com> (raw)
In-Reply-To: <20070713184125.GA12156@amitarora.in.ibm.com>

Initial implementation of ->fallocate for XFS.

Version 2:

o Make allocation and setting the file size atomic.
o Drop deallocate/punch functionality
o use mode field appropriately to determine if size needs changing.

---
 fs/xfs/linux-2.6/xfs_iops.c |   47 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_iops.c
===================================================================
--- 2.6.x-xfs-new.orig/fs/xfs/linux-2.6/xfs_iops.c	2007-07-16 14:16:02.090255611 +1000
+++ 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_iops.c	2007-07-16 14:50:07.087885337 +1000
@@ -51,6 +51,7 @@
 #include <linux/xattr.h>
 #include <linux/namei.h>
 #include <linux/security.h>
+#include <linux/falloc.h>
 
 /*
  * Get a XFS inode from a given vnode.
@@ -812,6 +813,51 @@ xfs_vn_removexattr(
 	return namesp->attr_remove(vp, attr, xflags);
 }
 
+/*
+ * generic space allocation vector.
+ *
+ * This should really through a bhv_vop before stuffing around
+ * with xfs_inodes and such.
+ */
+STATIC long
+xfs_vn_fallocate(
+	struct inode	*inode,
+	int		mode,
+	loff_t		offset,
+	loff_t		len)
+{
+	long		error = -EOPNOTSUPP;
+	bhv_vnode_t	*vp = vn_from_inode(inode);
+	bhv_desc_t	*bdp;
+	loff_t		new_size = 0;
+	xfs_flock64_t	bf;
+
+	bf.l_whence = 0;
+	bf.l_start = offset;
+	bf.l_len = len;
+
+	bdp = bhv_lookup_range(VN_BHV_HEAD(vp), VNODE_POSITION_XFS,
+						VNODE_POSITION_XFS);
+
+	xfs_ilock(xfs_vtoi(vp), XFS_IOLOCK_EXCL);
+	error = xfs_change_file_space(bdp, XFS_IOC_RESVSP, &bf, 0, NULL,
+							ATTR_NOLOCK);
+	if (!error && !(mode & FALLOC_FL_KEEP_SIZE) &&
+	    offset + len > i_size_read(inode))
+		new_size = offset + len;
+
+	/* Change file size if needed */
+	if (new_size) {
+		bhv_vattr_t	va;
+
+		va.va_mask = XFS_AT_SIZE;
+		va.va_size = new_size;
+		error = bhv_vop_setattr(vp, &va, ATTR_NOLOCK, NULL);
+	}
+
+	xfs_iunlock(xfs_vtoi(vp), XFS_IOLOCK_EXCL);
+	return error;
+}
 
 const struct inode_operations xfs_inode_operations = {
 	.permission		= xfs_vn_permission,
@@ -822,6 +868,7 @@ const struct inode_operations xfs_inode_
 	.getxattr		= xfs_vn_getxattr,
 	.listxattr		= xfs_vn_listxattr,
 	.removexattr		= xfs_vn_removexattr,
+	.fallocate		= xfs_vn_fallocate,
 };
 
 const struct inode_operations xfs_dir_inode_operations = {
-- 
Dave Chinner
Principal Engineer
SGI Australian Software Group

  parent reply	other threads:[~2007-07-16  5:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-13 18:41 [PATCH 0/5][TAKE8] fallocate system call Amit K. Arora
2007-07-13 18:46 ` [PATCH 1/5][TAKE8] manpage for fallocate Amit K. Arora
2007-07-19  3:41   ` Mark Fasheh
2007-07-19  5:10     ` David Chinner
2007-07-19  5:31       ` Mark Fasheh
2007-07-19 23:58     ` Andreas Dilger
2007-07-13 18:49 ` [PATCH 2/5][TAKE8] fallocate() implementation in i386, x86_64 and powerpc Amit K. Arora
2007-07-13 18:50 ` [PATCH 3/5][TAKE8] ext4: fallocate support in ext4 Amit K. Arora
2007-07-13 18:51 ` [PATCH 4/5][TAKE8] ext4: write support for preallocated blocks Amit K. Arora
2007-07-13 18:52 ` [PATCH 5/5][TAKE8] ext4: change for better extent-to-group alignment Amit K. Arora
2007-07-16  5:33 ` [PATCH] ia64 fallocate system call David Chinner
2007-07-16  5:37 ` David Chinner [this message]
2007-07-16  5:55 ` [PATCH] introduce fallocate support into xfs_io David Chinner

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=20070716053751.GN12413810@sgi.com \
    --to=dgc@sgi.com \
    --cc=aarora@linux.vnet.ibm.com \
    --cc=adilger@clusterfs.com \
    --cc=cmm@us.ibm.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.kerrisk@gmx.net \
    --cc=suparna@in.ibm.com \
    --cc=tytso@mit.edu \
    --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).