erofs: support SEEK_HOLE/SEEK_DATA in inode_share mode
PATCH 1/1 erofs: support SEEK_HOLE/SEEK_DATA in inode_share mode
When inode_share is enabled, erofs_ishare_fops.llseek falls back to generic_file_llseek, which treats the whole file as data and always returns i_size for SEEK_HOLE, hiding real holes in sparse files.
Switch it to erofs_file_llseek instead. For user files f_mapping->host is always the real erofs inode, so SEEK_HOLE/SEEK_DATA resolve the per-file on-disk layout via iomap_seek_hole()/iomap_seek_data().
--- fs/erofs/data.c | 2 +- fs/erofs/internal.h | 2 ++ fs/erofs/ishare.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-)
fs/erofs/data.c +1 -1
@@ -509,7 +509,7 @@ static int erofs_file_mmap_prepare(struct vm_area_desc *desc)#define erofs_file_mmap_prepare generic_file_readonly_mmap_prepare#endif -static loff_t erofs_file_llseek (struct file *file,loff_t offset,int whence) +loff_t erofs_file_llseek (struct file *file,loff_t offset,int whence) {struct inode *inode = file->f_mapping->host;const struct iomap_ops *ops = &erofs_iomap_ops;
fs/erofs/internal.h +2 -0
@@ -528,6 +528,8 @@ static inline struct inode *erofs_real_inode(struct inode *inode, bool *need_ipu }#endif +loff_t erofs_file_llseek (struct file *file,loff_t offset,int whence); +long erofs_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);long erofs_compat_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);
fs/erofs/ishare.c +1 -1
@@ -156,7 +156,7 @@ static int erofs_ishare_fadvise(struct file *file, loff_t offset,const struct file_operations erofs_ishare_fops = { .open = erofs_ishare_file_open, - .llseek = generic_file_llseek, + .llseek = erofs_file_llseek, .read_iter = erofs_ishare_file_read_iter, .mmap = erofs_ishare_mmap, .release = erofs_ishare_file_release,
Signature · 1 line
2.19.1.6.gb485710b
Quoted 2 lines · Jingbo Xu
- .llseek =
generic_file_llseek,
+ .llseek =erofs_file_llseek,
No objection to the change. While in that table, .splice_read is the entry left that touches the page cache without going through ->private_data:
.read_iter kiocb_clone() onto private_data, then filemap_read() .mmap vma_set_file(vma, realfile) .fadvise vfs_fadvise(file->private_data, ...)
.splice_read filemap_splice_read
filemap_splice_read() does init_sync_kiocb(&iocb, in), and filemap_get_pages() then takes iocb->ki_filp->f_mapping (mm/filemap.c:2686), so it works on the user file's mapping, which after your patch is confirmed to be the real inode's. erofs_fill_inode() sets that mapping's a_ops unconditionally, so the data splice() and sendfile() return is correct, but they populate the per-file page cache from disk rather than the shared one read() and mmap() use, caching the same content twice.
Thanks,
Zhan Xusheng
Quoted 12 lines · Zhan Xusheng
Quoted 2 lines · Jingbo Xu
- .llseek =
generic_file_llseek,
+ .llseek =erofs_file_llseek,No objection to the change. While in that table, .splice_read is the entry left that touches the page cache without going through ->private_data:
.read_iter kiocb_clone() onto private_data, then filemap_read() .mmap vma_set_file(vma, realfile) .fadvise vfs_fadvise(file->private_data, ...).splice_read
filemap_splice_read
Quoted 7 lines
filemap_splice_read()doesinit_sync_kiocb(&iocb, in), andfilemap_get_pages()then takesiocb->ki_filp->f_mapping(mm/filemap.c:2686), so it works on the user file's mapping, which after your patch is confirmed to be the real inode's.erofs_fill_inode()sets that mapping'sa_opsunconditionally, so the datasplice()andsendfile()return is correct, but they populate the per-file page cache from disk rather than the shared oneread()andmmap()use, caching the same content twice.
Right. I think that would be another patch to fix that.
Signature · 2 lines
Thanks, Jingbo
Hi Jingbo,
Quoted 34 lines · Jingbo Xu
When
inode_shareis enabled, erofs_ishare_fops.llseek falls back togeneric_file_llseek, which treats the whole file as data and always returnsi_sizeforSEEK_HOLE, hiding real holes in sparse files.Switch it to
erofs_file_llseekinstead. For user filesf_mapping->hostis always the real erofs inode, so SEEK_HOLE/SEEK_DATA resolve the per-file on-disk layout via iomap_seek_hole()/iomap_seek_data().Reported-by Yuanhe Shu <[email protected]>Signed-off-by Jingbo Xu <[email protected]>--- fs/erofs/data.c | 2 +- fs/erofs/internal.h | 2 ++ fs/erofs/ishare.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-)fs/erofs/data.c +1
-1@@ -509,7 +509,7 @@ static int erofs_file_mmap_prepare(struct vm_area_desc *desc)#define erofs_file_mmap_prepare generic_file_readonly_mmap_prepare#endif -static loff_t erofs_file_llseek (struct file *file,loff_t offset,int whence) +loff_t erofs_file_llseek (struct file *file,loff_t offset,int whence) {struct inode *inode = file->f_mapping->host;const struct iomap_ops *ops = &erofs_iomap_ops;fs/erofs/internal.h +0
-0
fs/erofs/internal.h static inline struct inode *erofs_real_inode(struct inode *inode, bool *need_ipu · line 532
Quoted 5 lines
fs/erofs/internal.h +2
-0@@ -528,6 +528,8 @@ static inline struct inode *erofs_real_inode(struct inode *inode, bool *need_ipu }#endif +loff_t erofs_file_llseek (struct file *file,loff_t offset,int whence); +
Could you move this line below erofs_fiemap()? I hope all declarations in data.c are closer.
Otherwise it looks good to me,
Also could you help write a test for this functionality too?
Thanks,
Gao Xiang
Quoted 40 lines · Gao Xiang
Hi Jingbo,
Quoted 37 lines · Jingbo Xu
When
inode_shareis enabled, erofs_ishare_fops.llseek falls back togeneric_file_llseek, which treats the whole file as data and always returnsi_sizeforSEEK_HOLE, hiding real holes in sparse files.Switch it to
erofs_file_llseekinstead. For user filesf_mapping->hostis always the real erofs inode, so SEEK_HOLE/SEEK_DATA resolve the per-file on-disk layout via iomap_seek_hole()/iomap_seek_data().Reported-by Yuanhe Shu <[email protected]>Signed-off-by Jingbo Xu <[email protected]>--- fs/erofs/data.c | 2 +- fs/erofs/internal.h | 2 ++ fs/erofs/ishare.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-)fs/erofs/data.c +1
-1@@ -509,7 +509,7 @@ static int erofs_file_mmap_prepare(struct vm_area_desc *desc)#define erofs_file_mmap_prepare generic_file_readonly_mmap_prepare#endif -static loff_t erofs_file_llseek (struct file *file,loff_t offset,int whence) +loff_t erofs_file_llseek (struct file *file,loff_t offset,int whence) {struct inode *inode = file->f_mapping->host;const struct iomap_ops *ops = &erofs_iomap_ops;fs/erofs/internal.h +0
-0@@ -528,6 +528,8 @@ static inline struct inode *erofs_real_inode(struct inode *inode, bool *need_ipu }#endif
Quoted 5 lines
fs/erofs/internal.h static inline struct inode *erofs_real_inode(struct inode *inode, bool *need_ipu · line 532
Quoted 2 lines
fs/erofs/internal.h +2
-0+loff_t erofs_file_llseek (struct file *file,loff_t offset,int whence); +Could you move this line below
erofs_fiemap()? I hope all declarations indata.care closer.
Sure.
Quoted 5 lines
Otherwise it looks good to me,
Reviewed-by Gao Xiang <[email protected]>Also could you help write a test for this functionality too?
Will post the test later after posting v2.
Signature · 2 lines
Thanks, Jingbo