GFS2: Support for FIEMAP ioctl (RFC)
Subsystems (3)
My plan is to start off my next GFS2 -nmw git tree with this patch.
This patch implements the FIEMAP ioctl for GFS2. We can use the generic code (aside from a lock order issue, solved as per Ted Tso's suggestion) for which I've introduced a new variant of the generic function. We also have one exception to deal with, namely stuffed files, so we do that "by hand", setting all the required flags.
This has been tested with a modified (I could only find an old version) of Eric's test program, and appears to work correctly.
This patch does not currently support FIEMAP of xattrs, but the plan is to add that feature at some future point.
Signed-off-by Steven Whitehouse <[email protected]>
Cc Theodore Tso <[email protected]>
Cc Eric Sandeen <[email protected]>
fs/gfs2/ops_inode.c +46 -0
@@ -19,6 +19,7 @@#include <linux/gfs2_ondisk.h> #include <linux/crc32.h> #include <linux/lm_interface.h> +#include <linux/fiemap.h> #include <asm/uaccess.h> #include "gfs2.h"
@@ -1212,6 +1213,48 @@ static int gfs2_removexattr(struct dentry *dentry, const char *name)return gfs2_ea_remove (GFS2_I (dentry->d_inode), &er); } +static int gfs2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, +u64 start,u64 len) +{ +struct gfs2_inode *ip =GFS2_I (inode); +struct gfs2_holder gh; +int ret; + + ret =fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC ); +if (ret) +return ret; + +mutex_lock (&inode->i_mutex); + + ret =gfs2_glock_nq_init (ip->i_gl,LM_ST_SHARED ,0 , &gh); +if (ret) + goto out; + +if (gfs2_is_stuffed (ip)) { +u64 phys = ip->i_no_addr << inode->i_blkbits; +u64 size =i_size_read (inode); +u32 flags =FIEMAP_EXTENT_LAST |FIEMAP_EXTENT_NOT_ALIGNED | +FIEMAP_EXTENT_DATA_INLINE ; + phys +=sizeof (struct gfs2_dinode ); + phys += start; +if (start + len > size) + len = size - start; +if (start < size) + ret =fiemap_fill_next_extent (fieinfo, start, phys, + len, flags); +if (ret ==1 ) + ret =0 ; + }else { + ret =__generic_block_fiemap (inode, fieinfo, start, len, + gfs2_block_map); + } + +gfs2_glock_dq_uninit (&gh); +out: +mutex_unlock (&inode->i_mutex); +return ret; +} +const struct inode_operations gfs2_file_iops = { .permission = gfs2_permission, .setattr = gfs2_setattr,
@@ -1220,6 +1263,7 @@ const struct inode_operations gfs2_file_iops = { .getxattr = gfs2_getxattr, .listxattr = gfs2_listxattr, .removexattr = gfs2_removexattr, + .fiemap = gfs2_fiemap, };const struct inode_operations gfs2_dir_iops = {
@@ -1239,6 +1283,7 @@ const struct inode_operations gfs2_dir_iops = { .getxattr = gfs2_getxattr, .listxattr = gfs2_listxattr, .removexattr = gfs2_removexattr, + .fiemap = gfs2_fiemap, };const struct inode_operations gfs2_symlink_iops = {
@@ -1251,5 +1296,6 @@ const struct inode_operations gfs2_symlink_iops = { .getxattr = gfs2_getxattr, .listxattr = gfs2_listxattr, .removexattr = gfs2_removexattr, + .fiemap = gfs2_fiemap, };
fs/ioctl.c +34 -10
75 lines not on this page · raw message
include/linux/fs.h +3 -0
@@ -2005,6 +2005,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 int generic_block_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 start,u64 len,get_block_t *get_block);