Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'f2fs-for-3.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

Pull f2fs fixes from Jaegeuk Kim:
o Support swap file and link generic_file_remap_pages
o Enhance the bio streaming flow and free section control
o Major bug fix on recovery routine
o Minor bug/warning fixes and code cleanups

* tag 'f2fs-for-3.8-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (22 commits)
f2fs: use _safe() version of list_for_each
f2fs: add comments of start_bidx_of_node
f2fs: avoid issuing small bios due to several dirty node pages
f2fs: support swapfile
f2fs: add remap_pages as generic_file_remap_pages
f2fs: add __init to functions in init_f2fs_fs
f2fs: fix the debugfs entry creation path
f2fs: add global mutex_lock to protect f2fs_stat_list
f2fs: remove the blk_plug usage in f2fs_write_data_pages
f2fs: avoid redundant time update for parent directory in f2fs_delete_entry
f2fs: remove redundant call to set_blocksize in f2fs_fill_super
f2fs: move f2fs_balance_fs to punch_hole
f2fs: add f2fs_balance_fs in several interfaces
f2fs: revisit the f2fs_gc flow
f2fs: check return value during recovery
f2fs: avoid null dereference in f2fs_acl_from_disk
f2fs: initialize newly allocated dnode structure
f2fs: update f2fs partition info about SIT/NAT layout
f2fs: update f2fs document to reflect SIT/NAT layout correctly
f2fs: remove unneeded INIT_LIST_HEAD at few places
...

+198 -140
+9 -9
Documentation/filesystems/f2fs.txt
··· 175 175 align with the zone size <-| 176 176 |-> align with the segment size 177 177 _________________________________________________________________________ 178 - | | | Node | Segment | Segment | | 179 - | Superblock | Checkpoint | Address | Info. | Summary | Main | 180 - | (SB) | (CP) | Table (NAT) | Table (SIT) | Area (SSA) | | 178 + | | | Segment | Node | Segment | | 179 + | Superblock | Checkpoint | Info. | Address | Summary | Main | 180 + | (SB) | (CP) | Table (SIT) | Table (NAT) | Area (SSA) | | 181 181 |____________|_____2______|______N______|______N______|______N_____|__N___| 182 182 . . 183 183 . . ··· 200 200 : It contains file system information, bitmaps for valid NAT/SIT sets, orphan 201 201 inode lists, and summary entries of current active segments. 202 202 203 - - Node Address Table (NAT) 204 - : It is composed of a block address table for all the node blocks stored in 205 - Main area. 206 - 207 203 - Segment Information Table (SIT) 208 204 : It contains segment information such as valid block count and bitmap for the 209 205 validity of all the blocks. 206 + 207 + - Node Address Table (NAT) 208 + : It is composed of a block address table for all the node blocks stored in 209 + Main area. 210 210 211 211 - Segment Summary Area (SSA) 212 212 : It contains summary entries which contains the owner information of all the ··· 236 236 valid, as shown as below. 237 237 238 238 +--------+----------+---------+ 239 - | CP | NAT | SIT | 239 + | CP | SIT | NAT | 240 240 +--------+----------+---------+ 241 241 . . . . 242 242 . . . . 243 243 . . . . 244 244 +-------+-------+--------+--------+--------+--------+ 245 - | CP #0 | CP #1 | NAT #0 | NAT #1 | SIT #0 | SIT #1 | 245 + | CP #0 | CP #1 | SIT #0 | SIT #1 | NAT #0 | NAT #1 | 246 246 +-------+-------+--------+--------+--------+--------+ 247 247 | ^ ^ 248 248 | | |
+6 -7
fs/f2fs/acl.c
··· 191 191 retval = f2fs_getxattr(inode, name_index, "", value, retval); 192 192 } 193 193 194 - if (retval < 0) { 195 - if (retval == -ENODATA) 196 - acl = NULL; 197 - else 198 - acl = ERR_PTR(retval); 199 - } else { 194 + if (retval > 0) 200 195 acl = f2fs_acl_from_disk(value, retval); 201 - } 196 + else if (retval == -ENODATA) 197 + acl = NULL; 198 + else 199 + acl = ERR_PTR(retval); 202 200 kfree(value); 201 + 203 202 if (!IS_ERR(acl)) 204 203 set_cached_acl(inode, type, acl); 205 204
+1 -2
fs/f2fs/checkpoint.c
··· 214 214 goto retry; 215 215 } 216 216 new->ino = ino; 217 - INIT_LIST_HEAD(&new->list); 218 217 219 218 /* add new_oentry into list which is sorted by inode number */ 220 219 if (orphan) { ··· 771 772 sbi->n_orphans = 0; 772 773 } 773 774 774 - int create_checkpoint_caches(void) 775 + int __init create_checkpoint_caches(void) 775 776 { 776 777 orphan_entry_slab = f2fs_kmem_cache_create("f2fs_orphan_entry", 777 778 sizeof(struct orphan_inode_entry), NULL);
+16 -1
fs/f2fs/data.c
··· 547 547 548 548 #define MAX_DESIRED_PAGES_WP 4096 549 549 550 + static int __f2fs_writepage(struct page *page, struct writeback_control *wbc, 551 + void *data) 552 + { 553 + struct address_space *mapping = data; 554 + int ret = mapping->a_ops->writepage(page, wbc); 555 + mapping_set_error(mapping, ret); 556 + return ret; 557 + } 558 + 550 559 static int f2fs_write_data_pages(struct address_space *mapping, 551 560 struct writeback_control *wbc) 552 561 { ··· 572 563 573 564 if (!S_ISDIR(inode->i_mode)) 574 565 mutex_lock(&sbi->writepages); 575 - ret = generic_writepages(mapping, wbc); 566 + ret = write_cache_pages(mapping, wbc, __f2fs_writepage, mapping); 576 567 if (!S_ISDIR(inode->i_mode)) 577 568 mutex_unlock(&sbi->writepages); 578 569 f2fs_submit_bio(sbi, DATA, (wbc->sync_mode == WB_SYNC_ALL)); ··· 698 689 return 0; 699 690 } 700 691 692 + static sector_t f2fs_bmap(struct address_space *mapping, sector_t block) 693 + { 694 + return generic_block_bmap(mapping, block, get_data_block_ro); 695 + } 696 + 701 697 const struct address_space_operations f2fs_dblock_aops = { 702 698 .readpage = f2fs_read_data_page, 703 699 .readpages = f2fs_read_data_pages, ··· 714 700 .invalidatepage = f2fs_invalidate_data_page, 715 701 .releasepage = f2fs_release_data_page, 716 702 .direct_IO = f2fs_direct_IO, 703 + .bmap = f2fs_bmap, 717 704 };
+21 -29
fs/f2fs/debug.c
··· 26 26 27 27 static LIST_HEAD(f2fs_stat_list); 28 28 static struct dentry *debugfs_root; 29 + static DEFINE_MUTEX(f2fs_stat_mutex); 29 30 30 31 static void update_general_status(struct f2fs_sb_info *sbi) 31 32 { ··· 181 180 int i = 0; 182 181 int j; 183 182 183 + mutex_lock(&f2fs_stat_mutex); 184 184 list_for_each_entry_safe(si, next, &f2fs_stat_list, stat_list) { 185 185 186 - mutex_lock(&si->stat_lock); 187 - if (!si->sbi) { 188 - mutex_unlock(&si->stat_lock); 189 - continue; 190 - } 191 186 update_general_status(si->sbi); 192 187 193 188 seq_printf(s, "\n=====[ partition info. #%d ]=====\n", i++); 194 - seq_printf(s, "[SB: 1] [CP: 2] [NAT: %d] [SIT: %d] ", 195 - si->nat_area_segs, si->sit_area_segs); 189 + seq_printf(s, "[SB: 1] [CP: 2] [SIT: %d] [NAT: %d] ", 190 + si->sit_area_segs, si->nat_area_segs); 196 191 seq_printf(s, "[SSA: %d] [MAIN: %d", 197 192 si->ssa_area_segs, si->main_area_segs); 198 193 seq_printf(s, "(OverProv:%d Resv:%d)]\n\n", ··· 283 286 seq_printf(s, "\nMemory: %u KB = static: %u + cached: %u\n", 284 287 (si->base_mem + si->cache_mem) >> 10, 285 288 si->base_mem >> 10, si->cache_mem >> 10); 286 - mutex_unlock(&si->stat_lock); 287 289 } 290 + mutex_unlock(&f2fs_stat_mutex); 288 291 return 0; 289 292 } 290 293 ··· 300 303 .release = single_release, 301 304 }; 302 305 303 - static int init_stats(struct f2fs_sb_info *sbi) 306 + int f2fs_build_stats(struct f2fs_sb_info *sbi) 304 307 { 305 308 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); 306 309 struct f2fs_stat_info *si; ··· 310 313 return -ENOMEM; 311 314 312 315 si = sbi->stat_info; 313 - mutex_init(&si->stat_lock); 314 - list_add_tail(&si->stat_list, &f2fs_stat_list); 315 - 316 316 si->all_area_segs = le32_to_cpu(raw_super->segment_count); 317 317 si->sit_area_segs = le32_to_cpu(raw_super->segment_count_sit); 318 318 si->nat_area_segs = le32_to_cpu(raw_super->segment_count_nat); ··· 319 325 si->main_area_zones = si->main_area_sections / 320 326 le32_to_cpu(raw_super->secs_per_zone); 321 327 si->sbi = sbi; 322 - return 0; 323 - } 324 328 325 - int f2fs_build_stats(struct f2fs_sb_info *sbi) 326 - { 327 - int retval; 329 + mutex_lock(&f2fs_stat_mutex); 330 + list_add_tail(&si->stat_list, &f2fs_stat_list); 331 + mutex_unlock(&f2fs_stat_mutex); 328 332 329 - retval = init_stats(sbi); 330 - if (retval) 331 - return retval; 332 - 333 - if (!debugfs_root) 334 - debugfs_root = debugfs_create_dir("f2fs", NULL); 335 - 336 - debugfs_create_file("status", S_IRUGO, debugfs_root, NULL, &stat_fops); 337 333 return 0; 338 334 } 339 335 ··· 331 347 { 332 348 struct f2fs_stat_info *si = sbi->stat_info; 333 349 350 + mutex_lock(&f2fs_stat_mutex); 334 351 list_del(&si->stat_list); 335 - mutex_lock(&si->stat_lock); 336 - si->sbi = NULL; 337 - mutex_unlock(&si->stat_lock); 352 + mutex_unlock(&f2fs_stat_mutex); 353 + 338 354 kfree(sbi->stat_info); 339 355 } 340 356 341 - void destroy_root_stats(void) 357 + void __init f2fs_create_root_stats(void) 358 + { 359 + debugfs_root = debugfs_create_dir("f2fs", NULL); 360 + if (debugfs_root) 361 + debugfs_create_file("status", S_IRUGO, debugfs_root, 362 + NULL, &stat_fops); 363 + } 364 + 365 + void f2fs_destroy_root_stats(void) 342 366 { 343 367 debugfs_remove_recursive(debugfs_root); 344 368 debugfs_root = NULL;
+1 -1
fs/f2fs/dir.c
··· 503 503 } 504 504 505 505 if (inode) { 506 - inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; 506 + inode->i_ctime = CURRENT_TIME; 507 507 drop_nlink(inode); 508 508 if (S_ISDIR(inode->i_mode)) { 509 509 drop_nlink(inode);
+11 -7
fs/f2fs/f2fs.h
··· 211 211 static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 212 212 struct page *ipage, struct page *npage, nid_t nid) 213 213 { 214 + memset(dn, 0, sizeof(*dn)); 214 215 dn->inode = inode; 215 216 dn->inode_page = ipage; 216 217 dn->node_page = npage; 217 218 dn->nid = nid; 218 - dn->inode_page_locked = 0; 219 219 } 220 220 221 221 /* ··· 877 877 * super.c 878 878 */ 879 879 int f2fs_sync_fs(struct super_block *, int); 880 + extern __printf(3, 4) 881 + void f2fs_msg(struct super_block *, const char *, const char *, ...); 880 882 881 883 /* 882 884 * hash.c ··· 914 912 void flush_nat_entries(struct f2fs_sb_info *); 915 913 int build_node_manager(struct f2fs_sb_info *); 916 914 void destroy_node_manager(struct f2fs_sb_info *); 917 - int create_node_manager_caches(void); 915 + int __init create_node_manager_caches(void); 918 916 void destroy_node_manager_caches(void); 919 917 920 918 /* ··· 966 964 void block_operations(struct f2fs_sb_info *); 967 965 void write_checkpoint(struct f2fs_sb_info *, bool, bool); 968 966 void init_orphan_info(struct f2fs_sb_info *); 969 - int create_checkpoint_caches(void); 967 + int __init create_checkpoint_caches(void); 970 968 void destroy_checkpoint_caches(void); 971 969 972 970 /* ··· 986 984 int start_gc_thread(struct f2fs_sb_info *); 987 985 void stop_gc_thread(struct f2fs_sb_info *); 988 986 block_t start_bidx_of_node(unsigned int); 989 - int f2fs_gc(struct f2fs_sb_info *, int); 987 + int f2fs_gc(struct f2fs_sb_info *); 990 988 void build_gc_manager(struct f2fs_sb_info *); 991 - int create_gc_caches(void); 989 + int __init create_gc_caches(void); 992 990 void destroy_gc_caches(void); 993 991 994 992 /* ··· 1060 1058 1061 1059 int f2fs_build_stats(struct f2fs_sb_info *); 1062 1060 void f2fs_destroy_stats(struct f2fs_sb_info *); 1063 - void destroy_root_stats(void); 1061 + void __init f2fs_create_root_stats(void); 1062 + void f2fs_destroy_root_stats(void); 1064 1063 #else 1065 1064 #define stat_inc_call_count(si) 1066 1065 #define stat_inc_seg_count(si, type) ··· 1071 1068 1072 1069 static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 1073 1070 static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 1074 - static inline void destroy_root_stats(void) { } 1071 + static inline void __init f2fs_create_root_stats(void) { } 1072 + static inline void f2fs_destroy_root_stats(void) { } 1075 1073 #endif 1076 1074 1077 1075 extern const struct file_operations f2fs_dir_operations;
+12 -4
fs/f2fs/file.c
··· 96 96 } 97 97 98 98 static const struct vm_operations_struct f2fs_file_vm_ops = { 99 - .fault = filemap_fault, 100 - .page_mkwrite = f2fs_vm_page_mkwrite, 99 + .fault = filemap_fault, 100 + .page_mkwrite = f2fs_vm_page_mkwrite, 101 + .remap_pages = generic_file_remap_pages, 101 102 }; 102 103 103 104 static int need_to_sync_dir(struct f2fs_sb_info *sbi, struct inode *inode) ··· 137 136 ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 138 137 if (ret) 139 138 return ret; 139 + 140 + /* guarantee free sections for fsync */ 141 + f2fs_balance_fs(sbi); 140 142 141 143 mutex_lock(&inode->i_mutex); 142 144 ··· 411 407 struct dnode_of_data dn; 412 408 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); 413 409 410 + f2fs_balance_fs(sbi); 411 + 414 412 mutex_lock_op(sbi, DATA_TRUNC); 415 413 set_new_dnode(&dn, inode, NULL, NULL, 0); 416 414 err = get_dnode_of_data(&dn, index, RDONLY_NODE); ··· 540 534 loff_t offset, loff_t len) 541 535 { 542 536 struct inode *inode = file->f_path.dentry->d_inode; 543 - struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); 544 537 long ret; 545 538 546 539 if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)) ··· 550 545 else 551 546 ret = expand_inode_data(inode, offset, len, mode); 552 547 553 - f2fs_balance_fs(sbi); 548 + if (!ret) { 549 + inode->i_mtime = inode->i_ctime = CURRENT_TIME; 550 + mark_inode_dirty(inode); 551 + } 554 552 return ret; 555 553 } 556 554
+27 -41
fs/f2fs/gc.c
··· 78 78 79 79 sbi->bg_gc++; 80 80 81 - if (f2fs_gc(sbi, 1) == GC_NONE) 81 + if (f2fs_gc(sbi) == GC_NONE) 82 82 wait_ms = GC_THREAD_NOGC_SLEEP_TIME; 83 83 else if (wait_ms == GC_THREAD_NOGC_SLEEP_TIME) 84 84 wait_ms = GC_THREAD_MAX_SLEEP_TIME; ··· 424 424 } 425 425 426 426 /* 427 - * Calculate start block index that this node page contains 427 + * Calculate start block index indicating the given node offset. 428 + * Be careful, caller should give this node offset only indicating direct node 429 + * blocks. If any node offsets, which point the other types of node blocks such 430 + * as indirect or double indirect node blocks, are given, it must be a caller's 431 + * bug. 428 432 */ 429 433 block_t start_bidx_of_node(unsigned int node_ofs) 430 434 { ··· 655 651 return ret; 656 652 } 657 653 658 - int f2fs_gc(struct f2fs_sb_info *sbi, int nGC) 654 + int f2fs_gc(struct f2fs_sb_info *sbi) 659 655 { 660 - unsigned int segno; 661 - int old_free_secs, cur_free_secs; 662 - int gc_status, nfree; 663 656 struct list_head ilist; 657 + unsigned int segno, i; 664 658 int gc_type = BG_GC; 659 + int gc_status = GC_NONE; 665 660 666 661 INIT_LIST_HEAD(&ilist); 667 662 gc_more: 668 - nfree = 0; 669 - gc_status = GC_NONE; 663 + if (!(sbi->sb->s_flags & MS_ACTIVE)) 664 + goto stop; 670 665 671 666 if (has_not_enough_free_secs(sbi)) 672 - old_free_secs = reserved_sections(sbi); 673 - else 674 - old_free_secs = free_sections(sbi); 667 + gc_type = FG_GC; 675 668 676 - while (sbi->sb->s_flags & MS_ACTIVE) { 677 - int i; 678 - if (has_not_enough_free_secs(sbi)) 679 - gc_type = FG_GC; 669 + if (!__get_victim(sbi, &segno, gc_type, NO_CHECK_TYPE)) 670 + goto stop; 680 671 681 - cur_free_secs = free_sections(sbi) + nfree; 682 - 683 - /* We got free space successfully. */ 684 - if (nGC < cur_free_secs - old_free_secs) 672 + for (i = 0; i < sbi->segs_per_sec; i++) { 673 + /* 674 + * do_garbage_collect will give us three gc_status: 675 + * GC_ERROR, GC_DONE, and GC_BLOCKED. 676 + * If GC is finished uncleanly, we have to return 677 + * the victim to dirty segment list. 678 + */ 679 + gc_status = do_garbage_collect(sbi, segno + i, &ilist, gc_type); 680 + if (gc_status != GC_DONE) 685 681 break; 686 - 687 - if (!__get_victim(sbi, &segno, gc_type, NO_CHECK_TYPE)) 688 - break; 689 - 690 - for (i = 0; i < sbi->segs_per_sec; i++) { 691 - /* 692 - * do_garbage_collect will give us three gc_status: 693 - * GC_ERROR, GC_DONE, and GC_BLOCKED. 694 - * If GC is finished uncleanly, we have to return 695 - * the victim to dirty segment list. 696 - */ 697 - gc_status = do_garbage_collect(sbi, segno + i, 698 - &ilist, gc_type); 699 - if (gc_status != GC_DONE) 700 - goto stop; 701 - nfree++; 702 - } 703 682 } 704 - stop: 705 - if (has_not_enough_free_secs(sbi) || gc_status == GC_BLOCKED) { 683 + if (has_not_enough_free_secs(sbi)) { 706 684 write_checkpoint(sbi, (gc_status == GC_BLOCKED), false); 707 - if (nfree) 685 + if (has_not_enough_free_secs(sbi)) 708 686 goto gc_more; 709 687 } 688 + stop: 710 689 mutex_unlock(&sbi->gc_mutex); 711 690 712 691 put_gc_inode(&ilist); 713 - BUG_ON(!list_empty(&ilist)); 714 692 return gc_status; 715 693 } 716 694 ··· 701 715 DIRTY_I(sbi)->v_ops = &default_v_ops; 702 716 } 703 717 704 - int create_gc_caches(void) 718 + int __init create_gc_caches(void) 705 719 { 706 720 winode_slab = f2fs_kmem_cache_create("f2fs_gc_inodes", 707 721 sizeof(struct inode_entry), NULL);
+3
fs/f2fs/inode.c
··· 217 217 inode->i_ino == F2FS_META_INO(sbi)) 218 218 return 0; 219 219 220 + if (wbc) 221 + f2fs_balance_fs(sbi); 222 + 220 223 node_page = get_node_page(sbi, inode->i_ino); 221 224 if (IS_ERR(node_page)) 222 225 return PTR_ERR(node_page);
+12 -7
fs/f2fs/node.c
··· 1124 1124 return 0; 1125 1125 } 1126 1126 1127 + /* 1128 + * It is very important to gather dirty pages and write at once, so that we can 1129 + * submit a big bio without interfering other data writes. 1130 + * Be default, 512 pages (2MB), a segment size, is quite reasonable. 1131 + */ 1132 + #define COLLECT_DIRTY_NODES 512 1127 1133 static int f2fs_write_node_pages(struct address_space *mapping, 1128 1134 struct writeback_control *wbc) 1129 1135 { ··· 1137 1131 struct block_device *bdev = sbi->sb->s_bdev; 1138 1132 long nr_to_write = wbc->nr_to_write; 1139 1133 1140 - if (wbc->for_kupdate) 1141 - return 0; 1142 - 1143 - if (get_pages(sbi, F2FS_DIRTY_NODES) == 0) 1144 - return 0; 1145 - 1134 + /* First check balancing cached NAT entries */ 1146 1135 if (try_to_free_nats(sbi, NAT_ENTRY_PER_BLOCK)) { 1147 1136 write_checkpoint(sbi, false, false); 1148 1137 return 0; 1149 1138 } 1139 + 1140 + /* collect a number of dirty node pages and write together */ 1141 + if (get_pages(sbi, F2FS_DIRTY_NODES) < COLLECT_DIRTY_NODES) 1142 + return 0; 1150 1143 1151 1144 /* if mounting is failed, skip writing node pages */ 1152 1145 wbc->nr_to_write = bio_get_nr_vecs(bdev); ··· 1737 1732 kfree(nm_i); 1738 1733 } 1739 1734 1740 - int create_node_manager_caches(void) 1735 + int __init create_node_manager_caches(void) 1741 1736 { 1742 1737 nat_entry_slab = f2fs_kmem_cache_create("nat_entry", 1743 1738 sizeof(struct nat_entry), NULL);
+4 -6
fs/f2fs/recovery.c
··· 67 67 kunmap(page); 68 68 f2fs_put_page(page, 0); 69 69 } else { 70 - f2fs_add_link(&dent, inode); 70 + err = f2fs_add_link(&dent, inode); 71 71 } 72 72 iput(dir); 73 73 out: ··· 151 151 goto out; 152 152 } 153 153 154 - INIT_LIST_HEAD(&entry->list); 155 154 list_add_tail(&entry->list, head); 156 155 entry->blkaddr = blkaddr; 157 156 } ··· 173 174 static void destroy_fsync_dnodes(struct f2fs_sb_info *sbi, 174 175 struct list_head *head) 175 176 { 176 - struct list_head *this; 177 - struct fsync_inode_entry *entry; 178 - list_for_each(this, head) { 179 - entry = list_entry(this, struct fsync_inode_entry, list); 177 + struct fsync_inode_entry *entry, *tmp; 178 + 179 + list_for_each_entry_safe(entry, tmp, head, list) { 180 180 iput(entry->inode); 181 181 list_del(&entry->list); 182 182 kmem_cache_free(fsync_entry_slab, entry);
+1 -1
fs/f2fs/segment.c
··· 31 31 */ 32 32 if (has_not_enough_free_secs(sbi)) { 33 33 mutex_lock(&sbi->gc_mutex); 34 - f2fs_gc(sbi, 1); 34 + f2fs_gc(sbi); 35 35 } 36 36 } 37 37
+72 -25
fs/f2fs/super.c
··· 53 53 {Opt_err, NULL}, 54 54 }; 55 55 56 + void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...) 57 + { 58 + struct va_format vaf; 59 + va_list args; 60 + 61 + va_start(args, fmt); 62 + vaf.fmt = fmt; 63 + vaf.va = &args; 64 + printk("%sF2FS-fs (%s): %pV\n", level, sb->s_id, &vaf); 65 + va_end(args); 66 + } 67 + 56 68 static void init_once(void *foo) 57 69 { 58 70 struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo; ··· 137 125 138 126 if (sync) 139 127 write_checkpoint(sbi, false, false); 128 + else 129 + f2fs_balance_fs(sbi); 140 130 141 131 return 0; 142 132 } ··· 261 247 .get_parent = f2fs_get_parent, 262 248 }; 263 249 264 - static int parse_options(struct f2fs_sb_info *sbi, char *options) 250 + static int parse_options(struct super_block *sb, struct f2fs_sb_info *sbi, 251 + char *options) 265 252 { 266 253 substring_t args[MAX_OPT_ARGS]; 267 254 char *p; ··· 301 286 break; 302 287 #else 303 288 case Opt_nouser_xattr: 304 - pr_info("nouser_xattr options not supported\n"); 289 + f2fs_msg(sb, KERN_INFO, 290 + "nouser_xattr options not supported"); 305 291 break; 306 292 #endif 307 293 #ifdef CONFIG_F2FS_FS_POSIX_ACL ··· 311 295 break; 312 296 #else 313 297 case Opt_noacl: 314 - pr_info("noacl options not supported\n"); 298 + f2fs_msg(sb, KERN_INFO, "noacl options not supported"); 315 299 break; 316 300 #endif 317 301 case Opt_active_logs: ··· 325 309 set_opt(sbi, DISABLE_EXT_IDENTIFY); 326 310 break; 327 311 default: 328 - pr_err("Unrecognized mount option \"%s\" or missing value\n", 329 - p); 312 + f2fs_msg(sb, KERN_ERR, 313 + "Unrecognized mount option \"%s\" or missing value", 314 + p); 330 315 return -EINVAL; 331 316 } 332 317 } ··· 354 337 return result; 355 338 } 356 339 357 - static int sanity_check_raw_super(struct f2fs_super_block *raw_super) 340 + static int sanity_check_raw_super(struct super_block *sb, 341 + struct f2fs_super_block *raw_super) 358 342 { 359 343 unsigned int blocksize; 360 344 361 - if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) 345 + if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) { 346 + f2fs_msg(sb, KERN_INFO, 347 + "Magic Mismatch, valid(0x%x) - read(0x%x)", 348 + F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic)); 362 349 return 1; 350 + } 363 351 364 352 /* Currently, support only 4KB block size */ 365 353 blocksize = 1 << le32_to_cpu(raw_super->log_blocksize); 366 - if (blocksize != PAGE_CACHE_SIZE) 354 + if (blocksize != PAGE_CACHE_SIZE) { 355 + f2fs_msg(sb, KERN_INFO, 356 + "Invalid blocksize (%u), supports only 4KB\n", 357 + blocksize); 367 358 return 1; 359 + } 368 360 if (le32_to_cpu(raw_super->log_sectorsize) != 369 - F2FS_LOG_SECTOR_SIZE) 361 + F2FS_LOG_SECTOR_SIZE) { 362 + f2fs_msg(sb, KERN_INFO, "Invalid log sectorsize"); 370 363 return 1; 364 + } 371 365 if (le32_to_cpu(raw_super->log_sectors_per_block) != 372 - F2FS_LOG_SECTORS_PER_BLOCK) 366 + F2FS_LOG_SECTORS_PER_BLOCK) { 367 + f2fs_msg(sb, KERN_INFO, "Invalid log sectors per block"); 373 368 return 1; 369 + } 374 370 return 0; 375 371 } 376 372 ··· 443 413 if (!sbi) 444 414 return -ENOMEM; 445 415 446 - /* set a temporary block size */ 447 - if (!sb_set_blocksize(sb, F2FS_BLKSIZE)) 416 + /* set a block size */ 417 + if (!sb_set_blocksize(sb, F2FS_BLKSIZE)) { 418 + f2fs_msg(sb, KERN_ERR, "unable to set blocksize"); 448 419 goto free_sbi; 420 + } 449 421 450 422 /* read f2fs raw super block */ 451 423 raw_super_buf = sb_bread(sb, 0); 452 424 if (!raw_super_buf) { 453 425 err = -EIO; 426 + f2fs_msg(sb, KERN_ERR, "unable to read superblock"); 454 427 goto free_sbi; 455 428 } 456 429 raw_super = (struct f2fs_super_block *) ··· 471 438 set_opt(sbi, POSIX_ACL); 472 439 #endif 473 440 /* parse mount options */ 474 - if (parse_options(sbi, (char *)data)) 441 + if (parse_options(sb, sbi, (char *)data)) 475 442 goto free_sb_buf; 476 443 477 444 /* sanity checking of raw super */ 478 - if (sanity_check_raw_super(raw_super)) 445 + if (sanity_check_raw_super(sb, raw_super)) { 446 + f2fs_msg(sb, KERN_ERR, "Can't find a valid F2FS filesystem"); 479 447 goto free_sb_buf; 448 + } 480 449 481 450 sb->s_maxbytes = max_file_size(le32_to_cpu(raw_super->log_blocksize)); 482 451 sb->s_max_links = F2FS_LINK_MAX; ··· 512 477 /* get an inode for meta space */ 513 478 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); 514 479 if (IS_ERR(sbi->meta_inode)) { 480 + f2fs_msg(sb, KERN_ERR, "Failed to read F2FS meta data inode"); 515 481 err = PTR_ERR(sbi->meta_inode); 516 482 goto free_sb_buf; 517 483 } 518 484 519 485 err = get_valid_checkpoint(sbi); 520 - if (err) 486 + if (err) { 487 + f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint"); 521 488 goto free_meta_inode; 489 + } 522 490 523 491 /* sanity checking of checkpoint */ 524 492 err = -EINVAL; 525 - if (sanity_check_ckpt(raw_super, sbi->ckpt)) 493 + if (sanity_check_ckpt(raw_super, sbi->ckpt)) { 494 + f2fs_msg(sb, KERN_ERR, "Invalid F2FS checkpoint"); 526 495 goto free_cp; 496 + } 527 497 528 498 sbi->total_valid_node_count = 529 499 le32_to_cpu(sbi->ckpt->valid_node_count); ··· 542 502 INIT_LIST_HEAD(&sbi->dir_inode_list); 543 503 spin_lock_init(&sbi->dir_inode_lock); 544 504 545 - /* init super block */ 546 - if (!sb_set_blocksize(sb, sbi->blocksize)) 547 - goto free_cp; 548 - 549 505 init_orphan_info(sbi); 550 506 551 507 /* setup f2fs internal modules */ 552 508 err = build_segment_manager(sbi); 553 - if (err) 509 + if (err) { 510 + f2fs_msg(sb, KERN_ERR, 511 + "Failed to initialize F2FS segment manager"); 554 512 goto free_sm; 513 + } 555 514 err = build_node_manager(sbi); 556 - if (err) 515 + if (err) { 516 + f2fs_msg(sb, KERN_ERR, 517 + "Failed to initialize F2FS node manager"); 557 518 goto free_nm; 519 + } 558 520 559 521 build_gc_manager(sbi); 560 522 561 523 /* get an inode for node space */ 562 524 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); 563 525 if (IS_ERR(sbi->node_inode)) { 526 + f2fs_msg(sb, KERN_ERR, "Failed to read node inode"); 564 527 err = PTR_ERR(sbi->node_inode); 565 528 goto free_nm; 566 529 } ··· 576 533 /* read root inode and dentry */ 577 534 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); 578 535 if (IS_ERR(root)) { 536 + f2fs_msg(sb, KERN_ERR, "Failed to read root inode"); 579 537 err = PTR_ERR(root); 580 538 goto free_node_inode; 581 539 } ··· 640 596 .fs_flags = FS_REQUIRES_DEV, 641 597 }; 642 598 643 - static int init_inodecache(void) 599 + static int __init init_inodecache(void) 644 600 { 645 601 f2fs_inode_cachep = f2fs_kmem_cache_create("f2fs_inode_cache", 646 602 sizeof(struct f2fs_inode_info), NULL); ··· 675 631 err = create_checkpoint_caches(); 676 632 if (err) 677 633 goto fail; 678 - return register_filesystem(&f2fs_fs_type); 634 + err = register_filesystem(&f2fs_fs_type); 635 + if (err) 636 + goto fail; 637 + f2fs_create_root_stats(); 679 638 fail: 680 639 return err; 681 640 } 682 641 683 642 static void __exit exit_f2fs_fs(void) 684 643 { 685 - destroy_root_stats(); 644 + f2fs_destroy_root_stats(); 686 645 unregister_filesystem(&f2fs_fs_type); 687 646 destroy_checkpoint_caches(); 688 647 destroy_gc_caches();
+2
fs/f2fs/xattr.c
··· 318 318 if (name_len > 255 || value_len > MAX_VALUE_LEN) 319 319 return -ERANGE; 320 320 321 + f2fs_balance_fs(sbi); 322 + 321 323 mutex_lock_op(sbi, NODE_NEW); 322 324 if (!fi->i_xattr_nid) { 323 325 /* Allocate new attribute block */