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

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

Pull f2fs updates from Jaegeuk Kim:
"This series adds two ioctls to control cached data and fragmented
files. Most of the rest fixes missing error cases and bugs that we
have not covered so far. Summary:

Enhancements:
- support an ioctl to execute online file defragmentation
- support an ioctl to flush cached data
- speed up shrinking of extent_cache entries
- handle broken superblock
- refector dirty inode management infra
- revisit f2fs_map_blocks to handle more cases
- reduce global lock coverage
- add detecting user's idle time

Major bug fixes:
- fix data race condition on cached nat entries
- fix error cases of volatile and atomic writes"

* tag 'for-f2fs-4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (87 commits)
f2fs: should unset atomic flag after successful commit
f2fs: fix wrong memory condition check
f2fs: monitor the number of background checkpoint
f2fs: detect idle time depending on user behavior
f2fs: introduce time and interval facility
f2fs: skip releasing nodes in chindless extent tree
f2fs: use atomic type for node count in extent tree
f2fs: recognize encrypted data in f2fs_fiemap
f2fs: clean up f2fs_balance_fs
f2fs: remove redundant calls
f2fs: avoid unnecessary f2fs_balance_fs calls
f2fs: check the page status filled from disk
f2fs: introduce __get_node_page to reuse common code
f2fs: check node id earily when readaheading node page
f2fs: read isize while holding i_mutex in fiemap
Revert "f2fs: check the node block address of newly allocated nid"
f2fs: cover more area with nat_tree_lock
f2fs: introduce max_file_blocks in sbi
f2fs crypto: check CONFIG_F2FS_FS_XATTR for encrypted symlink
f2fs: introduce zombie list for fast shrinking extent trees
...

+1271 -735
+6
Documentation/ABI/testing/sysfs-fs-f2fs
··· 87 87 Description: 88 88 Controls the checkpoint timing. 89 89 90 + What: /sys/fs/f2fs/<disk>/idle_interval 91 + Date: January 2016 92 + Contact: "Jaegeuk Kim" <jaegeuk@kernel.org> 93 + Description: 94 + Controls the idle timing. 95 + 90 96 What: /sys/fs/f2fs/<disk>/ra_nid_pages 91 97 Date: October 2015 92 98 Contact: "Chao Yu" <chao2.yu@samsung.com>
+6 -4
Documentation/filesystems/f2fs.txt
··· 102 102 collection, triggered in background when I/O subsystem is 103 103 idle. If background_gc=on, it will turn on the garbage 104 104 collection and if background_gc=off, garbage collection 105 - will be truned off. If background_gc=sync, it will turn 105 + will be turned off. If background_gc=sync, it will turn 106 106 on synchronous garbage collection running in background. 107 107 Default value for this option is on. So garbage 108 108 collection is on by default. ··· 145 145 as many as extent which map between contiguous logical 146 146 address and physical address per inode, resulting in 147 147 increasing the cache hit ratio. Set by default. 148 - noextent_cache Diable an extent cache based on rb-tree explicitly, see 148 + noextent_cache Disable an extent cache based on rb-tree explicitly, see 149 149 the above extent_cache mount option. 150 150 noinline_data Disable the inline data feature, inline data feature is 151 151 enabled by default. 152 + data_flush Enable data flushing before checkpoint in order to 153 + persist data of regular and symlink. 152 154 153 155 ================================================================================ 154 156 DEBUGFS ENTRIES ··· 194 192 policy for garbage collection. Setting gc_idle = 0 195 193 (default) will disable this option. Setting 196 194 gc_idle = 1 will select the Cost Benefit approach 197 - & setting gc_idle = 2 will select the greedy aproach. 195 + & setting gc_idle = 2 will select the greedy approach. 198 196 199 197 reclaim_segments This parameter controls the number of prefree 200 198 segments to be reclaimed. If the number of prefree ··· 300 298 file. Each file is dump_ssa and dump_sit. 301 299 302 300 The dump.f2fs is used to debug on-disk data structures of the f2fs filesystem. 303 - It shows on-disk inode information reconized by a given inode number, and is 301 + It shows on-disk inode information recognized by a given inode number, and is 304 302 able to dump all the SSA and SIT entries into predefined files, ./dump_ssa and 305 303 ./dump_sit respectively. 306 304
+87 -90
fs/f2fs/checkpoint.c
··· 237 237 dec_page_count(sbi, F2FS_DIRTY_META); 238 238 unlock_page(page); 239 239 240 - if (wbc->for_reclaim) 240 + if (wbc->for_reclaim || unlikely(f2fs_cp_error(sbi))) 241 241 f2fs_submit_merged_bio(sbi, META, WRITE); 242 242 return 0; 243 243 ··· 410 410 spin_unlock(&im->ino_lock); 411 411 } 412 412 413 - void add_dirty_inode(struct f2fs_sb_info *sbi, nid_t ino, int type) 413 + void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) 414 414 { 415 415 /* add new dirty ino entry into list */ 416 416 __add_ino_entry(sbi, ino, type); 417 417 } 418 418 419 - void remove_dirty_inode(struct f2fs_sb_info *sbi, nid_t ino, int type) 419 + void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) 420 420 { 421 421 /* remove dirty ino entry from list */ 422 422 __remove_ino_entry(sbi, ino, type); ··· 434 434 return e ? true : false; 435 435 } 436 436 437 - void release_dirty_inode(struct f2fs_sb_info *sbi) 437 + void release_ino_entry(struct f2fs_sb_info *sbi) 438 438 { 439 439 struct ino_entry *e, *tmp; 440 440 int i; ··· 722 722 return -EINVAL; 723 723 } 724 724 725 - static int __add_dirty_inode(struct inode *inode, struct inode_entry *new) 725 + static void __add_dirty_inode(struct inode *inode, enum inode_type type) 726 726 { 727 727 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 728 + struct f2fs_inode_info *fi = F2FS_I(inode); 729 + int flag = (type == DIR_INODE) ? FI_DIRTY_DIR : FI_DIRTY_FILE; 728 730 729 - if (is_inode_flag_set(F2FS_I(inode), FI_DIRTY_DIR)) 730 - return -EEXIST; 731 + if (is_inode_flag_set(fi, flag)) 732 + return; 731 733 732 - set_inode_flag(F2FS_I(inode), FI_DIRTY_DIR); 733 - F2FS_I(inode)->dirty_dir = new; 734 - list_add_tail(&new->list, &sbi->dir_inode_list); 735 - stat_inc_dirty_dir(sbi); 736 - return 0; 734 + set_inode_flag(fi, flag); 735 + list_add_tail(&fi->dirty_list, &sbi->inode_list[type]); 736 + stat_inc_dirty_inode(sbi, type); 737 + } 738 + 739 + static void __remove_dirty_inode(struct inode *inode, enum inode_type type) 740 + { 741 + struct f2fs_inode_info *fi = F2FS_I(inode); 742 + int flag = (type == DIR_INODE) ? FI_DIRTY_DIR : FI_DIRTY_FILE; 743 + 744 + if (get_dirty_pages(inode) || 745 + !is_inode_flag_set(F2FS_I(inode), flag)) 746 + return; 747 + 748 + list_del_init(&fi->dirty_list); 749 + clear_inode_flag(fi, flag); 750 + stat_dec_dirty_inode(F2FS_I_SB(inode), type); 737 751 } 738 752 739 753 void update_dirty_page(struct inode *inode, struct page *page) 740 754 { 741 755 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 742 - struct inode_entry *new; 743 - int ret = 0; 756 + enum inode_type type = S_ISDIR(inode->i_mode) ? DIR_INODE : FILE_INODE; 744 757 745 758 if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 746 759 !S_ISLNK(inode->i_mode)) 747 760 return; 748 761 749 - if (!S_ISDIR(inode->i_mode)) { 750 - inode_inc_dirty_pages(inode); 751 - goto out; 752 - } 753 - 754 - new = f2fs_kmem_cache_alloc(inode_entry_slab, GFP_NOFS); 755 - new->inode = inode; 756 - INIT_LIST_HEAD(&new->list); 757 - 758 - spin_lock(&sbi->dir_inode_lock); 759 - ret = __add_dirty_inode(inode, new); 762 + spin_lock(&sbi->inode_lock[type]); 763 + __add_dirty_inode(inode, type); 760 764 inode_inc_dirty_pages(inode); 761 - spin_unlock(&sbi->dir_inode_lock); 765 + spin_unlock(&sbi->inode_lock[type]); 762 766 763 - if (ret) 764 - kmem_cache_free(inode_entry_slab, new); 765 - out: 766 767 SetPagePrivate(page); 767 768 f2fs_trace_pid(page); 768 769 } ··· 771 770 void add_dirty_dir_inode(struct inode *inode) 772 771 { 773 772 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 774 - struct inode_entry *new = 775 - f2fs_kmem_cache_alloc(inode_entry_slab, GFP_NOFS); 776 - int ret = 0; 777 773 778 - new->inode = inode; 779 - INIT_LIST_HEAD(&new->list); 780 - 781 - spin_lock(&sbi->dir_inode_lock); 782 - ret = __add_dirty_inode(inode, new); 783 - spin_unlock(&sbi->dir_inode_lock); 784 - 785 - if (ret) 786 - kmem_cache_free(inode_entry_slab, new); 774 + spin_lock(&sbi->inode_lock[DIR_INODE]); 775 + __add_dirty_inode(inode, DIR_INODE); 776 + spin_unlock(&sbi->inode_lock[DIR_INODE]); 787 777 } 788 778 789 - void remove_dirty_dir_inode(struct inode *inode) 779 + void remove_dirty_inode(struct inode *inode) 790 780 { 791 781 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 792 - struct inode_entry *entry; 782 + struct f2fs_inode_info *fi = F2FS_I(inode); 783 + enum inode_type type = S_ISDIR(inode->i_mode) ? DIR_INODE : FILE_INODE; 793 784 794 - if (!S_ISDIR(inode->i_mode)) 785 + if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 786 + !S_ISLNK(inode->i_mode)) 795 787 return; 796 788 797 - spin_lock(&sbi->dir_inode_lock); 798 - if (get_dirty_pages(inode) || 799 - !is_inode_flag_set(F2FS_I(inode), FI_DIRTY_DIR)) { 800 - spin_unlock(&sbi->dir_inode_lock); 801 - return; 802 - } 803 - 804 - entry = F2FS_I(inode)->dirty_dir; 805 - list_del(&entry->list); 806 - F2FS_I(inode)->dirty_dir = NULL; 807 - clear_inode_flag(F2FS_I(inode), FI_DIRTY_DIR); 808 - stat_dec_dirty_dir(sbi); 809 - spin_unlock(&sbi->dir_inode_lock); 810 - kmem_cache_free(inode_entry_slab, entry); 789 + spin_lock(&sbi->inode_lock[type]); 790 + __remove_dirty_inode(inode, type); 791 + spin_unlock(&sbi->inode_lock[type]); 811 792 812 793 /* Only from the recovery routine */ 813 - if (is_inode_flag_set(F2FS_I(inode), FI_DELAY_IPUT)) { 814 - clear_inode_flag(F2FS_I(inode), FI_DELAY_IPUT); 794 + if (is_inode_flag_set(fi, FI_DELAY_IPUT)) { 795 + clear_inode_flag(fi, FI_DELAY_IPUT); 815 796 iput(inode); 816 797 } 817 798 } 818 799 819 - void sync_dirty_dir_inodes(struct f2fs_sb_info *sbi) 800 + int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type) 820 801 { 821 802 struct list_head *head; 822 - struct inode_entry *entry; 823 803 struct inode *inode; 804 + struct f2fs_inode_info *fi; 805 + bool is_dir = (type == DIR_INODE); 806 + 807 + trace_f2fs_sync_dirty_inodes_enter(sbi->sb, is_dir, 808 + get_pages(sbi, is_dir ? 809 + F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA)); 824 810 retry: 825 811 if (unlikely(f2fs_cp_error(sbi))) 826 - return; 812 + return -EIO; 827 813 828 - spin_lock(&sbi->dir_inode_lock); 814 + spin_lock(&sbi->inode_lock[type]); 829 815 830 - head = &sbi->dir_inode_list; 816 + head = &sbi->inode_list[type]; 831 817 if (list_empty(head)) { 832 - spin_unlock(&sbi->dir_inode_lock); 833 - return; 818 + spin_unlock(&sbi->inode_lock[type]); 819 + trace_f2fs_sync_dirty_inodes_exit(sbi->sb, is_dir, 820 + get_pages(sbi, is_dir ? 821 + F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA)); 822 + return 0; 834 823 } 835 - entry = list_entry(head->next, struct inode_entry, list); 836 - inode = igrab(entry->inode); 837 - spin_unlock(&sbi->dir_inode_lock); 824 + fi = list_entry(head->next, struct f2fs_inode_info, dirty_list); 825 + inode = igrab(&fi->vfs_inode); 826 + spin_unlock(&sbi->inode_lock[type]); 838 827 if (inode) { 839 828 filemap_fdatawrite(inode->i_mapping); 840 829 iput(inode); ··· 859 868 /* write all the dirty dentry pages */ 860 869 if (get_pages(sbi, F2FS_DIRTY_DENTS)) { 861 870 f2fs_unlock_all(sbi); 862 - sync_dirty_dir_inodes(sbi); 863 - if (unlikely(f2fs_cp_error(sbi))) { 864 - err = -EIO; 871 + err = sync_dirty_inodes(sbi, DIR_INODE); 872 + if (err) 865 873 goto out; 866 - } 867 874 goto retry_flush_dents; 868 875 } 869 876 ··· 874 885 875 886 if (get_pages(sbi, F2FS_DIRTY_NODES)) { 876 887 up_write(&sbi->node_write); 877 - sync_node_pages(sbi, 0, &wbc); 878 - if (unlikely(f2fs_cp_error(sbi))) { 888 + err = sync_node_pages(sbi, 0, &wbc); 889 + if (err) { 879 890 f2fs_unlock_all(sbi); 880 - err = -EIO; 881 891 goto out; 882 892 } 883 893 goto retry_flush_nodes; ··· 907 919 finish_wait(&sbi->cp_wait, &wait); 908 920 } 909 921 910 - static void do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) 922 + static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) 911 923 { 912 924 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 913 925 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_WARM_NODE); ··· 933 945 while (get_pages(sbi, F2FS_DIRTY_META)) { 934 946 sync_meta_pages(sbi, META, LONG_MAX); 935 947 if (unlikely(f2fs_cp_error(sbi))) 936 - return; 948 + return -EIO; 937 949 } 938 950 939 951 next_free_nid(sbi, &last_nid); ··· 1018 1030 /* need to wait for end_io results */ 1019 1031 wait_on_all_pages_writeback(sbi); 1020 1032 if (unlikely(f2fs_cp_error(sbi))) 1021 - return; 1033 + return -EIO; 1022 1034 1023 1035 /* write out checkpoint buffer at block 0 */ 1024 1036 update_meta_page(sbi, ckpt, start_blk++); ··· 1046 1058 wait_on_all_pages_writeback(sbi); 1047 1059 1048 1060 if (unlikely(f2fs_cp_error(sbi))) 1049 - return; 1061 + return -EIO; 1050 1062 1051 1063 filemap_fdatawait_range(NODE_MAPPING(sbi), 0, LONG_MAX); 1052 1064 filemap_fdatawait_range(META_MAPPING(sbi), 0, LONG_MAX); ··· 1069 1081 invalidate_mapping_pages(META_MAPPING(sbi), discard_blk, 1070 1082 discard_blk); 1071 1083 1072 - release_dirty_inode(sbi); 1084 + release_ino_entry(sbi); 1073 1085 1074 1086 if (unlikely(f2fs_cp_error(sbi))) 1075 - return; 1087 + return -EIO; 1076 1088 1077 1089 clear_prefree_segments(sbi, cpc); 1078 1090 clear_sbi_flag(sbi, SBI_IS_DIRTY); 1091 + 1092 + return 0; 1079 1093 } 1080 1094 1081 1095 /* 1082 1096 * We guarantee that this checkpoint procedure will not fail. 1083 1097 */ 1084 - void write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) 1098 + int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) 1085 1099 { 1086 1100 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1087 1101 unsigned long long ckpt_ver; 1102 + int err = 0; 1088 1103 1089 1104 mutex_lock(&sbi->cp_mutex); 1090 1105 ··· 1095 1104 (cpc->reason == CP_FASTBOOT || cpc->reason == CP_SYNC || 1096 1105 (cpc->reason == CP_DISCARD && !sbi->discard_blks))) 1097 1106 goto out; 1098 - if (unlikely(f2fs_cp_error(sbi))) 1107 + if (unlikely(f2fs_cp_error(sbi))) { 1108 + err = -EIO; 1099 1109 goto out; 1100 - if (f2fs_readonly(sbi->sb)) 1110 + } 1111 + if (f2fs_readonly(sbi->sb)) { 1112 + err = -EROFS; 1101 1113 goto out; 1114 + } 1102 1115 1103 1116 trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "start block_ops"); 1104 1117 1105 - if (block_operations(sbi)) 1118 + err = block_operations(sbi); 1119 + if (err) 1106 1120 goto out; 1107 1121 1108 1122 trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish block_ops"); ··· 1129 1133 flush_sit_entries(sbi, cpc); 1130 1134 1131 1135 /* unlock all the fs_lock[] in do_checkpoint() */ 1132 - do_checkpoint(sbi, cpc); 1136 + err = do_checkpoint(sbi, cpc); 1133 1137 1134 1138 unblock_operations(sbi); 1135 1139 stat_inc_cp_count(sbi->stat_info); ··· 1139 1143 "checkpoint: version = %llx", ckpt_ver); 1140 1144 1141 1145 /* do checkpoint periodically */ 1142 - sbi->cp_expires = round_jiffies_up(jiffies + HZ * sbi->cp_interval); 1146 + f2fs_update_time(sbi, CP_TIME); 1147 + trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish checkpoint"); 1143 1148 out: 1144 1149 mutex_unlock(&sbi->cp_mutex); 1145 - trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish checkpoint"); 1150 + return err; 1146 1151 } 1147 1152 1148 1153 void init_ino_entry_info(struct f2fs_sb_info *sbi)
+221 -168
fs/f2fs/data.c
··· 225 225 /* Get physical address of data block */ 226 226 addr_array = blkaddr_in_node(rn); 227 227 addr_array[ofs_in_node] = cpu_to_le32(dn->data_blkaddr); 228 - set_page_dirty(node_page); 228 + if (set_page_dirty(node_page)) 229 + dn->node_changed = true; 229 230 } 230 231 231 232 int reserve_new_block(struct dnode_of_data *dn) ··· 413 412 struct page *page; 414 413 struct dnode_of_data dn; 415 414 int err; 416 - repeat: 415 + 417 416 page = f2fs_grab_cache_page(mapping, index, true); 418 417 if (!page) { 419 418 /* ··· 442 441 } else { 443 442 f2fs_put_page(page, 1); 444 443 445 - page = get_read_data_page(inode, index, READ_SYNC, true); 444 + /* if ipage exists, blkaddr should be NEW_ADDR */ 445 + f2fs_bug_on(F2FS_I_SB(inode), ipage); 446 + page = get_lock_data_page(inode, index, true); 446 447 if (IS_ERR(page)) 447 - goto repeat; 448 - 449 - /* wait for read completion */ 450 - lock_page(page); 448 + return page; 451 449 } 452 450 got_it: 453 451 if (new_i_size && i_size_read(inode) < ··· 494 494 if (i_size_read(dn->inode) < ((loff_t)(fofs + 1) << PAGE_CACHE_SHIFT)) 495 495 i_size_write(dn->inode, 496 496 ((loff_t)(fofs + 1) << PAGE_CACHE_SHIFT)); 497 - 498 - /* direct IO doesn't use extent cache to maximize the performance */ 499 - f2fs_drop_largest_extent(dn->inode, fofs); 500 - 501 497 return 0; 502 498 } 503 499 504 - static void __allocate_data_blocks(struct inode *inode, loff_t offset, 500 + static int __allocate_data_blocks(struct inode *inode, loff_t offset, 505 501 size_t count) 506 502 { 507 503 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); ··· 506 510 u64 len = F2FS_BYTES_TO_BLK(count); 507 511 bool allocated; 508 512 u64 end_offset; 513 + int err = 0; 509 514 510 515 while (len) { 511 - f2fs_balance_fs(sbi); 512 516 f2fs_lock_op(sbi); 513 517 514 518 /* When reading holes, we need its node page */ 515 519 set_new_dnode(&dn, inode, NULL, NULL, 0); 516 - if (get_dnode_of_data(&dn, start, ALLOC_NODE)) 520 + err = get_dnode_of_data(&dn, start, ALLOC_NODE); 521 + if (err) 517 522 goto out; 518 523 519 524 allocated = false; ··· 523 526 while (dn.ofs_in_node < end_offset && len) { 524 527 block_t blkaddr; 525 528 526 - if (unlikely(f2fs_cp_error(sbi))) 529 + if (unlikely(f2fs_cp_error(sbi))) { 530 + err = -EIO; 527 531 goto sync_out; 532 + } 528 533 529 534 blkaddr = datablock_addr(dn.node_page, dn.ofs_in_node); 530 535 if (blkaddr == NULL_ADDR || blkaddr == NEW_ADDR) { 531 - if (__allocate_data_block(&dn)) 536 + err = __allocate_data_block(&dn); 537 + if (err) 532 538 goto sync_out; 533 539 allocated = true; 534 540 } ··· 545 545 546 546 f2fs_put_dnode(&dn); 547 547 f2fs_unlock_op(sbi); 548 + 549 + f2fs_balance_fs(sbi, dn.node_changed); 548 550 } 549 - return; 551 + return err; 550 552 551 553 sync_out: 552 554 if (allocated) ··· 556 554 f2fs_put_dnode(&dn); 557 555 out: 558 556 f2fs_unlock_op(sbi); 559 - return; 557 + f2fs_balance_fs(sbi, dn.node_changed); 558 + return err; 560 559 } 561 560 562 561 /* ··· 569 566 * b. do not use extent cache for better performance 570 567 * c. give the block addresses to blockdev 571 568 */ 572 - static int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 569 + int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 573 570 int create, int flag) 574 571 { 575 572 unsigned int maxblocks = map->m_len; ··· 580 577 int err = 0, ofs = 1; 581 578 struct extent_info ei; 582 579 bool allocated = false; 580 + block_t blkaddr; 583 581 584 582 map->m_len = 0; 585 583 map->m_flags = 0; ··· 596 592 } 597 593 598 594 if (create) 599 - f2fs_lock_op(F2FS_I_SB(inode)); 595 + f2fs_lock_op(sbi); 600 596 601 597 /* When reading holes, we need its node page */ 602 598 set_new_dnode(&dn, inode, NULL, NULL, 0); ··· 644 640 pgofs++; 645 641 646 642 get_next: 643 + if (map->m_len >= maxblocks) 644 + goto sync_out; 645 + 647 646 if (dn.ofs_in_node >= end_offset) { 648 647 if (allocated) 649 648 sync_inode_page(&dn); 650 649 allocated = false; 651 650 f2fs_put_dnode(&dn); 651 + 652 + if (create) { 653 + f2fs_unlock_op(sbi); 654 + f2fs_balance_fs(sbi, dn.node_changed); 655 + f2fs_lock_op(sbi); 656 + } 652 657 653 658 set_new_dnode(&dn, inode, NULL, NULL, 0); 654 659 err = get_dnode_of_data(&dn, pgofs, mode); ··· 670 657 end_offset = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode)); 671 658 } 672 659 673 - if (maxblocks > map->m_len) { 674 - block_t blkaddr = datablock_addr(dn.node_page, dn.ofs_in_node); 660 + blkaddr = datablock_addr(dn.node_page, dn.ofs_in_node); 675 661 676 - if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) { 677 - if (create) { 678 - if (unlikely(f2fs_cp_error(sbi))) { 679 - err = -EIO; 680 - goto sync_out; 681 - } 682 - err = __allocate_data_block(&dn); 683 - if (err) 684 - goto sync_out; 685 - allocated = true; 686 - map->m_flags |= F2FS_MAP_NEW; 687 - blkaddr = dn.data_blkaddr; 688 - } else { 689 - /* 690 - * we only merge preallocated unwritten blocks 691 - * for fiemap. 692 - */ 693 - if (flag != F2FS_GET_BLOCK_FIEMAP || 694 - blkaddr != NEW_ADDR) 695 - goto sync_out; 662 + if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) { 663 + if (create) { 664 + if (unlikely(f2fs_cp_error(sbi))) { 665 + err = -EIO; 666 + goto sync_out; 696 667 } 697 - } 698 - 699 - /* Give more consecutive addresses for the readahead */ 700 - if ((map->m_pblk != NEW_ADDR && 701 - blkaddr == (map->m_pblk + ofs)) || 702 - (map->m_pblk == NEW_ADDR && 703 - blkaddr == NEW_ADDR)) { 704 - ofs++; 705 - dn.ofs_in_node++; 706 - pgofs++; 707 - map->m_len++; 708 - goto get_next; 668 + err = __allocate_data_block(&dn); 669 + if (err) 670 + goto sync_out; 671 + allocated = true; 672 + map->m_flags |= F2FS_MAP_NEW; 673 + blkaddr = dn.data_blkaddr; 674 + } else { 675 + /* 676 + * we only merge preallocated unwritten blocks 677 + * for fiemap. 678 + */ 679 + if (flag != F2FS_GET_BLOCK_FIEMAP || 680 + blkaddr != NEW_ADDR) 681 + goto sync_out; 709 682 } 710 683 } 684 + 685 + /* Give more consecutive addresses for the readahead */ 686 + if ((map->m_pblk != NEW_ADDR && 687 + blkaddr == (map->m_pblk + ofs)) || 688 + (map->m_pblk == NEW_ADDR && 689 + blkaddr == NEW_ADDR)) { 690 + ofs++; 691 + dn.ofs_in_node++; 692 + pgofs++; 693 + map->m_len++; 694 + goto get_next; 695 + } 696 + 711 697 sync_out: 712 698 if (allocated) 713 699 sync_inode_page(&dn); 714 700 put_out: 715 701 f2fs_put_dnode(&dn); 716 702 unlock_out: 717 - if (create) 718 - f2fs_unlock_op(F2FS_I_SB(inode)); 703 + if (create) { 704 + f2fs_unlock_op(sbi); 705 + f2fs_balance_fs(sbi, dn.node_changed); 706 + } 719 707 out: 720 708 trace_f2fs_map_blocks(inode, map, err); 721 709 return err; ··· 756 742 static int get_data_block_bmap(struct inode *inode, sector_t iblock, 757 743 struct buffer_head *bh_result, int create) 758 744 { 745 + /* Block number less than F2FS MAX BLOCKS */ 746 + if (unlikely(iblock >= F2FS_I_SB(inode)->max_file_blocks)) 747 + return -EFBIG; 748 + 759 749 return __get_data_block(inode, iblock, bh_result, create, 760 750 F2FS_GET_BLOCK_BMAP); 761 751 } ··· 779 761 { 780 762 struct buffer_head map_bh; 781 763 sector_t start_blk, last_blk; 782 - loff_t isize = i_size_read(inode); 764 + loff_t isize; 783 765 u64 logical = 0, phys = 0, size = 0; 784 766 u32 flags = 0; 785 - bool past_eof = false, whole_file = false; 786 767 int ret = 0; 787 768 788 769 ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC); ··· 796 779 797 780 mutex_lock(&inode->i_mutex); 798 781 799 - if (len >= isize) { 800 - whole_file = true; 801 - len = isize; 802 - } 782 + isize = i_size_read(inode); 783 + if (start >= isize) 784 + goto out; 785 + 786 + if (start + len > isize) 787 + len = isize - start; 803 788 804 789 if (logical_to_blk(inode, len) == 0) 805 790 len = blk_to_logical(inode, 1); 806 791 807 792 start_blk = logical_to_blk(inode, start); 808 793 last_blk = logical_to_blk(inode, start + len - 1); 794 + 809 795 next: 810 796 memset(&map_bh, 0, sizeof(struct buffer_head)); 811 797 map_bh.b_size = len; ··· 820 800 821 801 /* HOLE */ 822 802 if (!buffer_mapped(&map_bh)) { 823 - start_blk++; 824 - 825 - if (!past_eof && blk_to_logical(inode, start_blk) >= isize) 826 - past_eof = 1; 827 - 828 - if (past_eof && size) { 829 - flags |= FIEMAP_EXTENT_LAST; 830 - ret = fiemap_fill_next_extent(fieinfo, logical, 831 - phys, size, flags); 832 - } else if (size) { 833 - ret = fiemap_fill_next_extent(fieinfo, logical, 834 - phys, size, flags); 835 - size = 0; 836 - } 837 - 838 - /* if we have holes up to/past EOF then we're done */ 839 - if (start_blk > last_blk || past_eof || ret) 840 - goto out; 841 - } else { 842 - if (start_blk > last_blk && !whole_file) { 843 - ret = fiemap_fill_next_extent(fieinfo, logical, 844 - phys, size, flags); 845 - goto out; 846 - } 847 - 848 - /* 849 - * if size != 0 then we know we already have an extent 850 - * to add, so add it. 803 + /* Go through holes util pass the EOF */ 804 + if (blk_to_logical(inode, start_blk++) < isize) 805 + goto prep_next; 806 + /* Found a hole beyond isize means no more extents. 807 + * Note that the premise is that filesystems don't 808 + * punch holes beyond isize and keep size unchanged. 851 809 */ 852 - if (size) { 853 - ret = fiemap_fill_next_extent(fieinfo, logical, 854 - phys, size, flags); 855 - if (ret) 856 - goto out; 857 - } 858 - 859 - logical = blk_to_logical(inode, start_blk); 860 - phys = blk_to_logical(inode, map_bh.b_blocknr); 861 - size = map_bh.b_size; 862 - flags = 0; 863 - if (buffer_unwritten(&map_bh)) 864 - flags = FIEMAP_EXTENT_UNWRITTEN; 865 - 866 - start_blk += logical_to_blk(inode, size); 867 - 868 - /* 869 - * If we are past the EOF, then we need to make sure as 870 - * soon as we find a hole that the last extent we found 871 - * is marked with FIEMAP_EXTENT_LAST 872 - */ 873 - if (!past_eof && logical + size >= isize) 874 - past_eof = true; 810 + flags |= FIEMAP_EXTENT_LAST; 875 811 } 812 + 813 + if (size) { 814 + if (f2fs_encrypted_inode(inode)) 815 + flags |= FIEMAP_EXTENT_DATA_ENCRYPTED; 816 + 817 + ret = fiemap_fill_next_extent(fieinfo, logical, 818 + phys, size, flags); 819 + } 820 + 821 + if (start_blk > last_blk || ret) 822 + goto out; 823 + 824 + logical = blk_to_logical(inode, start_blk); 825 + phys = blk_to_logical(inode, map_bh.b_blocknr); 826 + size = map_bh.b_size; 827 + flags = 0; 828 + if (buffer_unwritten(&map_bh)) 829 + flags = FIEMAP_EXTENT_UNWRITTEN; 830 + 831 + start_blk += logical_to_blk(inode, size); 832 + 833 + prep_next: 876 834 cond_resched(); 877 835 if (fatal_signal_pending(current)) 878 836 ret = -EINTR; ··· 1081 1083 */ 1082 1084 if (unlikely(fio->blk_addr != NEW_ADDR && 1083 1085 !is_cold_data(page) && 1086 + !IS_ATOMIC_WRITTEN_PAGE(page) && 1084 1087 need_inplace_update(inode))) { 1085 1088 rewrite_data_page(fio); 1086 1089 set_inode_flag(F2FS_I(inode), FI_UPDATE_WRITE); ··· 1178 1179 if (err) 1179 1180 ClearPageUptodate(page); 1180 1181 unlock_page(page); 1181 - if (need_balance_fs) 1182 - f2fs_balance_fs(sbi); 1183 - if (wbc->for_reclaim) 1182 + f2fs_balance_fs(sbi, need_balance_fs); 1183 + if (wbc->for_reclaim || unlikely(f2fs_cp_error(sbi))) { 1184 1184 f2fs_submit_merged_bio(sbi, DATA, WRITE); 1185 + remove_dirty_inode(inode); 1186 + } 1185 1187 return 0; 1186 1188 1187 1189 redirty_out: ··· 1354 1354 available_free_memory(sbi, DIRTY_DENTS)) 1355 1355 goto skip_write; 1356 1356 1357 + /* skip writing during file defragment */ 1358 + if (is_inode_flag_set(F2FS_I(inode), FI_DO_DEFRAG)) 1359 + goto skip_write; 1360 + 1357 1361 /* during POR, we don't need to trigger writepage at all. */ 1358 1362 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) 1359 1363 goto skip_write; ··· 1373 1369 if (locked) 1374 1370 mutex_unlock(&sbi->writepages); 1375 1371 1376 - remove_dirty_dir_inode(inode); 1372 + remove_dirty_inode(inode); 1377 1373 1378 1374 wbc->nr_to_write = max((long)0, wbc->nr_to_write - diff); 1379 1375 return ret; ··· 1386 1382 static void f2fs_write_failed(struct address_space *mapping, loff_t to) 1387 1383 { 1388 1384 struct inode *inode = mapping->host; 1385 + loff_t i_size = i_size_read(inode); 1389 1386 1390 - if (to > inode->i_size) { 1391 - truncate_pagecache(inode, inode->i_size); 1392 - truncate_blocks(inode, inode->i_size, true); 1387 + if (to > i_size) { 1388 + truncate_pagecache(inode, i_size); 1389 + truncate_blocks(inode, i_size, true); 1393 1390 } 1391 + } 1392 + 1393 + static int prepare_write_begin(struct f2fs_sb_info *sbi, 1394 + struct page *page, loff_t pos, unsigned len, 1395 + block_t *blk_addr, bool *node_changed) 1396 + { 1397 + struct inode *inode = page->mapping->host; 1398 + pgoff_t index = page->index; 1399 + struct dnode_of_data dn; 1400 + struct page *ipage; 1401 + bool locked = false; 1402 + struct extent_info ei; 1403 + int err = 0; 1404 + 1405 + if (f2fs_has_inline_data(inode) || 1406 + (pos & PAGE_CACHE_MASK) >= i_size_read(inode)) { 1407 + f2fs_lock_op(sbi); 1408 + locked = true; 1409 + } 1410 + restart: 1411 + /* check inline_data */ 1412 + ipage = get_node_page(sbi, inode->i_ino); 1413 + if (IS_ERR(ipage)) { 1414 + err = PTR_ERR(ipage); 1415 + goto unlock_out; 1416 + } 1417 + 1418 + set_new_dnode(&dn, inode, ipage, ipage, 0); 1419 + 1420 + if (f2fs_has_inline_data(inode)) { 1421 + if (pos + len <= MAX_INLINE_DATA) { 1422 + read_inline_data(page, ipage); 1423 + set_inode_flag(F2FS_I(inode), FI_DATA_EXIST); 1424 + sync_inode_page(&dn); 1425 + } else { 1426 + err = f2fs_convert_inline_page(&dn, page); 1427 + if (err) 1428 + goto out; 1429 + if (dn.data_blkaddr == NULL_ADDR) 1430 + err = f2fs_get_block(&dn, index); 1431 + } 1432 + } else if (locked) { 1433 + err = f2fs_get_block(&dn, index); 1434 + } else { 1435 + if (f2fs_lookup_extent_cache(inode, index, &ei)) { 1436 + dn.data_blkaddr = ei.blk + index - ei.fofs; 1437 + } else { 1438 + bool restart = false; 1439 + 1440 + /* hole case */ 1441 + err = get_dnode_of_data(&dn, index, LOOKUP_NODE); 1442 + if (err || (!err && dn.data_blkaddr == NULL_ADDR)) 1443 + restart = true; 1444 + if (restart) { 1445 + f2fs_put_dnode(&dn); 1446 + f2fs_lock_op(sbi); 1447 + locked = true; 1448 + goto restart; 1449 + } 1450 + } 1451 + } 1452 + 1453 + /* convert_inline_page can make node_changed */ 1454 + *blk_addr = dn.data_blkaddr; 1455 + *node_changed = dn.node_changed; 1456 + out: 1457 + f2fs_put_dnode(&dn); 1458 + unlock_out: 1459 + if (locked) 1460 + f2fs_unlock_op(sbi); 1461 + return err; 1394 1462 } 1395 1463 1396 1464 static int f2fs_write_begin(struct file *file, struct address_space *mapping, ··· 1472 1396 struct inode *inode = mapping->host; 1473 1397 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 1474 1398 struct page *page = NULL; 1475 - struct page *ipage; 1476 1399 pgoff_t index = ((unsigned long long) pos) >> PAGE_CACHE_SHIFT; 1477 - struct dnode_of_data dn; 1400 + bool need_balance = false; 1401 + block_t blkaddr = NULL_ADDR; 1478 1402 int err = 0; 1479 1403 1480 1404 trace_f2fs_write_begin(inode, pos, len, flags); 1481 - 1482 - f2fs_balance_fs(sbi); 1483 1405 1484 1406 /* 1485 1407 * We should check this at this moment to avoid deadlock on inode page ··· 1498 1424 1499 1425 *pagep = page; 1500 1426 1501 - f2fs_lock_op(sbi); 1502 - 1503 - /* check inline_data */ 1504 - ipage = get_node_page(sbi, inode->i_ino); 1505 - if (IS_ERR(ipage)) { 1506 - err = PTR_ERR(ipage); 1507 - goto unlock_fail; 1508 - } 1509 - 1510 - set_new_dnode(&dn, inode, ipage, ipage, 0); 1511 - 1512 - if (f2fs_has_inline_data(inode)) { 1513 - if (pos + len <= MAX_INLINE_DATA) { 1514 - read_inline_data(page, ipage); 1515 - set_inode_flag(F2FS_I(inode), FI_DATA_EXIST); 1516 - sync_inode_page(&dn); 1517 - goto put_next; 1518 - } 1519 - err = f2fs_convert_inline_page(&dn, page); 1520 - if (err) 1521 - goto put_fail; 1522 - } 1523 - 1524 - err = f2fs_get_block(&dn, index); 1427 + err = prepare_write_begin(sbi, page, pos, len, 1428 + &blkaddr, &need_balance); 1525 1429 if (err) 1526 - goto put_fail; 1527 - put_next: 1528 - f2fs_put_dnode(&dn); 1529 - f2fs_unlock_op(sbi); 1430 + goto fail; 1431 + 1432 + if (need_balance && has_not_enough_free_secs(sbi, 0)) { 1433 + unlock_page(page); 1434 + f2fs_balance_fs(sbi, true); 1435 + lock_page(page); 1436 + if (page->mapping != mapping) { 1437 + /* The page got truncated from under us */ 1438 + f2fs_put_page(page, 1); 1439 + goto repeat; 1440 + } 1441 + } 1530 1442 1531 1443 f2fs_wait_on_page_writeback(page, DATA); 1532 1444 1533 1445 /* wait for GCed encrypted page writeback */ 1534 1446 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) 1535 - f2fs_wait_on_encrypted_page_writeback(sbi, dn.data_blkaddr); 1447 + f2fs_wait_on_encrypted_page_writeback(sbi, blkaddr); 1536 1448 1537 1449 if (len == PAGE_CACHE_SIZE) 1538 1450 goto out_update; ··· 1534 1474 goto out_update; 1535 1475 } 1536 1476 1537 - if (dn.data_blkaddr == NEW_ADDR) { 1477 + if (blkaddr == NEW_ADDR) { 1538 1478 zero_user_segment(page, 0, PAGE_CACHE_SIZE); 1539 1479 } else { 1540 1480 struct f2fs_io_info fio = { 1541 1481 .sbi = sbi, 1542 1482 .type = DATA, 1543 1483 .rw = READ_SYNC, 1544 - .blk_addr = dn.data_blkaddr, 1484 + .blk_addr = blkaddr, 1545 1485 .page = page, 1546 1486 .encrypted_page = NULL, 1547 1487 }; ··· 1572 1512 clear_cold_data(page); 1573 1513 return 0; 1574 1514 1575 - put_fail: 1576 - f2fs_put_dnode(&dn); 1577 - unlock_fail: 1578 - f2fs_unlock_op(sbi); 1579 1515 fail: 1580 1516 f2fs_put_page(page, 1); 1581 1517 f2fs_write_failed(mapping, pos + len); ··· 1596 1540 } 1597 1541 1598 1542 f2fs_put_page(page, 1); 1543 + f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); 1599 1544 return copied; 1600 1545 } 1601 1546 ··· 1624 1567 int err; 1625 1568 1626 1569 /* we don't need to use inline_data strictly */ 1627 - if (f2fs_has_inline_data(inode)) { 1628 - err = f2fs_convert_inline_inode(inode); 1629 - if (err) 1630 - return err; 1631 - } 1570 + err = f2fs_convert_inline_inode(inode); 1571 + if (err) 1572 + return err; 1632 1573 1633 1574 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) 1634 1575 return 0; ··· 1638 1583 trace_f2fs_direct_IO_enter(inode, offset, count, iov_iter_rw(iter)); 1639 1584 1640 1585 if (iov_iter_rw(iter) == WRITE) { 1641 - __allocate_data_blocks(inode, offset, count); 1642 - if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) { 1643 - err = -EIO; 1586 + err = __allocate_data_blocks(inode, offset, count); 1587 + if (err) 1644 1588 goto out; 1645 - } 1646 1589 } 1647 1590 1648 1591 err = blockdev_direct_IO(iocb, inode, iter, offset, get_data_block_dio);
+19 -10
fs/f2fs/debug.c
··· 38 38 si->hit_rbtree = atomic64_read(&sbi->read_hit_rbtree); 39 39 si->hit_total = si->hit_largest + si->hit_cached + si->hit_rbtree; 40 40 si->total_ext = atomic64_read(&sbi->total_hit_ext); 41 - si->ext_tree = sbi->total_ext_tree; 41 + si->ext_tree = atomic_read(&sbi->total_ext_tree); 42 + si->zombie_tree = atomic_read(&sbi->total_zombie_tree); 42 43 si->ext_node = atomic_read(&sbi->total_ext_node); 43 44 si->ndirty_node = get_pages(sbi, F2FS_DIRTY_NODES); 44 45 si->ndirty_dent = get_pages(sbi, F2FS_DIRTY_DENTS); 45 - si->ndirty_dirs = sbi->n_dirty_dirs; 46 46 si->ndirty_meta = get_pages(sbi, F2FS_DIRTY_META); 47 + si->ndirty_data = get_pages(sbi, F2FS_DIRTY_DATA); 48 + si->ndirty_dirs = sbi->ndirty_inode[DIR_INODE]; 49 + si->ndirty_files = sbi->ndirty_inode[FILE_INODE]; 47 50 si->inmem_pages = get_pages(sbi, F2FS_INMEM_PAGES); 48 51 si->wb_pages = get_pages(sbi, F2FS_WRITEBACK); 49 52 si->total_count = (int)sbi->user_block_count / sbi->blocks_per_seg; ··· 108 105 109 106 bimodal = 0; 110 107 total_vblocks = 0; 111 - blks_per_sec = sbi->segs_per_sec * (1 << sbi->log_blocks_per_seg); 108 + blks_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 112 109 hblks_per_sec = blks_per_sec / 2; 113 110 for (segno = 0; segno < MAIN_SEGS(sbi); segno += sbi->segs_per_sec) { 114 111 vblocks = get_valid_blocks(sbi, segno, sbi->segs_per_sec); ··· 192 189 si->cache_mem += NM_I(sbi)->dirty_nat_cnt * 193 190 sizeof(struct nat_entry_set); 194 191 si->cache_mem += si->inmem_pages * sizeof(struct inmem_pages); 195 - si->cache_mem += sbi->n_dirty_dirs * sizeof(struct inode_entry); 196 192 for (i = 0; i <= UPDATE_INO; i++) 197 193 si->cache_mem += sbi->im[i].ino_num * sizeof(struct ino_entry); 198 - si->cache_mem += sbi->total_ext_tree * sizeof(struct extent_tree); 194 + si->cache_mem += atomic_read(&sbi->total_ext_tree) * 195 + sizeof(struct extent_tree); 199 196 si->cache_mem += atomic_read(&sbi->total_ext_node) * 200 197 sizeof(struct extent_node); 201 198 ··· 270 267 si->dirty_count); 271 268 seq_printf(s, " - Prefree: %d\n - Free: %d (%d)\n\n", 272 269 si->prefree_count, si->free_segs, si->free_secs); 273 - seq_printf(s, "CP calls: %d\n", si->cp_count); 270 + seq_printf(s, "CP calls: %d (BG: %d)\n", 271 + si->cp_count, si->bg_cp_count); 274 272 seq_printf(s, "GC calls: %d (BG: %d)\n", 275 273 si->call_count, si->bg_gc); 276 274 seq_printf(s, " - data segments : %d (%d)\n", ··· 292 288 !si->total_ext ? 0 : 293 289 div64_u64(si->hit_total * 100, si->total_ext), 294 290 si->hit_total, si->total_ext); 295 - seq_printf(s, " - Inner Struct Count: tree: %d, node: %d\n", 296 - si->ext_tree, si->ext_node); 291 + seq_printf(s, " - Inner Struct Count: tree: %d(%d), node: %d\n", 292 + si->ext_tree, si->zombie_tree, si->ext_node); 297 293 seq_puts(s, "\nBalancing F2FS Async:\n"); 298 294 seq_printf(s, " - inmem: %4d, wb: %4d\n", 299 295 si->inmem_pages, si->wb_pages); ··· 301 297 si->ndirty_node, si->node_pages); 302 298 seq_printf(s, " - dents: %4d in dirs:%4d\n", 303 299 si->ndirty_dent, si->ndirty_dirs); 300 + seq_printf(s, " - datas: %4d in files:%4d\n", 301 + si->ndirty_data, si->ndirty_files); 304 302 seq_printf(s, " - meta: %4d in %4d\n", 305 303 si->ndirty_meta, si->meta_pages); 306 304 seq_printf(s, " - NATs: %9d/%9d\n - SITs: %9d/%9d\n", ··· 410 404 kfree(si); 411 405 } 412 406 413 - void __init f2fs_create_root_stats(void) 407 + int __init f2fs_create_root_stats(void) 414 408 { 415 409 struct dentry *file; 416 410 417 411 f2fs_debugfs_root = debugfs_create_dir("f2fs", NULL); 418 412 if (!f2fs_debugfs_root) 419 - return; 413 + return -ENOMEM; 420 414 421 415 file = debugfs_create_file("status", S_IRUGO, f2fs_debugfs_root, 422 416 NULL, &stat_fops); 423 417 if (!file) { 424 418 debugfs_remove(f2fs_debugfs_root); 425 419 f2fs_debugfs_root = NULL; 420 + return -ENOMEM; 426 421 } 422 + 423 + return 0; 427 424 } 428 425 429 426 void f2fs_destroy_root_stats(void)
+25 -13
fs/f2fs/dir.c
··· 172 172 173 173 namehash = f2fs_dentry_hash(&name); 174 174 175 - f2fs_bug_on(F2FS_I_SB(dir), level > MAX_DIR_HASH_DEPTH); 176 - 177 175 nbucket = dir_buckets(level, F2FS_I(dir)->i_dir_level); 178 176 nblock = bucket_blocks(level); 179 177 ··· 236 238 goto out; 237 239 238 240 max_depth = F2FS_I(dir)->i_current_depth; 241 + if (unlikely(max_depth > MAX_DIR_HASH_DEPTH)) { 242 + f2fs_msg(F2FS_I_SB(dir)->sb, KERN_WARNING, 243 + "Corrupted max_depth of %lu: %u", 244 + dir->i_ino, max_depth); 245 + max_depth = MAX_DIR_HASH_DEPTH; 246 + F2FS_I(dir)->i_current_depth = max_depth; 247 + mark_inode_dirty(dir); 248 + } 239 249 240 250 for (level = 0; level < max_depth; level++) { 241 251 de = find_in_level(dir, level, &fname, res_page); ··· 450 444 /* once the failed inode becomes a bad inode, i_mode is S_IFREG */ 451 445 truncate_inode_pages(&inode->i_data, 0); 452 446 truncate_blocks(inode, 0, false); 453 - remove_dirty_dir_inode(inode); 447 + remove_dirty_inode(inode); 454 448 remove_inode_page(inode); 455 449 return ERR_PTR(err); 456 450 } ··· 636 630 f2fs_put_page(dentry_page, 1); 637 631 out: 638 632 f2fs_fname_free_filename(&fname); 633 + f2fs_update_time(F2FS_I_SB(dir), REQ_TIME); 639 634 return err; 640 635 } 641 636 ··· 658 651 clear_inode_flag(F2FS_I(inode), FI_NEW_INODE); 659 652 fail: 660 653 up_write(&F2FS_I(inode)->i_sem); 654 + f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); 661 655 return err; 662 656 } 663 657 ··· 702 694 unsigned int bit_pos; 703 695 int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len)); 704 696 int i; 697 + 698 + f2fs_update_time(F2FS_I_SB(dir), REQ_TIME); 705 699 706 700 if (f2fs_has_inline_dentry(dir)) 707 701 return f2fs_delete_inline_entry(dentry, page, dir, inode); ··· 865 855 866 856 for (; n < npages; n++) { 867 857 dentry_page = get_lock_data_page(inode, n, false); 868 - if (IS_ERR(dentry_page)) 869 - continue; 858 + if (IS_ERR(dentry_page)) { 859 + err = PTR_ERR(dentry_page); 860 + if (err == -ENOENT) 861 + continue; 862 + else 863 + goto out; 864 + } 870 865 871 866 dentry_blk = kmap(dentry_page); 872 867 873 868 make_dentry_ptr(inode, &d, (void *)dentry_blk, 1); 874 869 875 - if (f2fs_fill_dentries(ctx, &d, n * NR_DENTRY_IN_BLOCK, &fstr)) 876 - goto stop; 870 + if (f2fs_fill_dentries(ctx, &d, n * NR_DENTRY_IN_BLOCK, &fstr)) { 871 + kunmap(dentry_page); 872 + f2fs_put_page(dentry_page, 1); 873 + break; 874 + } 877 875 878 876 ctx->pos = (n + 1) * NR_DENTRY_IN_BLOCK; 879 - kunmap(dentry_page); 880 - f2fs_put_page(dentry_page, 1); 881 - dentry_page = NULL; 882 - } 883 - stop: 884 - if (dentry_page && !IS_ERR(dentry_page)) { 885 877 kunmap(dentry_page); 886 878 f2fs_put_page(dentry_page, 1); 887 879 }
+69 -55
fs/f2fs/extent_cache.c
··· 36 36 37 37 rb_link_node(&en->rb_node, parent, p); 38 38 rb_insert_color(&en->rb_node, &et->root); 39 - et->count++; 39 + atomic_inc(&et->node_cnt); 40 40 atomic_inc(&sbi->total_ext_node); 41 41 return en; 42 42 } ··· 45 45 struct extent_tree *et, struct extent_node *en) 46 46 { 47 47 rb_erase(&en->rb_node, &et->root); 48 - et->count--; 48 + atomic_dec(&et->node_cnt); 49 49 atomic_dec(&sbi->total_ext_node); 50 50 51 51 if (et->cached_en == en) ··· 68 68 et->root = RB_ROOT; 69 69 et->cached_en = NULL; 70 70 rwlock_init(&et->lock); 71 - atomic_set(&et->refcount, 0); 72 - et->count = 0; 73 - sbi->total_ext_tree++; 71 + INIT_LIST_HEAD(&et->list); 72 + atomic_set(&et->node_cnt, 0); 73 + atomic_inc(&sbi->total_ext_tree); 74 + } else { 75 + atomic_dec(&sbi->total_zombie_tree); 76 + list_del_init(&et->list); 74 77 } 75 - atomic_inc(&et->refcount); 76 78 up_write(&sbi->extent_tree_lock); 77 79 78 80 /* never died until evict_inode */ ··· 133 131 { 134 132 struct rb_node *node, *next; 135 133 struct extent_node *en; 136 - unsigned int count = et->count; 134 + unsigned int count = atomic_read(&et->node_cnt); 137 135 138 136 node = rb_first(&et->root); 139 137 while (node) { ··· 154 152 node = next; 155 153 } 156 154 157 - return count - et->count; 155 + return count - atomic_read(&et->node_cnt); 158 156 } 159 157 160 158 static void __drop_largest_extent(struct inode *inode, ··· 166 164 largest->len = 0; 167 165 } 168 166 169 - void f2fs_drop_largest_extent(struct inode *inode, pgoff_t fofs) 170 - { 171 - if (!f2fs_may_extent_tree(inode)) 172 - return; 173 - 174 - __drop_largest_extent(inode, fofs, 1); 175 - } 176 - 177 - void f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext) 167 + /* return true, if inode page is changed */ 168 + bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext) 178 169 { 179 170 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 180 171 struct extent_tree *et; 181 172 struct extent_node *en; 182 173 struct extent_info ei; 183 174 184 - if (!f2fs_may_extent_tree(inode)) 185 - return; 175 + if (!f2fs_may_extent_tree(inode)) { 176 + /* drop largest extent */ 177 + if (i_ext && i_ext->len) { 178 + i_ext->len = 0; 179 + return true; 180 + } 181 + return false; 182 + } 186 183 187 184 et = __grab_extent_tree(inode); 188 185 189 - if (!i_ext || le32_to_cpu(i_ext->len) < F2FS_MIN_EXTENT_LEN) 190 - return; 186 + if (!i_ext || !i_ext->len) 187 + return false; 191 188 192 189 set_extent_info(&ei, le32_to_cpu(i_ext->fofs), 193 190 le32_to_cpu(i_ext->blk), le32_to_cpu(i_ext->len)); 194 191 195 192 write_lock(&et->lock); 196 - if (et->count) 193 + if (atomic_read(&et->node_cnt)) 197 194 goto out; 198 195 199 196 en = __init_extent_tree(sbi, et, &ei); ··· 203 202 } 204 203 out: 205 204 write_unlock(&et->lock); 205 + return false; 206 206 } 207 207 208 208 static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs, ··· 551 549 unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink) 552 550 { 553 551 struct extent_tree *treevec[EXT_TREE_VEC_SIZE]; 552 + struct extent_tree *et, *next; 554 553 struct extent_node *en, *tmp; 555 554 unsigned long ino = F2FS_ROOT_INO(sbi); 556 - struct radix_tree_root *root = &sbi->extent_tree_root; 557 555 unsigned int found; 558 556 unsigned int node_cnt = 0, tree_cnt = 0; 559 557 int remained; 558 + bool do_free = false; 560 559 561 560 if (!test_opt(sbi, EXTENT_CACHE)) 562 561 return 0; 562 + 563 + if (!atomic_read(&sbi->total_zombie_tree)) 564 + goto free_node; 563 565 564 566 if (!down_write_trylock(&sbi->extent_tree_lock)) 565 567 goto out; 566 568 567 569 /* 1. remove unreferenced extent tree */ 568 - while ((found = radix_tree_gang_lookup(root, 569 - (void **)treevec, ino, EXT_TREE_VEC_SIZE))) { 570 - unsigned i; 571 - 572 - ino = treevec[found - 1]->ino + 1; 573 - for (i = 0; i < found; i++) { 574 - struct extent_tree *et = treevec[i]; 575 - 576 - if (!atomic_read(&et->refcount)) { 577 - write_lock(&et->lock); 578 - node_cnt += __free_extent_tree(sbi, et, true); 579 - write_unlock(&et->lock); 580 - 581 - radix_tree_delete(root, et->ino); 582 - kmem_cache_free(extent_tree_slab, et); 583 - sbi->total_ext_tree--; 584 - tree_cnt++; 585 - 586 - if (node_cnt + tree_cnt >= nr_shrink) 587 - goto unlock_out; 588 - } 570 + list_for_each_entry_safe(et, next, &sbi->zombie_list, list) { 571 + if (atomic_read(&et->node_cnt)) { 572 + write_lock(&et->lock); 573 + node_cnt += __free_extent_tree(sbi, et, true); 574 + write_unlock(&et->lock); 589 575 } 576 + 577 + list_del_init(&et->list); 578 + radix_tree_delete(&sbi->extent_tree_root, et->ino); 579 + kmem_cache_free(extent_tree_slab, et); 580 + atomic_dec(&sbi->total_ext_tree); 581 + atomic_dec(&sbi->total_zombie_tree); 582 + tree_cnt++; 583 + 584 + if (node_cnt + tree_cnt >= nr_shrink) 585 + goto unlock_out; 590 586 } 591 587 up_write(&sbi->extent_tree_lock); 592 588 589 + free_node: 593 590 /* 2. remove LRU extent entries */ 594 591 if (!down_write_trylock(&sbi->extent_tree_lock)) 595 592 goto out; ··· 600 599 if (!remained--) 601 600 break; 602 601 list_del_init(&en->list); 602 + do_free = true; 603 603 } 604 604 spin_unlock(&sbi->extent_lock); 605 + 606 + if (do_free == false) 607 + goto unlock_out; 605 608 606 609 /* 607 610 * reset ino for searching victims from beginning of global extent tree. 608 611 */ 609 612 ino = F2FS_ROOT_INO(sbi); 610 613 611 - while ((found = radix_tree_gang_lookup(root, 614 + while ((found = radix_tree_gang_lookup(&sbi->extent_tree_root, 612 615 (void **)treevec, ino, EXT_TREE_VEC_SIZE))) { 613 616 unsigned i; 614 617 ··· 620 615 for (i = 0; i < found; i++) { 621 616 struct extent_tree *et = treevec[i]; 622 617 623 - write_lock(&et->lock); 624 - node_cnt += __free_extent_tree(sbi, et, false); 625 - write_unlock(&et->lock); 618 + if (!atomic_read(&et->node_cnt)) 619 + continue; 620 + 621 + if (write_trylock(&et->lock)) { 622 + node_cnt += __free_extent_tree(sbi, et, false); 623 + write_unlock(&et->lock); 624 + } 626 625 627 626 if (node_cnt + tree_cnt >= nr_shrink) 628 627 goto unlock_out; ··· 646 637 struct extent_tree *et = F2FS_I(inode)->extent_tree; 647 638 unsigned int node_cnt = 0; 648 639 649 - if (!et) 640 + if (!et || !atomic_read(&et->node_cnt)) 650 641 return 0; 651 642 652 643 write_lock(&et->lock); ··· 665 656 if (!et) 666 657 return; 667 658 668 - if (inode->i_nlink && !is_bad_inode(inode) && et->count) { 669 - atomic_dec(&et->refcount); 659 + if (inode->i_nlink && !is_bad_inode(inode) && 660 + atomic_read(&et->node_cnt)) { 661 + down_write(&sbi->extent_tree_lock); 662 + list_add_tail(&et->list, &sbi->zombie_list); 663 + atomic_inc(&sbi->total_zombie_tree); 664 + up_write(&sbi->extent_tree_lock); 670 665 return; 671 666 } 672 667 ··· 679 666 680 667 /* delete extent tree entry in radix tree */ 681 668 down_write(&sbi->extent_tree_lock); 682 - atomic_dec(&et->refcount); 683 - f2fs_bug_on(sbi, atomic_read(&et->refcount) || et->count); 669 + f2fs_bug_on(sbi, atomic_read(&et->node_cnt)); 684 670 radix_tree_delete(&sbi->extent_tree_root, inode->i_ino); 685 671 kmem_cache_free(extent_tree_slab, et); 686 - sbi->total_ext_tree--; 672 + atomic_dec(&sbi->total_ext_tree); 687 673 up_write(&sbi->extent_tree_lock); 688 674 689 675 F2FS_I(inode)->extent_tree = NULL; ··· 734 722 init_rwsem(&sbi->extent_tree_lock); 735 723 INIT_LIST_HEAD(&sbi->extent_list); 736 724 spin_lock_init(&sbi->extent_lock); 737 - sbi->total_ext_tree = 0; 725 + atomic_set(&sbi->total_ext_tree, 0); 726 + INIT_LIST_HEAD(&sbi->zombie_list); 727 + atomic_set(&sbi->total_zombie_tree, 0); 738 728 atomic_set(&sbi->total_ext_node, 0); 739 729 } 740 730
+96 -46
fs/f2fs/f2fs.h
··· 21 21 #include <linux/sched.h> 22 22 #include <linux/vmalloc.h> 23 23 #include <linux/bio.h> 24 + #include <linux/blkdev.h> 24 25 25 26 #ifdef CONFIG_F2FS_CHECK_FS 26 27 #define f2fs_bug_on(sbi, condition) BUG_ON(condition) ··· 55 54 #define F2FS_MOUNT_FASTBOOT 0x00001000 56 55 #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 57 56 #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 57 + #define F2FS_MOUNT_DATA_FLUSH 0x00008000 58 58 59 59 #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 60 60 #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) ··· 127 125 #define BATCHED_TRIM_BLOCKS(sbi) \ 128 126 (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 129 127 #define DEF_CP_INTERVAL 60 /* 60 secs */ 128 + #define DEF_IDLE_INTERVAL 120 /* 2 mins */ 130 129 131 130 struct cp_control { 132 131 int reason; ··· 161 158 nid_t ino; /* inode number */ 162 159 }; 163 160 164 - /* 165 - * for the list of directory inodes or gc inodes. 166 - * NOTE: there are two slab users for this structure, if we add/modify/delete 167 - * fields in structure for one of slab users, it may affect fields or size of 168 - * other one, in this condition, it's better to split both of slab and related 169 - * data structure. 170 - */ 161 + /* for the list of inodes to be GCed */ 171 162 struct inode_entry { 172 163 struct list_head list; /* list head */ 173 164 struct inode *inode; /* vfs inode pointer */ ··· 231 234 #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 232 235 #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) 233 236 #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 237 + #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8) 234 238 235 239 #define F2FS_IOC_SET_ENCRYPTION_POLICY \ 236 240 _IOR('f', 19, struct f2fs_encryption_policy) ··· 254 256 /* 255 257 * ioctl commands in 32 bit emulation 256 258 */ 257 - #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 258 - #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 259 + #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 260 + #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 261 + #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 259 262 #endif 263 + 264 + struct f2fs_defragment { 265 + u64 start; 266 + u64 len; 267 + }; 260 268 261 269 /* 262 270 * For INODE and NODE manager ··· 361 357 struct rb_root root; /* root of extent info rb-tree */ 362 358 struct extent_node *cached_en; /* recently accessed extent node */ 363 359 struct extent_info largest; /* largested extent info */ 360 + struct list_head list; /* to be used by sbi->zombie_list */ 364 361 rwlock_t lock; /* protect extent info rb-tree */ 365 - atomic_t refcount; /* reference count of rb-tree */ 366 - unsigned int count; /* # of extent node in rb-tree*/ 362 + atomic_t node_cnt; /* # of extent node in rb-tree*/ 367 363 }; 368 364 369 365 /* ··· 438 434 unsigned int clevel; /* maximum level of given file name */ 439 435 nid_t i_xattr_nid; /* node id that contains xattrs */ 440 436 unsigned long long xattr_ver; /* cp version of xattr modification */ 441 - struct inode_entry *dirty_dir; /* the pointer of dirty dir */ 442 437 438 + struct list_head dirty_list; /* linked in global dirty list */ 443 439 struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 444 440 struct mutex inmem_lock; /* lock for inmemory pages */ 445 441 ··· 548 544 nid_t nid; /* node id of the direct node block */ 549 545 unsigned int ofs_in_node; /* data offset in the node page */ 550 546 bool inode_page_locked; /* inode page is locked or not */ 547 + bool node_changed; /* is node block changed */ 551 548 block_t data_blkaddr; /* block address of the node block */ 552 549 }; 553 550 ··· 652 647 enum count_type { 653 648 F2FS_WRITEBACK, 654 649 F2FS_DIRTY_DENTS, 650 + F2FS_DIRTY_DATA, 655 651 F2FS_DIRTY_NODES, 656 652 F2FS_DIRTY_META, 657 653 F2FS_INMEM_PAGES, ··· 701 695 struct rw_semaphore io_rwsem; /* blocking op for bio */ 702 696 }; 703 697 698 + enum inode_type { 699 + DIR_INODE, /* for dirty dir inode */ 700 + FILE_INODE, /* for dirty regular/symlink inode */ 701 + NR_INODE_TYPE, 702 + }; 703 + 704 704 /* for inner inode cache management */ 705 705 struct inode_management { 706 706 struct radix_tree_root ino_root; /* ino entry array */ ··· 723 711 SBI_POR_DOING, /* recovery is doing or not */ 724 712 }; 725 713 714 + enum { 715 + CP_TIME, 716 + REQ_TIME, 717 + MAX_TIME, 718 + }; 719 + 726 720 struct f2fs_sb_info { 727 721 struct super_block *sb; /* pointer to VFS super block */ 728 722 struct proc_dir_entry *s_proc; /* proc entry */ 729 - struct buffer_head *raw_super_buf; /* buffer head of raw sb */ 730 723 struct f2fs_super_block *raw_super; /* raw super block pointer */ 724 + int valid_super_block; /* valid super block no */ 731 725 int s_flag; /* flags for sbi */ 732 726 733 727 /* for node-related operations */ ··· 755 737 struct rw_semaphore node_write; /* locking node writes */ 756 738 struct mutex writepages; /* mutex for writepages() */ 757 739 wait_queue_head_t cp_wait; 758 - long cp_expires, cp_interval; /* next expected periodic cp */ 740 + unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 741 + long interval_time[MAX_TIME]; /* to store thresholds */ 759 742 760 743 struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 761 744 762 745 /* for orphan inode, use 0'th array */ 763 746 unsigned int max_orphans; /* max orphan inodes */ 764 747 765 - /* for directory inode management */ 766 - struct list_head dir_inode_list; /* dir inode list */ 767 - spinlock_t dir_inode_lock; /* for dir inode list lock */ 748 + /* for inode management */ 749 + struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 750 + spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 768 751 769 752 /* for extent tree cache */ 770 753 struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 771 754 struct rw_semaphore extent_tree_lock; /* locking extent radix tree */ 772 755 struct list_head extent_list; /* lru list for shrinker */ 773 756 spinlock_t extent_lock; /* locking extent lru list */ 774 - int total_ext_tree; /* extent tree count */ 757 + atomic_t total_ext_tree; /* extent tree count */ 758 + struct list_head zombie_list; /* extent zombie tree list */ 759 + atomic_t total_zombie_tree; /* extent zombie tree count */ 775 760 atomic_t total_ext_node; /* extent info count */ 776 761 777 762 /* basic filesystem units */ ··· 792 771 unsigned int total_node_count; /* total node block count */ 793 772 unsigned int total_valid_node_count; /* valid node block count */ 794 773 unsigned int total_valid_inode_count; /* valid inode count */ 774 + loff_t max_file_blocks; /* max block index of file */ 795 775 int active_logs; /* # of active logs */ 796 776 int dir_level; /* directory level */ 797 777 ··· 831 809 atomic_t inline_inode; /* # of inline_data inodes */ 832 810 atomic_t inline_dir; /* # of inline_dentry inodes */ 833 811 int bg_gc; /* background gc calls */ 834 - unsigned int n_dirty_dirs; /* # of dir inodes */ 812 + unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 835 813 #endif 836 814 unsigned int last_victim[2]; /* last victim segment # */ 837 815 spinlock_t stat_lock; /* lock for stat operations */ ··· 845 823 struct mutex umount_mutex; 846 824 unsigned int shrinker_run_no; 847 825 }; 826 + 827 + static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 828 + { 829 + sbi->last_time[type] = jiffies; 830 + } 831 + 832 + static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 833 + { 834 + struct timespec ts = {sbi->interval_time[type], 0}; 835 + unsigned long interval = timespec_to_jiffies(&ts); 836 + 837 + return time_after(jiffies, sbi->last_time[type] + interval); 838 + } 839 + 840 + static inline bool is_idle(struct f2fs_sb_info *sbi) 841 + { 842 + struct block_device *bdev = sbi->sb->s_bdev; 843 + struct request_queue *q = bdev_get_queue(bdev); 844 + struct request_list *rl = &q->root_rl; 845 + 846 + if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 847 + return 0; 848 + 849 + return f2fs_time_over(sbi, REQ_TIME); 850 + } 848 851 849 852 /* 850 853 * Inline functions ··· 1106 1059 static inline void inode_inc_dirty_pages(struct inode *inode) 1107 1060 { 1108 1061 atomic_inc(&F2FS_I(inode)->dirty_pages); 1109 - if (S_ISDIR(inode->i_mode)) 1110 - inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 1062 + inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1063 + F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 1111 1064 } 1112 1065 1113 1066 static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) ··· 1122 1075 return; 1123 1076 1124 1077 atomic_dec(&F2FS_I(inode)->dirty_pages); 1125 - 1126 - if (S_ISDIR(inode->i_mode)) 1127 - dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS); 1078 + dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1079 + F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 1128 1080 } 1129 1081 1130 1082 static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) ··· 1138 1092 1139 1093 static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 1140 1094 { 1141 - unsigned int pages_per_sec = sbi->segs_per_sec * 1142 - (1 << sbi->log_blocks_per_seg); 1095 + unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1143 1096 return ((get_pages(sbi, block_type) + pages_per_sec - 1) 1144 1097 >> sbi->log_blocks_per_seg) / sbi->segs_per_sec; 1145 1098 } ··· 1461 1416 FI_DROP_CACHE, /* drop dirty page cache */ 1462 1417 FI_DATA_EXIST, /* indicate data exists */ 1463 1418 FI_INLINE_DOTS, /* indicate inline dot dentries */ 1419 + FI_DO_DEFRAG, /* indicate defragment is running */ 1420 + FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 1464 1421 }; 1465 1422 1466 1423 static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) ··· 1706 1659 void f2fs_set_inode_flags(struct inode *); 1707 1660 struct inode *f2fs_iget(struct super_block *, unsigned long); 1708 1661 int try_to_free_nats(struct f2fs_sb_info *, int); 1709 - void update_inode(struct inode *, struct page *); 1710 - void update_inode_page(struct inode *); 1662 + int update_inode(struct inode *, struct page *); 1663 + int update_inode_page(struct inode *); 1711 1664 int f2fs_write_inode(struct inode *, struct writeback_control *); 1712 1665 void f2fs_evict_inode(struct inode *); 1713 1666 void handle_failed_inode(struct inode *); ··· 1812 1765 */ 1813 1766 void register_inmem_page(struct inode *, struct page *); 1814 1767 int commit_inmem_pages(struct inode *, bool); 1815 - void f2fs_balance_fs(struct f2fs_sb_info *); 1768 + void f2fs_balance_fs(struct f2fs_sb_info *, bool); 1816 1769 void f2fs_balance_fs_bg(struct f2fs_sb_info *); 1817 1770 int f2fs_issue_flush(struct f2fs_sb_info *); 1818 1771 int create_flush_cmd_control(struct f2fs_sb_info *); ··· 1858 1811 int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int, bool); 1859 1812 void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t); 1860 1813 long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); 1861 - void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 1862 - void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type); 1863 - void release_dirty_inode(struct f2fs_sb_info *); 1814 + void add_ino_entry(struct f2fs_sb_info *, nid_t, int type); 1815 + void remove_ino_entry(struct f2fs_sb_info *, nid_t, int type); 1816 + void release_ino_entry(struct f2fs_sb_info *); 1864 1817 bool exist_written_data(struct f2fs_sb_info *, nid_t, int); 1865 1818 int acquire_orphan_inode(struct f2fs_sb_info *); 1866 1819 void release_orphan_inode(struct f2fs_sb_info *); ··· 1870 1823 int get_valid_checkpoint(struct f2fs_sb_info *); 1871 1824 void update_dirty_page(struct inode *, struct page *); 1872 1825 void add_dirty_dir_inode(struct inode *); 1873 - void remove_dirty_dir_inode(struct inode *); 1874 - void sync_dirty_dir_inodes(struct f2fs_sb_info *); 1875 - void write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 1826 + void remove_dirty_inode(struct inode *); 1827 + int sync_dirty_inodes(struct f2fs_sb_info *, enum inode_type); 1828 + int write_checkpoint(struct f2fs_sb_info *, struct cp_control *); 1876 1829 void init_ino_entry_info(struct f2fs_sb_info *); 1877 1830 int __init create_checkpoint_caches(void); 1878 1831 void destroy_checkpoint_caches(void); ··· 1892 1845 struct page *get_lock_data_page(struct inode *, pgoff_t, bool); 1893 1846 struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); 1894 1847 int do_write_data_page(struct f2fs_io_info *); 1848 + int f2fs_map_blocks(struct inode *, struct f2fs_map_blocks *, int, int); 1895 1849 int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64); 1896 1850 void f2fs_invalidate_page(struct page *, unsigned int, unsigned int); 1897 1851 int f2fs_release_page(struct page *, gfp_t); ··· 1923 1875 int main_area_segs, main_area_sections, main_area_zones; 1924 1876 unsigned long long hit_largest, hit_cached, hit_rbtree; 1925 1877 unsigned long long hit_total, total_ext; 1926 - int ext_tree, ext_node; 1927 - int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta; 1878 + int ext_tree, zombie_tree, ext_node; 1879 + int ndirty_node, ndirty_meta; 1880 + int ndirty_dent, ndirty_dirs, ndirty_data, ndirty_files; 1928 1881 int nats, dirty_nats, sits, dirty_sits, fnids; 1929 1882 int total_count, utilization; 1930 1883 int bg_gc, inmem_pages, wb_pages; ··· 1935 1886 int util_free, util_valid, util_invalid; 1936 1887 int rsvd_segs, overp_segs; 1937 1888 int dirty_count, node_pages, meta_pages; 1938 - int prefree_count, call_count, cp_count; 1889 + int prefree_count, call_count, cp_count, bg_cp_count; 1939 1890 int tot_segs, node_segs, data_segs, free_segs, free_secs; 1940 1891 int bg_node_segs, bg_data_segs; 1941 1892 int tot_blks, data_blks, node_blks; ··· 1956 1907 } 1957 1908 1958 1909 #define stat_inc_cp_count(si) ((si)->cp_count++) 1910 + #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 1959 1911 #define stat_inc_call_count(si) ((si)->call_count++) 1960 1912 #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 1961 - #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++) 1962 - #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--) 1913 + #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 1914 + #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 1963 1915 #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 1964 1916 #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 1965 1917 #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) ··· 2035 1985 2036 1986 int f2fs_build_stats(struct f2fs_sb_info *); 2037 1987 void f2fs_destroy_stats(struct f2fs_sb_info *); 2038 - void __init f2fs_create_root_stats(void); 1988 + int __init f2fs_create_root_stats(void); 2039 1989 void f2fs_destroy_root_stats(void); 2040 1990 #else 2041 1991 #define stat_inc_cp_count(si) 1992 + #define stat_inc_bg_cp_count(si) 2042 1993 #define stat_inc_call_count(si) 2043 1994 #define stat_inc_bggc_count(si) 2044 - #define stat_inc_dirty_dir(sbi) 2045 - #define stat_dec_dirty_dir(sbi) 1995 + #define stat_inc_dirty_inode(sbi, type) 1996 + #define stat_dec_dirty_inode(sbi, type) 2046 1997 #define stat_inc_total_hit(sb) 2047 1998 #define stat_inc_rbtree_node_hit(sb) 2048 1999 #define stat_inc_largest_node_hit(sbi) ··· 2064 2013 2065 2014 static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 2066 2015 static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2067 - static inline void __init f2fs_create_root_stats(void) { } 2016 + static inline int __init f2fs_create_root_stats(void) { return 0; } 2068 2017 static inline void f2fs_destroy_root_stats(void) { } 2069 2018 #endif 2070 2019 ··· 2118 2067 * extent_cache.c 2119 2068 */ 2120 2069 unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int); 2121 - void f2fs_drop_largest_extent(struct inode *, pgoff_t); 2122 - void f2fs_init_extent_tree(struct inode *, struct f2fs_extent *); 2070 + bool f2fs_init_extent_tree(struct inode *, struct f2fs_extent *); 2123 2071 unsigned int f2fs_destroy_extent_node(struct inode *); 2124 2072 void f2fs_destroy_extent_tree(struct inode *); 2125 2073 bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *);
+274 -70
fs/f2fs/file.c
··· 40 40 struct dnode_of_data dn; 41 41 int err; 42 42 43 - f2fs_balance_fs(sbi); 44 - 45 43 sb_start_pagefault(inode->i_sb); 46 44 47 45 f2fs_bug_on(sbi, f2fs_has_inline_data(inode)); ··· 54 56 } 55 57 f2fs_put_dnode(&dn); 56 58 f2fs_unlock_op(sbi); 59 + 60 + f2fs_balance_fs(sbi, dn.node_changed); 57 61 58 62 file_update_time(vma->vm_file); 59 63 lock_page(page); ··· 96 96 clear_cold_data(page); 97 97 out: 98 98 sb_end_pagefault(inode->i_sb); 99 + f2fs_update_time(sbi, REQ_TIME); 99 100 return block_page_mkwrite_return(err); 100 101 } 101 102 ··· 202 201 trace_f2fs_sync_file_enter(inode); 203 202 204 203 /* if fdatasync is triggered, let's do in-place-update */ 205 - if (get_dirty_pages(inode) <= SM_I(sbi)->min_fsync_blocks) 204 + if (datasync || get_dirty_pages(inode) <= SM_I(sbi)->min_fsync_blocks) 206 205 set_inode_flag(fi, FI_NEED_IPU); 207 206 ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 208 207 clear_inode_flag(fi, FI_NEED_IPU); ··· 234 233 goto out; 235 234 } 236 235 go_write: 237 - /* guarantee free sections for fsync */ 238 - f2fs_balance_fs(sbi); 239 - 240 236 /* 241 237 * Both of fdatasync() and fsync() are able to be recovered from 242 238 * sudden-power-off. ··· 259 261 sync_node_pages(sbi, ino, &wbc); 260 262 261 263 /* if cp_error was enabled, we should avoid infinite loop */ 262 - if (unlikely(f2fs_cp_error(sbi))) 264 + if (unlikely(f2fs_cp_error(sbi))) { 265 + ret = -EIO; 263 266 goto out; 267 + } 264 268 265 269 if (need_inode_block_update(sbi, ino)) { 266 270 mark_inode_dirty_sync(inode); ··· 275 275 goto out; 276 276 277 277 /* once recovery info is written, don't need to tack this */ 278 - remove_dirty_inode(sbi, ino, APPEND_INO); 278 + remove_ino_entry(sbi, ino, APPEND_INO); 279 279 clear_inode_flag(fi, FI_APPEND_WRITE); 280 280 flush_out: 281 - remove_dirty_inode(sbi, ino, UPDATE_INO); 281 + remove_ino_entry(sbi, ino, UPDATE_INO); 282 282 clear_inode_flag(fi, FI_UPDATE_WRITE); 283 283 ret = f2fs_issue_flush(sbi); 284 + f2fs_update_time(sbi, REQ_TIME); 284 285 out: 285 286 trace_f2fs_sync_file_exit(inode, need_cp, datasync, ret); 286 287 f2fs_trace_ios(NULL, 1); ··· 419 418 static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma) 420 419 { 421 420 struct inode *inode = file_inode(file); 421 + int err; 422 422 423 423 if (f2fs_encrypted_inode(inode)) { 424 - int err = f2fs_get_encryption_info(inode); 424 + err = f2fs_get_encryption_info(inode); 425 425 if (err) 426 426 return 0; 427 427 } 428 428 429 429 /* we don't need to use inline_data strictly */ 430 - if (f2fs_has_inline_data(inode)) { 431 - int err = f2fs_convert_inline_inode(inode); 432 - if (err) 433 - return err; 434 - } 430 + err = f2fs_convert_inline_inode(inode); 431 + if (err) 432 + return err; 435 433 436 434 file_accessed(file); 437 435 vma->vm_ops = &f2fs_file_vm_ops; ··· 483 483 F2FS_I(dn->inode)) + ofs; 484 484 f2fs_update_extent_cache_range(dn, fofs, 0, len); 485 485 dec_valid_block_count(sbi, dn->inode, nr_free); 486 - set_page_dirty(dn->node_page); 487 486 sync_inode_page(dn); 488 487 } 489 488 dn->ofs_in_node = ofs; 490 489 490 + f2fs_update_time(sbi, REQ_TIME); 491 491 trace_f2fs_truncate_data_blocks_range(dn->inode, dn->nid, 492 492 dn->ofs_in_node, nr_free); 493 493 return nr_free; ··· 604 604 trace_f2fs_truncate(inode); 605 605 606 606 /* we should check inline_data size */ 607 - if (f2fs_has_inline_data(inode) && !f2fs_may_inline_data(inode)) { 607 + if (!f2fs_may_inline_data(inode)) { 608 608 err = f2fs_convert_inline_inode(inode); 609 609 if (err) 610 610 return err; ··· 679 679 err = f2fs_truncate(inode, true); 680 680 if (err) 681 681 return err; 682 - f2fs_balance_fs(F2FS_I_SB(inode)); 682 + f2fs_balance_fs(F2FS_I_SB(inode), true); 683 683 } else { 684 684 /* 685 685 * do not trim all blocks after i_size if target size is 686 686 * larger than i_size. 687 687 */ 688 688 truncate_setsize(inode, attr->ia_size); 689 + 690 + /* should convert inline inode here */ 691 + if (!f2fs_may_inline_data(inode)) { 692 + err = f2fs_convert_inline_inode(inode); 693 + if (err) 694 + return err; 695 + } 689 696 inode->i_mtime = inode->i_ctime = CURRENT_TIME; 690 697 } 691 698 } ··· 734 727 if (!len) 735 728 return 0; 736 729 737 - f2fs_balance_fs(sbi); 730 + f2fs_balance_fs(sbi, true); 738 731 739 732 f2fs_lock_op(sbi); 740 733 page = get_new_data_page(inode, NULL, index, false); ··· 785 778 { 786 779 pgoff_t pg_start, pg_end; 787 780 loff_t off_start, off_end; 788 - int ret = 0; 781 + int ret; 789 782 790 - if (f2fs_has_inline_data(inode)) { 791 - ret = f2fs_convert_inline_inode(inode); 792 - if (ret) 793 - return ret; 794 - } 783 + ret = f2fs_convert_inline_inode(inode); 784 + if (ret) 785 + return ret; 795 786 796 787 pg_start = ((unsigned long long) offset) >> PAGE_CACHE_SHIFT; 797 788 pg_end = ((unsigned long long) offset + len) >> PAGE_CACHE_SHIFT; ··· 820 815 loff_t blk_start, blk_end; 821 816 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 822 817 823 - f2fs_balance_fs(sbi); 818 + f2fs_balance_fs(sbi, true); 824 819 825 820 blk_start = (loff_t)pg_start << PAGE_CACHE_SHIFT; 826 821 blk_end = (loff_t)pg_end << PAGE_CACHE_SHIFT; ··· 923 918 int ret = 0; 924 919 925 920 for (; end < nrpages; start++, end++) { 926 - f2fs_balance_fs(sbi); 921 + f2fs_balance_fs(sbi, true); 927 922 f2fs_lock_op(sbi); 928 923 ret = __exchange_data_block(inode, end, start, true); 929 924 f2fs_unlock_op(sbi); ··· 946 941 if (offset & (F2FS_BLKSIZE - 1) || len & (F2FS_BLKSIZE - 1)) 947 942 return -EINVAL; 948 943 949 - f2fs_balance_fs(F2FS_I_SB(inode)); 950 - 951 - if (f2fs_has_inline_data(inode)) { 952 - ret = f2fs_convert_inline_inode(inode); 953 - if (ret) 954 - return ret; 955 - } 944 + ret = f2fs_convert_inline_inode(inode); 945 + if (ret) 946 + return ret; 956 947 957 948 pg_start = offset >> PAGE_CACHE_SHIFT; 958 949 pg_end = (offset + len) >> PAGE_CACHE_SHIFT; ··· 992 991 if (ret) 993 992 return ret; 994 993 995 - f2fs_balance_fs(sbi); 996 - 997 - if (f2fs_has_inline_data(inode)) { 998 - ret = f2fs_convert_inline_inode(inode); 999 - if (ret) 1000 - return ret; 1001 - } 994 + ret = f2fs_convert_inline_inode(inode); 995 + if (ret) 996 + return ret; 1002 997 1003 998 ret = filemap_write_and_wait_range(mapping, offset, offset + len - 1); 1004 999 if (ret) ··· 1101 1104 if (offset & (F2FS_BLKSIZE - 1) || len & (F2FS_BLKSIZE - 1)) 1102 1105 return -EINVAL; 1103 1106 1104 - f2fs_balance_fs(sbi); 1107 + ret = f2fs_convert_inline_inode(inode); 1108 + if (ret) 1109 + return ret; 1105 1110 1106 - if (f2fs_has_inline_data(inode)) { 1107 - ret = f2fs_convert_inline_inode(inode); 1108 - if (ret) 1109 - return ret; 1110 - } 1111 + f2fs_balance_fs(sbi, true); 1111 1112 1112 1113 ret = truncate_blocks(inode, i_size_read(inode), true); 1113 1114 if (ret) ··· 1149 1154 loff_t off_start, off_end; 1150 1155 int ret = 0; 1151 1156 1152 - f2fs_balance_fs(sbi); 1153 - 1154 1157 ret = inode_newsize_ok(inode, (len + offset)); 1155 1158 if (ret) 1156 1159 return ret; 1157 1160 1158 - if (f2fs_has_inline_data(inode)) { 1159 - ret = f2fs_convert_inline_inode(inode); 1160 - if (ret) 1161 - return ret; 1162 - } 1161 + ret = f2fs_convert_inline_inode(inode); 1162 + if (ret) 1163 + return ret; 1164 + 1165 + f2fs_balance_fs(sbi, true); 1163 1166 1164 1167 pg_start = ((unsigned long long) offset) >> PAGE_CACHE_SHIFT; 1165 1168 pg_end = ((unsigned long long) offset + len) >> PAGE_CACHE_SHIFT; ··· 1239 1246 if (!ret) { 1240 1247 inode->i_mtime = inode->i_ctime = CURRENT_TIME; 1241 1248 mark_inode_dirty(inode); 1249 + f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); 1242 1250 } 1243 1251 1244 1252 out: ··· 1347 1353 if (!inode_owner_or_capable(inode)) 1348 1354 return -EACCES; 1349 1355 1350 - f2fs_balance_fs(F2FS_I_SB(inode)); 1351 - 1352 1356 if (f2fs_is_atomic_file(inode)) 1353 1357 return 0; 1354 1358 ··· 1355 1363 return ret; 1356 1364 1357 1365 set_inode_flag(F2FS_I(inode), FI_ATOMIC_FILE); 1366 + f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); 1367 + 1358 1368 return 0; 1359 1369 } 1360 1370 ··· 1378 1384 if (f2fs_is_atomic_file(inode)) { 1379 1385 clear_inode_flag(F2FS_I(inode), FI_ATOMIC_FILE); 1380 1386 ret = commit_inmem_pages(inode, false); 1381 - if (ret) 1387 + if (ret) { 1388 + set_inode_flag(F2FS_I(inode), FI_ATOMIC_FILE); 1382 1389 goto err_out; 1390 + } 1383 1391 } 1384 1392 1385 1393 ret = f2fs_sync_file(filp, 0, LLONG_MAX, 0); ··· 1406 1410 return ret; 1407 1411 1408 1412 set_inode_flag(F2FS_I(inode), FI_VOLATILE_FILE); 1413 + f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); 1409 1414 return 0; 1410 1415 } 1411 1416 ··· 1438 1441 if (ret) 1439 1442 return ret; 1440 1443 1441 - f2fs_balance_fs(F2FS_I_SB(inode)); 1442 - 1443 - clear_inode_flag(F2FS_I(inode), FI_ATOMIC_FILE); 1444 - clear_inode_flag(F2FS_I(inode), FI_VOLATILE_FILE); 1445 - commit_inmem_pages(inode, true); 1444 + if (f2fs_is_atomic_file(inode)) { 1445 + clear_inode_flag(F2FS_I(inode), FI_ATOMIC_FILE); 1446 + commit_inmem_pages(inode, true); 1447 + } 1448 + if (f2fs_is_volatile_file(inode)) { 1449 + clear_inode_flag(F2FS_I(inode), FI_VOLATILE_FILE); 1450 + ret = f2fs_sync_file(filp, 0, LLONG_MAX, 0); 1451 + } 1446 1452 1447 1453 mnt_drop_write_file(filp); 1454 + f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); 1448 1455 return ret; 1449 1456 } 1450 1457 ··· 1488 1487 default: 1489 1488 return -EINVAL; 1490 1489 } 1490 + f2fs_update_time(sbi, REQ_TIME); 1491 1491 return 0; 1492 1492 } 1493 1493 ··· 1519 1517 if (copy_to_user((struct fstrim_range __user *)arg, &range, 1520 1518 sizeof(range))) 1521 1519 return -EFAULT; 1520 + f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); 1522 1521 return 0; 1523 1522 } 1524 1523 ··· 1543 1540 sizeof(policy))) 1544 1541 return -EFAULT; 1545 1542 1543 + f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); 1546 1544 return f2fs_process_policy(&policy, inode); 1547 1545 #else 1548 1546 return -EOPNOTSUPP; ··· 1590 1586 generate_random_uuid(sbi->raw_super->encrypt_pw_salt); 1591 1587 1592 1588 err = f2fs_commit_super(sbi, false); 1593 - 1594 - mnt_drop_write_file(filp); 1595 1589 if (err) { 1596 1590 /* undo new data */ 1597 1591 memset(sbi->raw_super->encrypt_pw_salt, 0, 16); 1592 + mnt_drop_write_file(filp); 1598 1593 return err; 1599 1594 } 1595 + mnt_drop_write_file(filp); 1600 1596 got_it: 1601 1597 if (copy_to_user((__u8 __user *)arg, sbi->raw_super->encrypt_pw_salt, 1602 1598 16)) ··· 1633 1629 { 1634 1630 struct inode *inode = file_inode(filp); 1635 1631 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 1636 - struct cp_control cpc; 1637 1632 1638 1633 if (!capable(CAP_SYS_ADMIN)) 1639 1634 return -EPERM; ··· 1640 1637 if (f2fs_readonly(sbi->sb)) 1641 1638 return -EROFS; 1642 1639 1643 - cpc.reason = __get_cp_reason(sbi); 1640 + return f2fs_sync_fs(sbi->sb, 1); 1641 + } 1644 1642 1645 - mutex_lock(&sbi->gc_mutex); 1646 - write_checkpoint(sbi, &cpc); 1647 - mutex_unlock(&sbi->gc_mutex); 1643 + static int f2fs_defragment_range(struct f2fs_sb_info *sbi, 1644 + struct file *filp, 1645 + struct f2fs_defragment *range) 1646 + { 1647 + struct inode *inode = file_inode(filp); 1648 + struct f2fs_map_blocks map; 1649 + struct extent_info ei; 1650 + pgoff_t pg_start, pg_end; 1651 + unsigned int blk_per_seg = sbi->blocks_per_seg; 1652 + unsigned int total = 0, sec_num; 1653 + unsigned int pages_per_sec = sbi->segs_per_sec * blk_per_seg; 1654 + block_t blk_end = 0; 1655 + bool fragmented = false; 1656 + int err; 1648 1657 1649 - return 0; 1658 + /* if in-place-update policy is enabled, don't waste time here */ 1659 + if (need_inplace_update(inode)) 1660 + return -EINVAL; 1661 + 1662 + pg_start = range->start >> PAGE_CACHE_SHIFT; 1663 + pg_end = (range->start + range->len) >> PAGE_CACHE_SHIFT; 1664 + 1665 + f2fs_balance_fs(sbi, true); 1666 + 1667 + mutex_lock(&inode->i_mutex); 1668 + 1669 + /* writeback all dirty pages in the range */ 1670 + err = filemap_write_and_wait_range(inode->i_mapping, range->start, 1671 + range->start + range->len - 1); 1672 + if (err) 1673 + goto out; 1674 + 1675 + /* 1676 + * lookup mapping info in extent cache, skip defragmenting if physical 1677 + * block addresses are continuous. 1678 + */ 1679 + if (f2fs_lookup_extent_cache(inode, pg_start, &ei)) { 1680 + if (ei.fofs + ei.len >= pg_end) 1681 + goto out; 1682 + } 1683 + 1684 + map.m_lblk = pg_start; 1685 + 1686 + /* 1687 + * lookup mapping info in dnode page cache, skip defragmenting if all 1688 + * physical block addresses are continuous even if there are hole(s) 1689 + * in logical blocks. 1690 + */ 1691 + while (map.m_lblk < pg_end) { 1692 + map.m_len = pg_end - map.m_lblk; 1693 + err = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_READ); 1694 + if (err) 1695 + goto out; 1696 + 1697 + if (!(map.m_flags & F2FS_MAP_FLAGS)) { 1698 + map.m_lblk++; 1699 + continue; 1700 + } 1701 + 1702 + if (blk_end && blk_end != map.m_pblk) { 1703 + fragmented = true; 1704 + break; 1705 + } 1706 + blk_end = map.m_pblk + map.m_len; 1707 + 1708 + map.m_lblk += map.m_len; 1709 + } 1710 + 1711 + if (!fragmented) 1712 + goto out; 1713 + 1714 + map.m_lblk = pg_start; 1715 + map.m_len = pg_end - pg_start; 1716 + 1717 + sec_num = (map.m_len + pages_per_sec - 1) / pages_per_sec; 1718 + 1719 + /* 1720 + * make sure there are enough free section for LFS allocation, this can 1721 + * avoid defragment running in SSR mode when free section are allocated 1722 + * intensively 1723 + */ 1724 + if (has_not_enough_free_secs(sbi, sec_num)) { 1725 + err = -EAGAIN; 1726 + goto out; 1727 + } 1728 + 1729 + while (map.m_lblk < pg_end) { 1730 + pgoff_t idx; 1731 + int cnt = 0; 1732 + 1733 + do_map: 1734 + map.m_len = pg_end - map.m_lblk; 1735 + err = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_READ); 1736 + if (err) 1737 + goto clear_out; 1738 + 1739 + if (!(map.m_flags & F2FS_MAP_FLAGS)) { 1740 + map.m_lblk++; 1741 + continue; 1742 + } 1743 + 1744 + set_inode_flag(F2FS_I(inode), FI_DO_DEFRAG); 1745 + 1746 + idx = map.m_lblk; 1747 + while (idx < map.m_lblk + map.m_len && cnt < blk_per_seg) { 1748 + struct page *page; 1749 + 1750 + page = get_lock_data_page(inode, idx, true); 1751 + if (IS_ERR(page)) { 1752 + err = PTR_ERR(page); 1753 + goto clear_out; 1754 + } 1755 + 1756 + set_page_dirty(page); 1757 + f2fs_put_page(page, 1); 1758 + 1759 + idx++; 1760 + cnt++; 1761 + total++; 1762 + } 1763 + 1764 + map.m_lblk = idx; 1765 + 1766 + if (idx < pg_end && cnt < blk_per_seg) 1767 + goto do_map; 1768 + 1769 + clear_inode_flag(F2FS_I(inode), FI_DO_DEFRAG); 1770 + 1771 + err = filemap_fdatawrite(inode->i_mapping); 1772 + if (err) 1773 + goto out; 1774 + } 1775 + clear_out: 1776 + clear_inode_flag(F2FS_I(inode), FI_DO_DEFRAG); 1777 + out: 1778 + mutex_unlock(&inode->i_mutex); 1779 + if (!err) 1780 + range->len = (u64)total << PAGE_CACHE_SHIFT; 1781 + return err; 1782 + } 1783 + 1784 + static int f2fs_ioc_defragment(struct file *filp, unsigned long arg) 1785 + { 1786 + struct inode *inode = file_inode(filp); 1787 + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 1788 + struct f2fs_defragment range; 1789 + int err; 1790 + 1791 + if (!capable(CAP_SYS_ADMIN)) 1792 + return -EPERM; 1793 + 1794 + if (!S_ISREG(inode->i_mode)) 1795 + return -EINVAL; 1796 + 1797 + err = mnt_want_write_file(filp); 1798 + if (err) 1799 + return err; 1800 + 1801 + if (f2fs_readonly(sbi->sb)) { 1802 + err = -EROFS; 1803 + goto out; 1804 + } 1805 + 1806 + if (copy_from_user(&range, (struct f2fs_defragment __user *)arg, 1807 + sizeof(range))) { 1808 + err = -EFAULT; 1809 + goto out; 1810 + } 1811 + 1812 + /* verify alignment of offset & size */ 1813 + if (range.start & (F2FS_BLKSIZE - 1) || 1814 + range.len & (F2FS_BLKSIZE - 1)) { 1815 + err = -EINVAL; 1816 + goto out; 1817 + } 1818 + 1819 + err = f2fs_defragment_range(sbi, filp, &range); 1820 + f2fs_update_time(sbi, REQ_TIME); 1821 + if (err < 0) 1822 + goto out; 1823 + 1824 + if (copy_to_user((struct f2fs_defragment __user *)arg, &range, 1825 + sizeof(range))) 1826 + err = -EFAULT; 1827 + out: 1828 + mnt_drop_write_file(filp); 1829 + return err; 1650 1830 } 1651 1831 1652 1832 long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ··· 1865 1679 return f2fs_ioc_gc(filp, arg); 1866 1680 case F2FS_IOC_WRITE_CHECKPOINT: 1867 1681 return f2fs_ioc_write_checkpoint(filp, arg); 1682 + case F2FS_IOC_DEFRAGMENT: 1683 + return f2fs_ioc_defragment(filp, arg); 1868 1684 default: 1869 1685 return -ENOTTY; 1870 1686 } ··· 1893 1705 break; 1894 1706 case F2FS_IOC32_SETFLAGS: 1895 1707 cmd = F2FS_IOC_SETFLAGS; 1708 + break; 1709 + case F2FS_IOC32_GETVERSION: 1710 + cmd = F2FS_IOC_GETVERSION; 1711 + break; 1712 + case F2FS_IOC_START_ATOMIC_WRITE: 1713 + case F2FS_IOC_COMMIT_ATOMIC_WRITE: 1714 + case F2FS_IOC_START_VOLATILE_WRITE: 1715 + case F2FS_IOC_RELEASE_VOLATILE_WRITE: 1716 + case F2FS_IOC_ABORT_VOLATILE_WRITE: 1717 + case F2FS_IOC_SHUTDOWN: 1718 + case F2FS_IOC_SET_ENCRYPTION_POLICY: 1719 + case F2FS_IOC_GET_ENCRYPTION_PWSALT: 1720 + case F2FS_IOC_GET_ENCRYPTION_POLICY: 1721 + case F2FS_IOC_GARBAGE_COLLECT: 1722 + case F2FS_IOC_WRITE_CHECKPOINT: 1723 + case F2FS_IOC_DEFRAGMENT: 1896 1724 break; 1897 1725 default: 1898 1726 return -ENOIOCTLCMD;
+5 -4
fs/f2fs/gc.c
··· 16 16 #include <linux/kthread.h> 17 17 #include <linux/delay.h> 18 18 #include <linux/freezer.h> 19 - #include <linux/blkdev.h> 20 19 21 20 #include "f2fs.h" 22 21 #include "node.h" ··· 172 173 { 173 174 /* SSR allocates in a segment unit */ 174 175 if (p->alloc_mode == SSR) 175 - return 1 << sbi->log_blocks_per_seg; 176 + return sbi->blocks_per_seg; 176 177 if (p->gc_mode == GC_GREEDY) 177 - return (1 << sbi->log_blocks_per_seg) * p->ofs_unit; 178 + return sbi->blocks_per_seg * p->ofs_unit; 178 179 else if (p->gc_mode == GC_CB) 179 180 return UINT_MAX; 180 181 else /* No other gc_mode */ ··· 831 832 832 833 if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE))) 833 834 goto stop; 834 - if (unlikely(f2fs_cp_error(sbi))) 835 + if (unlikely(f2fs_cp_error(sbi))) { 836 + ret = -EIO; 835 837 goto stop; 838 + } 836 839 837 840 if (gc_type == BG_GC && has_not_enough_free_secs(sbi, sec_freed)) { 838 841 gc_type = FG_GC;
-8
fs/f2fs/gc.h
··· 100 100 return true; 101 101 return false; 102 102 } 103 - 104 - static inline int is_idle(struct f2fs_sb_info *sbi) 105 - { 106 - struct block_device *bdev = sbi->sb->s_bdev; 107 - struct request_queue *q = bdev_get_queue(bdev); 108 - struct request_list *rl = &q->root_rl; 109 - return !(rl->count[BLK_RW_SYNC]) && !(rl->count[BLK_RW_ASYNC]); 110 - }
+6 -3
fs/f2fs/inline.c
··· 16 16 17 17 bool f2fs_may_inline_data(struct inode *inode) 18 18 { 19 - if (!test_opt(F2FS_I_SB(inode), INLINE_DATA)) 20 - return false; 21 - 22 19 if (f2fs_is_atomic_file(inode)) 23 20 return false; 24 21 ··· 174 177 struct page *ipage, *page; 175 178 int err = 0; 176 179 180 + if (!f2fs_has_inline_data(inode)) 181 + return 0; 182 + 177 183 page = grab_cache_page(inode->i_mapping, 0); 178 184 if (!page) 179 185 return -ENOMEM; ··· 199 199 f2fs_unlock_op(sbi); 200 200 201 201 f2fs_put_page(page, 1); 202 + 203 + f2fs_balance_fs(sbi, dn.node_changed); 204 + 202 205 return err; 203 206 } 204 207
+15 -13
fs/f2fs/inode.c
··· 138 138 fi->i_pino = le32_to_cpu(ri->i_pino); 139 139 fi->i_dir_level = ri->i_dir_level; 140 140 141 - f2fs_init_extent_tree(inode, &ri->i_ext); 141 + if (f2fs_init_extent_tree(inode, &ri->i_ext)) 142 + set_page_dirty(node_page); 142 143 143 144 get_inline_info(fi, ri); 144 145 ··· 223 222 return ERR_PTR(ret); 224 223 } 225 224 226 - void update_inode(struct inode *inode, struct page *node_page) 225 + int update_inode(struct inode *inode, struct page *node_page) 227 226 { 228 227 struct f2fs_inode *ri; 229 228 ··· 261 260 262 261 __set_inode_rdev(inode, ri); 263 262 set_cold_node(inode, node_page); 264 - set_page_dirty(node_page); 265 - 266 263 clear_inode_flag(F2FS_I(inode), FI_DIRTY_INODE); 264 + 265 + return set_page_dirty(node_page); 267 266 } 268 267 269 - void update_inode_page(struct inode *inode) 268 + int update_inode_page(struct inode *inode) 270 269 { 271 270 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 272 271 struct page *node_page; 272 + int ret = 0; 273 273 retry: 274 274 node_page = get_node_page(sbi, inode->i_ino); 275 275 if (IS_ERR(node_page)) { ··· 281 279 } else if (err != -ENOENT) { 282 280 f2fs_stop_checkpoint(sbi); 283 281 } 284 - return; 282 + return 0; 285 283 } 286 - update_inode(inode, node_page); 284 + ret = update_inode(inode, node_page); 287 285 f2fs_put_page(node_page, 1); 286 + return ret; 288 287 } 289 288 290 289 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc) ··· 303 300 * We need to balance fs here to prevent from producing dirty node pages 304 301 * during the urgent cleaning time when runing out of free sections. 305 302 */ 306 - update_inode_page(inode); 307 - 308 - f2fs_balance_fs(sbi); 303 + if (update_inode_page(inode)) 304 + f2fs_balance_fs(sbi, true); 309 305 return 0; 310 306 } 311 307 ··· 330 328 goto out_clear; 331 329 332 330 f2fs_bug_on(sbi, get_dirty_pages(inode)); 333 - remove_dirty_dir_inode(inode); 331 + remove_dirty_inode(inode); 334 332 335 333 f2fs_destroy_extent_tree(inode); 336 334 ··· 360 358 if (xnid) 361 359 invalidate_mapping_pages(NODE_MAPPING(sbi), xnid, xnid); 362 360 if (is_inode_flag_set(fi, FI_APPEND_WRITE)) 363 - add_dirty_inode(sbi, inode->i_ino, APPEND_INO); 361 + add_ino_entry(sbi, inode->i_ino, APPEND_INO); 364 362 if (is_inode_flag_set(fi, FI_UPDATE_WRITE)) 365 - add_dirty_inode(sbi, inode->i_ino, UPDATE_INO); 363 + add_ino_entry(sbi, inode->i_ino, UPDATE_INO); 366 364 if (is_inode_flag_set(fi, FI_FREE_NID)) { 367 365 if (err && err != -ENOENT) 368 366 alloc_nid_done(sbi, inode->i_ino);
+39 -20
fs/f2fs/namei.c
··· 60 60 if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode)) 61 61 f2fs_set_encrypted_inode(inode); 62 62 63 - if (f2fs_may_inline_data(inode)) 63 + if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode)) 64 64 set_inode_flag(F2FS_I(inode), FI_INLINE_DATA); 65 65 if (f2fs_may_inline_dentry(inode)) 66 66 set_inode_flag(F2FS_I(inode), FI_INLINE_DENTRY); ··· 128 128 nid_t ino = 0; 129 129 int err; 130 130 131 - f2fs_balance_fs(sbi); 132 - 133 131 inode = f2fs_new_inode(dir, mode); 134 132 if (IS_ERR(inode)) 135 133 return PTR_ERR(inode); ··· 139 141 inode->i_fop = &f2fs_file_operations; 140 142 inode->i_mapping->a_ops = &f2fs_dblock_aops; 141 143 ino = inode->i_ino; 144 + 145 + f2fs_balance_fs(sbi, true); 142 146 143 147 f2fs_lock_op(sbi); 144 148 err = f2fs_add_link(dentry, inode); ··· 172 172 !f2fs_is_child_context_consistent_with_parent(dir, inode)) 173 173 return -EPERM; 174 174 175 - f2fs_balance_fs(sbi); 175 + f2fs_balance_fs(sbi, true); 176 176 177 177 inode->i_ctime = CURRENT_TIME; 178 178 ihold(inode); ··· 213 213 struct f2fs_dir_entry *de; 214 214 struct page *page; 215 215 int err = 0; 216 + 217 + if (f2fs_readonly(sbi->sb)) { 218 + f2fs_msg(sbi->sb, KERN_INFO, 219 + "skip recovering inline_dots inode (ino:%lu, pino:%u) " 220 + "in readonly mountpoint", dir->i_ino, pino); 221 + return 0; 222 + } 223 + 224 + f2fs_balance_fs(sbi, true); 216 225 217 226 f2fs_lock_op(sbi); 218 227 ··· 297 288 int err = -ENOENT; 298 289 299 290 trace_f2fs_unlink_enter(dir, dentry); 300 - f2fs_balance_fs(sbi); 301 291 302 292 de = f2fs_find_entry(dir, &dentry->d_name, &page); 303 293 if (!de) 304 294 goto fail; 295 + 296 + f2fs_balance_fs(sbi, true); 305 297 306 298 f2fs_lock_op(sbi); 307 299 err = acquire_orphan_inode(sbi); ··· 354 344 if (len > dir->i_sb->s_blocksize) 355 345 return -ENAMETOOLONG; 356 346 357 - f2fs_balance_fs(sbi); 358 - 359 347 inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO); 360 348 if (IS_ERR(inode)) 361 349 return PTR_ERR(inode); ··· 364 356 inode->i_op = &f2fs_symlink_inode_operations; 365 357 inode_nohighmem(inode); 366 358 inode->i_mapping->a_ops = &f2fs_dblock_aops; 359 + 360 + f2fs_balance_fs(sbi, true); 367 361 368 362 f2fs_lock_op(sbi); 369 363 err = f2fs_add_link(dentry, inode); ··· 447 437 struct inode *inode; 448 438 int err; 449 439 450 - f2fs_balance_fs(sbi); 451 - 452 440 inode = f2fs_new_inode(dir, S_IFDIR | mode); 453 441 if (IS_ERR(inode)) 454 442 return PTR_ERR(inode); ··· 455 447 inode->i_fop = &f2fs_dir_operations; 456 448 inode->i_mapping->a_ops = &f2fs_dblock_aops; 457 449 mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_HIGH_ZERO); 450 + 451 + f2fs_balance_fs(sbi, true); 458 452 459 453 set_inode_flag(F2FS_I(inode), FI_INC_LINK); 460 454 f2fs_lock_op(sbi); ··· 495 485 struct inode *inode; 496 486 int err = 0; 497 487 498 - f2fs_balance_fs(sbi); 499 - 500 488 inode = f2fs_new_inode(dir, mode); 501 489 if (IS_ERR(inode)) 502 490 return PTR_ERR(inode); 503 491 504 492 init_special_inode(inode, inode->i_mode, rdev); 505 493 inode->i_op = &f2fs_special_inode_operations; 494 + 495 + f2fs_balance_fs(sbi, true); 506 496 507 497 f2fs_lock_op(sbi); 508 498 err = f2fs_add_link(dentry, inode); ··· 530 520 struct inode *inode; 531 521 int err; 532 522 533 - if (!whiteout) 534 - f2fs_balance_fs(sbi); 535 - 536 523 inode = f2fs_new_inode(dir, mode); 537 524 if (IS_ERR(inode)) 538 525 return PTR_ERR(inode); ··· 542 535 inode->i_fop = &f2fs_file_operations; 543 536 inode->i_mapping->a_ops = &f2fs_dblock_aops; 544 537 } 538 + 539 + f2fs_balance_fs(sbi, true); 545 540 546 541 f2fs_lock_op(sbi); 547 542 err = acquire_orphan_inode(sbi); ··· 617 608 goto out; 618 609 } 619 610 620 - f2fs_balance_fs(sbi); 621 - 622 611 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page); 623 612 if (!old_entry) 624 613 goto out; ··· 645 638 &new_page); 646 639 if (!new_entry) 647 640 goto out_whiteout; 641 + 642 + f2fs_balance_fs(sbi, true); 648 643 649 644 f2fs_lock_op(sbi); 650 645 ··· 679 670 update_inode_page(old_inode); 680 671 update_inode_page(new_inode); 681 672 } else { 673 + f2fs_balance_fs(sbi, true); 674 + 682 675 f2fs_lock_op(sbi); 683 676 684 677 err = f2fs_add_link(new_dentry, old_inode); ··· 778 767 new_inode))) 779 768 return -EPERM; 780 769 781 - f2fs_balance_fs(sbi); 782 - 783 770 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page); 784 771 if (!old_entry) 785 772 goto out; ··· 819 810 (new_nlink > 0 && new_inode->i_nlink >= F2FS_LINK_MAX)) 820 811 goto out_new_dir; 821 812 } 813 + 814 + f2fs_balance_fs(sbi, true); 822 815 823 816 f2fs_lock_op(sbi); 824 817 ··· 944 933 { 945 934 struct page *cpage = NULL; 946 935 char *caddr, *paddr = NULL; 947 - struct f2fs_str cstr; 936 + struct f2fs_str cstr = FSTR_INIT(NULL, 0); 948 937 struct f2fs_str pstr = FSTR_INIT(NULL, 0); 949 938 struct f2fs_encrypted_symlink_data *sd; 950 939 loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1); ··· 967 956 /* Symlink is encrypted */ 968 957 sd = (struct f2fs_encrypted_symlink_data *)caddr; 969 958 cstr.len = le16_to_cpu(sd->len); 959 + 960 + /* this is broken symlink case */ 961 + if (unlikely(cstr.len == 0)) { 962 + res = -ENOENT; 963 + goto errout; 964 + } 970 965 cstr.name = kmalloc(cstr.len, GFP_NOFS); 971 966 if (!cstr.name) { 972 967 res = -ENOMEM; ··· 981 964 memcpy(cstr.name, sd->encrypted_path, cstr.len); 982 965 983 966 /* this is broken symlink case */ 984 - if (cstr.name[0] == 0 && cstr.len == 0) { 967 + if (unlikely(cstr.name[0] == 0)) { 985 968 res = -ENOENT; 986 969 goto errout; 987 970 } ··· 1022 1005 .get_link = f2fs_encrypted_get_link, 1023 1006 .getattr = f2fs_getattr, 1024 1007 .setattr = f2fs_setattr, 1008 + #ifdef CONFIG_F2FS_FS_XATTR 1025 1009 .setxattr = generic_setxattr, 1026 1010 .getxattr = generic_getxattr, 1027 1011 .listxattr = f2fs_listxattr, 1028 1012 .removexattr = generic_removexattr, 1013 + #endif 1029 1014 }; 1030 1015 #endif 1031 1016
+84 -90
fs/f2fs/node.c
··· 65 65 sizeof(struct ino_entry)) >> PAGE_CACHE_SHIFT; 66 66 res = mem_size < ((avail_ram * nm_i->ram_thresh / 100) >> 1); 67 67 } else if (type == EXTENT_CACHE) { 68 - mem_size = (sbi->total_ext_tree * sizeof(struct extent_tree) + 68 + mem_size = (atomic_read(&sbi->total_ext_tree) * 69 + sizeof(struct extent_tree) + 69 70 atomic_read(&sbi->total_ext_node) * 70 71 sizeof(struct extent_node)) >> PAGE_CACHE_SHIFT; 71 72 res = mem_size < ((avail_ram * nm_i->ram_thresh / 100) >> 1); 72 73 } else { 73 - if (sbi->sb->s_bdi->wb.dirty_exceeded) 74 - return false; 74 + if (!sbi->sb->s_bdi->wb.dirty_exceeded) 75 + return true; 75 76 } 76 77 return res; 77 78 } ··· 262 261 { 263 262 struct nat_entry *e; 264 263 265 - down_write(&nm_i->nat_tree_lock); 266 264 e = __lookup_nat_cache(nm_i, nid); 267 265 if (!e) { 268 266 e = grab_nat_entry(nm_i, nid); 269 267 node_info_from_raw_nat(&e->ni, ne); 270 268 } 271 - up_write(&nm_i->nat_tree_lock); 272 269 } 273 270 274 271 static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni, ··· 378 379 379 380 memset(&ne, 0, sizeof(struct f2fs_nat_entry)); 380 381 382 + down_write(&nm_i->nat_tree_lock); 383 + 381 384 /* Check current segment summary */ 382 385 mutex_lock(&curseg->curseg_mutex); 383 386 i = lookup_journal_in_cursum(sum, NAT_JOURNAL, nid, 0); ··· 400 399 cache: 401 400 /* cache nat entry */ 402 401 cache_nat_entry(NM_I(sbi), nid, &ne); 402 + up_write(&nm_i->nat_tree_lock); 403 403 } 404 404 405 405 /* ··· 678 676 ret = truncate_dnode(&rdn); 679 677 if (ret < 0) 680 678 goto out_err; 681 - set_nid(page, i, 0, false); 679 + if (set_nid(page, i, 0, false)) 680 + dn->node_changed = true; 682 681 } 683 682 } else { 684 683 child_nofs = nofs + ofs * (NIDS_PER_BLOCK + 1) + 1; ··· 692 689 rdn.nid = child_nid; 693 690 ret = truncate_nodes(&rdn, child_nofs, 0, depth - 1); 694 691 if (ret == (NIDS_PER_BLOCK + 1)) { 695 - set_nid(page, i, 0, false); 692 + if (set_nid(page, i, 0, false)) 693 + dn->node_changed = true; 696 694 child_nofs += ret; 697 695 } else if (ret < 0 && ret != -ENOENT) { 698 696 goto out_err; ··· 754 750 err = truncate_dnode(dn); 755 751 if (err < 0) 756 752 goto fail; 757 - set_nid(pages[idx], i, 0, false); 753 + if (set_nid(pages[idx], i, 0, false)) 754 + dn->node_changed = true; 758 755 } 759 756 760 757 if (offset[idx + 1] == 0) { ··· 980 975 fill_node_footer(page, dn->nid, dn->inode->i_ino, ofs, true); 981 976 set_cold_node(dn->inode, page); 982 977 SetPageUptodate(page); 983 - set_page_dirty(page); 978 + if (set_page_dirty(page)) 979 + dn->node_changed = true; 984 980 985 981 if (f2fs_has_xattr_block(ofs)) 986 982 F2FS_I(dn->inode)->i_xattr_nid = dn->nid; ··· 1041 1035 struct page *apage; 1042 1036 int err; 1043 1037 1038 + if (!nid) 1039 + return; 1040 + f2fs_bug_on(sbi, check_nid_range(sbi, nid)); 1041 + 1044 1042 apage = find_get_page(NODE_MAPPING(sbi), nid); 1045 1043 if (apage && PageUptodate(apage)) { 1046 1044 f2fs_put_page(apage, 0); ··· 1060 1050 f2fs_put_page(apage, err ? 1 : 0); 1061 1051 } 1062 1052 1063 - struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid) 1064 - { 1065 - struct page *page; 1066 - int err; 1067 - repeat: 1068 - page = grab_cache_page(NODE_MAPPING(sbi), nid); 1069 - if (!page) 1070 - return ERR_PTR(-ENOMEM); 1071 - 1072 - err = read_node_page(page, READ_SYNC); 1073 - if (err < 0) { 1074 - f2fs_put_page(page, 1); 1075 - return ERR_PTR(err); 1076 - } else if (err != LOCKED_PAGE) { 1077 - lock_page(page); 1078 - } 1079 - 1080 - if (unlikely(!PageUptodate(page) || nid != nid_of_node(page))) { 1081 - ClearPageUptodate(page); 1082 - f2fs_put_page(page, 1); 1083 - return ERR_PTR(-EIO); 1084 - } 1085 - if (unlikely(page->mapping != NODE_MAPPING(sbi))) { 1086 - f2fs_put_page(page, 1); 1087 - goto repeat; 1088 - } 1089 - return page; 1090 - } 1091 - 1092 1053 /* 1093 - * Return a locked page for the desired node page. 1094 - * And, readahead MAX_RA_NODE number of node pages. 1054 + * readahead MAX_RA_NODE number of node pages. 1095 1055 */ 1096 - struct page *get_node_page_ra(struct page *parent, int start) 1056 + void ra_node_pages(struct page *parent, int start) 1097 1057 { 1098 1058 struct f2fs_sb_info *sbi = F2FS_P_SB(parent); 1099 1059 struct blk_plug plug; 1100 - struct page *page; 1101 - int err, i, end; 1060 + int i, end; 1102 1061 nid_t nid; 1103 1062 1104 - /* First, try getting the desired direct node. */ 1105 - nid = get_nid(parent, start, false); 1063 + blk_start_plug(&plug); 1064 + 1065 + /* Then, try readahead for siblings of the desired node */ 1066 + end = start + MAX_RA_NODE; 1067 + end = min(end, NIDS_PER_BLOCK); 1068 + for (i = start; i < end; i++) { 1069 + nid = get_nid(parent, i, false); 1070 + ra_node_page(sbi, nid); 1071 + } 1072 + 1073 + blk_finish_plug(&plug); 1074 + } 1075 + 1076 + struct page *__get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid, 1077 + struct page *parent, int start) 1078 + { 1079 + struct page *page; 1080 + int err; 1081 + 1106 1082 if (!nid) 1107 1083 return ERR_PTR(-ENOENT); 1084 + f2fs_bug_on(sbi, check_nid_range(sbi, nid)); 1108 1085 repeat: 1109 1086 page = grab_cache_page(NODE_MAPPING(sbi), nid); 1110 1087 if (!page) ··· 1105 1108 goto page_hit; 1106 1109 } 1107 1110 1108 - blk_start_plug(&plug); 1109 - 1110 - /* Then, try readahead for siblings of the desired node */ 1111 - end = start + MAX_RA_NODE; 1112 - end = min(end, NIDS_PER_BLOCK); 1113 - for (i = start + 1; i < end; i++) { 1114 - nid = get_nid(parent, i, false); 1115 - if (!nid) 1116 - continue; 1117 - ra_node_page(sbi, nid); 1118 - } 1119 - 1120 - blk_finish_plug(&plug); 1111 + if (parent) 1112 + ra_node_pages(parent, start + 1); 1121 1113 1122 1114 lock_page(page); 1115 + 1116 + if (unlikely(!PageUptodate(page))) { 1117 + f2fs_put_page(page, 1); 1118 + return ERR_PTR(-EIO); 1119 + } 1123 1120 if (unlikely(page->mapping != NODE_MAPPING(sbi))) { 1124 1121 f2fs_put_page(page, 1); 1125 1122 goto repeat; 1126 1123 } 1127 1124 page_hit: 1128 - if (unlikely(!PageUptodate(page))) { 1129 - f2fs_put_page(page, 1); 1130 - return ERR_PTR(-EIO); 1131 - } 1125 + f2fs_bug_on(sbi, nid != nid_of_node(page)); 1132 1126 return page; 1127 + } 1128 + 1129 + struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid) 1130 + { 1131 + return __get_node_page(sbi, nid, NULL, 0); 1132 + } 1133 + 1134 + struct page *get_node_page_ra(struct page *parent, int start) 1135 + { 1136 + struct f2fs_sb_info *sbi = F2FS_P_SB(parent); 1137 + nid_t nid = get_nid(parent, start, false); 1138 + 1139 + return __get_node_page(sbi, nid, parent, start); 1133 1140 } 1134 1141 1135 1142 void sync_inode_page(struct dnode_of_data *dn) 1136 1143 { 1144 + int ret = 0; 1145 + 1137 1146 if (IS_INODE(dn->node_page) || dn->inode_page == dn->node_page) { 1138 - update_inode(dn->inode, dn->node_page); 1147 + ret = update_inode(dn->inode, dn->node_page); 1139 1148 } else if (dn->inode_page) { 1140 1149 if (!dn->inode_page_locked) 1141 1150 lock_page(dn->inode_page); 1142 - update_inode(dn->inode, dn->inode_page); 1151 + ret = update_inode(dn->inode, dn->inode_page); 1143 1152 if (!dn->inode_page_locked) 1144 1153 unlock_page(dn->inode_page); 1145 1154 } else { 1146 - update_inode_page(dn->inode); 1155 + ret = update_inode_page(dn->inode); 1147 1156 } 1157 + dn->node_changed = ret ? true: false; 1148 1158 } 1149 1159 1150 1160 int sync_node_pages(struct f2fs_sb_info *sbi, nid_t ino, ··· 1178 1174 1179 1175 for (i = 0; i < nr_pages; i++) { 1180 1176 struct page *page = pvec.pages[i]; 1177 + 1178 + if (unlikely(f2fs_cp_error(sbi))) { 1179 + pagevec_release(&pvec); 1180 + return -EIO; 1181 + } 1181 1182 1182 1183 /* 1183 1184 * flushing sequence with step: ··· 1358 1349 up_read(&sbi->node_write); 1359 1350 unlock_page(page); 1360 1351 1361 - if (wbc->for_reclaim) 1352 + if (wbc->for_reclaim || unlikely(f2fs_cp_error(sbi))) 1362 1353 f2fs_submit_merged_bio(sbi, NODE, WRITE); 1363 1354 1364 1355 return 0; ··· 1449 1440 1450 1441 if (build) { 1451 1442 /* do not add allocated nids */ 1452 - down_read(&nm_i->nat_tree_lock); 1453 1443 ne = __lookup_nat_cache(nm_i, nid); 1454 - if (ne && 1455 - (!get_nat_flag(ne, IS_CHECKPOINTED) || 1444 + if (ne && (!get_nat_flag(ne, IS_CHECKPOINTED) || 1456 1445 nat_get_blkaddr(ne) != NULL_ADDR)) 1457 1446 allocated = true; 1458 - up_read(&nm_i->nat_tree_lock); 1459 1447 if (allocated) 1460 1448 return 0; 1461 1449 } ··· 1538 1532 ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), FREE_NID_PAGES, 1539 1533 META_NAT, true); 1540 1534 1535 + down_read(&nm_i->nat_tree_lock); 1536 + 1541 1537 while (1) { 1542 1538 struct page *page = get_current_nat_page(sbi, nid); 1543 1539 ··· 1568 1560 remove_free_nid(nm_i, nid); 1569 1561 } 1570 1562 mutex_unlock(&curseg->curseg_mutex); 1563 + up_read(&nm_i->nat_tree_lock); 1571 1564 1572 1565 ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nm_i->next_scan_nid), 1573 1566 nm_i->ra_nid_pages, META_NAT, false); ··· 1591 1582 1592 1583 /* We should not use stale free nids created by build_free_nids */ 1593 1584 if (nm_i->fcnt && !on_build_free_nids(nm_i)) { 1594 - struct node_info ni; 1595 - 1596 1585 f2fs_bug_on(sbi, list_empty(&nm_i->free_nid_list)); 1597 1586 list_for_each_entry(i, &nm_i->free_nid_list, list) 1598 1587 if (i->state == NID_NEW) ··· 1601 1594 i->state = NID_ALLOC; 1602 1595 nm_i->fcnt--; 1603 1596 spin_unlock(&nm_i->free_nid_list_lock); 1604 - 1605 - /* check nid is allocated already */ 1606 - get_node_info(sbi, *nid, &ni); 1607 - if (ni.blk_addr != NULL_ADDR) { 1608 - alloc_nid_done(sbi, *nid); 1609 - goto retry; 1610 - } 1611 1597 return true; 1612 1598 } 1613 1599 spin_unlock(&nm_i->free_nid_list_lock); ··· 1842 1842 1843 1843 raw_ne = nat_in_journal(sum, i); 1844 1844 1845 - down_write(&nm_i->nat_tree_lock); 1846 1845 ne = __lookup_nat_cache(nm_i, nid); 1847 1846 if (!ne) { 1848 1847 ne = grab_nat_entry(nm_i, nid); 1849 1848 node_info_from_raw_nat(&ne->ni, &raw_ne); 1850 1849 } 1851 1850 __set_nat_cache_dirty(nm_i, ne); 1852 - up_write(&nm_i->nat_tree_lock); 1853 1851 } 1854 1852 update_nats_in_cursum(sum, -i); 1855 1853 mutex_unlock(&curseg->curseg_mutex); ··· 1881 1883 struct f2fs_nat_block *nat_blk; 1882 1884 struct nat_entry *ne, *cur; 1883 1885 struct page *page = NULL; 1884 - struct f2fs_nm_info *nm_i = NM_I(sbi); 1885 1886 1886 1887 /* 1887 1888 * there are two steps to flush nat entries: ··· 1917 1920 raw_ne = &nat_blk->entries[nid - start_nid]; 1918 1921 } 1919 1922 raw_nat_from_node_info(raw_ne, &ne->ni); 1920 - 1921 - down_write(&NM_I(sbi)->nat_tree_lock); 1922 1923 nat_reset_flag(ne); 1923 1924 __clear_nat_cache_dirty(NM_I(sbi), ne); 1924 - up_write(&NM_I(sbi)->nat_tree_lock); 1925 - 1926 1925 if (nat_get_blkaddr(ne) == NULL_ADDR) 1927 1926 add_free_nid(sbi, nid, false); 1928 1927 } ··· 1930 1937 1931 1938 f2fs_bug_on(sbi, set->entry_cnt); 1932 1939 1933 - down_write(&nm_i->nat_tree_lock); 1934 1940 radix_tree_delete(&NM_I(sbi)->nat_set_root, set->set); 1935 - up_write(&nm_i->nat_tree_lock); 1936 1941 kmem_cache_free(nat_entry_set_slab, set); 1937 1942 } 1938 1943 ··· 1950 1959 1951 1960 if (!nm_i->dirty_nat_cnt) 1952 1961 return; 1962 + 1963 + down_write(&nm_i->nat_tree_lock); 1964 + 1953 1965 /* 1954 1966 * if there are no enough space in journal to store dirty nat 1955 1967 * entries, remove all entries from journal and merge them ··· 1961 1967 if (!__has_cursum_space(sum, nm_i->dirty_nat_cnt, NAT_JOURNAL)) 1962 1968 remove_nats_in_journal(sbi); 1963 1969 1964 - down_write(&nm_i->nat_tree_lock); 1965 1970 while ((found = __gang_lookup_nat_set(nm_i, 1966 1971 set_idx, SETVEC_SIZE, setvec))) { 1967 1972 unsigned idx; ··· 1969 1976 __adjust_nat_entry_set(setvec[idx], &sets, 1970 1977 MAX_NAT_JENTRIES(sum)); 1971 1978 } 1972 - up_write(&nm_i->nat_tree_lock); 1973 1979 1974 1980 /* flush dirty nats in nat entry set */ 1975 1981 list_for_each_entry_safe(set, tmp, &sets, set_list) 1976 1982 __flush_nat_entry_set(sbi, set); 1983 + 1984 + up_write(&nm_i->nat_tree_lock); 1977 1985 1978 1986 f2fs_bug_on(sbi, nm_i->dirty_nat_cnt); 1979 1987 }
+3 -3
fs/f2fs/node.h
··· 183 183 184 184 block_addr = (pgoff_t)(nm_i->nat_blkaddr + 185 185 (seg_off << sbi->log_blocks_per_seg << 1) + 186 - (block_off & ((1 << sbi->log_blocks_per_seg) - 1))); 186 + (block_off & (sbi->blocks_per_seg - 1))); 187 187 188 188 if (f2fs_test_bit(block_off, nm_i->nat_bitmap)) 189 189 block_addr += sbi->blocks_per_seg; ··· 317 317 return true; 318 318 } 319 319 320 - static inline void set_nid(struct page *p, int off, nid_t nid, bool i) 320 + static inline int set_nid(struct page *p, int off, nid_t nid, bool i) 321 321 { 322 322 struct f2fs_node *rn = F2FS_NODE(p); 323 323 ··· 327 327 rn->i.i_nid[off - NODE_DIR1_BLOCK] = cpu_to_le32(nid); 328 328 else 329 329 rn->in.nid[off] = cpu_to_le32(nid); 330 - set_page_dirty(p); 330 + return set_page_dirty(p); 331 331 } 332 332 333 333 static inline nid_t get_nid(struct page *p, int off, bool i)
+34 -6
fs/f2fs/recovery.c
··· 168 168 ino_of_node(page), name); 169 169 } 170 170 171 + static bool is_same_inode(struct inode *inode, struct page *ipage) 172 + { 173 + struct f2fs_inode *ri = F2FS_INODE(ipage); 174 + struct timespec disk; 175 + 176 + if (!IS_INODE(ipage)) 177 + return true; 178 + 179 + disk.tv_sec = le64_to_cpu(ri->i_ctime); 180 + disk.tv_nsec = le32_to_cpu(ri->i_ctime_nsec); 181 + if (timespec_compare(&inode->i_ctime, &disk) > 0) 182 + return false; 183 + 184 + disk.tv_sec = le64_to_cpu(ri->i_atime); 185 + disk.tv_nsec = le32_to_cpu(ri->i_atime_nsec); 186 + if (timespec_compare(&inode->i_atime, &disk) > 0) 187 + return false; 188 + 189 + disk.tv_sec = le64_to_cpu(ri->i_mtime); 190 + disk.tv_nsec = le32_to_cpu(ri->i_mtime_nsec); 191 + if (timespec_compare(&inode->i_mtime, &disk) > 0) 192 + return false; 193 + 194 + return true; 195 + } 196 + 171 197 static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head) 172 198 { 173 199 unsigned long long cp_ver = cur_cp_version(F2FS_CKPT(sbi)); ··· 223 197 goto next; 224 198 225 199 entry = get_fsync_inode(head, ino_of_node(page)); 226 - if (!entry) { 200 + if (entry) { 201 + if (!is_same_inode(entry->inode, page)) 202 + goto next; 203 + } else { 227 204 if (IS_INODE(page) && is_dent_dnode(page)) { 228 205 err = recover_inode_page(sbi, page); 229 206 if (err) ··· 488 459 return err; 489 460 } 490 461 491 - static int recover_data(struct f2fs_sb_info *sbi, 492 - struct list_head *head, int type) 462 + static int recover_data(struct f2fs_sb_info *sbi, struct list_head *head) 493 463 { 494 464 unsigned long long cp_ver = cur_cp_version(F2FS_CKPT(sbi)); 495 465 struct curseg_info *curseg; ··· 497 469 block_t blkaddr; 498 470 499 471 /* get node pages in the current segment */ 500 - curseg = CURSEG_I(sbi, type); 472 + curseg = CURSEG_I(sbi, CURSEG_WARM_NODE); 501 473 blkaddr = NEXT_FREE_BLKADDR(sbi, curseg); 502 474 503 475 while (1) { ··· 584 556 need_writecp = true; 585 557 586 558 /* step #2: recover data */ 587 - err = recover_data(sbi, &inode_list, CURSEG_WARM_NODE); 559 + err = recover_data(sbi, &inode_list); 588 560 if (!err) 589 561 f2fs_bug_on(sbi, !list_empty(&inode_list)); 590 562 out: ··· 623 595 .reason = CP_RECOVERY, 624 596 }; 625 597 mutex_unlock(&sbi->cp_mutex); 626 - write_checkpoint(sbi, &cpc); 598 + err = write_checkpoint(sbi, &cpc); 627 599 } else { 628 600 mutex_unlock(&sbi->cp_mutex); 629 601 }
+51 -63
fs/f2fs/segment.c
··· 86 86 /* 87 87 * __find_rev_next(_zero)_bit is copied from lib/find_next_bit.c because 88 88 * f2fs_set_bit makes MSB and LSB reversed in a byte. 89 + * @size must be integral times of unsigned long. 89 90 * Example: 90 91 * MSB <--> LSB 91 92 * f2fs_set_bit(0, bitmap) => 1000 0000 ··· 96 95 unsigned long size, unsigned long offset) 97 96 { 98 97 const unsigned long *p = addr + BIT_WORD(offset); 99 - unsigned long result = offset & ~(BITS_PER_LONG - 1); 98 + unsigned long result = size; 100 99 unsigned long tmp; 101 100 102 101 if (offset >= size) 103 102 return size; 104 103 105 - size -= result; 104 + size -= (offset & ~(BITS_PER_LONG - 1)); 106 105 offset %= BITS_PER_LONG; 107 - if (!offset) 108 - goto aligned; 109 106 110 - tmp = __reverse_ulong((unsigned char *)p); 111 - tmp &= ~0UL >> offset; 107 + while (1) { 108 + if (*p == 0) 109 + goto pass; 112 110 113 - if (size < BITS_PER_LONG) 114 - goto found_first; 115 - if (tmp) 116 - goto found_middle; 117 - 118 - size -= BITS_PER_LONG; 119 - result += BITS_PER_LONG; 120 - p++; 121 - aligned: 122 - while (size & ~(BITS_PER_LONG-1)) { 123 111 tmp = __reverse_ulong((unsigned char *)p); 112 + 113 + tmp &= ~0UL >> offset; 114 + if (size < BITS_PER_LONG) 115 + tmp &= (~0UL << (BITS_PER_LONG - size)); 124 116 if (tmp) 125 - goto found_middle; 126 - result += BITS_PER_LONG; 117 + goto found; 118 + pass: 119 + if (size <= BITS_PER_LONG) 120 + break; 127 121 size -= BITS_PER_LONG; 122 + offset = 0; 128 123 p++; 129 124 } 130 - if (!size) 131 - return result; 132 - 133 - tmp = __reverse_ulong((unsigned char *)p); 134 - found_first: 135 - tmp &= (~0UL << (BITS_PER_LONG - size)); 136 - if (!tmp) /* Are any bits set? */ 137 - return result + size; /* Nope. */ 138 - found_middle: 139 - return result + __reverse_ffs(tmp); 125 + return result; 126 + found: 127 + return result - size + __reverse_ffs(tmp); 140 128 } 141 129 142 130 static unsigned long __find_rev_next_zero_bit(const unsigned long *addr, 143 131 unsigned long size, unsigned long offset) 144 132 { 145 133 const unsigned long *p = addr + BIT_WORD(offset); 146 - unsigned long result = offset & ~(BITS_PER_LONG - 1); 134 + unsigned long result = size; 147 135 unsigned long tmp; 148 136 149 137 if (offset >= size) 150 138 return size; 151 139 152 - size -= result; 140 + size -= (offset & ~(BITS_PER_LONG - 1)); 153 141 offset %= BITS_PER_LONG; 154 - if (!offset) 155 - goto aligned; 156 142 157 - tmp = __reverse_ulong((unsigned char *)p); 158 - tmp |= ~((~0UL << offset) >> offset); 143 + while (1) { 144 + if (*p == ~0UL) 145 + goto pass; 159 146 160 - if (size < BITS_PER_LONG) 161 - goto found_first; 162 - if (tmp != ~0UL) 163 - goto found_middle; 164 - 165 - size -= BITS_PER_LONG; 166 - result += BITS_PER_LONG; 167 - p++; 168 - aligned: 169 - while (size & ~(BITS_PER_LONG - 1)) { 170 147 tmp = __reverse_ulong((unsigned char *)p); 148 + 149 + if (offset) 150 + tmp |= ~0UL << (BITS_PER_LONG - offset); 151 + if (size < BITS_PER_LONG) 152 + tmp |= ~0UL >> size; 171 153 if (tmp != ~0UL) 172 - goto found_middle; 173 - result += BITS_PER_LONG; 154 + goto found; 155 + pass: 156 + if (size <= BITS_PER_LONG) 157 + break; 174 158 size -= BITS_PER_LONG; 159 + offset = 0; 175 160 p++; 176 161 } 177 - if (!size) 178 - return result; 179 - 180 - tmp = __reverse_ulong((unsigned char *)p); 181 - found_first: 182 - tmp |= ~(~0UL << (BITS_PER_LONG - size)); 183 - if (tmp == ~0UL) /* Are any bits zero? */ 184 - return result + size; /* Nope. */ 185 - found_middle: 186 - return result + __reverse_ffz(tmp); 162 + return result; 163 + found: 164 + return result - size + __reverse_ffz(tmp); 187 165 } 188 166 189 167 void register_inmem_page(struct inode *inode, struct page *page) ··· 213 233 * inode becomes free by iget_locked in f2fs_iget. 214 234 */ 215 235 if (!abort) { 216 - f2fs_balance_fs(sbi); 236 + f2fs_balance_fs(sbi, true); 217 237 f2fs_lock_op(sbi); 218 238 } 219 239 ··· 237 257 submit_bio = true; 238 258 } 239 259 } else { 260 + ClearPageUptodate(cur->page); 240 261 trace_f2fs_commit_inmem_page(cur->page, INMEM_DROP); 241 262 } 242 263 set_page_private(cur->page, 0); ··· 262 281 * This function balances dirty node and dentry pages. 263 282 * In addition, it controls garbage collection. 264 283 */ 265 - void f2fs_balance_fs(struct f2fs_sb_info *sbi) 284 + void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need) 266 285 { 286 + if (!need) 287 + return; 267 288 /* 268 289 * We should do GC or end up with checkpoint, if there are so many dirty 269 290 * dir/node pages without enough free segments. ··· 293 310 if (!available_free_memory(sbi, NAT_ENTRIES) || 294 311 excess_prefree_segs(sbi) || 295 312 !available_free_memory(sbi, INO_ENTRIES) || 296 - jiffies > sbi->cp_expires) 313 + (is_idle(sbi) && f2fs_time_over(sbi, CP_TIME))) { 314 + if (test_opt(sbi, DATA_FLUSH)) 315 + sync_dirty_inodes(sbi, FILE_INODE); 297 316 f2fs_sync_fs(sbi->sb, true); 317 + stat_inc_bg_cp_count(sbi->stat_info); 318 + } 298 319 } 299 320 300 321 static int issue_flush_thread(void *data) ··· 1121 1134 __u64 end = start + F2FS_BYTES_TO_BLK(range->len) - 1; 1122 1135 unsigned int start_segno, end_segno; 1123 1136 struct cp_control cpc; 1137 + int err = 0; 1124 1138 1125 1139 if (start >= MAX_BLKADDR(sbi) || range->len < sbi->blocksize) 1126 1140 return -EINVAL; ··· 1152 1164 sbi->segs_per_sec) - 1, end_segno); 1153 1165 1154 1166 mutex_lock(&sbi->gc_mutex); 1155 - write_checkpoint(sbi, &cpc); 1167 + err = write_checkpoint(sbi, &cpc); 1156 1168 mutex_unlock(&sbi->gc_mutex); 1157 1169 } 1158 1170 out: 1159 1171 range->len = F2FS_BLK_TO_BYTES(cpc.trimmed); 1160 - return 0; 1172 + return err; 1161 1173 } 1162 1174 1163 1175 static bool __has_curseg_space(struct f2fs_sb_info *sbi, int type) ··· 1737 1749 if (le32_to_cpu(nid_in_journal(sum, i)) == val) 1738 1750 return i; 1739 1751 } 1740 - if (alloc && nats_in_cursum(sum) < NAT_JOURNAL_ENTRIES) 1752 + if (alloc && __has_cursum_space(sum, 1, NAT_JOURNAL)) 1741 1753 return update_nats_in_cursum(sum, 1); 1742 1754 } else if (type == SIT_JOURNAL) { 1743 1755 for (i = 0; i < sits_in_cursum(sum); i++) 1744 1756 if (le32_to_cpu(segno_in_journal(sum, i)) == val) 1745 1757 return i; 1746 - if (alloc && sits_in_cursum(sum) < SIT_JOURNAL_ENTRIES) 1758 + if (alloc && __has_cursum_space(sum, 1, SIT_JOURNAL)) 1747 1759 return update_sits_in_cursum(sum, 1); 1748 1760 } 1749 1761 return -1;
+2 -1
fs/f2fs/shrinker.c
··· 32 32 33 33 static unsigned long __count_extent_cache(struct f2fs_sb_info *sbi) 34 34 { 35 - return sbi->total_ext_tree + atomic_read(&sbi->total_ext_node); 35 + return atomic_read(&sbi->total_zombie_tree) + 36 + atomic_read(&sbi->total_ext_node); 36 37 } 37 38 38 39 unsigned long f2fs_shrink_count(struct shrinker *shrink,
+187 -66
fs/f2fs/super.c
··· 67 67 Opt_extent_cache, 68 68 Opt_noextent_cache, 69 69 Opt_noinline_data, 70 + Opt_data_flush, 70 71 Opt_err, 71 72 }; 72 73 ··· 92 91 {Opt_extent_cache, "extent_cache"}, 93 92 {Opt_noextent_cache, "noextent_cache"}, 94 93 {Opt_noinline_data, "noinline_data"}, 94 + {Opt_data_flush, "data_flush"}, 95 95 {Opt_err, NULL}, 96 96 }; 97 97 ··· 218 216 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages); 219 217 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search); 220 218 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level); 221 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, cp_interval); 219 + F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]); 220 + F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]); 222 221 223 222 #define ATTR_LIST(name) (&f2fs_attr_##name.attr) 224 223 static struct attribute *f2fs_attrs[] = { ··· 238 235 ATTR_LIST(ram_thresh), 239 236 ATTR_LIST(ra_nid_pages), 240 237 ATTR_LIST(cp_interval), 238 + ATTR_LIST(idle_interval), 241 239 NULL, 242 240 }; 243 241 ··· 410 406 case Opt_noinline_data: 411 407 clear_opt(sbi, INLINE_DATA); 412 408 break; 409 + case Opt_data_flush: 410 + set_opt(sbi, DATA_FLUSH); 411 + break; 413 412 default: 414 413 f2fs_msg(sb, KERN_ERR, 415 414 "Unrecognized mount option \"%s\" or missing value", ··· 439 432 fi->i_current_depth = 1; 440 433 fi->i_advise = 0; 441 434 init_rwsem(&fi->i_sem); 435 + INIT_LIST_HEAD(&fi->dirty_list); 442 436 INIT_LIST_HEAD(&fi->inmem_pages); 443 437 mutex_init(&fi->inmem_lock); 444 438 ··· 556 548 * normally superblock is clean, so we need to release this. 557 549 * In addition, EIO will skip do checkpoint, we need this as well. 558 550 */ 559 - release_dirty_inode(sbi); 551 + release_ino_entry(sbi); 560 552 release_discard_addrs(sbi); 561 553 562 554 f2fs_leave_shrinker(sbi); ··· 574 566 wait_for_completion(&sbi->s_kobj_unregister); 575 567 576 568 sb->s_fs_info = NULL; 577 - brelse(sbi->raw_super_buf); 569 + kfree(sbi->raw_super); 578 570 kfree(sbi); 579 571 } 580 572 581 573 int f2fs_sync_fs(struct super_block *sb, int sync) 582 574 { 583 575 struct f2fs_sb_info *sbi = F2FS_SB(sb); 576 + int err = 0; 584 577 585 578 trace_f2fs_sync_fs(sb, sync); 586 579 ··· 591 582 cpc.reason = __get_cp_reason(sbi); 592 583 593 584 mutex_lock(&sbi->gc_mutex); 594 - write_checkpoint(sbi, &cpc); 585 + err = write_checkpoint(sbi, &cpc); 595 586 mutex_unlock(&sbi->gc_mutex); 596 - } else { 597 - f2fs_balance_fs(sbi); 598 587 } 599 588 f2fs_trace_ios(NULL, 1); 600 589 601 - return 0; 590 + return err; 602 591 } 603 592 604 593 static int f2fs_freeze(struct super_block *sb) ··· 693 686 seq_puts(seq, ",extent_cache"); 694 687 else 695 688 seq_puts(seq, ",noextent_cache"); 689 + if (test_opt(sbi, DATA_FLUSH)) 690 + seq_puts(seq, ",data_flush"); 696 691 seq_printf(seq, ",active_logs=%u", sbi->active_logs); 697 692 698 693 return 0; ··· 907 898 .get_parent = f2fs_get_parent, 908 899 }; 909 900 910 - static loff_t max_file_size(unsigned bits) 901 + static loff_t max_file_blocks(void) 911 902 { 912 903 loff_t result = (DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS); 913 904 loff_t leaf_count = ADDRS_PER_BLOCK; ··· 923 914 leaf_count *= NIDS_PER_BLOCK; 924 915 result += leaf_count; 925 916 926 - result <<= bits; 927 917 return result; 918 + } 919 + 920 + static inline bool sanity_check_area_boundary(struct super_block *sb, 921 + struct f2fs_super_block *raw_super) 922 + { 923 + u32 segment0_blkaddr = le32_to_cpu(raw_super->segment0_blkaddr); 924 + u32 cp_blkaddr = le32_to_cpu(raw_super->cp_blkaddr); 925 + u32 sit_blkaddr = le32_to_cpu(raw_super->sit_blkaddr); 926 + u32 nat_blkaddr = le32_to_cpu(raw_super->nat_blkaddr); 927 + u32 ssa_blkaddr = le32_to_cpu(raw_super->ssa_blkaddr); 928 + u32 main_blkaddr = le32_to_cpu(raw_super->main_blkaddr); 929 + u32 segment_count_ckpt = le32_to_cpu(raw_super->segment_count_ckpt); 930 + u32 segment_count_sit = le32_to_cpu(raw_super->segment_count_sit); 931 + u32 segment_count_nat = le32_to_cpu(raw_super->segment_count_nat); 932 + u32 segment_count_ssa = le32_to_cpu(raw_super->segment_count_ssa); 933 + u32 segment_count_main = le32_to_cpu(raw_super->segment_count_main); 934 + u32 segment_count = le32_to_cpu(raw_super->segment_count); 935 + u32 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); 936 + 937 + if (segment0_blkaddr != cp_blkaddr) { 938 + f2fs_msg(sb, KERN_INFO, 939 + "Mismatch start address, segment0(%u) cp_blkaddr(%u)", 940 + segment0_blkaddr, cp_blkaddr); 941 + return true; 942 + } 943 + 944 + if (cp_blkaddr + (segment_count_ckpt << log_blocks_per_seg) != 945 + sit_blkaddr) { 946 + f2fs_msg(sb, KERN_INFO, 947 + "Wrong CP boundary, start(%u) end(%u) blocks(%u)", 948 + cp_blkaddr, sit_blkaddr, 949 + segment_count_ckpt << log_blocks_per_seg); 950 + return true; 951 + } 952 + 953 + if (sit_blkaddr + (segment_count_sit << log_blocks_per_seg) != 954 + nat_blkaddr) { 955 + f2fs_msg(sb, KERN_INFO, 956 + "Wrong SIT boundary, start(%u) end(%u) blocks(%u)", 957 + sit_blkaddr, nat_blkaddr, 958 + segment_count_sit << log_blocks_per_seg); 959 + return true; 960 + } 961 + 962 + if (nat_blkaddr + (segment_count_nat << log_blocks_per_seg) != 963 + ssa_blkaddr) { 964 + f2fs_msg(sb, KERN_INFO, 965 + "Wrong NAT boundary, start(%u) end(%u) blocks(%u)", 966 + nat_blkaddr, ssa_blkaddr, 967 + segment_count_nat << log_blocks_per_seg); 968 + return true; 969 + } 970 + 971 + if (ssa_blkaddr + (segment_count_ssa << log_blocks_per_seg) != 972 + main_blkaddr) { 973 + f2fs_msg(sb, KERN_INFO, 974 + "Wrong SSA boundary, start(%u) end(%u) blocks(%u)", 975 + ssa_blkaddr, main_blkaddr, 976 + segment_count_ssa << log_blocks_per_seg); 977 + return true; 978 + } 979 + 980 + if (main_blkaddr + (segment_count_main << log_blocks_per_seg) != 981 + segment0_blkaddr + (segment_count << log_blocks_per_seg)) { 982 + f2fs_msg(sb, KERN_INFO, 983 + "Wrong MAIN_AREA boundary, start(%u) end(%u) blocks(%u)", 984 + main_blkaddr, 985 + segment0_blkaddr + (segment_count << log_blocks_per_seg), 986 + segment_count_main << log_blocks_per_seg); 987 + return true; 988 + } 989 + 990 + return false; 928 991 } 929 992 930 993 static int sanity_check_raw_super(struct super_block *sb, ··· 1028 947 return 1; 1029 948 } 1030 949 950 + /* check log blocks per segment */ 951 + if (le32_to_cpu(raw_super->log_blocks_per_seg) != 9) { 952 + f2fs_msg(sb, KERN_INFO, 953 + "Invalid log blocks per segment (%u)\n", 954 + le32_to_cpu(raw_super->log_blocks_per_seg)); 955 + return 1; 956 + } 957 + 1031 958 /* Currently, support 512/1024/2048/4096 bytes sector size */ 1032 959 if (le32_to_cpu(raw_super->log_sectorsize) > 1033 960 F2FS_MAX_LOG_SECTOR_SIZE || ··· 1054 965 le32_to_cpu(raw_super->log_sectorsize)); 1055 966 return 1; 1056 967 } 968 + 969 + /* check reserved ino info */ 970 + if (le32_to_cpu(raw_super->node_ino) != 1 || 971 + le32_to_cpu(raw_super->meta_ino) != 2 || 972 + le32_to_cpu(raw_super->root_ino) != 3) { 973 + f2fs_msg(sb, KERN_INFO, 974 + "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)", 975 + le32_to_cpu(raw_super->node_ino), 976 + le32_to_cpu(raw_super->meta_ino), 977 + le32_to_cpu(raw_super->root_ino)); 978 + return 1; 979 + } 980 + 981 + /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */ 982 + if (sanity_check_area_boundary(sb, raw_super)) 983 + return 1; 984 + 1057 985 return 0; 1058 986 } 1059 987 ··· 1124 1018 atomic_set(&sbi->nr_pages[i], 0); 1125 1019 1126 1020 sbi->dir_level = DEF_DIR_LEVEL; 1127 - sbi->cp_interval = DEF_CP_INTERVAL; 1021 + sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL; 1022 + sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL; 1128 1023 clear_sbi_flag(sbi, SBI_NEED_FSCK); 1129 1024 1130 1025 INIT_LIST_HEAD(&sbi->s_list); ··· 1139 1032 */ 1140 1033 static int read_raw_super_block(struct super_block *sb, 1141 1034 struct f2fs_super_block **raw_super, 1142 - struct buffer_head **raw_super_buf, 1143 - int *recovery) 1035 + int *valid_super_block, int *recovery) 1144 1036 { 1145 1037 int block = 0; 1146 - struct buffer_head *buffer; 1147 - struct f2fs_super_block *super; 1038 + struct buffer_head *bh; 1039 + struct f2fs_super_block *super, *buf; 1148 1040 int err = 0; 1149 1041 1042 + super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL); 1043 + if (!super) 1044 + return -ENOMEM; 1150 1045 retry: 1151 - buffer = sb_bread(sb, block); 1152 - if (!buffer) { 1046 + bh = sb_bread(sb, block); 1047 + if (!bh) { 1153 1048 *recovery = 1; 1154 1049 f2fs_msg(sb, KERN_ERR, "Unable to read %dth superblock", 1155 1050 block + 1); 1156 - if (block == 0) { 1157 - block++; 1158 - goto retry; 1159 - } else { 1160 - err = -EIO; 1161 - goto out; 1162 - } 1051 + err = -EIO; 1052 + goto next; 1163 1053 } 1164 1054 1165 - super = (struct f2fs_super_block *) 1166 - ((char *)(buffer)->b_data + F2FS_SUPER_OFFSET); 1055 + buf = (struct f2fs_super_block *)(bh->b_data + F2FS_SUPER_OFFSET); 1167 1056 1168 1057 /* sanity checking of raw super */ 1169 - if (sanity_check_raw_super(sb, super)) { 1170 - brelse(buffer); 1058 + if (sanity_check_raw_super(sb, buf)) { 1059 + brelse(bh); 1171 1060 *recovery = 1; 1172 1061 f2fs_msg(sb, KERN_ERR, 1173 1062 "Can't find valid F2FS filesystem in %dth superblock", 1174 1063 block + 1); 1175 - if (block == 0) { 1176 - block++; 1177 - goto retry; 1178 - } else { 1179 - err = -EINVAL; 1180 - goto out; 1181 - } 1064 + err = -EINVAL; 1065 + goto next; 1182 1066 } 1183 1067 1184 1068 if (!*raw_super) { 1185 - *raw_super_buf = buffer; 1069 + memcpy(super, buf, sizeof(*super)); 1070 + *valid_super_block = block; 1186 1071 *raw_super = super; 1187 - } else { 1188 - /* already have a valid superblock */ 1189 - brelse(buffer); 1190 1072 } 1073 + brelse(bh); 1191 1074 1075 + next: 1192 1076 /* check the validity of the second superblock */ 1193 1077 if (block == 0) { 1194 1078 block++; 1195 1079 goto retry; 1196 1080 } 1197 1081 1198 - out: 1199 1082 /* No valid superblock */ 1200 - if (!*raw_super) 1083 + if (!*raw_super) { 1084 + kfree(super); 1201 1085 return err; 1086 + } 1202 1087 1203 1088 return 0; 1204 1089 } 1205 1090 1091 + static int __f2fs_commit_super(struct f2fs_sb_info *sbi, int block) 1092 + { 1093 + struct f2fs_super_block *super = F2FS_RAW_SUPER(sbi); 1094 + struct buffer_head *bh; 1095 + int err; 1096 + 1097 + bh = sb_getblk(sbi->sb, block); 1098 + if (!bh) 1099 + return -EIO; 1100 + 1101 + lock_buffer(bh); 1102 + memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super)); 1103 + set_buffer_uptodate(bh); 1104 + set_buffer_dirty(bh); 1105 + unlock_buffer(bh); 1106 + 1107 + /* it's rare case, we can do fua all the time */ 1108 + err = __sync_dirty_buffer(bh, WRITE_FLUSH_FUA); 1109 + brelse(bh); 1110 + 1111 + return err; 1112 + } 1113 + 1206 1114 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) 1207 1115 { 1208 - struct buffer_head *sbh = sbi->raw_super_buf; 1209 - sector_t block = sbh->b_blocknr; 1210 1116 int err; 1211 1117 1212 1118 /* write back-up superblock first */ 1213 - sbh->b_blocknr = block ? 0 : 1; 1214 - mark_buffer_dirty(sbh); 1215 - err = sync_dirty_buffer(sbh); 1216 - 1217 - sbh->b_blocknr = block; 1119 + err = __f2fs_commit_super(sbi, sbi->valid_super_block ? 0 : 1); 1218 1120 1219 1121 /* if we are in recovery path, skip writing valid superblock */ 1220 1122 if (recover || err) 1221 - goto out; 1123 + return err; 1222 1124 1223 1125 /* write current valid superblock */ 1224 - mark_buffer_dirty(sbh); 1225 - err = sync_dirty_buffer(sbh); 1226 - out: 1227 - clear_buffer_write_io_error(sbh); 1228 - set_buffer_uptodate(sbh); 1229 - return err; 1126 + return __f2fs_commit_super(sbi, sbi->valid_super_block); 1230 1127 } 1231 1128 1232 1129 static int f2fs_fill_super(struct super_block *sb, void *data, int silent) 1233 1130 { 1234 1131 struct f2fs_sb_info *sbi; 1235 1132 struct f2fs_super_block *raw_super; 1236 - struct buffer_head *raw_super_buf; 1237 1133 struct inode *root; 1238 1134 long err; 1239 1135 bool retry = true, need_fsck = false; 1240 1136 char *options = NULL; 1241 - int recovery, i; 1137 + int recovery, i, valid_super_block; 1242 1138 1243 1139 try_onemore: 1244 1140 err = -EINVAL; 1245 1141 raw_super = NULL; 1246 - raw_super_buf = NULL; 1142 + valid_super_block = -1; 1247 1143 recovery = 0; 1248 1144 1249 1145 /* allocate memory for f2fs-specific super block info */ ··· 1260 1150 goto free_sbi; 1261 1151 } 1262 1152 1263 - err = read_raw_super_block(sb, &raw_super, &raw_super_buf, &recovery); 1153 + err = read_raw_super_block(sb, &raw_super, &valid_super_block, 1154 + &recovery); 1264 1155 if (err) 1265 1156 goto free_sbi; 1266 1157 ··· 1278 1167 if (err) 1279 1168 goto free_options; 1280 1169 1281 - sb->s_maxbytes = max_file_size(le32_to_cpu(raw_super->log_blocksize)); 1170 + sbi->max_file_blocks = max_file_blocks(); 1171 + sb->s_maxbytes = sbi->max_file_blocks << 1172 + le32_to_cpu(raw_super->log_blocksize); 1282 1173 sb->s_max_links = F2FS_LINK_MAX; 1283 1174 get_random_bytes(&sbi->s_next_generation, sizeof(u32)); 1284 1175 ··· 1296 1183 /* init f2fs-specific super block info */ 1297 1184 sbi->sb = sb; 1298 1185 sbi->raw_super = raw_super; 1299 - sbi->raw_super_buf = raw_super_buf; 1186 + sbi->valid_super_block = valid_super_block; 1300 1187 mutex_init(&sbi->gc_mutex); 1301 1188 mutex_init(&sbi->writepages); 1302 1189 mutex_init(&sbi->cp_mutex); ··· 1349 1236 le64_to_cpu(sbi->ckpt->valid_block_count); 1350 1237 sbi->last_valid_block_count = sbi->total_valid_block_count; 1351 1238 sbi->alloc_valid_block_count = 0; 1352 - INIT_LIST_HEAD(&sbi->dir_inode_list); 1353 - spin_lock_init(&sbi->dir_inode_lock); 1239 + for (i = 0; i < NR_INODE_TYPE; i++) { 1240 + INIT_LIST_HEAD(&sbi->inode_list[i]); 1241 + spin_lock_init(&sbi->inode_lock[i]); 1242 + } 1354 1243 1355 1244 init_extent_cache_info(sbi); 1356 1245 ··· 1470 1355 f2fs_commit_super(sbi, true); 1471 1356 } 1472 1357 1473 - sbi->cp_expires = round_jiffies_up(jiffies); 1474 - 1358 + f2fs_update_time(sbi, CP_TIME); 1359 + f2fs_update_time(sbi, REQ_TIME); 1475 1360 return 0; 1476 1361 1477 1362 free_kobj: 1478 1363 kobject_del(&sbi->s_kobj); 1364 + kobject_put(&sbi->s_kobj); 1365 + wait_for_completion(&sbi->s_kobj_unregister); 1479 1366 free_proc: 1480 1367 if (sbi->s_proc) { 1481 1368 remove_proc_entry("segment_info", sbi->s_proc); ··· 1504 1387 free_options: 1505 1388 kfree(options); 1506 1389 free_sb_buf: 1507 - brelse(raw_super_buf); 1390 + kfree(raw_super); 1508 1391 free_sbi: 1509 1392 kfree(sbi); 1510 1393 ··· 1595 1478 err = register_filesystem(&f2fs_fs_type); 1596 1479 if (err) 1597 1480 goto free_shrinker; 1598 - f2fs_create_root_stats(); 1481 + err = f2fs_create_root_stats(); 1482 + if (err) 1483 + goto free_filesystem; 1599 1484 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); 1600 1485 return 0; 1601 1486 1487 + free_filesystem: 1488 + unregister_filesystem(&f2fs_fs_type); 1602 1489 free_shrinker: 1603 1490 unregister_shrinker(&f2fs_shrinker_info); 1604 1491 free_crypto:
+2 -1
fs/f2fs/xattr.c
··· 571 571 if (ipage) 572 572 return __f2fs_setxattr(inode, index, name, value, 573 573 size, ipage, flags); 574 - f2fs_balance_fs(sbi); 574 + f2fs_balance_fs(sbi, true); 575 575 576 576 f2fs_lock_op(sbi); 577 577 /* protect xattr_ver */ ··· 580 580 up_write(&F2FS_I(inode)->i_sem); 581 581 f2fs_unlock_op(sbi); 582 582 583 + f2fs_update_time(sbi, REQ_TIME); 583 584 return err; 584 585 }
+2 -1
include/linux/f2fs_fs.h
··· 51 51 #define MAX_ACTIVE_DATA_LOGS 8 52 52 53 53 #define VERSION_LEN 256 54 + #define MAX_VOLUME_NAME 512 54 55 55 56 /* 56 57 * For superblock ··· 85 84 __le32 node_ino; /* node inode number */ 86 85 __le32 meta_ino; /* meta inode number */ 87 86 __u8 uuid[16]; /* 128-bit uuid for volume */ 88 - __le16 volume_name[512]; /* volume name */ 87 + __le16 volume_name[MAX_VOLUME_NAME]; /* volume name */ 89 88 __le32 extension_count; /* # of extensions below */ 90 89 __u8 extension_list[F2FS_MAX_EXTENSION][8]; /* extension array */ 91 90 __le32 cp_payload;
+38
include/trace/events/f2fs.h
··· 1265 1265 __entry->node_cnt) 1266 1266 ); 1267 1267 1268 + DECLARE_EVENT_CLASS(f2fs_sync_dirty_inodes, 1269 + 1270 + TP_PROTO(struct super_block *sb, int type, int count), 1271 + 1272 + TP_ARGS(sb, type, count), 1273 + 1274 + TP_STRUCT__entry( 1275 + __field(dev_t, dev) 1276 + __field(int, type) 1277 + __field(int, count) 1278 + ), 1279 + 1280 + TP_fast_assign( 1281 + __entry->dev = sb->s_dev; 1282 + __entry->type = type; 1283 + __entry->count = count; 1284 + ), 1285 + 1286 + TP_printk("dev = (%d,%d), %s, dirty count = %d", 1287 + show_dev(__entry), 1288 + show_file_type(__entry->type), 1289 + __entry->count) 1290 + ); 1291 + 1292 + DEFINE_EVENT(f2fs_sync_dirty_inodes, f2fs_sync_dirty_inodes_enter, 1293 + 1294 + TP_PROTO(struct super_block *sb, int type, int count), 1295 + 1296 + TP_ARGS(sb, type, count) 1297 + ); 1298 + 1299 + DEFINE_EVENT(f2fs_sync_dirty_inodes, f2fs_sync_dirty_inodes_exit, 1300 + 1301 + TP_PROTO(struct super_block *sb, int type, int count), 1302 + 1303 + TP_ARGS(sb, type, count) 1304 + ); 1305 + 1268 1306 #endif /* _TRACE_F2FS_H */ 1269 1307 1270 1308 /* This part must be outside protection */