The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] erofs: support SEEK_HOLE/SEEK_DATA in inode_share mode
@ 2026-08-18 11:37 Jingbo Xu
  2026-08-20  3:10 ` Zhan Xusheng
  2026-08-20 13:33 ` Gao Xiang
  0 siblings, 2 replies; 5+ messages in thread
From: Jingbo Xu @ 2026-08-18 11:37 UTC (permalink / raw)
  To: xiang, chao, linux-erofs; +Cc: linux-kernel

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().

Reported-by: Yuanhe Shu <xiangzao@linux.alibaba.com>
Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
---
 fs/erofs/data.c     | 2 +-
 fs/erofs/internal.h | 2 ++
 fs/erofs/ishare.c   | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index d2f01245ee79..09d668deb86d 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -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;
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 57bd21859c65..3263c11d714c 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -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);
diff --git a/fs/erofs/ishare.c b/fs/erofs/ishare.c
index fa7d4112dec5..4c7be60565cb 100644
--- a/fs/erofs/ishare.c
+++ b/fs/erofs/ishare.c
@@ -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,
-- 
2.19.1.6.gb485710b


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] erofs: support SEEK_HOLE/SEEK_DATA in inode_share mode
  2026-08-18 11:37 [PATCH] erofs: support SEEK_HOLE/SEEK_DATA in inode_share mode Jingbo Xu
@ 2026-08-20  3:10 ` Zhan Xusheng
  2026-08-20  6:17   ` Jingbo Xu
  2026-08-20 13:33 ` Gao Xiang
  1 sibling, 1 reply; 5+ messages in thread
From: Zhan Xusheng @ 2026-08-20  3:10 UTC (permalink / raw)
  To: Jingbo Xu, xiang, chao, linux-erofs; +Cc: Zhan Xusheng, linux-kernel

On Tue, 18 Aug 2026 19:37:13 +0800, Jingbo Xu wrote:
> - .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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] erofs: support SEEK_HOLE/SEEK_DATA in inode_share mode
  2026-08-20  3:10 ` Zhan Xusheng
@ 2026-08-20  6:17   ` Jingbo Xu
  0 siblings, 0 replies; 5+ messages in thread
From: Jingbo Xu @ 2026-08-20  6:17 UTC (permalink / raw)
  To: Zhan Xusheng, xiang, chao, linux-erofs; +Cc: Zhan Xusheng, linux-kernel



On 8/20/26 11:10 AM, Zhan Xusheng wrote:
> On Tue, 18 Aug 2026 19:37:13 +0800, Jingbo Xu wrote:
>> - .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.

Right.  I think that would be another patch to fix that.

-- 
Thanks,
Jingbo


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] erofs: support SEEK_HOLE/SEEK_DATA in inode_share mode
  2026-08-18 11:37 [PATCH] erofs: support SEEK_HOLE/SEEK_DATA in inode_share mode Jingbo Xu
  2026-08-20  3:10 ` Zhan Xusheng
@ 2026-08-20 13:33 ` Gao Xiang
  2026-08-20 13:35   ` Jingbo Xu
  1 sibling, 1 reply; 5+ messages in thread
From: Gao Xiang @ 2026-08-20 13:33 UTC (permalink / raw)
  To: Jingbo Xu; +Cc: xiang, chao, linux-erofs, linux-kernel

Hi Jingbo,

On Tue, Aug 18, 2026 at 07:37:13PM +0800, Jingbo Xu wrote:
> 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().
> 
> Reported-by: Yuanhe Shu <xiangzao@linux.alibaba.com>
> Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
> ---
>  fs/erofs/data.c     | 2 +-
>  fs/erofs/internal.h | 2 ++
>  fs/erofs/ishare.c   | 2 +-
>  3 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/erofs/data.c b/fs/erofs/data.c
> index d2f01245ee79..09d668deb86d 100644
> --- a/fs/erofs/data.c
> +++ b/fs/erofs/data.c
> @@ -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;
> diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
> index 57bd21859c65..3263c11d714c 100644
> --- a/fs/erofs/internal.h
> +++ b/fs/erofs/internal.h
> @@ -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,
Reviewed-by: Gao Xiang <xiang@kernel.org>

Also could you help write a test for this functionality too?

Thanks,
Gao Xiang

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] erofs: support SEEK_HOLE/SEEK_DATA in inode_share mode
  2026-08-20 13:33 ` Gao Xiang
@ 2026-08-20 13:35   ` Jingbo Xu
  0 siblings, 0 replies; 5+ messages in thread
From: Jingbo Xu @ 2026-08-20 13:35 UTC (permalink / raw)
  To: xiang, chao, linux-erofs, linux-kernel



On 8/20/26 9:33 PM, Gao Xiang wrote:
> Hi Jingbo,
> 
> On Tue, Aug 18, 2026 at 07:37:13PM +0800, Jingbo Xu wrote:
>> 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().
>>
>> Reported-by: Yuanhe Shu <xiangzao@linux.alibaba.com>
>> Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
>> ---
>>  fs/erofs/data.c     | 2 +-
>>  fs/erofs/internal.h | 2 ++
>>  fs/erofs/ishare.c   | 2 +-
>>  3 files changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/erofs/data.c b/fs/erofs/data.c
>> index d2f01245ee79..09d668deb86d 100644
>> --- a/fs/erofs/data.c
>> +++ b/fs/erofs/data.c
>> @@ -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;
>> diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
>> index 57bd21859c65..3263c11d714c 100644
>> --- a/fs/erofs/internal.h
>> +++ b/fs/erofs/internal.h
>> @@ -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.

Sure.

> 
> Otherwise it looks good to me,
> Reviewed-by: Gao Xiang <xiang@kernel.org>
> 
> Also could you help write a test for this functionality too?

Will post the test later after posting v2.

-- 
Thanks,
Jingbo


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-20 13:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-18 11:37 [PATCH] erofs: support SEEK_HOLE/SEEK_DATA in inode_share mode Jingbo Xu
2026-08-20  3:10 ` Zhan Xusheng
2026-08-20  6:17   ` Jingbo Xu
2026-08-20 13:33 ` Gao Xiang
2026-08-20 13:35   ` Jingbo Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox