Unverified Commit 2a5574fc authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Christian Brauner
Browse files

iomap: replace iomap_folio_ops with iomap_write_ops



The iomap_folio_ops are only used for buffered writes, including the zero
and unshare variants.  Rename them to iomap_write_ops to better describe
the usage, and pass them through the call chain like the other operation
specific methods instead of through the iomap.

xfs_iomap_valid grows a IOMAP_HOLE check to keep the existing behavior
that never attached the folio_ops to a iomap representing a hole.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/20250710133343.399917-12-hch@lst.de


Acked-by: default avatarDamien Le Moal <dlemoal@kernel.org>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 8b217cf7
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -167,7 +167,6 @@ structure below:
     struct dax_device   *dax_dev;
     void                *inline_data;
     void                *private;
     const struct iomap_folio_ops *folio_ops;
     u64                 validity_cookie;
 };

@@ -292,8 +291,6 @@ The fields are as follows:
   <https://lore.kernel.org/all/20180619164137.13720-7-hch@lst.de/>`_.
   This value will be passed unchanged to ``->iomap_end``.

 * ``folio_ops`` will be covered in the section on pagecache operations.

 * ``validity_cookie`` is a magic freshness value set by the filesystem
   that should be used to detect stale mappings.
   For pagecache operations this is critical for correct operation
+2 −6
Original line number Diff line number Diff line
@@ -57,16 +57,12 @@ The following address space operations can be wrapped easily:
 * ``bmap``
 * ``swap_activate``

``struct iomap_folio_ops``
``struct iomap_write_ops``
--------------------------

The ``->iomap_begin`` function for pagecache operations may set the
``struct iomap::folio_ops`` field to an ops structure to override
default behaviors of iomap:

.. code-block:: c

 struct iomap_folio_ops {
 struct iomap_write_ops {
     struct folio *(*get_folio)(struct iomap_iter *iter, loff_t pos,
                                unsigned len);
     void (*put_folio)(struct inode *inode, loff_t pos, unsigned copied,
+2 −1
Original line number Diff line number Diff line
@@ -723,7 +723,8 @@ blkdev_direct_write(struct kiocb *iocb, struct iov_iter *from)

static ssize_t blkdev_buffered_write(struct kiocb *iocb, struct iov_iter *from)
{
	return iomap_file_buffered_write(iocb, from, &blkdev_iomap_ops, NULL);
	return iomap_file_buffered_write(iocb, from, &blkdev_iomap_ops, NULL,
			NULL);
}

/*
+12 −9
Original line number Diff line number Diff line
@@ -963,12 +963,16 @@ static struct folio *
gfs2_iomap_get_folio(struct iomap_iter *iter, loff_t pos, unsigned len)
{
	struct inode *inode = iter->inode;
	struct gfs2_inode *ip = GFS2_I(inode);
	unsigned int blockmask = i_blocksize(inode) - 1;
	struct gfs2_sbd *sdp = GFS2_SB(inode);
	unsigned int blocks;
	struct folio *folio;
	int status;

	if (!gfs2_is_jdata(ip) && !gfs2_is_stuffed(ip))
		return iomap_get_folio(iter, pos, len);

	blocks = ((pos & blockmask) + len + blockmask) >> inode->i_blkbits;
	status = gfs2_trans_begin(sdp, RES_DINODE + blocks, 0);
	if (status)
@@ -987,7 +991,7 @@ static void gfs2_iomap_put_folio(struct inode *inode, loff_t pos,
	struct gfs2_inode *ip = GFS2_I(inode);
	struct gfs2_sbd *sdp = GFS2_SB(inode);

	if (!gfs2_is_stuffed(ip))
	if (gfs2_is_jdata(ip) && !gfs2_is_stuffed(ip))
		gfs2_trans_add_databufs(ip->i_gl, folio,
					offset_in_folio(folio, pos),
					copied);
@@ -995,13 +999,14 @@ static void gfs2_iomap_put_folio(struct inode *inode, loff_t pos,
	folio_unlock(folio);
	folio_put(folio);

	if (gfs2_is_jdata(ip) || gfs2_is_stuffed(ip)) {
		if (tr->tr_num_buf_new)
			__mark_inode_dirty(inode, I_DIRTY_DATASYNC);

		gfs2_trans_end(sdp);
	}
}

static const struct iomap_folio_ops gfs2_iomap_folio_ops = {
const struct iomap_write_ops gfs2_iomap_write_ops = {
	.get_folio = gfs2_iomap_get_folio,
	.put_folio = gfs2_iomap_put_folio,
};
@@ -1078,8 +1083,6 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
		gfs2_trans_end(sdp);
	}

	if (gfs2_is_stuffed(ip) || gfs2_is_jdata(ip))
		iomap->folio_ops = &gfs2_iomap_folio_ops;
	return 0;

out_trans_end:
@@ -1304,7 +1307,7 @@ static int gfs2_block_zero_range(struct inode *inode, loff_t from, loff_t length
		return 0;
	length = min(length, inode->i_size - from);
	return iomap_zero_range(inode, from, length, NULL, &gfs2_iomap_ops,
			NULL);
			&gfs2_iomap_write_ops, NULL);
}

#define GFS2_JTRUNC_REVOKES 8192
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ static inline void gfs2_write_calc_reserv(const struct gfs2_inode *ip,
}

extern const struct iomap_ops gfs2_iomap_ops;
extern const struct iomap_write_ops gfs2_iomap_write_ops;
extern const struct iomap_writeback_ops gfs2_writeback_ops;

int gfs2_unstuff_dinode(struct gfs2_inode *ip);
Loading