recovery.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /*
  2. * fs/f2fs/recovery.c
  3. *
  4. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com/
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/fs.h>
  12. #include <linux/f2fs_fs.h>
  13. #include "f2fs.h"
  14. #include "node.h"
  15. #include "segment.h"
  16. /*
  17. * Roll forward recovery scenarios.
  18. *
  19. * [Term] F: fsync_mark, D: dentry_mark
  20. *
  21. * 1. inode(x) | CP | inode(x) | dnode(F)
  22. * -> Update the latest inode(x).
  23. *
  24. * 2. inode(x) | CP | inode(F) | dnode(F)
  25. * -> No problem.
  26. *
  27. * 3. inode(x) | CP | dnode(F) | inode(x)
  28. * -> Recover to the latest dnode(F), and drop the last inode(x)
  29. *
  30. * 4. inode(x) | CP | dnode(F) | inode(F)
  31. * -> No problem.
  32. *
  33. * 5. CP | inode(x) | dnode(F)
  34. * -> The inode(DF) was missing. Should drop this dnode(F).
  35. *
  36. * 6. CP | inode(DF) | dnode(F)
  37. * -> No problem.
  38. *
  39. * 7. CP | dnode(F) | inode(DF)
  40. * -> If f2fs_iget fails, then goto next to find inode(DF).
  41. *
  42. * 8. CP | dnode(F) | inode(x)
  43. * -> If f2fs_iget fails, then goto next to find inode(DF).
  44. * But it will fail due to no inode(DF).
  45. */
  46. static struct kmem_cache *fsync_entry_slab;
  47. bool space_for_roll_forward(struct f2fs_sb_info *sbi)
  48. {
  49. s64 nalloc = percpu_counter_sum_positive(&sbi->alloc_valid_block_count);
  50. if (sbi->last_valid_block_count + nalloc > sbi->user_block_count)
  51. return false;
  52. return true;
  53. }
  54. static struct fsync_inode_entry *get_fsync_inode(struct list_head *head,
  55. nid_t ino)
  56. {
  57. struct fsync_inode_entry *entry;
  58. list_for_each_entry(entry, head, list)
  59. if (entry->inode->i_ino == ino)
  60. return entry;
  61. return NULL;
  62. }
  63. static struct fsync_inode_entry *add_fsync_inode(struct f2fs_sb_info *sbi,
  64. struct list_head *head, nid_t ino, bool quota_inode)
  65. {
  66. struct inode *inode;
  67. struct fsync_inode_entry *entry;
  68. int err;
  69. inode = f2fs_iget_retry(sbi->sb, ino);
  70. if (IS_ERR(inode))
  71. return ERR_CAST(inode);
  72. err = dquot_initialize(inode);
  73. if (err)
  74. goto err_out;
  75. if (quota_inode) {
  76. err = dquot_alloc_inode(inode);
  77. if (err)
  78. goto err_out;
  79. }
  80. entry = f2fs_kmem_cache_alloc(fsync_entry_slab, GFP_F2FS_ZERO);
  81. entry->inode = inode;
  82. list_add_tail(&entry->list, head);
  83. return entry;
  84. err_out:
  85. iput(inode);
  86. return ERR_PTR(err);
  87. }
  88. static void del_fsync_inode(struct fsync_inode_entry *entry)
  89. {
  90. iput(entry->inode);
  91. list_del(&entry->list);
  92. kmem_cache_free(fsync_entry_slab, entry);
  93. }
  94. static int recover_dentry(struct inode *inode, struct page *ipage,
  95. struct list_head *dir_list)
  96. {
  97. struct f2fs_inode *raw_inode = F2FS_INODE(ipage);
  98. nid_t pino = le32_to_cpu(raw_inode->i_pino);
  99. struct f2fs_dir_entry *de;
  100. struct fscrypt_name fname;
  101. struct page *page;
  102. struct inode *dir, *einode;
  103. struct fsync_inode_entry *entry;
  104. int err = 0;
  105. char *name;
  106. entry = get_fsync_inode(dir_list, pino);
  107. if (!entry) {
  108. entry = add_fsync_inode(F2FS_I_SB(inode), dir_list,
  109. pino, false);
  110. if (IS_ERR(entry)) {
  111. dir = ERR_CAST(entry);
  112. err = PTR_ERR(entry);
  113. goto out;
  114. }
  115. }
  116. dir = entry->inode;
  117. memset(&fname, 0, sizeof(struct fscrypt_name));
  118. fname.disk_name.len = le32_to_cpu(raw_inode->i_namelen);
  119. fname.disk_name.name = raw_inode->i_name;
  120. if (unlikely(fname.disk_name.len > F2FS_NAME_LEN)) {
  121. WARN_ON(1);
  122. err = -ENAMETOOLONG;
  123. goto out;
  124. }
  125. retry:
  126. de = __f2fs_find_entry(dir, &fname, &page);
  127. if (de && inode->i_ino == le32_to_cpu(de->ino))
  128. goto out_unmap_put;
  129. if (de) {
  130. einode = f2fs_iget_retry(inode->i_sb, le32_to_cpu(de->ino));
  131. if (IS_ERR(einode)) {
  132. WARN_ON(1);
  133. err = PTR_ERR(einode);
  134. if (err == -ENOENT)
  135. err = -EEXIST;
  136. goto out_unmap_put;
  137. }
  138. err = dquot_initialize(einode);
  139. if (err) {
  140. iput(einode);
  141. goto out_unmap_put;
  142. }
  143. err = acquire_orphan_inode(F2FS_I_SB(inode));
  144. if (err) {
  145. iput(einode);
  146. goto out_unmap_put;
  147. }
  148. f2fs_delete_entry(de, page, dir, einode);
  149. iput(einode);
  150. goto retry;
  151. } else if (IS_ERR(page)) {
  152. err = PTR_ERR(page);
  153. } else {
  154. err = __f2fs_do_add_link(dir, &fname, inode,
  155. inode->i_ino, inode->i_mode);
  156. }
  157. if (err == -ENOMEM)
  158. goto retry;
  159. goto out;
  160. out_unmap_put:
  161. f2fs_dentry_kunmap(dir, page);
  162. f2fs_put_page(page, 0);
  163. out:
  164. if (file_enc_name(inode))
  165. name = "<encrypted>";
  166. else
  167. name = raw_inode->i_name;
  168. f2fs_msg(inode->i_sb, KERN_NOTICE,
  169. "%s: ino = %x, name = %s, dir = %lx, err = %d",
  170. __func__, ino_of_node(ipage), name,
  171. IS_ERR(dir) ? 0 : dir->i_ino, err);
  172. return err;
  173. }
  174. static void recover_inline_flags(struct inode *inode, struct f2fs_inode *ri)
  175. {
  176. if (ri->i_inline & F2FS_PIN_FILE)
  177. set_inode_flag(inode, FI_PIN_FILE);
  178. else
  179. clear_inode_flag(inode, FI_PIN_FILE);
  180. if (ri->i_inline & F2FS_DATA_EXIST)
  181. set_inode_flag(inode, FI_DATA_EXIST);
  182. else
  183. clear_inode_flag(inode, FI_DATA_EXIST);
  184. if (!(ri->i_inline & F2FS_INLINE_DOTS))
  185. clear_inode_flag(inode, FI_INLINE_DOTS);
  186. }
  187. static void recover_inode(struct inode *inode, struct page *page)
  188. {
  189. struct f2fs_inode *raw = F2FS_INODE(page);
  190. char *name;
  191. inode->i_mode = le16_to_cpu(raw->i_mode);
  192. f2fs_i_size_write(inode, le64_to_cpu(raw->i_size));
  193. inode->i_atime.tv_sec = le64_to_cpu(raw->i_atime);
  194. inode->i_ctime.tv_sec = le64_to_cpu(raw->i_ctime);
  195. inode->i_mtime.tv_sec = le64_to_cpu(raw->i_mtime);
  196. inode->i_atime.tv_nsec = le32_to_cpu(raw->i_atime_nsec);
  197. inode->i_ctime.tv_nsec = le32_to_cpu(raw->i_ctime_nsec);
  198. inode->i_mtime.tv_nsec = le32_to_cpu(raw->i_mtime_nsec);
  199. F2FS_I(inode)->i_advise = raw->i_advise;
  200. recover_inline_flags(inode, raw);
  201. if (file_enc_name(inode))
  202. name = "<encrypted>";
  203. else
  204. name = F2FS_INODE(page)->i_name;
  205. f2fs_msg(inode->i_sb, KERN_NOTICE,
  206. "recover_inode: ino = %x, name = %s, inline = %x",
  207. ino_of_node(page), name, raw->i_inline);
  208. }
  209. static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
  210. bool check_only)
  211. {
  212. struct curseg_info *curseg;
  213. struct page *page = NULL;
  214. block_t blkaddr;
  215. int err = 0;
  216. /* get node pages in the current segment */
  217. curseg = CURSEG_I(sbi, CURSEG_WARM_NODE);
  218. blkaddr = NEXT_FREE_BLKADDR(sbi, curseg);
  219. while (1) {
  220. struct fsync_inode_entry *entry;
  221. if (!is_valid_blkaddr(sbi, blkaddr, META_POR))
  222. return 0;
  223. page = get_tmp_page(sbi, blkaddr);
  224. if (!is_recoverable_dnode(page))
  225. break;
  226. if (!is_fsync_dnode(page))
  227. goto next;
  228. entry = get_fsync_inode(head, ino_of_node(page));
  229. if (!entry) {
  230. bool quota_inode = false;
  231. if (!check_only &&
  232. IS_INODE(page) && is_dent_dnode(page)) {
  233. err = recover_inode_page(sbi, page);
  234. if (err)
  235. break;
  236. quota_inode = true;
  237. }
  238. /*
  239. * CP | dnode(F) | inode(DF)
  240. * For this case, we should not give up now.
  241. */
  242. entry = add_fsync_inode(sbi, head, ino_of_node(page),
  243. quota_inode);
  244. if (IS_ERR(entry)) {
  245. err = PTR_ERR(entry);
  246. if (err == -ENOENT) {
  247. err = 0;
  248. goto next;
  249. }
  250. break;
  251. }
  252. }
  253. entry->blkaddr = blkaddr;
  254. if (IS_INODE(page) && is_dent_dnode(page))
  255. entry->last_dentry = blkaddr;
  256. next:
  257. /* check next segment */
  258. blkaddr = next_blkaddr_of_node(page);
  259. f2fs_put_page(page, 1);
  260. ra_meta_pages_cond(sbi, blkaddr);
  261. }
  262. f2fs_put_page(page, 1);
  263. return err;
  264. }
  265. static void destroy_fsync_dnodes(struct list_head *head)
  266. {
  267. struct fsync_inode_entry *entry, *tmp;
  268. list_for_each_entry_safe(entry, tmp, head, list)
  269. del_fsync_inode(entry);
  270. }
  271. static int check_index_in_prev_nodes(struct f2fs_sb_info *sbi,
  272. block_t blkaddr, struct dnode_of_data *dn)
  273. {
  274. struct seg_entry *sentry;
  275. unsigned int segno = GET_SEGNO(sbi, blkaddr);
  276. unsigned short blkoff = GET_BLKOFF_FROM_SEG0(sbi, blkaddr);
  277. struct f2fs_summary_block *sum_node;
  278. struct f2fs_summary sum;
  279. struct page *sum_page, *node_page;
  280. struct dnode_of_data tdn = *dn;
  281. nid_t ino, nid;
  282. struct inode *inode;
  283. unsigned int offset;
  284. block_t bidx;
  285. int i;
  286. sentry = get_seg_entry(sbi, segno);
  287. if (!f2fs_test_bit(blkoff, sentry->cur_valid_map))
  288. return 0;
  289. /* Get the previous summary */
  290. for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) {
  291. struct curseg_info *curseg = CURSEG_I(sbi, i);
  292. if (curseg->segno == segno) {
  293. sum = curseg->sum_blk->entries[blkoff];
  294. goto got_it;
  295. }
  296. }
  297. sum_page = get_sum_page(sbi, segno);
  298. sum_node = (struct f2fs_summary_block *)page_address(sum_page);
  299. sum = sum_node->entries[blkoff];
  300. f2fs_put_page(sum_page, 1);
  301. got_it:
  302. /* Use the locked dnode page and inode */
  303. nid = le32_to_cpu(sum.nid);
  304. if (dn->inode->i_ino == nid) {
  305. tdn.nid = nid;
  306. if (!dn->inode_page_locked)
  307. lock_page(dn->inode_page);
  308. tdn.node_page = dn->inode_page;
  309. tdn.ofs_in_node = le16_to_cpu(sum.ofs_in_node);
  310. goto truncate_out;
  311. } else if (dn->nid == nid) {
  312. tdn.ofs_in_node = le16_to_cpu(sum.ofs_in_node);
  313. goto truncate_out;
  314. }
  315. /* Get the node page */
  316. node_page = get_node_page(sbi, nid);
  317. if (IS_ERR(node_page))
  318. return PTR_ERR(node_page);
  319. offset = ofs_of_node(node_page);
  320. ino = ino_of_node(node_page);
  321. f2fs_put_page(node_page, 1);
  322. if (ino != dn->inode->i_ino) {
  323. int ret;
  324. /* Deallocate previous index in the node page */
  325. inode = f2fs_iget_retry(sbi->sb, ino);
  326. if (IS_ERR(inode))
  327. return PTR_ERR(inode);
  328. ret = dquot_initialize(inode);
  329. if (ret) {
  330. iput(inode);
  331. return ret;
  332. }
  333. } else {
  334. inode = dn->inode;
  335. }
  336. bidx = start_bidx_of_node(offset, inode) + le16_to_cpu(sum.ofs_in_node);
  337. /*
  338. * if inode page is locked, unlock temporarily, but its reference
  339. * count keeps alive.
  340. */
  341. if (ino == dn->inode->i_ino && dn->inode_page_locked)
  342. unlock_page(dn->inode_page);
  343. set_new_dnode(&tdn, inode, NULL, NULL, 0);
  344. if (get_dnode_of_data(&tdn, bidx, LOOKUP_NODE))
  345. goto out;
  346. if (tdn.data_blkaddr == blkaddr)
  347. truncate_data_blocks_range(&tdn, 1);
  348. f2fs_put_dnode(&tdn);
  349. out:
  350. if (ino != dn->inode->i_ino)
  351. iput(inode);
  352. else if (dn->inode_page_locked)
  353. lock_page(dn->inode_page);
  354. return 0;
  355. truncate_out:
  356. if (datablock_addr(tdn.inode, tdn.node_page,
  357. tdn.ofs_in_node) == blkaddr)
  358. truncate_data_blocks_range(&tdn, 1);
  359. if (dn->inode->i_ino == nid && !dn->inode_page_locked)
  360. unlock_page(dn->inode_page);
  361. return 0;
  362. }
  363. static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
  364. struct page *page)
  365. {
  366. struct dnode_of_data dn;
  367. struct node_info ni;
  368. unsigned int start, end;
  369. int err = 0, recovered = 0;
  370. /* step 1: recover xattr */
  371. if (IS_INODE(page)) {
  372. recover_inline_xattr(inode, page);
  373. } else if (f2fs_has_xattr_block(ofs_of_node(page))) {
  374. err = recover_xattr_data(inode, page);
  375. if (!err)
  376. recovered++;
  377. goto out;
  378. }
  379. /* step 2: recover inline data */
  380. if (recover_inline_data(inode, page))
  381. goto out;
  382. /* step 3: recover data indices */
  383. start = start_bidx_of_node(ofs_of_node(page), inode);
  384. end = start + ADDRS_PER_PAGE(page, inode);
  385. set_new_dnode(&dn, inode, NULL, NULL, 0);
  386. retry_dn:
  387. err = get_dnode_of_data(&dn, start, ALLOC_NODE);
  388. if (err) {
  389. if (err == -ENOMEM) {
  390. congestion_wait(BLK_RW_ASYNC, HZ/50);
  391. goto retry_dn;
  392. }
  393. goto out;
  394. }
  395. f2fs_wait_on_page_writeback(dn.node_page, NODE, true);
  396. get_node_info(sbi, dn.nid, &ni);
  397. f2fs_bug_on(sbi, ni.ino != ino_of_node(page));
  398. f2fs_bug_on(sbi, ofs_of_node(dn.node_page) != ofs_of_node(page));
  399. for (; start < end; start++, dn.ofs_in_node++) {
  400. block_t src, dest;
  401. src = datablock_addr(dn.inode, dn.node_page, dn.ofs_in_node);
  402. dest = datablock_addr(dn.inode, page, dn.ofs_in_node);
  403. /* skip recovering if dest is the same as src */
  404. if (src == dest)
  405. continue;
  406. /* dest is invalid, just invalidate src block */
  407. if (dest == NULL_ADDR) {
  408. truncate_data_blocks_range(&dn, 1);
  409. continue;
  410. }
  411. if (!file_keep_isize(inode) &&
  412. (i_size_read(inode) <= ((loff_t)start << PAGE_SHIFT)))
  413. f2fs_i_size_write(inode,
  414. (loff_t)(start + 1) << PAGE_SHIFT);
  415. /*
  416. * dest is reserved block, invalidate src block
  417. * and then reserve one new block in dnode page.
  418. */
  419. if (dest == NEW_ADDR) {
  420. truncate_data_blocks_range(&dn, 1);
  421. reserve_new_block(&dn);
  422. continue;
  423. }
  424. /* dest is valid block, try to recover from src to dest */
  425. if (is_valid_blkaddr(sbi, dest, META_POR)) {
  426. if (src == NULL_ADDR) {
  427. err = reserve_new_block(&dn);
  428. #ifdef CONFIG_F2FS_FAULT_INJECTION
  429. while (err)
  430. err = reserve_new_block(&dn);
  431. #endif
  432. /* We should not get -ENOSPC */
  433. f2fs_bug_on(sbi, err);
  434. if (err)
  435. goto err;
  436. }
  437. retry_prev:
  438. /* Check the previous node page having this index */
  439. err = check_index_in_prev_nodes(sbi, dest, &dn);
  440. if (err) {
  441. if (err == -ENOMEM) {
  442. congestion_wait(BLK_RW_ASYNC, HZ/50);
  443. goto retry_prev;
  444. }
  445. goto err;
  446. }
  447. /* write dummy data page */
  448. f2fs_replace_block(sbi, &dn, src, dest,
  449. ni.version, false, false);
  450. recovered++;
  451. }
  452. }
  453. copy_node_footer(dn.node_page, page);
  454. fill_node_footer(dn.node_page, dn.nid, ni.ino,
  455. ofs_of_node(page), false);
  456. set_page_dirty(dn.node_page);
  457. err:
  458. f2fs_put_dnode(&dn);
  459. out:
  460. f2fs_msg(sbi->sb, KERN_NOTICE,
  461. "recover_data: ino = %lx (i_size: %s) recovered = %d, err = %d",
  462. inode->i_ino,
  463. file_keep_isize(inode) ? "keep" : "recover",
  464. recovered, err);
  465. return err;
  466. }
  467. static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list,
  468. struct list_head *dir_list)
  469. {
  470. struct curseg_info *curseg;
  471. struct page *page = NULL;
  472. int err = 0;
  473. block_t blkaddr;
  474. /* get node pages in the current segment */
  475. curseg = CURSEG_I(sbi, CURSEG_WARM_NODE);
  476. blkaddr = NEXT_FREE_BLKADDR(sbi, curseg);
  477. while (1) {
  478. struct fsync_inode_entry *entry;
  479. if (!is_valid_blkaddr(sbi, blkaddr, META_POR))
  480. break;
  481. ra_meta_pages_cond(sbi, blkaddr);
  482. page = get_tmp_page(sbi, blkaddr);
  483. if (!is_recoverable_dnode(page)) {
  484. f2fs_put_page(page, 1);
  485. break;
  486. }
  487. entry = get_fsync_inode(inode_list, ino_of_node(page));
  488. if (!entry)
  489. goto next;
  490. /*
  491. * inode(x) | CP | inode(x) | dnode(F)
  492. * In this case, we can lose the latest inode(x).
  493. * So, call recover_inode for the inode update.
  494. */
  495. if (IS_INODE(page))
  496. recover_inode(entry->inode, page);
  497. if (entry->last_dentry == blkaddr) {
  498. err = recover_dentry(entry->inode, page, dir_list);
  499. if (err) {
  500. f2fs_put_page(page, 1);
  501. break;
  502. }
  503. }
  504. err = do_recover_data(sbi, entry->inode, page);
  505. if (err) {
  506. f2fs_put_page(page, 1);
  507. break;
  508. }
  509. if (entry->blkaddr == blkaddr)
  510. del_fsync_inode(entry);
  511. next:
  512. /* check next segment */
  513. blkaddr = next_blkaddr_of_node(page);
  514. f2fs_put_page(page, 1);
  515. }
  516. if (!err)
  517. allocate_new_segments(sbi);
  518. return err;
  519. }
  520. int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)
  521. {
  522. struct list_head inode_list;
  523. struct list_head dir_list;
  524. int err;
  525. int ret = 0;
  526. unsigned long s_flags = sbi->sb->s_flags;
  527. bool need_writecp = false;
  528. #ifdef CONFIG_QUOTA
  529. int quota_enabled;
  530. #endif
  531. if (s_flags & SB_RDONLY) {
  532. f2fs_msg(sbi->sb, KERN_INFO, "orphan cleanup on readonly fs");
  533. sbi->sb->s_flags &= ~SB_RDONLY;
  534. }
  535. #ifdef CONFIG_QUOTA
  536. /* Needed for iput() to work correctly and not trash data */
  537. sbi->sb->s_flags |= SB_ACTIVE;
  538. /* Turn on quotas so that they are updated correctly */
  539. quota_enabled = f2fs_enable_quota_files(sbi, s_flags & SB_RDONLY);
  540. #endif
  541. fsync_entry_slab = f2fs_kmem_cache_create("f2fs_fsync_inode_entry",
  542. sizeof(struct fsync_inode_entry));
  543. if (!fsync_entry_slab) {
  544. err = -ENOMEM;
  545. goto out;
  546. }
  547. INIT_LIST_HEAD(&inode_list);
  548. INIT_LIST_HEAD(&dir_list);
  549. /* prevent checkpoint */
  550. mutex_lock(&sbi->cp_mutex);
  551. /* step #1: find fsynced inode numbers */
  552. err = find_fsync_dnodes(sbi, &inode_list, check_only);
  553. if (err || list_empty(&inode_list))
  554. goto skip;
  555. if (check_only) {
  556. ret = 1;
  557. goto skip;
  558. }
  559. need_writecp = true;
  560. /* step #2: recover data */
  561. err = recover_data(sbi, &inode_list, &dir_list);
  562. if (!err)
  563. f2fs_bug_on(sbi, !list_empty(&inode_list));
  564. skip:
  565. destroy_fsync_dnodes(&inode_list);
  566. /* truncate meta pages to be used by the recovery */
  567. truncate_inode_pages_range(META_MAPPING(sbi),
  568. (loff_t)MAIN_BLKADDR(sbi) << PAGE_SHIFT, -1);
  569. if (err) {
  570. truncate_inode_pages_final(NODE_MAPPING(sbi));
  571. truncate_inode_pages_final(META_MAPPING(sbi));
  572. }
  573. clear_sbi_flag(sbi, SBI_POR_DOING);
  574. mutex_unlock(&sbi->cp_mutex);
  575. /* let's drop all the directory inodes for clean checkpoint */
  576. destroy_fsync_dnodes(&dir_list);
  577. if (!err && need_writecp) {
  578. struct cp_control cpc = {
  579. .reason = CP_RECOVERY,
  580. };
  581. err = write_checkpoint(sbi, &cpc);
  582. }
  583. kmem_cache_destroy(fsync_entry_slab);
  584. out:
  585. #ifdef CONFIG_QUOTA
  586. /* Turn quotas off */
  587. if (quota_enabled)
  588. f2fs_quota_off_umount(sbi->sb);
  589. #endif
  590. sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */
  591. return ret ? ret: err;
  592. }