Skip to content

Commit 2a5574f

Browse files
Christoph Hellwigbrauner
authored andcommitted
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: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/[email protected] Acked-by: Damien Le Moal <[email protected]> Reviewed-by: Brian Foster <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 8b217cf commit 2a5574f

File tree

13 files changed

+89
-76
lines changed

13 files changed

+89
-76
lines changed

Documentation/filesystems/iomap/design.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ structure below:
167167
struct dax_device *dax_dev;
168168
void *inline_data;
169169
void *private;
170-
const struct iomap_folio_ops *folio_ops;
171170
u64 validity_cookie;
172171
};
173172
@@ -292,8 +291,6 @@ The fields are as follows:
292291
<https://lore.kernel.org/all/[email protected]/>`_.
293292
This value will be passed unchanged to ``->iomap_end``.
294293

295-
* ``folio_ops`` will be covered in the section on pagecache operations.
296-
297294
* ``validity_cookie`` is a magic freshness value set by the filesystem
298295
that should be used to detect stale mappings.
299296
For pagecache operations this is critical for correct operation

Documentation/filesystems/iomap/operations.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,12 @@ The following address space operations can be wrapped easily:
5757
* ``bmap``
5858
* ``swap_activate``
5959

60-
``struct iomap_folio_ops``
60+
``struct iomap_write_ops``
6161
--------------------------
6262

63-
The ``->iomap_begin`` function for pagecache operations may set the
64-
``struct iomap::folio_ops`` field to an ops structure to override
65-
default behaviors of iomap:
66-
6763
.. code-block:: c
6864
69-
struct iomap_folio_ops {
65+
struct iomap_write_ops {
7066
struct folio *(*get_folio)(struct iomap_iter *iter, loff_t pos,
7167
unsigned len);
7268
void (*put_folio)(struct inode *inode, loff_t pos, unsigned copied,

block/fops.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,8 @@ blkdev_direct_write(struct kiocb *iocb, struct iov_iter *from)
723723

724724
static ssize_t blkdev_buffered_write(struct kiocb *iocb, struct iov_iter *from)
725725
{
726-
return iomap_file_buffered_write(iocb, from, &blkdev_iomap_ops, NULL);
726+
return iomap_file_buffered_write(iocb, from, &blkdev_iomap_ops, NULL,
727+
NULL);
727728
}
728729

729730
/*

fs/gfs2/bmap.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -963,12 +963,16 @@ static struct folio *
963963
gfs2_iomap_get_folio(struct iomap_iter *iter, loff_t pos, unsigned len)
964964
{
965965
struct inode *inode = iter->inode;
966+
struct gfs2_inode *ip = GFS2_I(inode);
966967
unsigned int blockmask = i_blocksize(inode) - 1;
967968
struct gfs2_sbd *sdp = GFS2_SB(inode);
968969
unsigned int blocks;
969970
struct folio *folio;
970971
int status;
971972

973+
if (!gfs2_is_jdata(ip) && !gfs2_is_stuffed(ip))
974+
return iomap_get_folio(iter, pos, len);
975+
972976
blocks = ((pos & blockmask) + len + blockmask) >> inode->i_blkbits;
973977
status = gfs2_trans_begin(sdp, RES_DINODE + blocks, 0);
974978
if (status)
@@ -987,21 +991,22 @@ static void gfs2_iomap_put_folio(struct inode *inode, loff_t pos,
987991
struct gfs2_inode *ip = GFS2_I(inode);
988992
struct gfs2_sbd *sdp = GFS2_SB(inode);
989993

990-
if (!gfs2_is_stuffed(ip))
994+
if (gfs2_is_jdata(ip) && !gfs2_is_stuffed(ip))
991995
gfs2_trans_add_databufs(ip->i_gl, folio,
992996
offset_in_folio(folio, pos),
993997
copied);
994998

995999
folio_unlock(folio);
9961000
folio_put(folio);
9971001

998-
if (tr->tr_num_buf_new)
999-
__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
1000-
1001-
gfs2_trans_end(sdp);
1002+
if (gfs2_is_jdata(ip) || gfs2_is_stuffed(ip)) {
1003+
if (tr->tr_num_buf_new)
1004+
__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
1005+
gfs2_trans_end(sdp);
1006+
}
10021007
}
10031008

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

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

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

13101313
#define GFS2_JTRUNC_REVOKES 8192

fs/gfs2/bmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static inline void gfs2_write_calc_reserv(const struct gfs2_inode *ip,
4444
}
4545

4646
extern const struct iomap_ops gfs2_iomap_ops;
47+
extern const struct iomap_write_ops gfs2_iomap_write_ops;
4748
extern const struct iomap_writeback_ops gfs2_writeback_ops;
4849

4950
int gfs2_unstuff_dinode(struct gfs2_inode *ip);

fs/gfs2/file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,8 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
10581058
}
10591059

10601060
pagefault_disable();
1061-
ret = iomap_file_buffered_write(iocb, from, &gfs2_iomap_ops, NULL);
1061+
ret = iomap_file_buffered_write(iocb, from, &gfs2_iomap_ops,
1062+
&gfs2_iomap_write_ops, NULL);
10621063
pagefault_enable();
10631064
if (ret > 0)
10641065
written += ret;

fs/iomap/buffered-io.c

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -733,28 +733,27 @@ static int __iomap_write_begin(const struct iomap_iter *iter, size_t len,
733733
return 0;
734734
}
735735

736-
static struct folio *__iomap_get_folio(struct iomap_iter *iter, size_t len)
736+
static struct folio *__iomap_get_folio(struct iomap_iter *iter,
737+
const struct iomap_write_ops *write_ops, size_t len)
737738
{
738-
const struct iomap_folio_ops *folio_ops = iter->iomap.folio_ops;
739739
loff_t pos = iter->pos;
740740

741741
if (!mapping_large_folio_support(iter->inode->i_mapping))
742742
len = min_t(size_t, len, PAGE_SIZE - offset_in_page(pos));
743743

744-
if (folio_ops && folio_ops->get_folio)
745-
return folio_ops->get_folio(iter, pos, len);
746-
else
747-
return iomap_get_folio(iter, pos, len);
744+
if (write_ops && write_ops->get_folio)
745+
return write_ops->get_folio(iter, pos, len);
746+
return iomap_get_folio(iter, pos, len);
748747
}
749748

750-
static void __iomap_put_folio(struct iomap_iter *iter, size_t ret,
749+
static void __iomap_put_folio(struct iomap_iter *iter,
750+
const struct iomap_write_ops *write_ops, size_t ret,
751751
struct folio *folio)
752752
{
753-
const struct iomap_folio_ops *folio_ops = iter->iomap.folio_ops;
754753
loff_t pos = iter->pos;
755754

756-
if (folio_ops && folio_ops->put_folio) {
757-
folio_ops->put_folio(iter->inode, pos, ret, folio);
755+
if (write_ops && write_ops->put_folio) {
756+
write_ops->put_folio(iter->inode, pos, ret, folio);
758757
} else {
759758
folio_unlock(folio);
760759
folio_put(folio);
@@ -791,10 +790,10 @@ static int iomap_write_begin_inline(const struct iomap_iter *iter,
791790
* offset, and length. Callers can optionally pass a max length *plen,
792791
* otherwise init to zero.
793792
*/
794-
static int iomap_write_begin(struct iomap_iter *iter, struct folio **foliop,
793+
static int iomap_write_begin(struct iomap_iter *iter,
794+
const struct iomap_write_ops *write_ops, struct folio **foliop,
795795
size_t *poffset, u64 *plen)
796796
{
797-
const struct iomap_folio_ops *folio_ops = iter->iomap.folio_ops;
798797
const struct iomap *srcmap = iomap_iter_srcmap(iter);
799798
loff_t pos = iter->pos;
800799
u64 len = min_t(u64, SIZE_MAX, iomap_length(iter));
@@ -809,7 +808,7 @@ static int iomap_write_begin(struct iomap_iter *iter, struct folio **foliop,
809808
if (fatal_signal_pending(current))
810809
return -EINTR;
811810

812-
folio = __iomap_get_folio(iter, len);
811+
folio = __iomap_get_folio(iter, write_ops, len);
813812
if (IS_ERR(folio))
814813
return PTR_ERR(folio);
815814

@@ -823,8 +822,8 @@ static int iomap_write_begin(struct iomap_iter *iter, struct folio **foliop,
823822
* could do the wrong thing here (zero a page range incorrectly or fail
824823
* to zero) and corrupt data.
825824
*/
826-
if (folio_ops && folio_ops->iomap_valid) {
827-
bool iomap_valid = folio_ops->iomap_valid(iter->inode,
825+
if (write_ops && write_ops->iomap_valid) {
826+
bool iomap_valid = write_ops->iomap_valid(iter->inode,
828827
&iter->iomap);
829828
if (!iomap_valid) {
830829
iter->iomap.flags |= IOMAP_F_STALE;
@@ -850,8 +849,7 @@ static int iomap_write_begin(struct iomap_iter *iter, struct folio **foliop,
850849
return 0;
851850

852851
out_unlock:
853-
__iomap_put_folio(iter, 0, folio);
854-
852+
__iomap_put_folio(iter, write_ops, 0, folio);
855853
return status;
856854
}
857855

@@ -923,7 +921,8 @@ static bool iomap_write_end(struct iomap_iter *iter, size_t len, size_t copied,
923921
return __iomap_write_end(iter->inode, pos, len, copied, folio);
924922
}
925923

926-
static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
924+
static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i,
925+
const struct iomap_write_ops *write_ops)
927926
{
928927
ssize_t total_written = 0;
929928
int status = 0;
@@ -967,7 +966,8 @@ static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
967966
break;
968967
}
969968

970-
status = iomap_write_begin(iter, &folio, &offset, &bytes);
969+
status = iomap_write_begin(iter, write_ops, &folio, &offset,
970+
&bytes);
971971
if (unlikely(status)) {
972972
iomap_write_failed(iter->inode, iter->pos, bytes);
973973
break;
@@ -996,7 +996,7 @@ static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
996996
i_size_write(iter->inode, pos + written);
997997
iter->iomap.flags |= IOMAP_F_SIZE_CHANGED;
998998
}
999-
__iomap_put_folio(iter, written, folio);
999+
__iomap_put_folio(iter, write_ops, written, folio);
10001000

10011001
if (old_size < pos)
10021002
pagecache_isize_extended(iter->inode, old_size, pos);
@@ -1029,7 +1029,8 @@ static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
10291029

10301030
ssize_t
10311031
iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i,
1032-
const struct iomap_ops *ops, void *private)
1032+
const struct iomap_ops *ops,
1033+
const struct iomap_write_ops *write_ops, void *private)
10331034
{
10341035
struct iomap_iter iter = {
10351036
.inode = iocb->ki_filp->f_mapping->host,
@@ -1046,7 +1047,7 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *i,
10461047
iter.flags |= IOMAP_DONTCACHE;
10471048

10481049
while ((ret = iomap_iter(&iter, ops)) > 0)
1049-
iter.status = iomap_write_iter(&iter, i);
1050+
iter.status = iomap_write_iter(&iter, i, write_ops);
10501051

10511052
if (unlikely(iter.pos == iocb->ki_pos))
10521053
return ret;
@@ -1280,7 +1281,8 @@ void iomap_write_delalloc_release(struct inode *inode, loff_t start_byte,
12801281
}
12811282
EXPORT_SYMBOL_GPL(iomap_write_delalloc_release);
12821283

1283-
static int iomap_unshare_iter(struct iomap_iter *iter)
1284+
static int iomap_unshare_iter(struct iomap_iter *iter,
1285+
const struct iomap_write_ops *write_ops)
12841286
{
12851287
struct iomap *iomap = &iter->iomap;
12861288
u64 bytes = iomap_length(iter);
@@ -1295,14 +1297,15 @@ static int iomap_unshare_iter(struct iomap_iter *iter)
12951297
bool ret;
12961298

12971299
bytes = min_t(u64, SIZE_MAX, bytes);
1298-
status = iomap_write_begin(iter, &folio, &offset, &bytes);
1300+
status = iomap_write_begin(iter, write_ops, &folio, &offset,
1301+
&bytes);
12991302
if (unlikely(status))
13001303
return status;
13011304
if (iomap->flags & IOMAP_F_STALE)
13021305
break;
13031306

13041307
ret = iomap_write_end(iter, bytes, bytes, folio);
1305-
__iomap_put_folio(iter, bytes, folio);
1308+
__iomap_put_folio(iter, write_ops, bytes, folio);
13061309
if (WARN_ON_ONCE(!ret))
13071310
return -EIO;
13081311

@@ -1320,7 +1323,8 @@ static int iomap_unshare_iter(struct iomap_iter *iter)
13201323

13211324
int
13221325
iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
1323-
const struct iomap_ops *ops)
1326+
const struct iomap_ops *ops,
1327+
const struct iomap_write_ops *write_ops)
13241328
{
13251329
struct iomap_iter iter = {
13261330
.inode = inode,
@@ -1335,7 +1339,7 @@ iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
13351339

13361340
iter.len = min(len, size - pos);
13371341
while ((ret = iomap_iter(&iter, ops)) > 0)
1338-
iter.status = iomap_unshare_iter(&iter);
1342+
iter.status = iomap_unshare_iter(&iter, write_ops);
13391343
return ret;
13401344
}
13411345
EXPORT_SYMBOL_GPL(iomap_file_unshare);
@@ -1354,7 +1358,8 @@ static inline int iomap_zero_iter_flush_and_stale(struct iomap_iter *i)
13541358
return filemap_write_and_wait_range(mapping, i->pos, end);
13551359
}
13561360

1357-
static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero)
1361+
static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero,
1362+
const struct iomap_write_ops *write_ops)
13581363
{
13591364
u64 bytes = iomap_length(iter);
13601365
int status;
@@ -1365,7 +1370,8 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero)
13651370
bool ret;
13661371

13671372
bytes = min_t(u64, SIZE_MAX, bytes);
1368-
status = iomap_write_begin(iter, &folio, &offset, &bytes);
1373+
status = iomap_write_begin(iter, write_ops, &folio, &offset,
1374+
&bytes);
13691375
if (status)
13701376
return status;
13711377
if (iter->iomap.flags & IOMAP_F_STALE)
@@ -1378,7 +1384,7 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero)
13781384
folio_mark_accessed(folio);
13791385

13801386
ret = iomap_write_end(iter, bytes, bytes, folio);
1381-
__iomap_put_folio(iter, bytes, folio);
1387+
__iomap_put_folio(iter, write_ops, bytes, folio);
13821388
if (WARN_ON_ONCE(!ret))
13831389
return -EIO;
13841390

@@ -1394,7 +1400,8 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero)
13941400

13951401
int
13961402
iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
1397-
const struct iomap_ops *ops, void *private)
1403+
const struct iomap_ops *ops,
1404+
const struct iomap_write_ops *write_ops, void *private)
13981405
{
13991406
struct iomap_iter iter = {
14001407
.inode = inode,
@@ -1424,7 +1431,8 @@ iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
14241431
filemap_range_needs_writeback(mapping, pos, pos + plen - 1)) {
14251432
iter.len = plen;
14261433
while ((ret = iomap_iter(&iter, ops)) > 0)
1427-
iter.status = iomap_zero_iter(&iter, did_zero);
1434+
iter.status = iomap_zero_iter(&iter, did_zero,
1435+
write_ops);
14281436

14291437
iter.len = len - (iter.pos - pos);
14301438
if (ret || !iter.len)
@@ -1455,15 +1463,16 @@ iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
14551463
continue;
14561464
}
14571465

1458-
iter.status = iomap_zero_iter(&iter, did_zero);
1466+
iter.status = iomap_zero_iter(&iter, did_zero, write_ops);
14591467
}
14601468
return ret;
14611469
}
14621470
EXPORT_SYMBOL_GPL(iomap_zero_range);
14631471

14641472
int
14651473
iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
1466-
const struct iomap_ops *ops, void *private)
1474+
const struct iomap_ops *ops,
1475+
const struct iomap_write_ops *write_ops, void *private)
14671476
{
14681477
unsigned int blocksize = i_blocksize(inode);
14691478
unsigned int off = pos & (blocksize - 1);
@@ -1472,7 +1481,7 @@ iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
14721481
if (!off)
14731482
return 0;
14741483
return iomap_zero_range(inode, pos, blocksize - off, did_zero, ops,
1475-
private);
1484+
write_ops, private);
14761485
}
14771486
EXPORT_SYMBOL_GPL(iomap_truncate_page);
14781487

0 commit comments

Comments
 (0)