lseek SEEK_HOLE / SEEK_DATA fixes and switch to iomap V3.2-hch
Subsystems (8)
Christoph Hellwig
reviewerPATCH 4/5 xfs: Switch to iomap for SEEK_HOLE / SEEK_DATA
In reply to Christoph HellwigSwitch 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.
Based on patches from Andreas Gruenbacher <[email protected]>.
--- fs/xfs/xfs_file.c | 375 ++--------------------------------------------------- fs/xfs/xfs_inode.h | 3 - 2 files changed, 14 insertions(+), 364 deletions(-)
fs/xfs/xfs_file.c +14 -361
@@ -953,378 +953,31 @@ xfs_file_readdir(return xfs_readdir (NULL , ip, ctx, bufsize); } -/* -* This type is designed to indicate the type of offset we would like -* to search from page cache for xfs_seek_hole_data(). -*/ -enum { -HOLE_OFF =0 , -DATA_OFF , -}; - -/* -* Lookup the desired type of offset from the given page. -* -* On success, return true and the offset argument will point to the -* start of the region that was found. Otherwise this function will -* return false and keep the offset argument unchanged. -*/ -STATIC bool -xfs_lookup_buffer_offset ( -struct page *page, -loff_t *offset, -unsigned int type) -{ -loff_t lastoff =page_offset (page); -bool found = false; -struct buffer_head *bh, *head; - - bh = head =page_buffers (page); -do { -/* -* Unwritten extents that have data in the page -* cache covering them can be identified by the -* BH_Unwritten state flag. Pages with multiple -* buffers might have a mix of holes, data and -* unwritten extents - any buffer with valid -* data in it should have BH_Uptodate flag set -* on it. -*/ -if (buffer_unwritten (bh) || -buffer_uptodate (bh)) { -if (type ==DATA_OFF ) - found = true; - }else { -if (type ==HOLE_OFF ) - found = true; - } - -if (found) { - *offset = lastoff; -break ; - } - lastoff += bh->b_size; - }while ((bh = bh->b_this_page) != head); - -return found; -} - -/* -* This routine is called to find out and return a data or hole offset -* from the page cache for unwritten extents according to the desired -* type for xfs_seek_hole_data(). -* -* The argument offset is used to tell where we start to search from the -* page cache. Map is used to figure out the end points of the range to -* lookup pages. -* -* Return true if the desired type of offset was found, and the argument -* offset is filled with that address. Otherwise, return false and keep -* offset unchanged. -*/ -STATIC bool -xfs_find_get_desired_pgoff ( -struct inode *inode, -struct xfs_bmbt_irec *map, -unsigned int type, -loff_t *offset) -{ -struct xfs_inode *ip =XFS_I (inode); -struct xfs_mount *mp = ip->i_mount; -struct pagevec pvec; -pgoff_t index; -pgoff_t end; -loff_t endoff; -loff_t startoff = *offset; -loff_t lastoff = startoff; -bool found = false; - -pagevec_init (&pvec,0 ); - - index = startoff >>PAGE_SHIFT ; - endoff =XFS_FSB_TO_B (mp, map->br_startoff + map->br_blockcount); - end = (endoff -1 ) >>PAGE_SHIFT ; -do { -int want; -unsigned nr_pages; -unsigned int i; - - want =min_t (pgoff_t, end - index,PAGEVEC_SIZE -1 ) +1 ; - nr_pages =pagevec_lookup (&pvec, inode->i_mapping, index, - want); -if (nr_pages ==0 ) -break ; - -for (i =0 ; i < nr_pages; i++) { -struct page *page = pvec.pages[i]; -loff_t b_offset; - -/* -* At this point, the page may be truncated or -* invalidated (changing page->mapping to NULL), -* or even swizzled back from swapper_space to tmpfs -* file mapping. However, page->index will not change -* because we have a reference on the page. -* -* If current page offset is beyond where we've ended, -* we've found a hole. -*/ -if (type ==HOLE_OFF && lastoff < endoff && - lastoff <page_offset (pvec.pages[i])) { - found = true; - *offset = lastoff; - goto out; - } -/* Searching done if the page index is out of range. */ -if (page->index > end) - goto out; - -lock_page (page); -/* -* Page truncated or invalidated(page->mapping == NULL). -* We can freely skip it and proceed to check the next -* page. -*/ -if (unlikely (page->mapping != inode->i_mapping)) { -unlock_page (page); -continue ; - } - -if (!page_has_buffers (page)) { -unlock_page (page); -continue ; - } - - found =xfs_lookup_buffer_offset (page, &b_offset, type); -if (found) { -/* -* The found offset may be less than the start -* point to search if this is the first time to -* come here. -*/ - *offset =max_t (loff_t, startoff, b_offset); -unlock_page (page); - goto out; - } - -/* -* We either searching data but nothing was found, or -* searching hole but found a data buffer. In either -* case, probably the next page contains the desired -* things, update the last offset to it so. -*/ - lastoff =page_offset (page) +PAGE_SIZE ; -unlock_page (page); - } - -/* -* The number of returned pages less than our desired, search -* done. -*/ -if (nr_pages < want) -break ; - - index = pvec.pages[i -1 ]->index +1 ; -pagevec_release (&pvec); - }while (index <= end); - -/* No page at lastoff and we are not done - we found a hole. */ -if (type ==HOLE_OFF && lastoff < endoff) { - *offset = lastoff; - found = true; - } -out: -pagevec_release (&pvec); -return found; -} - -/* -* caller must lock inode with xfs_ilock_data_map_shared, -* can we craft an appropriate ASSERT? -* -* end is because the VFS-level lseek interface is defined such that any -* offset past i_size shall return -ENXIO, but we use this for quota code -* which does not maintain i_size, and we want to SEEK_DATA past i_size. -*/ -loff_t -__xfs_seek_hole_data ( -struct inode *inode, -loff_t start, -loff_t end, -int whence) -{ -struct xfs_inode *ip =XFS_I (inode); -struct xfs_mount *mp = ip->i_mount; -loff_t uninitialized_var (offset ); -xfs_fileoff_t fsbno; -xfs_filblks_t lastbno; -int error; - -if (start >= end) { - error = -ENXIO ; - goto out_error; - } - -/* -* Try to read extents from the first block indicated -* by fsbno to the end block of the file. -*/ - fsbno =XFS_B_TO_FSBT (mp, start); - lastbno =XFS_B_TO_FSB (mp, end); - -for (;;) { -struct xfs_bmbt_irec map[2 ]; -int nmap =2 ; -unsigned int i; - - error =xfs_bmapi_read (ip, fsbno, lastbno - fsbno, map, &nmap, -XFS_BMAPI_ENTIRE ); -if (error) - goto out_error; - -/* No extents at given offset, must be beyond EOF */ -if (nmap ==0 ) { - error = -ENXIO ; - goto out_error; - } - -for (i =0 ; i < nmap; i++) { - offset =max_t (loff_t, start, -XFS_FSB_TO_B (mp, map[i].br_startoff)); - -/* Landed in the hole we wanted? */ -if (whence ==SEEK_HOLE && - map[i].br_startblock ==HOLESTARTBLOCK ) - goto out; - -/* Landed in the data extent we wanted? */ -if (whence ==SEEK_DATA && - (map[i].br_startblock ==DELAYSTARTBLOCK || - (map[i].br_state ==XFS_EXT_NORM && - !isnullstartblock (map[i].br_startblock)))) - goto out; - -/* -* Landed in an unwritten extent, try to search -* for hole or data from page cache. -*/ -if (map[i].br_state ==XFS_EXT_UNWRITTEN ) { -if (xfs_find_get_desired_pgoff (inode, &map[i], - whence ==SEEK_HOLE ?HOLE_OFF :DATA_OFF , - &offset)) - goto out; - } - } - -/* -* We only received one extent out of the two requested. This -* means we've hit EOF and didn't find what we are looking for. -*/ -if (nmap ==1 ) { -/* -* If we were looking for a hole, set offset to -* the end of the file (i.e., there is an implicit -* hole at the end of any file). -*/ -if (whence ==SEEK_HOLE ) { - offset = end; -break ; - } -/* -* If we were looking for data, it's nowhere to be found -*/ -ASSERT (whence ==SEEK_DATA ); - error = -ENXIO ; - goto out_error; - } - -ASSERT (i >1 ); - -/* -* Nothing was found, proceed to the next round of search -* if the next reading offset is not at or beyond EOF. -*/ - fsbno = map[i -1 ].br_startoff + map[i -1 ].br_blockcount; - start =XFS_FSB_TO_B (mp, fsbno); -if (start >= end) { -if (whence ==SEEK_HOLE ) { - offset = end; -break ; - } -ASSERT (whence ==SEEK_DATA ); - error = -ENXIO ; - goto out_error; - } - } - -out: -/* -* If at this point we have found the hole we wanted, the returned -* offset may be bigger than the file size as it may be aligned to -* page boundary for unwritten extents. We need to deal with this -* situation in particular. -*/ -if (whence ==SEEK_HOLE ) - offset =min_t (loff_t, offset, end); - -return offset; - -out_error: -return error; -} - -STATIC loff_t -xfs_seek_hole_data ( -struct file *file, -loff_t start, -int whence) -{ -struct inode *inode = file->f_mapping->host; -struct xfs_inode *ip =XFS_I (inode); -struct xfs_mount *mp = ip->i_mount; -uint lock; -loff_t offset, end; -int error =0 ; - -if (XFS_FORCED_SHUTDOWN (mp)) -return -EIO ; - - lock =xfs_ilock_data_map_shared (ip); - - end =i_size_read (inode); - offset =__xfs_seek_hole_data (inode, start, end, whence); -if (offset <0 ) { - error = offset; - goto out_unlock; - } - - offset =vfs_setpos (file, offset, inode->i_sb->s_maxbytes); - -out_unlock: -xfs_iunlock (ip, lock); - -if (error) -return error; -return offset; -} - STATIC loff_txfs_file_llseek (struct file *file,loff_t offset,int whence) { +struct inode *inode = file->f_mapping->host; + +if (XFS_FORCED_SHUTDOWN (XFS_I (inode)->i_mount)) +return -EIO ; +switch (whence) { -case SEEK_END : -case SEEK_CUR : -case SEEK_SET : +default :return generic_file_llseek (file, offset, whence);case SEEK_HOLE : + offset =iomap_seek_hole (inode, offset, &xfs_iomap_ops); +break ;case SEEK_DATA : -return xfs_seek_hole_data (file, offset, whence); -default : -return -EINVAL ; + offset =iomap_seek_data (inode, offset, &xfs_iomap_ops); +break ; } + +if (offset <0 ) +return offset; +return vfs_setpos (file, offset, inode->i_sb->s_maxbytes); }/*
fs/xfs/xfs_inode.h +0 -3
@@ -445,9 +445,6 @@ int xfs_zero_eof(struct xfs_inode *ip, xfs_off_t offset, xfs_fsize_t isize, bool *did_zeroing);int xfs_zero_range (struct xfs_inode *ip,xfs_off_t pos,xfs_off_t count,bool *did_zero); -loff_t __xfs_seek_hole_data (struct inode *inode,loff_t start, -loff_t eof,int whence); -/* from xfs_iops.c */ extern void xfs_setup_inode (struct xfs_inode *ip);
Signature · 1 line
2.11.0
Christoph Hellwig
reviewerPATCH 5/5 ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
In reply to Christoph HellwigSwitch 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 | 264 +++----------------------------------------------------- fs/ext4/inode.c | 96 ++++++--------------- 4 files changed, 36 insertions(+), 328 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
@@ -2490,9 +2490,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 +10 -254
287 lines not on this page · raw message
fs/ext4/inode.c +25 -71
129 lines not on this page · raw message
Signature · 1 line
2.11.0
Christoph Hellwig
reviewerHere is my take on all the current seek work. It has my XFS quota changes (unmodified from last post), Andrea's page cache seek helper (unmodified except that the export is dropped), and Andreas iomap SEEK_HOLE / DATA, for which I've added a couple of cleanups and converted ext4 as well.
I've made sure both xfs and ext4 pass all the xfstests.
Changes since the previous posting:
- trivial cleanups of the iomap helper
Christoph Hellwig
reviewerPATCH 1/5 xfs: remove a whitespace-only line from xfs_fs_get_nextdqblk
--- fs/xfs/xfs_quotaops.c | 1 - 1 file changed, 1 deletion(-)
fs/xfs/xfs_quotaops.c +0 -1
@@ -269,7 +269,6 @@ xfs_fs_get_nextdqblk(/* ID may be different, so convert back what we got */ *qid =make_kqid (current_user_ns (), qid->type, id);return 0 ; - }STATIC int
Signature · 1 line
2.11.0
Christoph Hellwig
reviewerPATCH 2/5 vfs: Add page_cache_seek_hole_data helper
In reply to Christoph HellwigFrom: Andreas Gruenbacher <[email protected]>
Both ext4 and xfs implement seeking for the next hole or piece of data in unwritten extents by scanning the page cache, and both versions share the same bug when iterating the buffers of a page: the start offset into the page isn't taken into account, so when a page fits more than two filesystem blocks, things will go wrong. For example, on a filesystem with a block size of 1k, the following command will fail:
xfs_io -f -c "falloc 0 4k" \
-c "pwrite 1k 1k" \
-c "pwrite 3k 1k" \
-c "seek -a -r 0" fooIn this example, neither lseek(fd, 1024, SEEK_HOLE) nor lseek(fd, 2048, SEEK_DATA) will return the correct result.
Introduce a generic vfs helper for seeking in the page cache that gets this right. The next commits will replace the filesystem specific implementations.
--- fs/buffer.c | 124 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/buffer_head.h | 2 + 2 files changed, 126 insertions(+)
fs/buffer.c +124 -0
@@ -3492,6 +3492,130 @@ int bh_submit_read(struct buffer_head *bh) }EXPORT_SYMBOL (bh_submit_read); +/* +* Seek for SEEK_DATA / SEEK_HOLE within @page, starting at @lastoff. +* +* Returns the offset within the file on success, and -ENOENT otherwise. +*/ +static loff_t +page_seek_hole_data (struct page *page,loff_t lastoff,int whence) +{ +loff_t offset =page_offset (page); +struct buffer_head *bh, *head; +bool seek_data = whence ==SEEK_DATA ; + +if (lastoff < offset) + lastoff = offset; + + bh = head =page_buffers (page); +do { + offset += bh->b_size; +if (lastoff >= offset) +continue ; + +/* +* Unwritten extents that have data in the page cache covering +* them can be identified by the BH_Unwritten state flag. +* Pages with multiple buffers might have a mix of holes, data +* and unwritten extents - any buffer with valid data in it +* should have BH_Uptodate flag set on it. +*/ + +if ((buffer_unwritten (bh) ||buffer_uptodate (bh)) == seek_data) +return lastoff; + + lastoff = offset; + }while ((bh = bh->b_this_page) != head); +return -ENOENT ; +} + +/* +* Seek for SEEK_DATA / SEEK_HOLE in the page cache. +* +* Within unwritten extents, the page cache determines which parts are holes +* and which are data: unwritten and uptodate buffer heads count as data; +* everything else counts as a hole. +* +* Returns the resulting offset on successs, and -ENOENT otherwise. +*/ +loff_t +page_cache_seek_hole_data (struct inode *inode,loff_t offset,loff_t length, +int whence) +{ +pgoff_t index = offset >>PAGE_SHIFT ; +pgoff_t end =DIV_ROUND_UP (offset + length,PAGE_SIZE ); +loff_t lastoff = offset; +struct pagevec pvec; + +if (length <=0 ) +return -ENOENT ; + +pagevec_init (&pvec,0 ); + +do { +unsigned want, nr_pages, i; + + want =min_t (unsigned, end - index,PAGEVEC_SIZE ); + nr_pages =pagevec_lookup (&pvec, inode->i_mapping, index, want); +if (nr_pages ==0 ) +break ; + +for (i =0 ; i < nr_pages; i++) { +struct page *page = pvec.pages[i]; + +/* +* At this point, the page may be truncated or +* invalidated (changing page->mapping to NULL), or +* even swizzled back from swapper_space to tmpfs file +* mapping. However, page->index will not change +* because we have a reference on the page. +* +* If current page offset is beyond where we've ended, +* we've found a hole. +*/ +if (whence ==SEEK_HOLE && + lastoff <page_offset (page)) + goto check_range; + +/* Searching done if the page index is out of range. */ +if (page->index >= end) + goto not_found; + +lock_page (page); +if (likely (page->mapping == inode->i_mapping) && +page_has_buffers (page)) { + lastoff =page_seek_hole_data (page, lastoff, whence); +if (lastoff >=0 ) { +unlock_page (page); + goto check_range; + } + } +unlock_page (page); + lastoff =page_offset (page) +PAGE_SIZE ; + } + +/* Searching done if fewer pages returned than wanted. */ +if (nr_pages < want) +break ; + + index = pvec.pages[i -1 ]->index +1 ; +pagevec_release (&pvec); + }while (index < end); + +/* When no page at lastoff and we are not done, we found a hole. */ +if (whence !=SEEK_HOLE ) + goto not_found; + +check_range: +if (lastoff < offset + length) + goto out; +not_found: + lastoff = -ENOENT ; +out: +pagevec_release (&pvec); +return lastoff; +} +void __init buffer_init (void ) {unsigned long nrpages;
include/linux/buffer_head.h +2 -0
@@ -201,6 +201,8 @@ void write_boundary_block(struct block_device *bdev, sector_t bblock, unsigned blocksize);int bh_uptodate_or_lock (struct buffer_head *bh);int bh_submit_read (struct buffer_head *bh); +loff_t page_cache_seek_hole_data (struct inode *inode,loff_t offset, +loff_t length,int whence);extern int buffer_heads_over_limit;
Signature · 1 line
2.11.0
Christoph Hellwig
reviewerPATCH 3/5 vfs: Add iomap_seek_hole and iomap_seek_data helpers
In reply to Christoph HellwigFrom: Andreas Gruenbacher <[email protected]>
Filesystems can use this for implementing lseek SEEK_HOLE / SEEK_DATA support via iomap.
--- fs/iomap.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/iomap.h | 4 +++ 2 files changed, 98 insertions(+)
fs/iomap.c +94 -0
@@ -584,6 +584,100 @@ int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi, }EXPORT_SYMBOL_GPL (iomap_fiemap); +static loff_t +iomap_seek_hole_actor (struct inode *inode,loff_t offset,loff_t length, +void *data,struct iomap *iomap) +{ +switch (iomap->type) { +case IOMAP_UNWRITTEN : + offset =page_cache_seek_hole_data (inode, offset, length, +SEEK_HOLE ); +if (offset <0 ) +return length; +/* fall through */ +case IOMAP_HOLE : + *(loff_t *)data = offset; +return 0 ; +default : +return length; + } +} + +loff_t +iomap_seek_hole (struct inode *inode,loff_t offset,const struct iomap_ops *ops) +{ +loff_t size =i_size_read (inode); +loff_t length = size - offset; +loff_t ret; + +/* Nothing to be found beyond the end of the file. */ +if (offset >= size) +return -ENXIO ; + +while (length >0 ) { + ret =iomap_apply (inode, offset, length,IOMAP_REPORT , ops, + &offset, iomap_seek_hole_actor); +if (ret <0 ) +return ret; +if (ret ==0 ) +break ; + + offset += ret; + length -= ret; + } + +return offset; +} +EXPORT_SYMBOL_GPL (iomap_seek_hole); + +static loff_t +iomap_seek_data_actor (struct inode *inode,loff_t offset,loff_t length, +void *data,struct iomap *iomap) +{ +switch (iomap->type) { +case IOMAP_HOLE : +return length; +case IOMAP_UNWRITTEN : + offset =page_cache_seek_hole_data (inode, offset, length, +SEEK_DATA ); +if (offset <0 ) +return length; +/*FALLTHRU*/ +default : + *(loff_t *)data = offset; +return 0 ; + } +} + +loff_t +iomap_seek_data (struct inode *inode,loff_t offset,const struct iomap_ops *ops) +{ +loff_t size =i_size_read (inode); +loff_t length = size - offset; +loff_t ret; + +/* Nothing to be found beyond the end of the file. */ +if (offset >= size) +return -ENXIO ; + +while (length >0 ) { + ret =iomap_apply (inode, offset, length,IOMAP_REPORT , ops, + &offset, iomap_seek_data_actor); +if (ret <0 ) +return ret; +if (ret ==0 ) +break ; + + offset += ret; + length -= ret; + } + +if (length <=0 ) +return -ENXIO ; +return offset; +} +EXPORT_SYMBOL_GPL (iomap_seek_data); +/* * Private flags for iomap_dio, must not overlap with the public ones in * iomap.h:
include/linux/iomap.h +4 -0
@@ -83,6 +83,10 @@ int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,int 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); +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, +const struct iomap_ops *ops);/* * Flags for direct I/O ->end_io:
Signature · 1 line
2.11.0
Quoted 1 line · Christoph Hellwig
Here is my take on all the current seek work. It has my XFS quota changes
I think the quota change patch fell out of this series, but I can grab it from the previous iteration if it hasn't changed.
--D
Quoted 12 lines
(unmodified from last post), Andrea's page cache seek helper (unmodified except that the export is dropped), and Andreas iomap
SEEK_HOLE/ DATA, for which I've added a couple of cleanups and converted ext4 as well.I've made sure both xfs and ext4 pass all the xfstests.
Changes since the previous posting:
- trivial cleanups of the iomap helper
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Christoph Hellwig
reviewerQuoted 5 lines · Darrick J. Wong
Quoted 1 line · Christoph Hellwig
Here is my take on all the current seek work. It has my XFS quota changes
I think the quota change patch fell out of this series, but I can grab it from the previous iteration if it hasn't changed.
It hasn't, please do.
Re: [PATCH 5/5] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
In reply to Christoph HellwigQuoted 8 lines · Christoph Hellwig
Switch to the
iomap_seek_holeandiomap_seek_datahelpers for implementing lseekSEEK_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_DAXis enabled, and it requires adding a call into the extent status tree foriomap_beginas well to properly deal with delalloc extents.
This breaks SEEK_HOLE / SEEK_DATA on filesystems with the inline_data feature.
Also, ext4 no longer calls inode_lock or inode_lock_shared; that needs to be added back for consistency between reading i_size and walking the file extents.
Thanks,
Andreas
Re: [PATCH 5/5] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
Quoted 10 lines · Andreas Gruenbacher
Quoted 8 lines · Christoph Hellwig
Switch to the
iomap_seek_holeandiomap_seek_datahelpers for implementing lseekSEEK_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_DAXis enabled, and it requires adding a call into the extent status tree foriomap_beginas well to properly deal with delalloc extents.
Quoted 5 lines
This breaks
SEEK_HOLE/SEEK_DATAon filesystems with theinline_datafeature.Also, ext4 no longer calls
inode_lockorinode_lock_shared; that needs to be added back for consistency between readingi_sizeand walking the file extents.
Same on xfs, btw.
Thanks,
Andreas
Christoph Hellwig
reviewerRe: [PATCH 5/5] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
In reply to Andreas GruenbacherQuoted 3 lines · Andreas Gruenbacher
Also, ext4 no longer calls
inode_lockorinode_lock_shared; that needs to be added back for consistency between readingi_sizeand walking the file extents.
At least for XFS we never had such a consistency as we never took the iolock (aka i_rwsem).
Re: [PATCH 1/5] xfs: remove a whitespace-only line from xfs_fs_get_nextdqblk
In reply to Christoph HellwigQuoted 1 line · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>
Quoted 23 lines
--- fs/xfs/xfs_quotaops.c | 1 - 1 file changed, 1 deletion(-)fs/xfs/xfs_quotaops.c +0
-1@@ -269,7 +269,6 @@ xfs_fs_get_nextdqblk(/* ID may be different, so convert back what we got */ *qid =make_kqid (current_user_ns (), qid->type, id);return 0 ; - }STATIC intSignature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 5/5] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
In reply to Christoph HellwigQuoted 7 lines · Christoph Hellwig
Quoted 3 lines · Andreas Gruenbacher
Also, ext4 no longer calls
inode_lockorinode_lock_shared; that needs to be added back for consistency between readingi_sizeand walking the file extents.At least for XFS we never had such a consistency as we never took the iolock (aka
i_rwsem).
Do we need it? It seems strange to me that someone else could be changing the file size while we're trying to use it to scan for holes or data, but OTOH there are plenty of other places where the kernel effectively requires that userspace either has synchronized writer processess with the seeker process or is prepared to deal with the inconsistent results. If that's the intended behavior for the SEEK_{HOLE,DATA} then I guess I can put my fears to rest about XFS /not/ taking the IOLOCK/i_rwsem.
The non-ext4 mechanical parts look ok to me (and test out ok), but I want to be sure that we don't create a locking mess. Dave complained in an earlier thread about lockdep problems because the old code took the ilock and then started locking pages; since we take the ILOCK during ->iomap_begin, drop it, and only take page locks during page_cache_seek_hole_data (which is called from the iomap actor) I think that particular problem goes away.
(As for the ext4 patch that involves deeper surgery to the ext4 iomap implementation so you'll have to take that up with Ted...)
--D
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Christoph Hellwig
reviewerRe: [PATCH 5/5] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
Quoted 10 lines · Darrick J. Wong
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Andreas Gruenbacher
Also, ext4 no longer calls
inode_lockorinode_lock_shared; that needs to be added back for consistency between readingi_sizeand walking the file extents.At least for XFS we never had such a consistency as we never took the iolock (aka
i_rwsem).Do we need it?
For XFS I'm pretty sure we don't. The lseek is fundamentally safe without it due to the ilock.
Quoted 7 lines
The non-ext4 mechanical parts look ok to me (and test out ok), but I want to be sure that we don't create a locking mess. Dave complained in an earlier thread about lockdep problems because the old code took the ilock and then started locking pages; since we take the ILOCK during ->iomap_begin, drop it, and only take page locks during
page_cache_seek_hole_data(which is called from the iomap actor) I think that particular problem goes away.
The old code took the ilook in the seek hole/data helper, which had two problems: it double locked the ilock as we take it in iomap, and it hols the ilock over the page cache calls. None of which happen with this code.
Re: [PATCH 5/5] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
In reply to Christoph HellwigQuoted 7 lines · Christoph Hellwig
Quoted 3 lines · Andreas Gruenbacher
Also, ext4 no longer calls
inode_lockorinode_lock_shared; that needs to be added back for consistency between readingi_sizeand walking the file extents.At least for XFS we never had such a consistency as we never took the iolock (aka
i_rwsem).
What else does this piece of code from mainline xfs_seek_hole_data() do instead then?
lock = xfs_ilock_data_map_shared(ip);
end = i_size_read(inode);
offset = __xfs_seek_hole_data(inode, start, end, whence);Thanks,
Andreas
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Darrick J. Wong
Quoted 1 line · Christoph Hellwig
Here is my take on all the current seek work. It has my XFS quota changes
I think the quota change patch fell out of this series, but I can grab it from the previous iteration if it hasn't changed.
It hasn't, please do.
We haven't heard from the ext4 folks on this yet: is everyone happy with the vfs changes in this series at least? Can those be merged through the xfs tree? That would allow us to move ahead on the gfs2 side.
Thanks,
Andreas
Re: [PATCH 5/5] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
In reply to Andreas GruenbacherQuoted 6 lines · Andreas Gruenbacher
Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · Andreas Gruenbacher
Also, ext4 no longer calls
inode_lockorinode_lock_shared; that needs to be added back for consistency between readingi_sizeand walking the file extents.
Quoted 7 lines
Quoted 2 lines
At least for XFS we never had such a consistency as we never took the iolock (aka
i_rwsem).What else does this piece of code from mainline
xfs_seek_hole_data()do instead then?lock = xfs_ilock_data_map_shared(ip);
To avoid confusion, I'll start with ilock != iolock.
If I'm reading everything correctly, there are three levels of inode locks that must be taken in XFS: First, the IOLOCK (aka i_rwsem) to protect against concurrent IO when we need it, then the MMAPLOCK (istr this was created to handle dax page faults, which don't take i_rwsem?), and finally the ILOCK for inode core/extent map updates. I think page locks are supposed to happen before ILOCK.
xfs_ilock_data_map_shared() is a helper that takes the ILOCK in shared or exclusive mode depending on whether or not all the inode metadata have already been cached in memory.
The ILOCK must be held before reading or writing the extent map.
--D
Quoted 10 lines
end = i_size_read(inode); offset = __xfs_seek_hole_data(inode, start, end, whence);Thanks,
Andreas
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 5/5] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
Quoted 15 lines · Darrick J. Wong
Quoted 6 lines · Andreas Gruenbacher
Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · Andreas Gruenbacher
Also, ext4 no longer calls
inode_lockorinode_lock_shared; that needs to be added back for consistency between readingi_sizeand walking the file extents.Quoted 7 lines
Quoted 2 lines
At least for XFS we never had such a consistency as we never took the iolock (aka
i_rwsem).What else does this piece of code from mainline
xfs_seek_hole_data()do instead then?lock = xfs_ilock_data_map_shared(ip);
Quoted 8 lines
To avoid confusion, I'll start with ilock != iolock.
If I'm reading everything correctly, there are three levels of inode locks that must be taken in XFS: First, the IOLOCK (aka
i_rwsem) to protect against concurrent IO when we need it, then the MMAPLOCK (istr this was created to handle dax page faults, which don't takei_rwsem?), and finally the ILOCK for inode core/extent map updates. I think page locks are supposed to happen before ILOCK.
IOLOCK and MMAPLOCK are equivalent - there are two locks because we can't take the IOLOCK in page fault context because page faults can occur while we are holding the IOLOCK.
Locking order for IO path is:
IOLOCK -> page lock -> ILOCK
Locking order for page faults is:
mmap_sem -> MMAPLOCK -> page lock -> ILOCK
Quoted 5 lines
xfs_ilock_data_map_shared()is a helper that takes the ILOCK in shared or exclusive mode depending on whether or not all the inode metadata have already been cached in memory.The ILOCK must be held before reading or writing the extent map.
More simply:
- IOLOCK/MMAPLOCK is for access control to file data
- ILOCK is for access control to inode metadata
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH v4 1/3 ext4: Add missing locking around iomap_seek_{hole,data}
In reply to Andreas GruenbacherAdd back the inode locking that "ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA" blew away. We can use inode_lock_shared instead of inode_lock instead, though.
--- fs/ext4/file.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/ext4/file.c +4 -0
@@ -459,10 +459,14 @@ loff_t ext4_llseek(struct file *file, loff_t offset, int whence)return generic_file_llseek_size (file, offset, whence, maxbytes,i_size_read (inode));case SEEK_HOLE : +inode_lock_shared (inode); offset =iomap_seek_hole (inode, offset, &ext4_iomap_ops); +inode_unlock_shared (inode);break ;case SEEK_DATA : +inode_lock_shared (inode); offset =iomap_seek_data (inode, offset, &ext4_iomap_ops); +inode_unlock_shared (inode);break ; }
Signature · 1 line
2.7.5
PATCH v4 2/3 iomap: Switch from blkno to physical offset
In reply to Andreas GruenbacherReplace iomap->blkno, the sector number in 512-byte units, into iomap->pyhsical, the physical offset in bytes. For invalid physical offsets, use the special value IOMAP_NULL_PHYSICAL instead of IOMAP_NULL_BLOCK. This allows to use iomap for mappings which are not block aligned, line inline data on ext4.
Add a new IOMAP_F_INLINE flag to indicate that a mapping is in an area that contains data as well as metadata. In iomap_fiemap, map that flag to FIEMAP_EXTENT_DATA_INLINE.
--- fs/buffer.c | 2 +- fs/dax.c | 2 +- fs/ext2/inode.c | 4 ++-- fs/ext4/inode.c | 4 ++-- fs/iomap.c | 14 ++++++++------ fs/nfsd/blocklayout.c | 4 ++-- fs/xfs/xfs_iomap.c | 6 +++--- include/linux/iomap.h | 5 +++-- 8 files changed, 22 insertions(+), 19 deletions(-)
fs/buffer.c +1 -1
@@ -1982,7 +1982,7 @@ 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 )) + + bh->b_blocknr = (iomap->physical >> inode->i_blkbits) + ((offset - iomap->offset) >> inode->i_blkbits);set_buffer_mapped (bh);break ;
fs/dax.c +1 -1
@@ -985,7 +985,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->physical + (pos &PAGE_MASK ) - iomap->offset) >>9 ; } static loff_t
fs/ext2/inode.c +2 -2
@@ -823,11 +823,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->physical =IOMAP_NULL_PHYSICAL ; iomap->length =1 << blkbits; }else { iomap->type =IOMAP_MAPPED ; - iomap->blkno = (sector_t )bno << (blkbits -9 ); + iomap->physical = (u64 )bno << blkbits; iomap->length = (u64 )ret << blkbits; iomap->flags |=IOMAP_F_MERGED ; }
fs/ext4/inode.c +2 -2
@@ -3454,7 +3454,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->physical =IOMAP_NULL_PHYSICAL ; iomap->length = (u64 )map.m_len << blkbits; }else {if (delalloc) {
@@ -3467,7 +3467,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->physical = (u64 )map.m_pblk << blkbits; iomap->length = (u64 )map.m_len << blkbits; }
fs/iomap.c +8 -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->physical + + (pos & ~(PAGE_SIZE -1 )) - iomap->offset) >>9 ;return __dax_zero_page_range (iomap->bdev, iomap->dax_dev, sector, offset, bytes);
@@ -510,11 +510,13 @@ 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_INLINE ) + flags |=FIEMAP_EXTENT_DATA_INLINE ;return fiemap_fill_next_extent (fi, iomap->offset, - iomap->blkno !=IOMAP_NULL_BLOCK ? iomap->blkno <<9 :0 , + iomap->physical !=IOMAP_NULL_PHYSICAL ? + iomap->physical :0 , iomap->length, flags); - } static loff_t
@@ -807,7 +809,7 @@ iomap_dio_zero(struct iomap_dio *dio, struct iomap *iomap, loff_t pos, bio =bio_alloc (GFP_KERNEL ,1 ); bio->bi_bdev = iomap->bdev; bio->bi_iter.bi_sector = - iomap->blkno + ((pos - iomap->offset) >>9 ); + (iomap->physical + pos - iomap->offset) >>9 ; bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io;
@@ -886,7 +888,7 @@ iomap_dio_actor(struct inode *inode, loff_t pos, loff_t length, bio =bio_alloc (GFP_KERNEL , nr_pages); bio->bi_bdev = iomap->bdev; bio->bi_iter.bi_sector = - iomap->blkno + ((pos - iomap->offset) >>9 ); + (iomap->physical + pos - iomap->offset) >>9 ; 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.physical;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.physical;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->physical =IOMAP_NULL_PHYSICAL ; iomap->type =IOMAP_HOLE ; }else if (imap->br_startblock ==DELAYSTARTBLOCK ) { - iomap->blkno =IOMAP_NULL_BLOCK ; + iomap->physical =IOMAP_NULL_PHYSICAL ; iomap->type =IOMAP_DELALLOC ; }else { - iomap->blkno =xfs_fsb_to_db (ip, imap->br_startblock); + iomap->physical =xfs_fsb_to_db (ip, imap->br_startblock) <<9 ;if (imap->br_state ==XFS_EXT_UNWRITTEN ) iomap->type =IOMAP_UNWRITTEN ;else
include/linux/iomap.h +3 -2
@@ -28,14 +28,15 @@ struct vm_fault;*/ #define IOMAP_F_MERGED 0x10/* contains multiple blocks/extents */ #define IOMAP_F_SHARED 0x20/* block shared with another file */ +#define IOMAP_F_INLINE 0x40/* data mixed with metadata */ /* * Magic value for blkno: */ -#define IOMAP_NULL_BLOCK -1LL/* blkno is not valid */ +#define IOMAP_NULL_PHYSICAL -1LL/* physical offset is not valid */ struct iomap { -sector_t blkno;/* 1st sector of mapping, 512b units */ +u64 physical;/* physical 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.7.5
Re: [PATCH 5/5] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
In reply to Andreas GruenbacherQuoted 10 lines · Andreas Gruenbacher
Quoted 8 lines · Christoph Hellwig
Switch to the
iomap_seek_holeandiomap_seek_datahelpers for implementing lseekSEEK_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_DAXis enabled, and it requires adding a call into the extent status tree foriomap_beginas well to properly deal with delalloc extents.
Quoted 5 lines
This breaks
SEEK_HOLE/SEEK_DATAon filesystems with theinline_datafeature.Also, ext4 no longer calls
inode_lockorinode_lock_shared; that needs to be added back for consistency between readingi_sizeand walking the file extents.
Here are some possible fixes on top of this patch.
One problem with iomap is that is uses a sector number for the physical offset instead of a byte offset which prevents iomap from being used for inline data (ext4) / stuffed inodes (gfs2). If we convert that into a byte offset, iomap_fiemap and iomap_seek_{hole,data} will just work for those kinds of files.
Andreas
Andreas Gruenbacher (3):
ext4: Add missing locking around iomap_seek_{hole,data}
iomap: Switch from blkno to physical offset
ext4: Add IOMAP_REPORT support for inline data
fs/buffer.c | 2 +- fs/dax.c | 2 +- fs/ext2/inode.c | 4 ++-- fs/ext4/ext4.h | 4 ++++ fs/ext4/file.c | 4 ++++ fs/ext4/inline.c | 33 +++++++++++++++++++++++++++++++++ fs/ext4/inode.c | 13 +++++++++---- fs/iomap.c | 14 ++++++++------ fs/nfsd/blocklayout.c | 4 ++-- fs/xfs/xfs_iomap.c | 6 +++--- include/linux/iomap.h | 5 +++-- 11 files changed, 70 insertions(+), 21 deletions(-)
Signature · 1 line
2.7.5
PATCH v4 3/3 ext4: Add IOMAP_REPORT support for inline data
Fixes iomap_seek_{hole,data} for files with inline data (on filesystems with the inline_data feature). In addition, this will make converting ext4 to use iomap_fiemap easier.
--- fs/ext4/ext4.h | 4 ++++ fs/ext4/inline.c | 33 +++++++++++++++++++++++++++++++++ fs/ext4/inode.c | 9 +++++++-- 3 files changed, 44 insertions(+), 2 deletions(-)
fs/ext4/ext4.h +4 -0
@@ -3017,6 +3017,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 physical; +int error = -ENOENT ; +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; + + physical = (__u64 )iloc.bh->b_blocknr << inode->i_sb->s_blocksize_bits; + physical += (char *)ext4_raw_inode (&iloc) - iloc.bh->b_data; + physical += offsetof(struct ext4_inode , i_block); + +brelse (iloc.bh); + + iomap->physical = physical; + iomap->offset =0 ; + iomap->length =min_t (loff_t,ext4_get_inline_size (inode), +i_size_read (inode)); + iomap->type =IOMAP_MAPPED ; + iomap->flags =IOMAP_F_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 +7 -2
@@ -3361,8 +3361,13 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,bool delalloc = false;int ret; -if (WARN_ON_ONCE (ext4_has_inline_data (inode))) -return -ERANGE ; +if (ext4_has_inline_data (inode)) { +if (WARN_ON_ONCE (!(flags &IOMAP_REPORT ))) +return -ERANGE ; +if (!ext4_inline_data_iomap (inode, iomap) && + offset < iomap->length) +return 0 ; + } map.m_lblk = first_block; map.m_len = last_block - first_block +1 ;
Signature · 1 line
2.7.5
Christoph Hellwig
reviewerRe: [PATCH v4 1/3] ext4: Add missing locking around iomap_seek_{hole,data}
In reply to Andreas GruenbacherQuoted 3 lines · Andreas Gruenbacher
Add back the inode locking that "ext4: Switch to iomap for
SEEK_HOLE/SEEK_DATA" blew away. We can useinode_lock_sharedinstead ofinode_lockinstead, though.
should be folded into that patch.
Christoph Hellwig
reviewerRe: [PATCH v4 2/3] iomap: Switch from blkno to physical offset
In reply to Andreas GruenbacherMaybe diskaddr or just addr instead of physical which sounds a little confusing?
Also how well was this tested? With all the calculation I'm a little worried about overflows, so a full xfstests run including sub-page blocksize and DAX really is in order here.
Quoted 1 line
+#define
IOMAP_F_INLINE0x40/* data mixed with metadata */
data inline in the inode?
Jan Kara
reviewerRe: [PATCH v4 3/3] ext4: Add IOMAP_REPORT support for inline data
In reply to Andreas GruenbacherQuoted 5 lines · Andreas Gruenbacher
fs/ext4/inode.c +0
-0
fs/ext4/inode.c static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 3368
Quoted 10 lines
fs/ext4/inode.c +5
-2@@ -3361,8 +3361,13 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,bool delalloc = false;int ret; -if (WARN_ON_ONCE (ext4_has_inline_data (inode))) -return -ERANGE ; +if (ext4_has_inline_data (inode)) { +if (WARN_ON_ONCE (!(flags &IOMAP_REPORT ))) +return -ERANGE ; +if (!ext4_inline_data_iomap (inode, iomap) && + offset < iomap->length)
Hum, what's the thinking behind this "offset < iomap->length" check? If it fails, we'd just fall through to the normal case which I'm not sure is guaranteed to be safe? Shouldn't we return error instead?
Honza
Quoted 8 lines
fs/ext4/inode.c +2
-0+return 0 ; + } map.m_lblk = first_block; map.m_len = last_block - first_block +1 ;Signature · 1 line
2.7.5
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v4 3/3] ext4: Add IOMAP_REPORT support for inline data
Quoted 9 lines · Jan Kara
Quoted 8 lines · Andreas Gruenbacher
fs/ext4/inode.c +0
-0@@ -3361,8 +3361,13 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,bool delalloc = false;int ret;
Quoted 11 lines
fs/ext4/inode.c static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 3368
Quoted 7 lines
fs/ext4/inode.c +5
-2-if (WARN_ON_ONCE (ext4_has_inline_data (inode))) -return -ERANGE ; +if (ext4_has_inline_data (inode)) { +if (WARN_ON_ONCE (!(flags &IOMAP_REPORT ))) +return -ERANGE ; +if (!ext4_inline_data_iomap (inode, iomap) && + offset < iomap->length)Hum, what's the thinking behind this "offset <
iomap->length" check? If it fails, we'd just fall through to the normal case which I'm not sure is guaranteed to be safe? Shouldn't we return error instead?
Indeed. I'll send out an updated patch queue including this and several other changes shortly.
Thanks,
Andreas
Jan Kara
reviewerRe: [PATCH 5/5] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
In reply to Christoph HellwigQuoted 15 lines · Christoph Hellwig
fs/ext4/inode.c +4
-0@@ -3359,6 +3358,7 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,unsigned long first_block = offset >> blkbits;unsigned long last_block = (offset + length -1 ) >> blkbits;struct ext4_map_blocks map; +bool delalloc = false;int ret;if (WARN_ON_ONCE (ext4_has_inline_data (inode)))@@ -3369,6 +3369,27 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,if (!(flags &IOMAP_WRITE )) { ret =ext4_map_blocks (NULL , inode, &map,0 ); +if (!ret) { +struct extent_status es = {}; +
fs/ext4/inode.c static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 3384
Quoted 10 lines
fs/ext4/inode.c +10
-0+ext4_es_find_delayed_extent_range (inode, map.m_lblk, + map.m_lblk + map.m_len -1 , &es); +/* Is delalloc data before next block in extent tree? */ +if (es.es_len && es.es_lblk < map.m_lblk + map.m_len) { +ext4_lblk_t offset =0 ; + +if (es.es_lblk < map.m_lblk) + offset = map.m_lblk - es.es_lblk; + map.m_lblk = es.es_lblk + offset; + map.m_pblk =ext4_es_pblock (&es) + offset;
This is wrong for delalloc extent - adding offset to some magic block value...
fs/ext4/inode.c static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 3392
Quoted 8 lines
fs/ext4/inode.c +8
-0+ map.m_len = es.es_len - offset; +if (ext4_es_status (&es) &EXTENT_STATUS_UNWRITTEN ) + map.m_flags |=EXT4_MAP_UNWRITTEN ; +if (ext4_es_status (&es) &EXTENT_STATUS_DELAYED ) + delalloc = true; + ret =1 ; + } + }
Also the delalloc handling seems to be wrong that if we have file as:
HD
where H is hole, D is delalloc block, and iomap is called at offset 0, we should be getting back "hole at 0" back but instead you will return "delalloc at 1".
We deal with a similar situation in ext4_da_map_blocks() so it would be good if we could reuse that one rather than reimplementing it here. But factoring the necessary functionality out isn't that easy.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 5/5] ext4: Switch to iomap for SEEK_HOLE / SEEK_DATA
Jan,
Quoted 21 lines · Jan Kara
Quoted 20 lines · Christoph Hellwig
fs/ext4/inode.c +9
-0@@ -3359,6 +3358,7 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,unsigned long first_block = offset >> blkbits;unsigned long last_block = (offset + length -1 ) >> blkbits;struct ext4_map_blocks map; +bool delalloc = false;int ret;if (WARN_ON_ONCE (ext4_has_inline_data (inode)))@@ -3369,6 +3369,27 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,if (!(flags &IOMAP_WRITE )) { ret =ext4_map_blocks (NULL , inode, &map,0 ); +if (!ret) { +struct extent_status es = {}; + +ext4_es_find_delayed_extent_range (inode, map.m_lblk, + map.m_lblk + map.m_len -1 , &es); +/* Is delalloc data before next block in extent tree? */ +if (es.es_len && es.es_lblk < map.m_lblk + map.m_len) { +ext4_lblk_t offset =0 ;
Quoted 8 lines
fs/ext4/inode.c static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 3384
Quoted 5 lines
fs/ext4/inode.c +5
-0+ +if (es.es_lblk < map.m_lblk) + offset = map.m_lblk - es.es_lblk; + map.m_lblk = es.es_lblk + offset; + map.m_pblk =ext4_es_pblock (&es) + offset;This is wrong for delalloc extent - adding offset to some magic block value...
Right.
Quoted 13 lines
fs/ext4/inode.c static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, · line 3392
Quoted 8 lines
fs/ext4/inode.c +8
-0+ map.m_len = es.es_len - offset; +if (ext4_es_status (&es) &EXTENT_STATUS_UNWRITTEN ) + map.m_flags |=EXT4_MAP_UNWRITTEN ; +if (ext4_es_status (&es) &EXTENT_STATUS_DELAYED ) + delalloc = true; + ret =1 ; + } + }Also the delalloc handling seems to be wrong that if we have file as:
HD
Quoted 7 lines
where H is hole, D is delalloc block, and iomap is called at offset 0, we should be getting back "hole at 0" back but instead you will return "delalloc at 1".
We deal with a similar situation in
ext4_da_map_blocks()so it would be good if we could reuse that one rather than reimplementing it here. But factoring the necessary functionality out isn't that easy.
I've tried to figure out where the issue might be, and I really don't see any.
It may be confusing that ext4_iomap_begin doesn't split up IOMAP_UNWRITTEN maps into holes and data as ext4_find_unwritten_pgoff did. This splitting is instead done generically in iomap_seek_{hole,data} for IOMAP_UNWRITTEN maps using page_cache_seek_hole_data.
I'll post an improved version of this patch queue shortly.
Thanks,
Andreas