10a8165d7SJaegeuk Kim /* 2127e670aSJaegeuk Kim * fs/f2fs/checkpoint.c 3127e670aSJaegeuk Kim * 4127e670aSJaegeuk Kim * Copyright (c) 2012 Samsung Electronics Co., Ltd. 5127e670aSJaegeuk Kim * http://www.samsung.com/ 6127e670aSJaegeuk Kim * 7127e670aSJaegeuk Kim * This program is free software; you can redistribute it and/or modify 8127e670aSJaegeuk Kim * it under the terms of the GNU General Public License version 2 as 9127e670aSJaegeuk Kim * published by the Free Software Foundation. 10127e670aSJaegeuk Kim */ 11127e670aSJaegeuk Kim #include <linux/fs.h> 12127e670aSJaegeuk Kim #include <linux/bio.h> 13127e670aSJaegeuk Kim #include <linux/mpage.h> 14127e670aSJaegeuk Kim #include <linux/writeback.h> 15127e670aSJaegeuk Kim #include <linux/blkdev.h> 16127e670aSJaegeuk Kim #include <linux/f2fs_fs.h> 17127e670aSJaegeuk Kim #include <linux/pagevec.h> 18127e670aSJaegeuk Kim #include <linux/swap.h> 19127e670aSJaegeuk Kim 20127e670aSJaegeuk Kim #include "f2fs.h" 21127e670aSJaegeuk Kim #include "node.h" 22127e670aSJaegeuk Kim #include "segment.h" 239e4ded3fSJaegeuk Kim #include "trace.h" 242af4bd6cSNamjae Jeon #include <trace/events/f2fs.h> 25127e670aSJaegeuk Kim 266451e041SJaegeuk Kim static struct kmem_cache *ino_entry_slab; 2706292073SChao Yu struct kmem_cache *inode_entry_slab; 28127e670aSJaegeuk Kim 2938f91ca8SJaegeuk Kim void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io) 3038f91ca8SJaegeuk Kim { 31aaec2b1dSChao Yu set_ckpt_flags(sbi, CP_ERROR_FLAG); 3238f91ca8SJaegeuk Kim if (!end_io) 33b9109b0eSJaegeuk Kim f2fs_flush_merged_writes(sbi); 3438f91ca8SJaegeuk Kim } 3538f91ca8SJaegeuk Kim 360a8165d7SJaegeuk Kim /* 37127e670aSJaegeuk Kim * We guarantee no failure on the returned page. 38127e670aSJaegeuk Kim */ 39127e670aSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index) 40127e670aSJaegeuk Kim { 419df27d98SGu Zheng struct address_space *mapping = META_MAPPING(sbi); 42127e670aSJaegeuk Kim struct page *page = NULL; 43127e670aSJaegeuk Kim repeat: 44300e129cSJaegeuk Kim page = f2fs_grab_cache_page(mapping, index, false); 45127e670aSJaegeuk Kim if (!page) { 46127e670aSJaegeuk Kim cond_resched(); 47127e670aSJaegeuk Kim goto repeat; 48127e670aSJaegeuk Kim } 49fec1d657SJaegeuk Kim f2fs_wait_on_page_writeback(page, META, true); 50237c0790SJaegeuk Kim if (!PageUptodate(page)) 51127e670aSJaegeuk Kim SetPageUptodate(page); 52127e670aSJaegeuk Kim return page; 53127e670aSJaegeuk Kim } 54127e670aSJaegeuk Kim 550a8165d7SJaegeuk Kim /* 56127e670aSJaegeuk Kim * We guarantee no failure on the returned page. 57127e670aSJaegeuk Kim */ 582b947003SChao Yu static struct page *__get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index, 592b947003SChao Yu bool is_meta) 60127e670aSJaegeuk Kim { 619df27d98SGu Zheng struct address_space *mapping = META_MAPPING(sbi); 62127e670aSJaegeuk Kim struct page *page; 63cf04e8ebSJaegeuk Kim struct f2fs_io_info fio = { 6405ca3632SJaegeuk Kim .sbi = sbi, 65cf04e8ebSJaegeuk Kim .type = META, 6604d328deSMike Christie .op = REQ_OP_READ, 6770fd7614SChristoph Hellwig .op_flags = REQ_META | REQ_PRIO, 687a9d7548SChao Yu .old_blkaddr = index, 697a9d7548SChao Yu .new_blkaddr = index, 704375a336SJaegeuk Kim .encrypted_page = NULL, 71cf04e8ebSJaegeuk Kim }; 722b947003SChao Yu 732b947003SChao Yu if (unlikely(!is_meta)) 7404d328deSMike Christie fio.op_flags &= ~REQ_META; 75127e670aSJaegeuk Kim repeat: 76300e129cSJaegeuk Kim page = f2fs_grab_cache_page(mapping, index, false); 77127e670aSJaegeuk Kim if (!page) { 78127e670aSJaegeuk Kim cond_resched(); 79127e670aSJaegeuk Kim goto repeat; 80127e670aSJaegeuk Kim } 81393ff91fSJaegeuk Kim if (PageUptodate(page)) 82393ff91fSJaegeuk Kim goto out; 83127e670aSJaegeuk Kim 8405ca3632SJaegeuk Kim fio.page = page; 8505ca3632SJaegeuk Kim 8686531d6bSJaegeuk Kim if (f2fs_submit_page_bio(&fio)) { 8786531d6bSJaegeuk Kim f2fs_put_page(page, 1); 88393ff91fSJaegeuk Kim goto repeat; 8986531d6bSJaegeuk Kim } 90393ff91fSJaegeuk Kim 91393ff91fSJaegeuk Kim lock_page(page); 926bacf52fSJaegeuk Kim if (unlikely(page->mapping != mapping)) { 93afcb7ca0SJaegeuk Kim f2fs_put_page(page, 1); 94afcb7ca0SJaegeuk Kim goto repeat; 95afcb7ca0SJaegeuk Kim } 96f3f338caSChao Yu 97f3f338caSChao Yu /* 98f3f338caSChao Yu * if there is any IO error when accessing device, make our filesystem 99f3f338caSChao Yu * readonly and make sure do not write checkpoint with non-uptodate 100f3f338caSChao Yu * meta page. 101f3f338caSChao Yu */ 102f3f338caSChao Yu if (unlikely(!PageUptodate(page))) 10338f91ca8SJaegeuk Kim f2fs_stop_checkpoint(sbi, false); 104393ff91fSJaegeuk Kim out: 105127e670aSJaegeuk Kim return page; 106127e670aSJaegeuk Kim } 107127e670aSJaegeuk Kim 1082b947003SChao Yu struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index) 1092b947003SChao Yu { 1102b947003SChao Yu return __get_meta_page(sbi, index, true); 1112b947003SChao Yu } 1122b947003SChao Yu 1132b947003SChao Yu /* for POR only */ 1142b947003SChao Yu struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index) 1152b947003SChao Yu { 1162b947003SChao Yu return __get_meta_page(sbi, index, false); 1172b947003SChao Yu } 1182b947003SChao Yu 119f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type) 120662befdaSChao Yu { 121662befdaSChao Yu switch (type) { 122662befdaSChao Yu case META_NAT: 12366b00c18SChao Yu break; 124662befdaSChao Yu case META_SIT: 12566b00c18SChao Yu if (unlikely(blkaddr >= SIT_BLK_CNT(sbi))) 12666b00c18SChao Yu return false; 12766b00c18SChao Yu break; 12881c1a0f1SChao Yu case META_SSA: 12966b00c18SChao Yu if (unlikely(blkaddr >= MAIN_BLKADDR(sbi) || 13066b00c18SChao Yu blkaddr < SM_I(sbi)->ssa_blkaddr)) 13166b00c18SChao Yu return false; 13266b00c18SChao Yu break; 133662befdaSChao Yu case META_CP: 13466b00c18SChao Yu if (unlikely(blkaddr >= SIT_I(sbi)->sit_base_addr || 13566b00c18SChao Yu blkaddr < __start_cp_addr(sbi))) 13666b00c18SChao Yu return false; 13766b00c18SChao Yu break; 1384c521f49SJaegeuk Kim case META_POR: 13966b00c18SChao Yu if (unlikely(blkaddr >= MAX_BLKADDR(sbi) || 14066b00c18SChao Yu blkaddr < MAIN_BLKADDR(sbi))) 14166b00c18SChao Yu return false; 14266b00c18SChao Yu break; 143662befdaSChao Yu default: 144662befdaSChao Yu BUG(); 145662befdaSChao Yu } 14666b00c18SChao Yu 14766b00c18SChao Yu return true; 148662befdaSChao Yu } 149662befdaSChao Yu 150662befdaSChao Yu /* 15181c1a0f1SChao Yu * Readahead CP/NAT/SIT/SSA pages 152662befdaSChao Yu */ 15326879fb1SChao Yu int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 15426879fb1SChao Yu int type, bool sync) 155662befdaSChao Yu { 156662befdaSChao Yu struct page *page; 1574c521f49SJaegeuk Kim block_t blkno = start; 158662befdaSChao Yu struct f2fs_io_info fio = { 15905ca3632SJaegeuk Kim .sbi = sbi, 160662befdaSChao Yu .type = META, 16104d328deSMike Christie .op = REQ_OP_READ, 16270fd7614SChristoph Hellwig .op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD, 1634375a336SJaegeuk Kim .encrypted_page = NULL, 164fb830fc5SChao Yu .in_list = false, 165662befdaSChao Yu }; 166e9f5b8b8SChao Yu struct blk_plug plug; 167662befdaSChao Yu 1682b947003SChao Yu if (unlikely(type == META_POR)) 16904d328deSMike Christie fio.op_flags &= ~REQ_META; 1702b947003SChao Yu 171e9f5b8b8SChao Yu blk_start_plug(&plug); 172662befdaSChao Yu for (; nrpages-- > 0; blkno++) { 173662befdaSChao Yu 17466b00c18SChao Yu if (!is_valid_blkaddr(sbi, blkno, type)) 17566b00c18SChao Yu goto out; 17666b00c18SChao Yu 177662befdaSChao Yu switch (type) { 178662befdaSChao Yu case META_NAT: 17966b00c18SChao Yu if (unlikely(blkno >= 18066b00c18SChao Yu NAT_BLOCK_OFFSET(NM_I(sbi)->max_nid))) 181662befdaSChao Yu blkno = 0; 18266b00c18SChao Yu /* get nat block addr */ 1837a9d7548SChao Yu fio.new_blkaddr = current_nat_addr(sbi, 184662befdaSChao Yu blkno * NAT_ENTRY_PER_BLOCK); 185662befdaSChao Yu break; 186662befdaSChao Yu case META_SIT: 187662befdaSChao Yu /* get sit block addr */ 1887a9d7548SChao Yu fio.new_blkaddr = current_sit_addr(sbi, 189662befdaSChao Yu blkno * SIT_ENTRY_PER_BLOCK); 190662befdaSChao Yu break; 19181c1a0f1SChao Yu case META_SSA: 192662befdaSChao Yu case META_CP: 1934c521f49SJaegeuk Kim case META_POR: 1947a9d7548SChao Yu fio.new_blkaddr = blkno; 195662befdaSChao Yu break; 196662befdaSChao Yu default: 197662befdaSChao Yu BUG(); 198662befdaSChao Yu } 199662befdaSChao Yu 200300e129cSJaegeuk Kim page = f2fs_grab_cache_page(META_MAPPING(sbi), 201300e129cSJaegeuk Kim fio.new_blkaddr, false); 202662befdaSChao Yu if (!page) 203662befdaSChao Yu continue; 204662befdaSChao Yu if (PageUptodate(page)) { 205662befdaSChao Yu f2fs_put_page(page, 1); 206662befdaSChao Yu continue; 207662befdaSChao Yu } 208662befdaSChao Yu 20905ca3632SJaegeuk Kim fio.page = page; 2101919ffc0SJaegeuk Kim f2fs_submit_page_bio(&fio); 211662befdaSChao Yu f2fs_put_page(page, 0); 212662befdaSChao Yu } 213662befdaSChao Yu out: 214e9f5b8b8SChao Yu blk_finish_plug(&plug); 215662befdaSChao Yu return blkno - start; 216662befdaSChao Yu } 217662befdaSChao Yu 218635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index) 219635aee1fSChao Yu { 220635aee1fSChao Yu struct page *page; 221635aee1fSChao Yu bool readahead = false; 222635aee1fSChao Yu 223635aee1fSChao Yu page = find_get_page(META_MAPPING(sbi), index); 2244da7bf5aSJaegeuk Kim if (!page || !PageUptodate(page)) 225635aee1fSChao Yu readahead = true; 226635aee1fSChao Yu f2fs_put_page(page, 0); 227635aee1fSChao Yu 228635aee1fSChao Yu if (readahead) 229664ba972SJaegeuk Kim ra_meta_pages(sbi, index, BIO_MAX_PAGES, META_POR, true); 230635aee1fSChao Yu } 231635aee1fSChao Yu 232b0af6d49SChao Yu static int __f2fs_write_meta_page(struct page *page, 233b0af6d49SChao Yu struct writeback_control *wbc, 234b0af6d49SChao Yu enum iostat_type io_type) 235127e670aSJaegeuk Kim { 2364081363fSJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_P_SB(page); 237577e3495SJaegeuk Kim 238ecda0de3SChao Yu trace_f2fs_writepage(page, META); 239ecda0de3SChao Yu 240caf0047eSChao Yu if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) 241cfb271d4SChao Yu goto redirty_out; 242857dc4e0SJaegeuk Kim if (wbc->for_reclaim && page->index < GET_SUM_BLOCK(sbi, 0)) 243cfb271d4SChao Yu goto redirty_out; 2441e968fdfSJaegeuk Kim if (unlikely(f2fs_cp_error(sbi))) 245cf779cabSJaegeuk Kim goto redirty_out; 246127e670aSJaegeuk Kim 247b0af6d49SChao Yu write_meta_page(sbi, page, io_type); 248127e670aSJaegeuk Kim dec_page_count(sbi, F2FS_DIRTY_META); 2490c3a5797SChao Yu 2500c3a5797SChao Yu if (wbc->for_reclaim) 251b9109b0eSJaegeuk Kim f2fs_submit_merged_write_cond(sbi, page->mapping->host, 252b9109b0eSJaegeuk Kim 0, page->index, META); 2530c3a5797SChao Yu 254127e670aSJaegeuk Kim unlock_page(page); 255857dc4e0SJaegeuk Kim 2560c3a5797SChao Yu if (unlikely(f2fs_cp_error(sbi))) 257b9109b0eSJaegeuk Kim f2fs_submit_merged_write(sbi, META); 2580c3a5797SChao Yu 259577e3495SJaegeuk Kim return 0; 260cfb271d4SChao Yu 261cfb271d4SChao Yu redirty_out: 26276f60268SJaegeuk Kim redirty_page_for_writepage(wbc, page); 263cfb271d4SChao Yu return AOP_WRITEPAGE_ACTIVATE; 264127e670aSJaegeuk Kim } 265127e670aSJaegeuk Kim 266b0af6d49SChao Yu static int f2fs_write_meta_page(struct page *page, 267b0af6d49SChao Yu struct writeback_control *wbc) 268b0af6d49SChao Yu { 269b0af6d49SChao Yu return __f2fs_write_meta_page(page, wbc, FS_META_IO); 270b0af6d49SChao Yu } 271b0af6d49SChao Yu 272127e670aSJaegeuk Kim static int f2fs_write_meta_pages(struct address_space *mapping, 273127e670aSJaegeuk Kim struct writeback_control *wbc) 274127e670aSJaegeuk Kim { 2754081363fSJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); 27650c8cdb3SJaegeuk Kim long diff, written; 277127e670aSJaegeuk Kim 2780771fcc7SChao Yu if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) 2790771fcc7SChao Yu goto skip_write; 2800771fcc7SChao Yu 2815459aa97SJaegeuk Kim /* collect a number of dirty meta pages and write together */ 28250c8cdb3SJaegeuk Kim if (wbc->for_kupdate || 28350c8cdb3SJaegeuk Kim get_pages(sbi, F2FS_DIRTY_META) < nr_pages_to_skip(sbi, META)) 284d3baf95dSJaegeuk Kim goto skip_write; 285127e670aSJaegeuk Kim 286a29d0e0bSYunlei He /* if locked failed, cp will flush dirty pages instead */ 287a29d0e0bSYunlei He if (!mutex_trylock(&sbi->cp_mutex)) 288a29d0e0bSYunlei He goto skip_write; 289d31c7c3fSYunlei He 290a29d0e0bSYunlei He trace_f2fs_writepages(mapping->host, wbc, META); 29150c8cdb3SJaegeuk Kim diff = nr_pages_to_write(sbi, META, wbc); 292b0af6d49SChao Yu written = sync_meta_pages(sbi, META, wbc->nr_to_write, FS_META_IO); 293127e670aSJaegeuk Kim mutex_unlock(&sbi->cp_mutex); 29450c8cdb3SJaegeuk Kim wbc->nr_to_write = max((long)0, wbc->nr_to_write - written - diff); 295127e670aSJaegeuk Kim return 0; 296d3baf95dSJaegeuk Kim 297d3baf95dSJaegeuk Kim skip_write: 298d3baf95dSJaegeuk Kim wbc->pages_skipped += get_pages(sbi, F2FS_DIRTY_META); 299d31c7c3fSYunlei He trace_f2fs_writepages(mapping->host, wbc, META); 300d3baf95dSJaegeuk Kim return 0; 301127e670aSJaegeuk Kim } 302127e670aSJaegeuk Kim 303127e670aSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 304b0af6d49SChao Yu long nr_to_write, enum iostat_type io_type) 305127e670aSJaegeuk Kim { 3069df27d98SGu Zheng struct address_space *mapping = META_MAPPING(sbi); 30780dd9c0eSChao Yu pgoff_t index = 0, end = ULONG_MAX, prev = ULONG_MAX; 308127e670aSJaegeuk Kim struct pagevec pvec; 309127e670aSJaegeuk Kim long nwritten = 0; 310127e670aSJaegeuk Kim struct writeback_control wbc = { 311127e670aSJaegeuk Kim .for_reclaim = 0, 312127e670aSJaegeuk Kim }; 313e9f5b8b8SChao Yu struct blk_plug plug; 314127e670aSJaegeuk Kim 315127e670aSJaegeuk Kim pagevec_init(&pvec, 0); 316127e670aSJaegeuk Kim 317e9f5b8b8SChao Yu blk_start_plug(&plug); 318e9f5b8b8SChao Yu 319127e670aSJaegeuk Kim while (index <= end) { 320127e670aSJaegeuk Kim int i, nr_pages; 321127e670aSJaegeuk Kim nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, 322127e670aSJaegeuk Kim PAGECACHE_TAG_DIRTY, 323127e670aSJaegeuk Kim min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1); 324cfb271d4SChao Yu if (unlikely(nr_pages == 0)) 325127e670aSJaegeuk Kim break; 326127e670aSJaegeuk Kim 327127e670aSJaegeuk Kim for (i = 0; i < nr_pages; i++) { 328127e670aSJaegeuk Kim struct page *page = pvec.pages[i]; 329203681f6SJaegeuk Kim 33080dd9c0eSChao Yu if (prev == ULONG_MAX) 3316066d8cdSJaegeuk Kim prev = page->index - 1; 3326066d8cdSJaegeuk Kim if (nr_to_write != LONG_MAX && page->index != prev + 1) { 3336066d8cdSJaegeuk Kim pagevec_release(&pvec); 3346066d8cdSJaegeuk Kim goto stop; 3356066d8cdSJaegeuk Kim } 3366066d8cdSJaegeuk Kim 337127e670aSJaegeuk Kim lock_page(page); 338203681f6SJaegeuk Kim 339203681f6SJaegeuk Kim if (unlikely(page->mapping != mapping)) { 340203681f6SJaegeuk Kim continue_unlock: 341203681f6SJaegeuk Kim unlock_page(page); 342203681f6SJaegeuk Kim continue; 343203681f6SJaegeuk Kim } 344203681f6SJaegeuk Kim if (!PageDirty(page)) { 345203681f6SJaegeuk Kim /* someone wrote it for us */ 346203681f6SJaegeuk Kim goto continue_unlock; 347203681f6SJaegeuk Kim } 348203681f6SJaegeuk Kim 349fa3d2bdfSJaegeuk Kim f2fs_wait_on_page_writeback(page, META, true); 350fa3d2bdfSJaegeuk Kim 351fa3d2bdfSJaegeuk Kim BUG_ON(PageWriteback(page)); 352203681f6SJaegeuk Kim if (!clear_page_dirty_for_io(page)) 353203681f6SJaegeuk Kim goto continue_unlock; 354203681f6SJaegeuk Kim 355b0af6d49SChao Yu if (__f2fs_write_meta_page(page, &wbc, io_type)) { 356577e3495SJaegeuk Kim unlock_page(page); 357577e3495SJaegeuk Kim break; 358577e3495SJaegeuk Kim } 359cfb271d4SChao Yu nwritten++; 3606066d8cdSJaegeuk Kim prev = page->index; 361cfb271d4SChao Yu if (unlikely(nwritten >= nr_to_write)) 362127e670aSJaegeuk Kim break; 363127e670aSJaegeuk Kim } 364127e670aSJaegeuk Kim pagevec_release(&pvec); 365127e670aSJaegeuk Kim cond_resched(); 366127e670aSJaegeuk Kim } 3676066d8cdSJaegeuk Kim stop: 368127e670aSJaegeuk Kim if (nwritten) 369b9109b0eSJaegeuk Kim f2fs_submit_merged_write(sbi, type); 370127e670aSJaegeuk Kim 371e9f5b8b8SChao Yu blk_finish_plug(&plug); 372e9f5b8b8SChao Yu 373127e670aSJaegeuk Kim return nwritten; 374127e670aSJaegeuk Kim } 375127e670aSJaegeuk Kim 376127e670aSJaegeuk Kim static int f2fs_set_meta_page_dirty(struct page *page) 377127e670aSJaegeuk Kim { 37826c6b887SJaegeuk Kim trace_f2fs_set_page_dirty(page, META); 37926c6b887SJaegeuk Kim 380237c0790SJaegeuk Kim if (!PageUptodate(page)) 381127e670aSJaegeuk Kim SetPageUptodate(page); 382127e670aSJaegeuk Kim if (!PageDirty(page)) { 383fe76b796SJaegeuk Kim f2fs_set_page_dirty_nobuffers(page); 3844081363fSJaegeuk Kim inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_META); 3851601839eSChao Yu SetPagePrivate(page); 3869e4ded3fSJaegeuk Kim f2fs_trace_pid(page); 387127e670aSJaegeuk Kim return 1; 388127e670aSJaegeuk Kim } 389127e670aSJaegeuk Kim return 0; 390127e670aSJaegeuk Kim } 391127e670aSJaegeuk Kim 392127e670aSJaegeuk Kim const struct address_space_operations f2fs_meta_aops = { 393127e670aSJaegeuk Kim .writepage = f2fs_write_meta_page, 394127e670aSJaegeuk Kim .writepages = f2fs_write_meta_pages, 395127e670aSJaegeuk Kim .set_page_dirty = f2fs_set_meta_page_dirty, 396487261f3SChao Yu .invalidatepage = f2fs_invalidate_page, 397487261f3SChao Yu .releasepage = f2fs_release_page, 3985b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 3995b7a487cSWeichao Guo .migratepage = f2fs_migrate_page, 4005b7a487cSWeichao Guo #endif 401127e670aSJaegeuk Kim }; 402127e670aSJaegeuk Kim 40339d787beSChao Yu static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, 40439d787beSChao Yu unsigned int devidx, int type) 405953e6cc6SJaegeuk Kim { 40667298804SChao Yu struct inode_management *im = &sbi->im[type]; 40780c54505SJaegeuk Kim struct ino_entry *e, *tmp; 40880c54505SJaegeuk Kim 40980c54505SJaegeuk Kim tmp = f2fs_kmem_cache_alloc(ino_entry_slab, GFP_NOFS); 410*19526d74SChao Yu 41180c54505SJaegeuk Kim radix_tree_preload(GFP_NOFS | __GFP_NOFAIL); 412769ec6e5SJaegeuk Kim 41367298804SChao Yu spin_lock(&im->ino_lock); 41467298804SChao Yu e = radix_tree_lookup(&im->ino_root, ino); 41539efac41SJaegeuk Kim if (!e) { 41680c54505SJaegeuk Kim e = tmp; 417*19526d74SChao Yu if (unlikely(radix_tree_insert(&im->ino_root, ino, e))) 418*19526d74SChao Yu f2fs_bug_on(sbi, 1); 419*19526d74SChao Yu 42039efac41SJaegeuk Kim memset(e, 0, sizeof(struct ino_entry)); 42139efac41SJaegeuk Kim e->ino = ino; 42239efac41SJaegeuk Kim 42367298804SChao Yu list_add_tail(&e->list, &im->ino_list); 4248c402946SJaegeuk Kim if (type != ORPHAN_INO) 42567298804SChao Yu im->ino_num++; 42639efac41SJaegeuk Kim } 42739d787beSChao Yu 42839d787beSChao Yu if (type == FLUSH_INO) 42939d787beSChao Yu f2fs_set_bit(devidx, (char *)&e->dirty_device); 43039d787beSChao Yu 43167298804SChao Yu spin_unlock(&im->ino_lock); 432769ec6e5SJaegeuk Kim radix_tree_preload_end(); 43380c54505SJaegeuk Kim 43480c54505SJaegeuk Kim if (e != tmp) 43580c54505SJaegeuk Kim kmem_cache_free(ino_entry_slab, tmp); 436953e6cc6SJaegeuk Kim } 437953e6cc6SJaegeuk Kim 4386451e041SJaegeuk Kim static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) 439953e6cc6SJaegeuk Kim { 44067298804SChao Yu struct inode_management *im = &sbi->im[type]; 4416451e041SJaegeuk Kim struct ino_entry *e; 442953e6cc6SJaegeuk Kim 44367298804SChao Yu spin_lock(&im->ino_lock); 44467298804SChao Yu e = radix_tree_lookup(&im->ino_root, ino); 44539efac41SJaegeuk Kim if (e) { 446953e6cc6SJaegeuk Kim list_del(&e->list); 44767298804SChao Yu radix_tree_delete(&im->ino_root, ino); 44867298804SChao Yu im->ino_num--; 44967298804SChao Yu spin_unlock(&im->ino_lock); 4506451e041SJaegeuk Kim kmem_cache_free(ino_entry_slab, e); 451953e6cc6SJaegeuk Kim return; 452953e6cc6SJaegeuk Kim } 45367298804SChao Yu spin_unlock(&im->ino_lock); 454953e6cc6SJaegeuk Kim } 455953e6cc6SJaegeuk Kim 456a49324f1SChao Yu void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) 457fff04f90SJaegeuk Kim { 458fff04f90SJaegeuk Kim /* add new dirty ino entry into list */ 45939d787beSChao Yu __add_ino_entry(sbi, ino, 0, type); 460fff04f90SJaegeuk Kim } 461fff04f90SJaegeuk Kim 462a49324f1SChao Yu void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) 463fff04f90SJaegeuk Kim { 464fff04f90SJaegeuk Kim /* remove dirty ino entry from list */ 465fff04f90SJaegeuk Kim __remove_ino_entry(sbi, ino, type); 466fff04f90SJaegeuk Kim } 467fff04f90SJaegeuk Kim 468fff04f90SJaegeuk Kim /* mode should be APPEND_INO or UPDATE_INO */ 469fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode) 470fff04f90SJaegeuk Kim { 47167298804SChao Yu struct inode_management *im = &sbi->im[mode]; 472fff04f90SJaegeuk Kim struct ino_entry *e; 47367298804SChao Yu 47467298804SChao Yu spin_lock(&im->ino_lock); 47567298804SChao Yu e = radix_tree_lookup(&im->ino_root, ino); 47667298804SChao Yu spin_unlock(&im->ino_lock); 477fff04f90SJaegeuk Kim return e ? true : false; 478fff04f90SJaegeuk Kim } 479fff04f90SJaegeuk Kim 48074ef9241SJaegeuk Kim void release_ino_entry(struct f2fs_sb_info *sbi, bool all) 481fff04f90SJaegeuk Kim { 482fff04f90SJaegeuk Kim struct ino_entry *e, *tmp; 483fff04f90SJaegeuk Kim int i; 484fff04f90SJaegeuk Kim 48539d787beSChao Yu for (i = all ? ORPHAN_INO : APPEND_INO; i < MAX_INO_ENTRY; i++) { 48667298804SChao Yu struct inode_management *im = &sbi->im[i]; 48767298804SChao Yu 48867298804SChao Yu spin_lock(&im->ino_lock); 48967298804SChao Yu list_for_each_entry_safe(e, tmp, &im->ino_list, list) { 490fff04f90SJaegeuk Kim list_del(&e->list); 49167298804SChao Yu radix_tree_delete(&im->ino_root, e->ino); 492fff04f90SJaegeuk Kim kmem_cache_free(ino_entry_slab, e); 49367298804SChao Yu im->ino_num--; 494fff04f90SJaegeuk Kim } 49567298804SChao Yu spin_unlock(&im->ino_lock); 496fff04f90SJaegeuk Kim } 497fff04f90SJaegeuk Kim } 498fff04f90SJaegeuk Kim 49939d787beSChao Yu void set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 50039d787beSChao Yu unsigned int devidx, int type) 50139d787beSChao Yu { 50239d787beSChao Yu __add_ino_entry(sbi, ino, devidx, type); 50339d787beSChao Yu } 50439d787beSChao Yu 50539d787beSChao Yu bool is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 50639d787beSChao Yu unsigned int devidx, int type) 50739d787beSChao Yu { 50839d787beSChao Yu struct inode_management *im = &sbi->im[type]; 50939d787beSChao Yu struct ino_entry *e; 51039d787beSChao Yu bool is_dirty = false; 51139d787beSChao Yu 51239d787beSChao Yu spin_lock(&im->ino_lock); 51339d787beSChao Yu e = radix_tree_lookup(&im->ino_root, ino); 51439d787beSChao Yu if (e && f2fs_test_bit(devidx, (char *)&e->dirty_device)) 51539d787beSChao Yu is_dirty = true; 51639d787beSChao Yu spin_unlock(&im->ino_lock); 51739d787beSChao Yu return is_dirty; 51839d787beSChao Yu } 51939d787beSChao Yu 520cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *sbi) 521127e670aSJaegeuk Kim { 52267298804SChao Yu struct inode_management *im = &sbi->im[ORPHAN_INO]; 523127e670aSJaegeuk Kim int err = 0; 524127e670aSJaegeuk Kim 52567298804SChao Yu spin_lock(&im->ino_lock); 526cb78942bSJaegeuk Kim 527cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 5281ecc0c5cSChao Yu if (time_to_inject(sbi, FAULT_ORPHAN)) { 529cb78942bSJaegeuk Kim spin_unlock(&im->ino_lock); 53055523519SChao Yu f2fs_show_injection_info(FAULT_ORPHAN); 531cb78942bSJaegeuk Kim return -ENOSPC; 532cb78942bSJaegeuk Kim } 533cb78942bSJaegeuk Kim #endif 53467298804SChao Yu if (unlikely(im->ino_num >= sbi->max_orphans)) 535127e670aSJaegeuk Kim err = -ENOSPC; 536cbd56e7dSJaegeuk Kim else 53767298804SChao Yu im->ino_num++; 53867298804SChao Yu spin_unlock(&im->ino_lock); 5390d47c1adSGu Zheng 540127e670aSJaegeuk Kim return err; 541127e670aSJaegeuk Kim } 542127e670aSJaegeuk Kim 543cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *sbi) 544cbd56e7dSJaegeuk Kim { 54567298804SChao Yu struct inode_management *im = &sbi->im[ORPHAN_INO]; 54667298804SChao Yu 54767298804SChao Yu spin_lock(&im->ino_lock); 54867298804SChao Yu f2fs_bug_on(sbi, im->ino_num == 0); 54967298804SChao Yu im->ino_num--; 55067298804SChao Yu spin_unlock(&im->ino_lock); 551cbd56e7dSJaegeuk Kim } 552cbd56e7dSJaegeuk Kim 55367c3758dSJaegeuk Kim void add_orphan_inode(struct inode *inode) 554127e670aSJaegeuk Kim { 55539efac41SJaegeuk Kim /* add new orphan ino entry into list */ 55639d787beSChao Yu __add_ino_entry(F2FS_I_SB(inode), inode->i_ino, 0, ORPHAN_INO); 55767c3758dSJaegeuk Kim update_inode_page(inode); 558127e670aSJaegeuk Kim } 559127e670aSJaegeuk Kim 560127e670aSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) 561127e670aSJaegeuk Kim { 562953e6cc6SJaegeuk Kim /* remove orphan entry from orphan list */ 5636451e041SJaegeuk Kim __remove_ino_entry(sbi, ino, ORPHAN_INO); 564127e670aSJaegeuk Kim } 565127e670aSJaegeuk Kim 5668c14bfadSChao Yu static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) 567127e670aSJaegeuk Kim { 5688c14bfadSChao Yu struct inode *inode; 5695905f9afSJaegeuk Kim struct node_info ni; 570d41065e2SJaegeuk Kim int err = acquire_orphan_inode(sbi); 571d41065e2SJaegeuk Kim 572d41065e2SJaegeuk Kim if (err) { 573d41065e2SJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 574d41065e2SJaegeuk Kim f2fs_msg(sbi->sb, KERN_WARNING, 575d41065e2SJaegeuk Kim "%s: orphan failed (ino=%x), run fsck to fix.", 576d41065e2SJaegeuk Kim __func__, ino); 577d41065e2SJaegeuk Kim return err; 578d41065e2SJaegeuk Kim } 579d41065e2SJaegeuk Kim 58039d787beSChao Yu __add_ino_entry(sbi, ino, 0, ORPHAN_INO); 5818c14bfadSChao Yu 5825905f9afSJaegeuk Kim inode = f2fs_iget_retry(sbi->sb, ino); 5838c14bfadSChao Yu if (IS_ERR(inode)) { 5848c14bfadSChao Yu /* 5858c14bfadSChao Yu * there should be a bug that we can't find the entry 5868c14bfadSChao Yu * to orphan inode. 5878c14bfadSChao Yu */ 5888c14bfadSChao Yu f2fs_bug_on(sbi, PTR_ERR(inode) == -ENOENT); 5898c14bfadSChao Yu return PTR_ERR(inode); 5908c14bfadSChao Yu } 5918c14bfadSChao Yu 592127e670aSJaegeuk Kim clear_nlink(inode); 593127e670aSJaegeuk Kim 594127e670aSJaegeuk Kim /* truncate all the data during iput */ 595127e670aSJaegeuk Kim iput(inode); 5965905f9afSJaegeuk Kim 5975905f9afSJaegeuk Kim get_node_info(sbi, ino, &ni); 5985905f9afSJaegeuk Kim 5995905f9afSJaegeuk Kim /* ENOMEM was fully retried in f2fs_evict_inode. */ 6005905f9afSJaegeuk Kim if (ni.blk_addr != NULL_ADDR) { 6015905f9afSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 6025905f9afSJaegeuk Kim f2fs_msg(sbi->sb, KERN_WARNING, 6035ce4738aSJaegeuk Kim "%s: orphan failed (ino=%x) by kernel, retry mount.", 6045905f9afSJaegeuk Kim __func__, ino); 605d41065e2SJaegeuk Kim return -EIO; 6065905f9afSJaegeuk Kim } 607d41065e2SJaegeuk Kim __remove_ino_entry(sbi, ino, ORPHAN_INO); 6088c14bfadSChao Yu return 0; 609127e670aSJaegeuk Kim } 610127e670aSJaegeuk Kim 6118c14bfadSChao Yu int recover_orphan_inodes(struct f2fs_sb_info *sbi) 612127e670aSJaegeuk Kim { 6133c642985SWanpeng Li block_t start_blk, orphan_blocks, i, j; 6144b2414d0SChao Yu unsigned int s_flags = sbi->sb->s_flags; 6154b2414d0SChao Yu int err = 0; 616ea676733SJaegeuk Kim #ifdef CONFIG_QUOTA 617ea676733SJaegeuk Kim int quota_enabled; 618ea676733SJaegeuk Kim #endif 619127e670aSJaegeuk Kim 620aaec2b1dSChao Yu if (!is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG)) 6218c14bfadSChao Yu return 0; 622127e670aSJaegeuk Kim 6234b2414d0SChao Yu if (s_flags & MS_RDONLY) { 6244b2414d0SChao Yu f2fs_msg(sbi->sb, KERN_INFO, "orphan cleanup on readonly fs"); 6254b2414d0SChao Yu sbi->sb->s_flags &= ~MS_RDONLY; 6264b2414d0SChao Yu } 6274b2414d0SChao Yu 6284b2414d0SChao Yu #ifdef CONFIG_QUOTA 6294b2414d0SChao Yu /* Needed for iput() to work correctly and not trash data */ 6304b2414d0SChao Yu sbi->sb->s_flags |= MS_ACTIVE; 631ea676733SJaegeuk Kim 6324b2414d0SChao Yu /* Turn on quotas so that they are updated correctly */ 633ea676733SJaegeuk Kim quota_enabled = f2fs_enable_quota_files(sbi, s_flags & MS_RDONLY); 6344b2414d0SChao Yu #endif 6354b2414d0SChao Yu 63655141486SWanpeng Li start_blk = __start_cp_addr(sbi) + 1 + __cp_payload(sbi); 6373c642985SWanpeng Li orphan_blocks = __start_sum_addr(sbi) - 1 - __cp_payload(sbi); 638127e670aSJaegeuk Kim 63926879fb1SChao Yu ra_meta_pages(sbi, start_blk, orphan_blocks, META_CP, true); 640662befdaSChao Yu 6413c642985SWanpeng Li for (i = 0; i < orphan_blocks; i++) { 642127e670aSJaegeuk Kim struct page *page = get_meta_page(sbi, start_blk + i); 643127e670aSJaegeuk Kim struct f2fs_orphan_block *orphan_blk; 644127e670aSJaegeuk Kim 645127e670aSJaegeuk Kim orphan_blk = (struct f2fs_orphan_block *)page_address(page); 646127e670aSJaegeuk Kim for (j = 0; j < le32_to_cpu(orphan_blk->entry_count); j++) { 647127e670aSJaegeuk Kim nid_t ino = le32_to_cpu(orphan_blk->ino[j]); 6488c14bfadSChao Yu err = recover_orphan_inode(sbi, ino); 6498c14bfadSChao Yu if (err) { 6508c14bfadSChao Yu f2fs_put_page(page, 1); 6514b2414d0SChao Yu goto out; 6528c14bfadSChao Yu } 653127e670aSJaegeuk Kim } 654127e670aSJaegeuk Kim f2fs_put_page(page, 1); 655127e670aSJaegeuk Kim } 656127e670aSJaegeuk Kim /* clear Orphan Flag */ 657aaec2b1dSChao Yu clear_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG); 6584b2414d0SChao Yu out: 6594b2414d0SChao Yu #ifdef CONFIG_QUOTA 6604b2414d0SChao Yu /* Turn quotas off */ 661ea676733SJaegeuk Kim if (quota_enabled) 6624b2414d0SChao Yu f2fs_quota_off_umount(sbi->sb); 6634b2414d0SChao Yu #endif 6644b2414d0SChao Yu sbi->sb->s_flags = s_flags; /* Restore MS_RDONLY status */ 6654b2414d0SChao Yu 6664b2414d0SChao Yu return err; 667127e670aSJaegeuk Kim } 668127e670aSJaegeuk Kim 669127e670aSJaegeuk Kim static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk) 670127e670aSJaegeuk Kim { 671502c6e0bSGu Zheng struct list_head *head; 672127e670aSJaegeuk Kim struct f2fs_orphan_block *orphan_blk = NULL; 673127e670aSJaegeuk Kim unsigned int nentries = 0; 674bd936f84SChao Yu unsigned short index = 1; 6758c402946SJaegeuk Kim unsigned short orphan_blocks; 6764531929eSGu Zheng struct page *page = NULL; 6776451e041SJaegeuk Kim struct ino_entry *orphan = NULL; 67867298804SChao Yu struct inode_management *im = &sbi->im[ORPHAN_INO]; 679127e670aSJaegeuk Kim 68067298804SChao Yu orphan_blocks = GET_ORPHAN_BLOCKS(im->ino_num); 6818c402946SJaegeuk Kim 682d6c67a4fSJaegeuk Kim /* 683d6c67a4fSJaegeuk Kim * we don't need to do spin_lock(&im->ino_lock) here, since all the 684d6c67a4fSJaegeuk Kim * orphan inode operations are covered under f2fs_lock_op(). 685d6c67a4fSJaegeuk Kim * And, spin_lock should be avoided due to page operations below. 686d6c67a4fSJaegeuk Kim */ 68767298804SChao Yu head = &im->ino_list; 688127e670aSJaegeuk Kim 689127e670aSJaegeuk Kim /* loop for each orphan inode entry and write them in Jornal block */ 690502c6e0bSGu Zheng list_for_each_entry(orphan, head, list) { 691502c6e0bSGu Zheng if (!page) { 692bd936f84SChao Yu page = grab_meta_page(sbi, start_blk++); 693502c6e0bSGu Zheng orphan_blk = 694502c6e0bSGu Zheng (struct f2fs_orphan_block *)page_address(page); 695502c6e0bSGu Zheng memset(orphan_blk, 0, sizeof(*orphan_blk)); 696502c6e0bSGu Zheng } 697127e670aSJaegeuk Kim 69836795567SGu Zheng orphan_blk->ino[nentries++] = cpu_to_le32(orphan->ino); 699127e670aSJaegeuk Kim 70036795567SGu Zheng if (nentries == F2FS_ORPHANS_PER_BLOCK) { 701127e670aSJaegeuk Kim /* 702127e670aSJaegeuk Kim * an orphan block is full of 1020 entries, 703127e670aSJaegeuk Kim * then we need to flush current orphan blocks 704127e670aSJaegeuk Kim * and bring another one in memory 705127e670aSJaegeuk Kim */ 706127e670aSJaegeuk Kim orphan_blk->blk_addr = cpu_to_le16(index); 707127e670aSJaegeuk Kim orphan_blk->blk_count = cpu_to_le16(orphan_blocks); 708127e670aSJaegeuk Kim orphan_blk->entry_count = cpu_to_le32(nentries); 709127e670aSJaegeuk Kim set_page_dirty(page); 710127e670aSJaegeuk Kim f2fs_put_page(page, 1); 711127e670aSJaegeuk Kim index++; 712127e670aSJaegeuk Kim nentries = 0; 713127e670aSJaegeuk Kim page = NULL; 714127e670aSJaegeuk Kim } 715127e670aSJaegeuk Kim } 716127e670aSJaegeuk Kim 717502c6e0bSGu Zheng if (page) { 718127e670aSJaegeuk Kim orphan_blk->blk_addr = cpu_to_le16(index); 719127e670aSJaegeuk Kim orphan_blk->blk_count = cpu_to_le16(orphan_blocks); 720127e670aSJaegeuk Kim orphan_blk->entry_count = cpu_to_le32(nentries); 721127e670aSJaegeuk Kim set_page_dirty(page); 722127e670aSJaegeuk Kim f2fs_put_page(page, 1); 723502c6e0bSGu Zheng } 724127e670aSJaegeuk Kim } 725127e670aSJaegeuk Kim 726fc0065adSTiezhu Yang static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr, 727fc0065adSTiezhu Yang struct f2fs_checkpoint **cp_block, struct page **cp_page, 728fc0065adSTiezhu Yang unsigned long long *version) 729fc0065adSTiezhu Yang { 730fc0065adSTiezhu Yang unsigned long blk_size = sbi->blocksize; 731fc0065adSTiezhu Yang size_t crc_offset = 0; 732fc0065adSTiezhu Yang __u32 crc = 0; 733fc0065adSTiezhu Yang 734fc0065adSTiezhu Yang *cp_page = get_meta_page(sbi, cp_addr); 735fc0065adSTiezhu Yang *cp_block = (struct f2fs_checkpoint *)page_address(*cp_page); 736fc0065adSTiezhu Yang 737fc0065adSTiezhu Yang crc_offset = le32_to_cpu((*cp_block)->checksum_offset); 738c6f89dfdSKinglong Mee if (crc_offset > (blk_size - sizeof(__le32))) { 739fc0065adSTiezhu Yang f2fs_msg(sbi->sb, KERN_WARNING, 740fc0065adSTiezhu Yang "invalid crc_offset: %zu", crc_offset); 741fc0065adSTiezhu Yang return -EINVAL; 742fc0065adSTiezhu Yang } 743fc0065adSTiezhu Yang 744ced2c7eaSKinglong Mee crc = cur_cp_crc(*cp_block); 745fc0065adSTiezhu Yang if (!f2fs_crc_valid(sbi, crc, *cp_block, crc_offset)) { 746fc0065adSTiezhu Yang f2fs_msg(sbi->sb, KERN_WARNING, "invalid crc value"); 747fc0065adSTiezhu Yang return -EINVAL; 748fc0065adSTiezhu Yang } 749fc0065adSTiezhu Yang 750fc0065adSTiezhu Yang *version = cur_cp_version(*cp_block); 751fc0065adSTiezhu Yang return 0; 752fc0065adSTiezhu Yang } 753fc0065adSTiezhu Yang 754127e670aSJaegeuk Kim static struct page *validate_checkpoint(struct f2fs_sb_info *sbi, 755127e670aSJaegeuk Kim block_t cp_addr, unsigned long long *version) 756127e670aSJaegeuk Kim { 757fc0065adSTiezhu Yang struct page *cp_page_1 = NULL, *cp_page_2 = NULL; 758fc0065adSTiezhu Yang struct f2fs_checkpoint *cp_block = NULL; 759127e670aSJaegeuk Kim unsigned long long cur_version = 0, pre_version = 0; 760fc0065adSTiezhu Yang int err; 761127e670aSJaegeuk Kim 762fc0065adSTiezhu Yang err = get_checkpoint_version(sbi, cp_addr, &cp_block, 763fc0065adSTiezhu Yang &cp_page_1, version); 764fc0065adSTiezhu Yang if (err) 765127e670aSJaegeuk Kim goto invalid_cp1; 766fc0065adSTiezhu Yang pre_version = *version; 767127e670aSJaegeuk Kim 76825ca923bSJaegeuk Kim cp_addr += le32_to_cpu(cp_block->cp_pack_total_block_count) - 1; 769fc0065adSTiezhu Yang err = get_checkpoint_version(sbi, cp_addr, &cp_block, 770fc0065adSTiezhu Yang &cp_page_2, version); 771fc0065adSTiezhu Yang if (err) 772127e670aSJaegeuk Kim goto invalid_cp2; 773fc0065adSTiezhu Yang cur_version = *version; 774127e670aSJaegeuk Kim 775127e670aSJaegeuk Kim if (cur_version == pre_version) { 776127e670aSJaegeuk Kim *version = cur_version; 777127e670aSJaegeuk Kim f2fs_put_page(cp_page_2, 1); 778127e670aSJaegeuk Kim return cp_page_1; 779127e670aSJaegeuk Kim } 780127e670aSJaegeuk Kim invalid_cp2: 781127e670aSJaegeuk Kim f2fs_put_page(cp_page_2, 1); 782127e670aSJaegeuk Kim invalid_cp1: 783127e670aSJaegeuk Kim f2fs_put_page(cp_page_1, 1); 784127e670aSJaegeuk Kim return NULL; 785127e670aSJaegeuk Kim } 786127e670aSJaegeuk Kim 787127e670aSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *sbi) 788127e670aSJaegeuk Kim { 789127e670aSJaegeuk Kim struct f2fs_checkpoint *cp_block; 790127e670aSJaegeuk Kim struct f2fs_super_block *fsb = sbi->raw_super; 791127e670aSJaegeuk Kim struct page *cp1, *cp2, *cur_page; 792127e670aSJaegeuk Kim unsigned long blk_size = sbi->blocksize; 793127e670aSJaegeuk Kim unsigned long long cp1_version = 0, cp2_version = 0; 794127e670aSJaegeuk Kim unsigned long long cp_start_blk_no; 79555141486SWanpeng Li unsigned int cp_blks = 1 + __cp_payload(sbi); 7961dbe4152SChangman Lee block_t cp_blk_no; 7971dbe4152SChangman Lee int i; 798127e670aSJaegeuk Kim 7991dbe4152SChangman Lee sbi->ckpt = kzalloc(cp_blks * blk_size, GFP_KERNEL); 800127e670aSJaegeuk Kim if (!sbi->ckpt) 801127e670aSJaegeuk Kim return -ENOMEM; 802127e670aSJaegeuk Kim /* 803127e670aSJaegeuk Kim * Finding out valid cp block involves read both 804127e670aSJaegeuk Kim * sets( cp pack1 and cp pack 2) 805127e670aSJaegeuk Kim */ 806127e670aSJaegeuk Kim cp_start_blk_no = le32_to_cpu(fsb->cp_blkaddr); 807127e670aSJaegeuk Kim cp1 = validate_checkpoint(sbi, cp_start_blk_no, &cp1_version); 808127e670aSJaegeuk Kim 809127e670aSJaegeuk Kim /* The second checkpoint pack should start at the next segment */ 810f9a4e6dfSJaegeuk Kim cp_start_blk_no += ((unsigned long long)1) << 811f9a4e6dfSJaegeuk Kim le32_to_cpu(fsb->log_blocks_per_seg); 812127e670aSJaegeuk Kim cp2 = validate_checkpoint(sbi, cp_start_blk_no, &cp2_version); 813127e670aSJaegeuk Kim 814127e670aSJaegeuk Kim if (cp1 && cp2) { 815127e670aSJaegeuk Kim if (ver_after(cp2_version, cp1_version)) 816127e670aSJaegeuk Kim cur_page = cp2; 817127e670aSJaegeuk Kim else 818127e670aSJaegeuk Kim cur_page = cp1; 819127e670aSJaegeuk Kim } else if (cp1) { 820127e670aSJaegeuk Kim cur_page = cp1; 821127e670aSJaegeuk Kim } else if (cp2) { 822127e670aSJaegeuk Kim cur_page = cp2; 823127e670aSJaegeuk Kim } else { 824127e670aSJaegeuk Kim goto fail_no_cp; 825127e670aSJaegeuk Kim } 826127e670aSJaegeuk Kim 827127e670aSJaegeuk Kim cp_block = (struct f2fs_checkpoint *)page_address(cur_page); 828127e670aSJaegeuk Kim memcpy(sbi->ckpt, cp_block, blk_size); 829127e670aSJaegeuk Kim 830984ec63cSShawn Lin /* Sanity checking of checkpoint */ 831984ec63cSShawn Lin if (sanity_check_ckpt(sbi)) 832a2125ff7SJaegeuk Kim goto free_fail_no_cp; 833984ec63cSShawn Lin 8348508e44aSJaegeuk Kim if (cur_page == cp1) 8358508e44aSJaegeuk Kim sbi->cur_cp_pack = 1; 8368508e44aSJaegeuk Kim else 8378508e44aSJaegeuk Kim sbi->cur_cp_pack = 2; 8381dbe4152SChangman Lee 8391dbe4152SChangman Lee if (cp_blks <= 1) 8401dbe4152SChangman Lee goto done; 8411dbe4152SChangman Lee 8421dbe4152SChangman Lee cp_blk_no = le32_to_cpu(fsb->cp_blkaddr); 8431dbe4152SChangman Lee if (cur_page == cp2) 8441dbe4152SChangman Lee cp_blk_no += 1 << le32_to_cpu(fsb->log_blocks_per_seg); 8451dbe4152SChangman Lee 8461dbe4152SChangman Lee for (i = 1; i < cp_blks; i++) { 8471dbe4152SChangman Lee void *sit_bitmap_ptr; 8481dbe4152SChangman Lee unsigned char *ckpt = (unsigned char *)sbi->ckpt; 8491dbe4152SChangman Lee 8501dbe4152SChangman Lee cur_page = get_meta_page(sbi, cp_blk_no + i); 8511dbe4152SChangman Lee sit_bitmap_ptr = page_address(cur_page); 852127e670aSJaegeuk Kim memcpy(ckpt + i * blk_size, sit_bitmap_ptr, blk_size); 853127e670aSJaegeuk Kim f2fs_put_page(cur_page, 1); 854127e670aSJaegeuk Kim } 855127e670aSJaegeuk Kim done: 856127e670aSJaegeuk Kim f2fs_put_page(cp1, 1); 857127e670aSJaegeuk Kim f2fs_put_page(cp2, 1); 858127e670aSJaegeuk Kim return 0; 859127e670aSJaegeuk Kim 860a2125ff7SJaegeuk Kim free_fail_no_cp: 861a2125ff7SJaegeuk Kim f2fs_put_page(cp1, 1); 862a2125ff7SJaegeuk Kim f2fs_put_page(cp2, 1); 863127e670aSJaegeuk Kim fail_no_cp: 864127e670aSJaegeuk Kim kfree(sbi->ckpt); 865127e670aSJaegeuk Kim return -EINVAL; 866127e670aSJaegeuk Kim } 867127e670aSJaegeuk Kim 868c227f912SChao Yu static void __add_dirty_inode(struct inode *inode, enum inode_type type) 869127e670aSJaegeuk Kim { 8704081363fSJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 871c227f912SChao Yu int flag = (type == DIR_INODE) ? FI_DIRTY_DIR : FI_DIRTY_FILE; 8722d7b822aSChao Yu 87391942321SJaegeuk Kim if (is_inode_flag_set(inode, flag)) 8742710fd7eSChao Yu return; 8752d7b822aSChao Yu 87691942321SJaegeuk Kim set_inode_flag(inode, flag); 87799f4b917SChao Yu if (!f2fs_is_volatile_file(inode)) 87899f4b917SChao Yu list_add_tail(&F2FS_I(inode)->dirty_list, 87999f4b917SChao Yu &sbi->inode_list[type]); 88033fbd510SChao Yu stat_inc_dirty_inode(sbi, type); 8815deb8267SJaegeuk Kim } 8825deb8267SJaegeuk Kim 883c227f912SChao Yu static void __remove_dirty_inode(struct inode *inode, enum inode_type type) 8846ad7609aSChao Yu { 885c227f912SChao Yu int flag = (type == DIR_INODE) ? FI_DIRTY_DIR : FI_DIRTY_FILE; 8866ad7609aSChao Yu 88791942321SJaegeuk Kim if (get_dirty_pages(inode) || !is_inode_flag_set(inode, flag)) 8886ad7609aSChao Yu return; 8896ad7609aSChao Yu 89091942321SJaegeuk Kim list_del_init(&F2FS_I(inode)->dirty_list); 89191942321SJaegeuk Kim clear_inode_flag(inode, flag); 89233fbd510SChao Yu stat_dec_dirty_inode(F2FS_I_SB(inode), type); 8936ad7609aSChao Yu } 8946ad7609aSChao Yu 895a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *inode, struct page *page) 8965deb8267SJaegeuk Kim { 8974081363fSJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 898c227f912SChao Yu enum inode_type type = S_ISDIR(inode->i_mode) ? DIR_INODE : FILE_INODE; 8995deb8267SJaegeuk Kim 9005ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 9015ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 902127e670aSJaegeuk Kim return; 9037bd59381SGu Zheng 904c227f912SChao Yu spin_lock(&sbi->inode_lock[type]); 9051c4bf763SJaegeuk Kim if (type != FILE_INODE || test_opt(sbi, DATA_FLUSH)) 906c227f912SChao Yu __add_dirty_inode(inode, type); 907b951a4ecSYunlei He inode_inc_dirty_pages(inode); 9081c4bf763SJaegeuk Kim spin_unlock(&sbi->inode_lock[type]); 9091c4bf763SJaegeuk Kim 910a7ffdbe2SJaegeuk Kim SetPagePrivate(page); 9119e4ded3fSJaegeuk Kim f2fs_trace_pid(page); 9125deb8267SJaegeuk Kim } 913127e670aSJaegeuk Kim 914c227f912SChao Yu void remove_dirty_inode(struct inode *inode) 915127e670aSJaegeuk Kim { 9164081363fSJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 917c227f912SChao Yu enum inode_type type = S_ISDIR(inode->i_mode) ? DIR_INODE : FILE_INODE; 918127e670aSJaegeuk Kim 919c227f912SChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 920c227f912SChao Yu !S_ISLNK(inode->i_mode)) 921127e670aSJaegeuk Kim return; 922127e670aSJaegeuk Kim 92310aa97c3SJaegeuk Kim if (type == FILE_INODE && !test_opt(sbi, DATA_FLUSH)) 92410aa97c3SJaegeuk Kim return; 92510aa97c3SJaegeuk Kim 926c227f912SChao Yu spin_lock(&sbi->inode_lock[type]); 927c227f912SChao Yu __remove_dirty_inode(inode, type); 928c227f912SChao Yu spin_unlock(&sbi->inode_lock[type]); 929afc3eda2SJaegeuk Kim } 93074d0b917SJaegeuk Kim 9316d5a1495SChao Yu int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type) 932127e670aSJaegeuk Kim { 933ce3b7d80SGu Zheng struct list_head *head; 934127e670aSJaegeuk Kim struct inode *inode; 9352710fd7eSChao Yu struct f2fs_inode_info *fi; 9364cf18537SChao Yu bool is_dir = (type == DIR_INODE); 9374db08d01SJaegeuk Kim unsigned long ino = 0; 9384cf18537SChao Yu 9394cf18537SChao Yu trace_f2fs_sync_dirty_inodes_enter(sbi->sb, is_dir, 9404cf18537SChao Yu get_pages(sbi, is_dir ? 9414cf18537SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA)); 942127e670aSJaegeuk Kim retry: 943af41d3eeSJaegeuk Kim if (unlikely(f2fs_cp_error(sbi))) 9446d5a1495SChao Yu return -EIO; 945af41d3eeSJaegeuk Kim 946c227f912SChao Yu spin_lock(&sbi->inode_lock[type]); 947ce3b7d80SGu Zheng 948c227f912SChao Yu head = &sbi->inode_list[type]; 949127e670aSJaegeuk Kim if (list_empty(head)) { 950c227f912SChao Yu spin_unlock(&sbi->inode_lock[type]); 9514cf18537SChao Yu trace_f2fs_sync_dirty_inodes_exit(sbi->sb, is_dir, 9524cf18537SChao Yu get_pages(sbi, is_dir ? 9534cf18537SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA)); 9546d5a1495SChao Yu return 0; 955127e670aSJaegeuk Kim } 956939afa94SChao Yu fi = list_first_entry(head, struct f2fs_inode_info, dirty_list); 9572710fd7eSChao Yu inode = igrab(&fi->vfs_inode); 958c227f912SChao Yu spin_unlock(&sbi->inode_lock[type]); 959127e670aSJaegeuk Kim if (inode) { 9604db08d01SJaegeuk Kim unsigned long cur_ino = inode->i_ino; 9614db08d01SJaegeuk Kim 962b0af6d49SChao Yu if (is_dir) 963b0af6d49SChao Yu F2FS_I(inode)->cp_task = current; 964b0af6d49SChao Yu 96587d6f890SJaegeuk Kim filemap_fdatawrite(inode->i_mapping); 966b0af6d49SChao Yu 967b0af6d49SChao Yu if (is_dir) 968b0af6d49SChao Yu F2FS_I(inode)->cp_task = NULL; 969b0af6d49SChao Yu 970127e670aSJaegeuk Kim iput(inode); 9714db08d01SJaegeuk Kim /* We need to give cpu to another writers. */ 9724db08d01SJaegeuk Kim if (ino == cur_ino) { 9734db08d01SJaegeuk Kim congestion_wait(BLK_RW_ASYNC, HZ/50); 9744db08d01SJaegeuk Kim cond_resched(); 9754db08d01SJaegeuk Kim } else { 9764db08d01SJaegeuk Kim ino = cur_ino; 9774db08d01SJaegeuk Kim } 978127e670aSJaegeuk Kim } else { 979127e670aSJaegeuk Kim /* 980127e670aSJaegeuk Kim * We should submit bio, since it exists several 981127e670aSJaegeuk Kim * wribacking dentry pages in the freeing inode. 982127e670aSJaegeuk Kim */ 983b9109b0eSJaegeuk Kim f2fs_submit_merged_write(sbi, DATA); 9847ecebe5eSSebastian Andrzej Siewior cond_resched(); 985127e670aSJaegeuk Kim } 986127e670aSJaegeuk Kim goto retry; 987127e670aSJaegeuk Kim } 988127e670aSJaegeuk Kim 9890f18b462SJaegeuk Kim int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi) 9900f18b462SJaegeuk Kim { 9910f18b462SJaegeuk Kim struct list_head *head = &sbi->inode_list[DIRTY_META]; 9920f18b462SJaegeuk Kim struct inode *inode; 9930f18b462SJaegeuk Kim struct f2fs_inode_info *fi; 9940f18b462SJaegeuk Kim s64 total = get_pages(sbi, F2FS_DIRTY_IMETA); 9950f18b462SJaegeuk Kim 9960f18b462SJaegeuk Kim while (total--) { 9970f18b462SJaegeuk Kim if (unlikely(f2fs_cp_error(sbi))) 9980f18b462SJaegeuk Kim return -EIO; 9990f18b462SJaegeuk Kim 10000f18b462SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 10010f18b462SJaegeuk Kim if (list_empty(head)) { 10020f18b462SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 10030f18b462SJaegeuk Kim return 0; 10040f18b462SJaegeuk Kim } 1005939afa94SChao Yu fi = list_first_entry(head, struct f2fs_inode_info, 10060f18b462SJaegeuk Kim gdirty_list); 10070f18b462SJaegeuk Kim inode = igrab(&fi->vfs_inode); 10080f18b462SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 10090f18b462SJaegeuk Kim if (inode) { 101018340edcSJaegeuk Kim sync_inode_metadata(inode, 0); 101118340edcSJaegeuk Kim 101218340edcSJaegeuk Kim /* it's on eviction */ 101318340edcSJaegeuk Kim if (is_inode_flag_set(inode, FI_DIRTY_INODE)) 10140f18b462SJaegeuk Kim update_inode_page(inode); 10150f18b462SJaegeuk Kim iput(inode); 10160f18b462SJaegeuk Kim } 1017dee668c1SChao Yu } 10180f18b462SJaegeuk Kim return 0; 10190f18b462SJaegeuk Kim } 10200f18b462SJaegeuk Kim 102159c9081bSYunlei He static void __prepare_cp_block(struct f2fs_sb_info *sbi) 102259c9081bSYunlei He { 102359c9081bSYunlei He struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 102459c9081bSYunlei He struct f2fs_nm_info *nm_i = NM_I(sbi); 102559c9081bSYunlei He nid_t last_nid = nm_i->next_scan_nid; 102659c9081bSYunlei He 102759c9081bSYunlei He next_free_nid(sbi, &last_nid); 102859c9081bSYunlei He ckpt->valid_block_count = cpu_to_le64(valid_user_blocks(sbi)); 102959c9081bSYunlei He ckpt->valid_node_count = cpu_to_le32(valid_node_count(sbi)); 103059c9081bSYunlei He ckpt->valid_inode_count = cpu_to_le32(valid_inode_count(sbi)); 103159c9081bSYunlei He ckpt->next_free_nid = cpu_to_le32(last_nid); 103259c9081bSYunlei He } 103359c9081bSYunlei He 10340a8165d7SJaegeuk Kim /* 1035127e670aSJaegeuk Kim * Freeze all the FS-operations for checkpoint. 1036127e670aSJaegeuk Kim */ 1037cf779cabSJaegeuk Kim static int block_operations(struct f2fs_sb_info *sbi) 1038127e670aSJaegeuk Kim { 1039127e670aSJaegeuk Kim struct writeback_control wbc = { 1040127e670aSJaegeuk Kim .sync_mode = WB_SYNC_ALL, 1041127e670aSJaegeuk Kim .nr_to_write = LONG_MAX, 1042127e670aSJaegeuk Kim .for_reclaim = 0, 1043127e670aSJaegeuk Kim }; 1044c718379bSJaegeuk Kim struct blk_plug plug; 1045cf779cabSJaegeuk Kim int err = 0; 1046c718379bSJaegeuk Kim 1047c718379bSJaegeuk Kim blk_start_plug(&plug); 1048c718379bSJaegeuk Kim 104939936837SJaegeuk Kim retry_flush_dents: 1050e479556bSGu Zheng f2fs_lock_all(sbi); 1051127e670aSJaegeuk Kim /* write all the dirty dentry pages */ 1052127e670aSJaegeuk Kim if (get_pages(sbi, F2FS_DIRTY_DENTS)) { 1053e479556bSGu Zheng f2fs_unlock_all(sbi); 10546d5a1495SChao Yu err = sync_dirty_inodes(sbi, DIR_INODE); 10556d5a1495SChao Yu if (err) 1056cf779cabSJaegeuk Kim goto out; 105730973883SJaegeuk Kim cond_resched(); 105839936837SJaegeuk Kim goto retry_flush_dents; 1059127e670aSJaegeuk Kim } 1060127e670aSJaegeuk Kim 106159c9081bSYunlei He /* 106259c9081bSYunlei He * POR: we should ensure that there are no dirty node pages 106359c9081bSYunlei He * until finishing nat/sit flush. inode->i_blocks can be updated. 106459c9081bSYunlei He */ 106559c9081bSYunlei He down_write(&sbi->node_change); 106659c9081bSYunlei He 10670f18b462SJaegeuk Kim if (get_pages(sbi, F2FS_DIRTY_IMETA)) { 106859c9081bSYunlei He up_write(&sbi->node_change); 10690f18b462SJaegeuk Kim f2fs_unlock_all(sbi); 10700f18b462SJaegeuk Kim err = f2fs_sync_inode_meta(sbi); 10710f18b462SJaegeuk Kim if (err) 10720f18b462SJaegeuk Kim goto out; 107330973883SJaegeuk Kim cond_resched(); 10740f18b462SJaegeuk Kim goto retry_flush_dents; 10750f18b462SJaegeuk Kim } 10760f18b462SJaegeuk Kim 107739936837SJaegeuk Kim retry_flush_nodes: 1078b3582c68SChao Yu down_write(&sbi->node_write); 1079127e670aSJaegeuk Kim 1080127e670aSJaegeuk Kim if (get_pages(sbi, F2FS_DIRTY_NODES)) { 1081b3582c68SChao Yu up_write(&sbi->node_write); 1082b0af6d49SChao Yu err = sync_node_pages(sbi, &wbc, false, FS_CP_NODE_IO); 10836d5a1495SChao Yu if (err) { 108459c9081bSYunlei He up_write(&sbi->node_change); 1085cf779cabSJaegeuk Kim f2fs_unlock_all(sbi); 1086cf779cabSJaegeuk Kim goto out; 1087cf779cabSJaegeuk Kim } 108830973883SJaegeuk Kim cond_resched(); 108939936837SJaegeuk Kim goto retry_flush_nodes; 1090127e670aSJaegeuk Kim } 109159c9081bSYunlei He 109259c9081bSYunlei He /* 109359c9081bSYunlei He * sbi->node_change is used only for AIO write_begin path which produces 109459c9081bSYunlei He * dirty node blocks and some checkpoint values by block allocation. 109559c9081bSYunlei He */ 109659c9081bSYunlei He __prepare_cp_block(sbi); 109759c9081bSYunlei He up_write(&sbi->node_change); 1098cf779cabSJaegeuk Kim out: 1099c718379bSJaegeuk Kim blk_finish_plug(&plug); 1100cf779cabSJaegeuk Kim return err; 1101127e670aSJaegeuk Kim } 1102127e670aSJaegeuk Kim 1103127e670aSJaegeuk Kim static void unblock_operations(struct f2fs_sb_info *sbi) 1104127e670aSJaegeuk Kim { 1105b3582c68SChao Yu up_write(&sbi->node_write); 1106e479556bSGu Zheng f2fs_unlock_all(sbi); 1107127e670aSJaegeuk Kim } 1108127e670aSJaegeuk Kim 1109fb51b5efSChangman Lee static void wait_on_all_pages_writeback(struct f2fs_sb_info *sbi) 1110fb51b5efSChangman Lee { 1111fb51b5efSChangman Lee DEFINE_WAIT(wait); 1112fb51b5efSChangman Lee 1113fb51b5efSChangman Lee for (;;) { 1114fb51b5efSChangman Lee prepare_to_wait(&sbi->cp_wait, &wait, TASK_UNINTERRUPTIBLE); 1115fb51b5efSChangman Lee 111636951b38SChao Yu if (!get_pages(sbi, F2FS_WB_CP_DATA)) 1117fb51b5efSChangman Lee break; 1118fb51b5efSChangman Lee 11190ff21646SYunlei He io_schedule_timeout(5*HZ); 1120fb51b5efSChangman Lee } 1121fb51b5efSChangman Lee finish_wait(&sbi->cp_wait, &wait); 1122fb51b5efSChangman Lee } 1123fb51b5efSChangman Lee 1124e4c5d848SJaegeuk Kim static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc) 1125e4c5d848SJaegeuk Kim { 1126e4c5d848SJaegeuk Kim unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num; 1127e4c5d848SJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1128d1aa2453SChao Yu unsigned long flags; 1129e4c5d848SJaegeuk Kim 1130d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1131e4c5d848SJaegeuk Kim 1132c473f1a9SChao Yu if ((cpc->reason & CP_UMOUNT) && 113310047f53SKinglong Mee le32_to_cpu(ckpt->cp_pack_total_block_count) > 113422ad0b6aSJaegeuk Kim sbi->blocks_per_seg - NM_I(sbi)->nat_bits_blocks) 113522ad0b6aSJaegeuk Kim disable_nat_bits(sbi, false); 113622ad0b6aSJaegeuk Kim 11371f43e2adSChao Yu if (cpc->reason & CP_TRIMMED) 11381f43e2adSChao Yu __set_ckpt_flags(ckpt, CP_TRIMMED_FLAG); 11391f43e2adSChao Yu 1140c473f1a9SChao Yu if (cpc->reason & CP_UMOUNT) 1141e4c5d848SJaegeuk Kim __set_ckpt_flags(ckpt, CP_UMOUNT_FLAG); 1142e4c5d848SJaegeuk Kim else 1143e4c5d848SJaegeuk Kim __clear_ckpt_flags(ckpt, CP_UMOUNT_FLAG); 1144e4c5d848SJaegeuk Kim 1145c473f1a9SChao Yu if (cpc->reason & CP_FASTBOOT) 1146e4c5d848SJaegeuk Kim __set_ckpt_flags(ckpt, CP_FASTBOOT_FLAG); 1147e4c5d848SJaegeuk Kim else 1148e4c5d848SJaegeuk Kim __clear_ckpt_flags(ckpt, CP_FASTBOOT_FLAG); 1149e4c5d848SJaegeuk Kim 1150e4c5d848SJaegeuk Kim if (orphan_num) 1151e4c5d848SJaegeuk Kim __set_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG); 1152e4c5d848SJaegeuk Kim else 1153e4c5d848SJaegeuk Kim __clear_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG); 1154e4c5d848SJaegeuk Kim 1155e4c5d848SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) 1156e4c5d848SJaegeuk Kim __set_ckpt_flags(ckpt, CP_FSCK_FLAG); 1157e4c5d848SJaegeuk Kim 1158e4c5d848SJaegeuk Kim /* set this flag to activate crc|cp_ver for recovery */ 1159e4c5d848SJaegeuk Kim __set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG); 1160e4c5d848SJaegeuk Kim 1161d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1162e4c5d848SJaegeuk Kim } 1163e4c5d848SJaegeuk Kim 1164c34f42e2SChao Yu static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) 1165127e670aSJaegeuk Kim { 1166127e670aSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 116777041823SHuang Ying struct f2fs_nm_info *nm_i = NM_I(sbi); 1168d1aa2453SChao Yu unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num, flags; 1169127e670aSJaegeuk Kim block_t start_blk; 1170127e670aSJaegeuk Kim unsigned int data_sum_blocks, orphan_blocks; 11717e586fa0SJaegeuk Kim __u32 crc32 = 0; 1172127e670aSJaegeuk Kim int i; 117355141486SWanpeng Li int cp_payload_blks = __cp_payload(sbi); 11748f1dbbbbSShuoran Liu struct super_block *sb = sbi->sb; 11758f1dbbbbSShuoran Liu struct curseg_info *seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); 11768f1dbbbbSShuoran Liu u64 kbytes_written; 11771228b482SChao Yu int err; 1178127e670aSJaegeuk Kim 1179127e670aSJaegeuk Kim /* Flush all the NAT/SIT pages */ 1180cf779cabSJaegeuk Kim while (get_pages(sbi, F2FS_DIRTY_META)) { 1181b0af6d49SChao Yu sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO); 1182cf779cabSJaegeuk Kim if (unlikely(f2fs_cp_error(sbi))) 1183c34f42e2SChao Yu return -EIO; 1184cf779cabSJaegeuk Kim } 1185127e670aSJaegeuk Kim 1186127e670aSJaegeuk Kim /* 1187127e670aSJaegeuk Kim * modify checkpoint 1188127e670aSJaegeuk Kim * version number is already updated 1189127e670aSJaegeuk Kim */ 1190127e670aSJaegeuk Kim ckpt->elapsed_time = cpu_to_le64(get_mtime(sbi)); 1191127e670aSJaegeuk Kim ckpt->free_segment_count = cpu_to_le32(free_segments(sbi)); 1192b5b82205SChao Yu for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) { 1193127e670aSJaegeuk Kim ckpt->cur_node_segno[i] = 1194127e670aSJaegeuk Kim cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_NODE)); 1195127e670aSJaegeuk Kim ckpt->cur_node_blkoff[i] = 1196127e670aSJaegeuk Kim cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_NODE)); 1197127e670aSJaegeuk Kim ckpt->alloc_type[i + CURSEG_HOT_NODE] = 1198127e670aSJaegeuk Kim curseg_alloc_type(sbi, i + CURSEG_HOT_NODE); 1199127e670aSJaegeuk Kim } 1200b5b82205SChao Yu for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { 1201127e670aSJaegeuk Kim ckpt->cur_data_segno[i] = 1202127e670aSJaegeuk Kim cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_DATA)); 1203127e670aSJaegeuk Kim ckpt->cur_data_blkoff[i] = 1204127e670aSJaegeuk Kim cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_DATA)); 1205127e670aSJaegeuk Kim ckpt->alloc_type[i + CURSEG_HOT_DATA] = 1206127e670aSJaegeuk Kim curseg_alloc_type(sbi, i + CURSEG_HOT_DATA); 1207127e670aSJaegeuk Kim } 1208127e670aSJaegeuk Kim 1209127e670aSJaegeuk Kim /* 2 cp + n data seg summary + orphan inode blocks */ 12103fa06d7bSChao Yu data_sum_blocks = npages_for_summary_flush(sbi, false); 1211d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1212b5b82205SChao Yu if (data_sum_blocks < NR_CURSEG_DATA_TYPE) 1213aaec2b1dSChao Yu __set_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG); 1214127e670aSJaegeuk Kim else 1215aaec2b1dSChao Yu __clear_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG); 1216d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1217127e670aSJaegeuk Kim 121867298804SChao Yu orphan_blocks = GET_ORPHAN_BLOCKS(orphan_num); 12191dbe4152SChangman Lee ckpt->cp_pack_start_sum = cpu_to_le32(1 + cp_payload_blks + 12201dbe4152SChangman Lee orphan_blocks); 1221127e670aSJaegeuk Kim 1222119ee914SJaegeuk Kim if (__remain_node_summaries(cpc->reason)) 1223b5b82205SChao Yu ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS+ 12241dbe4152SChangman Lee cp_payload_blks + data_sum_blocks + 12251dbe4152SChangman Lee orphan_blocks + NR_CURSEG_NODE_TYPE); 1226119ee914SJaegeuk Kim else 1227b5b82205SChao Yu ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS + 12281dbe4152SChangman Lee cp_payload_blks + data_sum_blocks + 12291dbe4152SChangman Lee orphan_blocks); 1230119ee914SJaegeuk Kim 1231e4c5d848SJaegeuk Kim /* update ckpt flag for checkpoint */ 1232e4c5d848SJaegeuk Kim update_ckpt_flags(sbi, cpc); 1233a468f0efSJaegeuk Kim 1234127e670aSJaegeuk Kim /* update SIT/NAT bitmap */ 1235127e670aSJaegeuk Kim get_sit_bitmap(sbi, __bitmap_ptr(sbi, SIT_BITMAP)); 1236127e670aSJaegeuk Kim get_nat_bitmap(sbi, __bitmap_ptr(sbi, NAT_BITMAP)); 1237127e670aSJaegeuk Kim 123843b6573bSKeith Mok crc32 = f2fs_crc32(sbi, ckpt, le32_to_cpu(ckpt->checksum_offset)); 12397e586fa0SJaegeuk Kim *((__le32 *)((unsigned char *)ckpt + 12407e586fa0SJaegeuk Kim le32_to_cpu(ckpt->checksum_offset))) 1241127e670aSJaegeuk Kim = cpu_to_le32(crc32); 1242127e670aSJaegeuk Kim 12438508e44aSJaegeuk Kim start_blk = __start_cp_next_addr(sbi); 1244127e670aSJaegeuk Kim 124522ad0b6aSJaegeuk Kim /* write nat bits */ 124622ad0b6aSJaegeuk Kim if (enabled_nat_bits(sbi, cpc)) { 124722ad0b6aSJaegeuk Kim __u64 cp_ver = cur_cp_version(ckpt); 124822ad0b6aSJaegeuk Kim block_t blk; 124922ad0b6aSJaegeuk Kim 125022ad0b6aSJaegeuk Kim cp_ver |= ((__u64)crc32 << 32); 125122ad0b6aSJaegeuk Kim *(__le64 *)nm_i->nat_bits = cpu_to_le64(cp_ver); 125222ad0b6aSJaegeuk Kim 125322ad0b6aSJaegeuk Kim blk = start_blk + sbi->blocks_per_seg - nm_i->nat_bits_blocks; 125422ad0b6aSJaegeuk Kim for (i = 0; i < nm_i->nat_bits_blocks; i++) 125522ad0b6aSJaegeuk Kim update_meta_page(sbi, nm_i->nat_bits + 125622ad0b6aSJaegeuk Kim (i << F2FS_BLKSIZE_BITS), blk + i); 125722ad0b6aSJaegeuk Kim 125822ad0b6aSJaegeuk Kim /* Flush all the NAT BITS pages */ 125922ad0b6aSJaegeuk Kim while (get_pages(sbi, F2FS_DIRTY_META)) { 1260b0af6d49SChao Yu sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO); 126122ad0b6aSJaegeuk Kim if (unlikely(f2fs_cp_error(sbi))) 126222ad0b6aSJaegeuk Kim return -EIO; 126322ad0b6aSJaegeuk Kim } 126422ad0b6aSJaegeuk Kim } 126522ad0b6aSJaegeuk Kim 1266a7230d16SJaegeuk Kim /* need to wait for end_io results */ 1267a7230d16SJaegeuk Kim wait_on_all_pages_writeback(sbi); 1268a7230d16SJaegeuk Kim if (unlikely(f2fs_cp_error(sbi))) 1269c34f42e2SChao Yu return -EIO; 1270a7230d16SJaegeuk Kim 12711228b482SChao Yu /* flush all device cache */ 12721228b482SChao Yu err = f2fs_flush_device_cache(sbi); 12731228b482SChao Yu if (err) 12741228b482SChao Yu return err; 12751228b482SChao Yu 1276127e670aSJaegeuk Kim /* write out checkpoint buffer at block 0 */ 1277381722d2SChao Yu update_meta_page(sbi, ckpt, start_blk++); 1278127e670aSJaegeuk Kim 1279381722d2SChao Yu for (i = 1; i < 1 + cp_payload_blks; i++) 1280381722d2SChao Yu update_meta_page(sbi, (char *)ckpt + i * F2FS_BLKSIZE, 1281381722d2SChao Yu start_blk++); 12821dbe4152SChangman Lee 128367298804SChao Yu if (orphan_num) { 1284127e670aSJaegeuk Kim write_orphan_inodes(sbi, start_blk); 1285127e670aSJaegeuk Kim start_blk += orphan_blocks; 1286127e670aSJaegeuk Kim } 1287127e670aSJaegeuk Kim 1288127e670aSJaegeuk Kim write_data_summaries(sbi, start_blk); 1289127e670aSJaegeuk Kim start_blk += data_sum_blocks; 12908f1dbbbbSShuoran Liu 12918f1dbbbbSShuoran Liu /* Record write statistics in the hot node summary */ 12928f1dbbbbSShuoran Liu kbytes_written = sbi->kbytes_written; 12938f1dbbbbSShuoran Liu if (sb->s_bdev->bd_part) 12948f1dbbbbSShuoran Liu kbytes_written += BD_PART_WRITTEN(sbi); 12958f1dbbbbSShuoran Liu 1296b7ad7512SChao Yu seg_i->journal->info.kbytes_written = cpu_to_le64(kbytes_written); 12978f1dbbbbSShuoran Liu 1298119ee914SJaegeuk Kim if (__remain_node_summaries(cpc->reason)) { 1299127e670aSJaegeuk Kim write_node_summaries(sbi, start_blk); 1300127e670aSJaegeuk Kim start_blk += NR_CURSEG_NODE_TYPE; 1301127e670aSJaegeuk Kim } 1302127e670aSJaegeuk Kim 1303127e670aSJaegeuk Kim /* writeout checkpoint block */ 1304381722d2SChao Yu update_meta_page(sbi, ckpt, start_blk); 1305127e670aSJaegeuk Kim 1306127e670aSJaegeuk Kim /* wait for previous submitted node/meta pages writeback */ 1307fb51b5efSChangman Lee wait_on_all_pages_writeback(sbi); 1308127e670aSJaegeuk Kim 1309cf779cabSJaegeuk Kim if (unlikely(f2fs_cp_error(sbi))) 1310c34f42e2SChao Yu return -EIO; 1311cf779cabSJaegeuk Kim 131280dd9c0eSChao Yu filemap_fdatawait_range(NODE_MAPPING(sbi), 0, LLONG_MAX); 131380dd9c0eSChao Yu filemap_fdatawait_range(META_MAPPING(sbi), 0, LLONG_MAX); 1314127e670aSJaegeuk Kim 1315127e670aSJaegeuk Kim /* update user_block_counts */ 1316127e670aSJaegeuk Kim sbi->last_valid_block_count = sbi->total_valid_block_count; 131741382ec4SJaegeuk Kim percpu_counter_set(&sbi->alloc_valid_block_count, 0); 1318127e670aSJaegeuk Kim 1319127e670aSJaegeuk Kim /* Here, we only have one bio having CP pack */ 1320b0af6d49SChao Yu sync_meta_pages(sbi, META_FLUSH, LONG_MAX, FS_CP_META_IO); 1321127e670aSJaegeuk Kim 13226a8f8ca5SJaegeuk Kim /* wait for previous submitted meta pages writeback */ 13236a8f8ca5SJaegeuk Kim wait_on_all_pages_writeback(sbi); 13246a8f8ca5SJaegeuk Kim 132574ef9241SJaegeuk Kim release_ino_entry(sbi, false); 1326cf779cabSJaegeuk Kim 1327cf779cabSJaegeuk Kim if (unlikely(f2fs_cp_error(sbi))) 1328c34f42e2SChao Yu return -EIO; 1329cf779cabSJaegeuk Kim 1330caf0047eSChao Yu clear_sbi_flag(sbi, SBI_IS_DIRTY); 1331bbf156f7SJaegeuk Kim clear_sbi_flag(sbi, SBI_NEED_CP); 13328508e44aSJaegeuk Kim __set_cp_next_pack(sbi); 1333c34f42e2SChao Yu 1334c2a080aeSChao Yu /* 1335c2a080aeSChao Yu * redirty superblock if metadata like node page or inode cache is 1336c2a080aeSChao Yu * updated during writing checkpoint. 1337c2a080aeSChao Yu */ 1338c2a080aeSChao Yu if (get_pages(sbi, F2FS_DIRTY_NODES) || 1339c2a080aeSChao Yu get_pages(sbi, F2FS_DIRTY_IMETA)) 1340c2a080aeSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 1341c2a080aeSChao Yu 1342c2a080aeSChao Yu f2fs_bug_on(sbi, get_pages(sbi, F2FS_DIRTY_DENTS)); 1343c2a080aeSChao Yu 1344c34f42e2SChao Yu return 0; 1345127e670aSJaegeuk Kim } 1346127e670aSJaegeuk Kim 13470a8165d7SJaegeuk Kim /* 1348e1c42045Sarter97 * We guarantee that this checkpoint procedure will not fail. 1349127e670aSJaegeuk Kim */ 1350c34f42e2SChao Yu int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) 1351127e670aSJaegeuk Kim { 1352127e670aSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1353127e670aSJaegeuk Kim unsigned long long ckpt_ver; 1354c34f42e2SChao Yu int err = 0; 1355127e670aSJaegeuk Kim 1356127e670aSJaegeuk Kim mutex_lock(&sbi->cp_mutex); 13578501017eSJaegeuk Kim 1358caf0047eSChao Yu if (!is_sbi_flag_set(sbi, SBI_IS_DIRTY) && 1359c473f1a9SChao Yu ((cpc->reason & CP_FASTBOOT) || (cpc->reason & CP_SYNC) || 1360c473f1a9SChao Yu ((cpc->reason & CP_DISCARD) && !sbi->discard_blks))) 13618501017eSJaegeuk Kim goto out; 1362c34f42e2SChao Yu if (unlikely(f2fs_cp_error(sbi))) { 1363c34f42e2SChao Yu err = -EIO; 1364cf779cabSJaegeuk Kim goto out; 1365c34f42e2SChao Yu } 1366c34f42e2SChao Yu if (f2fs_readonly(sbi->sb)) { 1367c34f42e2SChao Yu err = -EROFS; 136811504a8eSJaegeuk Kim goto out; 1369c34f42e2SChao Yu } 13702bda542dSWanpeng Li 13712bda542dSWanpeng Li trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "start block_ops"); 13722bda542dSWanpeng Li 1373c34f42e2SChao Yu err = block_operations(sbi); 1374c34f42e2SChao Yu if (err) 1375cf779cabSJaegeuk Kim goto out; 1376127e670aSJaegeuk Kim 137775ab4cb8SJaegeuk Kim trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish block_ops"); 13782af4bd6cSNamjae Jeon 1379b9109b0eSJaegeuk Kim f2fs_flush_merged_writes(sbi); 1380127e670aSJaegeuk Kim 138158cce381SYunlei He /* this is the case of multiple fstrims without any changes */ 1382c473f1a9SChao Yu if (cpc->reason & CP_DISCARD) { 138325290fa5SJaegeuk Kim if (!exist_trim_candidates(sbi, cpc)) { 138425290fa5SJaegeuk Kim unblock_operations(sbi); 138525290fa5SJaegeuk Kim goto out; 138625290fa5SJaegeuk Kim } 138725290fa5SJaegeuk Kim 13880333ad4eSJaegeuk Kim if (NM_I(sbi)->dirty_nat_cnt == 0 && 13890333ad4eSJaegeuk Kim SIT_I(sbi)->dirty_sentries == 0 && 13900333ad4eSJaegeuk Kim prefree_segments(sbi) == 0) { 139158cce381SYunlei He flush_sit_entries(sbi, cpc); 139258cce381SYunlei He clear_prefree_segments(sbi, cpc); 139358cce381SYunlei He unblock_operations(sbi); 139458cce381SYunlei He goto out; 139558cce381SYunlei He } 13960333ad4eSJaegeuk Kim } 139758cce381SYunlei He 1398127e670aSJaegeuk Kim /* 1399127e670aSJaegeuk Kim * update checkpoint pack index 1400127e670aSJaegeuk Kim * Increase the version number so that 1401127e670aSJaegeuk Kim * SIT entries and seg summaries are written at correct place 1402127e670aSJaegeuk Kim */ 1403d71b5564SJaegeuk Kim ckpt_ver = cur_cp_version(ckpt); 1404127e670aSJaegeuk Kim ckpt->checkpoint_ver = cpu_to_le64(++ckpt_ver); 1405127e670aSJaegeuk Kim 1406127e670aSJaegeuk Kim /* write cached NAT/SIT entries to NAT/SIT area */ 140722ad0b6aSJaegeuk Kim flush_nat_entries(sbi, cpc); 14084b2fecc8SJaegeuk Kim flush_sit_entries(sbi, cpc); 1409127e670aSJaegeuk Kim 1410127e670aSJaegeuk Kim /* unlock all the fs_lock[] in do_checkpoint() */ 1411c34f42e2SChao Yu err = do_checkpoint(sbi, cpc); 14124e6a8d9bSJaegeuk Kim if (err) 14132dd15654SChao Yu release_discard_addrs(sbi); 14144e6a8d9bSJaegeuk Kim else 14152dd15654SChao Yu clear_prefree_segments(sbi, cpc); 1416275b66b0SChao Yu 1417127e670aSJaegeuk Kim unblock_operations(sbi); 1418942e0be6SChangman Lee stat_inc_cp_count(sbi->stat_info); 141910027551SJaegeuk Kim 1420c473f1a9SChao Yu if (cpc->reason & CP_RECOVERY) 142110027551SJaegeuk Kim f2fs_msg(sbi->sb, KERN_NOTICE, 142210027551SJaegeuk Kim "checkpoint: version = %llx", ckpt_ver); 142360b99b48SJaegeuk Kim 142460b99b48SJaegeuk Kim /* do checkpoint periodically */ 14256beceb54SJaegeuk Kim f2fs_update_time(sbi, CP_TIME); 142655d1cdb2SJaegeuk Kim trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish checkpoint"); 14278501017eSJaegeuk Kim out: 14288501017eSJaegeuk Kim mutex_unlock(&sbi->cp_mutex); 1429c34f42e2SChao Yu return err; 1430127e670aSJaegeuk Kim } 1431127e670aSJaegeuk Kim 14326451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *sbi) 1433127e670aSJaegeuk Kim { 14346451e041SJaegeuk Kim int i; 14356451e041SJaegeuk Kim 14366451e041SJaegeuk Kim for (i = 0; i < MAX_INO_ENTRY; i++) { 143767298804SChao Yu struct inode_management *im = &sbi->im[i]; 143867298804SChao Yu 143967298804SChao Yu INIT_RADIX_TREE(&im->ino_root, GFP_ATOMIC); 144067298804SChao Yu spin_lock_init(&im->ino_lock); 144167298804SChao Yu INIT_LIST_HEAD(&im->ino_list); 144267298804SChao Yu im->ino_num = 0; 14436451e041SJaegeuk Kim } 14446451e041SJaegeuk Kim 1445b5b82205SChao Yu sbi->max_orphans = (sbi->blocks_per_seg - F2FS_CP_PACKS - 144614b42817SWanpeng Li NR_CURSEG_TYPE - __cp_payload(sbi)) * 144714b42817SWanpeng Li F2FS_ORPHANS_PER_BLOCK; 1448127e670aSJaegeuk Kim } 1449127e670aSJaegeuk Kim 14506e6093a8SNamjae Jeon int __init create_checkpoint_caches(void) 1451127e670aSJaegeuk Kim { 14526451e041SJaegeuk Kim ino_entry_slab = f2fs_kmem_cache_create("f2fs_ino_entry", 14536451e041SJaegeuk Kim sizeof(struct ino_entry)); 14546451e041SJaegeuk Kim if (!ino_entry_slab) 1455127e670aSJaegeuk Kim return -ENOMEM; 145606292073SChao Yu inode_entry_slab = f2fs_kmem_cache_create("f2fs_inode_entry", 145706292073SChao Yu sizeof(struct inode_entry)); 14586bacf52fSJaegeuk Kim if (!inode_entry_slab) { 14596451e041SJaegeuk Kim kmem_cache_destroy(ino_entry_slab); 1460127e670aSJaegeuk Kim return -ENOMEM; 1461127e670aSJaegeuk Kim } 1462127e670aSJaegeuk Kim return 0; 1463127e670aSJaegeuk Kim } 1464127e670aSJaegeuk Kim 1465127e670aSJaegeuk Kim void destroy_checkpoint_caches(void) 1466127e670aSJaegeuk Kim { 14676451e041SJaegeuk Kim kmem_cache_destroy(ino_entry_slab); 1468127e670aSJaegeuk Kim kmem_cache_destroy(inode_entry_slab); 1469127e670aSJaegeuk Kim } 1470