linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Updated fiemap patches
@ 2008-10-03 21:59 Theodore Ts'o
  2008-10-03 21:59 ` [PATCH 1/4] vfs: vfs-level fiemap interface Theodore Ts'o
  0 siblings, 1 reply; 30+ messages in thread
From: Theodore Ts'o @ 2008-10-03 21:59 UTC (permalink / raw)
  To: linux-fsdevel

Since Mark has been busy, with his agreement I've updated the fiemap
patches based on the last series of comments.  All of the patches have
been cc'ed to linux-fsdevel, and the first patch (which contains the
interface definition) has been cc'ed to Michael Kerrisk and to the new
linux-abi mailing list.

Note that this patch has gone through a very long and tortured series
of bike shed painting, and my goal is to see if we can get consensus
so we can get this merged into the 2.6.28 merge window.  If not, I
will likely push an ext4-specific ioctl to Linus, as the long and
painful process of getting a common API that everyone can agree upon
is now starting to block ext4 online defrag development.

For that reason, this patch doesn't define support for things like
compression, as this was vetoed by Cristoph Hellwig.  There is however
plenty of room for the ABI to be extended to add this later.  It is my
devout wish that this get pushed at the next merge window, and folks
who want to extended it later can provide patches to do so.  I would
rather not have an extension of the game where one set of people
complain because the interface defines some feature, and another set
of people complain because it doesn't and in the meantime, months and
months go by with no forward progress.  Thanks in advance...

						- Ted



^ permalink raw reply	[flat|nested] 30+ messages in thread
* PATCH [0/4] Updated**3 fiemap patches
@ 2008-10-09  1:48 Theodore Ts'o
  2008-10-09  1:48 ` [PATCH 1/4] vfs: vfs-level fiemap interface Theodore Ts'o
  0 siblings, 1 reply; 30+ messages in thread
From: Theodore Ts'o @ 2008-10-09  1:48 UTC (permalink / raw)
  To: linux-fsdevel

These patches updates the name and definition of the
FIEMAP_EXTENT_ENCODED flag (formerly FIEMAP_EXTENT_NO_UNMOUNTED_IO).

At this point I believe (hope!) that we have consensus that this patch
series is ready for submission to mainline.

       					- Ted



^ permalink raw reply	[flat|nested] 30+ messages in thread
* PATCH [0/4] Updated**2 fiemap patches
@ 2008-10-07  1:06 Theodore Ts'o
  2008-10-07  1:06 ` [PATCH 1/4] vfs: vfs-level fiemap interface Theodore Ts'o
  0 siblings, 1 reply; 30+ messages in thread
From: Theodore Ts'o @ 2008-10-07  1:06 UTC (permalink / raw)
  To: linux-fsdevel

This the second update of the fiemap patches, which integrates the
changes and typographical fixups as suggested by Jim Owens.  In
particular, FIEMAP_EXTENT_NO_MOUNTED_IO was renamed to what I had
intended, but mistyped, FIEMAP_EXTENT_NO_UNMOUNTED_IO, and the
explanation of that flag has been clarified.

Hopefully folks are happy with this.  I plan to push this to Linus
when the next merge window opens up.

					- Ted



^ permalink raw reply	[flat|nested] 30+ messages in thread
* YET ANOTHER resend of the fiemap patches
@ 2008-09-13 18:47 Theodore Ts'o
  2008-09-13 18:49 ` [PATCH 1/4] vfs: vfs-level fiemap interface Theodore Ts'o
  0 siblings, 1 reply; 30+ messages in thread
From: Theodore Ts'o @ 2008-09-13 18:47 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Mark Fasheh, linux-ext4


So the last round of the on-going round-and-round of the FIEMAP patches
went to the linux-ext4 mailing list, because of a query there about why
these patches had been stalled for so long.  This resulted in a private
set of e-mails attacking an ext4 developer and putting forward a
conspiracy theory that these patches were trying to be snuck in, despite
the fact that they have been sent on linux-fsdevel at least 4 times
already.

Mark has at this point I believe answered all of Christoph Hellwig's
demands, and put forward a request to Andrew Morton to include them in
-mm (minus the ext4 patch, since the version he had no longer compiled).

As of this writing, Andrew has not put them into -mm, I suspect because
he perceives there is still controversies around these patches, despite
the fact that most of the e-mails and time wasted has been over
individual bitflags and other really tiny nit-picky details.  So I am
re-sending these patches out for review on linux-fsdevel.  The first
three patches are taken from Mark's fiemap branch on the ocfs2 branch.
The last patch is an updated ext4 patch from the ext4 patch queue, which
is provided so that folks can see that the fiemap patches work just fine
on ext4.

Given that filesystem designers seem to love nit-picking tiny details,
and I am personally starting to lose patience, if the fiemap patches
stalls any further, my plan is to take a page from the XFS playbook and
simply take the ext4-fiemap patch and implement an ext4-specific ioctl.
If and when the linux-fsdevel community manages come to consensus on the
fiemap patches, whether it happens in 2.6.28 or Linux 2.6.87, it will be
easy enough to wire the ext4 support to the generic fiemap ioctl.

	"It's *just* an ioctl, folks" --- Andreas Dilger

Yours disgustedly,

						- Ted


^ permalink raw reply	[flat|nested] 30+ messages in thread
* [PATCH 3/4] generic block based fiemap implementation
@ 2008-06-25 22:19 Mark Fasheh
  0 siblings, 0 replies; 30+ messages in thread
From: Mark Fasheh @ 2008-06-25 22:19 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Josef Bacik

From: Josef Bacik <jbacik@redhat.com>

Any block based fs (this patch includes ext3) just has to declare its own
fiemap() function and then call this generic function with its own
get_block_t. This works well for block based filesystems that will map
multiple contiguous blocks at one time, but will work for filesystems that
only map one block at a time, you will just end up with an "extent" for each
block. One gotcha is this will not play nicely where there is hole+data
after the EOF. This function will assume its hit the end of the data as soon
as it hits a hole after the EOF, so if there is any data past that it will
not pick that up. AFAIK no block based fs does this anyway, but its in the
comments of the function anyway just in case.

Signed-off-by: Josef Bacik <jbacik@redhat.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
---
 fs/ext2/ext2.h          |    2 +
 fs/ext2/file.c          |    1 +
 fs/ext2/inode.c         |    8 +++
 fs/ext3/file.c          |    1 +
 fs/ext3/inode.c         |    8 +++
 fs/ioctl.c              |  119 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/ext3_fs.h |    2 +
 include/linux/fs.h      |    3 +
 8 files changed, 144 insertions(+), 0 deletions(-)

diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h
index 47d88da..bae998c 100644
--- a/fs/ext2/ext2.h
+++ b/fs/ext2/ext2.h
@@ -133,6 +133,8 @@ extern void ext2_truncate (struct inode *);
 extern int ext2_setattr (struct dentry *, struct iattr *);
 extern void ext2_set_inode_flags(struct inode *inode);
 extern void ext2_get_inode_flags(struct ext2_inode_info *);
+extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
+		       u64 start, u64 len);
 int __ext2_write_begin(struct file *file, struct address_space *mapping,
 		loff_t pos, unsigned len, unsigned flags,
 		struct page **pagep, void **fsdata);
diff --git a/fs/ext2/file.c b/fs/ext2/file.c
index 5f2fa9c..45ed071 100644
--- a/fs/ext2/file.c
+++ b/fs/ext2/file.c
@@ -86,4 +86,5 @@ const struct inode_operations ext2_file_inode_operations = {
 #endif
 	.setattr	= ext2_setattr,
 	.permission	= ext2_permission,
+	.fiemap		= ext2_fiemap,
 };
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 384fc0d..f3b9d12 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -31,6 +31,7 @@
 #include <linux/writeback.h>
 #include <linux/buffer_head.h>
 #include <linux/mpage.h>
+#include <linux/fiemap.h>
 #include "ext2.h"
 #include "acl.h"
 #include "xip.h"
@@ -704,6 +705,13 @@ int ext2_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_
 
 }
 
+int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
+		u64 start, u64 len)
+{
+	return generic_block_fiemap(inode, fieinfo, start, len,
+				    ext2_get_block);
+}
+
 static int ext2_writepage(struct page *page, struct writeback_control *wbc)
 {
 	return block_write_full_page(page, ext2_get_block, wbc);
diff --git a/fs/ext3/file.c b/fs/ext3/file.c
index acc4913..3be1e06 100644
--- a/fs/ext3/file.c
+++ b/fs/ext3/file.c
@@ -134,5 +134,6 @@ const struct inode_operations ext3_file_inode_operations = {
 	.removexattr	= generic_removexattr,
 #endif
 	.permission	= ext3_permission,
+	.fiemap		= ext3_fiemap,
 };
 
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 6ae4ecf..878b6da 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -36,6 +36,7 @@
 #include <linux/mpage.h>
 #include <linux/uio.h>
 #include <linux/bio.h>
+#include <linux/fiemap.h>
 #include "xattr.h"
 #include "acl.h"
 
@@ -981,6 +982,13 @@ out:
 	return ret;
 }
 
+int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
+		u64 start, u64 len)
+{
+	return generic_block_fiemap(inode, fieinfo, start, len,
+				    ext3_get_block);
+}
+
 /*
  * `handle' can be NULL if create is zero
  */
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 0db1f8d..2c07e4b 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -13,6 +13,8 @@
 #include <linux/security.h>
 #include <linux/module.h>
 #include <linux/uaccess.h>
+#include <linux/writeback.h>
+#include <linux/buffer_head.h>
 
 #include <asm/ioctls.h>
 
@@ -227,6 +229,123 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)
 	return error;
 }
 
+#define blk_to_logical(inode, blk) (blk << (inode)->i_blkbits)
+#define logical_to_blk(inode, offset) (offset >> (inode)->i_blkbits);
+
+/*
+ * @inode - the inode to map
+ * @arg - the pointer to userspace where we copy everything to
+ * @get_block - the fs's get_block function
+ *
+ * This does FIEMAP for block based inodes.  Basically it will just loop
+ * through get_block until we hit the number of extents we want to map, or we
+ * go past the end of the file and hit a hole.
+ *
+ * If it is possible to have data blocks beyond a hole past @inode->i_size, then
+ * please do not use this function, it will stop at the first unmapped block
+ * beyond i_size
+ */
+int generic_block_fiemap(struct inode *inode,
+			 struct fiemap_extent_info *fieinfo, u64 start,
+			 u64 len, get_block_t *get_block)
+{
+	struct buffer_head tmp;
+	unsigned int start_blk;
+	long long length = 0, map_len = 0;
+	u64 logical = 0, phys = 0, size = 0;
+	u32 flags = FIEMAP_EXTENT_MERGED;
+	int ret = 0;
+	dev_t dev = inode->i_sb->s_dev;
+
+	if ((ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC)))
+		return ret;
+
+	start_blk = logical_to_blk(inode, start);
+
+	/* guard against change */
+	mutex_lock(&inode->i_mutex);
+
+	length = (long long)min_t(u64, len, i_size_read(inode));
+	map_len = length;
+
+	do {
+		/*
+		 * we set b_size to the total size we want so it will map as
+		 * many contiguous blocks as possible at once
+		 */
+		memset(&tmp, 0, sizeof(struct buffer_head));
+		tmp.b_size = map_len;
+
+		ret = get_block(inode, start_blk, &tmp, 0);
+		if (ret)
+			break;
+
+		/* HOLE */
+		if (!buffer_mapped(&tmp)) {
+			/*
+			 * first hole after going past the EOF, this is our
+			 * last extent
+			 */
+			if (length <= 0) {
+				flags = FIEMAP_EXTENT_MERGED|FIEMAP_EXTENT_LAST;
+				ret = fiemap_fill_next_extent(fieinfo, logical,
+							      phys, size,
+							      flags, dev);
+				break;
+			}
+
+			length -= blk_to_logical(inode, 1);
+
+			/* if we have holes up to/past EOF then we're done */
+			if (length <= 0)
+				break;
+
+			start_blk++;
+		} else {
+			if (length <= 0 && size) {
+				ret = fiemap_fill_next_extent(fieinfo, logical,
+							      phys, size,
+							      flags, dev);
+				if (ret)
+					break;
+			}
+
+			logical = blk_to_logical(inode, start_blk);
+			phys = blk_to_logical(inode, tmp.b_blocknr);
+			size = tmp.b_size;
+			flags = FIEMAP_EXTENT_MERGED;
+
+			length -= tmp.b_size;
+			start_blk += logical_to_blk(inode, size);
+
+			/*
+			 * if we are past the EOF we need to loop again to see
+			 * if there is a hole so we can mark this extent as the
+			 * last one, and if not keep mapping things until we
+			 * find a hole, or we run out of slots in the extent
+			 * array
+			 */
+			if (length <= 0)
+				continue;
+
+			ret = fiemap_fill_next_extent(fieinfo, logical, phys,
+						      size, flags, dev);
+			if (ret)
+				break;
+		}
+		cond_resched();
+	} while (1);
+
+	mutex_unlock(&inode->i_mutex);
+
+	/* if ret is 1 then we just hit the end of the extent array */
+	if (ret == 1)
+		ret = 0;
+
+	return ret;
+}
+EXPORT_SYMBOL(generic_block_fiemap);
+
 static int file_ioctl(struct file *filp, unsigned int cmd,
 		unsigned long arg)
 {
diff --git a/include/linux/ext3_fs.h b/include/linux/ext3_fs.h
index 36c5403..2dc0dbb 100644
--- a/include/linux/ext3_fs.h
+++ b/include/linux/ext3_fs.h
@@ -836,6 +836,8 @@ extern void ext3_truncate (struct inode *);
 extern void ext3_set_inode_flags(struct inode *);
 extern void ext3_get_inode_flags(struct ext3_inode_info *);
 extern void ext3_set_aops(struct inode *inode);
+extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
+		       u64 start, u64 len);
 
 /* ioctl.c */
 extern int ext3_ioctl (struct inode *, struct file *, unsigned int,
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 2069bfc..27e7245 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1978,6 +1978,9 @@ extern int vfs_fstat(unsigned int, struct kstat *);
 
 extern int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
 		    unsigned long arg);
+extern int generic_block_fiemap(struct inode *inode,
+				struct fiemap_extent_info *fieinfo, u64 start,
+				u64 len, get_block_t *get_block);
 
 extern void get_filesystem(struct file_system_type *fs);
 extern void put_filesystem(struct file_system_type *fs);
-- 
1.5.4.1



^ permalink raw reply related	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2008-10-09 20:40 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-03 21:59 [PATCH 0/4] Updated fiemap patches Theodore Ts'o
2008-10-03 21:59 ` [PATCH 1/4] vfs: vfs-level fiemap interface Theodore Ts'o
2008-10-03 21:59   ` [PATCH 2/4] ocfs2: fiemap support Theodore Ts'o
2008-10-03 21:59     ` [PATCH 3/4] generic block based fiemap implementation Theodore Ts'o
2008-10-03 21:59       ` [PATCH 4/4] Hook ext4 to the vfs fiemap interface Theodore Ts'o
2008-10-06 11:35       ` [PATCH 3/4] generic block based fiemap implementation steve
2008-10-06 21:14         ` Theodore Tso
2008-10-07  8:14           ` steve
2008-10-04  2:12   ` [PATCH 1/4] vfs: vfs-level fiemap interface Theodore Tso
2008-10-06 18:15     ` jim owens
2008-10-06 21:07       ` Theodore Tso
2008-10-07 10:12         ` Christoph Hellwig
2008-10-07 10:56           ` Andreas Dilger
2008-10-07 12:52             ` Theodore Tso
2008-10-07 13:00           ` Jamie Lokier
2008-10-07 13:02             ` Christoph Hellwig
2008-10-07 13:24               ` Jamie Lokier
2008-10-07 13:28                 ` Christoph Hellwig
2008-10-07 15:45                   ` Theodore Tso
2008-10-07 16:01                     ` jim owens
     [not found]                       ` <48EB87DE.4090607-VXdhtT5mjnY@public.gmane.org>
2008-10-07 18:52                         ` Theodore Tso
     [not found]                           ` <20081007185219.GD15929-3s7WtUTddSA@public.gmane.org>
2008-10-07 20:31                             ` Christoph Hellwig
2008-10-07 13:48             ` Theodore Tso
2008-10-07 23:43               ` Jamie Lokier
2008-10-09 20:40                 ` Andreas Dilger
2008-10-06 13:07   ` steve
  -- strict thread matches above, loose matches on Subject: below --
2008-10-09  1:48 PATCH [0/4] Updated**3 fiemap patches Theodore Ts'o
2008-10-09  1:48 ` [PATCH 1/4] vfs: vfs-level fiemap interface Theodore Ts'o
2008-10-09  1:48   ` [PATCH 2/4] ocfs2: fiemap support Theodore Ts'o
2008-10-09  1:48     ` [PATCH 3/4] generic block based fiemap implementation Theodore Ts'o
2008-10-07  1:06 PATCH [0/4] Updated**2 fiemap patches Theodore Ts'o
2008-10-07  1:06 ` [PATCH 1/4] vfs: vfs-level fiemap interface Theodore Ts'o
2008-10-07  1:06   ` [PATCH 2/4] ocfs2: fiemap support Theodore Ts'o
2008-10-07  1:06     ` [PATCH 3/4] generic block based fiemap implementation Theodore Ts'o
2008-09-13 18:47 YET ANOTHER resend of the fiemap patches Theodore Ts'o
2008-09-13 18:49 ` [PATCH 1/4] vfs: vfs-level fiemap interface Theodore Ts'o
2008-09-13 18:49   ` [PATCH 2/4] ocfs2: fiemap support Theodore Ts'o
2008-09-13 18:49     ` [PATCH 3/4] generic block based fiemap implementation Theodore Ts'o
2008-06-25 22:19 Mark Fasheh

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).