Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mpage: Provide variant of mpage_writepages() with own optional folio handler

Some filesystems need to treat some folios specially (for example for
inodes with inline data). Doing the handling in their .writepages method
in a race-free manner results in duplicating some of the writeback
internals. So provide generalized version of mpage_writepages() that
allows filesystem to provide a handler called for each folio which can
handle the folio in a special way.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://patch.msgid.link/20260326140635.15895-3-jack@suse.cz
Signed-off-by: Jan Kara <jack@suse.cz>

Jan Kara fffca572 c3692998

+33 -8
+24 -6
fs/mpage.c
··· 646 646 } 647 647 648 648 /** 649 - * mpage_writepages - walk the list of dirty pages of the given address space & writepage() all of them 649 + * __mpage_writepages - walk the list of dirty pages of the given address space 650 + * & writepage() all of them 650 651 * @mapping: address space structure to write 651 652 * @wbc: subtract the number of written pages from *@wbc->nr_to_write 652 653 * @get_block: the filesystem's block mapper function. 654 + * @write_folio: handler to call for each folio before calling 655 + * mpage_write_folio() 653 656 * 654 657 * This is a library function, which implements the writepages() 655 - * address_space_operation. 658 + * address_space_operation. It calls @write_folio handler for each folio. If 659 + * the handler returns value > 0, it calls mpage_write_folio() to do the 660 + * folio writeback. 656 661 */ 657 662 int 658 - mpage_writepages(struct address_space *mapping, 659 - struct writeback_control *wbc, get_block_t get_block) 663 + __mpage_writepages(struct address_space *mapping, 664 + struct writeback_control *wbc, get_block_t get_block, 665 + int (*write_folio)(struct folio *folio, 666 + struct writeback_control *wbc)) 660 667 { 661 668 struct mpage_data mpd = { 662 669 .get_block = get_block, ··· 673 666 int error; 674 667 675 668 blk_start_plug(&plug); 676 - while ((folio = writeback_iter(mapping, wbc, folio, &error))) 669 + while ((folio = writeback_iter(mapping, wbc, folio, &error))) { 670 + if (write_folio) { 671 + error = write_folio(folio, wbc); 672 + /* 673 + * == 0 means folio is handled, < 0 means error. In 674 + * both cases hand back control to writeback_iter() 675 + */ 676 + if (error <= 0) 677 + continue; 678 + /* Let mpage_write_folio() handle the folio. */ 679 + } 677 680 error = mpage_write_folio(wbc, folio, &mpd); 681 + } 678 682 if (mpd.bio) 679 683 mpage_bio_submit_write(mpd.bio); 680 684 blk_finish_plug(&plug); 681 685 return error; 682 686 } 683 - EXPORT_SYMBOL(mpage_writepages); 687 + EXPORT_SYMBOL(__mpage_writepages);
+9 -2
include/linux/mpage.h
··· 17 17 18 18 void mpage_readahead(struct readahead_control *, get_block_t get_block); 19 19 int mpage_read_folio(struct folio *folio, get_block_t get_block); 20 - int mpage_writepages(struct address_space *mapping, 21 - struct writeback_control *wbc, get_block_t get_block); 20 + int __mpage_writepages(struct address_space *mapping, 21 + struct writeback_control *wbc, get_block_t get_block, 22 + int (*write_folio)(struct folio *folio, 23 + struct writeback_control *wbc)); 24 + static inline int mpage_writepages(struct address_space *mapping, 25 + struct writeback_control *wbc, get_block_t get_block) 26 + { 27 + return __mpage_writepages(mapping, wbc, get_block, NULL); 28 + } 22 29 23 30 #endif