Skip to contentSkip to conversation

Updated fiemap patches

PATCH In review Theodore Ts'o 8 participants 26 messages Oct 3, 2008 – Oct 9, 2008 2 messages not in the archive

Subsystems (7)
lore
Share & tools
lore
author maintainer
#2 lore raw

PATCH 2/4 ocfs2: fiemap support

In reply to Theodore Ts'o

From: Mark Fasheh <[email protected]>

Plug ocfs2 into ->fiemap. Some portions of ocfs2_get_clusters() had to be refactored so that the extent cache can be skipped in favor of going directly to the on-disk records. This makes it easier for us to determine which extent is the last one in the btree. Also, I'm not sure we want to be caching fiemap lookups anyway as they're not directly related to data read/write.

Cc ocfs2-devel at oss.oracle.com
Cc linux-fsdevel at vger.kernel.org
---
 fs/ocfs2/alloc.c      |    9 --
 fs/ocfs2/alloc.h      |    9 ++
 fs/ocfs2/extent_map.c |  346 +++++++++++++++++++++++++++++++++++++++++--------
 fs/ocfs2/extent_map.h |    3 +
 fs/ocfs2/file.c       |    1 +
 5 files changed, 306 insertions(+), 62 deletions(-)
fs/ocfs2/alloc.c +0 -9
index 10bfb46..29ff57e 100644
@@ -990,15 +990,6 @@ out:
 }
 
 /*
- * This is only valid for leaf nodes, which are the only ones that can
- * have empty extents anyway.
- */
-static inline int ocfs2_is_empty_extent(struct ocfs2_extent_rec *rec)
-{
-	return !rec->e_leaf_clusters;
-}
-
-/*
  * This function will discard the rightmost extent record.
  */
 static void ocfs2_shift_records_right(struct ocfs2_extent_list *el)
fs/ocfs2/alloc.h +9 -0
index 42ff94b..60cd3d5 100644
@@ -146,4 +146,13 @@ static inline unsigned int ocfs2_rec_clusters(struct ocfs2_extent_list *el,
 		return le16_to_cpu(rec->e_leaf_clusters);
 }
 
+/*
+ * This is only valid for leaf nodes, which are the only ones that can
+ * have empty extents anyway.
+ */
+static inline int ocfs2_is_empty_extent(struct ocfs2_extent_rec *rec)
+{
+	return !rec->e_leaf_clusters;
+}
+
 #endif /* OCFS2_ALLOC_H */
fs/ocfs2/extent_map.c +293 -53

409 lines not on this page · raw message

fs/ocfs2/extent_map.h +3 -0
index de91e3e..1b97490 100644
@@ -50,4 +50,7 @@ int ocfs2_get_clusters(struct inode *inode, u32 v_cluster, u32 *p_cluster,
 int ocfs2_extent_map_get_blocks(struct inode *inode, u64 v_blkno, u64 *p_blkno,
 				u64 *ret_count, unsigned int *extent_flags);
 
+int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
+		 u64 map_start, u64 map_len);
+
 #endif  /* _EXTENT_MAP_H */
fs/ocfs2/file.c +1 -0
index ec2ed15..ed38796 100644
@@ -2228,6 +2228,7 @@ const struct inode_operations ocfs2_file_iops = {
 	.getattr	= ocfs2_getattr,
 	.permission	= ocfs2_permission,
 	.fallocate	= ocfs2_fallocate,
+	.fiemap		= ocfs2_fiemap,
 };
 
 const struct inode_operations ocfs2_special_file_iops = {
Signature · 1 line
1.5.6.1.205.ge2c7.dirty
author maintainer
#4 lore raw

PATCH 4/4 Hook ext4 to the vfs fiemap interface.

In reply to Theodore Ts'o

From: Eric Sandeen <[email protected]>

ext4_ext_walk_space() was reinstated to be used for iterating over file extents with a callback; it is used by the ext4 fiemap implementation.

---
 fs/ext4/ext4.h         |    2 +
 fs/ext4/ext4_extents.h |   15 +++
 fs/ext4/extents.c      |  248 ++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ext4/file.c         |    4 +
 4 files changed, 269 insertions(+), 0 deletions(-)
fs/ext4/ext4.h +2 -0
index 6db6857..caaca1b 100644
@@ -1083,6 +1083,8 @@ struct buffer_head *ext4_getblk(handle_t *, struct inode *,
 						ext4_lblk_t, int, int *);
 struct buffer_head *ext4_bread(handle_t *, struct inode *,
 						ext4_lblk_t, int, int *);
+int ext4_get_block(struct inode *inode, sector_t iblock,
+				struct buffer_head *bh_result, int create);
 int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
 				ext4_lblk_t iblock, unsigned long maxblocks,
 				struct buffer_head *bh_result,
fs/ext4/ext4_extents.h +15 -0
index 2fc0469..6407222 100644
@@ -124,6 +124,19 @@ struct ext4_ext_path {
 #define EXT4_EXT_CACHE_GAP	1
 #define EXT4_EXT_CACHE_EXTENT	2
 
+/*
+ * to be called by ext4_ext_walk_space()
+ * negative retcode - error
+ * positive retcode - signal for ext4_ext_walk_space(), see below
+ * callback must return valid extent (passed or newly created)
+ */
+typedef int (*ext_prepare_callback)(struct inode *, struct ext4_ext_path *,
+					struct ext4_ext_cache *,
+					struct ext4_extent *, void *);
+
+#define EXT_CONTINUE   0
+#define EXT_BREAK      1
+#define EXT_REPEAT     2
 
 #define EXT_MAX_BLOCK	0xffffffff
 
@@ -224,6 +237,8 @@ extern int ext4_ext_try_to_merge(struct inode *inode,
 				 struct ext4_extent *);
 extern unsigned int ext4_ext_check_overlap(struct inode *, struct ext4_extent *, struct ext4_ext_path *);
 extern int ext4_ext_insert_extent(handle_t *, struct inode *, struct ext4_ext_path *, struct ext4_extent *);
+extern int ext4_ext_walk_space(struct inode *, ext4_lblk_t, ext4_lblk_t,
+							ext_prepare_callback, void *);
 extern struct ext4_ext_path *ext4_ext_find_extent(struct inode *, ext4_lblk_t,
 							struct ext4_ext_path *);
 extern int ext4_ext_search_left(struct inode *, struct ext4_ext_path *,
fs/ext4/extents.c +248 -0

263 lines not on this page · raw message

fs/ext4/file.c +4 -0
index 62796b7..6d5be15 100644
@@ -140,6 +140,9 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
 	return 0;
 }
 
+extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
+		__u64 start, __u64 len);
+
 const struct file_operations ext4_file_operations = {
 	.llseek		= generic_file_llseek,
 	.read		= do_sync_read,
@@ -170,5 +173,6 @@ const struct inode_operations ext4_file_inode_operations = {
 #endif
 	.permission	= ext4_permission,
 	.fallocate	= ext4_fallocate,
+	.fiemap		= ext4_fiemap,
 };
 
Signature · 1 line
1.5.6.1.205.ge2c7.dirty

Theodore Ts'o

author maintainer
#0 lore raw

cover Updated fiemap patches

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

author maintainer
#3 lore raw

PATCH 3/4 generic block based fiemap implementation

In reply to Theodore Ts'o

From: Josef Bacik <[email protected]>

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.

---
 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              |  118 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/ext3_fs.h |    2 +
 include/linux/fs.h      |    3 +
 8 files changed, 143 insertions(+), 0 deletions(-)
fs/ext2/ext2.h +2 -0
index 47d88da..bae998c 100644
@@ -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);
fs/ext2/file.c +1 -0
index 5f2fa9c..45ed071 100644
@@ -86,4 +86,5 @@ const struct inode_operations ext2_file_inode_operations = {
 #endif
 	.setattr	= ext2_setattr,
 	.permission	= ext2_permission,
+	.fiemap		= ext2_fiemap,
 };
fs/ext2/inode.c +8 -0
index 991d6df..7658b33 100644
@@ -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);
fs/ext3/file.c +1 -0
index acc4913..3be1e06 100644
@@ -134,5 +134,6 @@ const struct inode_operations ext3_file_inode_operations = {
 	.removexattr	= generic_removexattr,
 #endif
 	.permission	= ext3_permission,
+	.fiemap		= ext3_fiemap,
 };
 
fs/ext3/inode.c +8 -0
index 507d868..ebfec4d 100644
@@ -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
  */
fs/ioctl.c +118 -0

130 lines not on this page · raw message

include/linux/ext3_fs.h +2 -0
index 80171ee..8120fa1 100644
@@ -837,6 +837,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,
include/linux/fs.h +3 -0
index 0724abf..6242491 100644
@@ -1999,6 +1999,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);
Signature · 1 line
1.5.6.1.205.ge2c7.dirty
author maintainer
#1 lore raw

PATCH 1/4 vfs: vfs-level fiemap interface

In reply to Theodore Ts'o

From: Mark Fasheh <[email protected]>

Basic vfs-level fiemap infrastructure, which sets up a new ->fiemap inode operation.

Userspace can get extent information on a file via fiemap ioctl. As input, the fiemap ioctl takes a struct fiemap which includes an array of struct fiemap_extent (fm_extents). Size of the extent array is passed as fm_extent_count and number of extents returned will be written into fm_mapped_extents. Offset and length fields on the fiemap structure (fm_start, fm_length) describe a logical range which will be searched for extents. All extents returned will at least partially contain this range. The actual extent offsets and ranges returned will be unmodified from their offset and range on-disk.

The fiemap ioctl returns '0' on success. On error, -1 is returned and errno is set. If errno is equal to EBADR, then fm_flags will contain those flags which were passed in which the kernel did not understand. On all other errors, the contents of fm_extents is undefined.

As fiemap evolved, there have been many authors of the vfs patch. As far as I can tell, the list includes:
Kalpak Shah <[email protected]>
Andreas Dilger <[email protected]>
Eric Sandeen <[email protected]>
Mark Fasheh <[email protected]>

---
 Documentation/filesystems/fiemap.txt |  221 ++++++++++++++++++++++++++++++++++
 fs/ioctl.c                           |  155 ++++++++++++++++++++++++
 include/linux/fiemap.h               |   64 ++++++++++
 include/linux/fs.h                   |   18 +++
 4 files changed, 458 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/filesystems/fiemap.txt
 create mode 100644 include/linux/fiemap.h
Documentation/filesystems/fiemap.txt new file +221 -0
new file mode 100644
index 0000000..0945d96
@@ -0,0 +1,221 @@
+============
+Fiemap Ioctl
+============
+
+The fiemap ioctl is an efficient method for userspace to get file
+extent mappings. Instead of block-by-block mapping (such as bmap), fiemap
+returns a list of extents.
+
+
+Request Basics
+--------------
+
+A fiemap request is encoded within struct fiemap:
+
+struct fiemap {
+	__u64	fm_start;	 /* logical offset (inclusive) at
+				  * which to start mapping (in) */
+	__u64	fm_length;	 /* logical length of mapping which
+				  * userspace cares about (in) */
+	__u32	fm_flags;	 /* FIEMAP_FLAG_* flags for request (in/out) */
+	__u32	fm_mapped_extents; /* number of extents that were
+				    * mapped (out) */
+	__u32	fm_extent_count; /* size of fm_extents array (in) */
+	__u32	fm_reserved;
+	struct fiemap_extent fm_extents[0]; /* array of mapped extents (out) */
+};
+
+
+fm_start, and fm_length specify the logical range within the file
+which the process would like mappings for. Extents returned mirror
+those on disk - that is, the logical offset of the 1st returned extent
+may start before fm_start, and the range covered by the last returned
+extent may end after fm_length. All offsets and lengths are in bytes.
+
+Certain flags to modify the way in which mappings are looked up can be
+set in fm_flags. If the kernel doesn't understand some particular
+flags, it will return EBADR and the contents of fm_flags will contain
+the set of flags which caused the error. If the kernel is compatible
+with all flags passed, the contents of fm_flags will be unmodified.
+It is up to userspace to determine whether rejection of a particular
+flag is fatal to it's operation. This scheme is intended to allow the
+fiemap interface to grow in the future but without losing
+compatibility with old software.
+
+fm_extent_count specifies the number of elements in the fm_extents[] array
+that can be used to return extents.  If fm_extent_count is zero, then the
+fm_extents[] array is ignored (no extents will be returned), and the
+fm_mapped_extents count will hold the number of extents needed in
+fm_extents[] to hold the file's current mapping.  Note that there is
+nothing to prevent the file from changing between calls to FIEMAP.
+
+Currently, there are three flags which can be set in fm_flags:
+
+* FIEMAP_FLAG_SYNC
+If this flag is set, the kernel will sync the file before mapping extents.
+
+* FIEMAP_FLAG_XATTR
+If this flag is set, the extents returned will describe the inodes
+extended attribute lookup tree, instead of it's data tree.
+
+
+Extent Mapping
+--------------
+
+Extent information is returned within the embedded fm_extents array
+which userspace must allocate along with the fiemap structure. The
+number of elements in the fiemap_extents[] array should be passed via
+fm_extent_count. The number of extents mapped by kernel will be
+returned via fm_mapped_extents. If the number of fiemap_extents
+allocated is less than would be required to map the requested range,
+the maximum number of extents that can be mapped in the fm_extent[]
+array will be returned and fm_mapped_extents will be equal to
+fm_extent_count. In that case, the last extent in the array will not
+complete the requested range and will not have the FIEMAP_EXTENT_LAST
+flag set (see the next section on extent flags).
+
+Each extent is described by a single fiemap_extent structure as
+returned in fm_extents.
+
+struct fiemap_extent {
+	__u64	fe_logical;  /* logical offset in bytes for the start of
+			      * the extent */
+	__u64	fe_physical; /* physical offset in bytes for the start
+			      * of the extent */
+	__u64	fe_length;   /* length in bytes for the extent */
+	__u64	fe_reserved64[2];
+	__u32	fe_flags;    /* FIEMAP_EXTENT_* flags for this extent */
+	__u32	fe_reserved[3];
+};
+
+All offsets and lengths are in bytes and mirror those on disk.  It is valid
+for an extents logical offset to start before the request or it's logical
+length to extend past the request.  Unless FIEMAP_EXTENT_NOT_ALIGNED is
+returned, fe_logical, fe_physical, and fe_length will be aligned to the
+block size of the file system.  With the exception of extents flagged as
+FIEMAP_EXTENT_MERGED, adjacent extents will not be merged.
+
+The fe_flags field contains flags which describe the extent returned.
+A special flag, FIEMAP_EXTENT_LAST is always set on the last extent in
+the file so that the process making fiemap calls can determine when no
+more extents are available, without having to call the ioctl again.
+
+Some flags are intentionally vague and will always be set in the
+presence of other more specific flags. This way a program looking for
+a general property does not have to know all existing and future flags
+which imply that property.
+
+For example, if FIEMAP_EXTENT_DATA_INLINE or FIEMAP_EXTENT_DATA_TAIL
+are set, FIEMAP_EXTENT_NOT_ALIGNED will also be set. A program looking
+for inline or tail-packed data can key on the specific flag. Software
+which simply cares not to try operating on non-aligned extents
+however, can just key on FIEMAP_EXTENT_NOT_ALIGNED, and not have to
+worry about all present and future flags which might imply unaligned
+data. Note that the opposite is not true - it would be valid for
+FIEMAP_EXTENT_NOT_ALIGNED to appear alone.
+
+* FIEMAP_EXTENT_LAST
+This is the last extent in the file. A mapping attempt past this
+extent will return nothing.
+
+* FIEMAP_EXTENT_UNKNOWN
+The location of this extent is currently unknown. This may indicate
+the data is stored on an inaccessible volume or that no storage has
+been allocated for the file yet.
+
+* FIEMAP_EXTENT_DELALLOC
+  - This will also set FIEMAP_EXTENT_UNKNOWN.
+Delayed allocation - while there is data for this extent, it's
+physical location has not been allocated yet.
+
+* FIEMAP_EXTENT_NO_MOUNTED_IO
+Accessing the data in this extent via I/O to the block device while the
+filesystem is unmounted is illegal or will have undefined results.  This
+may because the data is somehow encrypted or compressed by the filesystem.
+Note that accessing the data using the information returned by the
+FIEMAP interface is *always* undefined should not be attempted by user
+applications. 
+
+* FIEMAP_EXTENT_DATA_ENCRYPTED
+  - This will also set FIEMAP_EXTENT_NO_MOUNTED_IO
+The data in this extent has been encrypted by the file system.
+
+* FIEMAP_EXTENT_NOT_ALIGNED
+Extent offsets and length are not guaranteed to be block aligned.
+
+* FIEMAP_EXTENT_DATA_INLINE
+  This will also set FIEMAP_EXTENT_NOT_ALIGNED
+Data is located within a meta data block.
+
+* FIEMAP_EXTENT_DATA_TAIL
+  This will also set FIEMAP_EXTENT_NOT_ALIGNED
+Data is packed into a block with data from other files.
+
+* FIEMAP_EXTENT_UNWRITTEN
+Unwritten extent - the extent is allocated but it's data has not been
+initialized.  This indicates the extent's data will be all zero if read
+through the filesystem but the contents are undefined if read directly from
+the device.
+
+* FIEMAP_EXTENT_MERGED
+This will be set when a file does not support extents, i.e., it uses a block
+based addressing scheme.  Since returning an extent for each block back to
+userspace would be highly inefficient, the kernel will try to merge most
+adjacent blocks into 'extents'.
+
+
+VFS -> File System Implementation
+---------------------------------
+
+File systems wishing to support fiemap must implement a ->fiemap callback on
+their inode_operations structure. The fs ->fiemap call is responsible for
+defining it's set of supported fiemap flags, and calling a helper function on
+each discovered extent:
+
+struct inode_operations {
+       ...
+
+       int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
+                     u64 len);
+
+->fiemap is passed struct fiemap_extent_info which describes the
+fiemap request:
+
+struct fiemap_extent_info {
+	unsigned int fi_flags;		/* Flags as passed from user */
+	unsigned int fi_extents_mapped;	/* Number of mapped extents */
+	unsigned int fi_extents_max;	/* Size of fiemap_extent array */
+	struct fiemap_extent *fi_extents_start;	/* Start of fiemap_extent array */
+};
+
+It is intended that the file system should not need to access any of this
+structure directly.
+
+
+Flag checking should be done at the beginning of the ->fiemap callback via the
+fiemap_check_flags() helper:
+
+int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags);
+
+The struct fieinfo should be passed in as recieved from ioctl_fiemap(). The
+set of fiemap flags which the fs understands should be passed via fs_flags. If
+fiemap_check_flags finds invalid user flags, it will place the bad values in
+fieinfo->fi_flags and return -EBADR. If the file system gets -EBADR, from
+fiemap_check_flags(), it should immediately exit, returning that error back to
+ioctl_fiemap().
+
+
+For each extent in the request range, the file system should call
+the helper function, fiemap_fill_next_extent():
+
+int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
+			    u64 phys, u64 len, u32 flags, u32 dev);
+
+fiemap_fill_next_extent() will use the passed values to populate the
+next free extent in the fm_extents array. 'General' extent flags will
+automatically be set from specific flags on behalf of the calling file
+system so that the userspace API is not broken.
+
+fiemap_fill_next_extent() returns 0 on success, and 1 when the
+user-supplied fm_extents array is full. If an error is encountered
+while copying the extent to user memory, -EFAULT will be returned.
fs/ioctl.c +155 -0

173 lines not on this page · raw message

include/linux/fiemap.h new file +64 -0

64 lines not on this page · raw message

include/linux/fs.h +18 -0
index ae0ab82..0724abf 100644
@@ -232,6 +232,7 @@ extern int dir_notify_enable;
 #define	FS_IOC_SETFLAGS			_IOW('f', 2, long)
 #define	FS_IOC_GETVERSION		_IOR('v', 1, long)
 #define	FS_IOC_SETVERSION		_IOW('v', 2, long)
+#define FS_IOC_FIEMAP			_IOWR('f', 11, struct fiemap)
 #define FS_IOC32_GETFLAGS		_IOR('f', 1, int)
 #define FS_IOC32_SETFLAGS		_IOW('f', 2, int)
 #define FS_IOC32_GETVERSION		_IOR('v', 1, int)
@@ -292,6 +293,7 @@ extern int dir_notify_enable;
 #include <linux/mutex.h>
 #include <linux/capability.h>
 #include <linux/semaphore.h>
+#include <linux/fiemap.h>
 
 #include <asm/atomic.h>
 #include <asm/byteorder.h>
@@ -1180,6 +1182,20 @@ extern void dentry_unhash(struct dentry *dentry);
 extern int file_permission(struct file *, int);
 
 /*
+ * VFS FS_IOC_FIEMAP helper definitions.
+ */
+struct fiemap_extent_info {
+	unsigned int fi_flags;		/* Flags as passed from user */
+	unsigned int fi_extents_mapped;	/* Number of mapped extents */
+	unsigned int fi_extents_max;	/* Size of fiemap_extent array */
+	struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
+						 * array */
+};
+int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
+			    u64 phys, u64 len, u32 flags);
+int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags);
+
+/*
  * File types
  *
  * NOTE! These match bits 12..15 of stat.st_mode
@@ -1288,6 +1304,8 @@ struct inode_operations {
 	void (*truncate_range)(struct inode *, loff_t, loff_t);
 	long (*fallocate)(struct inode *inode, int mode, loff_t offset,
 			  loff_t len);
+	int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
+		      u64 len);
 };
 
 struct seq_file;
Signature · 1 line
1.5.6.1.205.ge2c7.dirty
author maintainer
#8 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

Whoops, sorry, the version of the patch I sent out earlier had a typo:

ioctl.c renamed from linux-2.6/fs/ioctl.c +1 -1
@@ -116,7 +116,7 @@
   if (flags & SET_NOT_ALIGNED_FLAGS)
      flags |= FIEMAP_EXTENT_NOT_ALIGNED;
 
-	memset(extent, 0, sizeof(extent));
+	memset(&extent, 0, sizeof(extent));
 	extent.fe_logical = logical;
 	extent.fe_physical = phys;
 	extent.fe_length = len;

- Ted

vfs: vfs-level fiemap interface

From: Mark Fasheh <[email protected]>

Basic vfs-level fiemap infrastructure, which sets up a new ->fiemap inode operation.

Userspace can get extent information on a file via fiemap ioctl. As input, the fiemap ioctl takes a struct fiemap which includes an array of struct fiemap_extent (fm_extents). Size of the extent array is passed as fm_extent_count and number of extents returned will be written into fm_mapped_extents. Offset and length fields on the fiemap structure (fm_start, fm_length) describe a logical range which will be searched for extents. All extents returned will at least partially contain this range. The actual extent offsets and ranges returned will be unmodified from their offset and range on-disk.

The fiemap ioctl returns '0' on success. On error, -1 is returned and errno is set. If errno is equal to EBADR, then fm_flags will contain those flags which were passed in which the kernel did not understand. On all other errors, the contents of fm_extents is undefined.

As fiemap evolved, there have been many authors of the vfs patch. As far as I can tell, the list includes:
Kalpak Shah <[email protected]>
Andreas Dilger <[email protected]>
Eric Sandeen <[email protected]>
Mark Fasheh <[email protected]>

Documentation/filesystems/fiemap.txt new file +221 -0

221 lines not on this page · raw message

fs/ioctl.c +155 -0

173 lines not on this page · raw message

include/linux/fiemap.h new file +64 -0

64 lines not on this page · raw message

include/linux/fs.h +18 -0
index ae0ab82..0724abf 100644
@@ -232,6 +232,7 @@ extern int dir_notify_enable;
 #define	FS_IOC_SETFLAGS			_IOW('f', 2, long)
 #define	FS_IOC_GETVERSION		_IOR('v', 1, long)
 #define	FS_IOC_SETVERSION		_IOW('v', 2, long)
+#define FS_IOC_FIEMAP			_IOWR('f', 11, struct fiemap)
 #define FS_IOC32_GETFLAGS		_IOR('f', 1, int)
 #define FS_IOC32_SETFLAGS		_IOW('f', 2, int)
 #define FS_IOC32_GETVERSION		_IOR('v', 1, int)
@@ -292,6 +293,7 @@ extern int dir_notify_enable;
 #include <linux/mutex.h>
 #include <linux/capability.h>
 #include <linux/semaphore.h>
+#include <linux/fiemap.h>
 
 #include <asm/atomic.h>
 #include <asm/byteorder.h>
@@ -1180,6 +1182,20 @@ extern void dentry_unhash(struct dentry *dentry);
 extern int file_permission(struct file *, int);
 
 /*
+ * VFS FS_IOC_FIEMAP helper definitions.
+ */
+struct fiemap_extent_info {
+	unsigned int fi_flags;		/* Flags as passed from user */
+	unsigned int fi_extents_mapped;	/* Number of mapped extents */
+	unsigned int fi_extents_max;	/* Size of fiemap_extent array */
+	struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
+						 * array */
+};
+int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
+			    u64 phys, u64 len, u32 flags);
+int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags);
+
+/*
  * File types
  *
  * NOTE! These match bits 12..15 of stat.st_mode
@@ -1288,6 +1304,8 @@ struct inode_operations {
 	void (*truncate_range)(struct inode *, loff_t, loff_t);
 	long (*fallocate)(struct inode *inode, int mode, loff_t offset,
 			  loff_t len);
+	int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
+		      u64 len);
 };
 
 struct seq_file;
#5 lore raw

Re: [PATCH 3/4] generic block based fiemap implementation

In reply to Theodore Ts'o

Hi,

Quoted 13 lines · Theodore Ts'o

From: Josef Bacik <[email protected]>

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.

Quoted 4 lines

Would it be possible to move the inode mutex out of generic_block_fiemap() and into the callers? The defined lock ordering in GFS2 is inode mutex -> inode glock, and thus we want to be able to lock in that order. We should be able to use generic_block_fiemap() for GFS2 in that case. Thanks,

Steve.

#27 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

In reply to Theodore Ts'o

Hi,

Quoted 5 lines · Theodore Ts'o

From: Mark Fasheh <[email protected]>

Basic vfs-level fiemap infrastructure, which sets up a new ->fiemap inode operation.

[snip]

Quoted 31 lines
fs/ioctl.c +31 -0
+/**
+ * fiemap_fill_next_extent - Fiemap helper function
+ * @fieinfo:	Fiemap context passed into ->fiemap
+ * @logical:	Extent logical start offset, in bytes
+ * @phys:	Extent physical start offset, in bytes
+ * @len:	Extent length, in bytes
+ * @flags:	FIEMAP_EXTENT flags that describe this extent
+ *
+ * Called from file system ->fiemap callback. Will populate extent
+ * info as passed in via arguments and copy to user memory. On
+ * success, extent count on fieinfo is incremented.
+ *
+ * Returns 0 on success, -errno on error, 1 if this was the last
+ * extent that will fit in user array.
+ */
+#define SET_UNKNOWN_FLAGS	(FIEMAP_EXTENT_DELALLOC)
+#define SET_NO_MOUNTED_IO_FLAGS	(FIEMAP_EXTENT_DATA_ENCRYPTED)
+#define SET_NOT_ALIGNED_FLAGS	(FIEMAP_EXTENT_DATA_TAIL|FIEMAP_EXTENT_DATA_INLINE)
+int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical,
+			    u64 phys, u64 len, u32 flags)
+{
+	struct fiemap_extent extent;
+	struct fiemap_extent *dest = fieinfo->fi_extents_start;
+
+	/* only count the extents */
+	if (fieinfo->fi_extents_max == 0) {
+		fieinfo->fi_extents_mapped++;
+		return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0;
+	}
+
+	if (fieinfo->fi_extents_mapped >= fieinfo->fi_extents_max)

fs/ioctl.c static int ioctl_fibmap(struct file *filp, int __user *p) · line 117

Quoted 10 lines
fs/ioctl.c +10 -0
+		return 1;
+
+	if (flags & SET_UNKNOWN_FLAGS)
+		flags |= FIEMAP_EXTENT_UNKNOWN;
+	if (flags & SET_NO_MOUNTED_IO_FLAGS)
+		flags |= FIEMAP_EXTENT_NO_MOUNTED_IO;
+	if (flags & SET_NOT_ALIGNED_FLAGS)
+		flags |= FIEMAP_EXTENT_NOT_ALIGNED;
+
+	memset(extent, 0, sizeof(extent));

The above ^^^^^^ fails to compile due to a missing &

Steve.

#9 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

In reply to Theodore Tso

A couple of old documentation nits that were to be fixed:

Documentation/filesystems/fiemap.txt line 52

Quoted 4 lines
Documentation/filesystems/fiemap.txt new file +4 -0
+fm_extents[] to hold the file's current mapping.  Note that there is
+nothing to prevent the file from changing between calls to FIEMAP.
+
+Currently, there are three flags which can be set in fm_flags:

Current flags which can be set in fm_flags:

Documentation/filesystems/fiemap.txt line 59

Quoted 7 lines
Documentation/filesystems/fiemap.txt new file +7 -0
+
+* FIEMAP_FLAG_SYNC
+If this flag is set, the kernel will sync the file before mapping extents.
+
+* FIEMAP_FLAG_XATTR
+If this flag is set, the extents returned will describe the inodes
+extended attribute lookup tree, instead of it's data tree.

extended attributes, otherwise the extents describe the file data.

-----------------------------------------------
And a documentation issue with this new change:

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+* FIEMAP_EXTENT_NO_MOUNTED_IO

Did you really intend to name it FIEMAP_EXTENT_NO_MOUNTED_IO or did you intend it to be FIEMAP_EXTENT_NO_UNMOUNTED_IO ?

Documentation/filesystems/fiemap.txt line 134

Quoted 3 lines
Documentation/filesystems/fiemap.txt new file +3 -0
+Accessing the data in this extent via I/O to the block device while the
+filesystem is unmounted is illegal or will have undefined results.  This
+may because the data is somehow encrypted or compressed by the filesystem.

may be because the data is somehow encrypted or compressed by the filesystem.

Documentation/filesystems/fiemap.txt line 137

Quoted 3 lines
Documentation/filesystems/fiemap.txt new file +3 -0
+Note that accessing the data using the information returned by the
+FIEMAP interface is *always* undefined should not be attempted by user
+applications. 

FIEMAP interface is never guaranteed to be consistent and should not be attempted by user applications.

[ IMO - it is confusing to say "undefined" when the flag is ]
[ set and also say "undefined" when the flag is clear ]

jim

author maintainer
#10 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

Quoted 5 lines · jim owens

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+Currently, there are three flags which can be set in fm_flags:

Current flags which can be set in fm_flags:

Good catch, thanks.

Quoted 7 lines

And a documentation issue with this new change:

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+* FIEMAP_EXTENT_NO_MOUNTED_IO

Did you really intend to name it FIEMAP_EXTENT_NO_MOUNTED_IO or did you intend it to be FIEMAP_EXTENT_NO_UNMOUNTED_IO ?

The latter; thanks for catching that

Quoted 6 lines

FIEMAP interface is never guaranteed to be consistent and should not be attempted by user applications.

[ IMO - it is confusing to say "undefined" when the flag is ]
[ set and also say "undefined" when the flag is clear ]

Yeah. Is this better?

+* FIEMAP_EXTENT_NO_UNMOUNTED_IO
+Accessing the data in this extent via I/O to the block device while the +filesystem is unmounted is illegal or will have undefined results. This +may be because the data is somehow encrypted or compressed by the filesystem. +Note that accessing the data using the information returned by the +FIEMAP interface while the filesystem is mounted is *always* undefined +should not be attempted by user applications.

- Ted

author maintainer
#6 lore raw

Re: [PATCH 3/4] generic block based fiemap implementation

In reply to [email protected]
Quoted 5 lines · On Mon, Oct 06, 2008 at 12:35:06PM +0100, [email protected] wrote:

Would it be possible to move the inode mutex out of generic_block_fiemap() and into the callers? The defined lock ordering in GFS2 is inode mutex -> inode glock, and thus we want to be able to lock in that order. We should be able to use generic_block_fiemap() for GFS2 in that case.

Given that nearly all other block-based filesystems that don't use extents would need to take the mutex lock, this would be error-prone. What about introducing an _generic_block_fiemap() for use by GFS2 that doesn't the inode mutex, and changing generic_block_fiemap() to be a wrapper that calls _generic_block_fiemap() and takes the inode mutex for the convenience of most other filesystems?

This would be a very simple change to make once a patch to enable GFS2 use of the FIEMAP interface. (If we introduce _generic_block_fiemap(), it's likely to get removed by some random roving Kernel Janitor, as an exported but unused interface. :-)

It occurs to me though that this is likely not all that is needed for GFS2, though, since like Lustre, BTRFS, and ZFS, there can be multiple disks or storage devices associated with a single filesystem, correct? So we would need to add some way of identifying the disk, not just the block number; how does GFS2 identify/enumerate storage devices which are part of a particular filesystem?

- Ted

#7 lore raw

Re: [PATCH 3/4] generic block based fiemap implementation

Hi,

Quoted 7 lines · Theodore Tso
Quoted 5 lines · On Mon, Oct 06, 2008 at 12:35:06PM +0100, [email protected] wrote:

Would it be possible to move the inode mutex out of generic_block_fiemap() and into the callers? The defined lock ordering in GFS2 is inode mutex -> inode glock, and thus we want to be able to lock in that order. We should be able to use generic_block_fiemap() for GFS2 in that case.

Quoted 7 lines

Given that nearly all other block-based filesystems that don't use extents would need to take the mutex lock, this would be error-prone. What about introducing an _generic_block_fiemap() for use by GFS2 that doesn't the inode mutex, and changing generic_block_fiemap() to be a wrapper that calls _generic_block_fiemap() and takes the inode mutex for the convenience of most other filesystems?

Yes, that sounds ok to me.

Quoted 5 lines

This would be a very simple change to make once a patch to enable GFS2 use of the FIEMAP interface. (If we introduce _generic_block_fiemap(), it's likely to get removed by some random roving Kernel Janitor, as an exported but unused interface. :-)

Quoted 8 lines

It occurs to me though that this is likely not all that is needed for GFS2, though, since like Lustre, BTRFS, and ZFS, there can be multiple disks or storage devices associated with a single filesystem, correct? So we would need to add some way of identifying the disk, not just the block number; how does GFS2 identify/enumerate storage devices which are part of a particular filesystem?

- Ted

No, we don't need anything else special. So far as GFS2 is concerned it only uses a single device. If there is a requirement for anything more complicated, we leave that to lvm etc. I don't know what the requirements are for the other filesystems you mention in that area.

The original plan was, that if anything complicated was required in terms of fs layout, then we'd get mkfs to do that at fs create time based on info which it might query from the underlying device. To date though we've not implemented anything like that, so its still fairly simple,

Steve.

#11 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

In reply to Theodore Tso

Review

Quoted 7 lines · Theodore Tso
(quoted diff) +7 -0
+* FIEMAP_EXTENT_NO_UNMOUNTED_IO
+Accessing the data in this extent via I/O to the block device while the
+filesystem is unmounted is illegal or will have undefined results.  This
+may be because the data is somehow encrypted or compressed by the filesystem.
+Note that accessing the data using the information returned by the
+FIEMAP interface while the filesystem is mounted is *always* undefined
+should not be attempted by user applications. 

I think the point we're trying to get down to is that this is not just a normal block that you can access using a block number but some complicated encoding scheme. Maybe

* FIEMAP_EXTENT_ENCODED

This extent does not consistant of plain filesystem blocks but is encoded (e.g. encrypted or compressed) or shared with other data by the filesystem. Accessing the data in this extent via I/O to the block device will have undefined resuts. Note that accessing the data using the information returned by the FIEMAP interface while the filesystem is mounted is *always* undefined should not be attempted by user applications.

Except for continuous nitpicking about this flag which could be continued in mainline before a release this patch looks good to me.

#12 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

Quoted 8 lines · Christoph Hellwig
Quoted 1 line · Theodore Tso

+* FIEMAP_EXTENT_NO_UNMOUNTED_IO

I think the point we're trying to get down to is that this is not just a normal block that you can access using a block number but some complicated encoding scheme. Maybe

* FIEMAP_EXTENT_ENCODED

I like this name much better than the cumbersome double-negative "NO_UNMOUNTED_IO" that is _still_ not any more clear than the previous proposals.

Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.

author maintainer
#13 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

Quoted 8 lines · Andreas Dilger
Quoted 7 lines · Christoph Hellwig
Quoted 1 line · Theodore Tso

+* FIEMAP_EXTENT_NO_UNMOUNTED_IO

I think the point we're trying to get down to is that this is not just a normal block that you can access using a block number but some complicated encoding scheme. Maybe

Quoted 5 lines
Quoted 1 line

* FIEMAP_EXTENT_ENCODED

I like this name much better than the cumbersome double-negative "NO_UNMOUNTED_IO" that is _still_ not any more clear than the previous proposals.

Sounds like we're converging on a color for the bike shed.... any objections to this name before I spin out a new version of the patches? It's just a global search and replace, but we've done it *so* many times. :-)

- Ted

#14 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

In reply to Christoph Hellwig
Quoted 1 line · Christoph Hellwig

* FIEMAP_EXTENT_ENCODED

I like this name better, it seems clearer what it means.

Quoted 2 lines

This extent does not consistant of plain filesystem blocks but is encoded (e.g. encrypted or compressed) or shared with other data by the

                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 1 line

filesystem.

^^^^^^^^^^

Shared blocks must not be overwritten to the block device when unmounted - but they might be safe to *read*, e.g. by LILO.

Shared data is not the only situation where it's unsafe to overwrite blocks in place but they can be read: anything wich data-dependent metadata, such as checksums, data version numbers or indexing.

Thus:

FIEMAP_EXTENT_READ_ENCODED
FIEMAP_EXTENT_WRITE_ENCODED

where

   #define FIEMAP_EXTENT_ENCODED \
       (FIEMAP_EXTENT_READ_ENCODED | FIEMAP_EXTENT_WRITE_ENCODED)
Quoted 2 lines

Except for continuous nitpicking about this flag which could be continued in mainline before a release this patch looks good to me.

I agree, if there are remaining nits they can be continued in mainline.

-- Jamie

#15 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

Quoted 5 lines · Jamie Lokier
Quoted 1 line · Christoph Hellwig

* FIEMAP_EXTENT_ENCODED

I like this name better, it seems clearer what it means.

Quoted 8 lines
Quoted 2 lines

This extent does not consistant of plain filesystem blocks but is encoded (e.g. encrypted or compressed) or shared with other data by the

                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 1 line

filesystem.

^^^^^^^^^^

Shared blocks must not be overwritten to the block device when unmounted - but they might be safe to *read*, e.g. by LILO.

I guess my terminalogy wasn't clear enough. I didn't mean shared by multiple files, but different areas in one block used by different files, e.g. reiserfs tail merging or ufs fragments. These things always were a pain in the neck for lilo.

#16 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

Quoted 7 lines · Christoph Hellwig
Quoted 2 lines

Shared blocks must not be overwritten to the block device when unmounted - but they might be safe to *read*, e.g. by LILO.

I guess my terminalogy wasn't clear enough. I didn't mean shared by multiple files, but different areas in one block used by different files, e.g. reiserfs tail merging or ufs fragments. These things always were a pain in the neck for lilo.

Fair enough.

Ok, without getting in the way any more :-) it would be good to clarify in the description whether !(flags & FIEMAP_EXTENT_ENCODED) means only reading is allowed, or if it means writing over the data blocks is safe too.

Just so that filesystems will know whether to set the flag for blocks which can be read but not written. This may include tail-merged blocks.

-- Jamie

#17 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

Quoted 8 lines · Jamie Lokier

Ok, without getting in the way any more :-) it would be good to clarify in the description whether !(flags & FIEMAP_EXTENT_ENCODED) means only reading is allowed, or if it means writing over the data blocks is safe too.

Just so that filesystems will know whether to set the flag for blocks which can be read but not written. This may include tail-merged blocks.

I think writing to a filesystem without fs assistance is always a bad idea. And yes, we should add this to the description.

author maintainer
#24 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

In reply to Jamie Lokier
Quoted 10 lines · Jamie Lokier

Shared blocks must not be overwritten to the block device when unmounted - but they might be safe to *read*, e.g. by LILO.

Shared data is not the only situation where it's unsafe to overwrite blocks in place but they can be read: anything wich data-dependent metadata, such as checksums, data version numbers or indexing.

FIEMAP_EXTENT_READ_ENCODED
FIEMAP_EXTENT_WRITE_ENCODED

Um, sure, but are there potential users for FIEMAP that would want to update a file in place while the filesystem is unmounted? I've always considered the flag (despite its many names) FIEMAP_EXTENT_ENCODED as only giving permission to read from a particular block. You're correct that just because you can read from a particular block doesn't mean that can safely update it in place. But I never imagined that it would be good and useful for the FIEMAP interface to give permission to an application to be able to update a file in place while the filesystem is unmounted.

If some application which wishes to use FIEMAP really wants to know whether it's safe to write to an extent while the fs is unmounted, we can add that flag later --- but I'm not that sure we really want to go there.

Do you have a use in mind for this interface where this would be useful?

Regards,

- Ted

author maintainer
#18 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Jamie Lokier

Ok, without getting in the way any more :-) it would be good to clarify in the description whether !(flags & FIEMAP_EXTENT_ENCODED) means only reading is allowed, or if it means writing over the data blocks is safe too.

Quoted 6 lines
Quoted 3 lines

Just so that filesystems will know whether to set the flag for blocks which can be read but not written. This may include tail-merged blocks.

I think writing to a filesystem without fs assistance is always a bad idea. And yes, we should add this to the description.

Ok, how about this?

* FIEMAP_EXTENT_ENCODED

This extent does not consistant of plain filesystem blocks but is encoded (e.g. encrypted or compressed). Reading the data in this extent via I/O to the block device will have undefined resuts.

Note that it is *always* undefined to try to update the data in-place by writing to indicated location without the assistance of the filesystem, or accessing the data using the information returned by the FIEMAP interface while the filesystem is mounted. In other words, user applications may only read the extent data via I/O to the block device while the filesystem is unmounted, and then only if the FIEMAP_EXTENT_ENCODED flag is clear; user applications must not try reading or writing to the filesystem via the block device under any other circumstances.

- Ted

#19 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

Ted, I think this is a really great definition.

jim

A couple of spelling/grammar fixes below.

Quoted 3 lines · Theodore Tso

* FIEMAP_EXTENT_ENCODED

This extent does not consistant of plain filesystem blocks but is

                          ^^^^^^^^^^
Quoted 5 lines

encoded (e.g. encrypted or compressed). Reading the data in this extent via I/O to the block device will have undefined resuts.

Note that it is *always* undefined to try to update the data in-place by writing to indicated location without the assistance of

                         ^^^^^^^^^^^^ to the
Quoted 1 line

the filesystem, or accessing the data using the information

                     ^^^^^^^^^^^^ or by
Quoted 6 lines

returned by the FIEMAP interface while the filesystem is mounted. In other words, user applications may only read the extent data via I/O to the block device while the filesystem is unmounted, and then only if the FIEMAP_EXTENT_ENCODED flag is clear; user applications must not try reading or writing to the filesystem via the block device under any other circumstances.

#21 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

In reply to a message not in the archive

Right, thanks. This time in proper English. :-)

* FIEMAP_EXTENT_ENCODED

This extent does not consist of plain filesystem blocks but is encoded (e.g. encrypted or compressed). Reading the data in this extent via I/O to the block device will have undefined results.

Note that it is *always* undefined to try to update the data in-place by writing to the indicated location without the assistance of the filesystem, or to access the data using the information returned by the FIEMAP interface while the filesystem is mounted. In other words, user applications may only read the extent data via I/O to the block device while the filesystem is unmounted, and then only if the FIEMAP_EXTENT_ENCODED flag is clear; user applications must not try reading or writing to the filesystem via the block device under any other circumstances.

- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#23 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

In reply to a message not in the archive
Quoted 8 lines · Theodore Tso

Right, thanks. This time in proper English. :-)

* FIEMAP_EXTENT_ENCODED

This extent does not consist of plain filesystem blocks but is encoded (e.g. encrypted or compressed). Reading the data in this extent via I/O to the block device will have undefined results.

Quoted 9 lines

Note that it is *always* undefined to try to update the data in-place by writing to the indicated location without the assistance of the filesystem, or to access the data using the information returned by the FIEMAP interface while the filesystem is mounted. In other words, user applications may only read the extent data via I/O to the block device while the filesystem is unmounted, and then only if the FIEMAP_EXTENT_ENCODED flag is clear; user applications must not try reading or writing to the filesystem via the block device under any other circumstances.

Looks good!

--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#25 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

In reply to Theodore Tso
Quoted 7 lines · Theodore Tso
Quoted 2 lines

FIEMAP_EXTENT_READ_ENCODED
FIEMAP_EXTENT_WRITE_ENCODED

If some application which wishes to use FIEMAP really wants to know whether it's safe to write to an extent while the fs is unmounted, we can add that flag later --- but I'm not that sure we really want to go there.

I agree. If it were ever added, it would have the opposite sense to
FIEMAP_EXTENT_ENCODED: set would mean "can write". Sounds messy and suggests the sense of FIEMAP_EXTENT_ENCODED should be reversed so that _set_ means safe to read - effectively "not safe unless filesystem explicitly says it is". But it's functionally adequate, not a real bike shed colour clash :-)

Quoted 2 lines

Do you have a use in mind for this interface where this would be useful?

Barely imaginable uses: boot loader, BIOS-stage device tester or similar logging to a preallocated file, or a userspace benchmark testing direct block device access to a preallocated file.

It's not something I'm interested in, just that it's barely conceivable, and I only thought of it when Chris mentioned shared data blocks.

So no. I just wanted to clarify, because on most filesystems you _can_ write to the data blocks safely, and that's an assumption that Joe Obscure Boot Loader Hacker (who isn't familiar with modern filesystems) might be tempted by.

One more thing, then:

How can you safely use !(flags & FLAG_EXTENT_ENCODED) anyway in userspace code which is filesystem-independent? What tells you that the data isn't moved after calling FIEMAP and before unmounting, by unrelated activity on the filesystem?

So should filesystems also set FLAG_EXTENT_ENCODED if there is any chance the data will move without any explicit operation on that file, even though the data itself is stored unencoded in data blocks?

-- Jamie

#26 lore raw

Re: [PATCH 1/4] vfs: vfs-level fiemap interface

Quoted 8 lines · Jamie Lokier

How can you safely use !(flags & FLAG_EXTENT_ENCODED) anyway in userspace code which is filesystem-independent? What tells you that the data isn't moved after calling FIEMAP and before unmounting, by unrelated activity on the filesystem?

So should filesystems also set FLAG_EXTENT_ENCODED if there is any chance the data will move without any explicit operation on that file, even though the data itself is stored unencoded in data blocks?

The safest way of using !EXTENT_ENCODED is having a static snapshot of the filesystem so nothing can change. It is probably acceptably safe to do FIEMAP before and after a read and verify the file hasn't changed, but this is not completely foolproof. For some applications (e.g. dump) they don't even have this level of checking and are still valuable, so this is really an application/user decision IMHO.

The presence of EXTENT_ENCODED just means "this is never going to work".

Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.