mdt.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Meta data file for NILFS
  4. *
  5. * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
  6. *
  7. * Written by Ryusuke Konishi.
  8. */
  9. #include <linux/buffer_head.h>
  10. #include <linux/mpage.h>
  11. #include <linux/mm.h>
  12. #include <linux/writeback.h>
  13. #include <linux/backing-dev.h>
  14. #include <linux/swap.h>
  15. #include <linux/slab.h>
  16. #include "nilfs.h"
  17. #include "btnode.h"
  18. #include "segment.h"
  19. #include "page.h"
  20. #include "mdt.h"
  21. #include "alloc.h" /* nilfs_palloc_destroy_cache() */
  22. #include <trace/events/nilfs2.h>
  23. #define NILFS_MDT_MAX_RA_BLOCKS (16 - 1)
  24. static int
  25. nilfs_mdt_insert_new_block(struct inode *inode, unsigned long block,
  26. struct buffer_head *bh,
  27. void (*init_block)(struct inode *,
  28. struct buffer_head *, void *))
  29. {
  30. struct nilfs_inode_info *ii = NILFS_I(inode);
  31. struct folio *folio = bh->b_folio;
  32. void *from;
  33. int ret;
  34. /* Caller exclude read accesses using page lock */
  35. /* set_buffer_new(bh); */
  36. bh->b_blocknr = 0;
  37. ret = nilfs_bmap_insert(ii->i_bmap, block, (unsigned long)bh);
  38. if (unlikely(ret))
  39. return ret;
  40. set_buffer_mapped(bh);
  41. /* Initialize block (block size > PAGE_SIZE not yet supported) */
  42. from = kmap_local_folio(folio, offset_in_folio(folio, bh->b_data));
  43. memset(from, 0, bh->b_size);
  44. if (init_block)
  45. init_block(inode, bh, from);
  46. kunmap_local(from);
  47. flush_dcache_folio(folio);
  48. set_buffer_uptodate(bh);
  49. mark_buffer_dirty(bh);
  50. nilfs_mdt_mark_dirty(inode);
  51. trace_nilfs2_mdt_insert_new_block(inode, inode->i_ino, block);
  52. return 0;
  53. }
  54. static int nilfs_mdt_create_block(struct inode *inode, unsigned long block,
  55. struct buffer_head **out_bh,
  56. void (*init_block)(struct inode *,
  57. struct buffer_head *,
  58. void *))
  59. {
  60. struct super_block *sb = inode->i_sb;
  61. struct nilfs_transaction_info ti;
  62. struct buffer_head *bh;
  63. int err;
  64. nilfs_transaction_begin(sb, &ti, 0);
  65. err = -ENOMEM;
  66. bh = nilfs_grab_buffer(inode, inode->i_mapping, block, 0);
  67. if (unlikely(!bh))
  68. goto failed_unlock;
  69. err = -EEXIST;
  70. if (buffer_uptodate(bh))
  71. goto failed_bh;
  72. wait_on_buffer(bh);
  73. if (buffer_uptodate(bh))
  74. goto failed_bh;
  75. err = nilfs_mdt_insert_new_block(inode, block, bh, init_block);
  76. if (likely(!err)) {
  77. get_bh(bh);
  78. *out_bh = bh;
  79. }
  80. failed_bh:
  81. folio_unlock(bh->b_folio);
  82. folio_put(bh->b_folio);
  83. brelse(bh);
  84. failed_unlock:
  85. if (likely(!err))
  86. err = nilfs_transaction_commit(sb);
  87. else
  88. nilfs_transaction_abort(sb);
  89. return err;
  90. }
  91. static int
  92. nilfs_mdt_submit_block(struct inode *inode, unsigned long blkoff, blk_opf_t opf,
  93. struct buffer_head **out_bh)
  94. {
  95. struct buffer_head *bh;
  96. __u64 blknum = 0;
  97. int ret = -ENOMEM;
  98. bh = nilfs_grab_buffer(inode, inode->i_mapping, blkoff, 0);
  99. if (unlikely(!bh))
  100. goto failed;
  101. ret = -EEXIST; /* internal code */
  102. if (buffer_uptodate(bh))
  103. goto out;
  104. if (opf & REQ_RAHEAD) {
  105. if (!trylock_buffer(bh)) {
  106. ret = -EBUSY;
  107. goto failed_bh;
  108. }
  109. } else /* opf == REQ_OP_READ */
  110. lock_buffer(bh);
  111. if (buffer_uptodate(bh)) {
  112. unlock_buffer(bh);
  113. goto out;
  114. }
  115. ret = nilfs_bmap_lookup(NILFS_I(inode)->i_bmap, blkoff, &blknum);
  116. if (unlikely(ret)) {
  117. unlock_buffer(bh);
  118. goto failed_bh;
  119. }
  120. map_bh(bh, inode->i_sb, (sector_t)blknum);
  121. bh->b_end_io = end_buffer_read_sync;
  122. get_bh(bh);
  123. submit_bh(opf, bh);
  124. ret = 0;
  125. trace_nilfs2_mdt_submit_block(inode, inode->i_ino, blkoff,
  126. opf & REQ_OP_MASK);
  127. out:
  128. get_bh(bh);
  129. *out_bh = bh;
  130. failed_bh:
  131. folio_unlock(bh->b_folio);
  132. folio_put(bh->b_folio);
  133. brelse(bh);
  134. failed:
  135. return ret;
  136. }
  137. static int nilfs_mdt_read_block(struct inode *inode, unsigned long block,
  138. int readahead, struct buffer_head **out_bh)
  139. {
  140. struct buffer_head *first_bh, *bh;
  141. unsigned long blkoff;
  142. int i, nr_ra_blocks = NILFS_MDT_MAX_RA_BLOCKS;
  143. int err;
  144. err = nilfs_mdt_submit_block(inode, block, REQ_OP_READ, &first_bh);
  145. if (err == -EEXIST) /* internal code */
  146. goto out;
  147. if (unlikely(err))
  148. goto failed;
  149. if (readahead) {
  150. blkoff = block + 1;
  151. for (i = 0; i < nr_ra_blocks; i++, blkoff++) {
  152. err = nilfs_mdt_submit_block(inode, blkoff,
  153. REQ_OP_READ | REQ_RAHEAD, &bh);
  154. if (likely(!err || err == -EEXIST))
  155. brelse(bh);
  156. else if (err != -EBUSY)
  157. break;
  158. /* abort readahead if bmap lookup failed */
  159. if (!buffer_locked(first_bh))
  160. goto out_no_wait;
  161. }
  162. }
  163. wait_on_buffer(first_bh);
  164. out_no_wait:
  165. err = -EIO;
  166. if (!buffer_uptodate(first_bh)) {
  167. nilfs_err(inode->i_sb,
  168. "I/O error reading meta-data file (ino=%lu, block-offset=%lu)",
  169. inode->i_ino, block);
  170. goto failed_bh;
  171. }
  172. out:
  173. *out_bh = first_bh;
  174. return 0;
  175. failed_bh:
  176. brelse(first_bh);
  177. failed:
  178. return err;
  179. }
  180. /**
  181. * nilfs_mdt_get_block - read or create a buffer on meta data file.
  182. * @inode: inode of the meta data file
  183. * @blkoff: block offset
  184. * @create: create flag
  185. * @init_block: initializer used for newly allocated block
  186. * @out_bh: output of a pointer to the buffer_head
  187. *
  188. * nilfs_mdt_get_block() looks up the specified buffer and tries to create
  189. * a new buffer if @create is not zero. If (and only if) this function
  190. * succeeds, it stores a pointer to the retrieved buffer head in the location
  191. * pointed to by @out_bh.
  192. *
  193. * The retrieved buffer may be either an existing one or a newly allocated one.
  194. * For a newly created buffer, if the callback function argument @init_block
  195. * is non-NULL, the callback will be called with the buffer locked to format
  196. * the block.
  197. *
  198. * Return: 0 on success, or one of the following negative error codes on
  199. * failure:
  200. * * %-EIO - I/O error (including metadata corruption).
  201. * * %-ENOENT - The specified block does not exist (hole block).
  202. * * %-ENOMEM - Insufficient memory available.
  203. * * %-EROFS - Read only filesystem (for create mode).
  204. */
  205. int nilfs_mdt_get_block(struct inode *inode, unsigned long blkoff, int create,
  206. void (*init_block)(struct inode *,
  207. struct buffer_head *, void *),
  208. struct buffer_head **out_bh)
  209. {
  210. int ret;
  211. /* Should be rewritten with merging nilfs_mdt_read_block() */
  212. retry:
  213. ret = nilfs_mdt_read_block(inode, blkoff, !create, out_bh);
  214. if (!create || ret != -ENOENT)
  215. return ret;
  216. ret = nilfs_mdt_create_block(inode, blkoff, out_bh, init_block);
  217. if (unlikely(ret == -EEXIST)) {
  218. /* create = 0; */ /* limit read-create loop retries */
  219. goto retry;
  220. }
  221. return ret;
  222. }
  223. /**
  224. * nilfs_mdt_find_block - find and get a buffer on meta data file.
  225. * @inode: inode of the meta data file
  226. * @start: start block offset (inclusive)
  227. * @end: end block offset (inclusive)
  228. * @blkoff: block offset
  229. * @out_bh: place to store a pointer to buffer_head struct
  230. *
  231. * nilfs_mdt_find_block() looks up an existing block in range of
  232. * [@start, @end] and stores pointer to a buffer head of the block to
  233. * @out_bh, and block offset to @blkoff, respectively. @out_bh and
  234. * @blkoff are substituted only when zero is returned.
  235. *
  236. * Return: 0 on success, or one of the following negative error codes on
  237. * failure:
  238. * * %-EIO - I/O error (including metadata corruption).
  239. * * %-ENOENT - No block was found in the range.
  240. * * %-ENOMEM - Insufficient memory available.
  241. */
  242. int nilfs_mdt_find_block(struct inode *inode, unsigned long start,
  243. unsigned long end, unsigned long *blkoff,
  244. struct buffer_head **out_bh)
  245. {
  246. __u64 next;
  247. int ret;
  248. if (unlikely(start > end))
  249. return -ENOENT;
  250. ret = nilfs_mdt_read_block(inode, start, true, out_bh);
  251. if (!ret) {
  252. *blkoff = start;
  253. goto out;
  254. }
  255. if (unlikely(ret != -ENOENT || start == ULONG_MAX))
  256. goto out;
  257. ret = nilfs_bmap_seek_key(NILFS_I(inode)->i_bmap, start + 1, &next);
  258. if (!ret) {
  259. if (next <= end) {
  260. ret = nilfs_mdt_read_block(inode, next, true, out_bh);
  261. if (!ret)
  262. *blkoff = next;
  263. } else {
  264. ret = -ENOENT;
  265. }
  266. }
  267. out:
  268. return ret;
  269. }
  270. /**
  271. * nilfs_mdt_delete_block - make a hole on the meta data file.
  272. * @inode: inode of the meta data file
  273. * @block: block offset
  274. *
  275. * Return: 0 on success, or one of the following negative error codes on
  276. * failure:
  277. * * %-EIO - I/O error (including metadata corruption).
  278. * * %-ENOENT - Non-existent block.
  279. * * %-ENOMEM - Insufficient memory available.
  280. */
  281. int nilfs_mdt_delete_block(struct inode *inode, unsigned long block)
  282. {
  283. struct nilfs_inode_info *ii = NILFS_I(inode);
  284. int err;
  285. err = nilfs_bmap_delete(ii->i_bmap, block);
  286. if (!err || err == -ENOENT) {
  287. nilfs_mdt_mark_dirty(inode);
  288. nilfs_mdt_forget_block(inode, block);
  289. }
  290. return err;
  291. }
  292. /**
  293. * nilfs_mdt_forget_block - discard dirty state and try to remove the page
  294. * @inode: inode of the meta data file
  295. * @block: block offset
  296. *
  297. * nilfs_mdt_forget_block() clears a dirty flag of the specified buffer, and
  298. * tries to release the page including the buffer from a page cache.
  299. *
  300. * Return: 0 on success, or one of the following negative error codes on
  301. * failure:
  302. * * %-EBUSY - Page has an active buffer.
  303. * * %-ENOENT - Page cache has no page addressed by the offset.
  304. */
  305. int nilfs_mdt_forget_block(struct inode *inode, unsigned long block)
  306. {
  307. pgoff_t index = block >> (PAGE_SHIFT - inode->i_blkbits);
  308. struct folio *folio;
  309. struct buffer_head *bh;
  310. int ret = 0;
  311. int still_dirty;
  312. folio = filemap_lock_folio(inode->i_mapping, index);
  313. if (IS_ERR(folio))
  314. return -ENOENT;
  315. folio_wait_writeback(folio);
  316. bh = folio_buffers(folio);
  317. if (bh) {
  318. unsigned long first_block = index <<
  319. (PAGE_SHIFT - inode->i_blkbits);
  320. bh = get_nth_bh(bh, block - first_block);
  321. nilfs_forget_buffer(bh);
  322. }
  323. still_dirty = folio_test_dirty(folio);
  324. folio_unlock(folio);
  325. folio_put(folio);
  326. if (still_dirty ||
  327. invalidate_inode_pages2_range(inode->i_mapping, index, index) != 0)
  328. ret = -EBUSY;
  329. return ret;
  330. }
  331. int nilfs_mdt_fetch_dirty(struct inode *inode)
  332. {
  333. struct nilfs_inode_info *ii = NILFS_I(inode);
  334. if (nilfs_bmap_test_and_clear_dirty(ii->i_bmap)) {
  335. set_bit(NILFS_I_DIRTY, &ii->i_state);
  336. return 1;
  337. }
  338. return test_bit(NILFS_I_DIRTY, &ii->i_state);
  339. }
  340. static int nilfs_mdt_write_folio(struct folio *folio,
  341. struct writeback_control *wbc)
  342. {
  343. struct inode *inode = folio->mapping->host;
  344. struct super_block *sb;
  345. int err = 0;
  346. if (inode && sb_rdonly(inode->i_sb)) {
  347. /*
  348. * It means that filesystem was remounted in read-only
  349. * mode because of error or metadata corruption. But we
  350. * have dirty folios that try to be flushed in background.
  351. * So, here we simply discard this dirty folio.
  352. */
  353. nilfs_clear_folio_dirty(folio);
  354. folio_unlock(folio);
  355. return -EROFS;
  356. }
  357. folio_redirty_for_writepage(wbc, folio);
  358. folio_unlock(folio);
  359. if (!inode)
  360. return 0;
  361. sb = inode->i_sb;
  362. if (wbc->sync_mode == WB_SYNC_ALL)
  363. err = nilfs_construct_segment(sb);
  364. return err;
  365. }
  366. static int nilfs_mdt_writeback(struct address_space *mapping,
  367. struct writeback_control *wbc)
  368. {
  369. struct folio *folio = NULL;
  370. int error;
  371. while ((folio = writeback_iter(mapping, wbc, folio, &error)))
  372. error = nilfs_mdt_write_folio(folio, wbc);
  373. return error;
  374. }
  375. static const struct address_space_operations def_mdt_aops = {
  376. .dirty_folio = block_dirty_folio,
  377. .invalidate_folio = block_invalidate_folio,
  378. .writepages = nilfs_mdt_writeback,
  379. .migrate_folio = buffer_migrate_folio_norefs,
  380. };
  381. static const struct inode_operations def_mdt_iops;
  382. static const struct file_operations def_mdt_fops;
  383. int nilfs_mdt_init(struct inode *inode, gfp_t gfp_mask, size_t objsz)
  384. {
  385. struct nilfs_mdt_info *mi;
  386. mi = kzalloc(max(sizeof(*mi), objsz), GFP_NOFS);
  387. if (!mi)
  388. return -ENOMEM;
  389. init_rwsem(&mi->mi_sem);
  390. inode->i_private = mi;
  391. inode->i_mode = S_IFREG;
  392. mapping_set_gfp_mask(inode->i_mapping, gfp_mask);
  393. inode->i_op = &def_mdt_iops;
  394. inode->i_fop = &def_mdt_fops;
  395. inode->i_mapping->a_ops = &def_mdt_aops;
  396. return 0;
  397. }
  398. /**
  399. * nilfs_mdt_clear - do cleanup for the metadata file
  400. * @inode: inode of the metadata file
  401. */
  402. void nilfs_mdt_clear(struct inode *inode)
  403. {
  404. struct nilfs_mdt_info *mdi = NILFS_MDT(inode);
  405. struct nilfs_shadow_map *shadow = mdi->mi_shadow;
  406. if (mdi->mi_palloc_cache)
  407. nilfs_palloc_destroy_cache(inode);
  408. if (shadow) {
  409. struct inode *s_inode = shadow->inode;
  410. shadow->inode = NULL;
  411. iput(s_inode);
  412. mdi->mi_shadow = NULL;
  413. }
  414. }
  415. /**
  416. * nilfs_mdt_destroy - release resources used by the metadata file
  417. * @inode: inode of the metadata file
  418. */
  419. void nilfs_mdt_destroy(struct inode *inode)
  420. {
  421. struct nilfs_mdt_info *mdi = NILFS_MDT(inode);
  422. kfree(mdi->mi_bgl); /* kfree(NULL) is safe */
  423. kfree(mdi);
  424. }
  425. void nilfs_mdt_set_entry_size(struct inode *inode, unsigned int entry_size,
  426. unsigned int header_size)
  427. {
  428. struct nilfs_mdt_info *mi = NILFS_MDT(inode);
  429. mi->mi_entry_size = entry_size;
  430. mi->mi_entries_per_block = i_blocksize(inode) / entry_size;
  431. mi->mi_first_entry_offset = DIV_ROUND_UP(header_size, entry_size);
  432. }
  433. /**
  434. * nilfs_mdt_setup_shadow_map - setup shadow map and bind it to metadata file
  435. * @inode: inode of the metadata file
  436. * @shadow: shadow mapping
  437. *
  438. * Return: 0 on success, or a negative error code on failure.
  439. */
  440. int nilfs_mdt_setup_shadow_map(struct inode *inode,
  441. struct nilfs_shadow_map *shadow)
  442. {
  443. struct nilfs_mdt_info *mi = NILFS_MDT(inode);
  444. struct inode *s_inode;
  445. INIT_LIST_HEAD(&shadow->frozen_buffers);
  446. s_inode = nilfs_iget_for_shadow(inode);
  447. if (IS_ERR(s_inode))
  448. return PTR_ERR(s_inode);
  449. shadow->inode = s_inode;
  450. mi->mi_shadow = shadow;
  451. return 0;
  452. }
  453. /**
  454. * nilfs_mdt_save_to_shadow_map - copy bmap and dirty pages to shadow map
  455. * @inode: inode of the metadata file
  456. *
  457. * Return: 0 on success, or a negative error code on failure.
  458. */
  459. int nilfs_mdt_save_to_shadow_map(struct inode *inode)
  460. {
  461. struct nilfs_mdt_info *mi = NILFS_MDT(inode);
  462. struct nilfs_inode_info *ii = NILFS_I(inode);
  463. struct nilfs_shadow_map *shadow = mi->mi_shadow;
  464. struct inode *s_inode = shadow->inode;
  465. int ret;
  466. ret = nilfs_copy_dirty_pages(s_inode->i_mapping, inode->i_mapping);
  467. if (ret)
  468. goto out;
  469. ret = nilfs_copy_dirty_pages(NILFS_I(s_inode)->i_assoc_inode->i_mapping,
  470. ii->i_assoc_inode->i_mapping);
  471. if (ret)
  472. goto out;
  473. nilfs_bmap_save(ii->i_bmap, &shadow->bmap_store);
  474. out:
  475. return ret;
  476. }
  477. int nilfs_mdt_freeze_buffer(struct inode *inode, struct buffer_head *bh)
  478. {
  479. struct nilfs_shadow_map *shadow = NILFS_MDT(inode)->mi_shadow;
  480. struct buffer_head *bh_frozen;
  481. struct folio *folio;
  482. int blkbits = inode->i_blkbits;
  483. folio = filemap_grab_folio(shadow->inode->i_mapping,
  484. bh->b_folio->index);
  485. if (IS_ERR(folio))
  486. return PTR_ERR(folio);
  487. bh_frozen = folio_buffers(folio);
  488. if (!bh_frozen)
  489. bh_frozen = create_empty_buffers(folio, 1 << blkbits, 0);
  490. bh_frozen = get_nth_bh(bh_frozen,
  491. offset_in_folio(folio, bh->b_data) >> blkbits);
  492. if (!buffer_uptodate(bh_frozen))
  493. nilfs_copy_buffer(bh_frozen, bh);
  494. if (list_empty(&bh_frozen->b_assoc_buffers)) {
  495. list_add_tail(&bh_frozen->b_assoc_buffers,
  496. &shadow->frozen_buffers);
  497. set_buffer_nilfs_redirected(bh);
  498. } else {
  499. brelse(bh_frozen); /* already frozen */
  500. }
  501. folio_unlock(folio);
  502. folio_put(folio);
  503. return 0;
  504. }
  505. struct buffer_head *
  506. nilfs_mdt_get_frozen_buffer(struct inode *inode, struct buffer_head *bh)
  507. {
  508. struct nilfs_shadow_map *shadow = NILFS_MDT(inode)->mi_shadow;
  509. struct buffer_head *bh_frozen = NULL;
  510. struct folio *folio;
  511. int n;
  512. folio = filemap_lock_folio(shadow->inode->i_mapping,
  513. bh->b_folio->index);
  514. if (!IS_ERR(folio)) {
  515. bh_frozen = folio_buffers(folio);
  516. if (bh_frozen) {
  517. n = offset_in_folio(folio, bh->b_data) >>
  518. inode->i_blkbits;
  519. bh_frozen = get_nth_bh(bh_frozen, n);
  520. }
  521. folio_unlock(folio);
  522. folio_put(folio);
  523. }
  524. return bh_frozen;
  525. }
  526. static void nilfs_release_frozen_buffers(struct nilfs_shadow_map *shadow)
  527. {
  528. struct list_head *head = &shadow->frozen_buffers;
  529. struct buffer_head *bh;
  530. while (!list_empty(head)) {
  531. bh = list_first_entry(head, struct buffer_head,
  532. b_assoc_buffers);
  533. list_del_init(&bh->b_assoc_buffers);
  534. brelse(bh); /* drop ref-count to make it releasable */
  535. }
  536. }
  537. /**
  538. * nilfs_mdt_restore_from_shadow_map - restore dirty pages and bmap state
  539. * @inode: inode of the metadata file
  540. */
  541. void nilfs_mdt_restore_from_shadow_map(struct inode *inode)
  542. {
  543. struct nilfs_mdt_info *mi = NILFS_MDT(inode);
  544. struct nilfs_inode_info *ii = NILFS_I(inode);
  545. struct nilfs_shadow_map *shadow = mi->mi_shadow;
  546. down_write(&mi->mi_sem);
  547. if (mi->mi_palloc_cache)
  548. nilfs_palloc_clear_cache(inode);
  549. nilfs_clear_dirty_pages(inode->i_mapping);
  550. nilfs_copy_back_pages(inode->i_mapping, shadow->inode->i_mapping);
  551. nilfs_clear_dirty_pages(ii->i_assoc_inode->i_mapping);
  552. nilfs_copy_back_pages(ii->i_assoc_inode->i_mapping,
  553. NILFS_I(shadow->inode)->i_assoc_inode->i_mapping);
  554. nilfs_bmap_restore(ii->i_bmap, &shadow->bmap_store);
  555. up_write(&mi->mi_sem);
  556. }
  557. /**
  558. * nilfs_mdt_clear_shadow_map - truncate pages in shadow map caches
  559. * @inode: inode of the metadata file
  560. */
  561. void nilfs_mdt_clear_shadow_map(struct inode *inode)
  562. {
  563. struct nilfs_mdt_info *mi = NILFS_MDT(inode);
  564. struct nilfs_shadow_map *shadow = mi->mi_shadow;
  565. struct inode *shadow_btnc_inode = NILFS_I(shadow->inode)->i_assoc_inode;
  566. down_write(&mi->mi_sem);
  567. nilfs_release_frozen_buffers(shadow);
  568. truncate_inode_pages(shadow->inode->i_mapping, 0);
  569. truncate_inode_pages(shadow_btnc_inode->i_mapping, 0);
  570. up_write(&mi->mi_sem);
  571. }