mpage.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * fs/mpage.c
  4. *
  5. * Copyright (C) 2002, Linus Torvalds.
  6. *
  7. * Contains functions related to preparing and submitting BIOs which contain
  8. * multiple pagecache pages.
  9. *
  10. * 15May2002 Andrew Morton
  11. * Initial version
  12. * 27Jun2002 axboe@suse.de
  13. * use bio_add_page() to build bio's just the right size
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/export.h>
  17. #include <linux/mm.h>
  18. #include <linux/kdev_t.h>
  19. #include <linux/gfp.h>
  20. #include <linux/bio.h>
  21. #include <linux/fs.h>
  22. #include <linux/buffer_head.h>
  23. #include <linux/blkdev.h>
  24. #include <linux/highmem.h>
  25. #include <linux/prefetch.h>
  26. #include <linux/mpage.h>
  27. #include <linux/mm_inline.h>
  28. #include <linux/writeback.h>
  29. #include <linux/backing-dev.h>
  30. #include <linux/pagevec.h>
  31. #include "internal.h"
  32. /*
  33. * I/O completion handler for multipage BIOs.
  34. *
  35. * The mpage code never puts partial pages into a BIO (except for end-of-file).
  36. * If a page does not map to a contiguous run of blocks then it simply falls
  37. * back to block_read_full_folio().
  38. *
  39. * Why is this? If a page's completion depends on a number of different BIOs
  40. * which can complete in any order (or at the same time) then determining the
  41. * status of that page is hard. See end_buffer_async_read() for the details.
  42. * There is no point in duplicating all that complexity.
  43. */
  44. static void mpage_read_end_io(struct bio *bio)
  45. {
  46. struct folio_iter fi;
  47. int err = blk_status_to_errno(bio->bi_status);
  48. bio_for_each_folio_all(fi, bio)
  49. folio_end_read(fi.folio, err == 0);
  50. bio_put(bio);
  51. }
  52. static void mpage_write_end_io(struct bio *bio)
  53. {
  54. struct folio_iter fi;
  55. int err = blk_status_to_errno(bio->bi_status);
  56. bio_for_each_folio_all(fi, bio) {
  57. if (err)
  58. mapping_set_error(fi.folio->mapping, err);
  59. folio_end_writeback(fi.folio);
  60. }
  61. bio_put(bio);
  62. }
  63. static struct bio *mpage_bio_submit_read(struct bio *bio)
  64. {
  65. bio->bi_end_io = mpage_read_end_io;
  66. guard_bio_eod(bio);
  67. submit_bio(bio);
  68. return NULL;
  69. }
  70. static struct bio *mpage_bio_submit_write(struct bio *bio)
  71. {
  72. bio->bi_end_io = mpage_write_end_io;
  73. guard_bio_eod(bio);
  74. submit_bio(bio);
  75. return NULL;
  76. }
  77. /*
  78. * support function for mpage_readahead. The fs supplied get_block might
  79. * return an up to date buffer. This is used to map that buffer into
  80. * the page, which allows read_folio to avoid triggering a duplicate call
  81. * to get_block.
  82. *
  83. * The idea is to avoid adding buffers to pages that don't already have
  84. * them. So when the buffer is up to date and the page size == block size,
  85. * this marks the page up to date instead of adding new buffers.
  86. */
  87. static void map_buffer_to_folio(struct folio *folio, struct buffer_head *bh,
  88. int page_block)
  89. {
  90. struct inode *inode = folio->mapping->host;
  91. struct buffer_head *page_bh, *head;
  92. int block = 0;
  93. head = folio_buffers(folio);
  94. if (!head) {
  95. /*
  96. * don't make any buffers if there is only one buffer on
  97. * the folio and the folio just needs to be set up to date
  98. */
  99. if (inode->i_blkbits == PAGE_SHIFT &&
  100. buffer_uptodate(bh)) {
  101. folio_mark_uptodate(folio);
  102. return;
  103. }
  104. head = create_empty_buffers(folio, i_blocksize(inode), 0);
  105. }
  106. page_bh = head;
  107. do {
  108. if (block == page_block) {
  109. page_bh->b_state = bh->b_state;
  110. page_bh->b_bdev = bh->b_bdev;
  111. page_bh->b_blocknr = bh->b_blocknr;
  112. break;
  113. }
  114. page_bh = page_bh->b_this_page;
  115. block++;
  116. } while (page_bh != head);
  117. }
  118. struct mpage_readpage_args {
  119. struct bio *bio;
  120. struct folio *folio;
  121. unsigned int nr_pages;
  122. bool is_readahead;
  123. sector_t last_block_in_bio;
  124. struct buffer_head map_bh;
  125. unsigned long first_logical_block;
  126. get_block_t *get_block;
  127. };
  128. /*
  129. * This is the worker routine which does all the work of mapping the disk
  130. * blocks and constructs largest possible bios, submits them for IO if the
  131. * blocks are not contiguous on the disk.
  132. *
  133. * We pass a buffer_head back and forth and use its buffer_mapped() flag to
  134. * represent the validity of its disk mapping and to decide when to do the next
  135. * get_block() call.
  136. */
  137. static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
  138. {
  139. struct folio *folio = args->folio;
  140. struct inode *inode = folio->mapping->host;
  141. const unsigned blkbits = inode->i_blkbits;
  142. const unsigned blocks_per_page = PAGE_SIZE >> blkbits;
  143. const unsigned blocksize = 1 << blkbits;
  144. struct buffer_head *map_bh = &args->map_bh;
  145. sector_t block_in_file;
  146. sector_t last_block;
  147. sector_t last_block_in_file;
  148. sector_t first_block;
  149. unsigned page_block;
  150. unsigned first_hole = blocks_per_page;
  151. struct block_device *bdev = NULL;
  152. int length;
  153. int fully_mapped = 1;
  154. blk_opf_t opf = REQ_OP_READ;
  155. unsigned nblocks;
  156. unsigned relative_block;
  157. gfp_t gfp = mapping_gfp_constraint(folio->mapping, GFP_KERNEL);
  158. /* MAX_BUF_PER_PAGE, for example */
  159. VM_BUG_ON_FOLIO(folio_test_large(folio), folio);
  160. if (args->is_readahead) {
  161. opf |= REQ_RAHEAD;
  162. gfp |= __GFP_NORETRY | __GFP_NOWARN;
  163. }
  164. if (folio_buffers(folio))
  165. goto confused;
  166. block_in_file = (sector_t)folio->index << (PAGE_SHIFT - blkbits);
  167. last_block = block_in_file + args->nr_pages * blocks_per_page;
  168. last_block_in_file = (i_size_read(inode) + blocksize - 1) >> blkbits;
  169. if (last_block > last_block_in_file)
  170. last_block = last_block_in_file;
  171. page_block = 0;
  172. /*
  173. * Map blocks using the result from the previous get_blocks call first.
  174. */
  175. nblocks = map_bh->b_size >> blkbits;
  176. if (buffer_mapped(map_bh) &&
  177. block_in_file > args->first_logical_block &&
  178. block_in_file < (args->first_logical_block + nblocks)) {
  179. unsigned map_offset = block_in_file - args->first_logical_block;
  180. unsigned last = nblocks - map_offset;
  181. first_block = map_bh->b_blocknr + map_offset;
  182. for (relative_block = 0; ; relative_block++) {
  183. if (relative_block == last) {
  184. clear_buffer_mapped(map_bh);
  185. break;
  186. }
  187. if (page_block == blocks_per_page)
  188. break;
  189. page_block++;
  190. block_in_file++;
  191. }
  192. bdev = map_bh->b_bdev;
  193. }
  194. /*
  195. * Then do more get_blocks calls until we are done with this folio.
  196. */
  197. map_bh->b_folio = folio;
  198. while (page_block < blocks_per_page) {
  199. map_bh->b_state = 0;
  200. map_bh->b_size = 0;
  201. if (block_in_file < last_block) {
  202. map_bh->b_size = (last_block-block_in_file) << blkbits;
  203. if (args->get_block(inode, block_in_file, map_bh, 0))
  204. goto confused;
  205. args->first_logical_block = block_in_file;
  206. }
  207. if (!buffer_mapped(map_bh)) {
  208. fully_mapped = 0;
  209. if (first_hole == blocks_per_page)
  210. first_hole = page_block;
  211. page_block++;
  212. block_in_file++;
  213. continue;
  214. }
  215. /* some filesystems will copy data into the page during
  216. * the get_block call, in which case we don't want to
  217. * read it again. map_buffer_to_folio copies the data
  218. * we just collected from get_block into the folio's buffers
  219. * so read_folio doesn't have to repeat the get_block call
  220. */
  221. if (buffer_uptodate(map_bh)) {
  222. map_buffer_to_folio(folio, map_bh, page_block);
  223. goto confused;
  224. }
  225. if (first_hole != blocks_per_page)
  226. goto confused; /* hole -> non-hole */
  227. /* Contiguous blocks? */
  228. if (!page_block)
  229. first_block = map_bh->b_blocknr;
  230. else if (first_block + page_block != map_bh->b_blocknr)
  231. goto confused;
  232. nblocks = map_bh->b_size >> blkbits;
  233. for (relative_block = 0; ; relative_block++) {
  234. if (relative_block == nblocks) {
  235. clear_buffer_mapped(map_bh);
  236. break;
  237. } else if (page_block == blocks_per_page)
  238. break;
  239. page_block++;
  240. block_in_file++;
  241. }
  242. bdev = map_bh->b_bdev;
  243. }
  244. if (first_hole != blocks_per_page) {
  245. folio_zero_segment(folio, first_hole << blkbits, PAGE_SIZE);
  246. if (first_hole == 0) {
  247. folio_mark_uptodate(folio);
  248. folio_unlock(folio);
  249. goto out;
  250. }
  251. } else if (fully_mapped) {
  252. folio_set_mappedtodisk(folio);
  253. }
  254. /*
  255. * This folio will go to BIO. Do we need to send this BIO off first?
  256. */
  257. if (args->bio && (args->last_block_in_bio != first_block - 1))
  258. args->bio = mpage_bio_submit_read(args->bio);
  259. alloc_new:
  260. if (args->bio == NULL) {
  261. args->bio = bio_alloc(bdev, bio_max_segs(args->nr_pages), opf,
  262. gfp);
  263. if (args->bio == NULL)
  264. goto confused;
  265. args->bio->bi_iter.bi_sector = first_block << (blkbits - 9);
  266. }
  267. length = first_hole << blkbits;
  268. if (!bio_add_folio(args->bio, folio, length, 0)) {
  269. args->bio = mpage_bio_submit_read(args->bio);
  270. goto alloc_new;
  271. }
  272. relative_block = block_in_file - args->first_logical_block;
  273. nblocks = map_bh->b_size >> blkbits;
  274. if ((buffer_boundary(map_bh) && relative_block == nblocks) ||
  275. (first_hole != blocks_per_page))
  276. args->bio = mpage_bio_submit_read(args->bio);
  277. else
  278. args->last_block_in_bio = first_block + blocks_per_page - 1;
  279. out:
  280. return args->bio;
  281. confused:
  282. if (args->bio)
  283. args->bio = mpage_bio_submit_read(args->bio);
  284. if (!folio_test_uptodate(folio))
  285. block_read_full_folio(folio, args->get_block);
  286. else
  287. folio_unlock(folio);
  288. goto out;
  289. }
  290. /**
  291. * mpage_readahead - start reads against pages
  292. * @rac: Describes which pages to read.
  293. * @get_block: The filesystem's block mapper function.
  294. *
  295. * This function walks the pages and the blocks within each page, building and
  296. * emitting large BIOs.
  297. *
  298. * If anything unusual happens, such as:
  299. *
  300. * - encountering a page which has buffers
  301. * - encountering a page which has a non-hole after a hole
  302. * - encountering a page with non-contiguous blocks
  303. *
  304. * then this code just gives up and calls the buffer_head-based read function.
  305. * It does handle a page which has holes at the end - that is a common case:
  306. * the end-of-file on blocksize < PAGE_SIZE setups.
  307. *
  308. * BH_Boundary explanation:
  309. *
  310. * There is a problem. The mpage read code assembles several pages, gets all
  311. * their disk mappings, and then submits them all. That's fine, but obtaining
  312. * the disk mappings may require I/O. Reads of indirect blocks, for example.
  313. *
  314. * So an mpage read of the first 16 blocks of an ext2 file will cause I/O to be
  315. * submitted in the following order:
  316. *
  317. * 12 0 1 2 3 4 5 6 7 8 9 10 11 13 14 15 16
  318. *
  319. * because the indirect block has to be read to get the mappings of blocks
  320. * 13,14,15,16. Obviously, this impacts performance.
  321. *
  322. * So what we do it to allow the filesystem's get_block() function to set
  323. * BH_Boundary when it maps block 11. BH_Boundary says: mapping of the block
  324. * after this one will require I/O against a block which is probably close to
  325. * this one. So you should push what I/O you have currently accumulated.
  326. *
  327. * This all causes the disk requests to be issued in the correct order.
  328. */
  329. void mpage_readahead(struct readahead_control *rac, get_block_t get_block)
  330. {
  331. struct folio *folio;
  332. struct mpage_readpage_args args = {
  333. .get_block = get_block,
  334. .is_readahead = true,
  335. };
  336. while ((folio = readahead_folio(rac))) {
  337. prefetchw(&folio->flags);
  338. args.folio = folio;
  339. args.nr_pages = readahead_count(rac);
  340. args.bio = do_mpage_readpage(&args);
  341. }
  342. if (args.bio)
  343. mpage_bio_submit_read(args.bio);
  344. }
  345. EXPORT_SYMBOL(mpage_readahead);
  346. /*
  347. * This isn't called much at all
  348. */
  349. int mpage_read_folio(struct folio *folio, get_block_t get_block)
  350. {
  351. struct mpage_readpage_args args = {
  352. .folio = folio,
  353. .nr_pages = 1,
  354. .get_block = get_block,
  355. };
  356. args.bio = do_mpage_readpage(&args);
  357. if (args.bio)
  358. mpage_bio_submit_read(args.bio);
  359. return 0;
  360. }
  361. EXPORT_SYMBOL(mpage_read_folio);
  362. /*
  363. * Writing is not so simple.
  364. *
  365. * If the page has buffers then they will be used for obtaining the disk
  366. * mapping. We only support pages which are fully mapped-and-dirty, with a
  367. * special case for pages which are unmapped at the end: end-of-file.
  368. *
  369. * If the page has no buffers (preferred) then the page is mapped here.
  370. *
  371. * If all blocks are found to be contiguous then the page can go into the
  372. * BIO. Otherwise fall back to the mapping's writepage().
  373. *
  374. * FIXME: This code wants an estimate of how many pages are still to be
  375. * written, so it can intelligently allocate a suitably-sized BIO. For now,
  376. * just allocate full-size (16-page) BIOs.
  377. */
  378. struct mpage_data {
  379. struct bio *bio;
  380. sector_t last_block_in_bio;
  381. get_block_t *get_block;
  382. };
  383. /*
  384. * We have our BIO, so we can now mark the buffers clean. Make
  385. * sure to only clean buffers which we know we'll be writing.
  386. */
  387. static void clean_buffers(struct folio *folio, unsigned first_unmapped)
  388. {
  389. unsigned buffer_counter = 0;
  390. struct buffer_head *bh, *head = folio_buffers(folio);
  391. if (!head)
  392. return;
  393. bh = head;
  394. do {
  395. if (buffer_counter++ == first_unmapped)
  396. break;
  397. clear_buffer_dirty(bh);
  398. bh = bh->b_this_page;
  399. } while (bh != head);
  400. /*
  401. * we cannot drop the bh if the page is not uptodate or a concurrent
  402. * read_folio would fail to serialize with the bh and it would read from
  403. * disk before we reach the platter.
  404. */
  405. if (buffer_heads_over_limit && folio_test_uptodate(folio))
  406. try_to_free_buffers(folio);
  407. }
  408. static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc,
  409. void *data)
  410. {
  411. struct mpage_data *mpd = data;
  412. struct bio *bio = mpd->bio;
  413. struct address_space *mapping = folio->mapping;
  414. struct inode *inode = mapping->host;
  415. const unsigned blkbits = inode->i_blkbits;
  416. const unsigned blocks_per_page = PAGE_SIZE >> blkbits;
  417. sector_t last_block;
  418. sector_t block_in_file;
  419. sector_t first_block;
  420. unsigned page_block;
  421. unsigned first_unmapped = blocks_per_page;
  422. struct block_device *bdev = NULL;
  423. int boundary = 0;
  424. sector_t boundary_block = 0;
  425. struct block_device *boundary_bdev = NULL;
  426. size_t length;
  427. struct buffer_head map_bh;
  428. loff_t i_size = i_size_read(inode);
  429. int ret = 0;
  430. struct buffer_head *head = folio_buffers(folio);
  431. if (head) {
  432. struct buffer_head *bh = head;
  433. /* If they're all mapped and dirty, do it */
  434. page_block = 0;
  435. do {
  436. BUG_ON(buffer_locked(bh));
  437. if (!buffer_mapped(bh)) {
  438. /*
  439. * unmapped dirty buffers are created by
  440. * block_dirty_folio -> mmapped data
  441. */
  442. if (buffer_dirty(bh))
  443. goto confused;
  444. if (first_unmapped == blocks_per_page)
  445. first_unmapped = page_block;
  446. continue;
  447. }
  448. if (first_unmapped != blocks_per_page)
  449. goto confused; /* hole -> non-hole */
  450. if (!buffer_dirty(bh) || !buffer_uptodate(bh))
  451. goto confused;
  452. if (page_block) {
  453. if (bh->b_blocknr != first_block + page_block)
  454. goto confused;
  455. } else {
  456. first_block = bh->b_blocknr;
  457. }
  458. page_block++;
  459. boundary = buffer_boundary(bh);
  460. if (boundary) {
  461. boundary_block = bh->b_blocknr;
  462. boundary_bdev = bh->b_bdev;
  463. }
  464. bdev = bh->b_bdev;
  465. } while ((bh = bh->b_this_page) != head);
  466. if (first_unmapped)
  467. goto page_is_mapped;
  468. /*
  469. * Page has buffers, but they are all unmapped. The page was
  470. * created by pagein or read over a hole which was handled by
  471. * block_read_full_folio(). If this address_space is also
  472. * using mpage_readahead then this can rarely happen.
  473. */
  474. goto confused;
  475. }
  476. /*
  477. * The page has no buffers: map it to disk
  478. */
  479. BUG_ON(!folio_test_uptodate(folio));
  480. block_in_file = (sector_t)folio->index << (PAGE_SHIFT - blkbits);
  481. /*
  482. * Whole page beyond EOF? Skip allocating blocks to avoid leaking
  483. * space.
  484. */
  485. if (block_in_file >= (i_size + (1 << blkbits) - 1) >> blkbits)
  486. goto page_is_mapped;
  487. last_block = (i_size - 1) >> blkbits;
  488. map_bh.b_folio = folio;
  489. for (page_block = 0; page_block < blocks_per_page; ) {
  490. map_bh.b_state = 0;
  491. map_bh.b_size = 1 << blkbits;
  492. if (mpd->get_block(inode, block_in_file, &map_bh, 1))
  493. goto confused;
  494. if (!buffer_mapped(&map_bh))
  495. goto confused;
  496. if (buffer_new(&map_bh))
  497. clean_bdev_bh_alias(&map_bh);
  498. if (buffer_boundary(&map_bh)) {
  499. boundary_block = map_bh.b_blocknr;
  500. boundary_bdev = map_bh.b_bdev;
  501. }
  502. if (page_block) {
  503. if (map_bh.b_blocknr != first_block + page_block)
  504. goto confused;
  505. } else {
  506. first_block = map_bh.b_blocknr;
  507. }
  508. page_block++;
  509. boundary = buffer_boundary(&map_bh);
  510. bdev = map_bh.b_bdev;
  511. if (block_in_file == last_block)
  512. break;
  513. block_in_file++;
  514. }
  515. BUG_ON(page_block == 0);
  516. first_unmapped = page_block;
  517. page_is_mapped:
  518. /* Don't bother writing beyond EOF, truncate will discard the folio */
  519. if (folio_pos(folio) >= i_size)
  520. goto confused;
  521. length = folio_size(folio);
  522. if (folio_pos(folio) + length > i_size) {
  523. /*
  524. * The page straddles i_size. It must be zeroed out on each
  525. * and every writepage invocation because it may be mmapped.
  526. * "A file is mapped in multiples of the page size. For a file
  527. * that is not a multiple of the page size, the remaining memory
  528. * is zeroed when mapped, and writes to that region are not
  529. * written out to the file."
  530. */
  531. length = i_size - folio_pos(folio);
  532. folio_zero_segment(folio, length, folio_size(folio));
  533. }
  534. /*
  535. * This page will go to BIO. Do we need to send this BIO off first?
  536. */
  537. if (bio && mpd->last_block_in_bio != first_block - 1)
  538. bio = mpage_bio_submit_write(bio);
  539. alloc_new:
  540. if (bio == NULL) {
  541. bio = bio_alloc(bdev, BIO_MAX_VECS,
  542. REQ_OP_WRITE | wbc_to_write_flags(wbc),
  543. GFP_NOFS);
  544. bio->bi_iter.bi_sector = first_block << (blkbits - 9);
  545. wbc_init_bio(wbc, bio);
  546. bio->bi_write_hint = inode->i_write_hint;
  547. }
  548. /*
  549. * Must try to add the page before marking the buffer clean or
  550. * the confused fail path above (OOM) will be very confused when
  551. * it finds all bh marked clean (i.e. it will not write anything)
  552. */
  553. wbc_account_cgroup_owner(wbc, folio, folio_size(folio));
  554. length = first_unmapped << blkbits;
  555. if (!bio_add_folio(bio, folio, length, 0)) {
  556. bio = mpage_bio_submit_write(bio);
  557. goto alloc_new;
  558. }
  559. clean_buffers(folio, first_unmapped);
  560. BUG_ON(folio_test_writeback(folio));
  561. folio_start_writeback(folio);
  562. folio_unlock(folio);
  563. if (boundary || (first_unmapped != blocks_per_page)) {
  564. bio = mpage_bio_submit_write(bio);
  565. if (boundary_block) {
  566. write_boundary_block(boundary_bdev,
  567. boundary_block, 1 << blkbits);
  568. }
  569. } else {
  570. mpd->last_block_in_bio = first_block + blocks_per_page - 1;
  571. }
  572. goto out;
  573. confused:
  574. if (bio)
  575. bio = mpage_bio_submit_write(bio);
  576. /*
  577. * The caller has a ref on the inode, so *mapping is stable
  578. */
  579. ret = block_write_full_folio(folio, wbc, mpd->get_block);
  580. mapping_set_error(mapping, ret);
  581. out:
  582. mpd->bio = bio;
  583. return ret;
  584. }
  585. /**
  586. * mpage_writepages - walk the list of dirty pages of the given address space & writepage() all of them
  587. * @mapping: address space structure to write
  588. * @wbc: subtract the number of written pages from *@wbc->nr_to_write
  589. * @get_block: the filesystem's block mapper function.
  590. *
  591. * This is a library function, which implements the writepages()
  592. * address_space_operation.
  593. */
  594. int
  595. mpage_writepages(struct address_space *mapping,
  596. struct writeback_control *wbc, get_block_t get_block)
  597. {
  598. struct mpage_data mpd = {
  599. .get_block = get_block,
  600. };
  601. struct blk_plug plug;
  602. int ret;
  603. blk_start_plug(&plug);
  604. ret = write_cache_pages(mapping, wbc, __mpage_writepage, &mpd);
  605. if (mpd.bio)
  606. mpage_bio_submit_write(mpd.bio);
  607. blk_finish_plug(&plug);
  608. return ret;
  609. }
  610. EXPORT_SYMBOL(mpage_writepages);