ext4: SEEK_HOLE / SEEK_DATA via iomap
Subsystems (8)
v2 cover ext4: SEEK_HOLE / SEEK_DATA via iomap
Add IOMAP_REPORT support to ext4, including support for inline data which iomap couldn't report so far. Switch to iomap_seek_{hole,data} on ext4.
This patch series should be ready to be merged.
Andreas Gruenbacher (3):
iomap: Switch from blkno to disk offset
iomap: Add IOMAP_F_DATA_INLINE flag
ext4: Add iomap support for inline data
Christoph Hellwig (1):
ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
fs/buffer.c | 4 +- fs/dax.c | 2 +- fs/ext2/inode.c | 4 +- fs/ext4/Kconfig | 1 + fs/ext4/ext4.h | 7 +- fs/ext4/file.c | 263 +++----------------------------------------------- fs/ext4/inline.c | 33 +++++++ fs/ext4/inode.c | 149 +++++++++++++--------------- fs/iomap.c | 13 +-- fs/nfsd/blocklayout.c | 4 +- fs/xfs/xfs_iomap.c | 6 +- include/linux/iomap.h | 15 +-- 12 files changed, 142 insertions(+), 359 deletions(-)
Signature · 1 line
2.13.3
PATCH v2 1/4 iomap: Switch from blkno to disk offset
Replace iomap->blkno, the sector number, with iomap->addr, the disk offset in bytes. For invalid disk offsets, use the special value IOMAP_NULL_ADDR instead of IOMAP_NULL_BLOCK.
This allows to use iomap for mappings which are not block aligned, such as inline data on ext4.
--- fs/buffer.c | 4 ++-- fs/dax.c | 2 +- fs/ext2/inode.c | 4 ++-- fs/ext4/inode.c | 4 ++-- fs/iomap.c | 11 +++++------ fs/nfsd/blocklayout.c | 4 ++-- fs/xfs/xfs_iomap.c | 6 +++--- include/linux/iomap.h | 10 +++++----- 8 files changed, 22 insertions(+), 23 deletions(-)
fs/buffer.c +2 -2
@@ -1978,8 +1978,8 @@ iomap_to_bh(struct inode *inode, sector_t block, struct buffer_head *bh,case IOMAP_MAPPED :if (offset >=i_size_read (inode))set_buffer_new (bh); - bh->b_blocknr = (iomap->blkno >> (inode->i_blkbits -9 )) + - ((offset - iomap->offset) >> inode->i_blkbits); + bh->b_blocknr = (iomap->addr + offset - iomap->offset) >> + inode->i_blkbits;set_buffer_mapped (bh);break ; }
fs/dax.c +1 -1
@@ -938,7 +938,7 @@ EXPORT_SYMBOL_GPL(__dax_zero_page_range);static sector_t dax_iomap_sector (struct iomap *iomap,loff_t pos) { -return iomap->blkno + (((pos &PAGE_MASK ) - iomap->offset) >>9 ); +return (iomap->addr + (pos &PAGE_MASK ) - iomap->offset) >>9 ; } static loff_t
fs/ext2/inode.c +2 -2
@@ -820,11 +820,11 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length,if (ret ==0 ) { iomap->type =IOMAP_HOLE ; - iomap->blkno =IOMAP_NULL_BLOCK ; + iomap->addr =IOMAP_NULL_ADDR ; iomap->length =1 << blkbits; }else { iomap->type =IOMAP_MAPPED ; - iomap->blkno = (sector_t )bno << (blkbits -9 ); + iomap->addr = (u64 )bno << blkbits; iomap->length = (u64 )ret << blkbits; iomap->flags |=IOMAP_F_MERGED ; }
fs/ext4/inode.c +2 -2
@@ -3472,7 +3472,7 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,if (ret ==0 ) { iomap->type =IOMAP_HOLE ; - iomap->blkno =IOMAP_NULL_BLOCK ; + iomap->addr =IOMAP_NULL_ADDR ; iomap->length = (u64 )map.m_len << blkbits; }else {if (map.m_flags &EXT4_MAP_MAPPED ) {
@@ -3483,7 +3483,7 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,WARN_ON_ONCE (1 );return -EIO ; } - iomap->blkno = (sector_t )map.m_pblk << (blkbits -9 ); + iomap->addr = (u64 )map.m_pblk << blkbits; iomap->length = (u64 )map.m_len << blkbits; }
fs/iomap.c +5 -6
@@ -350,8 +350,8 @@ static int iomap_zero(struct inode *inode, loff_t pos, unsigned offset,static int iomap_dax_zero (loff_t pos,unsigned offset,unsigned bytes,struct iomap *iomap) { -sector_t sector = iomap->blkno + - (((pos & ~(PAGE_SIZE -1 )) - iomap->offset) >>9 ); +sector_t sector = (iomap->addr + + (pos &PAGE_MASK ) - iomap->offset) >>9 ;return __dax_zero_page_range (iomap->bdev, iomap->dax_dev, sector, offset, bytes);
@@ -512,9 +512,8 @@ static int iomap_to_fiemap(struct fiemap_extent_info *fi, flags |=FIEMAP_EXTENT_SHARED ;return fiemap_fill_next_extent (fi, iomap->offset, - iomap->blkno !=IOMAP_NULL_BLOCK ? iomap->blkno <<9 :0 , + iomap->addr !=IOMAP_NULL_ADDR ? iomap->addr :0 , iomap->length, flags); - } static loff_t
@@ -807,7 +806,7 @@ iomap_dio_zero(struct iomap_dio *dio, struct iomap *iomap, loff_t pos, bio =bio_alloc (GFP_KERNEL ,1 );bio_set_dev (bio, iomap->bdev); bio->bi_iter.bi_sector = - iomap->blkno + ((pos - iomap->offset) >>9 ); + (iomap->addr + pos - iomap->offset) >>9 ; bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io;
@@ -886,7 +885,7 @@ iomap_dio_actor(struct inode *inode, loff_t pos, loff_t length, bio =bio_alloc (GFP_KERNEL , nr_pages);bio_set_dev (bio, iomap->bdev); bio->bi_iter.bi_sector = - iomap->blkno + ((pos - iomap->offset) >>9 ); + (iomap->addr + pos - iomap->offset) >>9 ; bio->bi_write_hint = dio->iocb->ki_hint; bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io;
fs/nfsd/blocklayout.c +2 -2
@@ -65,7 +65,7 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, bex->es =PNFS_BLOCK_READ_DATA ; else bex->es = PNFS_BLOCK_READWRITE_DATA; - bex->soff = (iomap.blkno <<9 ); + bex->soff = iomap.addr;break ;case IOMAP_UNWRITTEN :if (seg->iomode &IOMODE_RW ) {
@@ -78,7 +78,7 @@ nfsd4_block_proc_layoutget(struct inode *inode, const struct svc_fh *fhp, } bex->es =PNFS_BLOCK_INVALID_DATA ; - bex->soff = (iomap.blkno <<9 ); + bex->soff = iomap.addr;break ; }/*FALLTHRU*/
fs/xfs/xfs_iomap.c +3 -3
@@ -54,13 +54,13 @@ xfs_bmbt_to_iomap(struct xfs_mount *mp = ip->i_mount;if (imap->br_startblock ==HOLESTARTBLOCK ) { - iomap->blkno =IOMAP_NULL_BLOCK ; + iomap->addr =IOMAP_NULL_ADDR ; iomap->type =IOMAP_HOLE ; }else if (imap->br_startblock ==DELAYSTARTBLOCK ) { - iomap->blkno =IOMAP_NULL_BLOCK ; + iomap->addr =IOMAP_NULL_ADDR ; iomap->type =IOMAP_DELALLOC ; }else { - iomap->blkno =xfs_fsb_to_db (ip, imap->br_startblock); + iomap->addr =BBTOB (xfs_fsb_to_db (ip, imap->br_startblock));if (imap->br_state ==XFS_EXT_UNWRITTEN ) iomap->type =IOMAP_UNWRITTEN ;else
include/linux/iomap.h +5 -5
@@ -15,8 +15,8 @@ struct vm_fault;*/ #define IOMAP_HOLE 0x01/* no blocks allocated, need allocation */ #define IOMAP_DELALLOC 0x02/* delayed allocation blocks */ -#define IOMAP_MAPPED 0x03/* blocks allocated @blkno */ -#define IOMAP_UNWRITTEN 0x04/* blocks allocated @blkno in unwritten state */ +#define IOMAP_MAPPED 0x03/* blocks allocated at @addr */ +#define IOMAP_UNWRITTEN 0x04/* blocks allocated at @addr in unwritten state */ /* * Flags for all iomap mappings:
@@ -30,12 +30,12 @@ struct vm_fault;#define IOMAP_F_SHARED 0x20/* block shared with another file */ /* -* Magic value for blkno: +* Magic value for addr: */ -#define IOMAP_NULL_BLOCK -1LL/* blkno is not valid */ +#define IOMAP_NULL_ADDR -1ULL/* addr is not valid */ struct iomap { -sector_t blkno;/* 1st sector of mapping, 512b units */ +u64 addr;/* disk offset of mapping, bytes */ loff_t offset;/* file offset of mapping, bytes */ u64 length;/* length of mapping, bytes */ u16 type;/* type of mapping */
Signature · 1 line
2.13.3
PATCH v2 2/4 iomap: Add IOMAP_F_DATA_INLINE flag
In reply to Andreas GruenbacherAdd a new IOMAP_F_DATA_INLINE flag to indicate that a mapping is in a disk area that contains data as well as metadata. In iomap_fiemap, map this flag to FIEMAP_EXTENT_DATA_INLINE.
--- fs/iomap.c | 2 ++ include/linux/iomap.h | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-)
fs/iomap.c +2 -0
@@ -510,6 +510,8 @@ static int iomap_to_fiemap(struct fiemap_extent_info *fi, flags |=FIEMAP_EXTENT_MERGED ;if (iomap->flags &IOMAP_F_SHARED ) flags |=FIEMAP_EXTENT_SHARED ; +if (iomap->flags &IOMAP_F_DATA_INLINE ) + flags |=FIEMAP_EXTENT_DATA_INLINE ; return fiemap_fill_next_extent(fi, iomap->offset, iomap->addr != IOMAP_NULL_ADDR ? iomap->addr : 0,
include/linux/iomap.h +3 -2
@@ -26,8 +26,9 @@ struct vm_fault;/* * Flags that only need to be reported for IOMAP_REPORT requests: */ -#define IOMAP_F_MERGED 0x10/* contains multiple blocks/extents */ -#define IOMAP_F_SHARED 0x20/* block shared with another file */ +#define IOMAP_F_MERGED 0x10/* contains multiple blocks/extents */ +#define IOMAP_F_SHARED 0x20/* block shared with another file */ +#define IOMAP_F_DATA_INLINE 0x40/* data inline in the inode */ /* * Magic value for addr:
Signature · 1 line
2.13.3
PATCH v2 3/4 ext4: Add iomap support for inline data
In reply to Andreas GruenbacherReport inline data as a IOMAP_F_DATA_INLINE mapping. This allows to use iomap_seek_hole and iomap_seek_data in ext4_llseek and makes switching to iomap_fiemap in ext4_fiemap easier.
--- fs/ext4/ext4.h | 4 ++++ fs/ext4/inline.c | 33 +++++++++++++++++++++++++++++++++ fs/ext4/inode.c | 16 ++++++++++++++-- 3 files changed, 51 insertions(+), 2 deletions(-)
fs/ext4/ext4.h +4 -0
@@ -3048,6 +3048,10 @@ extern struct buffer_head *ext4_get_first_inline_block(struct inode *inode,extern int ext4_inline_data_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,int *has_inline,__u64 start,__u64 len); + +struct iomap ; +extern int ext4_inline_data_iomap (struct inode *inode,struct iomap *iomap); +extern int ext4_try_to_evict_inline_data (handle_t *handle,struct inode *inode,int needed);
fs/ext4/inline.c +33 -0
@@ -12,6 +12,7 @@* GNU General Public License for more details. */ +#include <linux/iomap.h> #include <linux/fiemap.h> #include "ext4_jbd2.h"
@@ -1827,6 +1828,38 @@ int ext4_destroy_inline_data(handle_t *handle, struct inode *inode)return ret; } +int ext4_inline_data_iomap (struct inode *inode,struct iomap *iomap) +{ +__u64 addr; +int error = -EAGAIN ; +struct ext4_iloc iloc; + +down_read (&EXT4_I (inode)->xattr_sem); +if (!ext4_has_inline_data (inode)) + goto out; + + error =ext4_get_inode_loc (inode, &iloc); +if (error) + goto out; + + addr = (__u64 )iloc.bh->b_blocknr << inode->i_sb->s_blocksize_bits; + addr += (char *)ext4_raw_inode (&iloc) - iloc.bh->b_data; + addr += offsetof(struct ext4_inode , i_block); + +brelse (iloc.bh); + + iomap->addr = addr; + iomap->offset =0 ; + iomap->length =min_t (loff_t,ext4_get_inline_size (inode), +i_size_read (inode)); + iomap->type =0 ; + iomap->flags =IOMAP_F_DATA_INLINE ; + +out: +up_read (&EXT4_I (inode)->xattr_sem); +return error; +} +int ext4_inline_data_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,int *has_inline,__u64 start,__u64 len)
fs/ext4/inode.c +14 -2
@@ -3404,8 +3404,20 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,struct ext4_map_blocks map;int ret; -if (WARN_ON_ONCE (ext4_has_inline_data (inode))) -return -ERANGE ; + +if (flags &IOMAP_REPORT ) { +if (ext4_has_inline_data (inode)) { + ret =ext4_inline_data_iomap (inode, iomap); +if (ret != -EAGAIN ) { +if (ret ==0 && offset >= iomap->length) + ret = -ENOENT ; +return ret; + } + } + }else { +if (WARN_ON_ONCE (ext4_has_inline_data (inode))) +return -ERANGE ; + } map.m_lblk = first_block; map.m_len = last_block - first_block +1 ;
Signature · 1 line
2.13.3
Theodore Ts'o
maintainerRe: [PATCH v2 3/4] ext4: Add iomap support for inline data
fs/ext4/inline.c int ext4_destroy_inline_data(handle_t *handle, struct inode *inode) · line 1839
Quoted 9 lines · Andreas Gruenbacher
fs/ext4/inline.c +9
-0+int ext4_inline_data_iomap (struct inode *inode,struct iomap *iomap) +{ +__u64 addr; +int error = -EAGAIN ; +struct ext4_iloc iloc; + +down_read (&EXT4_I (inode)->xattr_sem); +if (!ext4_has_inline_data (inode)) + goto out;
....
fs/ext4/inline.c int ext4_destroy_inline_data(handle_t *handle, struct inode *inode) · line 1861
Quoted 4 lines
fs/ext4/inline.c +4
-0+out: +up_read (&EXT4_I (inode)->xattr_sem); +return error; +}
If we race with the inline data flag getting cleared, ext4_iomap_begin() will return with -EAGAIN. As near as I can tell, this will get reflected all the way up to userspace, instead of having the retry happen in the kernel. Is this intentional?
It looks like a user visible change, no?
- Ted
Re: [PATCH v2 3/4] ext4: Add iomap support for inline data
Quoted 11 lines · Theodore Ts'o
fs/ext4/inline.c int ext4_destroy_inline_data(handle_t *handle, struct inode *inode) · line 1839
Quoted 9 lines · Andreas Gruenbacher
fs/ext4/inline.c +9
-0+int ext4_inline_data_iomap (struct inode *inode,struct iomap *iomap) +{ +__u64 addr; +int error = -EAGAIN ; +struct ext4_iloc iloc; + +down_read (&EXT4_I (inode)->xattr_sem); +if (!ext4_has_inline_data (inode)) + goto out;....
Quoted 8 lines
fs/ext4/inline.c int ext4_destroy_inline_data(handle_t *handle, struct inode *inode) · line 1861
Quoted 4 lines
fs/ext4/inline.c +4
-0+out: +up_read (&EXT4_I (inode)->xattr_sem); +return error; +}If we race with the inline data flag getting cleared,
ext4_iomap_begin()will return with-EAGAIN.
Actually, in that case, ext4_iomap_begin will treat the file as non-inline. It will not return -EAGAIN.
Quoted 5 lines
As near as I can tell,
this will get reflected all the way up to userspace, instead of having the retry happen in the kernel. Is this intentional?It looks like a user visible change, no?
That would be a bug.
Thanks,
Andreas
Theodore Ts'o
maintainerRe: [PATCH v2 3/4] ext4: Add iomap support for inline data
Quoted 5 lines · Andreas Gruenbacher
Quoted 2 lines
If we race with the inline data flag getting cleared,
ext4_iomap_begin()will return with-EAGAIN.Actually, in that case,
ext4_iomap_beginwill treat the file as non-inline. It will not return-EAGAIN.
Ah, thanks, I missed that.
- Ted
PATCH v2 4/4 ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
In reply to Andreas GruenbacherFrom: Christoph Hellwig <[email protected]>
Switch to the iomap_seek_hole and iomap_seek_data helpers for implementing lseek SEEK_HOLE / SEEK_DATA, and remove all the code that isn't needed any more.
Note that with this patch ext4 will now always depend on the iomap code instead of only when CONFIG_DAX is enabled, and it requires adding a call into the extent status tree for iomap_begin as well to properly deal with delalloc extents.
--- fs/ext4/Kconfig | 1 + fs/ext4/ext4.h | 3 - fs/ext4/file.c | 263 +++----------------------------------------------------- fs/ext4/inode.c | 131 +++++++++++----------------- 4 files changed, 65 insertions(+), 333 deletions(-)
fs/ext4/Kconfig +1 -0
@@ -37,6 +37,7 @@ config EXT4_FS select CRC16 select CRYPTO select CRYPTO_CRC32C + select FS_IOMAP help This is the next generation of the ext3 filesystem.
fs/ext4/ext4.h +0 -3
@@ -2515,9 +2515,6 @@ extern void ext4_da_update_reserve_space(struct inode *inode, int used, int quota_claim);extern int ext4_issue_zeroout (struct inode *inode,ext4_lblk_t lblk,ext4_fsblk_t pblk,ext4_lblk_t len); -extern int ext4_get_next_extent (struct inode *inode,ext4_lblk_t lblk, -unsigned int map_len, -struct extent_status *result);/* indirect.c */ extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
fs/ext4/file.c +14 -249
286 lines not on this page · raw message
fs/ext4/inode.c +50 -81
182 lines not on this page · raw message
Signature · 1 line
2.13.3
Re: [PATCH v2 4/4] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
Quoted 22 lines · Andreas Gruenbacher
fs/ext4/inode.c +15
-2@@ -3422,9 +3422,38 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, map.m_lblk = first_block; map.m_len = last_block - first_block +1 ; -if (!(flags &IOMAP_WRITE )) { +if (flags &IOMAP_REPORT ) { ret =ext4_map_blocks (NULL , inode, &map,0 ); - }else { +if (ret <0 ) +return ret; + +if (ret ==0 ) { +ext4_lblk_t end = map.m_lblk + map.m_len -1 ; +struct extent_status es; + +ext4_es_find_delayed_extent_range (inode, map.m_lblk, end, &es); + +if (!es.es_len || es.es_lblk > end) { +/* entire range is a hole */ + }else if (es.es_lblk > map.m_lblk) { +/* range starts with a hole */ + map.m_len = es.es_lblk - map.m_lblk;
fs/ext4/inode.c static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 3450
Quoted 10 lines
fs/ext4/inode.c +10
-0+ }else { +ext4_lblk_t offs =0 ; + +if (es.es_lblk < map.m_lblk) + offs = map.m_lblk - es.es_lblk; + map.m_lblk = es.es_lblk + offs; + map.m_pblk =ext4_es_pblock (&es) + offs; + map.m_len = es.es_len - offs; +if (ext4_es_is_unwritten (&es)) + map.m_flags |=EXT4_MAP_UNWRITTEN ;
This is not possible. If there is unwritten extent at map->m_lblk, then ext4_map_blocks() could not have possibly returned 0. So just delete this condition and set map.m_pblk to 0 since delalloc extent has no physical possition.
fs/ext4/inode.c static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 3452
Quoted 2 lines
fs/ext4/inode.c +2
-0+if (ext4_es_is_delayed (&es)) + delalloc = true;
Also ext4_es_is_delayed(&es) is guaranteed to be true since you've looked it up by ext4_es_find_delayed_extent_range(). So just set delalloc = true unconditionally.
Otherwise the patch looks good so after fixing up these small issues feel free to add:
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v2 4/4] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
2017-09-14 14:02 GMT+02:00 Jan Kara <[email protected]>:
Quoted 39 lines · Andreas Gruenbacher
Quoted 22 lines
fs/ext4/inode.c +15
-2@@ -3422,9 +3422,38 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, map.m_lblk = first_block; map.m_len = last_block - first_block +1 ; -if (!(flags &IOMAP_WRITE )) { +if (flags &IOMAP_REPORT ) { ret =ext4_map_blocks (NULL , inode, &map,0 ); - }else { +if (ret <0 ) +return ret; + +if (ret ==0 ) { +ext4_lblk_t end = map.m_lblk + map.m_len -1 ; +struct extent_status es; + +ext4_es_find_delayed_extent_range (inode, map.m_lblk, end, &es); + +if (!es.es_len || es.es_lblk > end) { +/* entire range is a hole */ + }else if (es.es_lblk > map.m_lblk) { +/* range starts with a hole */ + map.m_len = es.es_lblk - map.m_lblk;fs/ext4/inode.c static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 3450
Quoted 10 lines
fs/ext4/inode.c +10
-0+ }else { +ext4_lblk_t offs =0 ; + +if (es.es_lblk < map.m_lblk) + offs = map.m_lblk - es.es_lblk; + map.m_lblk = es.es_lblk + offs; + map.m_pblk =ext4_es_pblock (&es) + offs; + map.m_len = es.es_len - offs; +if (ext4_es_is_unwritten (&es)) + map.m_flags |=EXT4_MAP_UNWRITTEN ;This is not possible. If there is unwritten extent at
map->m_lblk, thenext4_map_blocks()could not have possibly returned 0. So just delete this condition and set map.m_pblk to 0 since delalloc extent has no physical position.
Quoted 6 lines
fs/ext4/inode.c static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 3452
Quoted 2 lines
fs/ext4/inode.c +2
-0+if (ext4_es_is_delayed (&es)) + delalloc = true;Also
ext4_es_is_delayed(&es)is guaranteed to be true since you've looked it up byext4_es_find_delayed_extent_range(). So just set delalloc = true unconditionally.
Since map.m_pblk is never used in the delalloc case, we can leave it undefined above as well.
Quoted 4 lines
Otherwise the patch looks good so after fixing up these small issues feel free to add:
Reviewed-by Jan Kara <[email protected]>
Thanks,
Andreas
Jan Kara
reviewerRe: [PATCH v2 4/4] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
Quoted 43 lines · Andreas Grünbacher
2017-09-14 14:02 GMT+02:00 Jan Kara <[email protected]>:
Quoted 42 lines · Andreas Gruenbacher
Quoted 22 lines
fs/ext4/inode.c +15
-2@@ -3422,9 +3422,38 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, map.m_lblk = first_block; map.m_len = last_block - first_block +1 ; -if (!(flags &IOMAP_WRITE )) { +if (flags &IOMAP_REPORT ) { ret =ext4_map_blocks (NULL , inode, &map,0 ); - }else { +if (ret <0 ) +return ret; + +if (ret ==0 ) { +ext4_lblk_t end = map.m_lblk + map.m_len -1 ; +struct extent_status es; + +ext4_es_find_delayed_extent_range (inode, map.m_lblk, end, &es); + +if (!es.es_len || es.es_lblk > end) { +/* entire range is a hole */ + }else if (es.es_lblk > map.m_lblk) { +/* range starts with a hole */ + map.m_len = es.es_lblk - map.m_lblk;fs/ext4/inode.c static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 3450
Quoted 10 lines
fs/ext4/inode.c +10
-0+ }else { +ext4_lblk_t offs =0 ; + +if (es.es_lblk < map.m_lblk) + offs = map.m_lblk - es.es_lblk; + map.m_lblk = es.es_lblk + offs; + map.m_pblk =ext4_es_pblock (&es) + offs; + map.m_len = es.es_len - offs; +if (ext4_es_is_unwritten (&es)) + map.m_flags |=EXT4_MAP_UNWRITTEN ;This is not possible. If there is unwritten extent at
map->m_lblk, thenext4_map_blocks()could not have possibly returned 0. So just delete this condition and set map.m_pblk to 0 since delalloc extent has no physical position.Quoted 2 lines
fs/ext4/inode.c +2
-0+if (ext4_es_is_delayed (&es)) + delalloc = true;
Quoted 6 lines
Quoted 3 lines
Also
ext4_es_is_delayed(&es)is guaranteed to be true since you've looked it up byext4_es_find_delayed_extent_range(). So just set delalloc = true unconditionally.Since map.m_pblk is never used in the delalloc case, we can leave it undefined above as well.
Yeah, that's fine by me as well.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR