1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
8 #include <asm/unaligned.h>
10 #include <linux/f2fs_fs.h>
11 #include <linux/sched/mm.h>
17 * Roll forward recovery scenarios.
19 * [Term] F: fsync_mark, D: dentry_mark
21 * 1. inode(x) | CP | inode(x) | dnode(F)
22 * -> Update the latest inode(x).
24 * 2. inode(x) | CP | inode(F) | dnode(F)
27 * 3. inode(x) | CP | dnode(F) | inode(x)
28 * -> Recover to the latest dnode(F), and drop the last inode(x)
30 * 4. inode(x) | CP | dnode(F) | inode(F)
33 * 5. CP | inode(x) | dnode(F)
34 * -> The inode(DF) was missing. Should drop this dnode(F).
36 * 6. CP | inode(DF) | dnode(F)
39 * 7. CP | dnode(F) | inode(DF)
40 * -> If f2fs_iget fails, then goto next to find inode(DF).
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).
47 static struct kmem_cache *fsync_entry_slab;
49 #if IS_ENABLED(CONFIG_UNICODE)
50 extern struct kmem_cache *f2fs_cf_name_slab;
53 bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi)
55 s64 nalloc = percpu_counter_sum_positive(&sbi->alloc_valid_block_count);
57 if (sbi->last_valid_block_count + nalloc > sbi->user_block_count)
59 if (NM_I(sbi)->max_rf_node_blocks &&
60 percpu_counter_sum_positive(&sbi->rf_node_block_count) >=
61 NM_I(sbi)->max_rf_node_blocks)
66 static struct fsync_inode_entry *get_fsync_inode(struct list_head *head,
69 struct fsync_inode_entry *entry;
71 list_for_each_entry(entry, head, list)
72 if (entry->inode->i_ino == ino)
78 static struct fsync_inode_entry *add_fsync_inode(struct f2fs_sb_info *sbi,
79 struct list_head *head, nid_t ino, bool quota_inode)
82 struct fsync_inode_entry *entry;
85 inode = f2fs_iget_retry(sbi->sb, ino);
87 return ERR_CAST(inode);
89 err = f2fs_dquot_initialize(inode);
94 err = dquot_alloc_inode(inode);
99 entry = f2fs_kmem_cache_alloc(fsync_entry_slab,
100 GFP_F2FS_ZERO, true, NULL);
101 entry->inode = inode;
102 list_add_tail(&entry->list, head);
110 static void del_fsync_inode(struct fsync_inode_entry *entry, int drop)
113 /* inode should not be recovered, drop it */
114 f2fs_inode_synced(entry->inode);
117 list_del(&entry->list);
118 kmem_cache_free(fsync_entry_slab, entry);
121 static int init_recovered_filename(const struct inode *dir,
122 struct f2fs_inode *raw_inode,
123 struct f2fs_filename *fname,
124 struct qstr *usr_fname)
128 memset(fname, 0, sizeof(*fname));
129 fname->disk_name.len = le32_to_cpu(raw_inode->i_namelen);
130 fname->disk_name.name = raw_inode->i_name;
132 if (WARN_ON(fname->disk_name.len > F2FS_NAME_LEN))
133 return -ENAMETOOLONG;
135 if (!IS_ENCRYPTED(dir)) {
136 usr_fname->name = fname->disk_name.name;
137 usr_fname->len = fname->disk_name.len;
138 fname->usr_fname = usr_fname;
141 /* Compute the hash of the filename */
142 if (IS_ENCRYPTED(dir) && IS_CASEFOLDED(dir)) {
144 * In this case the hash isn't computable without the key, so it
147 if (fname->disk_name.len + sizeof(f2fs_hash_t) > F2FS_NAME_LEN)
149 fname->hash = get_unaligned((f2fs_hash_t *)
150 &raw_inode->i_name[fname->disk_name.len]);
151 } else if (IS_CASEFOLDED(dir)) {
152 err = f2fs_init_casefolded_name(dir, fname);
155 f2fs_hash_filename(dir, fname);
156 #if IS_ENABLED(CONFIG_UNICODE)
157 /* Case-sensitive match is fine for recovery */
158 kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name);
159 fname->cf_name.name = NULL;
162 f2fs_hash_filename(dir, fname);
167 static int recover_dentry(struct inode *inode, struct page *ipage,
168 struct list_head *dir_list)
170 struct f2fs_inode *raw_inode = F2FS_INODE(ipage);
171 nid_t pino = le32_to_cpu(raw_inode->i_pino);
172 struct f2fs_dir_entry *de;
173 struct f2fs_filename fname;
174 struct qstr usr_fname;
176 struct inode *dir, *einode;
177 struct fsync_inode_entry *entry;
181 entry = get_fsync_inode(dir_list, pino);
183 entry = add_fsync_inode(F2FS_I_SB(inode), dir_list,
186 dir = ERR_CAST(entry);
187 err = PTR_ERR(entry);
193 err = init_recovered_filename(dir, raw_inode, &fname, &usr_fname);
197 de = __f2fs_find_entry(dir, &fname, &page);
198 if (de && inode->i_ino == le32_to_cpu(de->ino))
202 einode = f2fs_iget_retry(inode->i_sb, le32_to_cpu(de->ino));
203 if (IS_ERR(einode)) {
205 err = PTR_ERR(einode);
211 err = f2fs_dquot_initialize(einode);
217 err = f2fs_acquire_orphan_inode(F2FS_I_SB(inode));
222 f2fs_delete_entry(de, page, dir, einode);
225 } else if (IS_ERR(page)) {
228 err = f2fs_add_dentry(dir, &fname, inode,
229 inode->i_ino, inode->i_mode);
236 f2fs_put_page(page, 0);
238 if (file_enc_name(inode))
239 name = "<encrypted>";
241 name = raw_inode->i_name;
242 f2fs_notice(F2FS_I_SB(inode), "%s: ino = %x, name = %s, dir = %lx, err = %d",
243 __func__, ino_of_node(ipage), name,
244 IS_ERR(dir) ? 0 : dir->i_ino, err);
248 static int recover_quota_data(struct inode *inode, struct page *page)
250 struct f2fs_inode *raw = F2FS_INODE(page);
252 uid_t i_uid = le32_to_cpu(raw->i_uid);
253 gid_t i_gid = le32_to_cpu(raw->i_gid);
256 memset(&attr, 0, sizeof(attr));
258 attr.ia_vfsuid = VFSUIDT_INIT(make_kuid(inode->i_sb->s_user_ns, i_uid));
259 attr.ia_vfsgid = VFSGIDT_INIT(make_kgid(inode->i_sb->s_user_ns, i_gid));
261 if (!vfsuid_eq(attr.ia_vfsuid, i_uid_into_vfsuid(&init_user_ns, inode)))
262 attr.ia_valid |= ATTR_UID;
263 if (!vfsgid_eq(attr.ia_vfsgid, i_gid_into_vfsgid(&init_user_ns, inode)))
264 attr.ia_valid |= ATTR_GID;
269 err = dquot_transfer(&init_user_ns, inode, &attr);
271 set_sbi_flag(F2FS_I_SB(inode), SBI_QUOTA_NEED_REPAIR);
275 static void recover_inline_flags(struct inode *inode, struct f2fs_inode *ri)
277 if (ri->i_inline & F2FS_PIN_FILE)
278 set_inode_flag(inode, FI_PIN_FILE);
280 clear_inode_flag(inode, FI_PIN_FILE);
281 if (ri->i_inline & F2FS_DATA_EXIST)
282 set_inode_flag(inode, FI_DATA_EXIST);
284 clear_inode_flag(inode, FI_DATA_EXIST);
287 static int recover_inode(struct inode *inode, struct page *page)
289 struct f2fs_inode *raw = F2FS_INODE(page);
293 inode->i_mode = le16_to_cpu(raw->i_mode);
295 err = recover_quota_data(inode, page);
299 i_uid_write(inode, le32_to_cpu(raw->i_uid));
300 i_gid_write(inode, le32_to_cpu(raw->i_gid));
302 if (raw->i_inline & F2FS_EXTRA_ATTR) {
303 if (f2fs_sb_has_project_quota(F2FS_I_SB(inode)) &&
304 F2FS_FITS_IN_INODE(raw, le16_to_cpu(raw->i_extra_isize),
309 i_projid = (projid_t)le32_to_cpu(raw->i_projid);
310 kprojid = make_kprojid(&init_user_ns, i_projid);
312 if (!projid_eq(kprojid, F2FS_I(inode)->i_projid)) {
313 err = f2fs_transfer_project_quota(inode,
317 F2FS_I(inode)->i_projid = kprojid;
322 f2fs_i_size_write(inode, le64_to_cpu(raw->i_size));
323 inode->i_atime.tv_sec = le64_to_cpu(raw->i_atime);
324 inode->i_ctime.tv_sec = le64_to_cpu(raw->i_ctime);
325 inode->i_mtime.tv_sec = le64_to_cpu(raw->i_mtime);
326 inode->i_atime.tv_nsec = le32_to_cpu(raw->i_atime_nsec);
327 inode->i_ctime.tv_nsec = le32_to_cpu(raw->i_ctime_nsec);
328 inode->i_mtime.tv_nsec = le32_to_cpu(raw->i_mtime_nsec);
330 F2FS_I(inode)->i_advise = raw->i_advise;
331 F2FS_I(inode)->i_flags = le32_to_cpu(raw->i_flags);
332 f2fs_set_inode_flags(inode);
333 F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] =
334 le16_to_cpu(raw->i_gc_failures);
336 recover_inline_flags(inode, raw);
338 f2fs_mark_inode_dirty_sync(inode, true);
340 if (file_enc_name(inode))
341 name = "<encrypted>";
343 name = F2FS_INODE(page)->i_name;
345 f2fs_notice(F2FS_I_SB(inode), "recover_inode: ino = %x, name = %s, inline = %x",
346 ino_of_node(page), name, raw->i_inline);
350 static unsigned int adjust_por_ra_blocks(struct f2fs_sb_info *sbi,
351 unsigned int ra_blocks, unsigned int blkaddr,
352 unsigned int next_blkaddr)
354 if (blkaddr + 1 == next_blkaddr)
355 ra_blocks = min_t(unsigned int, RECOVERY_MAX_RA_BLOCKS,
357 else if (next_blkaddr % sbi->blocks_per_seg)
358 ra_blocks = max_t(unsigned int, RECOVERY_MIN_RA_BLOCKS,
363 static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
366 struct curseg_info *curseg;
367 struct page *page = NULL;
369 unsigned int loop_cnt = 0;
370 unsigned int ra_blocks = RECOVERY_MAX_RA_BLOCKS;
371 unsigned int free_blocks = MAIN_SEGS(sbi) * sbi->blocks_per_seg -
372 valid_user_blocks(sbi);
375 /* get node pages in the current segment */
376 curseg = CURSEG_I(sbi, CURSEG_WARM_NODE);
377 blkaddr = NEXT_FREE_BLKADDR(sbi, curseg);
380 struct fsync_inode_entry *entry;
382 if (!f2fs_is_valid_blkaddr(sbi, blkaddr, META_POR))
385 page = f2fs_get_tmp_page(sbi, blkaddr);
391 if (!is_recoverable_dnode(page)) {
392 f2fs_put_page(page, 1);
396 if (!is_fsync_dnode(page))
399 entry = get_fsync_inode(head, ino_of_node(page));
401 bool quota_inode = false;
404 IS_INODE(page) && is_dent_dnode(page)) {
405 err = f2fs_recover_inode_page(sbi, page);
407 f2fs_put_page(page, 1);
414 * CP | dnode(F) | inode(DF)
415 * For this case, we should not give up now.
417 entry = add_fsync_inode(sbi, head, ino_of_node(page),
420 err = PTR_ERR(entry);
421 if (err == -ENOENT) {
425 f2fs_put_page(page, 1);
429 entry->blkaddr = blkaddr;
431 if (IS_INODE(page) && is_dent_dnode(page))
432 entry->last_dentry = blkaddr;
434 /* sanity check in order to detect looped node chain */
435 if (++loop_cnt >= free_blocks ||
436 blkaddr == next_blkaddr_of_node(page)) {
437 f2fs_notice(sbi, "%s: detect looped node chain, blkaddr:%u, next:%u",
439 next_blkaddr_of_node(page));
440 f2fs_put_page(page, 1);
445 ra_blocks = adjust_por_ra_blocks(sbi, ra_blocks, blkaddr,
446 next_blkaddr_of_node(page));
448 /* check next segment */
449 blkaddr = next_blkaddr_of_node(page);
450 f2fs_put_page(page, 1);
452 f2fs_ra_meta_pages_cond(sbi, blkaddr, ra_blocks);
457 static void destroy_fsync_dnodes(struct list_head *head, int drop)
459 struct fsync_inode_entry *entry, *tmp;
461 list_for_each_entry_safe(entry, tmp, head, list)
462 del_fsync_inode(entry, drop);
465 static int check_index_in_prev_nodes(struct f2fs_sb_info *sbi,
466 block_t blkaddr, struct dnode_of_data *dn)
468 struct seg_entry *sentry;
469 unsigned int segno = GET_SEGNO(sbi, blkaddr);
470 unsigned short blkoff = GET_BLKOFF_FROM_SEG0(sbi, blkaddr);
471 struct f2fs_summary_block *sum_node;
472 struct f2fs_summary sum;
473 struct page *sum_page, *node_page;
474 struct dnode_of_data tdn = *dn;
477 unsigned int offset, ofs_in_node, max_addrs;
481 sentry = get_seg_entry(sbi, segno);
482 if (!f2fs_test_bit(blkoff, sentry->cur_valid_map))
485 /* Get the previous summary */
486 for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) {
487 struct curseg_info *curseg = CURSEG_I(sbi, i);
489 if (curseg->segno == segno) {
490 sum = curseg->sum_blk->entries[blkoff];
495 sum_page = f2fs_get_sum_page(sbi, segno);
496 if (IS_ERR(sum_page))
497 return PTR_ERR(sum_page);
498 sum_node = (struct f2fs_summary_block *)page_address(sum_page);
499 sum = sum_node->entries[blkoff];
500 f2fs_put_page(sum_page, 1);
502 /* Use the locked dnode page and inode */
503 nid = le32_to_cpu(sum.nid);
504 ofs_in_node = le16_to_cpu(sum.ofs_in_node);
506 max_addrs = ADDRS_PER_PAGE(dn->node_page, dn->inode);
507 if (ofs_in_node >= max_addrs) {
508 f2fs_err(sbi, "Inconsistent ofs_in_node:%u in summary, ino:%lu, nid:%u, max:%u",
509 ofs_in_node, dn->inode->i_ino, nid, max_addrs);
510 f2fs_handle_error(sbi, ERROR_INCONSISTENT_SUMMARY);
511 return -EFSCORRUPTED;
514 if (dn->inode->i_ino == nid) {
516 if (!dn->inode_page_locked)
517 lock_page(dn->inode_page);
518 tdn.node_page = dn->inode_page;
519 tdn.ofs_in_node = ofs_in_node;
521 } else if (dn->nid == nid) {
522 tdn.ofs_in_node = ofs_in_node;
526 /* Get the node page */
527 node_page = f2fs_get_node_page(sbi, nid);
528 if (IS_ERR(node_page))
529 return PTR_ERR(node_page);
531 offset = ofs_of_node(node_page);
532 ino = ino_of_node(node_page);
533 f2fs_put_page(node_page, 1);
535 if (ino != dn->inode->i_ino) {
538 /* Deallocate previous index in the node page */
539 inode = f2fs_iget_retry(sbi->sb, ino);
541 return PTR_ERR(inode);
543 ret = f2fs_dquot_initialize(inode);
552 bidx = f2fs_start_bidx_of_node(offset, inode) +
553 le16_to_cpu(sum.ofs_in_node);
556 * if inode page is locked, unlock temporarily, but its reference
559 if (ino == dn->inode->i_ino && dn->inode_page_locked)
560 unlock_page(dn->inode_page);
562 set_new_dnode(&tdn, inode, NULL, NULL, 0);
563 if (f2fs_get_dnode_of_data(&tdn, bidx, LOOKUP_NODE))
566 if (tdn.data_blkaddr == blkaddr)
567 f2fs_truncate_data_blocks_range(&tdn, 1);
569 f2fs_put_dnode(&tdn);
571 if (ino != dn->inode->i_ino)
573 else if (dn->inode_page_locked)
574 lock_page(dn->inode_page);
578 if (f2fs_data_blkaddr(&tdn) == blkaddr)
579 f2fs_truncate_data_blocks_range(&tdn, 1);
580 if (dn->inode->i_ino == nid && !dn->inode_page_locked)
581 unlock_page(dn->inode_page);
585 static int f2fs_reserve_new_block_retry(struct dnode_of_data *dn)
589 for (i = DEFAULT_FAILURE_RETRY_COUNT; i > 0; i--) {
590 err = f2fs_reserve_new_block(dn);
598 static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
601 struct dnode_of_data dn;
603 unsigned int start, end;
604 int err = 0, recovered = 0;
606 /* step 1: recover xattr */
607 if (IS_INODE(page)) {
608 err = f2fs_recover_inline_xattr(inode, page);
611 } else if (f2fs_has_xattr_block(ofs_of_node(page))) {
612 err = f2fs_recover_xattr_data(inode, page);
618 /* step 2: recover inline data */
619 err = f2fs_recover_inline_data(inode, page);
626 /* step 3: recover data indices */
627 start = f2fs_start_bidx_of_node(ofs_of_node(page), inode);
628 end = start + ADDRS_PER_PAGE(page, inode);
630 set_new_dnode(&dn, inode, NULL, NULL, 0);
632 err = f2fs_get_dnode_of_data(&dn, start, ALLOC_NODE);
634 if (err == -ENOMEM) {
635 memalloc_retry_wait(GFP_NOFS);
641 f2fs_wait_on_page_writeback(dn.node_page, NODE, true, true);
643 err = f2fs_get_node_info(sbi, dn.nid, &ni, false);
647 f2fs_bug_on(sbi, ni.ino != ino_of_node(page));
649 if (ofs_of_node(dn.node_page) != ofs_of_node(page)) {
650 f2fs_warn(sbi, "Inconsistent ofs_of_node, ino:%lu, ofs:%u, %u",
651 inode->i_ino, ofs_of_node(dn.node_page),
654 f2fs_handle_error(sbi, ERROR_INCONSISTENT_FOOTER);
658 for (; start < end; start++, dn.ofs_in_node++) {
661 src = f2fs_data_blkaddr(&dn);
662 dest = data_blkaddr(dn.inode, page, dn.ofs_in_node);
664 if (__is_valid_data_blkaddr(src) &&
665 !f2fs_is_valid_blkaddr(sbi, src, META_POR)) {
667 f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
671 if (__is_valid_data_blkaddr(dest) &&
672 !f2fs_is_valid_blkaddr(sbi, dest, META_POR)) {
674 f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
678 /* skip recovering if dest is the same as src */
682 /* dest is invalid, just invalidate src block */
683 if (dest == NULL_ADDR) {
684 f2fs_truncate_data_blocks_range(&dn, 1);
688 if (!file_keep_isize(inode) &&
689 (i_size_read(inode) <= ((loff_t)start << PAGE_SHIFT)))
690 f2fs_i_size_write(inode,
691 (loff_t)(start + 1) << PAGE_SHIFT);
694 * dest is reserved block, invalidate src block
695 * and then reserve one new block in dnode page.
697 if (dest == NEW_ADDR) {
698 f2fs_truncate_data_blocks_range(&dn, 1);
700 err = f2fs_reserve_new_block_retry(&dn);
706 /* dest is valid block, try to recover from src to dest */
707 if (f2fs_is_valid_blkaddr(sbi, dest, META_POR)) {
708 if (src == NULL_ADDR) {
709 err = f2fs_reserve_new_block_retry(&dn);
714 /* Check the previous node page having this index */
715 err = check_index_in_prev_nodes(sbi, dest, &dn);
717 if (err == -ENOMEM) {
718 memalloc_retry_wait(GFP_NOFS);
724 if (f2fs_is_valid_blkaddr(sbi, dest,
725 DATA_GENERIC_ENHANCE_UPDATE)) {
726 f2fs_err(sbi, "Inconsistent dest blkaddr:%u, ino:%lu, ofs:%u",
727 dest, inode->i_ino, dn.ofs_in_node);
729 f2fs_handle_error(sbi,
730 ERROR_INVALID_BLKADDR);
734 /* write dummy data page */
735 f2fs_replace_block(sbi, &dn, src, dest,
736 ni.version, false, false);
741 copy_node_footer(dn.node_page, page);
742 fill_node_footer(dn.node_page, dn.nid, ni.ino,
743 ofs_of_node(page), false);
744 set_page_dirty(dn.node_page);
748 f2fs_notice(sbi, "recover_data: ino = %lx (i_size: %s) recovered = %d, err = %d",
749 inode->i_ino, file_keep_isize(inode) ? "keep" : "recover",
754 static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list,
755 struct list_head *tmp_inode_list, struct list_head *dir_list)
757 struct curseg_info *curseg;
758 struct page *page = NULL;
761 unsigned int ra_blocks = RECOVERY_MAX_RA_BLOCKS;
763 /* get node pages in the current segment */
764 curseg = CURSEG_I(sbi, CURSEG_WARM_NODE);
765 blkaddr = NEXT_FREE_BLKADDR(sbi, curseg);
768 struct fsync_inode_entry *entry;
770 if (!f2fs_is_valid_blkaddr(sbi, blkaddr, META_POR))
773 page = f2fs_get_tmp_page(sbi, blkaddr);
779 if (!is_recoverable_dnode(page)) {
780 f2fs_put_page(page, 1);
784 entry = get_fsync_inode(inode_list, ino_of_node(page));
788 * inode(x) | CP | inode(x) | dnode(F)
789 * In this case, we can lose the latest inode(x).
790 * So, call recover_inode for the inode update.
792 if (IS_INODE(page)) {
793 err = recover_inode(entry->inode, page);
795 f2fs_put_page(page, 1);
799 if (entry->last_dentry == blkaddr) {
800 err = recover_dentry(entry->inode, page, dir_list);
802 f2fs_put_page(page, 1);
806 err = do_recover_data(sbi, entry->inode, page);
808 f2fs_put_page(page, 1);
812 if (entry->blkaddr == blkaddr)
813 list_move_tail(&entry->list, tmp_inode_list);
815 ra_blocks = adjust_por_ra_blocks(sbi, ra_blocks, blkaddr,
816 next_blkaddr_of_node(page));
818 /* check next segment */
819 blkaddr = next_blkaddr_of_node(page);
820 f2fs_put_page(page, 1);
822 f2fs_ra_meta_pages_cond(sbi, blkaddr, ra_blocks);
825 f2fs_allocate_new_segments(sbi);
829 int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)
831 struct list_head inode_list, tmp_inode_list;
832 struct list_head dir_list;
835 unsigned long s_flags = sbi->sb->s_flags;
836 bool need_writecp = false;
837 bool fix_curseg_write_pointer = false;
842 if (s_flags & SB_RDONLY) {
843 f2fs_info(sbi, "recover fsync data on readonly fs");
844 sbi->sb->s_flags &= ~SB_RDONLY;
848 /* Turn on quotas so that they are updated correctly */
849 quota_enabled = f2fs_enable_quota_files(sbi, s_flags & SB_RDONLY);
852 INIT_LIST_HEAD(&inode_list);
853 INIT_LIST_HEAD(&tmp_inode_list);
854 INIT_LIST_HEAD(&dir_list);
856 /* prevent checkpoint */
857 f2fs_down_write(&sbi->cp_global_sem);
859 /* step #1: find fsynced inode numbers */
860 err = find_fsync_dnodes(sbi, &inode_list, check_only);
861 if (err || list_empty(&inode_list))
871 /* step #2: recover data */
872 err = recover_data(sbi, &inode_list, &tmp_inode_list, &dir_list);
874 f2fs_bug_on(sbi, !list_empty(&inode_list));
876 f2fs_bug_on(sbi, sbi->sb->s_flags & SB_ACTIVE);
878 fix_curseg_write_pointer = !check_only || list_empty(&inode_list);
880 destroy_fsync_dnodes(&inode_list, err);
881 destroy_fsync_dnodes(&tmp_inode_list, err);
883 /* truncate meta pages to be used by the recovery */
884 truncate_inode_pages_range(META_MAPPING(sbi),
885 (loff_t)MAIN_BLKADDR(sbi) << PAGE_SHIFT, -1);
888 truncate_inode_pages_final(NODE_MAPPING(sbi));
889 truncate_inode_pages_final(META_MAPPING(sbi));
893 * If fsync data succeeds or there is no fsync data to recover,
894 * and the f2fs is not read only, check and fix zoned block devices'
895 * write pointer consistency.
897 if (!err && fix_curseg_write_pointer && !f2fs_readonly(sbi->sb) &&
898 f2fs_sb_has_blkzoned(sbi)) {
899 err = f2fs_fix_curseg_write_pointer(sbi);
901 err = f2fs_check_write_pointer(sbi);
906 clear_sbi_flag(sbi, SBI_POR_DOING);
908 f2fs_up_write(&sbi->cp_global_sem);
910 /* let's drop all the directory inodes for clean checkpoint */
911 destroy_fsync_dnodes(&dir_list, err);
914 set_sbi_flag(sbi, SBI_IS_RECOVERED);
917 struct cp_control cpc = {
918 .reason = CP_RECOVERY,
920 err = f2fs_write_checkpoint(sbi, &cpc);
925 /* Turn quotas off */
927 f2fs_quota_off_umount(sbi->sb);
929 sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */
931 return ret ? ret : err;
934 int __init f2fs_create_recovery_cache(void)
936 fsync_entry_slab = f2fs_kmem_cache_create("f2fs_fsync_inode_entry",
937 sizeof(struct fsync_inode_entry));
938 if (!fsync_entry_slab)
943 void f2fs_destroy_recovery_cache(void)
945 kmem_cache_destroy(fsync_entry_slab);