Skip to content

Commit 5f43db7

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 554b80d commit 5f43db7

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
@@ -1618,20 +1618,19 @@ static int iomap_submit_ioend(struct iomap_writepage_ctx *wpc, int error)
16181618
}
16191619

16201620
static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,
1621-
struct writeback_control *wbc, struct inode *inode, loff_t pos,
1622-
u16 ioend_flags)
1621+
loff_t pos, u16 ioend_flags)
16231622
{
16241623
struct bio *bio;
16251624

16261625
bio = bio_alloc_bioset(wpc->iomap.bdev, BIO_MAX_VECS,
1627-
REQ_OP_WRITE | wbc_to_write_flags(wbc),
1626+
REQ_OP_WRITE | wbc_to_write_flags(wpc->wbc),
16281627
GFP_NOFS, &iomap_ioend_bioset);
16291628
bio->bi_iter.bi_sector = iomap_sector(&wpc->iomap, pos);
16301629
bio->bi_end_io = iomap_writepage_end_bio;
1631-
bio->bi_write_hint = inode->i_write_hint;
1632-
wbc_init_bio(wbc, bio);
1630+
bio->bi_write_hint = wpc->inode->i_write_hint;
1631+
wbc_init_bio(wpc->wbc, bio);
16331632
wpc->nr_folios = 0;
1634-
return iomap_init_ioend(inode, bio, pos, ioend_flags);
1633+
return iomap_init_ioend(wpc->inode, bio, pos, ioend_flags);
16351634
}
16361635

16371636
static bool iomap_can_add_to_ioend(struct iomap_writepage_ctx *wpc, loff_t pos,
@@ -1670,9 +1669,7 @@ static bool iomap_can_add_to_ioend(struct iomap_writepage_ctx *wpc, loff_t pos,
16701669
* writepage context that the caller will need to submit.
16711670
*/
16721671
static int iomap_add_to_ioend(struct iomap_writepage_ctx *wpc,
1673-
struct writeback_control *wbc, struct folio *folio,
1674-
struct inode *inode, loff_t pos, loff_t end_pos,
1675-
unsigned len)
1672+
struct folio *folio, loff_t pos, loff_t end_pos, unsigned len)
16761673
{
16771674
struct iomap_folio_state *ifs = folio->private;
16781675
size_t poff = offset_in_folio(folio, pos);
@@ -1693,8 +1690,7 @@ static int iomap_add_to_ioend(struct iomap_writepage_ctx *wpc,
16931690
error = iomap_submit_ioend(wpc, 0);
16941691
if (error)
16951692
return error;
1696-
wpc->ioend = iomap_alloc_ioend(wpc, wbc, inode, pos,
1697-
ioend_flags);
1693+
wpc->ioend = iomap_alloc_ioend(wpc, pos, ioend_flags);
16981694
}
16991695

17001696
if (!bio_add_folio(&wpc->ioend->io_bio, folio, len, poff))
@@ -1748,24 +1744,24 @@ static int iomap_add_to_ioend(struct iomap_writepage_ctx *wpc,
17481744
if (wpc->ioend->io_offset + wpc->ioend->io_size > end_pos)
17491745
wpc->ioend->io_size = end_pos - wpc->ioend->io_offset;
17501746

1751-
wbc_account_cgroup_owner(wbc, folio, len);
1747+
wbc_account_cgroup_owner(wpc->wbc, folio, len);
17521748
return 0;
17531749
}
17541750

17551751
static int iomap_writepage_map_blocks(struct iomap_writepage_ctx *wpc,
1756-
struct writeback_control *wbc, struct folio *folio,
1757-
struct inode *inode, u64 pos, u64 end_pos,
1758-
unsigned dirty_len, unsigned *count)
1752+
struct folio *folio, u64 pos, u64 end_pos, unsigned dirty_len,
1753+
unsigned *count)
17591754
{
17601755
int error;
17611756

17621757
do {
17631758
unsigned map_len;
17641759

1765-
error = wpc->ops->map_blocks(wpc, inode, pos, dirty_len);
1760+
error = wpc->ops->map_blocks(wpc, wpc->inode, pos, dirty_len);
17661761
if (error)
17671762
break;
1768-
trace_iomap_writepage_map(inode, pos, dirty_len, &wpc->iomap);
1763+
trace_iomap_writepage_map(wpc->inode, pos, dirty_len,
1764+
&wpc->iomap);
17691765

17701766
map_len = min_t(u64, dirty_len,
17711767
wpc->iomap.offset + wpc->iomap.length - pos);
@@ -1779,8 +1775,8 @@ static int iomap_writepage_map_blocks(struct iomap_writepage_ctx *wpc,
17791775
case IOMAP_HOLE:
17801776
break;
17811777
default:
1782-
error = iomap_add_to_ioend(wpc, wbc, folio, inode, pos,
1783-
end_pos, map_len);
1778+
error = iomap_add_to_ioend(wpc, folio, pos, end_pos,
1779+
map_len);
17841780
if (!error)
17851781
(*count)++;
17861782
break;
@@ -1862,10 +1858,10 @@ static bool iomap_writepage_handle_eof(struct folio *folio, struct inode *inode,
18621858
}
18631859

18641860
static int iomap_writepage_map(struct iomap_writepage_ctx *wpc,
1865-
struct writeback_control *wbc, struct folio *folio)
1861+
struct folio *folio)
18661862
{
18671863
struct iomap_folio_state *ifs = folio->private;
1868-
struct inode *inode = folio->mapping->host;
1864+
struct inode *inode = wpc->inode;
18691865
u64 pos = folio_pos(folio);
18701866
u64 end_pos = pos + folio_size(folio);
18711867
u64 end_aligned = 0;
@@ -1912,8 +1908,8 @@ static int iomap_writepage_map(struct iomap_writepage_ctx *wpc,
19121908
*/
19131909
end_aligned = round_up(end_pos, i_blocksize(inode));
19141910
while ((rlen = iomap_find_dirty_range(folio, &pos, end_aligned))) {
1915-
error = iomap_writepage_map_blocks(wpc, wbc, folio, inode,
1916-
pos, end_pos, rlen, &count);
1911+
error = iomap_writepage_map_blocks(wpc, folio, pos, end_pos,
1912+
rlen, &count);
19171913
if (error)
19181914
break;
19191915
pos += rlen;
@@ -1949,10 +1945,9 @@ static int iomap_writepage_map(struct iomap_writepage_ctx *wpc,
19491945
}
19501946

19511947
int
1952-
iomap_writepages(struct address_space *mapping, struct writeback_control *wbc,
1953-
struct iomap_writepage_ctx *wpc,
1954-
const struct iomap_writeback_ops *ops)
1948+
iomap_writepages(struct iomap_writepage_ctx *wpc)
19551949
{
1950+
struct address_space *mapping = wpc->inode->i_mapping;
19561951
struct folio *folio = NULL;
19571952
int error;
19581953

@@ -1964,9 +1959,8 @@ iomap_writepages(struct address_space *mapping, struct writeback_control *wbc,
19641959
PF_MEMALLOC))
19651960
return -EIO;
19661961

1967-
wpc->ops = ops;
1968-
while ((folio = writeback_iter(mapping, wbc, folio, &error)))
1969-
error = iomap_writepage_map(wpc, wbc, folio);
1962+
while ((folio = writeback_iter(mapping, wpc->wbc, folio, &error)))
1963+
error = iomap_writepage_map(wpc, folio);
19701964
return iomap_submit_ioend(wpc, error);
19711965
}
19721966
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)