Skip to content

Commit 18da355

Browse files
Christoph Hellwigkawasaki
authored andcommitted
iomap: pass more arguments using the iomap writeback context
Add inode and wpc fields to pass the inode and writeback context that are needed in the entire writeback call chain, and let the callers initialize all fields in the writeback context before calling iomap_writepages to simplify the argument passing. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Brian Foster <[email protected]> Reviewed-by: Joanne Koong <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]>
1 parent 3cbd4eb commit 18da355

6 files changed

Lines changed: 61 additions & 45 deletions

File tree

block/fops.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,13 @@ static const struct iomap_writeback_ops blkdev_writeback_ops = {
558558
static int blkdev_writepages(struct address_space *mapping,
559559
struct writeback_control *wbc)
560560
{
561-
struct iomap_writepage_ctx wpc = { };
561+
struct iomap_writepage_ctx wpc = {
562+
.inode = mapping->host,
563+
.wbc = wbc,
564+
.ops = &blkdev_writeback_ops
565+
};
562566

563-
return iomap_writepages(mapping, wbc, &wpc, &blkdev_writeback_ops);
567+
return iomap_writepages(&wpc);
564568
}
565569

566570
const struct address_space_operations def_blk_aops = {

fs/gfs2/aops.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ static int gfs2_writepages(struct address_space *mapping,
159159
struct writeback_control *wbc)
160160
{
161161
struct gfs2_sbd *sdp = gfs2_mapping2sbd(mapping);
162-
struct iomap_writepage_ctx wpc = { };
162+
struct iomap_writepage_ctx wpc = {
163+
.inode = mapping->host,
164+
.wbc = wbc,
165+
.ops = &gfs2_writeback_ops,
166+
};
163167
int ret;
164168

165169
/*
@@ -168,7 +172,7 @@ static int gfs2_writepages(struct address_space *mapping,
168172
* want balance_dirty_pages() to loop indefinitely trying to write out
169173
* pages held in the ail that it can't find.
170174
*/
171-
ret = iomap_writepages(mapping, wbc, &wpc, &gfs2_writeback_ops);
175+
ret = iomap_writepages(&wpc);
172176
if (ret == 0 && wbc->nr_to_write > 0)
173177
set_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags);
174178
return ret;

fs/iomap/buffered-io.c

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,20 +1621,19 @@ static int iomap_submit_ioend(struct iomap_writepage_ctx *wpc, int error)
16211621
}
16221622

16231623
static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,
1624-
struct writeback_control *wbc, struct inode *inode, loff_t pos,
1625-
u16 ioend_flags)
1624+
loff_t pos, u16 ioend_flags)
16261625
{
16271626
struct bio *bio;
16281627

16291628
bio = bio_alloc_bioset(wpc->iomap.bdev, BIO_MAX_VECS,
1630-
REQ_OP_WRITE | wbc_to_write_flags(wbc),
1629+
REQ_OP_WRITE | wbc_to_write_flags(wpc->wbc),
16311630
GFP_NOFS, &iomap_ioend_bioset);
16321631
bio->bi_iter.bi_sector = iomap_sector(&wpc->iomap, pos);
16331632
bio->bi_end_io = iomap_writepage_end_bio;
1634-
bio->bi_write_hint = inode->i_write_hint;
1635-
wbc_init_bio(wbc, bio);
1633+
bio->bi_write_hint = wpc->inode->i_write_hint;
1634+
wbc_init_bio(wpc->wbc, bio);
16361635
wpc->nr_folios = 0;
1637-
return iomap_init_ioend(inode, bio, pos, ioend_flags);
1636+
return iomap_init_ioend(wpc->inode, bio, pos, ioend_flags);
16381637
}
16391638

16401639
static bool iomap_can_add_to_ioend(struct iomap_writepage_ctx *wpc, loff_t pos,
@@ -1673,9 +1672,7 @@ static bool iomap_can_add_to_ioend(struct iomap_writepage_ctx *wpc, loff_t pos,
16731672
* writepage context that the caller will need to submit.
16741673
*/
16751674
static int iomap_add_to_ioend(struct iomap_writepage_ctx *wpc,
1676-
struct writeback_control *wbc, struct folio *folio,
1677-
struct inode *inode, loff_t pos, loff_t end_pos,
1678-
unsigned len)
1675+
struct folio *folio, loff_t pos, loff_t end_pos, unsigned len)
16791676
{
16801677
struct iomap_folio_state *ifs = folio->private;
16811678
size_t poff = offset_in_folio(folio, pos);
@@ -1696,8 +1693,7 @@ static int iomap_add_to_ioend(struct iomap_writepage_ctx *wpc,
16961693
error = iomap_submit_ioend(wpc, 0);
16971694
if (error)
16981695
return error;
1699-
wpc->ioend = iomap_alloc_ioend(wpc, wbc, inode, pos,
1700-
ioend_flags);
1696+
wpc->ioend = iomap_alloc_ioend(wpc, pos, ioend_flags);
17011697
}
17021698

17031699
if (!bio_add_folio(&wpc->ioend->io_bio, folio, len, poff))
@@ -1751,24 +1747,24 @@ static int iomap_add_to_ioend(struct iomap_writepage_ctx *wpc,
17511747
if (wpc->ioend->io_offset + wpc->ioend->io_size > end_pos)
17521748
wpc->ioend->io_size = end_pos - wpc->ioend->io_offset;
17531749

1754-
wbc_account_cgroup_owner(wbc, folio, len);
1750+
wbc_account_cgroup_owner(wpc->wbc, folio, len);
17551751
return 0;
17561752
}
17571753

17581754
static int iomap_writepage_map_blocks(struct iomap_writepage_ctx *wpc,
1759-
struct writeback_control *wbc, struct folio *folio,
1760-
struct inode *inode, u64 pos, u64 end_pos,
1761-
unsigned dirty_len, unsigned *count)
1755+
struct folio *folio, u64 pos, u64 end_pos, unsigned dirty_len,
1756+
unsigned *count)
17621757
{
17631758
int error;
17641759

17651760
do {
17661761
unsigned map_len;
17671762

1768-
error = wpc->ops->map_blocks(wpc, inode, pos, dirty_len);
1763+
error = wpc->ops->map_blocks(wpc, wpc->inode, pos, dirty_len);
17691764
if (error)
17701765
break;
1771-
trace_iomap_writepage_map(inode, pos, dirty_len, &wpc->iomap);
1766+
trace_iomap_writepage_map(wpc->inode, pos, dirty_len,
1767+
&wpc->iomap);
17721768

17731769
map_len = min_t(u64, dirty_len,
17741770
wpc->iomap.offset + wpc->iomap.length - pos);
@@ -1782,8 +1778,8 @@ static int iomap_writepage_map_blocks(struct iomap_writepage_ctx *wpc,
17821778
case IOMAP_HOLE:
17831779
break;
17841780
default:
1785-
error = iomap_add_to_ioend(wpc, wbc, folio, inode, pos,
1786-
end_pos, map_len);
1781+
error = iomap_add_to_ioend(wpc, folio, pos, end_pos,
1782+
map_len);
17871783
if (!error)
17881784
(*count)++;
17891785
break;
@@ -1865,10 +1861,10 @@ static bool iomap_writepage_handle_eof(struct folio *folio, struct inode *inode,
18651861
}
18661862

18671863
static int iomap_writepage_map(struct iomap_writepage_ctx *wpc,
1868-
struct writeback_control *wbc, struct folio *folio)
1864+
struct folio *folio)
18691865
{
18701866
struct iomap_folio_state *ifs = folio->private;
1871-
struct inode *inode = folio->mapping->host;
1867+
struct inode *inode = wpc->inode;
18721868
u64 pos = folio_pos(folio);
18731869
u64 end_pos = pos + folio_size(folio);
18741870
u64 end_aligned = 0;
@@ -1915,8 +1911,8 @@ static int iomap_writepage_map(struct iomap_writepage_ctx *wpc,
19151911
*/
19161912
end_aligned = round_up(end_pos, i_blocksize(inode));
19171913
while ((rlen = iomap_find_dirty_range(folio, &pos, end_aligned))) {
1918-
error = iomap_writepage_map_blocks(wpc, wbc, folio, inode,
1919-
pos, end_pos, rlen, &count);
1914+
error = iomap_writepage_map_blocks(wpc, folio, pos, end_pos,
1915+
rlen, &count);
19201916
if (error)
19211917
break;
19221918
pos += rlen;
@@ -1952,10 +1948,9 @@ static int iomap_writepage_map(struct iomap_writepage_ctx *wpc,
19521948
}
19531949

19541950
int
1955-
iomap_writepages(struct address_space *mapping, struct writeback_control *wbc,
1956-
struct iomap_writepage_ctx *wpc,
1957-
const struct iomap_writeback_ops *ops)
1951+
iomap_writepages(struct iomap_writepage_ctx *wpc)
19581952
{
1953+
struct address_space *mapping = wpc->inode->i_mapping;
19591954
struct folio *folio = NULL;
19601955
int error;
19611956

@@ -1967,9 +1962,8 @@ iomap_writepages(struct address_space *mapping, struct writeback_control *wbc,
19671962
PF_MEMALLOC))
19681963
return -EIO;
19691964

1970-
wpc->ops = ops;
1971-
while ((folio = writeback_iter(mapping, wbc, folio, &error)))
1972-
error = iomap_writepage_map(wpc, wbc, folio);
1965+
while ((folio = writeback_iter(mapping, wpc->wbc, folio, &error)))
1966+
error = iomap_writepage_map(wpc, folio);
19731967
return iomap_submit_ioend(wpc, error);
19741968
}
19751969
EXPORT_SYMBOL_GPL(iomap_writepages);

fs/xfs/xfs_aops.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -636,19 +636,29 @@ xfs_vm_writepages(
636636
xfs_iflags_clear(ip, XFS_ITRUNCATED);
637637

638638
if (xfs_is_zoned_inode(ip)) {
639-
struct xfs_zoned_writepage_ctx xc = { };
639+
struct xfs_zoned_writepage_ctx xc = {
640+
.ctx = {
641+
.inode = mapping->host,
642+
.wbc = wbc,
643+
.ops = &xfs_zoned_writeback_ops
644+
},
645+
};
640646
int error;
641647

642-
error = iomap_writepages(mapping, wbc, &xc.ctx,
643-
&xfs_zoned_writeback_ops);
648+
error = iomap_writepages(&xc.ctx);
644649
if (xc.open_zone)
645650
xfs_open_zone_put(xc.open_zone);
646651
return error;
647652
} else {
648-
struct xfs_writepage_ctx wpc = { };
649-
650-
return iomap_writepages(mapping, wbc, &wpc.ctx,
651-
&xfs_writeback_ops);
653+
struct xfs_writepage_ctx wpc = {
654+
.ctx = {
655+
.inode = mapping->host,
656+
.wbc = wbc,
657+
.ops = &xfs_writeback_ops
658+
},
659+
};
660+
661+
return iomap_writepages(&wpc.ctx);
652662
}
653663
}
654664

fs/zonefs/file.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,13 @@ static const struct iomap_writeback_ops zonefs_writeback_ops = {
152152
static int zonefs_writepages(struct address_space *mapping,
153153
struct writeback_control *wbc)
154154
{
155-
struct iomap_writepage_ctx wpc = { };
155+
struct iomap_writepage_ctx wpc = {
156+
.inode = mapping->host,
157+
.wbc = wbc,
158+
.ops = &zonefs_writeback_ops,
159+
};
156160

157-
return iomap_writepages(mapping, wbc, &wpc, &zonefs_writeback_ops);
161+
return iomap_writepages(&wpc);
158162
}
159163

160164
static int zonefs_swap_activate(struct swap_info_struct *sis,

include/linux/iomap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ struct iomap_writeback_ops {
448448

449449
struct iomap_writepage_ctx {
450450
struct iomap iomap;
451+
struct inode *inode;
452+
struct writeback_control *wbc;
451453
struct iomap_ioend *ioend;
452454
const struct iomap_writeback_ops *ops;
453455
u32 nr_folios; /* folios added to the ioend */
@@ -461,9 +463,7 @@ void iomap_finish_ioends(struct iomap_ioend *ioend, int error);
461463
void iomap_ioend_try_merge(struct iomap_ioend *ioend,
462464
struct list_head *more_ioends);
463465
void iomap_sort_ioends(struct list_head *ioend_list);
464-
int iomap_writepages(struct address_space *mapping,
465-
struct writeback_control *wbc, struct iomap_writepage_ctx *wpc,
466-
const struct iomap_writeback_ops *ops);
466+
int iomap_writepages(struct iomap_writepage_ctx *wpc);
467467

468468
/*
469469
* Flags for direct I/O ->end_io:

0 commit comments

Comments
 (0)