History

vfs: Add page_cache_seek_hole_data helper

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" foo In 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.

Andreas Gruenbacher committed 9 years ago

Commit 334fd341 parent 7175a112 files · +126 −0Browse files

Showing the changes to include/linux/buffer_head.h (1 of 2 files). Show all

Unified · Split

include/linux/buffer_head.h+2−0
@@ -201,6 +201,8 @@ void write_boundary_block(struct block_device *bdev, · 200 unmodified lines
201 sector_t bblock, unsigned blocksize);201 sector_t bblock, unsigned blocksize);
202int bh_uptodate_or_lock(struct buffer_head *bh);202int bh_uptodate_or_lock(struct buffer_head *bh);
203int bh_submit_read(struct buffer_head *bh);203int bh_submit_read(struct buffer_head *bh);
204loff_t page_cache_seek_hole_data(struct inode *inode, loff_t offset,
205 loff_t length, int whence);
204 206
205extern int buffer_heads_over_limit;207extern int buffer_heads_over_limit;
206 208

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t