fix fiemap for ext4 bitmap files (+ cleanups) v2
Subsystems (14)
Hi all,
the first two patches should fix the issue where ext4 doesn't properly check the max file size for bitmap files in fiemap.
The rest cleans up the fiemap support in ext4 and in general.
Changes since v1:
- rename fiemap_validate to fiemap_prep
- lift FIEMAP_FLAG_SYNC handling to common code
- add a new linux/fiemap.h header
- remove __generic_block_fiemap
- remove access_ok calls from fiemap and ext4
PATCH 1/11 ext4: fix EXT4_MAX_LOGICAL_BLOCK macro
From: Ritesh Harjani <[email protected]>
ext4 supports max number of logical blocks in a file to be 0xffffffff. (This is since ext4_extent's ee_block is __le32).
This means that EXT4_MAX_LOGICAL_BLOCK should be 0xfffffffe (starting from 0 logical offset). This patch fixes this.
The issue was seen when ext4 moved to iomap_fiemap API and when overlayfs was mounted on top of ext4. Since overlayfs was missing filemap_check_ranges(), so it could pass a arbitrary huge length which lead to overflow of map.m_len logic.
This patch fixes that.
--- fs/ext4/ext4.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/ext4.h +1 -1
@@ -722,7 +722,7 @@ enum {#define EXT4_MAX_BLOCK_FILE_PHYS 0xFFFFFFFF/* Max logical block we can support */ -#define EXT4_MAX_LOGICAL_BLOCK 0xFFFFFFFF +#define EXT4_MAX_LOGICAL_BLOCK 0xFFFFFFFE/* * Structure of an inode on the disk
Signature · 1 line
2.26.1
PATCH 2/11 ext4: fix fiemap size checks for bitmap files
In reply to Christoph HellwigAdd an extra validation of the len parameter, as for ext4 some files might have smaller file size limits than others. This also means the redundant size check in ext4_ioctl_get_es_cache can go away, as all size checking is done in the shared fiemap handler.
--- fs/ext4/extents.c | 31 +++++++++++++++++++++++++++++++ fs/ext4/ioctl.c | 33 ++------------------------------- 2 files changed, 33 insertions(+), 31 deletions(-)
fs/ext4/extents.c +31 -0
@@ -4832,6 +4832,28 @@ static const struct iomap_ops ext4_iomap_xattr_ops = { .iomap_begin = ext4_iomap_xattr_begin, }; +static int ext4_fiemap_check_ranges (struct inode *inode,u64 start,u64 *len) +{ +u64 maxbytes; + +if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) + maxbytes = inode->i_sb->s_maxbytes; +else + maxbytes =EXT4_SB (inode->i_sb)->s_bitmap_maxbytes; + +if (*len ==0 ) +return -EINVAL ; +if (start > maxbytes) +return -EFBIG ; + +/* +* Shrink request scope to what the fs can actually handle. +*/ +if (*len > maxbytes || (maxbytes - *len) < start) + *len = maxbytes - start; +return 0 ; +} +static int _ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,__u64 start,__u64 len,bool from_es_cache) {
@@ -4852,6 +4874,15 @@ static int _ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,if (fiemap_check_flags (fieinfo, ext4_fiemap_flags))return -EBADR ; +/* +* For bitmap files the maximum size limit could be smaller than +* s_maxbytes, so check len here manually instead of just relying on the +* generic check. +*/ + error =ext4_fiemap_check_ranges (inode, start, &len); +if (error) +return error; +if (fieinfo->fi_flags &FIEMAP_FLAG_XATTR ) { fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR ; error = iomap_fiemap(inode, fieinfo, start, len,
fs/ext4/ioctl.c +2 -31
@@ -733,29 +733,6 @@ static void ext4_fill_fsxattr(struct inode *inode, struct fsxattr *fa) fa->fsx_projid =from_kprojid (&init_user_ns, ei->i_projid); } -/* copied from fs/ioctl.c */ -static int fiemap_check_ranges (struct super_block *sb, -u64 start,u64 len,u64 *new_len) -{ -u64 maxbytes = (u64 ) sb->s_maxbytes; - - *new_len = len; - -if (len ==0 ) -return -EINVAL ; - -if (start > maxbytes) -return -EFBIG ; - -/* -* Shrink request scope to what the fs can actually handle. -*/ -if (len > maxbytes || (maxbytes - len) < start) - *new_len = maxbytes - start; - -return 0 ; -} -/* So that the fiemap access checks can't overflow on 32 bit machines. */ #define FIEMAP_MAX_EXTENTS (UINT_MAX / sizeof(struct fiemap_extent))
@@ -765,8 +742,6 @@ static int ext4_ioctl_get_es_cache(struct file *filp, unsigned long arg)struct fiemap __user *ufiemap = (struct fiemap __user *) arg;struct fiemap_extent_info fieinfo = {0 , };struct inode *inode =file_inode (filp); -struct super_block *sb = inode->i_sb; -u64 len;int error;if (copy_from_user (&fiemap, ufiemap,sizeof (fiemap)))
@@ -775,11 +750,6 @@ static int ext4_ioctl_get_es_cache(struct file *filp, unsigned long arg)if (fiemap.fm_extent_count >FIEMAP_MAX_EXTENTS )return -EINVAL ; - error =fiemap_check_ranges (sb, fiemap.fm_start, fiemap.fm_length, - &len); -if (error) -return error; - fieinfo.fi_flags = fiemap.fm_flags; fieinfo.fi_extents_max = fiemap.fm_extent_count; fieinfo.fi_extents_start = ufiemap->fm_extents;
@@ -792,7 +762,8 @@ static int ext4_ioctl_get_es_cache(struct file *filp, unsigned long arg)if (fieinfo.fi_flags &FIEMAP_FLAG_SYNC )filemap_write_and_wait (inode->i_mapping); - error =ext4_get_es_cache (inode, &fieinfo, fiemap.fm_start, len); + error =ext4_get_es_cache (inode, &fieinfo, fiemap.fm_start, + fiemap.fm_length); fiemap.fm_flags = fieinfo.fi_flags; fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;if (copy_to_user (ufiemap, &fiemap,sizeof (fiemap)))
Signature · 1 line
2.26.1
Re: [PATCH 02/11] ext4: fix fiemap size checks for bitmap files
Quoted 6 lines · Christoph Hellwig
Add an extra validation of the len parameter, as for ext4 some files might have smaller file size limits than others. This also means the redundant size check in
ext4_ioctl_get_es_cachecan go away, as all size checking is done in the shared fiemap handler.Signed-off-by Christoph Hellwig <[email protected]>
Looks fine. Feel free to add
Quoted 120 lines
--- fs/ext4/extents.c | 31 +++++++++++++++++++++++++++++++ fs/ext4/ioctl.c | 33 ++------------------------------- 2 files changed, 33 insertions(+), 31 deletions(-)fs/ext4/extents.c +31
-0@@ -4832,6 +4832,28 @@ static const struct iomap_ops ext4_iomap_xattr_ops = { .iomap_begin = ext4_iomap_xattr_begin, }; +static int ext4_fiemap_check_ranges (struct inode *inode,u64 start,u64 *len) +{ +u64 maxbytes; + +if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) + maxbytes = inode->i_sb->s_maxbytes; +else + maxbytes =EXT4_SB (inode->i_sb)->s_bitmap_maxbytes; + +if (*len ==0 ) +return -EINVAL ; +if (start > maxbytes) +return -EFBIG ; + +/* +* Shrink request scope to what the fs can actually handle. +*/ +if (*len > maxbytes || (maxbytes - *len) < start) + *len = maxbytes - start; +return 0 ; +} +static int _ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,__u64 start,__u64 len,bool from_es_cache) {@@ -4852,6 +4874,15 @@ static int _ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,if (fiemap_check_flags (fieinfo, ext4_fiemap_flags))return -EBADR ; +/* +* For bitmap files the maximum size limit could be smaller than +* s_maxbytes, so check len here manually instead of just relying on the +* generic check. +*/ + error =ext4_fiemap_check_ranges (inode, start, &len); +if (error) +return error; +if (fieinfo->fi_flags &FIEMAP_FLAG_XATTR ) { fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR ; error = iomap_fiemap(inode, fieinfo, start, len,fs/ext4/ioctl.c +2
-31@@ -733,29 +733,6 @@ static void ext4_fill_fsxattr(struct inode *inode, struct fsxattr *fa) fa->fsx_projid =from_kprojid (&init_user_ns, ei->i_projid); } -/* copied from fs/ioctl.c */ -static int fiemap_check_ranges (struct super_block *sb, -u64 start,u64 len,u64 *new_len) -{ -u64 maxbytes = (u64 ) sb->s_maxbytes; - - *new_len = len; - -if (len ==0 ) -return -EINVAL ; - -if (start > maxbytes) -return -EFBIG ; - -/* -* Shrink request scope to what the fs can actually handle. -*/ -if (len > maxbytes || (maxbytes - len) < start) - *new_len = maxbytes - start; - -return 0 ; -} -/* So that the fiemap access checks can't overflow on 32 bit machines. */ #define FIEMAP_MAX_EXTENTS (UINT_MAX / sizeof(struct fiemap_extent))@@ -765,8 +742,6 @@ static int ext4_ioctl_get_es_cache(struct file *filp, unsigned long arg)struct fiemap __user *ufiemap = (struct fiemap __user *) arg;struct fiemap_extent_info fieinfo = {0 , };struct inode *inode =file_inode (filp); -struct super_block *sb = inode->i_sb; -u64 len;int error;if (copy_from_user (&fiemap, ufiemap,sizeof (fiemap)))@@ -775,11 +750,6 @@ static int ext4_ioctl_get_es_cache(struct file *filp, unsigned long arg)if (fiemap.fm_extent_count >FIEMAP_MAX_EXTENTS )return -EINVAL ; - error =fiemap_check_ranges (sb, fiemap.fm_start, fiemap.fm_length, - &len); -if (error) -return error; - fieinfo.fi_flags = fiemap.fm_flags; fieinfo.fi_extents_max = fiemap.fm_extent_count; fieinfo.fi_extents_start = ufiemap->fm_extents;@@ -792,7 +762,8 @@ static int ext4_ioctl_get_es_cache(struct file *filp, unsigned long arg)if (fieinfo.fi_flags &FIEMAP_FLAG_SYNC )filemap_write_and_wait (inode->i_mapping); - error =ext4_get_es_cache (inode, &fieinfo, fiemap.fm_start, len); + error =ext4_get_es_cache (inode, &fieinfo, fiemap.fm_start, + fiemap.fm_length); fiemap.fm_flags = fieinfo.fi_flags; fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;if (copy_to_user (ufiemap, &fiemap,sizeof (fiemap)))
PATCH 3/11 ext4: split _ext4_fiemap
In reply to Christoph HellwigThe fiemap and EXT4_IOC_GET_ES_CACHE cases share almost no code, so split them into entirely separate functions.
--- fs/ext4/extents.c | 72 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 37 deletions(-)
fs/ext4/extents.c +35 -37
@@ -4854,11 +4854,9 @@ static int ext4_fiemap_check_ranges(struct inode *inode, u64 start, u64 *len)return 0 ; } -static int _ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -__u64 start,__u64 len,bool from_es_cache) +int ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, +u64 start,u64 len) { -ext4_lblk_t start_blk; -u32 ext4_fiemap_flags =FIEMAP_FLAG_SYNC |FIEMAP_FLAG_XATTR ;int error =0 ;if (fieinfo->fi_flags &FIEMAP_FLAG_CACHE ) {
@@ -4868,10 +4866,7 @@ static int _ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE ; } -if (from_es_cache) - ext4_fiemap_flags &=FIEMAP_FLAG_XATTR ; - -if (fiemap_check_flags (fieinfo, ext4_fiemap_flags)) +if (fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC |FIEMAP_FLAG_XATTR ))return -EBADR ;/*
@@ -4885,40 +4880,20 @@ static int _ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,if (fieinfo->fi_flags &FIEMAP_FLAG_XATTR ) { fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR ; - error =iomap_fiemap (inode, fieinfo, start, len, - &ext4_iomap_xattr_ops); - }else if (!from_es_cache) { - error =iomap_fiemap (inode, fieinfo, start, len, - &ext4_iomap_report_ops); - }else { -ext4_lblk_t len_blks; -__u64 last_blk; - - start_blk = start >> inode->i_sb->s_blocksize_bits; - last_blk = (start + len -1 ) >> inode->i_sb->s_blocksize_bits; -if (last_blk >=EXT_MAX_BLOCKS ) - last_blk =EXT_MAX_BLOCKS -1 ; - len_blks = ((ext4_lblk_t ) last_blk) - start_blk +1 ; - -/* -* Walk the extent tree gathering extent information -* and pushing extents back to the user. -*/ - error =ext4_fill_es_cache_info (inode, start_blk, len_blks, - fieinfo); +return iomap_fiemap (inode, fieinfo, start, len, + &ext4_iomap_xattr_ops); } -return error; -} -int ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -__u64 start,__u64 len) -{ -return _ext4_fiemap (inode, fieinfo, start, len, false); +return iomap_fiemap (inode, fieinfo, start, len, &ext4_iomap_report_ops); }int ext4_get_es_cache (struct inode *inode,struct fiemap_extent_info *fieinfo,__u64 start,__u64 len) { +ext4_lblk_t start_blk, len_blks; +__u64 last_blk; +int error =0 ; +if (ext4_has_inline_data (inode)) {int has_inline;
@@ -4929,9 +4904,32 @@ int ext4_get_es_cache(struct inode *inode, struct fiemap_extent_info *fieinfo,return 0 ; } -return _ext4_fiemap (inode, fieinfo, start, len, true); -} +if (fieinfo->fi_flags &FIEMAP_FLAG_CACHE ) { + error =ext4_ext_precache (inode); +if (error) +return error; + fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE ; + } + +if (fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC )) +return -EBADR ; + error =ext4_fiemap_check_ranges (inode, start, &len); +if (error) +return error; + + start_blk = start >> inode->i_sb->s_blocksize_bits; + last_blk = (start + len -1 ) >> inode->i_sb->s_blocksize_bits; +if (last_blk >=EXT_MAX_BLOCKS ) + last_blk =EXT_MAX_BLOCKS -1 ; + len_blks = ((ext4_lblk_t ) last_blk) - start_blk +1 ; + +/* +* Walk the extent tree gathering extent information +* and pushing extents back to the user. +*/ +return ext4_fill_es_cache_info (inode, start_blk, len_blks, fieinfo); +}/* * ext4_access_path:
Signature · 1 line
2.26.1
Re: [PATCH 03/11] ext4: split _ext4_fiemap
Quoted 4 lines · Christoph Hellwig
The fiemap and
EXT4_IOC_GET_ES_CACHEcases share almost no code, so split them into entirely separate functions.Signed-off-by Christoph Hellwig <[email protected]>
Looks fine. Feel free to add
Quoted 118 lines
--- fs/ext4/extents.c | 72 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 37 deletions(-)fs/ext4/extents.c +35
-37@@ -4854,11 +4854,9 @@ static int ext4_fiemap_check_ranges(struct inode *inode, u64 start, u64 *len)return 0 ; } -static int _ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -__u64 start,__u64 len,bool from_es_cache) +int ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, +u64 start,u64 len) { -ext4_lblk_t start_blk; -u32 ext4_fiemap_flags =FIEMAP_FLAG_SYNC |FIEMAP_FLAG_XATTR ;int error =0 ;if (fieinfo->fi_flags &FIEMAP_FLAG_CACHE ) {@@ -4868,10 +4866,7 @@ static int _ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE ; } -if (from_es_cache) - ext4_fiemap_flags &=FIEMAP_FLAG_XATTR ; - -if (fiemap_check_flags (fieinfo, ext4_fiemap_flags)) +if (fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC |FIEMAP_FLAG_XATTR ))return -EBADR ;/* @@ -4885,40 +4880,20 @@ static int _ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,if (fieinfo->fi_flags &FIEMAP_FLAG_XATTR ) { fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR ; - error =iomap_fiemap (inode, fieinfo, start, len, - &ext4_iomap_xattr_ops); - }else if (!from_es_cache) { - error =iomap_fiemap (inode, fieinfo, start, len, - &ext4_iomap_report_ops); - }else { -ext4_lblk_t len_blks; -__u64 last_blk; - - start_blk = start >> inode->i_sb->s_blocksize_bits; - last_blk = (start + len -1 ) >> inode->i_sb->s_blocksize_bits; -if (last_blk >=EXT_MAX_BLOCKS ) - last_blk =EXT_MAX_BLOCKS -1 ; - len_blks = ((ext4_lblk_t ) last_blk) - start_blk +1 ; - -/* -* Walk the extent tree gathering extent information -* and pushing extents back to the user. -*/ - error =ext4_fill_es_cache_info (inode, start_blk, len_blks, - fieinfo); +return iomap_fiemap (inode, fieinfo, start, len, + &ext4_iomap_xattr_ops); } -return error; -} -int ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, -__u64 start,__u64 len) -{ -return _ext4_fiemap (inode, fieinfo, start, len, false); +return iomap_fiemap (inode, fieinfo, start, len, &ext4_iomap_report_ops); }int ext4_get_es_cache (struct inode *inode,struct fiemap_extent_info *fieinfo,__u64 start,__u64 len) { +ext4_lblk_t start_blk, len_blks; +__u64 last_blk; +int error =0 ; +if (ext4_has_inline_data (inode)) {int has_inline;@@ -4929,9 +4904,32 @@ int ext4_get_es_cache(struct inode *inode, struct fiemap_extent_info *fieinfo,return 0 ; } -return _ext4_fiemap (inode, fieinfo, start, len, true); -} +if (fieinfo->fi_flags &FIEMAP_FLAG_CACHE ) { + error =ext4_ext_precache (inode); +if (error) +return error; + fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE ; + } + +if (fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC )) +return -EBADR ; + error =ext4_fiemap_check_ranges (inode, start, &len); +if (error) +return error; + + start_blk = start >> inode->i_sb->s_blocksize_bits; + last_blk = (start + len -1 ) >> inode->i_sb->s_blocksize_bits; +if (last_blk >=EXT_MAX_BLOCKS ) + last_blk =EXT_MAX_BLOCKS -1 ; + len_blks = ((ext4_lblk_t ) last_blk) - start_blk +1 ; + +/* +* Walk the extent tree gathering extent information +* and pushing extents back to the user. +*/ +return ext4_fill_es_cache_info (inode, start_blk, len_blks, fieinfo); +}/* * ext4_access_path:
PATCH 4/11 ext4: remove the call to fiemap_check_flags in ext4_fiemap
In reply to Christoph Hellwigiomap_fiemap already calls fiemap_check_flags first thing, so this additional check is redundant.
--- fs/ext4/extents.c | 3 --- 1 file changed, 3 deletions(-)
fs/ext4/extents.c +0 -3
@@ -4866,9 +4866,6 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE ; } -if (fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC |FIEMAP_FLAG_XATTR )) -return -EBADR ; -/* * For bitmap files the maximum size limit could be smaller than * s_maxbytes, so check len here manually instead of just relying on the
Signature · 1 line
2.26.1
Re: [PATCH 04/11] ext4: remove the call to fiemap_check_flags in ext4_fiemap
Quoted 4 lines · Christoph Hellwig
iomap_fiemapalready callsfiemap_check_flagsfirst thing, so this additional check is redundant.Signed-off-by Christoph Hellwig <[email protected]>
Looks fine. Feel free to add
Quoted 19 lines
--- fs/ext4/extents.c | 3 --- 1 file changed, 3 deletions(-)fs/ext4/extents.c +0
-3@@ -4866,9 +4866,6 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE ; } -if (fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC |FIEMAP_FLAG_XATTR )) -return -EBADR ; -/* * For bitmap files the maximum size limit could be smaller than * s_maxbytes, so check len here manually instead of just relying on the
PATCH 5/11 fs: mark __generic_block_fiemap static
In reply to Christoph HellwigThere is no caller left outside of ioctl.c.
--- fs/ioctl.c | 4 +--- include/linux/fs.h | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-)
fs/ioctl.c +1 -3
@@ -299,8 +299,7 @@ static inline loff_t blk_to_logical(struct inode *inode, sector_t blk)* If you use this function directly, you need to do your own locking. Use * generic_block_fiemap if you want the locking done for you. */ - -int __generic_block_fiemap (struct inode *inode, +static int __generic_block_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,loff_t start,loff_t len,get_block_t *get_block) {
@@ -445,7 +444,6 @@ int __generic_block_fiemap(struct inode *inode,return ret; } -EXPORT_SYMBOL (__generic_block_fiemap);/** * generic_block_fiemap - FIEMAP for block based inodes
include/linux/fs.h +0 -4
@@ -3299,10 +3299,6 @@ static inline int vfs_fstat(int fd, struct kstat *stat)extern const char *vfs_get_link (struct dentry *,struct delayed_call *);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);
Signature · 1 line
2.26.1
Re: [PATCH 05/11] fs: mark __generic_block_fiemap static
Quoted 3 lines · Christoph Hellwig
There is no caller left outside of
ioctl.c.Signed-off-by Christoph Hellwig <[email protected]>
Looks good to me,
--D
Quoted 45 lines
--- fs/ioctl.c | 4 +--- include/linux/fs.h | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-)fs/ioctl.c +1
-3@@ -299,8 +299,7 @@ static inline loff_t blk_to_logical(struct inode *inode, sector_t blk)* If you use this function directly, you need to do your own locking. Use * generic_block_fiemap if you want the locking done for you. */ - -int __generic_block_fiemap (struct inode *inode, +static int __generic_block_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,loff_t start,loff_t len,get_block_t *get_block) {@@ -445,7 +444,6 @@ int __generic_block_fiemap(struct inode *inode,return ret; } -EXPORT_SYMBOL (__generic_block_fiemap);/** * generic_block_fiemap - FIEMAP for block based inodes include/linux/fs.h +0
-4@@ -3299,10 +3299,6 @@ static inline int vfs_fstat(int fd, struct kstat *stat)extern const char *vfs_get_link (struct dentry *,struct delayed_call *);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);Signature · 1 line
2.26.1
Re: [PATCH 05/11] fs: mark __generic_block_fiemap static
In reply to Christoph HellwigQuoted 1 line · Christoph Hellwig
There is no caller left outside of
ioctl.c.
Looks fine. Feel free to add
Quoted 45 lines
Signed-off-by Christoph Hellwig <[email protected]>--- fs/ioctl.c | 4 +--- include/linux/fs.h | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-)fs/ioctl.c +1
-3@@ -299,8 +299,7 @@ static inline loff_t blk_to_logical(struct inode *inode, sector_t blk)* If you use this function directly, you need to do your own locking. Use * generic_block_fiemap if you want the locking done for you. */ - -int __generic_block_fiemap (struct inode *inode, +static int __generic_block_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,loff_t start,loff_t len,get_block_t *get_block) {@@ -445,7 +444,6 @@ int __generic_block_fiemap(struct inode *inode,return ret; } -EXPORT_SYMBOL (__generic_block_fiemap);/** * generic_block_fiemap - FIEMAP for block based inodes include/linux/fs.h +0
-4@@ -3299,10 +3299,6 @@ static inline int vfs_fstat(int fd, struct kstat *stat)extern const char *vfs_get_link (struct dentry *,struct delayed_call *);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);
PATCH 6/11 fs: move the fiemap definitions out of fs.h
In reply to Christoph HellwigNo need to pull the fiemap definitions into almost every file in the kernel build.
--- fs/bad_inode.c | 1 + fs/btrfs/extent_io.h | 1 + fs/cifs/inode.c | 1 + fs/cifs/smb2ops.c | 1 + fs/ext2/inode.c | 1 + fs/ext4/ext4.h | 1 + fs/f2fs/data.c | 1 + fs/f2fs/inline.c | 1 + fs/gfs2/inode.c | 1 + fs/hpfs/file.c | 1 + fs/ioctl.c | 1 + fs/iomap/fiemap.c | 1 + fs/nilfs2/inode.c | 1 + fs/overlayfs/inode.c | 1 + fs/xfs/xfs_iops.c | 1 + include/linux/fiemap.h | 24 ++++++++++++++++++++++++ include/linux/fs.h | 19 +------------------ include/uapi/linux/fiemap.h | 6 +++--- 18 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 include/linux/fiemap.h
fs/bad_inode.c +1 -0
@@ -15,6 +15,7 @@#include <linux/time.h> #include <linux/namei.h> #include <linux/poll.h> +#include <linux/fiemap.h> static int bad_file_open (struct inode *inode,struct file *filp) {
fs/btrfs/extent_io.h +1 -0
@@ -5,6 +5,7 @@#include <linux/rbtree.h> #include <linux/refcount.h> +#include <linux/fiemap.h> #include "ulist.h" /*
fs/cifs/inode.c +1 -0
@@ -25,6 +25,7 @@#include <linux/freezer.h> #include <linux/sched/signal.h> #include <linux/wait_bit.h> +#include <linux/fiemap.h> #include <asm/div64.h> #include "cifsfs.h"
fs/cifs/smb2ops.c +1 -0
@@ -12,6 +12,7 @@#include <linux/uuid.h> #include <linux/sort.h> #include <crypto/aead.h> +#include <linux/fiemap.h> #include "cifsfs.h" #include "cifsglob.h" #include "smb2pdu.h"
fs/ext2/inode.c +1 -0
@@ -36,6 +36,7 @@#include <linux/iomap.h> #include <linux/namei.h> #include <linux/uio.h> +#include <linux/fiemap.h> #include "ext2.h" #include "acl.h" #include "xattr.h"
fs/ext4/ext4.h +1 -0
@@ -36,6 +36,7 @@#include <crypto/hash.h> #include <linux/falloc.h> #include <linux/percpu-rwsem.h> +#include <linux/fiemap.h> #ifdef __KERNEL__#include <linux/compat.h> #endif
fs/f2fs/data.c +1 -0
@@ -19,6 +19,7 @@#include <linux/uio.h> #include <linux/cleancache.h> #include <linux/sched/signal.h> +#include <linux/fiemap.h> #include "f2fs.h" #include "node.h"
fs/f2fs/inline.c +1 -0
@@ -8,6 +8,7 @@#include <linux/fs.h> #include <linux/f2fs_fs.h> +#include <linux/fiemap.h> #include "f2fs.h" #include "node.h"
fs/gfs2/inode.c +1 -0
@@ -17,6 +17,7 @@#include <linux/crc32.h> #include <linux/iomap.h> #include <linux/security.h> +#include <linux/fiemap.h> #include <linux/uaccess.h> #include "gfs2.h"
fs/hpfs/file.c +1 -0
@@ -9,6 +9,7 @@#include "hpfs_fn.h" #include <linux/mpage.h> +#include <linux/fiemap.h> #define BLOCKS (size) (((size) + 511) >> 9)
fs/ioctl.c +1 -0
@@ -18,6 +18,7 @@#include <linux/buffer_head.h> #include <linux/falloc.h> #include <linux/sched/signal.h> +#include <linux/fiemap.h> #include "internal.h"
fs/iomap/fiemap.c +1 -0
@@ -6,6 +6,7 @@#include <linux/compiler.h> #include <linux/fs.h> #include <linux/iomap.h> +#include <linux/fiemap.h> struct fiemap_ctx {struct fiemap_extent_info *fi;
fs/nilfs2/inode.c +1 -0
@@ -14,6 +14,7 @@#include <linux/pagemap.h> #include <linux/writeback.h> #include <linux/uio.h> +#include <linux/fiemap.h> #include "nilfs.h" #include "btnode.h" #include "segment.h"
fs/overlayfs/inode.c +1 -0
@@ -10,6 +10,7 @@#include <linux/xattr.h> #include <linux/posix_acl.h> #include <linux/ratelimit.h> +#include <linux/fiemap.h> #include "overlayfs.h"
fs/xfs/xfs_iops.c +1 -0
@@ -25,6 +25,7 @@#include <linux/posix_acl.h> #include <linux/security.h> #include <linux/iversion.h> +#include <linux/fiemap.h> /* * Directories have different lock order w.r.t. mmap_sem compared to regular
include/linux/fiemap.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_FIEMAP_H +#define _LINUX_FIEMAP_H 1 + +#include <uapi/linux/fiemap.h> +#include <linux/fs.h> + +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 */ +}; + +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); + +int generic_block_fiemap (struct inode *inode, +struct fiemap_extent_info *fieinfo,u64 start,u64 len, +get_block_t *get_block); + +#endif /* _LINUX_FIEMAP_H 1 */
include/linux/fs.h +1 -18
@@ -24,7 +24,6 @@#include <linux/capability.h> #include <linux/semaphore.h> #include <linux/fcntl.h> -#include <linux/fiemap.h> #include <linux/rculist_bl.h> #include <linux/atomic.h> #include <linux/shrinker.h>
@@ -48,6 +47,7 @@ struct backing_dev_info;struct bdi_writeback ;struct bio ;struct export_operations ; +struct fiemap_extent_info ;struct hd_geometry ;struct iovec ;struct kiocb ;
@@ -1745,19 +1745,6 @@ extern long compat_ptr_ioctl(struct file *file, unsigned int cmd,extern void inode_init_owner (struct inode *inode,const struct inode *dir,umode_t mode);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 */ -}; -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);/* * This is the "filldir" function type, used by readdir() to let
@@ -3299,10 +3286,6 @@ static inline int vfs_fstat(int fd, struct kstat *stat)extern const char *vfs_get_link (struct dentry *,struct delayed_call *);extern int vfs_readlink (struct dentry *,char __user *,int ); -extern int generic_block_fiemap (struct inode *inode, -struct fiemap_extent_info *fieinfo,u64 start, -u64 len,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);extern struct file_system_type *get_fs_type (const char *name);
include/uapi/linux/fiemap.h +3 -3
@@ -9,8 +9,8 @@* Andreas Dilger <[email protected]> */ -#ifndef _LINUX_FIEMAP_H -#define _LINUX_FIEMAP_H +#ifndef _UAPI_LINUX_FIEMAP_H +#define _UAPI_LINUX_FIEMAP_H#include <linux/types.h>
@@ -67,4 +67,4 @@ struct fiemap {#define FIEMAP_EXTENT_SHARED 0x00002000/* Space shared with other * files. */ -#endif /* _LINUX_FIEMAP_H */ +#endif /* _UAPI_LINUX_FIEMAP_H */
Signature · 1 line
2.26.1
Re: [PATCH 06/11] fs: move the fiemap definitions out of fs.h
Quoted 4 lines · Christoph Hellwig
No need to pull the fiemap definitions into almost every file in the kernel build.
Signed-off-by Christoph Hellwig <[email protected]>
Hooray, I hate the overloaded mess that fs.h has become...
--D
Quoted 307 lines
--- fs/bad_inode.c | 1 + fs/btrfs/extent_io.h | 1 + fs/cifs/inode.c | 1 + fs/cifs/smb2ops.c | 1 + fs/ext2/inode.c | 1 + fs/ext4/ext4.h | 1 + fs/f2fs/data.c | 1 + fs/f2fs/inline.c | 1 + fs/gfs2/inode.c | 1 + fs/hpfs/file.c | 1 + fs/ioctl.c | 1 + fs/iomap/fiemap.c | 1 + fs/nilfs2/inode.c | 1 + fs/overlayfs/inode.c | 1 + fs/xfs/xfs_iops.c | 1 + include/linux/fiemap.h | 24 ++++++++++++++++++++++++ include/linux/fs.h | 19 +------------------ include/uapi/linux/fiemap.h | 6 +++--- 18 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 include/linux/fiemap.hfs/bad_inode.c +1
-0@@ -15,6 +15,7 @@#include <linux/time.h> #include <linux/namei.h> #include <linux/poll.h> +#include <linux/fiemap.h> static int bad_file_open (struct inode *inode,struct file *filp) {fs/btrfs/extent_io.h +1
-0@@ -5,6 +5,7 @@#include <linux/rbtree.h> #include <linux/refcount.h> +#include <linux/fiemap.h> #include "ulist.h" /* fs/cifs/inode.c +1
-0@@ -25,6 +25,7 @@#include <linux/freezer.h> #include <linux/sched/signal.h> #include <linux/wait_bit.h> +#include <linux/fiemap.h> #include <asm/div64.h> #include "cifsfs.h" fs/cifs/smb2ops.c +1
-0@@ -12,6 +12,7 @@#include <linux/uuid.h> #include <linux/sort.h> #include <crypto/aead.h> +#include <linux/fiemap.h> #include "cifsfs.h" #include "cifsglob.h" #include "smb2pdu.h" fs/ext2/inode.c +1
-0@@ -36,6 +36,7 @@#include <linux/iomap.h> #include <linux/namei.h> #include <linux/uio.h> +#include <linux/fiemap.h> #include "ext2.h" #include "acl.h" #include "xattr.h" fs/ext4/ext4.h +1
-0@@ -36,6 +36,7 @@#include <crypto/hash.h> #include <linux/falloc.h> #include <linux/percpu-rwsem.h> +#include <linux/fiemap.h> #ifdef __KERNEL__#include <linux/compat.h> #endif fs/f2fs/data.c +1
-0@@ -19,6 +19,7 @@#include <linux/uio.h> #include <linux/cleancache.h> #include <linux/sched/signal.h> +#include <linux/fiemap.h> #include "f2fs.h" #include "node.h" fs/f2fs/inline.c +1
-0@@ -8,6 +8,7 @@#include <linux/fs.h> #include <linux/f2fs_fs.h> +#include <linux/fiemap.h> #include "f2fs.h" #include "node.h" fs/gfs2/inode.c +1
-0@@ -17,6 +17,7 @@#include <linux/crc32.h> #include <linux/iomap.h> #include <linux/security.h> +#include <linux/fiemap.h> #include <linux/uaccess.h> #include "gfs2.h" fs/hpfs/file.c +1
-0@@ -9,6 +9,7 @@#include "hpfs_fn.h" #include <linux/mpage.h> +#include <linux/fiemap.h> #define BLOCKS (size) (((size) + 511) >> 9)fs/ioctl.c +1
-0@@ -18,6 +18,7 @@#include <linux/buffer_head.h> #include <linux/falloc.h> #include <linux/sched/signal.h> +#include <linux/fiemap.h> #include "internal.h" fs/iomap/fiemap.c +1
-0@@ -6,6 +6,7 @@#include <linux/compiler.h> #include <linux/fs.h> #include <linux/iomap.h> +#include <linux/fiemap.h> struct fiemap_ctx {struct fiemap_extent_info *fi;fs/nilfs2/inode.c +1
-0@@ -14,6 +14,7 @@#include <linux/pagemap.h> #include <linux/writeback.h> #include <linux/uio.h> +#include <linux/fiemap.h> #include "nilfs.h" #include "btnode.h" #include "segment.h" fs/overlayfs/inode.c +1
-0@@ -10,6 +10,7 @@#include <linux/xattr.h> #include <linux/posix_acl.h> #include <linux/ratelimit.h> +#include <linux/fiemap.h> #include "overlayfs.h" fs/xfs/xfs_iops.c +1
-0@@ -25,6 +25,7 @@#include <linux/posix_acl.h> #include <linux/security.h> #include <linux/iversion.h> +#include <linux/fiemap.h> /* * Directories have different lock order w.r.t. mmap_sem compared to regular include/linux/fiemap.h new file +24
-0@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_FIEMAP_H +#define _LINUX_FIEMAP_H 1 + +#include <uapi/linux/fiemap.h> +#include <linux/fs.h> + +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 */ +}; + +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); + +int generic_block_fiemap (struct inode *inode, +struct fiemap_extent_info *fieinfo,u64 start,u64 len, +get_block_t *get_block); + +#endif /* _LINUX_FIEMAP_H 1 */ include/linux/fs.h +1
-18@@ -24,7 +24,6 @@#include <linux/capability.h> #include <linux/semaphore.h> #include <linux/fcntl.h> -#include <linux/fiemap.h> #include <linux/rculist_bl.h> #include <linux/atomic.h> #include <linux/shrinker.h> @@ -48,6 +47,7 @@ struct backing_dev_info;struct bdi_writeback ;struct bio ;struct export_operations ; +struct fiemap_extent_info ;struct hd_geometry ;struct iovec ;struct kiocb ;@@ -1745,19 +1745,6 @@ extern long compat_ptr_ioctl(struct file *file, unsigned int cmd,extern void inode_init_owner (struct inode *inode,const struct inode *dir,umode_t mode);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 */ -}; -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);/* * This is the "filldir" function type, used by readdir() to let @@ -3299,10 +3286,6 @@ static inline int vfs_fstat(int fd, struct kstat *stat)extern const char *vfs_get_link (struct dentry *,struct delayed_call *);extern int vfs_readlink (struct dentry *,char __user *,int ); -extern int generic_block_fiemap (struct inode *inode, -struct fiemap_extent_info *fieinfo,u64 start, -u64 len,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);extern struct file_system_type *get_fs_type (const char *name);include/uapi/linux/fiemap.h +3
-3@@ -9,8 +9,8 @@* Andreas Dilger <[email protected]> */ -#ifndef _LINUX_FIEMAP_H -#define _LINUX_FIEMAP_H +#ifndef _UAPI_LINUX_FIEMAP_H +#define _UAPI_LINUX_FIEMAP_H#include <linux/types.h> @@ -67,4 +67,4 @@ struct fiemap {#define FIEMAP_EXTENT_SHARED 0x00002000/* Space shared with other * files. */ -#endif /* _LINUX_FIEMAP_H */ +#endif /* _UAPI_LINUX_FIEMAP_H */ Signature · 1 line
2.26.1
Re: [PATCH 06/11] fs: move the fiemap definitions out of fs.h
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
No need to pull the fiemap definitions into almost every file in the kernel build.
Signed-off-by Christoph Hellwig <[email protected]>
Nice,
Feel free to add:
Quoted 305 lines
--- fs/bad_inode.c | 1 + fs/btrfs/extent_io.h | 1 + fs/cifs/inode.c | 1 + fs/cifs/smb2ops.c | 1 + fs/ext2/inode.c | 1 + fs/ext4/ext4.h | 1 + fs/f2fs/data.c | 1 + fs/f2fs/inline.c | 1 + fs/gfs2/inode.c | 1 + fs/hpfs/file.c | 1 + fs/ioctl.c | 1 + fs/iomap/fiemap.c | 1 + fs/nilfs2/inode.c | 1 + fs/overlayfs/inode.c | 1 + fs/xfs/xfs_iops.c | 1 + include/linux/fiemap.h | 24 ++++++++++++++++++++++++ include/linux/fs.h | 19 +------------------ include/uapi/linux/fiemap.h | 6 +++--- 18 files changed, 43 insertions(+), 21 deletions(-)create mode 100644
include/linux/fiemap.hfs/bad_inode.c +1
-0@@ -15,6 +15,7 @@#include <linux/time.h> #include <linux/namei.h> #include <linux/poll.h> +#include <linux/fiemap.h> static int bad_file_open (struct inode *inode,struct file *filp) {fs/btrfs/extent_io.h +1
-0@@ -5,6 +5,7 @@#include <linux/rbtree.h> #include <linux/refcount.h> +#include <linux/fiemap.h> #include "ulist.h" /* fs/cifs/inode.c +1
-0@@ -25,6 +25,7 @@#include <linux/freezer.h> #include <linux/sched/signal.h> #include <linux/wait_bit.h> +#include <linux/fiemap.h> #include <asm/div64.h> #include "cifsfs.h" fs/cifs/smb2ops.c +1
-0@@ -12,6 +12,7 @@#include <linux/uuid.h> #include <linux/sort.h> #include <crypto/aead.h> +#include <linux/fiemap.h> #include "cifsfs.h" #include "cifsglob.h" #include "smb2pdu.h" fs/ext2/inode.c +1
-0@@ -36,6 +36,7 @@#include <linux/iomap.h> #include <linux/namei.h> #include <linux/uio.h> +#include <linux/fiemap.h> #include "ext2.h" #include "acl.h" #include "xattr.h" fs/ext4/ext4.h +1
-0@@ -36,6 +36,7 @@#include <crypto/hash.h> #include <linux/falloc.h> #include <linux/percpu-rwsem.h> +#include <linux/fiemap.h> #ifdef __KERNEL__#include <linux/compat.h> #endif fs/f2fs/data.c +1
-0@@ -19,6 +19,7 @@#include <linux/uio.h> #include <linux/cleancache.h> #include <linux/sched/signal.h> +#include <linux/fiemap.h> #include "f2fs.h" #include "node.h" fs/f2fs/inline.c +1
-0@@ -8,6 +8,7 @@#include <linux/fs.h> #include <linux/f2fs_fs.h> +#include <linux/fiemap.h> #include "f2fs.h" #include "node.h" fs/gfs2/inode.c +1
-0@@ -17,6 +17,7 @@#include <linux/crc32.h> #include <linux/iomap.h> #include <linux/security.h> +#include <linux/fiemap.h> #include <linux/uaccess.h> #include "gfs2.h" fs/hpfs/file.c +1
-0@@ -9,6 +9,7 @@#include "hpfs_fn.h" #include <linux/mpage.h> +#include <linux/fiemap.h> #define BLOCKS (size) (((size) + 511) >> 9)fs/ioctl.c +1
-0@@ -18,6 +18,7 @@#include <linux/buffer_head.h> #include <linux/falloc.h> #include <linux/sched/signal.h> +#include <linux/fiemap.h> #include "internal.h" fs/iomap/fiemap.c +1
-0@@ -6,6 +6,7 @@#include <linux/compiler.h> #include <linux/fs.h> #include <linux/iomap.h> +#include <linux/fiemap.h> struct fiemap_ctx {struct fiemap_extent_info *fi;fs/nilfs2/inode.c +1
-0@@ -14,6 +14,7 @@#include <linux/pagemap.h> #include <linux/writeback.h> #include <linux/uio.h> +#include <linux/fiemap.h> #include "nilfs.h" #include "btnode.h" #include "segment.h" fs/overlayfs/inode.c +1
-0@@ -10,6 +10,7 @@#include <linux/xattr.h> #include <linux/posix_acl.h> #include <linux/ratelimit.h> +#include <linux/fiemap.h> #include "overlayfs.h" fs/xfs/xfs_iops.c +1
-0@@ -25,6 +25,7 @@#include <linux/posix_acl.h> #include <linux/security.h> #include <linux/iversion.h> +#include <linux/fiemap.h> /* * Directories have different lock order w.r.t. mmap_sem compared to regular include/linux/fiemap.h new file +24
-0@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_FIEMAP_H +#define _LINUX_FIEMAP_H 1 + +#include <uapi/linux/fiemap.h> +#include <linux/fs.h> + +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 */ +}; + +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); + +int generic_block_fiemap (struct inode *inode, +struct fiemap_extent_info *fieinfo,u64 start,u64 len, +get_block_t *get_block); + +#endif /* _LINUX_FIEMAP_H 1 */ include/linux/fs.h +1
-18@@ -24,7 +24,6 @@#include <linux/capability.h> #include <linux/semaphore.h> #include <linux/fcntl.h> -#include <linux/fiemap.h> #include <linux/rculist_bl.h> #include <linux/atomic.h> #include <linux/shrinker.h> @@ -48,6 +47,7 @@ struct backing_dev_info;struct bdi_writeback ;struct bio ;struct export_operations ; +struct fiemap_extent_info ;struct hd_geometry ;struct iovec ;struct kiocb ;@@ -1745,19 +1745,6 @@ extern long compat_ptr_ioctl(struct file *file, unsigned int cmd,extern void inode_init_owner (struct inode *inode,const struct inode *dir,umode_t mode);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 */ -}; -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);/* * This is the "filldir" function type, used by readdir() to let @@ -3299,10 +3286,6 @@ static inline int vfs_fstat(int fd, struct kstat *stat)extern const char *vfs_get_link (struct dentry *,struct delayed_call *);extern int vfs_readlink (struct dentry *,char __user *,int ); -extern int generic_block_fiemap (struct inode *inode, -struct fiemap_extent_info *fieinfo,u64 start, -u64 len,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);extern struct file_system_type *get_fs_type (const char *name);include/uapi/linux/fiemap.h +3
-3@@ -9,8 +9,8 @@* Andreas Dilger <[email protected]> */ -#ifndef _LINUX_FIEMAP_H -#define _LINUX_FIEMAP_H +#ifndef _UAPI_LINUX_FIEMAP_H +#define _UAPI_LINUX_FIEMAP_H#include <linux/types.h> @@ -67,4 +67,4 @@ struct fiemap {#define FIEMAP_EXTENT_SHARED 0x00002000/* Space shared with other * files. */ -#endif /* _LINUX_FIEMAP_H */ +#endif /* _UAPI_LINUX_FIEMAP_H */
PATCH 7/11 iomap: fix the iomap_fiemap prototype
In reply to Christoph Hellwigiomap_fiemap should take u64 start and len arguments, just like the ->fiemap prototype.
--- fs/iomap/fiemap.c | 2 +- include/linux/iomap.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/iomap/fiemap.c +1 -1
@@ -66,7 +66,7 @@ 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) +u64 start,u64 len,const struct iomap_ops *ops) {struct fiemap_ctx ctx;loff_t ret;
include/linux/iomap.h +1 -1
@@ -178,7 +178,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); +u64 start,u64 len,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.26.1
Re: [PATCH 07/11] iomap: fix the iomap_fiemap prototype
Quoted 4 lines · Christoph Hellwig
iomap_fiemapshould take u64 start and len arguments, just like the ->fiemap prototype.Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
--D
Quoted 34 lines
--- fs/iomap/fiemap.c | 2 +- include/linux/iomap.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/iomap/fiemap.c +1
-1@@ -66,7 +66,7 @@ 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) +u64 start,u64 len,const struct iomap_ops *ops) {struct fiemap_ctx ctx;loff_t ret;include/linux/iomap.h +1
-1@@ -178,7 +178,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); +u64 start,u64 len,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.26.1
Re: [PATCH 07/11] iomap: fix the iomap_fiemap prototype
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
iomap_fiemapshould take u64 start and len arguments, just like the ->fiemap prototype.Signed-off-by Christoph Hellwig <[email protected]>
hmm.. I guess,
it's only ->fiemap ops in inode_operations which has start and len arguments as u64.
While such other ops in struct file_operations have the arguments of type loff_t. (e.g. ->fallocate, -->llseek etc).
But sure to match the ->fiemap prototype, this patch looks ok to me.
Feel free to add:
Quoted 32 lines
--- fs/iomap/fiemap.c | 2 +- include/linux/iomap.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/iomap/fiemap.c +1
-1@@ -66,7 +66,7 @@ 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) +u64 start,u64 len,const struct iomap_ops *ops) {struct fiemap_ctx ctx;loff_t ret;include/linux/iomap.h +1
-1@@ -178,7 +178,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); +u64 start,u64 len,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,
Re: [PATCH 07/11] iomap: fix the iomap_fiemap prototype
Quoted 8 lines · Ritesh Harjani
Quoted 4 lines · Christoph Hellwig
iomap_fiemapshould take u64 start and len arguments, just like the ->fiemap prototype.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 8 lines
hmm.. I guess,
it's only ->fiemap ops ininode_operationswhich has start and len arguments as u64.While such other ops in struct
file_operationshave the arguments of typeloff_t. (e.g. ->fallocate, -->llseek etc).But sure to match the ->fiemap prototype, this patch looks ok to me.
Yes, fiemap is rather weird here, but it matches the ioctl prototype, so I'd rather pass it on to the method where fiemap_prep will catch anything that overflows s_maxbytes due to the signeness of loff_t.
PATCH 8/11 fs: move fiemap range validation into the file systems instances
In reply to Christoph HellwigReplace fiemap_check_flags with a fiemap_validate helpers that also takes the inode and mapped range, and performs the sanity check and truncation previously done in fiemap_check_range. This way the validation is inside the file system itself and thus properly works for the stacked overlayfs case as well.
--- Documentation/filesystems/fiemap.txt | 8 ++--- fs/btrfs/inode.c | 2 +- fs/cifs/smb2ops.c | 6 ++-- fs/ext4/extents.c | 5 +-- fs/f2fs/data.c | 3 +- fs/ioctl.c | 53 +++++++++++----------------- fs/iomap/fiemap.c | 2 +- fs/nilfs2/inode.c | 2 +- fs/ocfs2/extent_map.c | 3 +- include/linux/fiemap.h | 3 +- 10 files changed, 40 insertions(+), 47 deletions(-)
Documentation/filesystems/fiemap.txt +3 -5
@@ -203,15 +203,13 @@ EINTR once fatal signal received. 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); +fiemap_prep() helper. The struct fieinfo should be passed in as received 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 +fiemap_prep 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 +fiemap_prep(), it should immediately exit, returning that error back to ioctl_fiemap().
fs/btrfs/inode.c +1 -1
@@ -8250,7 +8250,7 @@ static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, {int ret; - ret =fiemap_check_flags (fieinfo,BTRFS_FIEMAP_FLAGS ); + ret =fiemap_prep (inode, fieinfo, start, &len,BTRFS_FIEMAP_FLAGS );if (ret)return ret;
fs/cifs/smb2ops.c +4 -2
@@ -3408,8 +3408,10 @@ static int smb3_fiemap(struct cifs_tcon *tcon,int i, num, rc, flags, last_blob;u64 next; -if (fiemap_check_flags (fei,FIEMAP_FLAG_SYNC )) -return -EBADR ; + rc =fiemap_prep (cfile->dentry->d_inode, fei, start, &len, +FIEMAP_FLAG_SYNC ); +if (rc) + rc; xid =get_xid (); again:
fs/ext4/extents.c +3 -2
@@ -4908,8 +4908,9 @@ int ext4_get_es_cache(struct inode *inode, struct fiemap_extent_info *fieinfo, fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE ; } -if (fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC )) -return -EBADR ; + error =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC ); +if (error) +return error; error =ext4_fiemap_check_ranges (inode, start, &len);if (error)
fs/f2fs/data.c +2 -1
@@ -1825,7 +1825,8 @@ 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_prep (inode, fieinfo, start, &len, +FIEMAP_FLAG_SYNC |FIEMAP_FLAG_XATTR );if (ret)return ret;
fs/ioctl.c +21 -32
103 lines not on this page · raw message
fs/iomap/fiemap.c +1 -1
@@ -75,7 +75,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_prep (inode, fi, start, &len,FIEMAP_FLAG_SYNC );if (ret)return ret;
fs/nilfs2/inode.c +1 -1
@@ -1006,7 +1006,7 @@ int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,unsigned int blkbits = inode->i_blkbits;int ret, n; - ret =fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC ); + ret =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC );if (ret)return ret;
fs/ocfs2/extent_map.c +2 -1
@@ -746,7 +746,8 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,struct buffer_head *di_bh =NULL ;struct ocfs2_extent_rec rec; - ret =fiemap_check_flags (fieinfo,OCFS2_FIEMAP_FLAGS ); + ret =fiemap_prep (inode, fieinfo, map_start, &map_len, +OCFS2_FIEMAP_FLAGS );if (ret)return ret;
include/linux/fiemap.h +2 -1
@@ -13,9 +13,10 @@ struct fiemap_extent_info {fiemap_extent array */ }; +int fiemap_prep (struct inode *inode,struct fiemap_extent_info *fieinfo, +u64 start,u64 *len,u32 supported_flags);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); int generic_block_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 start, u64 len,
Signature · 1 line
2.26.1
Re: [PATCH 08/11] fs: move fiemap range validation into the file systems instances
Quoted 2 lines · Christoph Hellwig
Replace
fiemap_check_flagswith afiemap_validatehelpers that also takes
Leftover fiemap_validate
Quoted 6 lines
the inode and mapped range, and performs the sanity check and truncation previously done in
fiemap_check_range. This way the validation is inside the file system itself and thus properly works for the stacked overlayfs case as well.Signed-off-by Christoph Hellwig <[email protected]>
Thanks for fixing this,
Amir.
Re: [PATCH 08/11] fs: move fiemap range validation into the file systems instances
In reply to Christoph HellwigQuoted 1 line · Christoph Hellwig
Replace
fiemap_check_flagswith afiemap_validatehelpers that also takes
"...with a fiemap_prep helper..." ?
(new to this patchset, confused)
--D
Quoted 273 lines
the inode and mapped range, and performs the sanity check and truncation previously done in
fiemap_check_range. This way the validation is inside the file system itself and thus properly works for the stacked overlayfs case as well.Signed-off-by Christoph Hellwig <[email protected]>--- Documentation/filesystems/fiemap.txt | 8 ++--- fs/btrfs/inode.c | 2 +- fs/cifs/smb2ops.c | 6 ++-- fs/ext4/extents.c | 5 +-- fs/f2fs/data.c | 3 +- fs/ioctl.c | 53 +++++++++++----------------- fs/iomap/fiemap.c | 2 +- fs/nilfs2/inode.c | 2 +- fs/ocfs2/extent_map.c | 3 +- include/linux/fiemap.h | 3 +- 10 files changed, 40 insertions(+), 47 deletions(-)Documentation/filesystems/fiemap.txt +3
-5@@ -203,15 +203,13 @@ EINTR once fatal signal received. 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); +fiemap_prep() helper. The struct fieinfo should be passed in as received 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 +fiemap_prep 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 +fiemap_prep(), it should immediately exit, returning that error back to ioctl_fiemap().fs/btrfs/inode.c +1
-1@@ -8250,7 +8250,7 @@ static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, {int ret; - ret =fiemap_check_flags (fieinfo,BTRFS_FIEMAP_FLAGS ); + ret =fiemap_prep (inode, fieinfo, start, &len,BTRFS_FIEMAP_FLAGS );if (ret)return ret;fs/cifs/smb2ops.c +4
-2@@ -3408,8 +3408,10 @@ static int smb3_fiemap(struct cifs_tcon *tcon,int i, num, rc, flags, last_blob;u64 next; -if (fiemap_check_flags (fei,FIEMAP_FLAG_SYNC )) -return -EBADR ; + rc =fiemap_prep (cfile->dentry->d_inode, fei, start, &len, +FIEMAP_FLAG_SYNC ); +if (rc) + rc; xid =get_xid (); again:fs/ext4/extents.c +3
-2@@ -4908,8 +4908,9 @@ int ext4_get_es_cache(struct inode *inode, struct fiemap_extent_info *fieinfo, fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE ; } -if (fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC )) -return -EBADR ; + error =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC ); +if (error) +return error; error =ext4_fiemap_check_ranges (inode, start, &len);if (error)fs/f2fs/data.c +2
-1@@ -1825,7 +1825,8 @@ 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_prep (inode, fieinfo, start, &len, +FIEMAP_FLAG_SYNC |FIEMAP_FLAG_XATTR );if (ret)return ret;fs/ioctl.c +21
-32@@ -141,9 +141,12 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical,EXPORT_SYMBOL (fiemap_fill_next_extent);/** -* fiemap_check_flags - check validity of requested flags for fiemap +* fiemap_prep - check validity of requested flags for fiemap +* @inode: Inode to operate on * @fieinfo: Fiemap context passed into ->fiemap -* @fs_flags: Set of fiemap flags that the file system understands +* @start: Start of the mapped range +* @len: Length of the mapped range, can be truncated by this function. +* @supported_flags: Set of fiemap flags that the file system understands * * Called from file system ->fiemap callback. This will compute the * intersection of valid fiemap flags and those that the fs supports. That @@ -154,48 +157,38 @@ EXPORT_SYMBOL(fiemap_fill_next_extent);* * Returns 0 on success, -EBADR on bad flags. */ -int fiemap_check_flags (struct fiemap_extent_info *fieinfo,u32 fs_flags) +int fiemap_prep (struct inode *inode,struct fiemap_extent_info *fieinfo, +u64 start,u64 *len,u32 supported_flags) { +u64 maxbytes = inode->i_sb->s_maxbytes;u32 incompat_flags; - incompat_flags = fieinfo->fi_flags & ~(FIEMAP_FLAGS_COMPAT & fs_flags); -if (incompat_flags) { - fieinfo->fi_flags = incompat_flags; -return -EBADR ; - } -return 0 ; -} -EXPORT_SYMBOL (fiemap_check_flags); - -static int fiemap_check_ranges (struct super_block *sb, -u64 start,u64 len,u64 *new_len) -{ -u64 maxbytes = (u64 ) sb->s_maxbytes; - - *new_len = len; - -if (len ==0 ) +if (*len ==0 )return -EINVAL ; -if (start > maxbytes)return -EFBIG ;/* * Shrink request scope to what the fs can actually handle. */ -if (len > maxbytes || (maxbytes - len) < start) - *new_len = maxbytes - start; +if (*len > maxbytes || (maxbytes - *len) < start) + *len = maxbytes - start; + supported_flags &=FIEMAP_FLAGS_COMPAT ; + incompat_flags = fieinfo->fi_flags & ~supported_flags; +if (incompat_flags) { + fieinfo->fi_flags = incompat_flags; +return -EBADR ; + }return 0 ; } +EXPORT_SYMBOL (fiemap_prep);static int ioctl_fiemap (struct file *filp,struct fiemap __user *ufiemap) {struct fiemap fiemap;struct fiemap_extent_info fieinfo = {0 , };struct inode *inode =file_inode (filp); -struct super_block *sb = inode->i_sb; -u64 len;int error;if (!inode->i_op->fiemap)@@ -207,11 +200,6 @@ static int ioctl_fiemap(struct file *filp, struct fiemap __user *ufiemap)if (fiemap.fm_extent_count >FIEMAP_MAX_EXTENTS )return -EINVAL ; - error =fiemap_check_ranges (sb, fiemap.fm_start, fiemap.fm_length, - &len); -if (error) -return error; - fieinfo.fi_flags = fiemap.fm_flags; fieinfo.fi_extents_max = fiemap.fm_extent_count; fieinfo.fi_extents_start = ufiemap->fm_extents;@@ -224,7 +212,8 @@ static int ioctl_fiemap(struct file *filp, struct fiemap __user *ufiemap)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_start, + fiemap.fm_length); fiemap.fm_flags = fieinfo.fi_flags; fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;if (copy_to_user (ufiemap, &fiemap,sizeof (fiemap)))@@ -312,7 +301,7 @@ static 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_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC );if (ret)return ret;fs/iomap/fiemap.c +1
-1@@ -75,7 +75,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_prep (inode, fi, start, &len,FIEMAP_FLAG_SYNC );if (ret)return ret;fs/nilfs2/inode.c +1
-1@@ -1006,7 +1006,7 @@ int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,unsigned int blkbits = inode->i_blkbits;int ret, n; - ret =fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC ); + ret =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC );if (ret)return ret;fs/ocfs2/extent_map.c +2
-1@@ -746,7 +746,8 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,struct buffer_head *di_bh =NULL ;struct ocfs2_extent_rec rec; - ret =fiemap_check_flags (fieinfo,OCFS2_FIEMAP_FLAGS ); + ret =fiemap_prep (inode, fieinfo, map_start, &map_len, +OCFS2_FIEMAP_FLAGS );if (ret)return ret;include/linux/fiemap.h +2
-1@@ -13,9 +13,10 @@ struct fiemap_extent_info {fiemap_extent array */ }; +int fiemap_prep (struct inode *inode,struct fiemap_extent_info *fieinfo, +u64 start,u64 *len,u32 supported_flags);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); int generic_block_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 start, u64 len,Signature · 1 line
2.26.1
Re: [PATCH 08/11] fs: move fiemap range validation into the file systems instances
In reply to Christoph HellwigQuoted 25 lines · Christoph Hellwig
Replace
fiemap_check_flagswith afiemap_validatehelpers that also takes the inode and mapped range, and performs the sanity check and truncation previously done infiemap_check_range. This way the validation is inside the file system itself and thus properly works for the stacked overlayfs case as well.Signed-off-by Christoph Hellwig <[email protected]>--- Documentation/filesystems/fiemap.txt | 8 ++--- fs/btrfs/inode.c | 2 +- fs/cifs/smb2ops.c | 6 ++-- fs/ext4/extents.c | 5 +-- fs/f2fs/data.c | 3 +- fs/ioctl.c | 53 +++++++++++----------------- fs/iomap/fiemap.c | 2 +- fs/nilfs2/inode.c | 2 +- fs/ocfs2/extent_map.c | 3 +- include/linux/fiemap.h | 3 +- 10 files changed, 40 insertions(+), 47 deletions(-)Documentation/filesystems/fiemap.txt +0
-0
Documentation/filesystems/fiemap.txt EINTR once fatal signal received. · line 206
Quoted 7 lines
Documentation/filesystems/fiemap.txt +1
-3@@ -203,15 +203,13 @@ EINTR once fatal signal received. 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); +fiemap_prep() helper.
Let's add the fiemap_prep() function prototype here. So that below description would make more sense.
Documentation/filesystems/fiemap.txt EINTR once fatal signal received. · line 213
Quoted 9 lines
Documentation/filesystems/fiemap.txt +2
-2The struct fieinfo should be passed in as received 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 +fiemap_prep 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 +fiemap_prep(), it should immediately exit, returning that error back to ioctl_fiemap().
Also maybe we should also add more info about fiemap_prep() helper. Since it also checks for invalid len and invalid start range and hence could return -EINVAL or -EFBIG.
Quoted 20 lines
fs/btrfs/inode.c +1
-1@@ -8250,7 +8250,7 @@ static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, {int ret; - ret =fiemap_check_flags (fieinfo,BTRFS_FIEMAP_FLAGS ); + ret =fiemap_prep (inode, fieinfo, start, &len,BTRFS_FIEMAP_FLAGS );if (ret)return ret;fs/cifs/smb2ops.c +0
-0
fs/cifs/smb2ops.c static int smb3_fiemap(struct cifs_tcon *tcon, · line 3412
Quoted 7 lines
fs/cifs/smb2ops.c +2
-2@@ -3408,8 +3408,10 @@ static int smb3_fiemap(struct cifs_tcon *tcon,int i, num, rc, flags, last_blob;u64 next; -if (fiemap_check_flags (fei,FIEMAP_FLAG_SYNC )) -return -EBADR ; + rc =fiemap_prep (cfile->dentry->d_inode, fei, start, &len, +FIEMAP_FLAG_SYNC );
How about d_inode(cfile->dentry) ?
fs/cifs/smb2ops.c static int smb3_fiemap(struct cifs_tcon *tcon, · line 3414
Quoted 2 lines
fs/cifs/smb2ops.c +2
-0+if (rc) + rc;
missed "return rc" here?
Quoted 42 lines
fs/cifs/smb2ops.c +0
-0xid =get_xid (); again:fs/ext4/extents.c +3
-2@@ -4908,8 +4908,9 @@ int ext4_get_es_cache(struct inode *inode, struct fiemap_extent_info *fieinfo, fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE ; } -if (fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC )) -return -EBADR ; + error =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC ); +if (error) +return error; error =ext4_fiemap_check_ranges (inode, start, &len);if (error)fs/f2fs/data.c +2
-1@@ -1825,7 +1825,8 @@ 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_prep (inode, fieinfo, start, &len, +FIEMAP_FLAG_SYNC |FIEMAP_FLAG_XATTR );if (ret)return ret;fs/ioctl.c +0
-1@@ -141,9 +141,12 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical,EXPORT_SYMBOL (fiemap_fill_next_extent);/** -* fiemap_check_flags - check validity of requested flags for fiemap
fs/ioctl.c int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical, · line 152
Quoted 10 lines
fs/ioctl.c +5
-1+* fiemap_prep - check validity of requested flags for fiemap +* @inode: Inode to operate on * @fieinfo: Fiemap context passed into ->fiemap -* @fs_flags: Set of fiemap flags that the file system understands +* @start: Start of the mapped range +* @len: Length of the mapped range, can be truncated by this function. +* @supported_flags: Set of fiemap flags that the file system understands * * Called from file system ->fiemap callback. This will compute the * intersection of valid fiemap flags and those that the fs supports. That
Let's also add more documentation about this new fiemap_prep() helper. Earlier comments above this function description only talks about incompat flags. We should add more info about check_ranges part as well here.
fs/ioctl.c EXPORT_SYMBOL(fiemap_fill_next_extent); · line 159
Quoted 4 lines
fs/ioctl.c +0
-0@@ -154,48 +157,38 @@ EXPORT_SYMBOL(fiemap_fill_next_extent);* * Returns 0 on success, -EBADR on bad flags. */
Also let's add ", -EINVAL or -EFBIG on invalid len or start range respectively"
Quoted 134 lines
fs/ioctl.c +16
-30-int fiemap_check_flags (struct fiemap_extent_info *fieinfo,u32 fs_flags) +int fiemap_prep (struct inode *inode,struct fiemap_extent_info *fieinfo, +u64 start,u64 *len,u32 supported_flags) { +u64 maxbytes = inode->i_sb->s_maxbytes;u32 incompat_flags; - incompat_flags = fieinfo->fi_flags & ~(FIEMAP_FLAGS_COMPAT & fs_flags); -if (incompat_flags) { - fieinfo->fi_flags = incompat_flags; -return -EBADR ; - } -return 0 ; -} -EXPORT_SYMBOL (fiemap_check_flags); - -static int fiemap_check_ranges (struct super_block *sb, -u64 start,u64 len,u64 *new_len) -{ -u64 maxbytes = (u64 ) sb->s_maxbytes; - - *new_len = len; - -if (len ==0 ) +if (*len ==0 )return -EINVAL ; -if (start > maxbytes)return -EFBIG ;/* * Shrink request scope to what the fs can actually handle. */ -if (len > maxbytes || (maxbytes - len) < start) - *new_len = maxbytes - start; +if (*len > maxbytes || (maxbytes - *len) < start) + *len = maxbytes - start; + supported_flags &=FIEMAP_FLAGS_COMPAT ; + incompat_flags = fieinfo->fi_flags & ~supported_flags; +if (incompat_flags) { + fieinfo->fi_flags = incompat_flags; +return -EBADR ; + }return 0 ; } +EXPORT_SYMBOL (fiemap_prep);static int ioctl_fiemap (struct file *filp,struct fiemap __user *ufiemap) {struct fiemap fiemap;struct fiemap_extent_info fieinfo = {0 , };struct inode *inode =file_inode (filp); -struct super_block *sb = inode->i_sb; -u64 len;int error;if (!inode->i_op->fiemap)@@ -207,11 +200,6 @@ static int ioctl_fiemap(struct file *filp, struct fiemap __user *ufiemap)if (fiemap.fm_extent_count >FIEMAP_MAX_EXTENTS )return -EINVAL ; - error =fiemap_check_ranges (sb, fiemap.fm_start, fiemap.fm_length, - &len); -if (error) -return error; - fieinfo.fi_flags = fiemap.fm_flags; fieinfo.fi_extents_max = fiemap.fm_extent_count; fieinfo.fi_extents_start = ufiemap->fm_extents;@@ -224,7 +212,8 @@ static int ioctl_fiemap(struct file *filp, struct fiemap __user *ufiemap)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_start, + fiemap.fm_length); fiemap.fm_flags = fieinfo.fi_flags; fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;if (copy_to_user (ufiemap, &fiemap,sizeof (fiemap)))@@ -312,7 +301,7 @@ static 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_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC );if (ret)return ret;fs/iomap/fiemap.c +1
-1@@ -75,7 +75,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_prep (inode, fi, start, &len,FIEMAP_FLAG_SYNC );if (ret)return ret;fs/nilfs2/inode.c +1
-1@@ -1006,7 +1006,7 @@ int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,unsigned int blkbits = inode->i_blkbits;int ret, n; - ret =fiemap_check_flags (fieinfo,FIEMAP_FLAG_SYNC ); + ret =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC );if (ret)return ret;fs/ocfs2/extent_map.c +2
-1@@ -746,7 +746,8 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,struct buffer_head *di_bh =NULL ;struct ocfs2_extent_rec rec; - ret =fiemap_check_flags (fieinfo,OCFS2_FIEMAP_FLAGS ); + ret =fiemap_prep (inode, fieinfo, map_start, &map_len, +OCFS2_FIEMAP_FLAGS );if (ret)return ret;include/linux/fiemap.h +0
-0
include/linux/fiemap.h struct fiemap_extent_info { · line 20
Quoted 9 lines
include/linux/fiemap.h +2
-1@@ -13,9 +13,10 @@ struct fiemap_extent_info {fiemap_extent array */ }; +int fiemap_prep (struct inode *inode,struct fiemap_extent_info *fieinfo, +u64 start,u64 *len,u32 supported_flags);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);
While we are at it, could remove this above additional line as well.
Quoted 3 lines
include/linux/fiemap.h +0
-0int generic_block_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 start, u64 len,
Re: [PATCH 08/11] fs: move fiemap range validation into the file systems instances
Quoted 5 lines · Ritesh Harjani
Documentation/filesystems/fiemap.txt EINTR once fatal signal received. · line 206
Quoted 2 lines
Documentation/filesystems/fiemap.txt +1
-1-int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags); +fiemap_prep() helper.Let's add the
fiemap_prep()function prototype here. So that below description would make more sense.
The annoying tendency to copy prototypes into docs just means they get out of date. Anyone who can't do a quick grep should not be writing code. I've added it back for consistency, but we really should remove all of them in this file.
Quoted 4 lines
Quoted 4 lines
ioctl_fiemap(). The
set of fiemap flags which the fs understands should be passed viafs_flags. IfDocumentation/filesystems/fiemap.txt +1
-1-fiemap_check_flags finds invalid user flags, it will place the bad values in +fiemap_prep finds invalid user flags, it will place the bad values in
Quoted 8 lines
Documentation/filesystems/fiemap.txt EINTR once fatal signal received. · line 213
Quoted 4 lines
fieinfo->fi_flagsand return-EBADR. If the file system gets-EBADR, fromDocumentation/filesystems/fiemap.txt +1
-1-fiemap_check_flags(), it should immediately exit, returning that error back to +fiemap_prep(), it should immediately exit, returning that error back to ioctl_fiemap().Also maybe we should also add more info about
fiemap_prep()helper. Since it also checks for invalid len and invalid start range and hence could return-EINVALor-EFBIG.
I've added it. But this kind of documentation that just badly spells out what is done is not very useful. A quick look at the function conveys the information much better.
Quoted 11 lines
fs/cifs/smb2ops.c static int smb3_fiemap(struct cifs_tcon *tcon, · line 3412
Quoted 9 lines
fs/cifs/smb2ops.c +2
-1@@ -3408,8 +3408,10 @@ static int smb3_fiemap(struct cifs_tcon *tcon,int i, num, rc, flags, last_blob;u64 next; - if (fiemap_check_flags(fei, FIEMAP_FLAG_SYNC)) - return -EBADR; + rc = fiemap_prep(cfile->dentry->d_inode, fei, start, &len, +FIEMAP_FLAG_SYNC );How about
d_inode(cfile->dentry)?
Ok.
Quoted 4 lines
fs/cifs/smb2ops.c static int smb3_fiemap(struct cifs_tcon *tcon, · line 3414
Quoted 2 lines
fs/cifs/smb2ops.c +2
-0+if (rc) + rc;missed "return rc" here?
Indeed.
Quoted 11 lines
fs/cifs/smb2ops.c static int smb3_fiemap(struct cifs_tcon *tcon,
Quoted 6 lines
fs/cifs/smb2ops.c +3
-0+* @start: Start of the mapped range +* @len: Length of the mapped range, can be truncated by this function. +* @supported_flags: Set of fiemap flags that the file system understands * * Called from file system ->fiemap callback. This will compute the * intersection of valid fiemap flags and those that the fs supports. That Let's also add more documentation about this new
fiemap_prep()helper. Earlier comments above this function description only talks about incompat flags. We should add more info aboutcheck_rangespart as well here.
Seriously, the details are in the f^$^$ing code. No need to have an easily out of sync version of the code in the comment. I'll just radically shorten this.
PATCH 9/11 fs: handle FIEMAP_FLAG_SYNC in fiemap_prep
In reply to Christoph HellwigBy moving FIEMAP_FLAG_SYNC handling to fiemap_prep we ensure it is handled once instead of duplicated, but can still be done under fs locks, like xfs/iomap intended with its duplicate handling. Also make sure the error value of filemap_write_and_wait is propagated to user space.
--- fs/btrfs/inode.c | 4 +--- fs/cifs/smb2ops.c | 3 +-- fs/ext4/extents.c | 2 +- fs/f2fs/data.c | 3 +-- fs/ioctl.c | 10 ++++++---- fs/iomap/fiemap.c | 8 +------- fs/nilfs2/inode.c | 2 +- fs/ocfs2/extent_map.c | 5 +---- fs/overlayfs/inode.c | 4 ---- 9 files changed, 13 insertions(+), 28 deletions(-)
fs/btrfs/inode.c +1 -3
@@ -8243,14 +8243,12 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)return ret; } -#define BTRFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC) -static int btrfs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,__u64 start,__u64 len) {int ret; - ret =fiemap_prep (inode, fieinfo, start, &len,BTRFS_FIEMAP_FLAGS ); + ret =fiemap_prep (inode, fieinfo, start, &len,0 );if (ret)return ret;
fs/cifs/smb2ops.c +1 -2
@@ -3408,8 +3408,7 @@ static int smb3_fiemap(struct cifs_tcon *tcon,int i, num, rc, flags, last_blob;u64 next; - rc =fiemap_prep (cfile->dentry->d_inode, fei, start, &len, -FIEMAP_FLAG_SYNC ); + rc =fiemap_prep (cfile->dentry->d_inode, fei, start, &len,0 );if (rc) rc;
fs/ext4/extents.c +1 -1
@@ -4908,7 +4908,7 @@ int ext4_get_es_cache(struct inode *inode, struct fiemap_extent_info *fieinfo, fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE ; } - error =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC ); + error =fiemap_prep (inode, fieinfo, start, &len,0 );if (error)return error;
fs/f2fs/data.c +1 -2
@@ -1825,8 +1825,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,return ret; } - ret =fiemap_prep (inode, fieinfo, start, &len, -FIEMAP_FLAG_SYNC |FIEMAP_FLAG_XATTR ); + ret =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_XATTR );if (ret)return ret;
fs/ioctl.c +6 -4
@@ -162,6 +162,7 @@ int fiemap_prep(struct inode *inode, struct fiemap_extent_info *fieinfo, {u64 maxbytes = inode->i_sb->s_maxbytes;u32 incompat_flags; +int ret =0 ;if (*len ==0 )return -EINVAL ;
@@ -174,13 +175,17 @@ int fiemap_prep(struct inode *inode, struct fiemap_extent_info *fieinfo,if (*len > maxbytes || (maxbytes - *len) < start) *len = maxbytes - start; + supported_flags |=FIEMAP_FLAG_SYNC ; supported_flags &=FIEMAP_FLAGS_COMPAT ; incompat_flags = fieinfo->fi_flags & ~supported_flags;if (incompat_flags) { fieinfo->fi_flags = incompat_flags;return -EBADR ; } -return 0 ; + +if (fieinfo->fi_flags &FIEMAP_FLAG_SYNC ) + ret =filemap_write_and_wait (inode->i_mapping); +return ret; }EXPORT_SYMBOL (fiemap_prep);
@@ -209,9 +214,6 @@ static int ioctl_fiemap(struct file *filp, struct fiemap __user *ufiemap) fieinfo.fi_extents_max * sizeof(struct fiemap_extent)))return -EFAULT ; -if (fieinfo.fi_flags &FIEMAP_FLAG_SYNC ) -filemap_write_and_wait (inode->i_mapping); - error = inode->i_op->fiemap (inode, &fieinfo, fiemap.fm_start, fiemap.fm_length); fiemap.fm_flags = fieinfo.fi_flags;
fs/iomap/fiemap.c +1 -7
@@ -75,16 +75,10 @@ int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi, ctx.fi = fi; ctx.prev.type =IOMAP_HOLE ; - ret =fiemap_prep (inode, fi, start, &len,FIEMAP_FLAG_SYNC ); + ret =fiemap_prep (inode, fi, start, &len,0 );if (ret)return ret; -if (fi->fi_flags &FIEMAP_FLAG_SYNC ) { - ret =filemap_write_and_wait (inode->i_mapping); -if (ret) -return ret; - } -while (len >0 ) { ret =iomap_apply (inode, start, len,IOMAP_REPORT , ops, &ctx, iomap_fiemap_actor);
fs/nilfs2/inode.c +1 -1
@@ -1006,7 +1006,7 @@ int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,unsigned int blkbits = inode->i_blkbits;int ret, n; - ret =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC ); + ret =fiemap_prep (inode, fieinfo, start, &len,0 );if (ret)return ret;
fs/ocfs2/extent_map.c +1 -4
@@ -733,8 +733,6 @@ static int ocfs2_fiemap_inline(struct inode *inode, struct buffer_head *di_bh,return 0 ; } -#define OCFS2_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC) -int ocfs2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 map_start,u64 map_len) {
@@ -746,8 +744,7 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,struct buffer_head *di_bh =NULL ;struct ocfs2_extent_rec rec; - ret =fiemap_prep (inode, fieinfo, map_start, &map_len, -OCFS2_FIEMAP_FLAGS ); + ret =fiemap_prep (inode, fieinfo, map_start, &map_len,0 );if (ret)return ret;
fs/overlayfs/inode.c +0 -4
@@ -462,10 +462,6 @@ static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,return -EOPNOTSUPP ; old_cred =ovl_override_creds (inode->i_sb); - -if (fieinfo->fi_flags &FIEMAP_FLAG_SYNC ) -filemap_write_and_wait (realinode->i_mapping); - err = realinode->i_op->fiemap (realinode, fieinfo, start, len);revert_creds (old_cred);
Signature · 1 line
2.26.1
Re: [PATCH 09/11] fs: handle FIEMAP_FLAG_SYNC in fiemap_prep
Quoted 7 lines · Christoph Hellwig
By moving
FIEMAP_FLAG_SYNChandling tofiemap_prepwe ensure it is handled once instead of duplicated, but can still be done under fs locks, like xfs/iomap intended with its duplicate handling. Also make sure the error value offilemap_write_and_waitis propagated to user space.Signed-off-by Christoph Hellwig <[email protected]>
Nice!
Thanks for fixing this,
Amir.
Re: [PATCH 09/11] fs: handle FIEMAP_FLAG_SYNC in fiemap_prep
In reply to Christoph HellwigQuoted 6 lines · Christoph Hellwig
By moving
FIEMAP_FLAG_SYNChandling tofiemap_prepwe ensure it is handled once instead of duplicated, but can still be done under fs locks, like xfs/iomap intended with its duplicate handling. Also make sure the error value offilemap_write_and_waitis propagated to user space.Signed-off-by Christoph Hellwig <[email protected]>
Seems reasonable,
--D
Quoted 190 lines
--- fs/btrfs/inode.c | 4 +--- fs/cifs/smb2ops.c | 3 +-- fs/ext4/extents.c | 2 +- fs/f2fs/data.c | 3 +-- fs/ioctl.c | 10 ++++++---- fs/iomap/fiemap.c | 8 +------- fs/nilfs2/inode.c | 2 +- fs/ocfs2/extent_map.c | 5 +---- fs/overlayfs/inode.c | 4 ---- 9 files changed, 13 insertions(+), 28 deletions(-)fs/btrfs/inode.c +1
-3@@ -8243,14 +8243,12 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)return ret; } -#define BTRFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC) -static int btrfs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,__u64 start,__u64 len) {int ret; - ret =fiemap_prep (inode, fieinfo, start, &len,BTRFS_FIEMAP_FLAGS ); + ret =fiemap_prep (inode, fieinfo, start, &len,0 );if (ret)return ret;fs/cifs/smb2ops.c +1
-2@@ -3408,8 +3408,7 @@ static int smb3_fiemap(struct cifs_tcon *tcon,int i, num, rc, flags, last_blob;u64 next; - rc =fiemap_prep (cfile->dentry->d_inode, fei, start, &len, -FIEMAP_FLAG_SYNC ); + rc =fiemap_prep (cfile->dentry->d_inode, fei, start, &len,0 );if (rc) rc;fs/ext4/extents.c +1
-1@@ -4908,7 +4908,7 @@ int ext4_get_es_cache(struct inode *inode, struct fiemap_extent_info *fieinfo, fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE ; } - error =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC ); + error =fiemap_prep (inode, fieinfo, start, &len,0 );if (error)return error;fs/f2fs/data.c +1
-2@@ -1825,8 +1825,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,return ret; } - ret =fiemap_prep (inode, fieinfo, start, &len, -FIEMAP_FLAG_SYNC |FIEMAP_FLAG_XATTR ); + ret =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_XATTR );if (ret)return ret;fs/ioctl.c +6
-4@@ -162,6 +162,7 @@ int fiemap_prep(struct inode *inode, struct fiemap_extent_info *fieinfo, {u64 maxbytes = inode->i_sb->s_maxbytes;u32 incompat_flags; +int ret =0 ;if (*len ==0 )return -EINVAL ;@@ -174,13 +175,17 @@ int fiemap_prep(struct inode *inode, struct fiemap_extent_info *fieinfo,if (*len > maxbytes || (maxbytes - *len) < start) *len = maxbytes - start; + supported_flags |=FIEMAP_FLAG_SYNC ; supported_flags &=FIEMAP_FLAGS_COMPAT ; incompat_flags = fieinfo->fi_flags & ~supported_flags;if (incompat_flags) { fieinfo->fi_flags = incompat_flags;return -EBADR ; } -return 0 ; + +if (fieinfo->fi_flags &FIEMAP_FLAG_SYNC ) + ret =filemap_write_and_wait (inode->i_mapping); +return ret; }EXPORT_SYMBOL (fiemap_prep);@@ -209,9 +214,6 @@ static int ioctl_fiemap(struct file *filp, struct fiemap __user *ufiemap) fieinfo.fi_extents_max * sizeof(struct fiemap_extent)))return -EFAULT ; -if (fieinfo.fi_flags &FIEMAP_FLAG_SYNC ) -filemap_write_and_wait (inode->i_mapping); - error = inode->i_op->fiemap (inode, &fieinfo, fiemap.fm_start, fiemap.fm_length); fiemap.fm_flags = fieinfo.fi_flags;fs/iomap/fiemap.c +1
-7@@ -75,16 +75,10 @@ int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi, ctx.fi = fi; ctx.prev.type =IOMAP_HOLE ; - ret =fiemap_prep (inode, fi, start, &len,FIEMAP_FLAG_SYNC ); + ret =fiemap_prep (inode, fi, start, &len,0 );if (ret)return ret; -if (fi->fi_flags &FIEMAP_FLAG_SYNC ) { - ret =filemap_write_and_wait (inode->i_mapping); -if (ret) -return ret; - } -while (len >0 ) { ret =iomap_apply (inode, start, len,IOMAP_REPORT , ops, &ctx, iomap_fiemap_actor);fs/nilfs2/inode.c +1
-1@@ -1006,7 +1006,7 @@ int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,unsigned int blkbits = inode->i_blkbits;int ret, n; - ret =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC ); + ret =fiemap_prep (inode, fieinfo, start, &len,0 );if (ret)return ret;fs/ocfs2/extent_map.c +1
-4@@ -733,8 +733,6 @@ static int ocfs2_fiemap_inline(struct inode *inode, struct buffer_head *di_bh,return 0 ; } -#define OCFS2_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC) -int ocfs2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 map_start,u64 map_len) {@@ -746,8 +744,7 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,struct buffer_head *di_bh =NULL ;struct ocfs2_extent_rec rec; - ret =fiemap_prep (inode, fieinfo, map_start, &map_len, -OCFS2_FIEMAP_FLAGS ); + ret =fiemap_prep (inode, fieinfo, map_start, &map_len,0 );if (ret)return ret;fs/overlayfs/inode.c +0
-4@@ -462,10 +462,6 @@ static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,return -EOPNOTSUPP ; old_cred =ovl_override_creds (inode->i_sb); - -if (fieinfo->fi_flags &FIEMAP_FLAG_SYNC ) -filemap_write_and_wait (realinode->i_mapping); - err = realinode->i_op->fiemap (realinode, fieinfo, start, len);revert_creds (old_cred);Signature · 1 line
2.26.1
Re: [PATCH 09/11] fs: handle FIEMAP_FLAG_SYNC in fiemap_prep
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
By moving
FIEMAP_FLAG_SYNChandling tofiemap_prepwe ensure it is handled once instead of duplicated, but can still be done under fs locks, like xfs/iomap intended with its duplicate handling. Also make sure the error value offilemap_write_and_waitis propagated to user space.
Forgot to remove filemap_write_and_wait() fromext4_ioctl_get_es_cache() ?
Quoted 93 lines
Signed-off-by Christoph Hellwig <[email protected]>--- fs/btrfs/inode.c | 4 +--- fs/cifs/smb2ops.c | 3 +-- fs/ext4/extents.c | 2 +- fs/f2fs/data.c | 3 +-- fs/ioctl.c | 10 ++++++---- fs/iomap/fiemap.c | 8 +------- fs/nilfs2/inode.c | 2 +- fs/ocfs2/extent_map.c | 5 +---- fs/overlayfs/inode.c | 4 ---- 9 files changed, 13 insertions(+), 28 deletions(-)fs/btrfs/inode.c +1
-3@@ -8243,14 +8243,12 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)return ret; } -#define BTRFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC) -static int btrfs_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,__u64 start,__u64 len) {int ret; - ret =fiemap_prep (inode, fieinfo, start, &len,BTRFS_FIEMAP_FLAGS ); + ret =fiemap_prep (inode, fieinfo, start, &len,0 );if (ret)return ret;fs/cifs/smb2ops.c +1
-2@@ -3408,8 +3408,7 @@ static int smb3_fiemap(struct cifs_tcon *tcon,int i, num, rc, flags, last_blob;u64 next; - rc =fiemap_prep (cfile->dentry->d_inode, fei, start, &len, -FIEMAP_FLAG_SYNC ); + rc =fiemap_prep (cfile->dentry->d_inode, fei, start, &len,0 );if (rc) rc;fs/ext4/extents.c +1
-1@@ -4908,7 +4908,7 @@ int ext4_get_es_cache(struct inode *inode, struct fiemap_extent_info *fieinfo, fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE ; } - error =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC ); + error =fiemap_prep (inode, fieinfo, start, &len,0 );if (error)return error;fs/f2fs/data.c +1
-2@@ -1825,8 +1825,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,return ret; } - ret =fiemap_prep (inode, fieinfo, start, &len, -FIEMAP_FLAG_SYNC |FIEMAP_FLAG_XATTR ); + ret =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_XATTR );if (ret)return ret;fs/ioctl.c +2
-0@@ -162,6 +162,7 @@ int fiemap_prep(struct inode *inode, struct fiemap_extent_info *fieinfo, {u64 maxbytes = inode->i_sb->s_maxbytes;u32 incompat_flags; +int ret =0 ;if (*len ==0 )return -EINVAL ;@@ -174,13 +175,17 @@ int fiemap_prep(struct inode *inode, struct fiemap_extent_info *fieinfo,if (*len > maxbytes || (maxbytes - *len) < start) *len = maxbytes - start; + supported_flags |=FIEMAP_FLAG_SYNC ; supported_flags &=FIEMAP_FLAGS_COMPAT ;
fs/ioctl.c int fiemap_prep(struct inode *inode, struct fiemap_extent_info *fieinfo, · line 188
Quoted 10 lines
fs/ioctl.c +4
-1incompat_flags = fieinfo->fi_flags & ~supported_flags;if (incompat_flags) { fieinfo->fi_flags = incompat_flags;return -EBADR ; } -return 0 ; + +if (fieinfo->fi_flags &FIEMAP_FLAG_SYNC ) + ret =filemap_write_and_wait (inode->i_mapping); +return ret;
Since we could return an error from here.
I think we should again update the function description that it could return a negative error value if filemap_write_and_wait() fails. And also should document this in Documentation/*
Quoted 87 lines
fs/ioctl.c +0
-3}EXPORT_SYMBOL (fiemap_prep);@@ -209,9 +214,6 @@ static int ioctl_fiemap(struct file *filp, struct fiemap __user *ufiemap) fieinfo.fi_extents_max * sizeof(struct fiemap_extent)))return -EFAULT ; -if (fieinfo.fi_flags &FIEMAP_FLAG_SYNC ) -filemap_write_and_wait (inode->i_mapping); - error = inode->i_op->fiemap (inode, &fieinfo, fiemap.fm_start, fiemap.fm_length); fiemap.fm_flags = fieinfo.fi_flags;fs/iomap/fiemap.c +1
-7@@ -75,16 +75,10 @@ int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi, ctx.fi = fi; ctx.prev.type =IOMAP_HOLE ; - ret =fiemap_prep (inode, fi, start, &len,FIEMAP_FLAG_SYNC ); + ret =fiemap_prep (inode, fi, start, &len,0 );if (ret)return ret; -if (fi->fi_flags &FIEMAP_FLAG_SYNC ) { - ret =filemap_write_and_wait (inode->i_mapping); -if (ret) -return ret; - } -while (len >0 ) { ret =iomap_apply (inode, start, len,IOMAP_REPORT , ops, &ctx, iomap_fiemap_actor);fs/nilfs2/inode.c +1
-1@@ -1006,7 +1006,7 @@ int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,unsigned int blkbits = inode->i_blkbits;int ret, n; - ret =fiemap_prep (inode, fieinfo, start, &len,FIEMAP_FLAG_SYNC ); + ret =fiemap_prep (inode, fieinfo, start, &len,0 );if (ret)return ret;fs/ocfs2/extent_map.c +1
-4@@ -733,8 +733,6 @@ static int ocfs2_fiemap_inline(struct inode *inode, struct buffer_head *di_bh,return 0 ; } -#define OCFS2_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC) -int ocfs2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 map_start,u64 map_len) {@@ -746,8 +744,7 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,struct buffer_head *di_bh =NULL ;struct ocfs2_extent_rec rec; - ret =fiemap_prep (inode, fieinfo, map_start, &map_len, -OCFS2_FIEMAP_FLAGS ); + ret =fiemap_prep (inode, fieinfo, map_start, &map_len,0 );if (ret)return ret;fs/overlayfs/inode.c +0
-4@@ -462,10 +462,6 @@ static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,return -EOPNOTSUPP ; old_cred =ovl_override_creds (inode->i_sb); - -if (fieinfo->fi_flags &FIEMAP_FLAG_SYNC ) -filemap_write_and_wait (realinode->i_mapping); - err = realinode->i_op->fiemap (realinode, fieinfo, start, len);revert_creds (old_cred);
Re: [PATCH 09/11] fs: handle FIEMAP_FLAG_SYNC in fiemap_prep
Quoted 11 lines · Ritesh Harjani
Quoted 4 lines · Christoph Hellwig
By moving
FIEMAP_FLAG_SYNChandling tofiemap_prepwe ensure it is handled once instead of duplicated, but can still be done under fs locks, like xfs/iomap intended with its duplicate handling. Also make sure the error value offilemap_write_and_waitis propagated to user space.Forgot to remove
filemap_write_and_wait()fromext4_ioctl_get_es_cache()?
Fixed.
PATCH 10/11 fs: remove the access_ok() check in ioctl_fiemap
In reply to Christoph Hellwigaccess_ok just checks we are fed a proper user pointer. We also do that in copy_to_user itself, so no need to do this early.
--- fs/ioctl.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
fs/ioctl.c +1 -5
@@ -209,13 +209,9 @@ static int ioctl_fiemap(struct file *filp, struct fiemap __user *ufiemap) fieinfo.fi_extents_max = fiemap.fm_extent_count; fieinfo.fi_extents_start = ufiemap->fm_extents; -if (fiemap.fm_extent_count !=0 && - !access_ok (fieinfo.fi_extents_start, - fieinfo.fi_extents_max *sizeof (struct fiemap_extent ))) -return -EFAULT ; - error = inode->i_op->fiemap (inode, &fieinfo, fiemap.fm_start, fiemap.fm_length); + fiemap.fm_flags = fieinfo.fi_flags; fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;if (copy_to_user (ufiemap, &fiemap,sizeof (fiemap)))
Signature · 1 line
2.26.1
Re: [PATCH 10/11] fs: remove the access_ok() check in ioctl_fiemap
Quoted 4 lines · Christoph Hellwig
access_okjust checks we are fed a proper user pointer. We also do that incopy_to_useritself, so no need to do this early.Signed-off-by Christoph Hellwig <[email protected]>
Hmm. It's a minor behavioral change that we no longer require the entire extent array to be accessible at the start even if parts of it would never have gotten accessed, but I don't think that matters, so:
--D
Quoted 26 lines
--- fs/ioctl.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)fs/ioctl.c +1
-5@@ -209,13 +209,9 @@ static int ioctl_fiemap(struct file *filp, struct fiemap __user *ufiemap) fieinfo.fi_extents_max = fiemap.fm_extent_count; fieinfo.fi_extents_start = ufiemap->fm_extents; -if (fiemap.fm_extent_count !=0 && - !access_ok (fieinfo.fi_extents_start, - fieinfo.fi_extents_max *sizeof (struct fiemap_extent ))) -return -EFAULT ; - error = inode->i_op->fiemap (inode, &fieinfo, fiemap.fm_start, fiemap.fm_length); + fiemap.fm_flags = fieinfo.fi_flags; fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;if (copy_to_user (ufiemap, &fiemap,sizeof (fiemap)))Signature · 1 line
2.26.1
Re: [PATCH 10/11] fs: remove the access_ok() check in ioctl_fiemap
Quoted 9 lines · Darrick J. Wong
Quoted 4 lines · Christoph Hellwig
access_okjust checks we are fed a proper user pointer. We also do that incopy_to_useritself, so no need to do this early.Signed-off-by Christoph Hellwig <[email protected]>Hmm. It's a minor behavioral change that we no longer require the entire extent array to be accessible at the start even if parts of it would never have gotten accessed, but I don't think that matters, so:
Note that access_ok only checks if the memory actually is in userspace, so they only thing seeing a behavior difference would be an exploit of some kind.
Re: [PATCH 10/11] fs: remove the access_ok() check in ioctl_fiemap
In reply to Christoph HellwigQuoted 2 lines · Christoph Hellwig
access_okjust checks we are fed a proper user pointer. We also do that incopy_to_useritself, so no need to do this early.
Ok.
Quoted 2 lines
Signed-off-by Christoph Hellwig <[email protected]>
Looks fine. Feel free to add
Quoted 24 lines
--- fs/ioctl.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)fs/ioctl.c +1
-5@@ -209,13 +209,9 @@ static int ioctl_fiemap(struct file *filp, struct fiemap __user *ufiemap) fieinfo.fi_extents_max = fiemap.fm_extent_count; fieinfo.fi_extents_start = ufiemap->fm_extents; -if (fiemap.fm_extent_count !=0 && - !access_ok (fieinfo.fi_extents_start, - fieinfo.fi_extents_max *sizeof (struct fiemap_extent ))) -return -EFAULT ; - error = inode->i_op->fiemap (inode, &fieinfo, fiemap.fm_start, fiemap.fm_length); + fiemap.fm_flags = fieinfo.fi_flags; fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;if (copy_to_user (ufiemap, &fiemap,sizeof (fiemap)))
PATCH 11/11 ext4: remove the access_ok() check in ext4_ioctl_get_es_cache
In reply to Christoph Hellwigaccess_ok just checks we are fed a proper user pointer. We also do that in copy_to_user itself, so no need to do this early.
--- fs/ext4/ioctl.c | 5 ----- 1 file changed, 5 deletions(-)
fs/ext4/ioctl.c +0 -5
@@ -754,11 +754,6 @@ static int ext4_ioctl_get_es_cache(struct file *filp, unsigned long arg) fieinfo.fi_extents_max = fiemap.fm_extent_count; fieinfo.fi_extents_start = ufiemap->fm_extents; -if (fiemap.fm_extent_count !=0 && - !access_ok (fieinfo.fi_extents_start, - fieinfo.fi_extents_max *sizeof (struct fiemap_extent ))) -return -EFAULT ; -if (fieinfo.fi_flags &FIEMAP_FLAG_SYNC )filemap_write_and_wait (inode->i_mapping);
Signature · 1 line
2.26.1
Re: [PATCH 11/11] ext4: remove the access_ok() check in ext4_ioctl_get_es_cache
Quoted 4 lines · Christoph Hellwig
access_okjust checks we are fed a proper user pointer. We also do that incopy_to_useritself, so no need to do this early.Signed-off-by Christoph Hellwig <[email protected]>
Looks fine. Feel free to add
Quoted 21 lines
--- fs/ext4/ioctl.c | 5 ----- 1 file changed, 5 deletions(-)fs/ext4/ioctl.c +0
-5@@ -754,11 +754,6 @@ static int ext4_ioctl_get_es_cache(struct file *filp, unsigned long arg) fieinfo.fi_extents_max = fiemap.fm_extent_count; fieinfo.fi_extents_start = ufiemap->fm_extents; -if (fiemap.fm_extent_count !=0 && - !access_ok (fieinfo.fi_extents_start, - fieinfo.fi_extents_max *sizeof (struct fiemap_extent ))) -return -EFAULT ; -if (fieinfo.fi_flags &FIEMAP_FLAG_SYNC )filemap_write_and_wait (inode->i_mapping);