Skip to content

Commit e9d8e2b

Browse files
Taotao Chenbrauner
authored andcommitted
fs: change write_begin/write_end interface to take struct kiocb *
Change the address_space_operations callbacks write_begin() and write_end() to take struct kiocb * as the first argument instead of struct file *. Update all affected function prototypes, implementations, call sites, and related documentation across VFS, filesystems, and block layer. Part of a series refactoring address_space_operations write_begin and write_end callbacks to use struct kiocb for passing write context and flags. Signed-off-by: Taotao Chen <chentaotao@didiglobal.com> Link: https://lore.kernel.org/20250716093559.217344-4-chentaotao@didiglobal.com Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 048832a commit e9d8e2b

45 files changed

Lines changed: 267 additions & 202 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Documentation/filesystems/locking.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ prototypes::
253253
int (*writepages)(struct address_space *, struct writeback_control *);
254254
bool (*dirty_folio)(struct address_space *, struct folio *folio);
255255
void (*readahead)(struct readahead_control *);
256-
int (*write_begin)(struct file *, struct address_space *mapping,
256+
int (*write_begin)(const struct kiocb *, struct address_space *mapping,
257257
loff_t pos, unsigned len,
258258
struct folio **foliop, void **fsdata);
259-
int (*write_end)(struct file *, struct address_space *mapping,
259+
int (*write_end)(const struct kiocb *, struct address_space *mapping,
260260
loff_t pos, unsigned len, unsigned copied,
261261
struct folio *folio, void *fsdata);
262262
sector_t (*bmap)(struct address_space *, sector_t);

Documentation/filesystems/vfs.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,10 @@ cache in your filesystem. The following members are defined:
823823
int (*writepages)(struct address_space *, struct writeback_control *);
824824
bool (*dirty_folio)(struct address_space *, struct folio *);
825825
void (*readahead)(struct readahead_control *);
826-
int (*write_begin)(struct file *, struct address_space *mapping,
826+
int (*write_begin)(const struct kiocb *, struct address_space *mapping,
827827
loff_t pos, unsigned len,
828-
struct page **pagep, void **fsdata);
829-
int (*write_end)(struct file *, struct address_space *mapping,
828+
struct page **pagep, void **fsdata);
829+
int (*write_end)(const struct kiocb *, struct address_space *mapping,
830830
loff_t pos, unsigned len, unsigned copied,
831831
struct folio *folio, void *fsdata);
832832
sector_t (*bmap)(struct address_space *, sector_t);

block/fops.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,15 +496,18 @@ static void blkdev_readahead(struct readahead_control *rac)
496496
mpage_readahead(rac, blkdev_get_block);
497497
}
498498

499-
static int blkdev_write_begin(struct file *file, struct address_space *mapping,
500-
loff_t pos, unsigned len, struct folio **foliop, void **fsdata)
499+
static int blkdev_write_begin(const struct kiocb *iocb,
500+
struct address_space *mapping, loff_t pos,
501+
unsigned len, struct folio **foliop,
502+
void **fsdata)
501503
{
502504
return block_write_begin(mapping, pos, len, foliop, blkdev_get_block);
503505
}
504506

505-
static int blkdev_write_end(struct file *file, struct address_space *mapping,
506-
loff_t pos, unsigned len, unsigned copied, struct folio *folio,
507-
void *fsdata)
507+
static int blkdev_write_end(const struct kiocb *iocb,
508+
struct address_space *mapping,
509+
loff_t pos, unsigned len, unsigned copied,
510+
struct folio *folio, void *fsdata)
508511
{
509512
int ret;
510513
ret = block_write_end(pos, len, copied, folio);

fs/adfs/inode.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ static void adfs_write_failed(struct address_space *mapping, loff_t to)
5353
truncate_pagecache(inode, inode->i_size);
5454
}
5555

56-
static int adfs_write_begin(struct file *file, struct address_space *mapping,
57-
loff_t pos, unsigned len,
58-
struct folio **foliop, void **fsdata)
56+
static int adfs_write_begin(const struct kiocb *iocb,
57+
struct address_space *mapping,
58+
loff_t pos, unsigned len,
59+
struct folio **foliop, void **fsdata)
5960
{
6061
int ret;
6162

62-
ret = cont_write_begin(file, mapping, pos, len, foliop, fsdata,
63+
ret = cont_write_begin(iocb, mapping, pos, len, foliop, fsdata,
6364
adfs_get_block,
6465
&ADFS_I(mapping->host)->mmu_private);
6566
if (unlikely(ret))

fs/affs/file.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,14 @@ affs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
415415
return ret;
416416
}
417417

418-
static int affs_write_begin(struct file *file, struct address_space *mapping,
419-
loff_t pos, unsigned len,
420-
struct folio **foliop, void **fsdata)
418+
static int affs_write_begin(const struct kiocb *iocb,
419+
struct address_space *mapping,
420+
loff_t pos, unsigned len,
421+
struct folio **foliop, void **fsdata)
421422
{
422423
int ret;
423424

424-
ret = cont_write_begin(file, mapping, pos, len, foliop, fsdata,
425+
ret = cont_write_begin(iocb, mapping, pos, len, foliop, fsdata,
425426
affs_get_block,
426427
&AFFS_I(mapping->host)->mmu_private);
427428
if (unlikely(ret))
@@ -430,14 +431,15 @@ static int affs_write_begin(struct file *file, struct address_space *mapping,
430431
return ret;
431432
}
432433

433-
static int affs_write_end(struct file *file, struct address_space *mapping,
434-
loff_t pos, unsigned int len, unsigned int copied,
434+
static int affs_write_end(const struct kiocb *iocb,
435+
struct address_space *mapping, loff_t pos,
436+
unsigned int len, unsigned int copied,
435437
struct folio *folio, void *fsdata)
436438
{
437439
struct inode *inode = mapping->host;
438440
int ret;
439441

440-
ret = generic_write_end(file, mapping, pos, len, copied, folio, fsdata);
442+
ret = generic_write_end(iocb, mapping, pos, len, copied, folio, fsdata);
441443

442444
/* Clear Archived bit on file writes, as AmigaOS would do */
443445
if (AFFS_I(inode)->i_protect & FIBF_ARCHIVED) {
@@ -645,7 +647,8 @@ static int affs_read_folio_ofs(struct file *file, struct folio *folio)
645647
return err;
646648
}
647649

648-
static int affs_write_begin_ofs(struct file *file, struct address_space *mapping,
650+
static int affs_write_begin_ofs(const struct kiocb *iocb,
651+
struct address_space *mapping,
649652
loff_t pos, unsigned len,
650653
struct folio **foliop, void **fsdata)
651654
{
@@ -684,9 +687,10 @@ static int affs_write_begin_ofs(struct file *file, struct address_space *mapping
684687
return err;
685688
}
686689

687-
static int affs_write_end_ofs(struct file *file, struct address_space *mapping,
688-
loff_t pos, unsigned len, unsigned copied,
689-
struct folio *folio, void *fsdata)
690+
static int affs_write_end_ofs(const struct kiocb *iocb,
691+
struct address_space *mapping,
692+
loff_t pos, unsigned len, unsigned copied,
693+
struct folio *folio, void *fsdata)
690694
{
691695
struct inode *inode = mapping->host;
692696
struct super_block *sb = inode->i_sb;

fs/bcachefs/fs-io-buffered.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ int bch2_writepages(struct address_space *mapping, struct writeback_control *wbc
674674

675675
/* buffered writes: */
676676

677-
int bch2_write_begin(struct file *file, struct address_space *mapping,
677+
int bch2_write_begin(const struct kiocb *iocb, struct address_space *mapping,
678678
loff_t pos, unsigned len,
679679
struct folio **foliop, void **fsdata)
680680
{
@@ -757,7 +757,7 @@ int bch2_write_begin(struct file *file, struct address_space *mapping,
757757
return bch2_err_class(ret);
758758
}
759759

760-
int bch2_write_end(struct file *file, struct address_space *mapping,
760+
int bch2_write_end(const struct kiocb *iocb, struct address_space *mapping,
761761
loff_t pos, unsigned len, unsigned copied,
762762
struct folio *folio, void *fsdata)
763763
{

fs/bcachefs/fs-io-buffered.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ int bch2_read_folio(struct file *, struct folio *);
1010
int bch2_writepages(struct address_space *, struct writeback_control *);
1111
void bch2_readahead(struct readahead_control *);
1212

13-
int bch2_write_begin(struct file *, struct address_space *, loff_t pos,
13+
int bch2_write_begin(const struct kiocb *, struct address_space *, loff_t pos,
1414
unsigned len, struct folio **, void **);
15-
int bch2_write_end(struct file *, struct address_space *, loff_t,
15+
int bch2_write_end(const struct kiocb *, struct address_space *, loff_t,
1616
unsigned len, unsigned copied, struct folio *, void *);
1717

1818
ssize_t bch2_write_iter(struct kiocb *, struct iov_iter *);

fs/bfs/file.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ static void bfs_write_failed(struct address_space *mapping, loff_t to)
170170
truncate_pagecache(inode, inode->i_size);
171171
}
172172

173-
static int bfs_write_begin(struct file *file, struct address_space *mapping,
174-
loff_t pos, unsigned len,
175-
struct folio **foliop, void **fsdata)
173+
static int bfs_write_begin(const struct kiocb *iocb,
174+
struct address_space *mapping,
175+
loff_t pos, unsigned len,
176+
struct folio **foliop, void **fsdata)
176177
{
177178
int ret;
178179

fs/buffer.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,9 +2297,9 @@ int block_write_end(loff_t pos, unsigned len, unsigned copied,
22972297
}
22982298
EXPORT_SYMBOL(block_write_end);
22992299

2300-
int generic_write_end(struct file *file, struct address_space *mapping,
2301-
loff_t pos, unsigned len, unsigned copied,
2302-
struct folio *folio, void *fsdata)
2300+
int generic_write_end(const struct kiocb *iocb, struct address_space *mapping,
2301+
loff_t pos, unsigned len, unsigned copied,
2302+
struct folio *folio, void *fsdata)
23032303
{
23042304
struct inode *inode = mapping->host;
23052305
loff_t old_size = inode->i_size;
@@ -2494,7 +2494,8 @@ int generic_cont_expand_simple(struct inode *inode, loff_t size)
24942494
}
24952495
EXPORT_SYMBOL(generic_cont_expand_simple);
24962496

2497-
static int cont_expand_zero(struct file *file, struct address_space *mapping,
2497+
static int cont_expand_zero(const struct kiocb *iocb,
2498+
struct address_space *mapping,
24982499
loff_t pos, loff_t *bytes)
24992500
{
25002501
struct inode *inode = mapping->host;
@@ -2518,12 +2519,12 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping,
25182519
}
25192520
len = PAGE_SIZE - zerofrom;
25202521

2521-
err = aops->write_begin(file, mapping, curpos, len,
2522+
err = aops->write_begin(iocb, mapping, curpos, len,
25222523
&folio, &fsdata);
25232524
if (err)
25242525
goto out;
25252526
folio_zero_range(folio, offset_in_folio(folio, curpos), len);
2526-
err = aops->write_end(file, mapping, curpos, len, len,
2527+
err = aops->write_end(iocb, mapping, curpos, len, len,
25272528
folio, fsdata);
25282529
if (err < 0)
25292530
goto out;
@@ -2551,12 +2552,12 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping,
25512552
}
25522553
len = offset - zerofrom;
25532554

2554-
err = aops->write_begin(file, mapping, curpos, len,
2555+
err = aops->write_begin(iocb, mapping, curpos, len,
25552556
&folio, &fsdata);
25562557
if (err)
25572558
goto out;
25582559
folio_zero_range(folio, offset_in_folio(folio, curpos), len);
2559-
err = aops->write_end(file, mapping, curpos, len, len,
2560+
err = aops->write_end(iocb, mapping, curpos, len, len,
25602561
folio, fsdata);
25612562
if (err < 0)
25622563
goto out;
@@ -2571,17 +2572,16 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping,
25712572
* For moronic filesystems that do not allow holes in file.
25722573
* We may have to extend the file.
25732574
*/
2574-
int cont_write_begin(struct file *file, struct address_space *mapping,
2575-
loff_t pos, unsigned len,
2576-
struct folio **foliop, void **fsdata,
2577-
get_block_t *get_block, loff_t *bytes)
2575+
int cont_write_begin(const struct kiocb *iocb, struct address_space *mapping,
2576+
loff_t pos, unsigned len, struct folio **foliop,
2577+
void **fsdata, get_block_t *get_block, loff_t *bytes)
25782578
{
25792579
struct inode *inode = mapping->host;
25802580
unsigned int blocksize = i_blocksize(inode);
25812581
unsigned int zerofrom;
25822582
int err;
25832583

2584-
err = cont_expand_zero(file, mapping, pos, bytes);
2584+
err = cont_expand_zero(iocb, mapping, pos, bytes);
25852585
if (err)
25862586
return err;
25872587

fs/ceph/addr.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,10 +1864,12 @@ static int ceph_netfs_check_write_begin(struct file *file, loff_t pos, unsigned
18641864
* We are only allowed to write into/dirty the page if the page is
18651865
* clean, or already dirty within the same snap context.
18661866
*/
1867-
static int ceph_write_begin(struct file *file, struct address_space *mapping,
1867+
static int ceph_write_begin(const struct kiocb *iocb,
1868+
struct address_space *mapping,
18681869
loff_t pos, unsigned len,
18691870
struct folio **foliop, void **fsdata)
18701871
{
1872+
struct file *file = iocb->ki_filp;
18711873
struct inode *inode = file_inode(file);
18721874
struct ceph_inode_info *ci = ceph_inode(inode);
18731875
int r;
@@ -1885,10 +1887,12 @@ static int ceph_write_begin(struct file *file, struct address_space *mapping,
18851887
* we don't do anything in here that simple_write_end doesn't do
18861888
* except adjust dirty page accounting
18871889
*/
1888-
static int ceph_write_end(struct file *file, struct address_space *mapping,
1889-
loff_t pos, unsigned len, unsigned copied,
1890+
static int ceph_write_end(const struct kiocb *iocb,
1891+
struct address_space *mapping, loff_t pos,
1892+
unsigned len, unsigned copied,
18901893
struct folio *folio, void *fsdata)
18911894
{
1895+
struct file *file = iocb->ki_filp;
18921896
struct inode *inode = file_inode(file);
18931897
struct ceph_client *cl = ceph_inode_to_client(inode);
18941898
bool check_cap = false;

0 commit comments

Comments
 (0)