New ->fiemap infrastructure and ->bmap removal
Subsystems (19)
v3 cover New ->fiemap infrastructure and ->bmap removal
Hi.
This is the 3rd version of the complete series with the goal to remove ->bmap interface completely, in lieu of FIEMAP.
This new version has been slightly modified in comparison with the second one, based on reviews of the second version. My apologies if I forgot to update anything based on previous discussion.
Patch 1-3 have no difference from the previous version, and Christoph's Reviewed-by has been kept.
Patch 4 is a V3 of the previous set, Containing just a small update renaming a variable.
Patches 5-6 are the same from previous version, including now Christoph's Reviewed-by tahg.
Patch 7 contains a merge of patches 7 and 8 from the previous version, a small conflict fix when rebasing on top of linux-next, and a rename of the pointer holding the fiemap callback.
Patch 8 is the biggest change in this patchset, and has been flagged as a RFC giving the fact we have not reached a decision on how the replacement of ->bmap by ->fiemap should be done. The patch description has all details.
Patch 9 is a V2 from the previous patchset, including removal of iomap unused functions.
As always, comments are much appreciated.
Cheers
Carlos Maiolino (9):
fs: Enable bmap() function to properly return errors
cachefiles: drop direct usage of ->bmap method.
ecryptfs: drop direct calls to ->bmap
fibmap: Use bmap instead of ->bmap method in ioctl_fibmap
fs: Move start and length fiemap fields into fiemap_extent_info
iomap: Remove length and start fields from iomap_fiemap
fiemap: Use a callback to fill fiemap extents
Use FIEMAP for FIBMAP calls
xfs: Get rid of ->bmap
drivers/md/md-bitmap.c | 16 ++++-- fs/bad_inode.c | 3 +- fs/btrfs/inode.c | 5 +- fs/cachefiles/rdwr.c | 27 ++++----- fs/ecryptfs/mmap.c | 16 ++---- fs/ext2/ext2.h | 3 +- fs/ext2/inode.c | 6 +- fs/ext4/ext4.h | 3 +- fs/ext4/extents.c | 15 +++-- fs/f2fs/data.c | 10 +++- fs/f2fs/f2fs.h | 3 +- fs/gfs2/inode.c | 5 +- fs/hpfs/file.c | 4 +- fs/inode.c | 106 +++++++++++++++++++++++++++++----- fs/ioctl.c | 126 ++++++++++++++++++++++++++--------------- fs/iomap.c | 40 ++----------- fs/jbd2/journal.c | 22 ++++--- fs/nilfs2/inode.c | 5 +- fs/nilfs2/nilfs.h | 3 +- fs/ocfs2/extent_map.c | 13 ++++- fs/ocfs2/extent_map.h | 3 +- fs/overlayfs/inode.c | 5 +- fs/xfs/xfs_aops.c | 24 -------- fs/xfs/xfs_iops.c | 19 ++++--- fs/xfs/xfs_trace.h | 1 - include/linux/fs.h | 33 +++++++---- include/linux/iomap.h | 2 +- mm/page_io.c | 11 ++-- 28 files changed, 309 insertions(+), 220 deletions(-)
Signature · 1 line
2.17.2
PATCH v3 1/9 fs: Enable bmap() function to properly return errors
By now, bmap() will either return the physical block number related to the requested file offset or 0 in case of error or the requested offset maps into a hole.
This patch makes the needed changes to enable bmap() to proper return errors, using the return value as an error return, and now, a pointer must be passed to bmap() to be filled with the mapped physical block.
It will change the behavior of bmap() on return:
- negative value in case of error
- zero on success or map fell into a hole
In case of a hole, the *block will be zero too
Since this is a prep patch, by now, the only error return is -EINVAL if ->bmap doesn't exist.
--- drivers/md/md-bitmap.c | 16 ++++++++++------ fs/inode.c | 30 +++++++++++++++++------------- fs/jbd2/journal.c | 22 +++++++++++++++------- include/linux/fs.h | 2 +- mm/page_io.c | 11 +++++++---- 5 files changed, 50 insertions(+), 31 deletions(-)
drivers/md/md-bitmap.c +10 -6
@@ -363,7 +363,7 @@ static int read_page(struct file *file, unsigned long index,int ret =0 ;struct inode *inode =file_inode (file);struct buffer_head *bh; -sector_t block; +sector_t block, blk_cur;pr_debug ("read bitmap file (%dB @ %llu)\n" , (int )PAGE_SIZE , (unsigned long long )index <<PAGE_SHIFT );
@@ -374,17 +374,21 @@ static int read_page(struct file *file, unsigned long index, goto out; }attach_page_buffers (page, bh); - block = index << (PAGE_SHIFT - inode->i_blkbits); + blk_cur = index << (PAGE_SHIFT - inode->i_blkbits);while (bh) { + block = blk_cur; +if (count ==0 ) bh->b_blocknr =0 ;else { - bh->b_blocknr =bmap (inode, block); -if (bh->b_blocknr ==0 ) { -/* Cannot use this file! */ + ret =bmap (inode, &block); +if (ret || !block) { ret = -EINVAL ; + bh->b_blocknr =0 ; goto out; } + + bh->b_blocknr = block; bh->b_bdev = inode->i_sb->s_bdev;if (count < (1 <<inode->i_blkbits)) count =0 ;
@@ -398,7 +402,7 @@ static int read_page(struct file *file, unsigned long index,set_buffer_mapped (bh);submit_bh (REQ_OP_READ ,0 , bh); } - block++; + blk_cur++; bh = bh->b_this_page; } page->index = index;
fs/inode.c +17 -13
@@ -1580,21 +1580,25 @@ EXPORT_SYMBOL(iput);/** * bmap - find a block number in a file -* @inode: inode of file -* @block: block to find -* -* Returns the block number on the device holding the inode that -* is the disk block number for the block of the file requested. -* That is, asked for block 4 of inode 1 the function will return the -* disk block relative to the disk start that holds that block of the -* file. +* @inode: inode owning the block number being requested +* @*block: pointer containing the block to find +* +* Replaces the value in *block with the block number on the device holding +* corresponding to the requested block number in the file. +* That is, asked for block 4 of inode 1 the function will replace the +* 4 in *block, with disk block relative to the disk start that holds that +* block of the file. +* +* Returns -EINVAL in case of error, 0 otherwise. If mapping falls into a +* hole, returns 0 and *block is also set to 0. */ -sector_t bmap (struct inode *inode,sector_t block) +int bmap (struct inode *inode,sector_t *block) { -sector_t res =0 ; -if (inode->i_mapping->a_ops->bmap) - res = inode->i_mapping->a_ops->bmap (inode->i_mapping, block); -return res; +if (!inode->i_mapping->a_ops->bmap) +return -EINVAL ; + + *block = inode->i_mapping->a_ops->bmap (inode->i_mapping, *block); +return 0 ; }EXPORT_SYMBOL (bmap);
fs/jbd2/journal.c +15 -7
@@ -814,18 +814,23 @@ int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr, {int err =0 ;unsigned long long ret; +sector_t block =0 ;if (journal->j_inode) { - ret =bmap (journal->j_inode, blocknr); -if (ret) - *retp = ret; -else { + block = blocknr; + ret =bmap (journal->j_inode, &block); + +if (ret || !block) {printk (KERN_ALERT "%s: journal block not found " "at offset %lu on %s\n" , __func__, blocknr, journal->j_devname); err = -EIO ;__journal_abort_soft (journal, err); + + }else { + *retp = block; } + }else { *retp = blocknr;/* +journal->j_blk_offset */ }
@@ -1251,11 +1256,14 @@ journal_t *jbd2_journal_init_dev(struct block_device *bdev,journal_t *jbd2_journal_init_inode (struct inode *inode) {journal_t *journal; +sector_t blocknr;char *p; -unsigned long long blocknr; +int err =0 ; + + blocknr =0 ; + err =bmap (inode, &blocknr); - blocknr =bmap (inode,0 ); -if (!blocknr) { +if (err || !blocknr) {pr_err ("%s: Cannot locate journal superblock\n" , __func__);return NULL ;
include/linux/fs.h +1 -1
@@ -2790,7 +2790,7 @@ static inline ssize_t generic_write_sync(struct kiocb *iocb, ssize_t count)extern void emergency_sync (void );extern void emergency_remount (void );#ifdef CONFIG_BLOCK -extern sector_t bmap (struct inode *,sector_t ); +extern int bmap (struct inode *,sector_t *);#endif extern int notify_change (struct dentry *,struct iattr *,struct inode **);extern int inode_permission (struct inode *,int );
mm/page_io.c +7 -4
@@ -177,8 +177,9 @@ int generic_swapfile_activate(struct swap_info_struct *sis,cond_resched (); - first_block =bmap (inode, probe_block); -if (first_block ==0 ) + first_block = probe_block; + ret =bmap (inode, &first_block); +if (ret || !first_block) goto bad_bmap;/*
@@ -193,9 +194,11 @@ int generic_swapfile_activate(struct swap_info_struct *sis, block_in_page++) {sector_t block; - block =bmap (inode, probe_block + block_in_page); -if (block ==0 ) + block = probe_block + block_in_page; + ret =bmap (inode, &block); +if (ret || !block) goto bad_bmap; +if (block != first_block + block_in_page) {/* Discontiguity */ probe_block++;
Signature · 1 line
2.17.2
PATCH v3 2/9 cachefiles: drop direct usage of ->bmap method.
In reply to Carlos MaiolinoReplace the direct usage of ->bmap method by a bmap() call.
--- fs/cachefiles/rdwr.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
fs/cachefiles/rdwr.c +14 -13
@@ -400,7 +400,7 @@ int cachefiles_read_or_alloc_page(struct fscache_retrieval *op,struct cachefiles_object *object;struct cachefiles_cache *cache;struct inode *inode; -sector_t block0, block; +sector_t block;unsigned shift;int ret;
@@ -416,7 +416,6 @@ int cachefiles_read_or_alloc_page(struct fscache_retrieval *op, inode =d_backing_inode (object->backer);ASSERT (S_ISREG (inode->i_mode)); -ASSERT (inode->i_mapping->a_ops->bmap);ASSERT (inode->i_mapping->a_ops->readpages);/* calculate the shift required to use bmap */
@@ -432,12 +431,14 @@ int cachefiles_read_or_alloc_page(struct fscache_retrieval *op,* enough for this as it doesn't indicate errors, but it's all we've * got for the moment */ - block0 = page->index; - block0 <<= shift; + block = page->index; + block <<= shift; + + ret =bmap (inode, &block); +ASSERT (!ret); - block = inode->i_mapping->a_ops->bmap (inode->i_mapping, block0);_debug ("%llx -> %llx" , - (unsigned long long ) block0, + (unsigned long long ) (page->index << shift), (unsigned long long ) block);if (block) {
@@ -715,7 +716,6 @@ int cachefiles_read_or_alloc_pages(struct fscache_retrieval *op, inode =d_backing_inode (object->backer);ASSERT (S_ISREG (inode->i_mode)); -ASSERT (inode->i_mapping->a_ops->bmap);ASSERT (inode->i_mapping->a_ops->readpages);/* calculate the shift required to use bmap */
@@ -732,7 +732,7 @@ int cachefiles_read_or_alloc_pages(struct fscache_retrieval *op, ret = space ? -ENODATA : -ENOBUFS ;list_for_each_entry_safe (page, _n, pages, lru) { -sector_t block0, block; +sector_t block;/* we assume the absence or presence of the first block is a * good enough indication for the page as a whole
@@ -740,13 +740,14 @@ int cachefiles_read_or_alloc_pages(struct fscache_retrieval *op,* good enough for this as it doesn't indicate errors, but * it's all we've got for the moment */ - block0 = page->index; - block0 <<= shift; + block = page->index; + block <<= shift; + + ret =bmap (inode, &block); +ASSERT (!ret); - block = inode->i_mapping->a_ops->bmap (inode->i_mapping, - block0);_debug ("%llx -> %llx" , - (unsigned long long ) block0, + (unsigned long long ) (page->index << shift), (unsigned long long ) block);if (block) {
Signature · 1 line
2.17.2
PATCH v3 3/9 ecryptfs: drop direct calls to ->bmap
In reply to Carlos MaiolinoReplace direct ->bmap calls by bmap() method.
--- fs/ecryptfs/mmap.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
fs/ecryptfs/mmap.c +6 -10
@@ -538,16 +538,12 @@ static int ecryptfs_write_end(struct file *file,static sector_t ecryptfs_bmap (struct address_space *mapping,sector_t block) { -int rc =0 ; -struct inode *inode; -struct inode *lower_inode; - - inode = (struct inode *)mapping->host; - lower_inode =ecryptfs_inode_to_lower (inode); -if (lower_inode->i_mapping->a_ops->bmap) - rc = lower_inode->i_mapping->a_ops->bmap (lower_inode->i_mapping, - block); -return rc; +struct inode *lower_inode =ecryptfs_inode_to_lower (mapping->host); +int ret =bmap (lower_inode, &block); + +if (ret) +return 0 ; +return block; }const struct address_space_operations ecryptfs_aops = {
Signature · 1 line
2.17.2
PATCH v3 4/9 fibmap: Use bmap instead of ->bmap method in ioctl_fibmap
In reply to Carlos MaiolinoNow we have the possibility of proper error return in bmap, use bmap() function in ioctl_fibmap() instead of calling ->bmap method directly.
V3:
- Rename usr_blk to ur_block
V2:
- Use a local sector_t variable to asign the block number instead of using direct casting.
--- fs/ioctl.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
fs/ioctl.c +17 -10
@@ -53,19 +53,26 @@ EXPORT_SYMBOL(vfs_ioctl);static int ioctl_fibmap (struct file *filp,int __user *p) { -struct address_space *mapping = filp->f_mapping; -int res, block; +struct inode *inode =file_inode (filp); +int error, ur_block; +sector_t block; -/* do we support this mess? */ -if (!mapping->a_ops->bmap) -return -EINVAL ;if (!capable (CAP_SYS_RAWIO ))return -EPERM ; - res =get_user (block, p); -if (res) -return res; - res = mapping->a_ops->bmap (mapping, block); -return put_user (res, p); + + error =get_user (ur_block, p); +if (error) +return error; + + block = ur_block; + error =bmap (inode, &block); +if (error) +return error; + ur_block = block; + + error =put_user (ur_block, p); + +return error; }/**
Signature · 1 line
2.17.2
PATCH v3 5/9 fs: Move start and length fiemap fields into fiemap_extent_info
In reply to Carlos MaiolinoAs the overall goal to deprecate fibmap, Christoph suggested a rework of the ->fiemap API, in a way we could pass to it a callback to fill the fiemap structure (one of these callbacks being fiemap_fill_next_extent).
To avoid the need to add several fields into the ->fiemap method, aggregate everything into a single data structure, and pass it along.
This patch isn't suppose to add any functional change, only to update filesystems providing ->fiemap() method.
--- fs/bad_inode.c | 3 +-- fs/btrfs/inode.c | 5 +++-- fs/ext2/ext2.h | 3 +-- fs/ext2/inode.c | 6 ++---- fs/ext4/ext4.h | 3 +-- fs/ext4/extents.c | 8 ++++---- fs/f2fs/data.c | 5 +++-- fs/f2fs/f2fs.h | 3 +-- fs/gfs2/inode.c | 5 +++-- fs/hpfs/file.c | 4 ++-- fs/ioctl.c | 16 ++++++++++------ fs/nilfs2/inode.c | 5 +++-- fs/nilfs2/nilfs.h | 3 +-- fs/ocfs2/extent_map.c | 5 +++-- fs/ocfs2/extent_map.h | 3 +-- fs/overlayfs/inode.c | 5 ++--- fs/xfs/xfs_iops.c | 10 +++++----- include/linux/fs.h | 21 +++++++++++---------- 18 files changed, 57 insertions(+), 56 deletions(-)
fs/bad_inode.c +1 -2
@@ -120,8 +120,7 @@ static struct posix_acl *bad_inode_get_acl(struct inode *inode, int type) }static int bad_inode_fiemap (struct inode *inode, -struct fiemap_extent_info *fieinfo,u64 start, -u64 len) +struct fiemap_extent_info *fieinfo) {return -EIO ; }
fs/btrfs/inode.c +3 -2
@@ -8628,9 +8628,10 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)#define BTRFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC) -static int btrfs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -__u64 start,__u64 len) +static int btrfs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) { +u64 start = fieinfo->fi_start; +u64 len = fieinfo->fi_len;int ret; ret =fiemap_check_flags (fieinfo,BTRFS_FIEMAP_FLAGS );
fs/ext2/ext2.h +1 -2
@@ -759,8 +759,7 @@ extern void ext2_evict_inode(struct inode *);extern int ext2_get_block (struct inode *,sector_t ,struct buffer_head *,int );extern int ext2_setattr (struct dentry *,struct iattr *);extern void ext2_set_inode_flags (struct inode *inode); -extern int ext2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -u64 start,u64 len); +extern int ext2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo);/* ioctl.c */ extern long ext2_ioctl (struct file *,unsigned int ,unsigned long );
fs/ext2/inode.c +2 -4
@@ -855,11 +855,9 @@ const struct iomap_ops ext2_iomap_ops = {const struct iomap_ops ext2_iomap_ops;#endif /* CONFIG_FS_DAX */ -int ext2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -u64 start,u64 len) +int ext2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) { -return generic_block_fiemap (inode, fieinfo, start, len, - ext2_get_block); +return generic_block_fiemap (inode, fieinfo, ext2_get_block); }static int ext2_writepage (struct page *page,struct writeback_control *wbc)
fs/ext4/ext4.h +1 -2
@@ -3147,8 +3147,7 @@ extern struct ext4_ext_path *ext4_find_extent(struct inode *, ext4_lblk_t,extern void ext4_ext_drop_refs (struct ext4_ext_path *);extern int ext4_ext_check_inode (struct inode *inode);extern ext4_lblk_t ext4_ext_next_allocated_block (struct ext4_ext_path *path); -extern int ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -__u64 start,__u64 len); +extern int ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo);extern int ext4_ext_precache (struct inode *inode);extern int ext4_collapse_range (struct inode *inode,loff_t offset,loff_t len);extern int ext4_insert_range (struct inode *inode,loff_t offset,loff_t len);
fs/ext4/extents.c +4 -4
@@ -5045,9 +5045,10 @@ static int ext4_xattr_fiemap(struct inode *inode,return (error <0 ? error :0 ); } -int ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -__u64 start,__u64 len) +int ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) { +u64 start = fieinfo->fi_start; +u64 len = fieinfo->fi_len;ext4_lblk_t start_blk;int error =0 ;
@@ -5069,8 +5070,7 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,/* fallback to generic here if not in extents fmt */ if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) -return generic_block_fiemap (inode, fieinfo, start, len, - ext4_get_block); +return generic_block_fiemap (inode, fieinfo, ext4_get_block);if (fiemap_check_flags (fieinfo,EXT4_FIEMAP_FLAGS ))return -EBADR ;
fs/f2fs/data.c +3 -2
@@ -1405,9 +1405,10 @@ static int f2fs_xattr_fiemap(struct inode *inode,return (err <0 ? err :0 ); } -int f2fs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -u64 start,u64 len) +int f2fs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) { +u64 start = fieinfo->fi_start; +u64 len = fieinfo->fi_len;struct buffer_head map_bh;sector_t start_blk, last_blk;pgoff_t next_pgofs;
fs/f2fs/f2fs.h +1 -2
@@ -3127,8 +3127,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio);void __do_map_lock (struct f2fs_sb_info *sbi,int flag,bool lock);int f2fs_map_blocks (struct inode *inode,struct f2fs_map_blocks *map,int create,int flag); -int f2fs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -u64 start,u64 len); +int f2fs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo);bool f2fs_should_update_inplace (struct inode *inode,struct f2fs_io_info *fio);bool f2fs_should_update_outplace (struct inode *inode,struct f2fs_io_info *fio); void f2fs_invalidate_page(struct page *page, unsigned int offset,
fs/gfs2/inode.c +3 -2
@@ -2004,9 +2004,10 @@ static int gfs2_getattr(const struct path *path, struct kstat *stat,return 0 ; } -static int gfs2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -u64 start,u64 len) +static int gfs2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) { +u64 start = fieinfo->fi_start; +u64 len = fieinfo->fi_len;struct gfs2_inode *ip =GFS2_I (inode);struct gfs2_holder gh;int ret;
fs/hpfs/file.c +2 -2
@@ -190,9 +190,9 @@ static sector_t _hpfs_bmap(struct address_space *mapping, sector_t block)return generic_block_bmap (mapping, block, hpfs_get_block); } -static int hpfs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 start,u64 len) +static int hpfs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) { -return generic_block_fiemap (inode, fieinfo, start, len, hpfs_get_block); +return generic_block_fiemap (inode, fieinfo, hpfs_get_block); }const struct address_space_operations hpfs_aops = {
fs/ioctl.c +10 -6
@@ -208,6 +208,8 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg) fieinfo.fi_flags = fiemap.fm_flags; fieinfo.fi_extents_max = fiemap.fm_extent_count; fieinfo.fi_extents_start = ufiemap->fm_extents; + fieinfo.fi_start = fiemap.fm_start; + fieinfo.fi_len = len;if (fiemap.fm_extent_count !=0 && !access_ok(fieinfo.fi_extents_start,
@@ -217,7 +219,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)if (fieinfo.fi_flags &FIEMAP_FLAG_SYNC )filemap_write_and_wait (inode->i_mapping); - error = inode->i_op->fiemap (inode, &fieinfo, fiemap.fm_start, len); + error = inode->i_op->fiemap (inode, &fieinfo); fiemap.fm_flags = fieinfo.fi_flags; fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;if (copy_to_user (ufiemap, &fiemap,sizeof (fiemap)))
@@ -294,9 +296,11 @@ static inline loff_t blk_to_logical(struct inode *inode, sector_t blk)*/ int __generic_block_fiemap (struct inode *inode, -struct fiemap_extent_info *fieinfo,loff_t start, -loff_t len,get_block_t *get_block) +struct fiemap_extent_info *fieinfo, +get_block_t *get_block) { +loff_t start = fieinfo->fi_start; +loff_t len = fieinfo->fi_len;struct buffer_head map_bh;sector_t start_blk, last_blk;loff_t isize =i_size_read (inode);
@@ -453,12 +457,12 @@ EXPORT_SYMBOL(__generic_block_fiemap);*/ int generic_block_fiemap (struct inode *inode, -struct fiemap_extent_info *fieinfo,u64 start, -u64 len,get_block_t *get_block) +struct fiemap_extent_info *fieinfo, +get_block_t *get_block) {int ret;inode_lock (inode); - ret =__generic_block_fiemap (inode, fieinfo, start, len, get_block); + ret =__generic_block_fiemap (inode, fieinfo, get_block);inode_unlock (inode);return ret; }
fs/nilfs2/inode.c +3 -2
@@ -992,9 +992,10 @@ void nilfs_dirty_inode(struct inode *inode, int flags)nilfs_transaction_commit (inode->i_sb);/* never fails */ } -int nilfs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -__u64 start,__u64 len) +int nilfs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) { +u64 start = fieinfo->fi_start; +u64 len = fieinfo->fi_len;struct the_nilfs *nilfs = inode->i_sb->s_fs_info;__u64 logical =0 , phys =0 , size =0 ;__u32 flags =0 ;
fs/nilfs2/nilfs.h +1 -2
@@ -276,8 +276,7 @@ extern int nilfs_inode_dirty(struct inode *);int nilfs_set_file_dirty (struct inode *inode,unsigned int nr_dirty);extern int __nilfs_mark_inode_dirty (struct inode *,int );extern void nilfs_dirty_inode (struct inode *,int flags); -int nilfs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -__u64 start,__u64 len); +int nilfs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo);static inline int nilfs_mark_inode_dirty (struct inode *inode) {return __nilfs_mark_inode_dirty (inode,I_DIRTY );
fs/ocfs2/extent_map.c +3 -2
@@ -749,8 +749,7 @@ static int ocfs2_fiemap_inline(struct inode *inode, struct buffer_head *di_bh,#define OCFS2_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC) -int ocfs2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -u64 map_start,u64 map_len) +int ocfs2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) {int ret, is_last;u32 mapping_end, cpos;
@@ -759,6 +758,8 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,u64 len_bytes, phys_bytes, virt_bytes;struct buffer_head *di_bh =NULL ;struct ocfs2_extent_rec rec; +u64 map_start = fieinfo->fi_start; +u64 map_len = fieinfo->fi_len; ret =fiemap_check_flags (fieinfo,OCFS2_FIEMAP_FLAGS );if (ret)
fs/ocfs2/extent_map.h +1 -2
@@ -50,8 +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); +int ocfs2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo);int ocfs2_overwrite_io (struct inode *inode,struct buffer_head *di_bh,u64 map_start,u64 map_len);
fs/overlayfs/inode.c +2 -3
@@ -456,8 +456,7 @@ int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags)return 0 ; } -static int ovl_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -u64 start,u64 len) +static int ovl_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) {int err;struct inode *realinode =ovl_inode_real (inode);
@@ -471,7 +470,7 @@ static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,if (fieinfo->fi_flags &FIEMAP_FLAG_SYNC )filemap_write_and_wait (realinode->i_mapping); - err = realinode->i_op->fiemap (realinode, fieinfo, start, len); + err = realinode->i_op->fiemap(realinode, fieinfo,);revert_creds (old_cred);return err;
fs/xfs/xfs_iops.c +5 -5
@@ -1092,12 +1092,12 @@ xfs_vn_update_time( STATIC intxfs_vn_fiemap ( -struct inode *inode, -struct fiemap_extent_info *fieinfo, -u64 start, -u64 length) +struct inode *inode, +struct fiemap_extent_info *fieinfo) { -int error; +u64 start = fieinfo->fi_start; +u64 length = fieinfo->fi_len; +int error;xfs_ilock (XFS_I (inode),XFS_IOLOCK_SHARED );if (fieinfo->fi_flags &FIEMAP_FLAG_XATTR ) {
include/linux/fs.h +11 -10
@@ -1694,11 +1694,14 @@ extern bool may_open_dev(const struct path *path);* 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 __user *fi_extents_start;/* Start of -fiemap_extent array */ +unsigned int fi_flags;/* Flags as passed from user */ +u64 fi_start; +u64 fi_len; +unsigned int fi_extents_mapped;/* Number of mapped extents */ +unsigned int fi_extents_max;/* Size of fiemap_extent array */ +struct fiemap_extent __user *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);
@@ -1829,8 +1832,7 @@ struct inode_operations {int (*setattr) (struct dentry *,struct iattr *);int (*getattr) (const struct path *,struct kstat *,u32 ,unsigned int );ssize_t (*listxattr) (struct dentry *,char *,size_t ); -int (*fiemap)(struct inode *,struct fiemap_extent_info *,u64 start, -u64 len); +int (*fiemap)(struct inode *,struct fiemap_extent_info *);int (*update_time)(struct inode *,struct timespec64 *,int ); int (*atomic_open)(struct inode *, struct dentry *, struct file *, unsigned open_flag,
@@ -3186,11 +3188,10 @@ extern int vfs_readlink(struct dentry *, char __user *, int);extern int __generic_block_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -loff_t start,loff_t 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); +struct fiemap_extent_info *fieinfo, +get_block_t *get_block);extern struct file_system_type *get_filesystem (struct file_system_type *fs);extern void put_filesystem (struct file_system_type *fs);
Signature · 1 line
2.17.2
PATCH v3 6/9 iomap: Remove length and start fields from iomap_fiemap
In reply to Carlos Maiolinofiemap_extent_info now embeds start and length parameters, users of iomap_fiemap() doesn't need to pass it individually anymore.
--- fs/gfs2/inode.c | 4 +--- fs/iomap.c | 4 +++- fs/xfs/xfs_iops.c | 8 ++------ include/linux/iomap.h | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-)
fs/gfs2/inode.c +1 -3
@@ -2006,8 +2006,6 @@ static int gfs2_getattr(const struct path *path, struct kstat *stat,static int gfs2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) { -u64 start = fieinfo->fi_start; -u64 len = fieinfo->fi_len;struct gfs2_inode *ip =GFS2_I (inode);struct gfs2_holder gh;int ret;
@@ -2018,7 +2016,7 @@ static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo)if (ret) goto out; - ret =iomap_fiemap (inode, fieinfo, start, len, &gfs2_iomap_ops); + ret =iomap_fiemap (inode, fieinfo, &gfs2_iomap_ops);gfs2_glock_dq_uninit (&gh);
fs/iomap.c +3 -1
@@ -1183,9 +1183,11 @@ iomap_fiemap_actor(struct inode *inode, loff_t pos, loff_t length, void *data, }int iomap_fiemap (struct inode *inode,struct fiemap_extent_info *fi, -loff_t start,loff_t len,const struct iomap_ops *ops) +const struct iomap_ops *ops) {struct fiemap_ctx ctx; +loff_t start = fi->fi_start; +loff_t len = fi->fi_len;loff_t ret;memset (&ctx,0 ,sizeof (ctx));
fs/xfs/xfs_iops.c +2 -6
@@ -1095,18 +1095,14 @@ xfs_vn_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) { - u64 start = fieinfo->fi_start; -u64 length = fieinfo->fi_len; int error;xfs_ilock (XFS_I (inode),XFS_IOLOCK_SHARED );if (fieinfo->fi_flags &FIEMAP_FLAG_XATTR ) { fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR ; - error =iomap_fiemap (inode, fieinfo, start, length, - &xfs_xattr_iomap_ops); + error =iomap_fiemap (inode, fieinfo, &xfs_xattr_iomap_ops); }else { - error =iomap_fiemap (inode, fieinfo, start, length, - &xfs_iomap_ops); + error =iomap_fiemap (inode, fieinfo, &xfs_iomap_ops); }xfs_iunlock (XFS_I (inode),XFS_IOLOCK_SHARED );
include/linux/iomap.h +1 -1
@@ -145,7 +145,7 @@ int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,vm_fault_t iomap_page_mkwrite (struct vm_fault *vmf,const struct iomap_ops *ops);int iomap_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -loff_t start,loff_t len,const struct iomap_ops *ops); +const struct iomap_ops *ops);loff_t iomap_seek_hole (struct inode *inode,loff_t offset,const struct iomap_ops *ops); loff_t iomap_seek_data(struct inode *inode, loff_t offset,
Signature · 1 line
2.17.2
PATCH v3 7/9 fiemap: Use a callback to fill fiemap extents
In reply to Carlos MaiolinoAs a goal to enable fiemap infrastructure to be used by fibmap too, we need a way to use different helpers to fill extent data, depending on its usage. One helper to fill extent data stored in user address space (used in fiemap), and another fo fill extent data stored in kernel address space (will be used in fibmap).
This patch sets up the usage of a callback to be used to fill in the extents. It transforms the current fiemap_fill_next_extent, into a simple helper to call the callback, avoiding unneeded changes on any filesystem, and reutilizes the original function as the callback used by FIEMAP.
V3:
- Rebase to current linux-next
- Fix conflict on rebase
- Merge this patch into patch 07 from V2
- Rename fi_extents_start to fi_cb_data
V2:
- Now based on the rework on fiemap_extent_info (previous was based on fiemap_ctx)
--- fs/ioctl.c | 45 ++++++++++++++++++++++++++------------------- include/linux/fs.h | 12 +++++++++--- 2 files changed, 35 insertions(+), 22 deletions(-)
fs/ioctl.c +26 -19
@@ -75,29 +75,14 @@ static int ioctl_fibmap(struct file *filp, int __user *p)return error; } -/** -* 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_UNMOUNTED_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, +int fiemap_fill_user_extent (struct fiemap_extent_info *fieinfo,u64 logical,u64 phys,u64 len,u32 flags) {struct fiemap_extent extent; -struct fiemap_extent __user *dest = fieinfo->fi_extents_start; +struct fiemap_extent __user *dest = fieinfo->fi_cb_data;/* only count the extents */ if (fieinfo->fi_extents_max ==0 ) {
@@ -130,6 +115,27 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical,return 1 ;return (flags &FIEMAP_EXTENT_LAST ) ?1 :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. +*/ +int fiemap_fill_next_extent (struct fiemap_extent_info *fieinfo,u64 logical, +u64 phys,u64 len,u32 flags) +{ +return fieinfo->fi_cb (fieinfo, logical, phys, len, flags); +}EXPORT_SYMBOL (fiemap_fill_next_extent);/**
@@ -207,12 +213,13 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg) fieinfo.fi_flags = fiemap.fm_flags; fieinfo.fi_extents_max = fiemap.fm_extent_count; - fieinfo.fi_extents_start = ufiemap->fm_extents; + fieinfo.fi_cb_data = ufiemap->fm_extents; fieinfo.fi_start = fiemap.fm_start; fieinfo.fi_len = len; + fieinfo.fi_cb = fiemap_fill_user_extent;if (fiemap.fm_extent_count !=0 && - !access_ok (fieinfo.fi_extents_start, + !access_ok (fieinfo.fi_cb_data, fieinfo.fi_extents_max *sizeof (struct fiemap_extent )))return -EFAULT ;
include/linux/fs.h +9 -3
@@ -64,6 +64,7 @@ struct fscrypt_info;struct fscrypt_operations ;struct fs_context ;struct fs_parameter_description ; +struct fiemap_extent_info ;extern void __init inode_init (void );extern void __init inode_init_early (void );
@@ -1693,16 +1694,21 @@ extern bool may_open_dev(const struct path *path);/* * VFS FS_IOC_FIEMAP helper definitions. */ + +typedef int (*fiemap_fill_cb )(struct fiemap_extent_info *fieinfo,u64 logical, +u64 phys,u64 len,u32 flags); +struct fiemap_extent_info {unsigned int fi_flags;/* Flags as passed from user */ u64 fi_start;u64 fi_len;unsigned int fi_extents_mapped;/* Number of mapped extents */ unsigned int fi_extents_max;/* Size of fiemap_extent array */ -struct fiemap_extent __user *fi_extents_start;/* Start of -fiemap_extent -array */ +void *fi_cb_data;/* Start of fiemap_extent +array */ +fiemap_fill_cb fi_cb; }; +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);
Signature · 1 line
2.17.2
RFC PATCH v3 8/9 Use FIEMAP for FIBMAP calls
In reply to Carlos MaiolinoEnables the usage of FIEMAP ioctl infrastructure to handle FIBMAP calls. From now on, ->bmap() methods can start to be removed from filesystems which already provides ->fiemap().
This adds a new helper - bmap_fiemap() - which is used to fill in the fiemap request, call into the underlying filesystem and check the flags set in the extent requested.
Add a new fiemap fill extent callback to handle the in-kernel only fiemap_extent structure used for FIBMAP.
The new FIEMAP_KERNEL_FIBMAP flag, is used to tell the filesystem ->fiemap interface, that the call is coming from ioctl_fibmap. The addition of this new flag, requires an update to fiemap_check_flags(), so it doesn't treat FIBMAP requests as invalid.
V3:
- Add FIEMAP_EXTENT_SHARED to the list of invalid extents in bmap_fiemap()
- Rename fi_extents_start to fi_cb_data
- Use if conditional instead of ternary operator
- Make fiemap_fill_* callbacks static (which required the removal of some macros
- Set FIEMAP_FLAG_SYNC when calling in ->fiemap method from fibmap
- Add FIEMAP_KERNEL_FIBMAP flag, to identify the usage of fiemap infrastructure for fibmap calls, defined in fs.h so it's not exported to userspace.
- Update fiemap_check_flags() to understand FIEMAP_KERNEL_FIBMAP
- Update filesystems supporting both FIBMAP and FIEMAP, which need extra checks on FIBMAP calls
V2:
- Now based on the updated fiemap_extent_info,
- move the fiemap call itself to a new helper
---
I'm flagging this patch as RFC, because here lies the big discussion about how to prevent filesystems without FIBMAP support, to keep not supporting it once this patchset is integrated.
Christoph suggested the use of a flag, so, the main difference between this RFC V3 and the previous one, is the inclusion of the flag FIEMAP_KERNEL_FIBMAP, which let the underlying filesystem know if the call is coming from which ioctl the call is coming from (fibmap or fiemap).
Note that I didn't bother to look too deep if some filesystems like ocfs2, f2fs, etc, (filesystems I don't use to work on) does require extra checks than those I added to this patch. The goal of this patch is to discuss the generic implementation of FIEMAP_KERNEL_FIBMAP flag. If this implementation is ok, I'll work on the filesystems specifically.
Note the bmap call is able to handle errors now, so, invalid fibmap requests can now return -EINVAL instead of 0.
I added modifications to specific filesystems in this patch, otherwise there would be a gap between the implementation of the feature (fibmap via fiemap) where filesystems without FIBMAP support, would suddenly start to support it
The remaining of the patches in this patchset are either a copy from the previous series (with the respective Reviewed-by tags), and/or a new updated version containing the changes suggested previously.
Comments are much appreciated.
Cheers
fs/ext4/extents.c | 7 +++- fs/f2fs/data.c | 5 ++- fs/inode.c | 80 +++++++++++++++++++++++++++++++++++++++++-- fs/ioctl.c | 40 +++++++++++++++------- fs/iomap.c | 2 +- fs/ocfs2/extent_map.c | 8 ++++- fs/xfs/xfs_iops.c | 5 +++ include/linux/fs.h | 4 +++ 8 files changed, 133 insertions(+), 18 deletions(-)
fs/ext4/extents.c +6 -1
@@ -5008,7 +5008,9 @@ static int ext4_find_delayed_extent(struct inode *inode,return next_del; }/* fiemap flags we can handle specified here */ -#define EXT4_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR) +#define EXT4_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC | \ + FIEMAP_FLAG_XATTR| \ + FIEMAP_KERNEL_FIBMAP)static int ext4_xattr_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo)
@@ -5055,6 +5057,9 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo)if (ext4_has_inline_data (inode)) {int has_inline =1 ; +if (fieinfo->fi_flags &FIEMAP_KERNEL_FIBMAP ) +return -EINVAL ; + error =ext4_inline_data_fiemap (inode, fieinfo, &has_inline, start, len);
fs/f2fs/data.c +4 -1
@@ -1405,6 +1405,9 @@ static int f2fs_xattr_fiemap(struct inode *inode,return (err <0 ? err :0 ); } +#define F2FS_FIEMAP_COMPAT (FIEMAP_FLAG_SYNC | \ + FIEMAP_FLAG_XATTR| \ + FIEMAP_KERNEL_FIBMAP)int f2fs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) {u64 start = fieinfo->fi_start;
@@ -1422,7 +1425,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo)return ret; } - ret =fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC |FIEMAP_FLAG_XATTR ); + ret =fiemap_check_flags (fieinfo,F2FS_FIEMAP_COMPAT );if (ret)return ret;
fs/inode.c +78 -2
94 lines not on this page · raw message
fs/ioctl.c +28 -12
@@ -75,11 +75,8 @@ static int ioctl_fibmap(struct file *filp, int __user *p)return error; } -#define SET_UNKNOWN_FLAGS (FIEMAP_EXTENT_DELALLOC) -#define SET_NO_UNMOUNTED_IO_FLAGS (FIEMAP_EXTENT_DATA_ENCRYPTED) -#define SET_NOT_ALIGNED_FLAGS (FIEMAP_EXTENT_DATA_TAIL|FIEMAP_EXTENT_DATA_INLINE) -int fiemap_fill_user_extent (struct fiemap_extent_info *fieinfo,u64 logical, -u64 phys,u64 len,u32 flags) +static int fiemap_fill_user_extent (struct fiemap_extent_info *fieinfo, +u64 logical,u64 phys,u64 len,u32 flags) {struct fiemap_extent extent;struct fiemap_extent __user *dest = fieinfo->fi_cb_data;
@@ -87,17 +84,17 @@ int fiemap_fill_user_extent(struct fiemap_extent_info *fieinfo, u64 logical,/* only count the extents */ if (fieinfo->fi_extents_max ==0 ) { fieinfo->fi_extents_mapped++; -return (flags &FIEMAP_EXTENT_LAST ) ?1 :0 ; + goto out; }if (fieinfo->fi_extents_mapped >= fieinfo->fi_extents_max)return 1 ; -if (flags &SET_UNKNOWN_FLAGS ) +if (flags &FIEMAP_EXTENT_DELALLOC ) flags |=FIEMAP_EXTENT_UNKNOWN ; -if (flags &SET_NO_UNMOUNTED_IO_FLAGS ) +if (flags &FIEMAP_EXTENT_DATA_ENCRYPTED ) flags |=FIEMAP_EXTENT_ENCODED ; -if (flags &SET_NOT_ALIGNED_FLAGS ) +if (flags & (FIEMAP_EXTENT_DATA_TAIL |FIEMAP_EXTENT_DATA_INLINE )) flags |=FIEMAP_EXTENT_NOT_ALIGNED ;memset (&extent,0 ,sizeof (extent));
@@ -113,7 +110,11 @@ int fiemap_fill_user_extent(struct fiemap_extent_info *fieinfo, u64 logical, fieinfo->fi_extents_mapped++;if (fieinfo->fi_extents_mapped == fieinfo->fi_extents_max)return 1 ; -return (flags &FIEMAP_EXTENT_LAST ) ?1 :0 ; + +out: +if (flags &FIEMAP_EXTENT_LAST ) +return 1 ; +return 0 ; }/**
@@ -149,13 +150,23 @@ EXPORT_SYMBOL(fiemap_fill_next_extent);* flags, the invalid values will be written into the fieinfo structure, and * -EBADR is returned, which tells ioctl_fiemap() to return those values to * userspace. For this reason, a return code of -EBADR should be preserved. +* In case ->fiemap is being used for FIBMAP calls, and the filesystem does not +* support it, return -EINVAL. * -* Returns 0 on success, -EBADR on bad flags. +* Returns 0 on success, -EBADR on bad flags, -EINVAL for an unsupported FIBMAP +* request. */ int fiemap_check_flags (struct fiemap_extent_info *fieinfo,u32 fs_flags) {u32 incompat_flags; +if (fieinfo->fi_flags &FIEMAP_KERNEL_FIBMAP ) { +if (fs_flags &FIEMAP_KERNEL_FIBMAP ) +return 0 ; + +return -EINVAL ; + } + incompat_flags = fieinfo->fi_flags & ~(FIEMAP_FLAGS_COMPAT & fs_flags);if (incompat_flags) { fieinfo->fi_flags = incompat_flags;
@@ -206,6 +217,10 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)if (fiemap.fm_extent_count >FIEMAP_MAX_EXTENTS )return -EINVAL ; +/* Userspace has no access to this flag */ +if (fiemap.fm_flags &FIEMAP_KERNEL_FIBMAP ) +return -EINVAL ; + error =fiemap_check_ranges (sb, fiemap.fm_start, fiemap.fm_length, &len);if (error)
@@ -316,7 +331,8 @@ int __generic_block_fiemap(struct inode *inode,bool past_eof = false, whole_file = false;int ret =0 ; - ret =fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC ); + ret =fiemap_check_flags (fieinfo, +FIEMAP_FLAG_SYNC |FIEMAP_KERNEL_FIBMAP );if (ret)return ret;
fs/iomap.c +1 -1
@@ -1194,7 +1194,7 @@ int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi, ctx.fi = fi; ctx.prev.type =IOMAP_HOLE ; - ret =fiemap_check_flags (fi,FIEMAP_FLAG_SYNC ); + ret =fiemap_check_flags (fi,FIEMAP_FLAG_SYNC |FIEMAP_KERNEL_FIBMAP );if (ret)return ret;
fs/ocfs2/extent_map.c +7 -1
@@ -747,7 +747,7 @@ static int ocfs2_fiemap_inline(struct inode *inode, struct buffer_head *di_bh,return 0 ; } -#define OCFS2_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC) +#define OCFS2_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC | FIEMAP_KERNEL_FIBMAP)int ocfs2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo) {
@@ -756,6 +756,7 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo)unsigned int hole_size;struct ocfs2_super *osb =OCFS2_SB (inode->i_sb);u64 len_bytes, phys_bytes, virt_bytes; +struct buffer_head *di_bh =NULL ;struct ocfs2_extent_rec rec;u64 map_start = fieinfo->fi_start;
@@ -765,6 +766,11 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo)if (ret)return ret; +if (fieinfo->fi_flags &FIEMAP_KERNEL_FIBMAP ) { +if (ocfs2_is_refcount_inode (inode)) +return -EINVAL ; + } + ret =ocfs2_inode_lock (inode, &di_bh,0 );if (ret) {mlog_errno (ret);
fs/xfs/xfs_iops.c +5 -0
@@ -1096,6 +1096,11 @@ xfs_vn_fiemap( struct fiemap_extent_info *fieinfo) {int error; +struct xfs_inode *ip =XFS_I (inode); + +if (fieinfo->fi_flags &FIEMAP_KERNEL_FIBMAP ) +if (xfs_is_reflink_inode (ip) ||XFS_IS_REALTIME_INODE (ip)) +return -EINVAL ;xfs_ilock (XFS_I (inode),XFS_IOLOCK_SHARED );if (fieinfo->fi_flags &FIEMAP_FLAG_XATTR ) {
include/linux/fs.h +4 -0
@@ -1698,6 +1698,10 @@ extern bool may_open_dev(const struct path *path);typedef int (*fiemap_fill_cb )(struct fiemap_extent_info *fieinfo,u64 logical,u64 phys,u64 len,u32 flags); +#define FIEMAP_KERNEL_FIBMAP 0x10000000/* FIBMAP call through FIEMAP +interface. This is a kernel +only flag */ +struct fiemap_extent_info {unsigned int fi_flags;/* Flags as passed from user */ u64 fi_start;
Signature · 1 line
2.17.2
Re: [PATCH RFC 8/9] Use FIEMAP for FIBMAP calls
Quoted 62 lines · Carlos Maiolino
Enables the usage of FIEMAP ioctl infrastructure to handle FIBMAP calls. From now on, ->bmap() methods can start to be removed from filesystems which already provides ->fiemap().
This adds a new helper -
bmap_fiemap()- which is used to fill in the fiemap request, call into the underlying filesystem and check the flags set in the extent requested.Add a new fiemap fill extent callback to handle the in-kernel only
fiemap_extentstructure used for FIBMAP.The new
FIEMAP_KERNEL_FIBMAPflag, is used to tell the filesystem ->fiemap interface, that the call is coming fromioctl_fibmap. The addition of this new flag, requires an update tofiemap_check_flags(), so it doesn't treat FIBMAP requests as invalid.V3:
- AddFIEMAP_EXTENT_SHAREDto the list of invalid extents inbmap_fiemap()
- Renamefi_extents_starttofi_cb_data
- Use if conditional instead of ternary operator
- Make fiemap_fill_* callbacks static (which required the removal of some macros
- SetFIEMAP_FLAG_SYNCwhen calling in ->fiemap method from fibmap
- AddFIEMAP_KERNEL_FIBMAPflag, to identify the usage of fiemap infrastructure for fibmap calls, defined infs.hso it's not exported to userspace.
- Updatefiemap_check_flags()to understandFIEMAP_KERNEL_FIBMAP
- Update filesystems supporting both FIBMAP and FIEMAP, which need extra checks on FIBMAP callsV2:
- Now based on the updatedfiemap_extent_info,
- move the fiemap call itself to a new helperSigned-off-by Carlos Maiolino <[email protected]>---
I'm flagging this patch as RFC, because here lies the big discussion about how to prevent filesystems without FIBMAP support, to keep not supporting it once this patchset is integrated.
Christoph suggested the use of a flag, so, the main difference between this RFC V3 and the previous one, is the inclusion of the flag
FIEMAP_KERNEL_FIBMAP, which let the underlying filesystem know if the call is coming from which ioctl the call is coming from (fibmap or fiemap).Note that I didn't bother to look too deep if some filesystems like ocfs2, f2fs, etc, (filesystems I don't use to work on) does require extra checks than those I added to this patch. The goal of this patch is to discuss the generic implementation of
FIEMAP_KERNEL_FIBMAPflag. If this implementation is ok, I'll work on the filesystems specifically.Note the bmap call is able to handle errors now, so, invalid fibmap requests can now return
-EINVALinstead of 0.I added modifications to specific filesystems in this patch, otherwise there would be a gap between the implementation of the feature (fibmap via fiemap) where filesystems without FIBMAP support, would suddenly start to support it
Quoted 7 lines
The remaining of the patches in this patchset are either a copy from the previous series (with the respective Reviewed-by tags), and/or a new updated version containing the changes suggested previously.
Comments are much appreciated.
Cheers
Looks pretty reasonable. A few minor nits, but nothing serious.
fs/inode.c void iput(struct inode *inode) · line 1615
Quoted 13 lines
fs/inode.c +8
-0+static int fiemap_fill_kernel_extent (struct fiemap_extent_info *fieinfo, +u64 logical,u64 phys,u64 len,u32 flags) +{ + +out: +if (flags &FIEMAP_EXTENT_LAST ) +return 1 ; +return 0 ;
Why not just the straight return:
return !!(flags & FIEMAP_EXTENT_LAST);
or if this function is only returning 0 or 1 then it could return bool and be:
return flags & FIEMAP_EXTENT_LAST;
fs/inode.c EXPORT_SYMBOL(iput); · line 1673
Quoted 10 lines
fs/inode.c +5
-1@@ -1594,10 +1666,14 @@ EXPORT_SYMBOL(iput);*/ int bmap (struct inode *inode,sector_t *block) { -if (!inode->i_mapping->a_ops->bmap) +if (inode->i_op->fiemap) +return bmap_fiemap (inode, block); +else if (inode->i_mapping->a_ops->bmap) + *block = inode->i_mapping->a_ops->bmap (inode->i_mapping, + *block);
Typically there is no "else" after return.
fs/inode.c int fiemap_fill_user_extent(struct fiemap_extent_info *fieinfo, u64 logical, · line 118
Quoted 11 lines
fs/inode.c +5
-1@@ -113,7 +110,11 @@ int fiemap_fill_user_extent(struct fiemap_extent_info *fieinfo, u64 logical, fieinfo->fi_extents_mapped++;if (fieinfo->fi_extents_mapped == fieinfo->fi_extents_max)return 1 ; -return (flags &FIEMAP_EXTENT_LAST ) ?1 :0 ; + +out: +if (flags &FIEMAP_EXTENT_LAST ) +return 1 ; +return 0 ; }
As above, the simpler code would be:
return !!(flags & FIEMAP_EXTENT_LAST);
Cheers, Andreas
Re: [PATCH RFC 8/9] Use FIEMAP for FIBMAP calls
Quoted 5 lines
Quoted 3 lines
Comments are much appreciated.
Cheers
Looks pretty reasonable. A few minor nits, but nothing serious.
Thanks for the review...
Quoted 17 lines
Quoted 5 lines
fs/inode.c +0
-0fs/inode.c void iput(struct inode *inode) · line 1615
Quoted 9 lines
fs/inode.c +8
-0+static int fiemap_fill_kernel_extent (struct fiemap_extent_info *fieinfo, +u64 logical,u64 phys,u64 len,u32 flags) +{ + +out: +if (flags &FIEMAP_EXTENT_LAST ) +return 1 ; +return 0 ;Why not just the straight return:
Quoted 5 lines
return !!(flags & FIEMAP_EXTENT_LAST);or if this function is only returning 0 or 1 then it could return bool and be:
return flags & FIEMAP_EXTENT_LAST;
Christoph asked to leave it on the good if () style :P
Quoted 13 lines
fs/inode.c EXPORT_SYMBOL(iput); · line 1673
Quoted 11 lines
fs/inode.c +5
-1@@ -1594,10 +1666,14 @@ EXPORT_SYMBOL(iput);*/ int bmap (struct inode *inode,sector_t *block) { -if (!inode->i_mapping->a_ops->bmap) +if (inode->i_op->fiemap) +return bmap_fiemap (inode, block); +else if (inode->i_mapping->a_ops->bmap) + *block = inode->i_mapping->a_ops->bmap (inode->i_mapping, + *block);Typically there is no "else" after return.
Makes sense.
Quoted 15 lines
fs/inode.c int fiemap_fill_user_extent(struct fiemap_extent_info *fieinfo, u64 logical, · line 118
Quoted 12 lines
fs/inode.c +5
-1@@ -113,7 +110,11 @@ int fiemap_fill_user_extent(struct fiemap_extent_info *fieinfo, u64 logical, fieinfo->fi_extents_mapped++;if (fieinfo->fi_extents_mapped == fieinfo->fi_extents_max)return 1 ; -return (flags &FIEMAP_EXTENT_LAST ) ?1 :0 ; + +out: +if (flags &FIEMAP_EXTENT_LAST ) +return 1 ; +return 0 ; }As above, the simpler code would be:
Quoted 1 line
return !!(flags & FIEMAP_EXTENT_LAST);
Same here, discussed on the last thread (I guess)
Quoted 2 lines
Cheers, Andreas
Thanks again for the review
Signature · 1 line
Carlos
PATCH v2 9/9 xfs: Get rid of ->bmap
In reply to Carlos MaiolinoWe don't need ->bmap anymore, only usage for it was FIBMAP, which is now gone.
Also kill iomap_bmap() and iomap_bmap_actor once it has no users anymore.
V2:
- Kill iomap_bmap() and iomap_bmap_actor()
--- fs/iomap.c | 34 ---------------------------------- fs/xfs/xfs_aops.c | 24 ------------------------ fs/xfs/xfs_trace.h | 1 - 3 files changed, 59 deletions(-)
fs/iomap.c +0 -34
@@ -2138,37 +2138,3 @@ int iomap_swapfile_activate(struct swap_info_struct *sis, }EXPORT_SYMBOL_GPL (iomap_swapfile_activate);#endif /* CONFIG_SWAP */ - -static loff_t -iomap_bmap_actor (struct inode *inode,loff_t pos,loff_t length, -void *data,struct iomap *iomap) -{ -sector_t *bno = data, addr; - -if (iomap->type ==IOMAP_MAPPED ) { - addr = (pos - iomap->offset + iomap->addr) >> inode->i_blkbits; -if (addr >INT_MAX ) -WARN (1 ,"would truncate bmap result\n" ); -else - *bno = addr; - } -return 0 ; -} - -/* legacy ->bmap interface. 0 is the error return (!) */ -sector_t -iomap_bmap (struct address_space *mapping,sector_t bno, -const struct iomap_ops *ops) -{ -struct inode *inode = mapping->host; -loff_t pos = bno << inode->i_blkbits; -unsigned blocksize =i_blocksize (inode); - -if (filemap_write_and_wait (mapping)) -return 0 ; - - bno =0 ; -iomap_apply (inode, pos, blocksize,0 , ops, &bno, iomap_bmap_actor); -return bno; -} -EXPORT_SYMBOL_GPL (iomap_bmap);
fs/xfs/xfs_aops.c +0 -24
@@ -963,29 +963,6 @@ xfs_vm_releasepage(return iomap_releasepage (page, gfp_mask); } -STATIC sector_t -xfs_vm_bmap ( -struct address_space *mapping, -sector_t block) -{ -struct xfs_inode *ip =XFS_I (mapping->host); - -trace_xfs_vm_bmap (ip); - -/* -* The swap code (ab-)uses ->bmap to get a block mapping and then -* bypasses the file system for actual I/O. We really can't allow -* that on reflinks inodes, so we have to skip out here. And yes, -* 0 is the magic code for a bmap error. -* -* Since we don't pass back blockdev info, we can't return bmap -* information for rt files either. -*/ -if (xfs_is_reflink_inode (ip) ||XFS_IS_REALTIME_INODE (ip)) -return 0 ; -return iomap_bmap (mapping, block, &xfs_iomap_ops); -} - STATIC int xfs_vm_readpage( struct file *unused,
@@ -1024,7 +1001,6 @@ const struct address_space_operations xfs_address_space_operations = { .set_page_dirty = iomap_set_page_dirty, .releasepage = xfs_vm_releasepage, .invalidatepage = xfs_vm_invalidatepage, - .bmap = xfs_vm_bmap, .direct_IO = noop_direct_IO, .migratepage = iomap_migrate_page, .is_partially_uptodate = iomap_is_partially_uptodate,
fs/xfs/xfs_trace.h +0 -1
@@ -621,7 +621,6 @@ DEFINE_INODE_EVENT(xfs_readdir);#ifdef CONFIG_XFS_POSIX_ACL DEFINE_INODE_EVENT (xfs_get_acl);#endif -DEFINE_INODE_EVENT (xfs_vm_bmap);DEFINE_INODE_EVENT (xfs_file_ioctl);DEFINE_INODE_EVENT (xfs_file_compat_ioctl);DEFINE_INODE_EVENT (xfs_ioctl_setattr);
Signature · 1 line
2.17.2