Re: [PATCH RFC 01/29] iomap: add iomap_writepages_unbound() to write beyond EOF

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2025-07-29 15:07:43, Darrick J. Wong wrote:
> On Mon, Jul 28, 2025 at 10:30:05PM +0200, Andrey Albershteyn wrote:
> > From: Andrey Albershteyn <aalbersh@xxxxxxxxxx>
> > 
> > Add iomap_writepages_unbound() without limit in form of EOF. XFS
> > will use this to write metadata (fs-verity Merkle tree) in range far
> > beyond EOF.
> 
> ...and I guess some day fscrypt might use it to encrypt merkle trees
> too?

Probably, then, the region offsets will need to be adjusted also.

> 
> > Signed-off-by: Andrey Albershteyn <aalbersh@xxxxxxxxxx>
> > ---
> >  fs/iomap/buffered-io.c | 51 +++++++++++++++++++++++++++++++++++++++-----------
> >  include/linux/iomap.h  |  3 +++
> >  2 files changed, 43 insertions(+), 11 deletions(-)
> > 
> > diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
> > index 3729391a18f3..7bef232254a3 100644
> > --- a/fs/iomap/buffered-io.c
> > +++ b/fs/iomap/buffered-io.c
> > @@ -1881,18 +1881,10 @@ static int iomap_writepage_map(struct iomap_writepage_ctx *wpc,
> >  	int error = 0;
> >  	u32 rlen;
> >  
> > -	WARN_ON_ONCE(!folio_test_locked(folio));
> > -	WARN_ON_ONCE(folio_test_dirty(folio));
> > -	WARN_ON_ONCE(folio_test_writeback(folio));
> > -
> > -	trace_iomap_writepage(inode, pos, folio_size(folio));
> > -
> > -	if (!iomap_writepage_handle_eof(folio, inode, &end_pos)) {
> > -		folio_unlock(folio);
> > -		return 0;
> > -	}
> >  	WARN_ON_ONCE(end_pos <= pos);
> >  
> > +	trace_iomap_writepage(inode, pos, folio_size(folio));
> > +
> >  	if (i_blocks_per_folio(inode, folio) > 1) {
> >  		if (!ifs) {
> >  			ifs = ifs_alloc(inode, folio, 0);
> > @@ -1956,6 +1948,23 @@ static int iomap_writepage_map(struct iomap_writepage_ctx *wpc,
> >  	return error;
> >  }
> >  
> > +/* Map pages bound by EOF */
> > +static int iomap_writepage_map_eof(struct iomap_writepage_ctx *wpc,
> 
> iomap_writepage_map_within_eof ?

sure

> 
> > +		struct writeback_control *wbc, struct folio *folio)
> > +{
> > +	int error;
> > +	struct inode *inode = folio->mapping->host;
> > +	u64 end_pos = folio_pos(folio) + folio_size(folio);
> > +
> > +	if (!iomap_writepage_handle_eof(folio, inode, &end_pos)) {
> > +		folio_unlock(folio);
> > +		return 0;
> > +	}
> > +
> > +	error = iomap_writepage_map(wpc, wbc, folio);
> > +	return error;
> > +}
> > +
> >  int
> >  iomap_writepages(struct address_space *mapping, struct writeback_control *wbc,
> >  		struct iomap_writepage_ctx *wpc,
> > @@ -1972,9 +1981,29 @@ iomap_writepages(struct address_space *mapping, struct writeback_control *wbc,
> >  			PF_MEMALLOC))
> >  		return -EIO;
> >  
> > +	wpc->ops = ops;
> > +	while ((folio = writeback_iter(mapping, wbc, folio, &error))) {
> > +		WARN_ON_ONCE(!folio_test_locked(folio));
> > +		WARN_ON_ONCE(folio_test_dirty(folio));
> > +		WARN_ON_ONCE(folio_test_writeback(folio));
> > +
> > +		error = iomap_writepage_map_eof(wpc, wbc, folio);
> > +	}
> > +	return iomap_submit_ioend(wpc, error);
> > +}
> > +EXPORT_SYMBOL_GPL(iomap_writepages);
> > +
> > +int
> > +iomap_writepages_unbound(struct address_space *mapping, struct writeback_control *wbc,
> 
> Might want to leave a comment here explaining what's the difference
> between the two iomap_writepages exports:
> 
> /*
>  * Write dirty pages, including any beyond EOF.  This is solely for use
>  * by files that allow post-EOF pagecache, which means fsverity.
>  */

sure, thanks!

> 
> > +		struct iomap_writepage_ctx *wpc,
> > +		const struct iomap_writeback_ops *ops)
> > +{
> > +	struct folio *folio = NULL;
> > +	int error;
> > +
> 
> ...and you might want a:
> 
> 	WARN_ON(!IS_VERITY(wpc->inode));
> 
> to keep it that way.

yup, make sense, thanks!

> 
> --D
> 
> >  	wpc->ops = ops;
> >  	while ((folio = writeback_iter(mapping, wbc, folio, &error)))
> >  		error = iomap_writepage_map(wpc, wbc, folio);
> >  	return iomap_submit_ioend(wpc, error);
> >  }
> > -EXPORT_SYMBOL_GPL(iomap_writepages);
> > +EXPORT_SYMBOL_GPL(iomap_writepages_unbound);
> > diff --git a/include/linux/iomap.h b/include/linux/iomap.h
> > index 522644d62f30..4a0b5ebb79e9 100644
> > --- a/include/linux/iomap.h
> > +++ b/include/linux/iomap.h
> > @@ -464,6 +464,9 @@ void iomap_sort_ioends(struct list_head *ioend_list);
> >  int iomap_writepages(struct address_space *mapping,
> >  		struct writeback_control *wbc, struct iomap_writepage_ctx *wpc,
> >  		const struct iomap_writeback_ops *ops);
> > +int iomap_writepages_unbound(struct address_space *mapping,
> > +		struct writeback_control *wbc, struct iomap_writepage_ctx *wpc,
> > +		const struct iomap_writeback_ops *ops);
> >  
> >  /*
> >   * Flags for direct I/O ->end_io:
> > 
> > -- 
> > 2.50.0
> > 
> > 
> 

-- 
- Andrey





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux