diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-01-30 22:07:32 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-01-30 22:07:32 -0500 |
commit | 3da90b159b146672f830bcd2489dd3a1f4e9e089 (patch) | |
tree | 3130e89a466afd4b4a86e3192538bcc0012f6d1c | |
parent | efd52b5d363e3e3b6224ad39949219c0df117c91 (diff) | |
parent | 1c1d35df71104c76a4a2e25862926f22c334c9d6 (diff) |
Merge tag 'f2fs-for-4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
Pull f2fs updates from Jaegeuk Kim:
"In this round, we've followed up to support some generic features such
as cgroup, block reservation, linking fscrypt_ops, delivering
write_hints, and some ioctls. And, we could fix some corner cases in
terms of power-cut recovery and subtle deadlocks.
Enhancements:
- bitmap operations to handle NAT blocks
- readahead to improve readdir speed
- switch to use fscrypt_*
- apply write hints for direct IO
- add reserve_root=%u,resuid=%u,resgid=%u to reserve blocks for root/uid/gid
- modify b_avail and b_free to consider root reserved blocks
- support cgroup writeback
- support FIEMAP_FLAG_XATTR for fibmap
- add F2FS_IOC_PRECACHE_EXTENTS to pre-cache extents
- add F2FS_IOC_{GET/SET}_PIN_FILE to pin LBAs for data blocks
- support inode creation time
Bug fixs:
- sysfile-based quota operations
- memory footprint accounting
- allow to write data on partial preallocation case
- fix deadlock case on fallocate
- fix to handle fill_super errors
- fix missing inode updates of fsync'ed file
- recover renamed file which was fsycn'ed before
- drop inmemory pages in corner error case
- keep last_disk_size correctly
- recover missing i_inline flags during roll-forward
Various clean-up patches were added as well"
* tag 'f2fs-for-4.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (72 commits)
f2fs: support inode creation time
f2fs: rebuild sit page from sit info in mem
f2fs: stop issuing discard if fs is readonly
f2fs: clean up duplicated assignment in init_discard_policy
f2fs: use GFP_F2FS_ZERO for cleanup
f2fs: allow to recover node blocks given updated checkpoint
f2fs: recover some i_inline flags
f2fs: correct removexattr behavior for null valued extended attribute
f2fs: drop page cache after fs shutdown
f2fs: stop gc/discard thread after fs shutdown
f2fs: hanlde error case in f2fs_ioc_shutdown
f2fs: split need_inplace_update
f2fs: fix to update last_disk_size correctly
f2fs: kill F2FS_INLINE_XATTR_ADDRS for cleanup
f2fs: clean up error path of fill_super
f2fs: avoid hungtask when GC encrypted block if io_bits is set
f2fs: allow quota to use reserved blocks
f2fs: fix to drop all inmem pages correctly
f2fs: speed up defragment on sparse file
f2fs: support F2FS_IOC_PRECACHE_EXTENTS
...
-rw-r--r-- | Documentation/ABI/testing/sysfs-fs-f2fs | 6 | ||||
-rw-r--r-- | fs/f2fs/acl.c | 2 | ||||
-rw-r--r-- | fs/f2fs/checkpoint.c | 10 | ||||
-rw-r--r-- | fs/f2fs/data.c | 299 | ||||
-rw-r--r-- | fs/f2fs/debug.c | 12 | ||||
-rw-r--r-- | fs/f2fs/dir.c | 6 | ||||
-rw-r--r-- | fs/f2fs/f2fs.h | 201 | ||||
-rw-r--r-- | fs/f2fs/file.c | 248 | ||||
-rw-r--r-- | fs/f2fs/gc.c | 18 | ||||
-rw-r--r-- | fs/f2fs/gc.h | 2 | ||||
-rw-r--r-- | fs/f2fs/inode.c | 34 | ||||
-rw-r--r-- | fs/f2fs/namei.c | 67 | ||||
-rw-r--r-- | fs/f2fs/node.c | 149 | ||||
-rw-r--r-- | fs/f2fs/node.h | 4 | ||||
-rw-r--r-- | fs/f2fs/recovery.c | 27 | ||||
-rw-r--r-- | fs/f2fs/segment.c | 129 | ||||
-rw-r--r-- | fs/f2fs/segment.h | 92 | ||||
-rw-r--r-- | fs/f2fs/super.c | 142 | ||||
-rw-r--r-- | fs/f2fs/sysfs.c | 14 | ||||
-rw-r--r-- | fs/f2fs/trace.c | 12 | ||||
-rw-r--r-- | fs/f2fs/xattr.c | 12 | ||||
-rw-r--r-- | fs/posix_acl.c | 6 | ||||
-rw-r--r-- | include/linux/f2fs_fs.h | 14 | ||||
-rw-r--r-- | include/linux/posix_acl.h | 7 | ||||
-rw-r--r-- | include/trace/events/f2fs.h | 3 |
25 files changed, 1064 insertions, 452 deletions
diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index a7799c2fca28..d870b5514d15 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs | |||
@@ -186,3 +186,9 @@ Date: August 2017 | |||
186 | Contact: "Jaegeuk Kim" <jaegeuk@kernel.org> | 186 | Contact: "Jaegeuk Kim" <jaegeuk@kernel.org> |
187 | Description: | 187 | Description: |
188 | Controls sleep time of GC urgent mode | 188 | Controls sleep time of GC urgent mode |
189 | |||
190 | What: /sys/fs/f2fs/<disk>/readdir_ra | ||
191 | Date: November 2017 | ||
192 | Contact: "Sheng Yong" <shengyong1@huawei.com> | ||
193 | Description: | ||
194 | Controls readahead inode block in readdir. | ||
diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c index 2bb7c9fc5144..111824199a88 100644 --- a/fs/f2fs/acl.c +++ b/fs/f2fs/acl.c | |||
@@ -270,7 +270,7 @@ static struct posix_acl *f2fs_acl_clone(const struct posix_acl *acl, | |||
270 | sizeof(struct posix_acl_entry); | 270 | sizeof(struct posix_acl_entry); |
271 | clone = kmemdup(acl, size, flags); | 271 | clone = kmemdup(acl, size, flags); |
272 | if (clone) | 272 | if (clone) |
273 | atomic_set(&clone->a_refcount, 1); | 273 | refcount_set(&clone->a_refcount, 1); |
274 | } | 274 | } |
275 | return clone; | 275 | return clone; |
276 | } | 276 | } |
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 4aa69bc1c70a..512dca8abc7d 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c | |||
@@ -237,12 +237,15 @@ static int __f2fs_write_meta_page(struct page *page, | |||
237 | 237 | ||
238 | trace_f2fs_writepage(page, META); | 238 | trace_f2fs_writepage(page, META); |
239 | 239 | ||
240 | if (unlikely(f2fs_cp_error(sbi))) { | ||
241 | dec_page_count(sbi, F2FS_DIRTY_META); | ||
242 | unlock_page(page); | ||
243 | return 0; | ||
244 | } | ||
240 | if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) | 245 | if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) |
241 | goto redirty_out; | 246 | goto redirty_out; |
242 | if (wbc->for_reclaim && page->index < GET_SUM_BLOCK(sbi, 0)) | 247 | if (wbc->for_reclaim && page->index < GET_SUM_BLOCK(sbi, 0)) |
243 | goto redirty_out; | 248 | goto redirty_out; |
244 | if (unlikely(f2fs_cp_error(sbi))) | ||
245 | goto redirty_out; | ||
246 | 249 | ||
247 | write_meta_page(sbi, page, io_type); | 250 | write_meta_page(sbi, page, io_type); |
248 | dec_page_count(sbi, F2FS_DIRTY_META); | 251 | dec_page_count(sbi, F2FS_DIRTY_META); |
@@ -793,7 +796,7 @@ int get_valid_checkpoint(struct f2fs_sb_info *sbi) | |||
793 | block_t cp_blk_no; | 796 | block_t cp_blk_no; |
794 | int i; | 797 | int i; |
795 | 798 | ||
796 | sbi->ckpt = kzalloc(cp_blks * blk_size, GFP_KERNEL); | 799 | sbi->ckpt = f2fs_kzalloc(sbi, cp_blks * blk_size, GFP_KERNEL); |
797 | if (!sbi->ckpt) | 800 | if (!sbi->ckpt) |
798 | return -ENOMEM; | 801 | return -ENOMEM; |
799 | /* | 802 | /* |
@@ -1154,6 +1157,7 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc) | |||
1154 | 1157 | ||
1155 | /* set this flag to activate crc|cp_ver for recovery */ | 1158 | /* set this flag to activate crc|cp_ver for recovery */ |
1156 | __set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG); | 1159 | __set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG); |
1160 | __clear_ckpt_flags(ckpt, CP_NOCRC_RECOVERY_FLAG); | ||
1157 | 1161 | ||
1158 | spin_unlock_irqrestore(&sbi->cp_lock, flags); | 1162 | spin_unlock_irqrestore(&sbi->cp_lock, flags); |
1159 | } | 1163 | } |
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 455f086cce3d..7578ed1a85e0 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c | |||
@@ -111,8 +111,13 @@ static void f2fs_write_end_io(struct bio *bio) | |||
111 | 111 | ||
112 | if (unlikely(bio->bi_status)) { | 112 | if (unlikely(bio->bi_status)) { |
113 | mapping_set_error(page->mapping, -EIO); | 113 | mapping_set_error(page->mapping, -EIO); |
114 | f2fs_stop_checkpoint(sbi, true); | 114 | if (type == F2FS_WB_CP_DATA) |
115 | f2fs_stop_checkpoint(sbi, true); | ||
115 | } | 116 | } |
117 | |||
118 | f2fs_bug_on(sbi, page->mapping == NODE_MAPPING(sbi) && | ||
119 | page->index != nid_of_node(page)); | ||
120 | |||
116 | dec_page_count(sbi, type); | 121 | dec_page_count(sbi, type); |
117 | clear_cold_data(page); | 122 | clear_cold_data(page); |
118 | end_page_writeback(page); | 123 | end_page_writeback(page); |
@@ -169,6 +174,7 @@ static bool __same_bdev(struct f2fs_sb_info *sbi, | |||
169 | * Low-level block read/write IO operations. | 174 | * Low-level block read/write IO operations. |
170 | */ | 175 | */ |
171 | static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr, | 176 | static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr, |
177 | struct writeback_control *wbc, | ||
172 | int npages, bool is_read) | 178 | int npages, bool is_read) |
173 | { | 179 | { |
174 | struct bio *bio; | 180 | struct bio *bio; |
@@ -178,6 +184,8 @@ static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr, | |||
178 | f2fs_target_device(sbi, blk_addr, bio); | 184 | f2fs_target_device(sbi, blk_addr, bio); |
179 | bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io; | 185 | bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io; |
180 | bio->bi_private = is_read ? NULL : sbi; | 186 | bio->bi_private = is_read ? NULL : sbi; |
187 | if (wbc) | ||
188 | wbc_init_bio(wbc, bio); | ||
181 | 189 | ||
182 | return bio; | 190 | return bio; |
183 | } | 191 | } |
@@ -373,7 +381,8 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) | |||
373 | f2fs_trace_ios(fio, 0); | 381 | f2fs_trace_ios(fio, 0); |
374 | 382 | ||
375 | /* Allocate a new bio */ | 383 | /* Allocate a new bio */ |
376 | bio = __bio_alloc(fio->sbi, fio->new_blkaddr, 1, is_read_io(fio->op)); | 384 | bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc, |
385 | 1, is_read_io(fio->op)); | ||
377 | 386 | ||
378 | if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { | 387 | if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { |
379 | bio_put(bio); | 388 | bio_put(bio); |
@@ -435,7 +444,7 @@ alloc_new: | |||
435 | dec_page_count(sbi, WB_DATA_TYPE(bio_page)); | 444 | dec_page_count(sbi, WB_DATA_TYPE(bio_page)); |
436 | goto out_fail; | 445 | goto out_fail; |
437 | } | 446 | } |
438 | io->bio = __bio_alloc(sbi, fio->new_blkaddr, | 447 | io->bio = __bio_alloc(sbi, fio->new_blkaddr, fio->io_wbc, |
439 | BIO_MAX_PAGES, false); | 448 | BIO_MAX_PAGES, false); |
440 | io->fio = *fio; | 449 | io->fio = *fio; |
441 | } | 450 | } |
@@ -445,6 +454,9 @@ alloc_new: | |||
445 | goto alloc_new; | 454 | goto alloc_new; |
446 | } | 455 | } |
447 | 456 | ||
457 | if (fio->io_wbc) | ||
458 | wbc_account_io(fio->io_wbc, bio_page, PAGE_SIZE); | ||
459 | |||
448 | io->last_block_in_bio = fio->new_blkaddr; | 460 | io->last_block_in_bio = fio->new_blkaddr; |
449 | f2fs_trace_ios(fio, 0); | 461 | f2fs_trace_ios(fio, 0); |
450 | 462 | ||
@@ -783,7 +795,7 @@ got_it: | |||
783 | return page; | 795 | return page; |
784 | } | 796 | } |
785 | 797 | ||
786 | static int __allocate_data_block(struct dnode_of_data *dn) | 798 | static int __allocate_data_block(struct dnode_of_data *dn, int seg_type) |
787 | { | 799 | { |
788 | struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); | 800 | struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); |
789 | struct f2fs_summary sum; | 801 | struct f2fs_summary sum; |
@@ -808,7 +820,7 @@ alloc: | |||
808 | set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version); | 820 | set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version); |
809 | 821 | ||
810 | allocate_data_block(sbi, NULL, dn->data_blkaddr, &dn->data_blkaddr, | 822 | allocate_data_block(sbi, NULL, dn->data_blkaddr, &dn->data_blkaddr, |
811 | &sum, CURSEG_WARM_DATA, NULL, false); | 823 | &sum, seg_type, NULL, false); |
812 | set_data_blkaddr(dn); | 824 | set_data_blkaddr(dn); |
813 | 825 | ||
814 | /* update i_size */ | 826 | /* update i_size */ |
@@ -831,10 +843,12 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from) | |||
831 | { | 843 | { |
832 | struct inode *inode = file_inode(iocb->ki_filp); | 844 | struct inode *inode = file_inode(iocb->ki_filp); |
833 | struct f2fs_map_blocks map; | 845 | struct f2fs_map_blocks map; |
846 | int flag; | ||
834 | int err = 0; | 847 | int err = 0; |
848 | bool direct_io = iocb->ki_flags & IOCB_DIRECT; | ||
835 | 849 | ||
836 | /* convert inline data for Direct I/O*/ | 850 | /* convert inline data for Direct I/O*/ |
837 | if (iocb->ki_flags & IOCB_DIRECT) { | 851 | if (direct_io) { |
838 | err = f2fs_convert_inline_inode(inode); | 852 | err = f2fs_convert_inline_inode(inode); |
839 | if (err) | 853 | if (err) |
840 | return err; | 854 | return err; |
@@ -851,19 +865,33 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from) | |||
851 | map.m_len = 0; | 865 | map.m_len = 0; |
852 | 866 | ||
853 | map.m_next_pgofs = NULL; | 867 | map.m_next_pgofs = NULL; |
868 | map.m_next_extent = NULL; | ||
869 | map.m_seg_type = NO_CHECK_TYPE; | ||
854 | 870 | ||
855 | if (iocb->ki_flags & IOCB_DIRECT) | 871 | if (direct_io) { |
856 | return f2fs_map_blocks(inode, &map, 1, | 872 | map.m_seg_type = rw_hint_to_seg_type(iocb->ki_hint); |
857 | __force_buffered_io(inode, WRITE) ? | 873 | flag = __force_buffered_io(inode, WRITE) ? |
858 | F2FS_GET_BLOCK_PRE_AIO : | 874 | F2FS_GET_BLOCK_PRE_AIO : |
859 | F2FS_GET_BLOCK_PRE_DIO); | 875 | F2FS_GET_BLOCK_PRE_DIO; |
876 | goto map_blocks; | ||
877 | } | ||
860 | if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA(inode)) { | 878 | if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA(inode)) { |
861 | err = f2fs_convert_inline_inode(inode); | 879 | err = f2fs_convert_inline_inode(inode); |
862 | if (err) | 880 | if (err) |
863 | return err; | 881 | return err; |
864 | } | 882 | } |
865 | if (!f2fs_has_inline_data(inode)) | 883 | if (f2fs_has_inline_data(inode)) |
866 | return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO); | 884 | return err; |
885 | |||
886 | flag = F2FS_GET_BLOCK_PRE_AIO; | ||
887 | |||
888 | map_blocks: | ||
889 | err = f2fs_map_blocks(inode, &map, 1, flag); | ||
890 | if (map.m_len > 0 && err == -ENOSPC) { | ||
891 | if (!direct_io) | ||
892 | set_inode_flag(inode, FI_NO_PREALLOC); | ||
893 | err = 0; | ||
894 | } | ||
867 | return err; | 895 | return err; |
868 | } | 896 | } |
869 | 897 | ||
@@ -904,6 +932,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, | |||
904 | blkcnt_t prealloc; | 932 | blkcnt_t prealloc; |
905 | struct extent_info ei = {0,0,0}; | 933 | struct extent_info ei = {0,0,0}; |
906 | block_t blkaddr; | 934 | block_t blkaddr; |
935 | unsigned int start_pgofs; | ||
907 | 936 | ||
908 | if (!maxblocks) | 937 | if (!maxblocks) |
909 | return 0; | 938 | return 0; |
@@ -919,6 +948,8 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, | |||
919 | map->m_pblk = ei.blk + pgofs - ei.fofs; | 948 | map->m_pblk = ei.blk + pgofs - ei.fofs; |
920 | map->m_len = min((pgoff_t)maxblocks, ei.fofs + ei.len - pgofs); | 949 | map->m_len = min((pgoff_t)maxblocks, ei.fofs + ei.len - pgofs); |
921 | map->m_flags = F2FS_MAP_MAPPED; | 950 | map->m_flags = F2FS_MAP_MAPPED; |
951 | if (map->m_next_extent) | ||
952 | *map->m_next_extent = pgofs + map->m_len; | ||
922 | goto out; | 953 | goto out; |
923 | } | 954 | } |
924 | 955 | ||
@@ -937,10 +968,14 @@ next_dnode: | |||
937 | if (map->m_next_pgofs) | 968 | if (map->m_next_pgofs) |
938 | *map->m_next_pgofs = | 969 | *map->m_next_pgofs = |
939 | get_next_page_offset(&dn, pgofs); | 970 | get_next_page_offset(&dn, pgofs); |
971 | if (map->m_next_extent) | ||
972 | *map->m_next_extent = | ||
973 | get_next_page_offset(&dn, pgofs); | ||
940 | } | 974 | } |
941 | goto unlock_out; | 975 | goto unlock_out; |
942 | } | 976 | } |
943 | 977 | ||
978 | start_pgofs = pgofs; | ||
944 | prealloc = 0; | 979 | prealloc = 0; |
945 | last_ofs_in_node = ofs_in_node = dn.ofs_in_node; | 980 | last_ofs_in_node = ofs_in_node = dn.ofs_in_node; |
946 | end_offset = ADDRS_PER_PAGE(dn.node_page, inode); | 981 | end_offset = ADDRS_PER_PAGE(dn.node_page, inode); |
@@ -960,7 +995,8 @@ next_block: | |||
960 | last_ofs_in_node = dn.ofs_in_node; | 995 | last_ofs_in_node = dn.ofs_in_node; |
961 | } | 996 | } |
962 | } else { | 997 | } else { |
963 | err = __allocate_data_block(&dn); | 998 | err = __allocate_data_block(&dn, |
999 | map->m_seg_type); | ||
964 | if (!err) | 1000 | if (!err) |
965 | set_inode_flag(inode, FI_APPEND_WRITE); | 1001 | set_inode_flag(inode, FI_APPEND_WRITE); |
966 | } | 1002 | } |
@@ -973,14 +1009,20 @@ next_block: | |||
973 | map->m_pblk = 0; | 1009 | map->m_pblk = 0; |
974 | goto sync_out; | 1010 | goto sync_out; |
975 | } | 1011 | } |
1012 | if (flag == F2FS_GET_BLOCK_PRECACHE) | ||
1013 | goto sync_out; | ||
976 | if (flag == F2FS_GET_BLOCK_FIEMAP && | 1014 | if (flag == F2FS_GET_BLOCK_FIEMAP && |
977 | blkaddr == NULL_ADDR) { | 1015 | blkaddr == NULL_ADDR) { |
978 | if (map->m_next_pgofs) | 1016 | if (map->m_next_pgofs) |
979 | *map->m_next_pgofs = pgofs + 1; | 1017 | *map->m_next_pgofs = pgofs + 1; |
1018 | goto sync_out; | ||
980 | } | 1019 | } |
981 | if (flag != F2FS_GET_BLOCK_FIEMAP || | 1020 | if (flag != F2FS_GET_BLOCK_FIEMAP) { |
982 | blkaddr != NEW_ADDR) | 1021 | /* for defragment case */ |
1022 | if (map->m_next_pgofs) | ||
1023 | *map->m_next_pgofs = pgofs + 1; | ||
983 | goto sync_out; | 1024 | goto sync_out; |
1025 | } | ||
984 | } | 1026 | } |
985 | } | 1027 | } |
986 | 1028 | ||
@@ -1031,6 +1073,16 @@ skip: | |||
1031 | else if (dn.ofs_in_node < end_offset) | 1073 | else if (dn.ofs_in_node < end_offset) |
1032 | goto next_block; | 1074 | goto next_block; |
1033 | 1075 | ||
1076 | if (flag == F2FS_GET_BLOCK_PRECACHE) { | ||
1077 | if (map->m_flags & F2FS_MAP_MAPPED) { | ||
1078 | unsigned int ofs = start_pgofs - map->m_lblk; | ||
1079 | |||
1080 | f2fs_update_extent_cache_range(&dn, | ||
1081 | start_pgofs, map->m_pblk + ofs, | ||
1082 | map->m_len - ofs); | ||
1083 | } | ||
1084 | } | ||
1085 | |||
1034 | f2fs_put_dnode(&dn); | 1086 | f2fs_put_dnode(&dn); |
1035 | 1087 | ||
1036 | if (create) { | 1088 | if (create) { |
@@ -1040,6 +1092,17 @@ skip: | |||
1040 | goto next_dnode; | 1092 | goto next_dnode; |
1041 | 1093 | ||
1042 | sync_out: | 1094 | sync_out: |
1095 | if (flag == F2FS_GET_BLOCK_PRECACHE) { | ||
1096 | if (map->m_flags & F2FS_MAP_MAPPED) { | ||
1097 | unsigned int ofs = start_pgofs - map->m_lblk; | ||
1098 | |||
1099 | f2fs_update_extent_cache_range(&dn, | ||
1100 | start_pgofs, map->m_pblk + ofs, | ||
1101 | map->m_len - ofs); | ||
1102 | } | ||
1103 | if (map->m_next_extent) | ||
1104 | *map->m_next_extent = pgofs + 1; | ||
1105 | } | ||
1043 | f2fs_put_dnode(&dn); | 1106 | f2fs_put_dnode(&dn); |
1044 | unlock_out: | 1107 | unlock_out: |
1045 | if (create) { | 1108 | if (create) { |
@@ -1053,7 +1116,7 @@ out: | |||
1053 | 1116 | ||
1054 | static int __get_data_block(struct inode *inode, sector_t iblock, | 1117 | static int __get_data_block(struct inode *inode, sector_t iblock, |
1055 | struct buffer_head *bh, int create, int flag, | 1118 | struct buffer_head *bh, int create, int flag, |
1056 | pgoff_t *next_pgofs) | 1119 | pgoff_t *next_pgofs, int seg_type) |
1057 | { | 1120 | { |
1058 | struct f2fs_map_blocks map; | 1121 | struct f2fs_map_blocks map; |
1059 | int err; | 1122 | int err; |
@@ -1061,6 +1124,8 @@ static int __get_data_block(struct inode *inode, sector_t iblock, | |||
1061 | map.m_lblk = iblock; | 1124 | map.m_lblk = iblock; |
1062 | map.m_len = bh->b_size >> inode->i_blkbits; | 1125 | map.m_len = bh->b_size >> inode->i_blkbits; |
1063 | map.m_next_pgofs = next_pgofs; | 1126 | map.m_next_pgofs = next_pgofs; |
1127 | map.m_next_extent = NULL; | ||
1128 | map.m_seg_type = seg_type; | ||
1064 | 1129 | ||
1065 | err = f2fs_map_blocks(inode, &map, create, flag); | 1130 | err = f2fs_map_blocks(inode, &map, create, flag); |
1066 | if (!err) { | 1131 | if (!err) { |
@@ -1076,14 +1141,17 @@ static int get_data_block(struct inode *inode, sector_t iblock, | |||
1076 | pgoff_t *next_pgofs) | 1141 | pgoff_t *next_pgofs) |
1077 | { | 1142 | { |
1078 | return __get_data_block(inode, iblock, bh_result, create, | 1143 | return __get_data_block(inode, iblock, bh_result, create, |
1079 | flag, next_pgofs); | 1144 | flag, next_pgofs, |
1145 | NO_CHECK_TYPE); | ||
1080 | } | 1146 | } |
1081 | 1147 | ||
1082 | static int get_data_block_dio(struct inode *inode, sector_t iblock, | 1148 | static int get_data_block_dio(struct inode *inode, sector_t iblock, |
1083 | struct buffer_head *bh_result, int create) | 1149 | struct buffer_head *bh_result, int create) |
1084 | { | 1150 | { |
1085 | return __get_data_block(inode, iblock, bh_result, create, | 1151 | return __get_data_block(inode, iblock, bh_result, create, |
1086 | F2FS_GET_BLOCK_DEFAULT, NULL); | 1152 | F2FS_GET_BLOCK_DEFAULT, NULL, |
1153 | rw_hint_to_seg_type( | ||
1154 | inode->i_write_hint)); | ||
1087 | } | 1155 | } |
1088 | 1156 | ||
1089 | static int get_data_block_bmap(struct inode *inode, sector_t iblock, | 1157 | static int get_data_block_bmap(struct inode *inode, sector_t iblock, |
@@ -1094,7 +1162,8 @@ static int get_data_block_bmap(struct inode *inode, sector_t iblock, | |||
1094 | return -EFBIG; | 1162 | return -EFBIG; |
1095 | 1163 | ||
1096 | return __get_data_block(inode, iblock, bh_result, create, | 1164 | return __get_data_block(inode, iblock, bh_result, create, |
1097 | F2FS_GET_BLOCK_BMAP, NULL); | 1165 | F2FS_GET_BLOCK_BMAP, NULL, |
1166 | NO_CHECK_TYPE); | ||
1098 | } | 1167 | } |
1099 | 1168 | ||
1100 | static inline sector_t logical_to_blk(struct inode *inode, loff_t offset) | 1169 | static inline sector_t logical_to_blk(struct inode *inode, loff_t offset) |
@@ -1107,6 +1176,68 @@ static inline loff_t blk_to_logical(struct inode *inode, sector_t blk) | |||
1107 | return (blk << inode->i_blkbits); | 1176 | return (blk << inode->i_blkbits); |
1108 | } | 1177 | } |
1109 | 1178 | ||
1179 | static int f2fs_xattr_fiemap(struct inode *inode, | ||
1180 | struct fiemap_extent_info *fieinfo) | ||
1181 | { | ||
1182 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | ||
1183 | struct page *page; | ||
1184 | struct node_info ni; | ||
1185 | __u64 phys = 0, len; | ||
1186 | __u32 flags; | ||
1187 | nid_t xnid = F2FS_I(inode)->i_xattr_nid; | ||
1188 | int err = 0; | ||
1189 | |||
1190 | if (f2fs_has_inline_xattr(inode)) { | ||
1191 | int offset; | ||
1192 | |||
1193 | page = f2fs_grab_cache_page(NODE_MAPPING(sbi), | ||
1194 | inode->i_ino, false); | ||
1195 | if (!page) | ||
1196 | return -ENOMEM; | ||
1197 | |||
1198 | get_node_info(sbi, inode->i_ino, &ni); | ||
1199 | |||
1200 | phys = (__u64)blk_to_logical(inode, ni.blk_addr); | ||
1201 | offset = offsetof(struct f2fs_inode, i_addr) + | ||
1202 | sizeof(__le32) * (DEF_ADDRS_PER_INODE - | ||
1203 | get_inline_xattr_addrs(inode)); | ||
1204 | |||
1205 | phys += offset; | ||
1206 | len = inline_xattr_size(inode); | ||
1207 | |||
1208 | f2fs_put_page(page, 1); | ||
1209 | |||
1210 | flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED; | ||
1211 | |||
1212 | if (!xnid) | ||
1213 | flags |= FIEMAP_EXTENT_LAST; | ||
1214 | |||
1215 | err = fiemap_fill_next_extent(fieinfo, 0, phys, len, flags); | ||
1216 | if (err || err == 1) | ||
1217 | return err; | ||
1218 | } | ||
1219 | |||
1220 | if (xnid) { | ||
1221 | page = f2fs_grab_cache_page(NODE_MAPPING(sbi), xnid, false); | ||
1222 | if (!page) | ||
1223 | return -ENOMEM; | ||
1224 | |||
1225 | get_node_info(sbi, xnid, &ni); | ||
1226 | |||
1227 | phys = (__u64)blk_to_logical(inode, ni.blk_addr); | ||
1228 | len = inode->i_sb->s_blocksize; | ||
1229 | |||
1230 | f2fs_put_page(page, 1); | ||
1231 | |||
1232 | flags = FIEMAP_EXTENT_LAST; | ||
1233 | } | ||
1234 | |||
1235 | if (phys) | ||
1236 | err = fiemap_fill_next_extent(fieinfo, 0, phys, len, flags); | ||
1237 | |||
1238 | return (err < 0 ? err : 0); | ||
1239 | } | ||
1240 | |||
1110 | int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | 1241 | int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
1111 | u64 start, u64 len) | 1242 | u64 start, u64 len) |
1112 | { | 1243 | { |
@@ -1117,18 +1248,29 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | |||
1117 | u32 flags = 0; | 1248 | u32 flags = 0; |
1118 | int ret = 0; | 1249 | int ret = 0; |
1119 | 1250 | ||
1120 | ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC); | 1251 | if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) { |
1252 | ret = f2fs_precache_extents(inode); | ||
1253 | if (ret) | ||
1254 | return ret; | ||
1255 | } | ||
1256 | |||
1257 | ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR); | ||
1121 | if (ret) | 1258 | if (ret) |
1122 | return ret; | 1259 | return ret; |
1123 | 1260 | ||
1261 | inode_lock(inode); | ||
1262 | |||
1263 | if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) { | ||
1264 | ret = f2fs_xattr_fiemap(inode, fieinfo); | ||
1265 | goto out; | ||
1266 | } | ||
1267 | |||
1124 | if (f2fs_has_inline_data(inode)) { | 1268 | if (f2fs_has_inline_data(inode)) { |
1125 | ret = f2fs_inline_data_fiemap(inode, fieinfo, start, len); | 1269 | ret = f2fs_inline_data_fiemap(inode, fieinfo, start, len); |
1126 | if (ret != -EAGAIN) | 1270 | if (ret != -EAGAIN) |
1127 | return ret; | 1271 | goto out; |
1128 | } | 1272 | } |
1129 | 1273 | ||
1130 | inode_lock(inode); | ||
1131 | |||
1132 | if (logical_to_blk(inode, len) == 0) | 1274 | if (logical_to_blk(inode, len) == 0) |
1133 | len = blk_to_logical(inode, 1); | 1275 | len = blk_to_logical(inode, 1); |
1134 | 1276 | ||
@@ -1198,7 +1340,6 @@ static int f2fs_mpage_readpages(struct address_space *mapping, | |||
1198 | unsigned nr_pages) | 1340 | unsigned nr_pages) |
1199 | { | 1341 | { |
1200 | struct bio *bio = NULL; | 1342 | struct bio *bio = NULL; |
1201 | unsigned page_idx; | ||
1202 | sector_t last_block_in_bio = 0; | 1343 | sector_t last_block_in_bio = 0; |
1203 | struct inode *inode = mapping->host; | 1344 | struct inode *inode = mapping->host; |
1204 | const unsigned blkbits = inode->i_blkbits; | 1345 | const unsigned blkbits = inode->i_blkbits; |
@@ -1214,9 +1355,10 @@ static int f2fs_mpage_readpages(struct address_space *mapping, | |||
1214 | map.m_len = 0; | 1355 | map.m_len = 0; |
1215 | map.m_flags = 0; | 1356 | map.m_flags = 0; |
1216 | map.m_next_pgofs = NULL; | 1357 | map.m_next_pgofs = NULL; |
1358 | map.m_next_extent = NULL; | ||
1359 | map.m_seg_type = NO_CHECK_TYPE; | ||
1217 | 1360 | ||
1218 | for (page_idx = 0; nr_pages; page_idx++, nr_pages--) { | 1361 | for (; nr_pages; nr_pages--) { |
1219 | |||
1220 | if (pages) { | 1362 | if (pages) { |
1221 | page = list_last_entry(pages, struct page, lru); | 1363 | page = list_last_entry(pages, struct page, lru); |
1222 | 1364 | ||
@@ -1376,18 +1518,79 @@ retry_encrypt: | |||
1376 | return PTR_ERR(fio->encrypted_page); | 1518 | return PTR_ERR(fio->encrypted_page); |
1377 | } | 1519 | } |
1378 | 1520 | ||
1521 | static inline bool check_inplace_update_policy(struct inode *inode, | ||
1522 | struct f2fs_io_info *fio) | ||
1523 | { | ||
1524 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | ||
1525 | unsigned int policy = SM_I(sbi)->ipu_policy; | ||
1526 | |||
1527 | if (policy & (0x1 << F2FS_IPU_FORCE)) | ||
1528 | return true; | ||
1529 | if (policy & (0x1 << F2FS_IPU_SSR) && need_SSR(sbi)) | ||
1530 | return true; | ||
1531 | if (policy & (0x1 << F2FS_IPU_UTIL) && | ||
1532 | utilization(sbi) > SM_I(sbi)->min_ipu_util) | ||
1533 | return true; | ||
1534 | if (policy & (0x1 << F2FS_IPU_SSR_UTIL) && need_SSR(sbi) && | ||
1535 | utilization(sbi) > SM_I(sbi)->min_ipu_util) | ||
1536 | return true; | ||
1537 | |||
1538 | /* | ||
1539 | * IPU for rewrite async pages | ||
1540 | */ | ||
1541 | if (policy & (0x1 << F2FS_IPU_ASYNC) && | ||
1542 | fio && fio->op == REQ_OP_WRITE && | ||
1543 | !(fio->op_flags & REQ_SYNC) && | ||
1544 | !f2fs_encrypted_inode(inode)) | ||
1545 | return true; | ||
1546 | |||
1547 | /* this is only set during fdatasync */ | ||
1548 | if (policy & (0x1 << F2FS_IPU_FSYNC) && | ||
1549 | is_inode_flag_set(inode, FI_NEED_IPU)) | ||
1550 | return true; | ||
1551 | |||
1552 | return false; | ||
1553 | } | ||
1554 | |||
1555 | bool should_update_inplace(struct inode *inode, struct f2fs_io_info *fio) | ||
1556 | { | ||
1557 | if (f2fs_is_pinned_file(inode)) | ||
1558 | return true; | ||
1559 | |||
1560 | /* if this is cold file, we should overwrite to avoid fragmentation */ | ||
1561 | if (file_is_cold(inode)) | ||
1562 | return true; | ||
1563 | |||
1564 | return check_inplace_update_policy(inode, fio); | ||
1565 | } | ||
1566 | |||
1567 | bool should_update_outplace(struct inode *inode, struct f2fs_io_info *fio) | ||
1568 | { | ||
1569 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | ||
1570 | |||
1571 | if (test_opt(sbi, LFS)) | ||
1572 | return true; | ||
1573 | if (S_ISDIR(inode->i_mode)) | ||
1574 | return true; | ||
1575 | if (f2fs_is_atomic_file(inode)) | ||
1576 | return true; | ||
1577 | if (fio) { | ||
1578 | if (is_cold_data(fio->page)) | ||
1579 | return true; | ||
1580 | if (IS_ATOMIC_WRITTEN_PAGE(fio->page)) | ||
1581 | return true; | ||
1582 | } | ||
1583 | return false; | ||
1584 | } | ||
1585 | |||
1379 | static inline bool need_inplace_update(struct f2fs_io_info *fio) | 1586 | static inline bool need_inplace_update(struct f2fs_io_info *fio) |
1380 | { | 1587 | { |
1381 | struct inode *inode = fio->page->mapping->host; | 1588 | struct inode *inode = fio->page->mapping->host; |
1382 | 1589 | ||
1383 | if (S_ISDIR(inode->i_mode) || f2fs_is_atomic_file(inode)) | 1590 | if (should_update_outplace(inode, fio)) |
1384 | return false; | ||
1385 | if (is_cold_data(fio->page)) | ||
1386 | return false; | ||
1387 | if (IS_ATOMIC_WRITTEN_PAGE(fio->page)) | ||
1388 | return false; | 1591 | return false; |
1389 | 1592 | ||
1390 | return need_inplace_update_policy(inode, fio); | 1593 | return should_update_inplace(inode, fio); |
1391 | } | 1594 | } |
1392 | 1595 | ||
1393 | static inline bool valid_ipu_blkaddr(struct f2fs_io_info *fio) | 1596 | static inline bool valid_ipu_blkaddr(struct f2fs_io_info *fio) |
@@ -1508,10 +1711,17 @@ static int __write_data_page(struct page *page, bool *submitted, | |||
1508 | .submitted = false, | 1711 | .submitted = false, |
1509 | .need_lock = LOCK_RETRY, | 1712 | .need_lock = LOCK_RETRY, |
1510 | .io_type = io_type, | 1713 | .io_type = io_type, |
1714 | .io_wbc = wbc, | ||
1511 | }; | 1715 | }; |
1512 | 1716 | ||
1513 | trace_f2fs_writepage(page, DATA); | 1717 | trace_f2fs_writepage(page, DATA); |
1514 | 1718 | ||
1719 | /* we should bypass data pages to proceed the kworkder jobs */ | ||
1720 | if (unlikely(f2fs_cp_error(sbi))) { | ||
1721 | mapping_set_error(page->mapping, -EIO); | ||
1722 | goto out; | ||
1723 | } | ||
1724 | |||
1515 | if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) | 1725 | if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) |
1516 | goto redirty_out; | 1726 | goto redirty_out; |
1517 | 1727 | ||
@@ -1536,12 +1746,6 @@ write: | |||
1536 | available_free_memory(sbi, BASE_CHECK)))) | 1746 | available_free_memory(sbi, BASE_CHECK)))) |
1537 | goto redirty_out; | 1747 | goto redirty_out; |
1538 | 1748 | ||
1539 | /* we should bypass data pages to proceed the kworkder jobs */ | ||
1540 | if (unlikely(f2fs_cp_error(sbi))) { | ||
1541 | mapping_set_error(page->mapping, -EIO); | ||
1542 | goto out; | ||
1543 | } | ||
1544 | |||
1545 | /* Dentry blocks are controlled by checkpoint */ | 1749 | /* Dentry blocks are controlled by checkpoint */ |
1546 | if (S_ISDIR(inode->i_mode)) { | 1750 | if (S_ISDIR(inode->i_mode)) { |
1547 | fio.need_lock = LOCK_DONE; | 1751 | fio.need_lock = LOCK_DONE; |
@@ -1571,10 +1775,14 @@ write: | |||
1571 | } | 1775 | } |
1572 | } | 1776 | } |
1573 | 1777 | ||
1574 | down_write(&F2FS_I(inode)->i_sem); | 1778 | if (err) { |
1575 | if (F2FS_I(inode)->last_disk_size < psize) | 1779 | file_set_keep_isize(inode); |
1576 | F2FS_I(inode)->last_disk_size = psize; | 1780 | } else { |
1577 | up_write(&F2FS_I(inode)->i_sem); | 1781 | down_write(&F2FS_I(inode)->i_sem); |
1782 | if (F2FS_I(inode)->last_disk_size < psize) | ||
1783 | F2FS_I(inode)->last_disk_size = psize; | ||
1784 | up_write(&F2FS_I(inode)->i_sem); | ||
1785 | } | ||
1578 | 1786 | ||
1579 | done: | 1787 | done: |
1580 | if (err && err != -ENOENT) | 1788 | if (err && err != -ENOENT) |
@@ -1933,7 +2141,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, | |||
1933 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | 2141 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
1934 | struct page *page = NULL; | 2142 | struct page *page = NULL; |
1935 | pgoff_t index = ((unsigned long long) pos) >> PAGE_SHIFT; | 2143 | pgoff_t index = ((unsigned long long) pos) >> PAGE_SHIFT; |
1936 | bool need_balance = false; | 2144 | bool need_balance = false, drop_atomic = false; |
1937 | block_t blkaddr = NULL_ADDR; | 2145 | block_t blkaddr = NULL_ADDR; |
1938 | int err = 0; | 2146 | int err = 0; |
1939 | 2147 | ||
@@ -1942,6 +2150,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, | |||
1942 | if (f2fs_is_atomic_file(inode) && | 2150 | if (f2fs_is_atomic_file(inode) && |
1943 | !available_free_memory(sbi, INMEM_PAGES)) { | 2151 | !available_free_memory(sbi, INMEM_PAGES)) { |
1944 | err = -ENOMEM; | 2152 | err = -ENOMEM; |
2153 | drop_atomic = true; | ||
1945 | goto fail; | 2154 | goto fail; |
1946 | } | 2155 | } |
1947 | 2156 | ||
@@ -2022,7 +2231,7 @@ repeat: | |||
2022 | fail: | 2231 | fail: |
2023 | f2fs_put_page(page, 1); | 2232 | f2fs_put_page(page, 1); |
2024 | f2fs_write_failed(mapping, pos + len); | 2233 | f2fs_write_failed(mapping, pos + len); |
2025 | if (f2fs_is_atomic_file(inode)) | 2234 | if (drop_atomic) |
2026 | drop_inmem_pages_all(sbi); | 2235 | drop_inmem_pages_all(sbi); |
2027 | return err; | 2236 | return err; |
2028 | } | 2237 | } |
diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index ecada8425268..a66107b5cfff 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c | |||
@@ -49,14 +49,7 @@ static void update_general_status(struct f2fs_sb_info *sbi) | |||
49 | si->ndirty_imeta = get_pages(sbi, F2FS_DIRTY_IMETA); | 49 | si->ndirty_imeta = get_pages(sbi, F2FS_DIRTY_IMETA); |
50 | si->ndirty_dirs = sbi->ndirty_inode[DIR_INODE]; | 50 | si->ndirty_dirs = sbi->ndirty_inode[DIR_INODE]; |
51 | si->ndirty_files = sbi->ndirty_inode[FILE_INODE]; | 51 | si->ndirty_files = sbi->ndirty_inode[FILE_INODE]; |
52 | 52 | si->nquota_files = sbi->nquota_files; | |
53 | si->nquota_files = 0; | ||
54 | if (f2fs_sb_has_quota_ino(sbi->sb)) { | ||
55 | for (i = 0; i < MAXQUOTAS; i++) { | ||
56 | if (f2fs_qf_ino(sbi->sb, i)) | ||
57 | si->nquota_files++; | ||
58 | } | ||
59 | } | ||
60 | si->ndirty_all = sbi->ndirty_inode[DIRTY_META]; | 53 | si->ndirty_all = sbi->ndirty_inode[DIRTY_META]; |
61 | si->inmem_pages = get_pages(sbi, F2FS_INMEM_PAGES); | 54 | si->inmem_pages = get_pages(sbi, F2FS_INMEM_PAGES); |
62 | si->aw_cnt = atomic_read(&sbi->aw_cnt); | 55 | si->aw_cnt = atomic_read(&sbi->aw_cnt); |
@@ -186,7 +179,6 @@ static void update_mem_info(struct f2fs_sb_info *sbi) | |||
186 | si->base_mem += sizeof(struct f2fs_sb_info) + sbi->sb->s_blocksize; | 179 | si->base_mem += sizeof(struct f2fs_sb_info) + sbi->sb->s_blocksize; |
187 | si->base_mem += 2 * sizeof(struct f2fs_inode_info); | 180 | si->base_mem += 2 * sizeof(struct f2fs_inode_info); |
188 | si->base_mem += sizeof(*sbi->ckpt); | 181 | si->base_mem += sizeof(*sbi->ckpt); |
189 | si->base_mem += sizeof(struct percpu_counter) * NR_COUNT_TYPE; | ||
190 | 182 | ||
191 | /* build sm */ | 183 | /* build sm */ |
192 | si->base_mem += sizeof(struct f2fs_sm_info); | 184 | si->base_mem += sizeof(struct f2fs_sm_info); |
@@ -447,7 +439,7 @@ int f2fs_build_stats(struct f2fs_sb_info *sbi) | |||
447 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); | 439 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); |
448 | struct f2fs_stat_info *si; | 440 | struct f2fs_stat_info *si; |
449 | 441 | ||
450 | si = kzalloc(sizeof(struct f2fs_stat_info), GFP_KERNEL); | 442 | si = f2fs_kzalloc(sbi, sizeof(struct f2fs_stat_info), GFP_KERNEL); |
451 | if (!si) | 443 | if (!si) |
452 | return -ENOMEM; | 444 | return -ENOMEM; |
453 | 445 | ||
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 2d98d877c09d..f00b5ed8c011 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c | |||
@@ -713,6 +713,8 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, | |||
713 | 713 | ||
714 | f2fs_update_time(F2FS_I_SB(dir), REQ_TIME); | 714 | f2fs_update_time(F2FS_I_SB(dir), REQ_TIME); |
715 | 715 | ||
716 | add_ino_entry(F2FS_I_SB(dir), dir->i_ino, TRANS_DIR_INO); | ||
717 | |||
716 | if (f2fs_has_inline_dentry(dir)) | 718 | if (f2fs_has_inline_dentry(dir)) |
717 | return f2fs_delete_inline_entry(dentry, page, dir, inode); | 719 | return f2fs_delete_inline_entry(dentry, page, dir, inode); |
718 | 720 | ||
@@ -798,6 +800,7 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, | |||
798 | unsigned int bit_pos; | 800 | unsigned int bit_pos; |
799 | struct f2fs_dir_entry *de = NULL; | 801 | struct f2fs_dir_entry *de = NULL; |
800 | struct fscrypt_str de_name = FSTR_INIT(NULL, 0); | 802 | struct fscrypt_str de_name = FSTR_INIT(NULL, 0); |
803 | struct f2fs_sb_info *sbi = F2FS_I_SB(d->inode); | ||
801 | 804 | ||
802 | bit_pos = ((unsigned long)ctx->pos % d->max); | 805 | bit_pos = ((unsigned long)ctx->pos % d->max); |
803 | 806 | ||
@@ -836,6 +839,9 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, | |||
836 | le32_to_cpu(de->ino), d_type)) | 839 | le32_to_cpu(de->ino), d_type)) |
837 | return 1; | 840 | return 1; |
838 | 841 | ||
842 | if (sbi->readdir_ra == 1) | ||
843 | ra_node_page(sbi, le32_to_cpu(de->ino)); | ||
844 | |||
839 | bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); | 845 | bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); |
840 | ctx->pos = start_pos + bit_pos; | 846 | ctx->pos = start_pos + bit_pos; |
841 | } | 847 | } |
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 6abf26c31d01..6300ac5bcbe4 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/magic.h> | 19 | #include <linux/magic.h> |
20 | #include <linux/kobject.h> | 20 | #include <linux/kobject.h> |
21 | #include <linux/sched.h> | 21 | #include <linux/sched.h> |
22 | #include <linux/cred.h> | ||
22 | #include <linux/vmalloc.h> | 23 | #include <linux/vmalloc.h> |
23 | #include <linux/bio.h> | 24 | #include <linux/bio.h> |
24 | #include <linux/blkdev.h> | 25 | #include <linux/blkdev.h> |
@@ -43,6 +44,7 @@ | |||
43 | #ifdef CONFIG_F2FS_FAULT_INJECTION | 44 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
44 | enum { | 45 | enum { |
45 | FAULT_KMALLOC, | 46 | FAULT_KMALLOC, |
47 | FAULT_KVMALLOC, | ||
46 | FAULT_PAGE_ALLOC, | 48 | FAULT_PAGE_ALLOC, |
47 | FAULT_PAGE_GET, | 49 | FAULT_PAGE_GET, |
48 | FAULT_ALLOC_BIO, | 50 | FAULT_ALLOC_BIO, |
@@ -94,6 +96,7 @@ extern char *fault_name[FAULT_MAX]; | |||
94 | #define F2FS_MOUNT_PRJQUOTA 0x00200000 | 96 | #define F2FS_MOUNT_PRJQUOTA 0x00200000 |
95 | #define F2FS_MOUNT_QUOTA 0x00400000 | 97 | #define F2FS_MOUNT_QUOTA 0x00400000 |
96 | #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 | 98 | #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 |
99 | #define F2FS_MOUNT_RESERVE_ROOT 0x01000000 | ||
97 | 100 | ||
98 | #define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option) | 101 | #define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option) |
99 | #define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option) | 102 | #define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option) |
@@ -121,6 +124,7 @@ struct f2fs_mount_info { | |||
121 | #define F2FS_FEATURE_INODE_CHKSUM 0x0020 | 124 | #define F2FS_FEATURE_INODE_CHKSUM 0x0020 |
122 | #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 | 125 | #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 |
123 | #define F2FS_FEATURE_QUOTA_INO 0x0080 | 126 | #define F2FS_FEATURE_QUOTA_INO 0x0080 |
127 | #define F2FS_FEATURE_INODE_CRTIME 0x0100 | ||
124 | 128 | ||
125 | #define F2FS_HAS_FEATURE(sb, mask) \ | 129 | #define F2FS_HAS_FEATURE(sb, mask) \ |
126 | ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) | 130 | ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) |
@@ -130,6 +134,12 @@ struct f2fs_mount_info { | |||
130 | (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) | 134 | (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) |
131 | 135 | ||
132 | /* | 136 | /* |
137 | * Default values for user and/or group using reserved blocks | ||
138 | */ | ||
139 | #define F2FS_DEF_RESUID 0 | ||
140 | #define F2FS_DEF_RESGID 0 | ||
141 | |||
142 | /* | ||
133 | * For checkpoint manager | 143 | * For checkpoint manager |
134 | */ | 144 | */ |
135 | enum { | 145 | enum { |
@@ -179,6 +189,7 @@ enum { | |||
179 | ORPHAN_INO, /* for orphan ino list */ | 189 | ORPHAN_INO, /* for orphan ino list */ |
180 | APPEND_INO, /* for append ino list */ | 190 | APPEND_INO, /* for append ino list */ |
181 | UPDATE_INO, /* for update ino list */ | 191 | UPDATE_INO, /* for update ino list */ |
192 | TRANS_DIR_INO, /* for trasactions dir ino list */ | ||
182 | FLUSH_INO, /* for multiple device flushing */ | 193 | FLUSH_INO, /* for multiple device flushing */ |
183 | MAX_INO_ENTRY, /* max. list */ | 194 | MAX_INO_ENTRY, /* max. list */ |
184 | }; | 195 | }; |
@@ -264,7 +275,6 @@ struct discard_cmd_control { | |||
264 | struct task_struct *f2fs_issue_discard; /* discard thread */ | 275 | struct task_struct *f2fs_issue_discard; /* discard thread */ |
265 | struct list_head entry_list; /* 4KB discard entry list */ | 276 | struct list_head entry_list; /* 4KB discard entry list */ |
266 | struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ | 277 | struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ |
267 | unsigned char pend_list_tag[MAX_PLIST_NUM];/* tag for pending entries */ | ||
268 | struct list_head wait_list; /* store on-flushing entries */ | 278 | struct list_head wait_list; /* store on-flushing entries */ |
269 | struct list_head fstrim_list; /* in-flight discard from fstrim */ | 279 | struct list_head fstrim_list; /* in-flight discard from fstrim */ |
270 | wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ | 280 | wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ |
@@ -347,6 +357,9 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal, | |||
347 | #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ | 357 | #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ |
348 | struct f2fs_gc_range) | 358 | struct f2fs_gc_range) |
349 | #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32) | 359 | #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32) |
360 | #define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32) | ||
361 | #define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32) | ||
362 | #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) | ||
350 | 363 | ||
351 | #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY | 364 | #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY |
352 | #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY | 365 | #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY |
@@ -402,10 +415,9 @@ struct f2fs_flush_device { | |||
402 | #define DEF_MIN_INLINE_SIZE 1 | 415 | #define DEF_MIN_INLINE_SIZE 1 |
403 | static inline int get_extra_isize(struct inode *inode); | 416 | static inline int get_extra_isize(struct inode *inode); |
404 | static inline int get_inline_xattr_addrs(struct inode *inode); | 417 | static inline int get_inline_xattr_addrs(struct inode *inode); |
405 | #define F2FS_INLINE_XATTR_ADDRS(inode) get_inline_xattr_addrs(inode) | ||
406 | #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ | 418 | #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ |
407 | (CUR_ADDRS_PER_INODE(inode) - \ | 419 | (CUR_ADDRS_PER_INODE(inode) - \ |
408 | F2FS_INLINE_XATTR_ADDRS(inode) - \ | 420 | get_inline_xattr_addrs(inode) - \ |
409 | DEF_INLINE_RESERVED_SIZE)) | 421 | DEF_INLINE_RESERVED_SIZE)) |
410 | 422 | ||
411 | /* for inline dir */ | 423 | /* for inline dir */ |
@@ -542,6 +554,8 @@ struct f2fs_map_blocks { | |||
542 | unsigned int m_len; | 554 | unsigned int m_len; |
543 | unsigned int m_flags; | 555 | unsigned int m_flags; |
544 | pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ | 556 | pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ |
557 | pgoff_t *m_next_extent; /* point to next possible extent */ | ||
558 | int m_seg_type; | ||
545 | }; | 559 | }; |
546 | 560 | ||
547 | /* for flag in get_data_block */ | 561 | /* for flag in get_data_block */ |
@@ -551,6 +565,7 @@ enum { | |||
551 | F2FS_GET_BLOCK_BMAP, | 565 | F2FS_GET_BLOCK_BMAP, |
552 | F2FS_GET_BLOCK_PRE_DIO, | 566 | F2FS_GET_BLOCK_PRE_DIO, |
553 | F2FS_GET_BLOCK_PRE_AIO, | 567 | F2FS_GET_BLOCK_PRE_AIO, |
568 | F2FS_GET_BLOCK_PRECACHE, | ||
554 | }; | 569 | }; |
555 | 570 | ||
556 | /* | 571 | /* |
@@ -583,7 +598,10 @@ struct f2fs_inode_info { | |||
583 | unsigned long i_flags; /* keep an inode flags for ioctl */ | 598 | unsigned long i_flags; /* keep an inode flags for ioctl */ |
584 | unsigned char i_advise; /* use to give file attribute hints */ | 599 | unsigned char i_advise; /* use to give file attribute hints */ |
585 | unsigned char i_dir_level; /* use for dentry level for large dir */ | 600 | unsigned char i_dir_level; /* use for dentry level for large dir */ |
586 | unsigned int i_current_depth; /* use only in directory structure */ | 601 | union { |
602 | unsigned int i_current_depth; /* only for directory depth */ | ||
603 | unsigned short i_gc_failures; /* only for regular file */ | ||
604 | }; | ||
587 | unsigned int i_pino; /* parent inode number */ | 605 | unsigned int i_pino; /* parent inode number */ |
588 | umode_t i_acl_mode; /* keep file acl mode temporarily */ | 606 | umode_t i_acl_mode; /* keep file acl mode temporarily */ |
589 | 607 | ||
@@ -618,6 +636,7 @@ struct f2fs_inode_info { | |||
618 | int i_extra_isize; /* size of extra space located in i_addr */ | 636 | int i_extra_isize; /* size of extra space located in i_addr */ |
619 | kprojid_t i_projid; /* id for project quota */ | 637 | kprojid_t i_projid; /* id for project quota */ |
620 | int i_inline_xattr_size; /* inline xattr size */ | 638 | int i_inline_xattr_size; /* inline xattr size */ |
639 | struct timespec i_crtime; /* inode creation time */ | ||
621 | }; | 640 | }; |
622 | 641 | ||
623 | static inline void get_extent_info(struct extent_info *ext, | 642 | static inline void get_extent_info(struct extent_info *ext, |
@@ -922,6 +941,7 @@ enum cp_reason_type { | |||
922 | CP_NODE_NEED_CP, | 941 | CP_NODE_NEED_CP, |
923 | CP_FASTBOOT_MODE, | 942 | CP_FASTBOOT_MODE, |
924 | CP_SPEC_LOG_NUM, | 943 | CP_SPEC_LOG_NUM, |
944 | CP_RECOVER_DIR, | ||
925 | }; | 945 | }; |
926 | 946 | ||
927 | enum iostat_type { | 947 | enum iostat_type { |
@@ -957,6 +977,7 @@ struct f2fs_io_info { | |||
957 | int need_lock; /* indicate we need to lock cp_rwsem */ | 977 | int need_lock; /* indicate we need to lock cp_rwsem */ |
958 | bool in_list; /* indicate fio is in io_list */ | 978 | bool in_list; /* indicate fio is in io_list */ |
959 | enum iostat_type io_type; /* io type */ | 979 | enum iostat_type io_type; /* io type */ |
980 | struct writeback_control *io_wbc; /* writeback control */ | ||
960 | }; | 981 | }; |
961 | 982 | ||
962 | #define is_read_io(rw) ((rw) == READ) | 983 | #define is_read_io(rw) ((rw) == READ) |
@@ -1093,6 +1114,7 @@ struct f2fs_sb_info { | |||
1093 | int dir_level; /* directory level */ | 1114 | int dir_level; /* directory level */ |
1094 | int inline_xattr_size; /* inline xattr size */ | 1115 | int inline_xattr_size; /* inline xattr size */ |
1095 | unsigned int trigger_ssr_threshold; /* threshold to trigger ssr */ | 1116 | unsigned int trigger_ssr_threshold; /* threshold to trigger ssr */ |
1117 | int readdir_ra; /* readahead inode in readdir */ | ||
1096 | 1118 | ||
1097 | block_t user_block_count; /* # of user blocks */ | 1119 | block_t user_block_count; /* # of user blocks */ |
1098 | block_t total_valid_block_count; /* # of valid blocks */ | 1120 | block_t total_valid_block_count; /* # of valid blocks */ |
@@ -1100,6 +1122,11 @@ struct f2fs_sb_info { | |||
1100 | block_t last_valid_block_count; /* for recovery */ | 1122 | block_t last_valid_block_count; /* for recovery */ |
1101 | block_t reserved_blocks; /* configurable reserved blocks */ | 1123 | block_t reserved_blocks; /* configurable reserved blocks */ |
1102 | block_t current_reserved_blocks; /* current reserved blocks */ | 1124 | block_t current_reserved_blocks; /* current reserved blocks */ |
1125 | block_t root_reserved_blocks; /* root reserved blocks */ | ||
1126 | kuid_t s_resuid; /* reserved blocks for uid */ | ||
1127 | kgid_t s_resgid; /* reserved blocks for gid */ | ||
1128 | |||
1129 | unsigned int nquota_files; /* # of quota sysfile */ | ||
1103 | 1130 | ||
1104 | u32 s_next_generation; /* for NFS support */ | 1131 | u32 s_next_generation; /* for NFS support */ |
1105 | 1132 | ||
@@ -1124,6 +1151,9 @@ struct f2fs_sb_info { | |||
1124 | /* threshold for converting bg victims for fg */ | 1151 | /* threshold for converting bg victims for fg */ |
1125 | u64 fggc_threshold; | 1152 | u64 fggc_threshold; |
1126 | 1153 | ||
1154 | /* threshold for gc trials on pinned files */ | ||
1155 | u64 gc_pin_file_threshold; | ||
1156 | |||
1127 | /* maximum # of trials to find a victim segment for SSR and GC */ | 1157 | /* maximum # of trials to find a victim segment for SSR and GC */ |
1128 | unsigned int max_victim_search; | 1158 | unsigned int max_victim_search; |
1129 | 1159 | ||
@@ -1250,33 +1280,7 @@ static inline bool is_idle(struct f2fs_sb_info *sbi) | |||
1250 | /* | 1280 | /* |
1251 | * Inline functions | 1281 | * Inline functions |
1252 | */ | 1282 | */ |
1253 | static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, | 1283 | static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc, |
1254 | unsigned int length) | ||
1255 | { | ||
1256 | SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); | ||
1257 | u32 *ctx = (u32 *)shash_desc_ctx(shash); | ||
1258 | u32 retval; | ||
1259 | int err; | ||
1260 | |||
1261 | shash->tfm = sbi->s_chksum_driver; | ||
1262 | shash->flags = 0; | ||
1263 | *ctx = F2FS_SUPER_MAGIC; | ||
1264 | |||
1265 | err = crypto_shash_update(shash, address, length); | ||
1266 | BUG_ON(err); | ||
1267 | |||
1268 | retval = *ctx; | ||
1269 | barrier_data(ctx); | ||
1270 | return retval; | ||
1271 | } | ||
1272 | |||
1273 | static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, | ||
1274 | void *buf, size_t buf_size) | ||
1275 | { | ||
1276 | return f2fs_crc32(sbi, buf, buf_size) == blk_crc; | ||
1277 | } | ||
1278 | |||
1279 | static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, | ||
1280 | const void *address, unsigned int length) | 1284 | const void *address, unsigned int length) |
1281 | { | 1285 | { |
1282 | struct { | 1286 | struct { |
@@ -1297,6 +1301,24 @@ static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, | |||
1297 | return *(u32 *)desc.ctx; | 1301 | return *(u32 *)desc.ctx; |
1298 | } | 1302 | } |
1299 | 1303 | ||
1304 | static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, | ||
1305 | unsigned int length) | ||
1306 | { | ||
1307 | return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length); | ||
1308 | } | ||
1309 | |||
1310 | static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, | ||
1311 | void *buf, size_t buf_size) | ||
1312 | { | ||
1313 | return f2fs_crc32(sbi, buf, buf_size) == blk_crc; | ||
1314 | } | ||
1315 | |||
1316 | static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, | ||
1317 | const void *address, unsigned int length) | ||
1318 | { | ||
1319 | return __f2fs_crc32(sbi, crc, address, length); | ||
1320 | } | ||
1321 | |||
1300 | static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) | 1322 | static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) |
1301 | { | 1323 | { |
1302 | return container_of(inode, struct f2fs_inode_info, vfs_inode); | 1324 | return container_of(inode, struct f2fs_inode_info, vfs_inode); |
@@ -1555,6 +1577,25 @@ static inline bool f2fs_has_xattr_block(unsigned int ofs) | |||
1555 | return ofs == XATTR_NODE_OFFSET; | 1577 | return ofs == XATTR_NODE_OFFSET; |
1556 | } | 1578 | } |
1557 | 1579 | ||
1580 | static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi, | ||
1581 | struct inode *inode) | ||
1582 | { | ||
1583 | if (!inode) | ||
1584 | return true; | ||
1585 | if (!test_opt(sbi, RESERVE_ROOT)) | ||
1586 | return false; | ||
1587 | if (IS_NOQUOTA(inode)) | ||
1588 | return true; | ||
1589 | if (capable(CAP_SYS_RESOURCE)) | ||
1590 | return true; | ||
1591 | if (uid_eq(sbi->s_resuid, current_fsuid())) | ||
1592 | return true; | ||
1593 | if (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && | ||
1594 | in_group_p(sbi->s_resgid)) | ||
1595 | return true; | ||
1596 | return false; | ||
1597 | } | ||
1598 | |||
1558 | static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); | 1599 | static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); |
1559 | static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, | 1600 | static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, |
1560 | struct inode *inode, blkcnt_t *count) | 1601 | struct inode *inode, blkcnt_t *count) |
@@ -1584,11 +1625,17 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, | |||
1584 | sbi->total_valid_block_count += (block_t)(*count); | 1625 | sbi->total_valid_block_count += (block_t)(*count); |
1585 | avail_user_block_count = sbi->user_block_count - | 1626 | avail_user_block_count = sbi->user_block_count - |
1586 | sbi->current_reserved_blocks; | 1627 | sbi->current_reserved_blocks; |
1628 | |||
1629 | if (!__allow_reserved_blocks(sbi, inode)) | ||
1630 | avail_user_block_count -= sbi->root_reserved_blocks; | ||
1631 | |||
1587 | if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { | 1632 | if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { |
1588 | diff = sbi->total_valid_block_count - avail_user_block_count; | 1633 | diff = sbi->total_valid_block_count - avail_user_block_count; |
1634 | if (diff > *count) | ||
1635 | diff = *count; | ||
1589 | *count -= diff; | 1636 | *count -= diff; |
1590 | release = diff; | 1637 | release = diff; |
1591 | sbi->total_valid_block_count = avail_user_block_count; | 1638 | sbi->total_valid_block_count -= diff; |
1592 | if (!*count) { | 1639 | if (!*count) { |
1593 | spin_unlock(&sbi->stat_lock); | 1640 | spin_unlock(&sbi->stat_lock); |
1594 | percpu_counter_sub(&sbi->alloc_valid_block_count, diff); | 1641 | percpu_counter_sub(&sbi->alloc_valid_block_count, diff); |
@@ -1597,7 +1644,7 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, | |||
1597 | } | 1644 | } |
1598 | spin_unlock(&sbi->stat_lock); | 1645 | spin_unlock(&sbi->stat_lock); |
1599 | 1646 | ||
1600 | if (release) | 1647 | if (unlikely(release)) |
1601 | dquot_release_reservation_block(inode, release); | 1648 | dquot_release_reservation_block(inode, release); |
1602 | f2fs_i_blocks_write(inode, *count, true, true); | 1649 | f2fs_i_blocks_write(inode, *count, true, true); |
1603 | return 0; | 1650 | return 0; |
@@ -1777,9 +1824,13 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, | |||
1777 | 1824 | ||
1778 | spin_lock(&sbi->stat_lock); | 1825 | spin_lock(&sbi->stat_lock); |
1779 | 1826 | ||
1780 | valid_block_count = sbi->total_valid_block_count + 1; | 1827 | valid_block_count = sbi->total_valid_block_count + |
1781 | if (unlikely(valid_block_count + sbi->current_reserved_blocks > | 1828 | sbi->current_reserved_blocks + 1; |
1782 | sbi->user_block_count)) { | 1829 | |
1830 | if (!__allow_reserved_blocks(sbi, inode)) | ||
1831 | valid_block_count += sbi->root_reserved_blocks; | ||
1832 | |||
1833 | if (unlikely(valid_block_count > sbi->user_block_count)) { | ||
1783 | spin_unlock(&sbi->stat_lock); | 1834 | spin_unlock(&sbi->stat_lock); |
1784 | goto enospc; | 1835 | goto enospc; |
1785 | } | 1836 | } |
@@ -1992,11 +2043,11 @@ static inline block_t datablock_addr(struct inode *inode, | |||
1992 | raw_node = F2FS_NODE(node_page); | 2043 | raw_node = F2FS_NODE(node_page); |
1993 | 2044 | ||
1994 | /* from GC path only */ | 2045 | /* from GC path only */ |
1995 | if (!inode) { | 2046 | if (is_inode) { |
1996 | if (is_inode) | 2047 | if (!inode) |
1997 | base = offset_in_addr(&raw_node->i); | 2048 | base = offset_in_addr(&raw_node->i); |
1998 | } else if (f2fs_has_extra_attr(inode) && is_inode) { | 2049 | else if (f2fs_has_extra_attr(inode)) |
1999 | base = get_extra_isize(inode); | 2050 | base = get_extra_isize(inode); |
2000 | } | 2051 | } |
2001 | 2052 | ||
2002 | addr_array = blkaddr_in_node(raw_node); | 2053 | addr_array = blkaddr_in_node(raw_node); |
@@ -2107,6 +2158,7 @@ enum { | |||
2107 | FI_HOT_DATA, /* indicate file is hot */ | 2158 | FI_HOT_DATA, /* indicate file is hot */ |
2108 | FI_EXTRA_ATTR, /* indicate file has extra attribute */ | 2159 | FI_EXTRA_ATTR, /* indicate file has extra attribute */ |
2109 | FI_PROJ_INHERIT, /* indicate file inherits projectid */ | 2160 | FI_PROJ_INHERIT, /* indicate file inherits projectid */ |
2161 | FI_PIN_FILE, /* indicate file should not be gced */ | ||
2110 | }; | 2162 | }; |
2111 | 2163 | ||
2112 | static inline void __mark_inode_dirty_flag(struct inode *inode, | 2164 | static inline void __mark_inode_dirty_flag(struct inode *inode, |
@@ -2116,10 +2168,12 @@ static inline void __mark_inode_dirty_flag(struct inode *inode, | |||
2116 | case FI_INLINE_XATTR: | 2168 | case FI_INLINE_XATTR: |
2117 | case FI_INLINE_DATA: | 2169 | case FI_INLINE_DATA: |
2118 | case FI_INLINE_DENTRY: | 2170 | case FI_INLINE_DENTRY: |
2171 | case FI_NEW_INODE: | ||
2119 | if (set) | 2172 | if (set) |
2120 | return; | 2173 | return; |
2121 | case FI_DATA_EXIST: | 2174 | case FI_DATA_EXIST: |
2122 | case FI_INLINE_DOTS: | 2175 | case FI_INLINE_DOTS: |
2176 | case FI_PIN_FILE: | ||
2123 | f2fs_mark_inode_dirty_sync(inode, true); | 2177 | f2fs_mark_inode_dirty_sync(inode, true); |
2124 | } | 2178 | } |
2125 | } | 2179 | } |
@@ -2200,6 +2254,13 @@ static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) | |||
2200 | f2fs_mark_inode_dirty_sync(inode, true); | 2254 | f2fs_mark_inode_dirty_sync(inode, true); |
2201 | } | 2255 | } |
2202 | 2256 | ||
2257 | static inline void f2fs_i_gc_failures_write(struct inode *inode, | ||
2258 | unsigned int count) | ||
2259 | { | ||
2260 | F2FS_I(inode)->i_gc_failures = count; | ||
2261 | f2fs_mark_inode_dirty_sync(inode, true); | ||
2262 | } | ||
2263 | |||
2203 | static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) | 2264 | static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) |
2204 | { | 2265 | { |
2205 | F2FS_I(inode)->i_xattr_nid = xnid; | 2266 | F2FS_I(inode)->i_xattr_nid = xnid; |
@@ -2228,6 +2289,8 @@ static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) | |||
2228 | set_bit(FI_INLINE_DOTS, &fi->flags); | 2289 | set_bit(FI_INLINE_DOTS, &fi->flags); |
2229 | if (ri->i_inline & F2FS_EXTRA_ATTR) | 2290 | if (ri->i_inline & F2FS_EXTRA_ATTR) |
2230 | set_bit(FI_EXTRA_ATTR, &fi->flags); | 2291 | set_bit(FI_EXTRA_ATTR, &fi->flags); |
2292 | if (ri->i_inline & F2FS_PIN_FILE) | ||
2293 | set_bit(FI_PIN_FILE, &fi->flags); | ||
2231 | } | 2294 | } |
2232 | 2295 | ||
2233 | static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) | 2296 | static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) |
@@ -2246,6 +2309,8 @@ static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) | |||
2246 | ri->i_inline |= F2FS_INLINE_DOTS; | 2309 | ri->i_inline |= F2FS_INLINE_DOTS; |
2247 | if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) | 2310 | if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) |
2248 | ri->i_inline |= F2FS_EXTRA_ATTR; | 2311 | ri->i_inline |= F2FS_EXTRA_ATTR; |
2312 | if (is_inode_flag_set(inode, FI_PIN_FILE)) | ||
2313 | ri->i_inline |= F2FS_PIN_FILE; | ||
2249 | } | 2314 | } |
2250 | 2315 | ||
2251 | static inline int f2fs_has_extra_attr(struct inode *inode) | 2316 | static inline int f2fs_has_extra_attr(struct inode *inode) |
@@ -2260,7 +2325,7 @@ static inline int f2fs_has_inline_xattr(struct inode *inode) | |||
2260 | 2325 | ||
2261 | static inline unsigned int addrs_per_inode(struct inode *inode) | 2326 | static inline unsigned int addrs_per_inode(struct inode *inode) |
2262 | { | 2327 | { |
2263 | return CUR_ADDRS_PER_INODE(inode) - F2FS_INLINE_XATTR_ADDRS(inode); | 2328 | return CUR_ADDRS_PER_INODE(inode) - get_inline_xattr_addrs(inode); |
2264 | } | 2329 | } |
2265 | 2330 | ||
2266 | static inline void *inline_xattr_addr(struct inode *inode, struct page *page) | 2331 | static inline void *inline_xattr_addr(struct inode *inode, struct page *page) |
@@ -2268,7 +2333,7 @@ static inline void *inline_xattr_addr(struct inode *inode, struct page *page) | |||
2268 | struct f2fs_inode *ri = F2FS_INODE(page); | 2333 | struct f2fs_inode *ri = F2FS_INODE(page); |
2269 | 2334 | ||
2270 | return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - | 2335 | return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - |
2271 | F2FS_INLINE_XATTR_ADDRS(inode)]); | 2336 | get_inline_xattr_addrs(inode)]); |
2272 | } | 2337 | } |
2273 | 2338 | ||
2274 | static inline int inline_xattr_size(struct inode *inode) | 2339 | static inline int inline_xattr_size(struct inode *inode) |
@@ -2291,6 +2356,11 @@ static inline int f2fs_has_inline_dots(struct inode *inode) | |||
2291 | return is_inode_flag_set(inode, FI_INLINE_DOTS); | 2356 | return is_inode_flag_set(inode, FI_INLINE_DOTS); |
2292 | } | 2357 | } |
2293 | 2358 | ||
2359 | static inline bool f2fs_is_pinned_file(struct inode *inode) | ||
2360 | { | ||
2361 | return is_inode_flag_set(inode, FI_PIN_FILE); | ||
2362 | } | ||
2363 | |||
2294 | static inline bool f2fs_is_atomic_file(struct inode *inode) | 2364 | static inline bool f2fs_is_atomic_file(struct inode *inode) |
2295 | { | 2365 | { |
2296 | return is_inode_flag_set(inode, FI_ATOMIC_FILE); | 2366 | return is_inode_flag_set(inode, FI_ATOMIC_FILE); |
@@ -2418,12 +2488,35 @@ static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, | |||
2418 | return kmalloc(size, flags); | 2488 | return kmalloc(size, flags); |
2419 | } | 2489 | } |
2420 | 2490 | ||
2491 | static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, | ||
2492 | size_t size, gfp_t flags) | ||
2493 | { | ||
2494 | return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO); | ||
2495 | } | ||
2496 | |||
2497 | static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi, | ||
2498 | size_t size, gfp_t flags) | ||
2499 | { | ||
2500 | #ifdef CONFIG_F2FS_FAULT_INJECTION | ||
2501 | if (time_to_inject(sbi, FAULT_KVMALLOC)) { | ||
2502 | f2fs_show_injection_info(FAULT_KVMALLOC); | ||
2503 | return NULL; | ||
2504 | } | ||
2505 | #endif | ||
2506 | return kvmalloc(size, flags); | ||
2507 | } | ||
2508 | |||
2509 | static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi, | ||
2510 | size_t size, gfp_t flags) | ||
2511 | { | ||
2512 | return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO); | ||
2513 | } | ||
2514 | |||
2421 | static inline int get_extra_isize(struct inode *inode) | 2515 | static inline int get_extra_isize(struct inode *inode) |
2422 | { | 2516 | { |
2423 | return F2FS_I(inode)->i_extra_isize / sizeof(__le32); | 2517 | return F2FS_I(inode)->i_extra_isize / sizeof(__le32); |
2424 | } | 2518 | } |
2425 | 2519 | ||
2426 | static inline int f2fs_sb_has_flexible_inline_xattr(struct super_block *sb); | ||
2427 | static inline int get_inline_xattr_addrs(struct inode *inode) | 2520 | static inline int get_inline_xattr_addrs(struct inode *inode) |
2428 | { | 2521 | { |
2429 | return F2FS_I(inode)->i_inline_xattr_size; | 2522 | return F2FS_I(inode)->i_inline_xattr_size; |
@@ -2479,9 +2572,11 @@ int f2fs_getattr(const struct path *path, struct kstat *stat, | |||
2479 | u32 request_mask, unsigned int flags); | 2572 | u32 request_mask, unsigned int flags); |
2480 | int f2fs_setattr(struct dentry *dentry, struct iattr *attr); | 2573 | int f2fs_setattr(struct dentry *dentry, struct iattr *attr); |
2481 | int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); | 2574 | int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); |
2482 | int truncate_data_blocks_range(struct dnode_of_data *dn, int count); | 2575 | void truncate_data_blocks_range(struct dnode_of_data *dn, int count); |
2576 | int f2fs_precache_extents(struct inode *inode); | ||
2483 | long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); | 2577 | long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); |
2484 | long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | 2578 | long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
2579 | int f2fs_pin_file_control(struct inode *inode, bool inc); | ||
2485 | 2580 | ||
2486 | /* | 2581 | /* |
2487 | * inode.c | 2582 | * inode.c |
@@ -2492,8 +2587,8 @@ void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); | |||
2492 | struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); | 2587 | struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); |
2493 | struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); | 2588 | struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); |
2494 | int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); | 2589 | int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); |
2495 | int update_inode(struct inode *inode, struct page *node_page); | 2590 | void update_inode(struct inode *inode, struct page *node_page); |
2496 | int update_inode_page(struct inode *inode); | 2591 | void update_inode_page(struct inode *inode); |
2497 | int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); | 2592 | int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); |
2498 | void f2fs_evict_inode(struct inode *inode); | 2593 | void f2fs_evict_inode(struct inode *inode); |
2499 | void handle_failed_inode(struct inode *inode); | 2594 | void handle_failed_inode(struct inode *inode); |
@@ -2604,10 +2699,9 @@ void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); | |||
2604 | void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); | 2699 | void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); |
2605 | int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); | 2700 | int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); |
2606 | void recover_inline_xattr(struct inode *inode, struct page *page); | 2701 | void recover_inline_xattr(struct inode *inode, struct page *page); |
2607 | int recover_xattr_data(struct inode *inode, struct page *page, | 2702 | int recover_xattr_data(struct inode *inode, struct page *page); |
2608 | block_t blkaddr); | ||
2609 | int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); | 2703 | int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); |
2610 | int restore_node_summary(struct f2fs_sb_info *sbi, | 2704 | void restore_node_summary(struct f2fs_sb_info *sbi, |
2611 | unsigned int segno, struct f2fs_summary_block *sum); | 2705 | unsigned int segno, struct f2fs_summary_block *sum); |
2612 | void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); | 2706 | void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); |
2613 | int build_node_manager(struct f2fs_sb_info *sbi); | 2707 | int build_node_manager(struct f2fs_sb_info *sbi); |
@@ -2634,6 +2728,7 @@ void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); | |||
2634 | bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); | 2728 | bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); |
2635 | void init_discard_policy(struct discard_policy *dpolicy, int discard_type, | 2729 | void init_discard_policy(struct discard_policy *dpolicy, int discard_type, |
2636 | unsigned int granularity); | 2730 | unsigned int granularity); |
2731 | void drop_discard_cmd(struct f2fs_sb_info *sbi); | ||
2637 | void stop_discard_thread(struct f2fs_sb_info *sbi); | 2732 | void stop_discard_thread(struct f2fs_sb_info *sbi); |
2638 | bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); | 2733 | bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); |
2639 | void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); | 2734 | void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); |
@@ -2672,6 +2767,7 @@ int build_segment_manager(struct f2fs_sb_info *sbi); | |||
2672 | void destroy_segment_manager(struct f2fs_sb_info *sbi); | 2767 | void destroy_segment_manager(struct f2fs_sb_info *sbi); |
2673 | int __init create_segment_manager_caches(void); | 2768 | int __init create_segment_manager_caches(void); |
2674 | void destroy_segment_manager_caches(void); | 2769 | void destroy_segment_manager_caches(void); |
2770 | int rw_hint_to_seg_type(enum rw_hint hint); | ||
2675 | 2771 | ||
2676 | /* | 2772 | /* |
2677 | * checkpoint.c | 2773 | * checkpoint.c |
@@ -2741,6 +2837,8 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, | |||
2741 | int create, int flag); | 2837 | int create, int flag); |
2742 | int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | 2838 | int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
2743 | u64 start, u64 len); | 2839 | u64 start, u64 len); |
2840 | bool should_update_inplace(struct inode *inode, struct f2fs_io_info *fio); | ||
2841 | bool should_update_outplace(struct inode *inode, struct f2fs_io_info *fio); | ||
2744 | void f2fs_set_page_dirty_nobuffers(struct page *page); | 2842 | void f2fs_set_page_dirty_nobuffers(struct page *page); |
2745 | int __f2fs_write_data_pages(struct address_space *mapping, | 2843 | int __f2fs_write_data_pages(struct address_space *mapping, |
2746 | struct writeback_control *wbc, | 2844 | struct writeback_control *wbc, |
@@ -3109,6 +3207,11 @@ static inline int f2fs_sb_has_quota_ino(struct super_block *sb) | |||
3109 | return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_QUOTA_INO); | 3207 | return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_QUOTA_INO); |
3110 | } | 3208 | } |
3111 | 3209 | ||
3210 | static inline int f2fs_sb_has_inode_crtime(struct super_block *sb) | ||
3211 | { | ||
3212 | return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_INODE_CRTIME); | ||
3213 | } | ||
3214 | |||
3112 | #ifdef CONFIG_BLK_DEV_ZONED | 3215 | #ifdef CONFIG_BLK_DEV_ZONED |
3113 | static inline int get_blkz_type(struct f2fs_sb_info *sbi, | 3216 | static inline int get_blkz_type(struct f2fs_sb_info *sbi, |
3114 | struct block_device *bdev, block_t blkaddr) | 3217 | struct block_device *bdev, block_t blkaddr) |
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 7874bbd7311d..672a542e5464 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c | |||
@@ -165,6 +165,9 @@ static inline enum cp_reason_type need_do_checkpoint(struct inode *inode) | |||
165 | cp_reason = CP_FASTBOOT_MODE; | 165 | cp_reason = CP_FASTBOOT_MODE; |
166 | else if (sbi->active_logs == 2) | 166 | else if (sbi->active_logs == 2) |
167 | cp_reason = CP_SPEC_LOG_NUM; | 167 | cp_reason = CP_SPEC_LOG_NUM; |
168 | else if (need_dentry_mark(sbi, inode->i_ino) && | ||
169 | exist_written_data(sbi, F2FS_I(inode)->i_pino, TRANS_DIR_INO)) | ||
170 | cp_reason = CP_RECOVER_DIR; | ||
168 | 171 | ||
169 | return cp_reason; | 172 | return cp_reason; |
170 | } | 173 | } |
@@ -472,26 +475,14 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma) | |||
472 | 475 | ||
473 | static int f2fs_file_open(struct inode *inode, struct file *filp) | 476 | static int f2fs_file_open(struct inode *inode, struct file *filp) |
474 | { | 477 | { |
475 | struct dentry *dir; | 478 | int err = fscrypt_file_open(inode, filp); |
476 | 479 | ||
477 | if (f2fs_encrypted_inode(inode)) { | 480 | if (err) |
478 | int ret = fscrypt_get_encryption_info(inode); | 481 | return err; |
479 | if (ret) | ||
480 | return -EACCES; | ||
481 | if (!fscrypt_has_encryption_key(inode)) | ||
482 | return -ENOKEY; | ||
483 | } | ||
484 | dir = dget_parent(file_dentry(filp)); | ||
485 | if (f2fs_encrypted_inode(d_inode(dir)) && | ||
486 | !fscrypt_has_permitted_context(d_inode(dir), inode)) { | ||
487 | dput(dir); | ||
488 | return -EPERM; | ||
489 | } | ||
490 | dput(dir); | ||
491 | return dquot_file_open(inode, filp); | 482 | return dquot_file_open(inode, filp); |
492 | } | 483 | } |
493 | 484 | ||
494 | int truncate_data_blocks_range(struct dnode_of_data *dn, int count) | 485 | void truncate_data_blocks_range(struct dnode_of_data *dn, int count) |
495 | { | 486 | { |
496 | struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); | 487 | struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); |
497 | struct f2fs_node *raw_node; | 488 | struct f2fs_node *raw_node; |
@@ -534,7 +525,6 @@ int truncate_data_blocks_range(struct dnode_of_data *dn, int count) | |||
534 | f2fs_update_time(sbi, REQ_TIME); | 525 | f2fs_update_time(sbi, REQ_TIME); |
535 | trace_f2fs_truncate_data_blocks_range(dn->inode, dn->nid, | 526 | trace_f2fs_truncate_data_blocks_range(dn->inode, dn->nid, |
536 | dn->ofs_in_node, nr_free); | 527 | dn->ofs_in_node, nr_free); |
537 | return nr_free; | ||
538 | } | 528 | } |
539 | 529 | ||
540 | void truncate_data_blocks(struct dnode_of_data *dn) | 530 | void truncate_data_blocks(struct dnode_of_data *dn) |
@@ -682,8 +672,17 @@ int f2fs_getattr(const struct path *path, struct kstat *stat, | |||
682 | { | 672 | { |
683 | struct inode *inode = d_inode(path->dentry); | 673 | struct inode *inode = d_inode(path->dentry); |
684 | struct f2fs_inode_info *fi = F2FS_I(inode); | 674 | struct f2fs_inode_info *fi = F2FS_I(inode); |
675 | struct f2fs_inode *ri; | ||
685 | unsigned int flags; | 676 | unsigned int flags; |
686 | 677 | ||
678 | if (f2fs_has_extra_attr(inode) && | ||
679 | f2fs_sb_has_inode_crtime(inode->i_sb) && | ||
680 | F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, i_crtime)) { | ||
681 | stat->result_mask |= STATX_BTIME; | ||
682 | stat->btime.tv_sec = fi->i_crtime.tv_sec; | ||
683 | stat->btime.tv_nsec = fi->i_crtime.tv_nsec; | ||
684 | } | ||
685 | |||
687 | flags = fi->i_flags & (FS_FL_USER_VISIBLE | FS_PROJINHERIT_FL); | 686 | flags = fi->i_flags & (FS_FL_USER_VISIBLE | FS_PROJINHERIT_FL); |
688 | if (flags & FS_APPEND_FL) | 687 | if (flags & FS_APPEND_FL) |
689 | stat->attributes |= STATX_ATTR_APPEND; | 688 | stat->attributes |= STATX_ATTR_APPEND; |
@@ -755,6 +754,10 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) | |||
755 | if (err) | 754 | if (err) |
756 | return err; | 755 | return err; |
757 | 756 | ||
757 | err = fscrypt_prepare_setattr(dentry, attr); | ||
758 | if (err) | ||
759 | return err; | ||
760 | |||
758 | if (is_quota_modification(inode, attr)) { | 761 | if (is_quota_modification(inode, attr)) { |
759 | err = dquot_initialize(inode); | 762 | err = dquot_initialize(inode); |
760 | if (err) | 763 | if (err) |
@@ -770,14 +773,6 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) | |||
770 | } | 773 | } |
771 | 774 | ||
772 | if (attr->ia_valid & ATTR_SIZE) { | 775 | if (attr->ia_valid & ATTR_SIZE) { |
773 | if (f2fs_encrypted_inode(inode)) { | ||
774 | err = fscrypt_get_encryption_info(inode); | ||
775 | if (err) | ||
776 | return err; | ||
777 | if (!fscrypt_has_encryption_key(inode)) | ||
778 | return -ENOKEY; | ||
779 | } | ||
780 | |||
781 | if (attr->ia_size <= i_size_read(inode)) { | 776 | if (attr->ia_size <= i_size_read(inode)) { |
782 | down_write(&F2FS_I(inode)->i_mmap_sem); | 777 | down_write(&F2FS_I(inode)->i_mmap_sem); |
783 | truncate_setsize(inode, attr->ia_size); | 778 | truncate_setsize(inode, attr->ia_size); |
@@ -1114,11 +1109,13 @@ static int __exchange_data_block(struct inode *src_inode, | |||
1114 | while (len) { | 1109 | while (len) { |
1115 | olen = min((pgoff_t)4 * ADDRS_PER_BLOCK, len); | 1110 | olen = min((pgoff_t)4 * ADDRS_PER_BLOCK, len); |
1116 | 1111 | ||
1117 | src_blkaddr = kvzalloc(sizeof(block_t) * olen, GFP_KERNEL); | 1112 | src_blkaddr = f2fs_kvzalloc(F2FS_I_SB(src_inode), |
1113 | sizeof(block_t) * olen, GFP_KERNEL); | ||
1118 | if (!src_blkaddr) | 1114 | if (!src_blkaddr) |
1119 | return -ENOMEM; | 1115 | return -ENOMEM; |
1120 | 1116 | ||
1121 | do_replace = kvzalloc(sizeof(int) * olen, GFP_KERNEL); | 1117 | do_replace = f2fs_kvzalloc(F2FS_I_SB(src_inode), |
1118 | sizeof(int) * olen, GFP_KERNEL); | ||
1122 | if (!do_replace) { | 1119 | if (!do_replace) { |
1123 | kvfree(src_blkaddr); | 1120 | kvfree(src_blkaddr); |
1124 | return -ENOMEM; | 1121 | return -ENOMEM; |
@@ -1186,14 +1183,14 @@ static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len) | |||
1186 | pg_start = offset >> PAGE_SHIFT; | 1183 | pg_start = offset >> PAGE_SHIFT; |
1187 | pg_end = (offset + len) >> PAGE_SHIFT; | 1184 | pg_end = (offset + len) >> PAGE_SHIFT; |
1188 | 1185 | ||
1186 | /* avoid gc operation during block exchange */ | ||
1187 | down_write(&F2FS_I(inode)->dio_rwsem[WRITE]); | ||
1188 | |||
1189 | down_write(&F2FS_I(inode)->i_mmap_sem); | 1189 | down_write(&F2FS_I(inode)->i_mmap_sem); |
1190 | /* write out all dirty pages from offset */ | 1190 | /* write out all dirty pages from offset */ |
1191 | ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX); | 1191 | ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX); |
1192 | if (ret) | 1192 | if (ret) |
1193 | goto out; | 1193 | goto out_unlock; |
1194 | |||
1195 | /* avoid gc operation during block exchange */ | ||
1196 | down_write(&F2FS_I(inode)->dio_rwsem[WRITE]); | ||
1197 | 1194 | ||
1198 | truncate_pagecache(inode, offset); | 1195 | truncate_pagecache(inode, offset); |
1199 | 1196 | ||
@@ -1212,9 +1209,8 @@ static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len) | |||
1212 | if (!ret) | 1209 | if (!ret) |
1213 | f2fs_i_size_write(inode, new_size); | 1210 | f2fs_i_size_write(inode, new_size); |
1214 | out_unlock: | 1211 | out_unlock: |
1215 | up_write(&F2FS_I(inode)->dio_rwsem[WRITE]); | ||
1216 | out: | ||
1217 | up_write(&F2FS_I(inode)->i_mmap_sem); | 1212 | up_write(&F2FS_I(inode)->i_mmap_sem); |
1213 | up_write(&F2FS_I(inode)->dio_rwsem[WRITE]); | ||
1218 | return ret; | 1214 | return ret; |
1219 | } | 1215 | } |
1220 | 1216 | ||
@@ -1385,6 +1381,9 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len) | |||
1385 | 1381 | ||
1386 | f2fs_balance_fs(sbi, true); | 1382 | f2fs_balance_fs(sbi, true); |
1387 | 1383 | ||
1384 | /* avoid gc operation during block exchange */ | ||
1385 | down_write(&F2FS_I(inode)->dio_rwsem[WRITE]); | ||
1386 | |||
1388 | down_write(&F2FS_I(inode)->i_mmap_sem); | 1387 | down_write(&F2FS_I(inode)->i_mmap_sem); |
1389 | ret = truncate_blocks(inode, i_size_read(inode), true); | 1388 | ret = truncate_blocks(inode, i_size_read(inode), true); |
1390 | if (ret) | 1389 | if (ret) |
@@ -1395,9 +1394,6 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len) | |||
1395 | if (ret) | 1394 | if (ret) |
1396 | goto out; | 1395 | goto out; |
1397 | 1396 | ||
1398 | /* avoid gc operation during block exchange */ | ||
1399 | down_write(&F2FS_I(inode)->dio_rwsem[WRITE]); | ||
1400 | |||
1401 | truncate_pagecache(inode, offset); | 1397 | truncate_pagecache(inode, offset); |
1402 | 1398 | ||
1403 | pg_start = offset >> PAGE_SHIFT; | 1399 | pg_start = offset >> PAGE_SHIFT; |
@@ -1425,10 +1421,9 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len) | |||
1425 | 1421 | ||
1426 | if (!ret) | 1422 | if (!ret) |
1427 | f2fs_i_size_write(inode, new_size); | 1423 | f2fs_i_size_write(inode, new_size); |
1428 | |||
1429 | up_write(&F2FS_I(inode)->dio_rwsem[WRITE]); | ||
1430 | out: | 1424 | out: |
1431 | up_write(&F2FS_I(inode)->i_mmap_sem); | 1425 | up_write(&F2FS_I(inode)->i_mmap_sem); |
1426 | up_write(&F2FS_I(inode)->dio_rwsem[WRITE]); | ||
1432 | return ret; | 1427 | return ret; |
1433 | } | 1428 | } |
1434 | 1429 | ||
@@ -1436,7 +1431,8 @@ static int expand_inode_data(struct inode *inode, loff_t offset, | |||
1436 | loff_t len, int mode) | 1431 | loff_t len, int mode) |
1437 | { | 1432 | { |
1438 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | 1433 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
1439 | struct f2fs_map_blocks map = { .m_next_pgofs = NULL }; | 1434 | struct f2fs_map_blocks map = { .m_next_pgofs = NULL, |
1435 | .m_next_extent = NULL, .m_seg_type = NO_CHECK_TYPE }; | ||
1440 | pgoff_t pg_end; | 1436 | pgoff_t pg_end; |
1441 | loff_t new_size = i_size_read(inode); | 1437 | loff_t new_size = i_size_read(inode); |
1442 | loff_t off_end; | 1438 | loff_t off_end; |
@@ -1852,14 +1848,20 @@ static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg) | |||
1852 | switch (in) { | 1848 | switch (in) { |
1853 | case F2FS_GOING_DOWN_FULLSYNC: | 1849 | case F2FS_GOING_DOWN_FULLSYNC: |
1854 | sb = freeze_bdev(sb->s_bdev); | 1850 | sb = freeze_bdev(sb->s_bdev); |
1855 | if (sb && !IS_ERR(sb)) { | 1851 | if (IS_ERR(sb)) { |
1852 | ret = PTR_ERR(sb); | ||
1853 | goto out; | ||
1854 | } | ||
1855 | if (sb) { | ||
1856 | f2fs_stop_checkpoint(sbi, false); | 1856 | f2fs_stop_checkpoint(sbi, false); |
1857 | thaw_bdev(sb->s_bdev, sb); | 1857 | thaw_bdev(sb->s_bdev, sb); |
1858 | } | 1858 | } |
1859 | break; | 1859 | break; |
1860 | case F2FS_GOING_DOWN_METASYNC: | 1860 | case F2FS_GOING_DOWN_METASYNC: |
1861 | /* do checkpoint only */ | 1861 | /* do checkpoint only */ |
1862 | f2fs_sync_fs(sb, 1); | 1862 | ret = f2fs_sync_fs(sb, 1); |
1863 | if (ret) | ||
1864 | goto out; | ||
1863 | f2fs_stop_checkpoint(sbi, false); | 1865 | f2fs_stop_checkpoint(sbi, false); |
1864 | break; | 1866 | break; |
1865 | case F2FS_GOING_DOWN_NOSYNC: | 1867 | case F2FS_GOING_DOWN_NOSYNC: |
@@ -1873,6 +1875,13 @@ static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg) | |||
1873 | ret = -EINVAL; | 1875 | ret = -EINVAL; |
1874 | goto out; | 1876 | goto out; |
1875 | } | 1877 | } |
1878 | |||
1879 | stop_gc_thread(sbi); | ||
1880 | stop_discard_thread(sbi); | ||
1881 | |||
1882 | drop_discard_cmd(sbi); | ||
1883 | clear_opt(sbi, DISCARD); | ||
1884 | |||
1876 | f2fs_update_time(sbi, REQ_TIME); | 1885 | f2fs_update_time(sbi, REQ_TIME); |
1877 | out: | 1886 | out: |
1878 | mnt_drop_write_file(filp); | 1887 | mnt_drop_write_file(filp); |
@@ -2084,9 +2093,10 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, | |||
2084 | struct f2fs_defragment *range) | 2093 | struct f2fs_defragment *range) |
2085 | { | 2094 | { |
2086 | struct inode *inode = file_inode(filp); | 2095 | struct inode *inode = file_inode(filp); |
2087 | struct f2fs_map_blocks map = { .m_next_pgofs = NULL }; | 2096 | struct f2fs_map_blocks map = { .m_next_extent = NULL, |
2097 | .m_seg_type = NO_CHECK_TYPE }; | ||
2088 | struct extent_info ei = {0,0,0}; | 2098 | struct extent_info ei = {0,0,0}; |
2089 | pgoff_t pg_start, pg_end; | 2099 | pgoff_t pg_start, pg_end, next_pgofs; |
2090 | unsigned int blk_per_seg = sbi->blocks_per_seg; | 2100 | unsigned int blk_per_seg = sbi->blocks_per_seg; |
2091 | unsigned int total = 0, sec_num; | 2101 | unsigned int total = 0, sec_num; |
2092 | block_t blk_end = 0; | 2102 | block_t blk_end = 0; |
@@ -2094,7 +2104,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, | |||
2094 | int err; | 2104 | int err; |
2095 | 2105 | ||
2096 | /* if in-place-update policy is enabled, don't waste time here */ | 2106 | /* if in-place-update policy is enabled, don't waste time here */ |
2097 | if (need_inplace_update_policy(inode, NULL)) | 2107 | if (should_update_inplace(inode, NULL)) |
2098 | return -EINVAL; | 2108 | return -EINVAL; |
2099 | 2109 | ||
2100 | pg_start = range->start >> PAGE_SHIFT; | 2110 | pg_start = range->start >> PAGE_SHIFT; |
@@ -2120,6 +2130,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, | |||
2120 | } | 2130 | } |
2121 | 2131 | ||
2122 | map.m_lblk = pg_start; | 2132 | map.m_lblk = pg_start; |
2133 | map.m_next_pgofs = &next_pgofs; | ||
2123 | 2134 | ||
2124 | /* | 2135 | /* |
2125 | * lookup mapping info in dnode page cache, skip defragmenting if all | 2136 | * lookup mapping info in dnode page cache, skip defragmenting if all |
@@ -2133,14 +2144,16 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, | |||
2133 | goto out; | 2144 | goto out; |
2134 | 2145 | ||
2135 | if (!(map.m_flags & F2FS_MAP_FLAGS)) { | 2146 | if (!(map.m_flags & F2FS_MAP_FLAGS)) { |
2136 | map.m_lblk++; | 2147 | map.m_lblk = next_pgofs; |
2137 | continue; | 2148 | continue; |
2138 | } | 2149 | } |
2139 | 2150 | ||
2140 | if (blk_end && blk_end != map.m_pblk) { | 2151 | if (blk_end && blk_end != map.m_pblk) |
2141 | fragmented = true; | 2152 | fragmented = true; |
2142 | break; | 2153 | |
2143 | } | 2154 | /* record total count of block that we're going to move */ |
2155 | total += map.m_len; | ||
2156 | |||
2144 | blk_end = map.m_pblk + map.m_len; | 2157 | blk_end = map.m_pblk + map.m_len; |
2145 | 2158 | ||
2146 | map.m_lblk += map.m_len; | 2159 | map.m_lblk += map.m_len; |
@@ -2149,10 +2162,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, | |||
2149 | if (!fragmented) | 2162 | if (!fragmented) |
2150 | goto out; | 2163 | goto out; |
2151 | 2164 | ||
2152 | map.m_lblk = pg_start; | 2165 | sec_num = (total + BLKS_PER_SEC(sbi) - 1) / BLKS_PER_SEC(sbi); |
2153 | map.m_len = pg_end - pg_start; | ||
2154 | |||
2155 | sec_num = (map.m_len + BLKS_PER_SEC(sbi) - 1) / BLKS_PER_SEC(sbi); | ||
2156 | 2166 | ||
2157 | /* | 2167 | /* |
2158 | * make sure there are enough free section for LFS allocation, this can | 2168 | * make sure there are enough free section for LFS allocation, this can |
@@ -2164,6 +2174,10 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, | |||
2164 | goto out; | 2174 | goto out; |
2165 | } | 2175 | } |
2166 | 2176 | ||
2177 | map.m_lblk = pg_start; | ||
2178 | map.m_len = pg_end - pg_start; | ||
2179 | total = 0; | ||
2180 | |||
2167 | while (map.m_lblk < pg_end) { | 2181 | while (map.m_lblk < pg_end) { |
2168 | pgoff_t idx; | 2182 | pgoff_t idx; |
2169 | int cnt = 0; | 2183 | int cnt = 0; |
@@ -2175,7 +2189,7 @@ do_map: | |||
2175 | goto clear_out; | 2189 | goto clear_out; |
2176 | 2190 | ||
2177 | if (!(map.m_flags & F2FS_MAP_FLAGS)) { | 2191 | if (!(map.m_flags & F2FS_MAP_FLAGS)) { |
2178 | map.m_lblk++; | 2192 | map.m_lblk = next_pgofs; |
2179 | continue; | 2193 | continue; |
2180 | } | 2194 | } |
2181 | 2195 | ||
@@ -2681,6 +2695,125 @@ static int f2fs_ioc_fssetxattr(struct file *filp, unsigned long arg) | |||
2681 | return 0; | 2695 | return 0; |
2682 | } | 2696 | } |
2683 | 2697 | ||
2698 | int f2fs_pin_file_control(struct inode *inode, bool inc) | ||
2699 | { | ||
2700 | struct f2fs_inode_info *fi = F2FS_I(inode); | ||
2701 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | ||
2702 | |||
2703 | /* Use i_gc_failures for normal file as a risk signal. */ | ||
2704 | if (inc) | ||
2705 | f2fs_i_gc_failures_write(inode, fi->i_gc_failures + 1); | ||
2706 | |||
2707 | if (fi->i_gc_failures > sbi->gc_pin_file_threshold) { | ||
2708 | f2fs_msg(sbi->sb, KERN_WARNING, | ||
2709 | "%s: Enable GC = ino %lx after %x GC trials\n", | ||
2710 | __func__, inode->i_ino, fi->i_gc_failures); | ||
2711 | clear_inode_flag(inode, FI_PIN_FILE); | ||
2712 | return -EAGAIN; | ||
2713 | } | ||
2714 | return 0; | ||
2715 | } | ||
2716 | |||
2717 | static int f2fs_ioc_set_pin_file(struct file *filp, unsigned long arg) | ||
2718 | { | ||
2719 | struct inode *inode = file_inode(filp); | ||
2720 | __u32 pin; | ||
2721 | int ret = 0; | ||
2722 | |||
2723 | if (!inode_owner_or_capable(inode)) | ||
2724 | return -EACCES; | ||
2725 | |||
2726 | if (get_user(pin, (__u32 __user *)arg)) | ||
2727 | return -EFAULT; | ||
2728 | |||
2729 | if (!S_ISREG(inode->i_mode)) | ||
2730 | return -EINVAL; | ||
2731 | |||
2732 | if (f2fs_readonly(F2FS_I_SB(inode)->sb)) | ||
2733 | return -EROFS; | ||
2734 | |||
2735 | ret = mnt_want_write_file(filp); | ||
2736 | if (ret) | ||
2737 | return ret; | ||
2738 | |||
2739 | inode_lock(inode); | ||
2740 | |||
2741 | if (should_update_outplace(inode, NULL)) { | ||
2742 | ret = -EINVAL; | ||
2743 | goto out; | ||
2744 | } | ||
2745 | |||
2746 | if (!pin) { | ||
2747 | clear_inode_flag(inode, FI_PIN_FILE); | ||
2748 | F2FS_I(inode)->i_gc_failures = 1; | ||
2749 | goto done; | ||
2750 | } | ||
2751 | |||
2752 | if (f2fs_pin_file_control(inode, false)) { | ||
2753 | ret = -EAGAIN; | ||
2754 | goto out; | ||
2755 | } | ||
2756 | ret = f2fs_convert_inline_inode(inode); | ||
2757 | if (ret) | ||
2758 | goto out; | ||
2759 | |||
2760 | set_inode_flag(inode, FI_PIN_FILE); | ||
2761 | ret = F2FS_I(inode)->i_gc_failures; | ||
2762 | done: | ||
2763 | f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); | ||
2764 | out: | ||
2765 | inode_unlock(inode); | ||
2766 | mnt_drop_write_file(filp); | ||
2767 | return ret; | ||
2768 | } | ||
2769 | |||
2770 | static int f2fs_ioc_get_pin_file(struct file *filp, unsigned long arg) | ||
2771 | { | ||
2772 | struct inode *inode = file_inode(filp); | ||
2773 | __u32 pin = 0; | ||
2774 | |||
2775 | if (is_inode_flag_set(inode, FI_PIN_FILE)) | ||
2776 | pin = F2FS_I(inode)->i_gc_failures; | ||
2777 | return put_user(pin, (u32 __user *)arg); | ||
2778 | } | ||
2779 | |||
2780 | int f2fs_precache_extents(struct inode *inode) | ||
2781 | { | ||
2782 | struct f2fs_inode_info *fi = F2FS_I(inode); | ||
2783 | struct f2fs_map_blocks map; | ||
2784 | pgoff_t m_next_extent; | ||
2785 | loff_t end; | ||
2786 | int err; | ||
2787 | |||
2788 | if (is_inode_flag_set(inode, FI_NO_EXTENT)) | ||
2789 | return -EOPNOTSUPP; | ||
2790 | |||
2791 | map.m_lblk = 0; | ||
2792 | map.m_next_pgofs = NULL; | ||
2793 | map.m_next_extent = &m_next_extent; | ||
2794 | map.m_seg_type = NO_CHECK_TYPE; | ||
2795 | end = F2FS_I_SB(inode)->max_file_blocks; | ||
2796 | |||
2797 | while (map.m_lblk < end) { | ||
2798 | map.m_len = end - map.m_lblk; | ||
2799 | |||
2800 | down_write(&fi->dio_rwsem[WRITE]); | ||
2801 | err = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_PRECACHE); | ||
2802 | up_write(&fi->dio_rwsem[WRITE]); | ||
2803 | if (err) | ||
2804 | return err; | ||
2805 | |||
2806 | map.m_lblk = m_next_extent; | ||
2807 | } | ||
2808 | |||
2809 | return err; | ||
2810 | } | ||
2811 | |||
2812 | static int f2fs_ioc_precache_extents(struct file *filp, unsigned long arg) | ||
2813 | { | ||
2814 | return f2fs_precache_extents(file_inode(filp)); | ||
2815 | } | ||
2816 | |||
2684 | long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | 2817 | long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
2685 | { | 2818 | { |
2686 | if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) | 2819 | if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) |
@@ -2731,6 +2864,12 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | |||
2731 | return f2fs_ioc_fsgetxattr(filp, arg); | 2864 | return f2fs_ioc_fsgetxattr(filp, arg); |
2732 | case F2FS_IOC_FSSETXATTR: | 2865 | case F2FS_IOC_FSSETXATTR: |
2733 | return f2fs_ioc_fssetxattr(filp, arg); | 2866 | return f2fs_ioc_fssetxattr(filp, arg); |
2867 | case F2FS_IOC_GET_PIN_FILE: | ||
2868 | return f2fs_ioc_get_pin_file(filp, arg); | ||
2869 | case F2FS_IOC_SET_PIN_FILE: | ||
2870 | return f2fs_ioc_set_pin_file(filp, arg); | ||
2871 | case F2FS_IOC_PRECACHE_EXTENTS: | ||
2872 | return f2fs_ioc_precache_extents(filp, arg); | ||
2734 | default: | 2873 | default: |
2735 | return -ENOTTY; | 2874 | return -ENOTTY; |
2736 | } | 2875 | } |
@@ -2806,6 +2945,9 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
2806 | case F2FS_IOC_GET_FEATURES: | 2945 | case F2FS_IOC_GET_FEATURES: |
2807 | case F2FS_IOC_FSGETXATTR: | 2946 | case F2FS_IOC_FSGETXATTR: |
2808 | case F2FS_IOC_FSSETXATTR: | 2947 | case F2FS_IOC_FSSETXATTR: |
2948 | case F2FS_IOC_GET_PIN_FILE: | ||
2949 | case F2FS_IOC_SET_PIN_FILE: | ||
2950 | case F2FS_IOC_PRECACHE_EXTENTS: | ||
2809 | break; | 2951 | break; |
2810 | default: | 2952 | default: |
2811 | return -ENOIOCTLCMD; | 2953 | return -ENOIOCTLCMD; |
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index d844dcb80570..aa720cc44509 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c | |||
@@ -624,6 +624,11 @@ static void move_data_block(struct inode *inode, block_t bidx, | |||
624 | if (f2fs_is_atomic_file(inode)) | 624 | if (f2fs_is_atomic_file(inode)) |
625 | goto out; | 625 | goto out; |
626 | 626 | ||
627 | if (f2fs_is_pinned_file(inode)) { | ||
628 | f2fs_pin_file_control(inode, true); | ||
629 | goto out; | ||
630 | } | ||
631 | |||
627 | set_new_dnode(&dn, inode, NULL, NULL, 0); | 632 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
628 | err = get_dnode_of_data(&dn, bidx, LOOKUP_NODE); | 633 | err = get_dnode_of_data(&dn, bidx, LOOKUP_NODE); |
629 | if (err) | 634 | if (err) |
@@ -686,7 +691,12 @@ static void move_data_block(struct inode *inode, block_t bidx, | |||
686 | fio.op = REQ_OP_WRITE; | 691 | fio.op = REQ_OP_WRITE; |
687 | fio.op_flags = REQ_SYNC; | 692 | fio.op_flags = REQ_SYNC; |
688 | fio.new_blkaddr = newaddr; | 693 | fio.new_blkaddr = newaddr; |
689 | f2fs_submit_page_write(&fio); | 694 | err = f2fs_submit_page_write(&fio); |
695 | if (err) { | ||
696 | if (PageWriteback(fio.encrypted_page)) | ||
697 | end_page_writeback(fio.encrypted_page); | ||
698 | goto put_page_out; | ||
699 | } | ||
690 | 700 | ||
691 | f2fs_update_iostat(fio.sbi, FS_GC_DATA_IO, F2FS_BLKSIZE); | 701 | f2fs_update_iostat(fio.sbi, FS_GC_DATA_IO, F2FS_BLKSIZE); |
692 | 702 | ||
@@ -720,6 +730,11 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type, | |||
720 | 730 | ||
721 | if (f2fs_is_atomic_file(inode)) | 731 | if (f2fs_is_atomic_file(inode)) |
722 | goto out; | 732 | goto out; |
733 | if (f2fs_is_pinned_file(inode)) { | ||
734 | if (gc_type == FG_GC) | ||
735 | f2fs_pin_file_control(inode, true); | ||
736 | goto out; | ||
737 | } | ||
723 | 738 | ||
724 | if (gc_type == BG_GC) { | 739 | if (gc_type == BG_GC) { |
725 | if (PageWriteback(page)) | 740 | if (PageWriteback(page)) |
@@ -1091,6 +1106,7 @@ void build_gc_manager(struct f2fs_sb_info *sbi) | |||
1091 | 1106 | ||
1092 | sbi->fggc_threshold = div64_u64((main_count - ovp_count) * | 1107 | sbi->fggc_threshold = div64_u64((main_count - ovp_count) * |
1093 | BLKS_PER_SEC(sbi), (main_count - resv_count)); | 1108 | BLKS_PER_SEC(sbi), (main_count - resv_count)); |
1109 | sbi->gc_pin_file_threshold = DEF_GC_FAILED_PINNED_FILES; | ||
1094 | 1110 | ||
1095 | /* give warm/cold data area from slower device */ | 1111 | /* give warm/cold data area from slower device */ |
1096 | if (sbi->s_ndevs && sbi->segs_per_sec == 1) | 1112 | if (sbi->s_ndevs && sbi->segs_per_sec == 1) |
diff --git a/fs/f2fs/gc.h b/fs/f2fs/gc.h index 9325191fab2d..b0045d4c8d1e 100644 --- a/fs/f2fs/gc.h +++ b/fs/f2fs/gc.h | |||
@@ -20,6 +20,8 @@ | |||
20 | #define LIMIT_INVALID_BLOCK 40 /* percentage over total user space */ | 20 | #define LIMIT_INVALID_BLOCK 40 /* percentage over total user space */ |
21 | #define LIMIT_FREE_BLOCK 40 /* percentage over invalid + free space */ | 21 | #define LIMIT_FREE_BLOCK 40 /* percentage over invalid + free space */ |
22 | 22 | ||
23 | #define DEF_GC_FAILED_PINNED_FILES 2048 | ||
24 | |||
23 | /* Search max. number of dirty segments to select a victim segment */ | 25 | /* Search max. number of dirty segments to select a victim segment */ |
24 | #define DEF_MAX_VICTIM_SEARCH 4096 /* covers 8GB */ | 26 | #define DEF_MAX_VICTIM_SEARCH 4096 /* covers 8GB */ |
25 | 27 | ||
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index b4c4f2b25304..89c838bfb067 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c | |||
@@ -22,6 +22,9 @@ | |||
22 | 22 | ||
23 | void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync) | 23 | void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync) |
24 | { | 24 | { |
25 | if (is_inode_flag_set(inode, FI_NEW_INODE)) | ||
26 | return; | ||
27 | |||
25 | if (f2fs_inode_dirtied(inode, sync)) | 28 | if (f2fs_inode_dirtied(inode, sync)) |
26 | return; | 29 | return; |
27 | 30 | ||
@@ -275,6 +278,12 @@ static int do_read_inode(struct inode *inode) | |||
275 | i_projid = F2FS_DEF_PROJID; | 278 | i_projid = F2FS_DEF_PROJID; |
276 | fi->i_projid = make_kprojid(&init_user_ns, i_projid); | 279 | fi->i_projid = make_kprojid(&init_user_ns, i_projid); |
277 | 280 | ||
281 | if (f2fs_has_extra_attr(inode) && f2fs_sb_has_inode_crtime(sbi->sb) && | ||
282 | F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, i_crtime)) { | ||
283 | fi->i_crtime.tv_sec = le64_to_cpu(ri->i_crtime); | ||
284 | fi->i_crtime.tv_nsec = le32_to_cpu(ri->i_crtime_nsec); | ||
285 | } | ||
286 | |||
278 | f2fs_put_page(node_page, 1); | 287 | f2fs_put_page(node_page, 1); |
279 | 288 | ||
280 | stat_inc_inline_xattr(inode); | 289 | stat_inc_inline_xattr(inode); |
@@ -360,14 +369,15 @@ retry: | |||
360 | return inode; | 369 | return inode; |
361 | } | 370 | } |
362 | 371 | ||
363 | int update_inode(struct inode *inode, struct page *node_page) | 372 | void update_inode(struct inode *inode, struct page *node_page) |
364 | { | 373 | { |
365 | struct f2fs_inode *ri; | 374 | struct f2fs_inode *ri; |
366 | struct extent_tree *et = F2FS_I(inode)->extent_tree; | 375 | struct extent_tree *et = F2FS_I(inode)->extent_tree; |
367 | 376 | ||
368 | f2fs_inode_synced(inode); | ||
369 | |||
370 | f2fs_wait_on_page_writeback(node_page, NODE, true); | 377 | f2fs_wait_on_page_writeback(node_page, NODE, true); |
378 | set_page_dirty(node_page); | ||
379 | |||
380 | f2fs_inode_synced(inode); | ||
371 | 381 | ||
372 | ri = F2FS_INODE(node_page); | 382 | ri = F2FS_INODE(node_page); |
373 | 383 | ||
@@ -417,6 +427,15 @@ int update_inode(struct inode *inode, struct page *node_page) | |||
417 | F2FS_I(inode)->i_projid); | 427 | F2FS_I(inode)->i_projid); |
418 | ri->i_projid = cpu_to_le32(i_projid); | 428 | ri->i_projid = cpu_to_le32(i_projid); |
419 | } | 429 | } |
430 | |||
431 | if (f2fs_sb_has_inode_crtime(F2FS_I_SB(inode)->sb) && | ||
432 | F2FS_FITS_IN_INODE(ri, F2FS_I(inode)->i_extra_isize, | ||
433 | i_crtime)) { | ||
434 | ri->i_crtime = | ||
435 | cpu_to_le64(F2FS_I(inode)->i_crtime.tv_sec); | ||
436 | ri->i_crtime_nsec = | ||
437 | cpu_to_le32(F2FS_I(inode)->i_crtime.tv_nsec); | ||
438 | } | ||
420 | } | 439 | } |
421 | 440 | ||
422 | __set_inode_rdev(inode, ri); | 441 | __set_inode_rdev(inode, ri); |
@@ -426,14 +445,12 @@ int update_inode(struct inode *inode, struct page *node_page) | |||
426 | if (inode->i_nlink == 0) | 445 | if (inode->i_nlink == 0) |
427 | clear_inline_node(node_page); | 446 | clear_inline_node(node_page); |
428 | 447 | ||
429 | return set_page_dirty(node_page); | ||
430 | } | 448 | } |
431 | 449 | ||
432 | int update_inode_page(struct inode *inode) | 450 | void update_inode_page(struct inode *inode) |
433 | { | 451 | { |
434 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | 452 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
435 | struct page *node_page; | 453 | struct page *node_page; |
436 | int ret = 0; | ||
437 | retry: | 454 | retry: |
438 | node_page = get_node_page(sbi, inode->i_ino); | 455 | node_page = get_node_page(sbi, inode->i_ino); |
439 | if (IS_ERR(node_page)) { | 456 | if (IS_ERR(node_page)) { |
@@ -444,11 +461,10 @@ retry: | |||
444 | } else if (err != -ENOENT) { | 461 | } else if (err != -ENOENT) { |
445 | f2fs_stop_checkpoint(sbi, false); | 462 | f2fs_stop_checkpoint(sbi, false); |
446 | } | 463 | } |
447 | return 0; | 464 | return; |
448 | } | 465 | } |
449 | ret = update_inode(inode, node_page); | 466 | update_inode(inode, node_page); |
450 | f2fs_put_page(node_page, 1); | 467 | f2fs_put_page(node_page, 1); |
451 | return ret; | ||
452 | } | 468 | } |
453 | 469 | ||
454 | int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc) | 470 | int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc) |
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index 28bdf8828e73..c4c94c7e9f4f 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c | |||
@@ -50,7 +50,8 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode) | |||
50 | 50 | ||
51 | inode->i_ino = ino; | 51 | inode->i_ino = ino; |
52 | inode->i_blocks = 0; | 52 | inode->i_blocks = 0; |
53 | inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); | 53 | inode->i_mtime = inode->i_atime = inode->i_ctime = |
54 | F2FS_I(inode)->i_crtime = current_time(inode); | ||
54 | inode->i_generation = sbi->s_next_generation++; | 55 | inode->i_generation = sbi->s_next_generation++; |
55 | 56 | ||
56 | err = insert_inode_locked(inode); | 57 | err = insert_inode_locked(inode); |
@@ -74,12 +75,12 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode) | |||
74 | if (err) | 75 | if (err) |
75 | goto fail_drop; | 76 | goto fail_drop; |
76 | 77 | ||
78 | set_inode_flag(inode, FI_NEW_INODE); | ||
79 | |||
77 | /* If the directory encrypted, then we should encrypt the inode. */ | 80 | /* If the directory encrypted, then we should encrypt the inode. */ |
78 | if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode)) | 81 | if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode)) |
79 | f2fs_set_encrypted_inode(inode); | 82 | f2fs_set_encrypted_inode(inode); |
80 | 83 | ||
81 | set_inode_flag(inode, FI_NEW_INODE); | ||
82 | |||
83 | if (f2fs_sb_has_extra_attr(sbi->sb)) { | 84 | if (f2fs_sb_has_extra_attr(sbi->sb)) { |
84 | set_inode_flag(inode, FI_EXTRA_ATTR); | 85 | set_inode_flag(inode, FI_EXTRA_ATTR); |
85 | F2FS_I(inode)->i_extra_isize = F2FS_TOTAL_EXTRA_ATTR_SIZE; | 86 | F2FS_I(inode)->i_extra_isize = F2FS_TOTAL_EXTRA_ATTR_SIZE; |
@@ -240,9 +241,9 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir, | |||
240 | if (unlikely(f2fs_cp_error(sbi))) | 241 | if (unlikely(f2fs_cp_error(sbi))) |
241 | return -EIO; | 242 | return -EIO; |
242 | 243 | ||
243 | if (f2fs_encrypted_inode(dir) && | 244 | err = fscrypt_prepare_link(old_dentry, dir, dentry); |
244 | !fscrypt_has_permitted_context(dir, inode)) | 245 | if (err) |
245 | return -EPERM; | 246 | return err; |
246 | 247 | ||
247 | if (is_inode_flag_set(dir, FI_PROJ_INHERIT) && | 248 | if (is_inode_flag_set(dir, FI_PROJ_INHERIT) && |
248 | (!projid_eq(F2FS_I(dir)->i_projid, | 249 | (!projid_eq(F2FS_I(dir)->i_projid, |
@@ -357,20 +358,9 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry, | |||
357 | 358 | ||
358 | trace_f2fs_lookup_start(dir, dentry, flags); | 359 | trace_f2fs_lookup_start(dir, dentry, flags); |
359 | 360 | ||
360 | if (f2fs_encrypted_inode(dir)) { | 361 | err = fscrypt_prepare_lookup(dir, dentry, flags); |
361 | err = fscrypt_get_encryption_info(dir); | 362 | if (err) |
362 | 363 | goto out; | |
363 | /* | ||
364 | * DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is | ||
365 | * created while the directory was encrypted and we | ||
366 | * don't have access to the key. | ||
367 | */ | ||
368 | if (fscrypt_has_encryption_key(dir)) | ||
369 | fscrypt_set_encrypted_dentry(dentry); | ||
370 | fscrypt_set_d_op(dentry); | ||
371 | if (err && err != -ENOKEY) | ||
372 | goto out; | ||
373 | } | ||
374 | 364 | ||
375 | if (dentry->d_name.len > F2FS_NAME_LEN) { | 365 | if (dentry->d_name.len > F2FS_NAME_LEN) { |
376 | err = -ENAMETOOLONG; | 366 | err = -ENAMETOOLONG; |
@@ -544,7 +534,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, | |||
544 | struct qstr istr = QSTR_INIT(symname, len); | 534 | struct qstr istr = QSTR_INIT(symname, len); |
545 | struct fscrypt_str ostr; | 535 | struct fscrypt_str ostr; |
546 | 536 | ||
547 | sd = kzalloc(disk_link.len, GFP_NOFS); | 537 | sd = f2fs_kzalloc(sbi, disk_link.len, GFP_NOFS); |
548 | if (!sd) { | 538 | if (!sd) { |
549 | err = -ENOMEM; | 539 | err = -ENOMEM; |
550 | goto err_out; | 540 | goto err_out; |
@@ -800,18 +790,6 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
800 | if (unlikely(f2fs_cp_error(sbi))) | 790 | if (unlikely(f2fs_cp_error(sbi))) |
801 | return -EIO; | 791 | return -EIO; |
802 | 792 | ||
803 | if ((f2fs_encrypted_inode(old_dir) && | ||
804 | !fscrypt_has_encryption_key(old_dir)) || | ||
805 | (f2fs_encrypted_inode(new_dir) && | ||
806 | !fscrypt_has_encryption_key(new_dir))) | ||
807 | return -ENOKEY; | ||
808 | |||
809 | if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) && | ||
810 | !fscrypt_has_permitted_context(new_dir, old_inode)) { | ||
811 | err = -EPERM; | ||
812 | goto out; | ||
813 | } | ||
814 | |||
815 | if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && | 793 | if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && |
816 | (!projid_eq(F2FS_I(new_dir)->i_projid, | 794 | (!projid_eq(F2FS_I(new_dir)->i_projid, |
817 | F2FS_I(old_dentry->d_inode)->i_projid))) | 795 | F2FS_I(old_dentry->d_inode)->i_projid))) |
@@ -958,6 +936,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
958 | } | 936 | } |
959 | f2fs_i_links_write(old_dir, false); | 937 | f2fs_i_links_write(old_dir, false); |
960 | } | 938 | } |
939 | add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO); | ||
961 | 940 | ||
962 | f2fs_unlock_op(sbi); | 941 | f2fs_unlock_op(sbi); |
963 | 942 | ||
@@ -1002,18 +981,6 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1002 | if (unlikely(f2fs_cp_error(sbi))) | 981 | if (unlikely(f2fs_cp_error(sbi))) |
1003 | return -EIO; | 982 | return -EIO; |
1004 | 983 | ||
1005 | if ((f2fs_encrypted_inode(old_dir) && | ||
1006 | !fscrypt_has_encryption_key(old_dir)) || | ||
1007 | (f2fs_encrypted_inode(new_dir) && | ||
1008 | !fscrypt_has_encryption_key(new_dir))) | ||
1009 | return -ENOKEY; | ||
1010 | |||
1011 | if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) && | ||
1012 | (old_dir != new_dir) && | ||
1013 | (!fscrypt_has_permitted_context(new_dir, old_inode) || | ||
1014 | !fscrypt_has_permitted_context(old_dir, new_inode))) | ||
1015 | return -EPERM; | ||
1016 | |||
1017 | if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && | 984 | if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && |
1018 | !projid_eq(F2FS_I(new_dir)->i_projid, | 985 | !projid_eq(F2FS_I(new_dir)->i_projid, |
1019 | F2FS_I(old_dentry->d_inode)->i_projid)) || | 986 | F2FS_I(old_dentry->d_inode)->i_projid)) || |
@@ -1124,6 +1091,9 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1124 | } | 1091 | } |
1125 | f2fs_mark_inode_dirty_sync(new_dir, false); | 1092 | f2fs_mark_inode_dirty_sync(new_dir, false); |
1126 | 1093 | ||
1094 | add_ino_entry(sbi, old_dir->i_ino, TRANS_DIR_INO); | ||
1095 | add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO); | ||
1096 | |||
1127 | f2fs_unlock_op(sbi); | 1097 | f2fs_unlock_op(sbi); |
1128 | 1098 | ||
1129 | if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir)) | 1099 | if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir)) |
@@ -1153,9 +1123,16 @@ static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry, | |||
1153 | struct inode *new_dir, struct dentry *new_dentry, | 1123 | struct inode *new_dir, struct dentry *new_dentry, |
1154 | unsigned int flags) | 1124 | unsigned int flags) |
1155 | { | 1125 | { |
1126 | int err; | ||
1127 | |||
1156 | if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT)) | 1128 | if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT)) |
1157 | return -EINVAL; | 1129 | return -EINVAL; |
1158 | 1130 | ||
1131 | err = fscrypt_prepare_rename(old_dir, old_dentry, new_dir, new_dentry, | ||
1132 | flags); | ||
1133 | if (err) | ||
1134 | return err; | ||
1135 | |||
1159 | if (flags & RENAME_EXCHANGE) { | 1136 | if (flags & RENAME_EXCHANGE) { |
1160 | return f2fs_cross_rename(old_dir, old_dentry, | 1137 | return f2fs_cross_rename(old_dir, old_dentry, |
1161 | new_dir, new_dentry); | 1138 | new_dir, new_dentry); |
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index d3322752426f..177c438e4a56 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c | |||
@@ -143,11 +143,9 @@ static struct nat_entry *__alloc_nat_entry(nid_t nid, bool no_fail) | |||
143 | struct nat_entry *new; | 143 | struct nat_entry *new; |
144 | 144 | ||
145 | if (no_fail) | 145 | if (no_fail) |
146 | new = f2fs_kmem_cache_alloc(nat_entry_slab, | 146 | new = f2fs_kmem_cache_alloc(nat_entry_slab, GFP_F2FS_ZERO); |
147 | GFP_NOFS | __GFP_ZERO); | ||
148 | else | 147 | else |
149 | new = kmem_cache_alloc(nat_entry_slab, | 148 | new = kmem_cache_alloc(nat_entry_slab, GFP_F2FS_ZERO); |
150 | GFP_NOFS | __GFP_ZERO); | ||
151 | if (new) { | 149 | if (new) { |
152 | nat_set_nid(new, nid); | 150 | nat_set_nid(new, nid); |
153 | nat_reset_flag(new); | 151 | nat_reset_flag(new); |
@@ -702,7 +700,6 @@ static void truncate_node(struct dnode_of_data *dn) | |||
702 | struct node_info ni; | 700 | struct node_info ni; |
703 | 701 | ||
704 | get_node_info(sbi, dn->nid, &ni); | 702 | get_node_info(sbi, dn->nid, &ni); |
705 | f2fs_bug_on(sbi, ni.blk_addr == NULL_ADDR); | ||
706 | 703 | ||
707 | /* Deallocate node address */ | 704 | /* Deallocate node address */ |
708 | invalidate_blocks(sbi, ni.blk_addr); | 705 | invalidate_blocks(sbi, ni.blk_addr); |
@@ -1336,14 +1333,19 @@ static int __write_node_page(struct page *page, bool atomic, bool *submitted, | |||
1336 | .encrypted_page = NULL, | 1333 | .encrypted_page = NULL, |
1337 | .submitted = false, | 1334 | .submitted = false, |
1338 | .io_type = io_type, | 1335 | .io_type = io_type, |
1336 | .io_wbc = wbc, | ||
1339 | }; | 1337 | }; |
1340 | 1338 | ||
1341 | trace_f2fs_writepage(page, NODE); | 1339 | trace_f2fs_writepage(page, NODE); |
1342 | 1340 | ||
1341 | if (unlikely(f2fs_cp_error(sbi))) { | ||
1342 | dec_page_count(sbi, F2FS_DIRTY_NODES); | ||
1343 | unlock_page(page); | ||
1344 | return 0; | ||
1345 | } | ||
1346 | |||
1343 | if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) | 1347 | if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) |
1344 | goto redirty_out; | 1348 | goto redirty_out; |
1345 | if (unlikely(f2fs_cp_error(sbi))) | ||
1346 | goto redirty_out; | ||
1347 | 1349 | ||
1348 | /* get old block addr of this node page */ | 1350 | /* get old block addr of this node page */ |
1349 | nid = nid_of_node(page); | 1351 | nid = nid_of_node(page); |
@@ -1580,12 +1582,6 @@ next_step: | |||
1580 | struct page *page = pvec.pages[i]; | 1582 | struct page *page = pvec.pages[i]; |
1581 | bool submitted = false; | 1583 | bool submitted = false; |
1582 | 1584 | ||
1583 | if (unlikely(f2fs_cp_error(sbi))) { | ||
1584 | pagevec_release(&pvec); | ||
1585 | ret = -EIO; | ||
1586 | goto out; | ||
1587 | } | ||
1588 | |||
1589 | /* | 1585 | /* |
1590 | * flushing sequence with step: | 1586 | * flushing sequence with step: |
1591 | * 0. indirect nodes | 1587 | * 0. indirect nodes |
@@ -1655,9 +1651,12 @@ continue_unlock: | |||
1655 | step++; | 1651 | step++; |
1656 | goto next_step; | 1652 | goto next_step; |
1657 | } | 1653 | } |
1658 | out: | 1654 | |
1659 | if (nwritten) | 1655 | if (nwritten) |
1660 | f2fs_submit_merged_write(sbi, NODE); | 1656 | f2fs_submit_merged_write(sbi, NODE); |
1657 | |||
1658 | if (unlikely(f2fs_cp_error(sbi))) | ||
1659 | return -EIO; | ||
1661 | return ret; | 1660 | return ret; |
1662 | } | 1661 | } |
1663 | 1662 | ||
@@ -1812,8 +1811,33 @@ static void __move_free_nid(struct f2fs_sb_info *sbi, struct free_nid *i, | |||
1812 | } | 1811 | } |
1813 | } | 1812 | } |
1814 | 1813 | ||
1814 | static void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid, | ||
1815 | bool set, bool build) | ||
1816 | { | ||
1817 | struct f2fs_nm_info *nm_i = NM_I(sbi); | ||
1818 | unsigned int nat_ofs = NAT_BLOCK_OFFSET(nid); | ||
1819 | unsigned int nid_ofs = nid - START_NID(nid); | ||
1820 | |||
1821 | if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap)) | ||
1822 | return; | ||
1823 | |||
1824 | if (set) { | ||
1825 | if (test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs])) | ||
1826 | return; | ||
1827 | __set_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]); | ||
1828 | nm_i->free_nid_count[nat_ofs]++; | ||
1829 | } else { | ||
1830 | if (!test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs])) | ||
1831 | return; | ||
1832 | __clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]); | ||
1833 | if (!build) | ||
1834 | nm_i->free_nid_count[nat_ofs]--; | ||
1835 | } | ||
1836 | } | ||
1837 | |||
1815 | /* return if the nid is recognized as free */ | 1838 | /* return if the nid is recognized as free */ |
1816 | static bool add_free_nid(struct f2fs_sb_info *sbi, nid_t nid, bool build) | 1839 | static bool add_free_nid(struct f2fs_sb_info *sbi, |
1840 | nid_t nid, bool build, bool update) | ||
1817 | { | 1841 | { |
1818 | struct f2fs_nm_info *nm_i = NM_I(sbi); | 1842 | struct f2fs_nm_info *nm_i = NM_I(sbi); |
1819 | struct free_nid *i, *e; | 1843 | struct free_nid *i, *e; |
@@ -1829,8 +1853,7 @@ static bool add_free_nid(struct f2fs_sb_info *sbi, nid_t nid, bool build) | |||
1829 | i->nid = nid; | 1853 | i->nid = nid; |
1830 | i->state = FREE_NID; | 1854 | i->state = FREE_NID; |
1831 | 1855 | ||
1832 | if (radix_tree_preload(GFP_NOFS)) | 1856 | radix_tree_preload(GFP_NOFS | __GFP_NOFAIL); |
1833 | goto err; | ||
1834 | 1857 | ||
1835 | spin_lock(&nm_i->nid_list_lock); | 1858 | spin_lock(&nm_i->nid_list_lock); |
1836 | 1859 | ||
@@ -1871,9 +1894,14 @@ static bool add_free_nid(struct f2fs_sb_info *sbi, nid_t nid, bool build) | |||
1871 | ret = true; | 1894 | ret = true; |
1872 | err = __insert_free_nid(sbi, i, FREE_NID); | 1895 | err = __insert_free_nid(sbi, i, FREE_NID); |
1873 | err_out: | 1896 | err_out: |
1897 | if (update) { | ||
1898 | update_free_nid_bitmap(sbi, nid, ret, build); | ||
1899 | if (!build) | ||
1900 | nm_i->available_nids++; | ||
1901 | } | ||
1874 | spin_unlock(&nm_i->nid_list_lock); | 1902 | spin_unlock(&nm_i->nid_list_lock); |
1875 | radix_tree_preload_end(); | 1903 | radix_tree_preload_end(); |
1876 | err: | 1904 | |
1877 | if (err) | 1905 | if (err) |
1878 | kmem_cache_free(free_nid_slab, i); | 1906 | kmem_cache_free(free_nid_slab, i); |
1879 | return ret; | 1907 | return ret; |
@@ -1897,30 +1925,6 @@ static void remove_free_nid(struct f2fs_sb_info *sbi, nid_t nid) | |||
1897 | kmem_cache_free(free_nid_slab, i); | 1925 | kmem_cache_free(free_nid_slab, i); |
1898 | } | 1926 | } |
1899 | 1927 | ||
1900 | static void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid, | ||
1901 | bool set, bool build) | ||
1902 | { | ||
1903 | struct f2fs_nm_info *nm_i = NM_I(sbi); | ||
1904 | unsigned int nat_ofs = NAT_BLOCK_OFFSET(nid); | ||
1905 | unsigned int nid_ofs = nid - START_NID(nid); | ||
1906 | |||
1907 | if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap)) | ||
1908 | return; | ||
1909 | |||
1910 | if (set) { | ||
1911 | if (test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs])) | ||
1912 | return; | ||
1913 | __set_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]); | ||
1914 | nm_i->free_nid_count[nat_ofs]++; | ||
1915 | } else { | ||
1916 | if (!test_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs])) | ||
1917 | return; | ||
1918 | __clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]); | ||
1919 | if (!build) | ||
1920 | nm_i->free_nid_count[nat_ofs]--; | ||
1921 | } | ||
1922 | } | ||
1923 | |||
1924 | static void scan_nat_page(struct f2fs_sb_info *sbi, | 1928 | static void scan_nat_page(struct f2fs_sb_info *sbi, |
1925 | struct page *nat_page, nid_t start_nid) | 1929 | struct page *nat_page, nid_t start_nid) |
1926 | { | 1930 | { |
@@ -1930,26 +1934,23 @@ static void scan_nat_page(struct f2fs_sb_info *sbi, | |||
1930 | unsigned int nat_ofs = NAT_BLOCK_OFFSET(start_nid); | 1934 | unsigned int nat_ofs = NAT_BLOCK_OFFSET(start_nid); |
1931 | int i; | 1935 | int i; |
1932 | 1936 | ||
1933 | if (test_bit_le(nat_ofs, nm_i->nat_block_bitmap)) | ||
1934 | return; | ||
1935 | |||
1936 | __set_bit_le(nat_ofs, nm_i->nat_block_bitmap); | 1937 | __set_bit_le(nat_ofs, nm_i->nat_block_bitmap); |
1937 | 1938 | ||
1938 | i = start_nid % NAT_ENTRY_PER_BLOCK; | 1939 | i = start_nid % NAT_ENTRY_PER_BLOCK; |
1939 | 1940 | ||
1940 | for (; i < NAT_ENTRY_PER_BLOCK; i++, start_nid++) { | 1941 | for (; i < NAT_ENTRY_PER_BLOCK; i++, start_nid++) { |
1941 | bool freed = false; | ||
1942 | |||
1943 | if (unlikely(start_nid >= nm_i->max_nid)) | 1942 | if (unlikely(start_nid >= nm_i->max_nid)) |
1944 | break; | 1943 | break; |
1945 | 1944 | ||
1946 | blk_addr = le32_to_cpu(nat_blk->entries[i].block_addr); | 1945 | blk_addr = le32_to_cpu(nat_blk->entries[i].block_addr); |
1947 | f2fs_bug_on(sbi, blk_addr == NEW_ADDR); | 1946 | f2fs_bug_on(sbi, blk_addr == NEW_ADDR); |
1948 | if (blk_addr == NULL_ADDR) | 1947 | if (blk_addr == NULL_ADDR) { |
1949 | freed = add_free_nid(sbi, start_nid, true); | 1948 | add_free_nid(sbi, start_nid, true, true); |
1950 | spin_lock(&NM_I(sbi)->nid_list_lock); | 1949 | } else { |
1951 | update_free_nid_bitmap(sbi, start_nid, freed, true); | 1950 | spin_lock(&NM_I(sbi)->nid_list_lock); |
1952 | spin_unlock(&NM_I(sbi)->nid_list_lock); | 1951 | update_free_nid_bitmap(sbi, start_nid, false, true); |
1952 | spin_unlock(&NM_I(sbi)->nid_list_lock); | ||
1953 | } | ||
1953 | } | 1954 | } |
1954 | } | 1955 | } |
1955 | 1956 | ||
@@ -1967,7 +1968,7 @@ static void scan_curseg_cache(struct f2fs_sb_info *sbi) | |||
1967 | addr = le32_to_cpu(nat_in_journal(journal, i).block_addr); | 1968 | addr = le32_to_cpu(nat_in_journal(journal, i).block_addr); |
1968 | nid = le32_to_cpu(nid_in_journal(journal, i)); | 1969 | nid = le32_to_cpu(nid_in_journal(journal, i)); |
1969 | if (addr == NULL_ADDR) | 1970 | if (addr == NULL_ADDR) |
1970 | add_free_nid(sbi, nid, true); | 1971 | add_free_nid(sbi, nid, true, false); |
1971 | else | 1972 | else |
1972 | remove_free_nid(sbi, nid); | 1973 | remove_free_nid(sbi, nid); |
1973 | } | 1974 | } |
@@ -1994,7 +1995,7 @@ static void scan_free_nid_bits(struct f2fs_sb_info *sbi) | |||
1994 | break; | 1995 | break; |
1995 | 1996 | ||
1996 | nid = i * NAT_ENTRY_PER_BLOCK + idx; | 1997 | nid = i * NAT_ENTRY_PER_BLOCK + idx; |
1997 | add_free_nid(sbi, nid, true); | 1998 | add_free_nid(sbi, nid, true, false); |
1998 | 1999 | ||
1999 | if (nm_i->nid_cnt[FREE_NID] >= MAX_FREE_NIDS) | 2000 | if (nm_i->nid_cnt[FREE_NID] >= MAX_FREE_NIDS) |
2000 | goto out; | 2001 | goto out; |
@@ -2037,10 +2038,13 @@ static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) | |||
2037 | down_read(&nm_i->nat_tree_lock); | 2038 | down_read(&nm_i->nat_tree_lock); |
2038 | 2039 | ||
2039 | while (1) { | 2040 | while (1) { |
2040 | struct page *page = get_current_nat_page(sbi, nid); | 2041 | if (!test_bit_le(NAT_BLOCK_OFFSET(nid), |
2042 | nm_i->nat_block_bitmap)) { | ||
2043 | struct page *page = get_current_nat_page(sbi, nid); | ||
2041 | 2044 | ||
2042 | scan_nat_page(sbi, page, nid); | 2045 | scan_nat_page(sbi, page, nid); |
2043 | f2fs_put_page(page, 1); | 2046 | f2fs_put_page(page, 1); |
2047 | } | ||
2044 | 2048 | ||
2045 | nid += (NAT_ENTRY_PER_BLOCK - (nid % NAT_ENTRY_PER_BLOCK)); | 2049 | nid += (NAT_ENTRY_PER_BLOCK - (nid % NAT_ENTRY_PER_BLOCK)); |
2046 | if (unlikely(nid >= nm_i->max_nid)) | 2050 | if (unlikely(nid >= nm_i->max_nid)) |
@@ -2203,7 +2207,9 @@ void recover_inline_xattr(struct inode *inode, struct page *page) | |||
2203 | f2fs_bug_on(F2FS_I_SB(inode), IS_ERR(ipage)); | 2207 | f2fs_bug_on(F2FS_I_SB(inode), IS_ERR(ipage)); |
2204 | 2208 | ||
2205 | ri = F2FS_INODE(page); | 2209 | ri = F2FS_INODE(page); |
2206 | if (!(ri->i_inline & F2FS_INLINE_XATTR)) { | 2210 | if (ri->i_inline & F2FS_INLINE_XATTR) { |
2211 | set_inode_flag(inode, FI_INLINE_XATTR); | ||
2212 | } else { | ||
2207 | clear_inode_flag(inode, FI_INLINE_XATTR); | 2213 | clear_inode_flag(inode, FI_INLINE_XATTR); |
2208 | goto update_inode; | 2214 | goto update_inode; |
2209 | } | 2215 | } |
@@ -2219,7 +2225,7 @@ update_inode: | |||
2219 | f2fs_put_page(ipage, 1); | 2225 | f2fs_put_page(ipage, 1); |
2220 | } | 2226 | } |
2221 | 2227 | ||
2222 | int recover_xattr_data(struct inode *inode, struct page *page, block_t blkaddr) | 2228 | int recover_xattr_data(struct inode *inode, struct page *page) |
2223 | { | 2229 | { |
2224 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | 2230 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
2225 | nid_t prev_xnid = F2FS_I(inode)->i_xattr_nid; | 2231 | nid_t prev_xnid = F2FS_I(inode)->i_xattr_nid; |
@@ -2233,7 +2239,6 @@ int recover_xattr_data(struct inode *inode, struct page *page, block_t blkaddr) | |||
2233 | 2239 | ||
2234 | /* 1: invalidate the previous xattr nid */ | 2240 | /* 1: invalidate the previous xattr nid */ |
2235 | get_node_info(sbi, prev_xnid, &ni); | 2241 | get_node_info(sbi, prev_xnid, &ni); |
2236 | f2fs_bug_on(sbi, ni.blk_addr == NULL_ADDR); | ||
2237 | invalidate_blocks(sbi, ni.blk_addr); | 2242 | invalidate_blocks(sbi, ni.blk_addr); |
2238 | dec_valid_node_count(sbi, inode, false); | 2243 | dec_valid_node_count(sbi, inode, false); |
2239 | set_node_addr(sbi, &ni, NULL_ADDR, false); | 2244 | set_node_addr(sbi, &ni, NULL_ADDR, false); |
@@ -2322,7 +2327,7 @@ retry: | |||
2322 | return 0; | 2327 | return 0; |
2323 | } | 2328 | } |
2324 | 2329 | ||
2325 | int restore_node_summary(struct f2fs_sb_info *sbi, | 2330 | void restore_node_summary(struct f2fs_sb_info *sbi, |
2326 | unsigned int segno, struct f2fs_summary_block *sum) | 2331 | unsigned int segno, struct f2fs_summary_block *sum) |
2327 | { | 2332 | { |
2328 | struct f2fs_node *rn; | 2333 | struct f2fs_node *rn; |
@@ -2355,7 +2360,6 @@ int restore_node_summary(struct f2fs_sb_info *sbi, | |||
2355 | invalidate_mapping_pages(META_MAPPING(sbi), addr, | 2360 | invalidate_mapping_pages(META_MAPPING(sbi), addr, |
2356 | addr + nrpages); | 2361 | addr + nrpages); |
2357 | } | 2362 | } |
2358 | return 0; | ||
2359 | } | 2363 | } |
2360 | 2364 | ||
2361 | static void remove_nats_in_journal(struct f2fs_sb_info *sbi) | 2365 | static void remove_nats_in_journal(struct f2fs_sb_info *sbi) |
@@ -2497,11 +2501,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, | |||
2497 | nat_reset_flag(ne); | 2501 | nat_reset_flag(ne); |
2498 | __clear_nat_cache_dirty(NM_I(sbi), set, ne); | 2502 | __clear_nat_cache_dirty(NM_I(sbi), set, ne); |
2499 | if (nat_get_blkaddr(ne) == NULL_ADDR) { | 2503 | if (nat_get_blkaddr(ne) == NULL_ADDR) { |
2500 | add_free_nid(sbi, nid, false); | 2504 | add_free_nid(sbi, nid, false, true); |
2501 | spin_lock(&NM_I(sbi)->nid_list_lock); | ||
2502 | NM_I(sbi)->available_nids++; | ||
2503 | update_free_nid_bitmap(sbi, nid, true, false); | ||
2504 | spin_unlock(&NM_I(sbi)->nid_list_lock); | ||
2505 | } else { | 2505 | } else { |
2506 | spin_lock(&NM_I(sbi)->nid_list_lock); | 2506 | spin_lock(&NM_I(sbi)->nid_list_lock); |
2507 | update_free_nid_bitmap(sbi, nid, false, false); | 2507 | update_free_nid_bitmap(sbi, nid, false, false); |
@@ -2582,8 +2582,8 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) | |||
2582 | 2582 | ||
2583 | nm_i->nat_bits_blocks = F2FS_BYTES_TO_BLK((nat_bits_bytes << 1) + 8 + | 2583 | nm_i->nat_bits_blocks = F2FS_BYTES_TO_BLK((nat_bits_bytes << 1) + 8 + |
2584 | F2FS_BLKSIZE - 1); | 2584 | F2FS_BLKSIZE - 1); |
2585 | nm_i->nat_bits = kzalloc(nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS, | 2585 | nm_i->nat_bits = f2fs_kzalloc(sbi, |
2586 | GFP_KERNEL); | 2586 | nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS, GFP_KERNEL); |
2587 | if (!nm_i->nat_bits) | 2587 | if (!nm_i->nat_bits) |
2588 | return -ENOMEM; | 2588 | return -ENOMEM; |
2589 | 2589 | ||
@@ -2661,7 +2661,7 @@ static int init_node_manager(struct f2fs_sb_info *sbi) | |||
2661 | 2661 | ||
2662 | /* not used nids: 0, node, meta, (and root counted as valid node) */ | 2662 | /* not used nids: 0, node, meta, (and root counted as valid node) */ |
2663 | nm_i->available_nids = nm_i->max_nid - sbi->total_valid_node_count - | 2663 | nm_i->available_nids = nm_i->max_nid - sbi->total_valid_node_count - |
2664 | F2FS_RESERVED_NODE_NUM; | 2664 | sbi->nquota_files - F2FS_RESERVED_NODE_NUM; |
2665 | nm_i->nid_cnt[FREE_NID] = 0; | 2665 | nm_i->nid_cnt[FREE_NID] = 0; |
2666 | nm_i->nid_cnt[PREALLOC_NID] = 0; | 2666 | nm_i->nid_cnt[PREALLOC_NID] = 0; |
2667 | nm_i->nat_cnt = 0; | 2667 | nm_i->nat_cnt = 0; |
@@ -2708,17 +2708,17 @@ static int init_free_nid_cache(struct f2fs_sb_info *sbi) | |||
2708 | { | 2708 | { |
2709 | struct f2fs_nm_info *nm_i = NM_I(sbi); | 2709 | struct f2fs_nm_info *nm_i = NM_I(sbi); |
2710 | 2710 | ||
2711 | nm_i->free_nid_bitmap = kvzalloc(nm_i->nat_blocks * | 2711 | nm_i->free_nid_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks * |
2712 | NAT_ENTRY_BITMAP_SIZE, GFP_KERNEL); | 2712 | NAT_ENTRY_BITMAP_SIZE, GFP_KERNEL); |
2713 | if (!nm_i->free_nid_bitmap) | 2713 | if (!nm_i->free_nid_bitmap) |
2714 | return -ENOMEM; | 2714 | return -ENOMEM; |
2715 | 2715 | ||
2716 | nm_i->nat_block_bitmap = kvzalloc(nm_i->nat_blocks / 8, | 2716 | nm_i->nat_block_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks / 8, |
2717 | GFP_KERNEL); | 2717 | GFP_KERNEL); |
2718 | if (!nm_i->nat_block_bitmap) | 2718 | if (!nm_i->nat_block_bitmap) |
2719 | return -ENOMEM; | 2719 | return -ENOMEM; |
2720 | 2720 | ||
2721 | nm_i->free_nid_count = kvzalloc(nm_i->nat_blocks * | 2721 | nm_i->free_nid_count = f2fs_kvzalloc(sbi, nm_i->nat_blocks * |
2722 | sizeof(unsigned short), GFP_KERNEL); | 2722 | sizeof(unsigned short), GFP_KERNEL); |
2723 | if (!nm_i->free_nid_count) | 2723 | if (!nm_i->free_nid_count) |
2724 | return -ENOMEM; | 2724 | return -ENOMEM; |
@@ -2729,7 +2729,8 @@ int build_node_manager(struct f2fs_sb_info *sbi) | |||
2729 | { | 2729 | { |
2730 | int err; | 2730 | int err; |
2731 | 2731 | ||
2732 | sbi->nm_info = kzalloc(sizeof(struct f2fs_nm_info), GFP_KERNEL); | 2732 | sbi->nm_info = f2fs_kzalloc(sbi, sizeof(struct f2fs_nm_info), |
2733 | GFP_KERNEL); | ||
2733 | if (!sbi->nm_info) | 2734 | if (!sbi->nm_info) |
2734 | return -ENOMEM; | 2735 | return -ENOMEM; |
2735 | 2736 | ||
diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index 0ee3e5ff49a3..081ef0d672bf 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h | |||
@@ -305,6 +305,10 @@ static inline bool is_recoverable_dnode(struct page *page) | |||
305 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(F2FS_P_SB(page)); | 305 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(F2FS_P_SB(page)); |
306 | __u64 cp_ver = cur_cp_version(ckpt); | 306 | __u64 cp_ver = cur_cp_version(ckpt); |
307 | 307 | ||
308 | /* Don't care crc part, if fsck.f2fs sets it. */ | ||
309 | if (__is_set_ckpt_flags(ckpt, CP_NOCRC_RECOVERY_FLAG)) | ||
310 | return (cp_ver << 32) == (cpver_of_node(page) << 32); | ||
311 | |||
308 | if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) | 312 | if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) |
309 | cp_ver |= (cur_cp_crc(ckpt) << 32); | 313 | cp_ver |= (cur_cp_crc(ckpt) << 32); |
310 | 314 | ||
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index b3a14b0429f2..337f3363f48f 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c | |||
@@ -195,6 +195,20 @@ out: | |||
195 | return err; | 195 | return err; |
196 | } | 196 | } |
197 | 197 | ||
198 | static void recover_inline_flags(struct inode *inode, struct f2fs_inode *ri) | ||
199 | { | ||
200 | if (ri->i_inline & F2FS_PIN_FILE) | ||
201 | set_inode_flag(inode, FI_PIN_FILE); | ||
202 | else | ||
203 | clear_inode_flag(inode, FI_PIN_FILE); | ||
204 | if (ri->i_inline & F2FS_DATA_EXIST) | ||
205 | set_inode_flag(inode, FI_DATA_EXIST); | ||
206 | else | ||
207 | clear_inode_flag(inode, FI_DATA_EXIST); | ||
208 | if (!(ri->i_inline & F2FS_INLINE_DOTS)) | ||
209 | clear_inode_flag(inode, FI_INLINE_DOTS); | ||
210 | } | ||
211 | |||
198 | static void recover_inode(struct inode *inode, struct page *page) | 212 | static void recover_inode(struct inode *inode, struct page *page) |
199 | { | 213 | { |
200 | struct f2fs_inode *raw = F2FS_INODE(page); | 214 | struct f2fs_inode *raw = F2FS_INODE(page); |
@@ -211,13 +225,16 @@ static void recover_inode(struct inode *inode, struct page *page) | |||
211 | 225 | ||
212 | F2FS_I(inode)->i_advise = raw->i_advise; | 226 | F2FS_I(inode)->i_advise = raw->i_advise; |
213 | 227 | ||
228 | recover_inline_flags(inode, raw); | ||
229 | |||
214 | if (file_enc_name(inode)) | 230 | if (file_enc_name(inode)) |
215 | name = "<encrypted>"; | 231 | name = "<encrypted>"; |
216 | else | 232 | else |
217 | name = F2FS_INODE(page)->i_name; | 233 | name = F2FS_INODE(page)->i_name; |
218 | 234 | ||
219 | f2fs_msg(inode->i_sb, KERN_NOTICE, "recover_inode: ino = %x, name = %s", | 235 | f2fs_msg(inode->i_sb, KERN_NOTICE, |
220 | ino_of_node(page), name); | 236 | "recover_inode: ino = %x, name = %s, inline = %x", |
237 | ino_of_node(page), name, raw->i_inline); | ||
221 | } | 238 | } |
222 | 239 | ||
223 | static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head, | 240 | static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head, |
@@ -404,7 +421,7 @@ truncate_out: | |||
404 | } | 421 | } |
405 | 422 | ||
406 | static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, | 423 | static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, |
407 | struct page *page, block_t blkaddr) | 424 | struct page *page) |
408 | { | 425 | { |
409 | struct dnode_of_data dn; | 426 | struct dnode_of_data dn; |
410 | struct node_info ni; | 427 | struct node_info ni; |
@@ -415,7 +432,7 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, | |||
415 | if (IS_INODE(page)) { | 432 | if (IS_INODE(page)) { |
416 | recover_inline_xattr(inode, page); | 433 | recover_inline_xattr(inode, page); |
417 | } else if (f2fs_has_xattr_block(ofs_of_node(page))) { | 434 | } else if (f2fs_has_xattr_block(ofs_of_node(page))) { |
418 | err = recover_xattr_data(inode, page, blkaddr); | 435 | err = recover_xattr_data(inode, page); |
419 | if (!err) | 436 | if (!err) |
420 | recovered++; | 437 | recovered++; |
421 | goto out; | 438 | goto out; |
@@ -568,7 +585,7 @@ static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list, | |||
568 | break; | 585 | break; |
569 | } | 586 | } |
570 | } | 587 | } |
571 | err = do_recover_data(sbi, entry->inode, page, blkaddr); | 588 | err = do_recover_data(sbi, entry->inode, page); |
572 | if (err) { | 589 | if (err) { |
573 | f2fs_put_page(page, 1); | 590 | f2fs_put_page(page, 1); |
574 | break; | 591 | break; |
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index c117e0913f2a..b16a8e6625aa 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c | |||
@@ -248,7 +248,11 @@ retry: | |||
248 | goto next; | 248 | goto next; |
249 | } | 249 | } |
250 | get_node_info(sbi, dn.nid, &ni); | 250 | get_node_info(sbi, dn.nid, &ni); |
251 | f2fs_replace_block(sbi, &dn, dn.data_blkaddr, | 251 | if (cur->old_addr == NEW_ADDR) { |
252 | invalidate_blocks(sbi, dn.data_blkaddr); | ||
253 | f2fs_update_data_blkaddr(&dn, NEW_ADDR); | ||
254 | } else | ||
255 | f2fs_replace_block(sbi, &dn, dn.data_blkaddr, | ||
252 | cur->old_addr, ni.version, true, true); | 256 | cur->old_addr, ni.version, true, true); |
253 | f2fs_put_dnode(&dn); | 257 | f2fs_put_dnode(&dn); |
254 | } | 258 | } |
@@ -657,7 +661,7 @@ int create_flush_cmd_control(struct f2fs_sb_info *sbi) | |||
657 | goto init_thread; | 661 | goto init_thread; |
658 | } | 662 | } |
659 | 663 | ||
660 | fcc = kzalloc(sizeof(struct flush_cmd_control), GFP_KERNEL); | 664 | fcc = f2fs_kzalloc(sbi, sizeof(struct flush_cmd_control), GFP_KERNEL); |
661 | if (!fcc) | 665 | if (!fcc) |
662 | return -ENOMEM; | 666 | return -ENOMEM; |
663 | atomic_set(&fcc->issued_flush, 0); | 667 | atomic_set(&fcc->issued_flush, 0); |
@@ -884,7 +888,7 @@ static void f2fs_submit_discard_endio(struct bio *bio) | |||
884 | bio_put(bio); | 888 | bio_put(bio); |
885 | } | 889 | } |
886 | 890 | ||
887 | void __check_sit_bitmap(struct f2fs_sb_info *sbi, | 891 | static void __check_sit_bitmap(struct f2fs_sb_info *sbi, |
888 | block_t start, block_t end) | 892 | block_t start, block_t end) |
889 | { | 893 | { |
890 | #ifdef CONFIG_F2FS_CHECK_FS | 894 | #ifdef CONFIG_F2FS_CHECK_FS |
@@ -1204,6 +1208,8 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi, | |||
1204 | pend_list = &dcc->pend_list[i]; | 1208 | pend_list = &dcc->pend_list[i]; |
1205 | 1209 | ||
1206 | mutex_lock(&dcc->cmd_lock); | 1210 | mutex_lock(&dcc->cmd_lock); |
1211 | if (list_empty(pend_list)) | ||
1212 | goto next; | ||
1207 | f2fs_bug_on(sbi, !__check_rb_tree_consistence(sbi, &dcc->root)); | 1213 | f2fs_bug_on(sbi, !__check_rb_tree_consistence(sbi, &dcc->root)); |
1208 | blk_start_plug(&plug); | 1214 | blk_start_plug(&plug); |
1209 | list_for_each_entry_safe(dc, tmp, pend_list, list) { | 1215 | list_for_each_entry_safe(dc, tmp, pend_list, list) { |
@@ -1222,6 +1228,7 @@ skip: | |||
1222 | break; | 1228 | break; |
1223 | } | 1229 | } |
1224 | blk_finish_plug(&plug); | 1230 | blk_finish_plug(&plug); |
1231 | next: | ||
1225 | mutex_unlock(&dcc->cmd_lock); | 1232 | mutex_unlock(&dcc->cmd_lock); |
1226 | 1233 | ||
1227 | if (iter >= dpolicy->max_requests) | 1234 | if (iter >= dpolicy->max_requests) |
@@ -1256,6 +1263,11 @@ static bool __drop_discard_cmd(struct f2fs_sb_info *sbi) | |||
1256 | return dropped; | 1263 | return dropped; |
1257 | } | 1264 | } |
1258 | 1265 | ||
1266 | void drop_discard_cmd(struct f2fs_sb_info *sbi) | ||
1267 | { | ||
1268 | __drop_discard_cmd(sbi); | ||
1269 | } | ||
1270 | |||
1259 | static unsigned int __wait_one_discard_bio(struct f2fs_sb_info *sbi, | 1271 | static unsigned int __wait_one_discard_bio(struct f2fs_sb_info *sbi, |
1260 | struct discard_cmd *dc) | 1272 | struct discard_cmd *dc) |
1261 | { | 1273 | { |
@@ -1324,7 +1336,7 @@ static void __wait_all_discard_cmd(struct f2fs_sb_info *sbi, | |||
1324 | } | 1336 | } |
1325 | 1337 | ||
1326 | /* This should be covered by global mutex, &sit_i->sentry_lock */ | 1338 | /* This should be covered by global mutex, &sit_i->sentry_lock */ |
1327 | void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr) | 1339 | static void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr) |
1328 | { | 1340 | { |
1329 | struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; | 1341 | struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; |
1330 | struct discard_cmd *dc; | 1342 | struct discard_cmd *dc; |
@@ -1394,6 +1406,8 @@ static int issue_discard_thread(void *data) | |||
1394 | msecs_to_jiffies(wait_ms)); | 1406 | msecs_to_jiffies(wait_ms)); |
1395 | if (try_to_freeze()) | 1407 | if (try_to_freeze()) |
1396 | continue; | 1408 | continue; |
1409 | if (f2fs_readonly(sbi->sb)) | ||
1410 | continue; | ||
1397 | if (kthread_should_stop()) | 1411 | if (kthread_should_stop()) |
1398 | return 0; | 1412 | return 0; |
1399 | 1413 | ||
@@ -1703,25 +1717,20 @@ void init_discard_policy(struct discard_policy *dpolicy, | |||
1703 | dpolicy->sync = true; | 1717 | dpolicy->sync = true; |
1704 | dpolicy->granularity = granularity; | 1718 | dpolicy->granularity = granularity; |
1705 | 1719 | ||
1720 | dpolicy->max_requests = DEF_MAX_DISCARD_REQUEST; | ||
1721 | dpolicy->io_aware_gran = MAX_PLIST_NUM; | ||
1722 | |||
1706 | if (discard_type == DPOLICY_BG) { | 1723 | if (discard_type == DPOLICY_BG) { |
1707 | dpolicy->min_interval = DEF_MIN_DISCARD_ISSUE_TIME; | 1724 | dpolicy->min_interval = DEF_MIN_DISCARD_ISSUE_TIME; |
1708 | dpolicy->max_interval = DEF_MAX_DISCARD_ISSUE_TIME; | 1725 | dpolicy->max_interval = DEF_MAX_DISCARD_ISSUE_TIME; |
1709 | dpolicy->max_requests = DEF_MAX_DISCARD_REQUEST; | ||
1710 | dpolicy->io_aware_gran = MAX_PLIST_NUM; | ||
1711 | dpolicy->io_aware = true; | 1726 | dpolicy->io_aware = true; |
1712 | } else if (discard_type == DPOLICY_FORCE) { | 1727 | } else if (discard_type == DPOLICY_FORCE) { |
1713 | dpolicy->min_interval = DEF_MIN_DISCARD_ISSUE_TIME; | 1728 | dpolicy->min_interval = DEF_MIN_DISCARD_ISSUE_TIME; |
1714 | dpolicy->max_interval = DEF_MAX_DISCARD_ISSUE_TIME; | 1729 | dpolicy->max_interval = DEF_MAX_DISCARD_ISSUE_TIME; |
1715 | dpolicy->max_requests = DEF_MAX_DISCARD_REQUEST; | ||
1716 | dpolicy->io_aware_gran = MAX_PLIST_NUM; | ||
1717 | dpolicy->io_aware = true; | 1730 | dpolicy->io_aware = true; |
1718 | } else if (discard_type == DPOLICY_FSTRIM) { | 1731 | } else if (discard_type == DPOLICY_FSTRIM) { |
1719 | dpolicy->max_requests = DEF_MAX_DISCARD_REQUEST; | ||
1720 | dpolicy->io_aware_gran = MAX_PLIST_NUM; | ||
1721 | dpolicy->io_aware = false; | 1732 | dpolicy->io_aware = false; |
1722 | } else if (discard_type == DPOLICY_UMOUNT) { | 1733 | } else if (discard_type == DPOLICY_UMOUNT) { |
1723 | dpolicy->max_requests = DEF_MAX_DISCARD_REQUEST; | ||
1724 | dpolicy->io_aware_gran = MAX_PLIST_NUM; | ||
1725 | dpolicy->io_aware = false; | 1734 | dpolicy->io_aware = false; |
1726 | } | 1735 | } |
1727 | } | 1736 | } |
@@ -1737,7 +1746,7 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi) | |||
1737 | goto init_thread; | 1746 | goto init_thread; |
1738 | } | 1747 | } |
1739 | 1748 | ||
1740 | dcc = kzalloc(sizeof(struct discard_cmd_control), GFP_KERNEL); | 1749 | dcc = f2fs_kzalloc(sbi, sizeof(struct discard_cmd_control), GFP_KERNEL); |
1741 | if (!dcc) | 1750 | if (!dcc) |
1742 | return -ENOMEM; | 1751 | return -ENOMEM; |
1743 | 1752 | ||
@@ -2739,6 +2748,7 @@ void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, | |||
2739 | } | 2748 | } |
2740 | } | 2749 | } |
2741 | 2750 | ||
2751 | f2fs_bug_on(sbi, !IS_DATASEG(type)); | ||
2742 | curseg = CURSEG_I(sbi, type); | 2752 | curseg = CURSEG_I(sbi, type); |
2743 | 2753 | ||
2744 | mutex_lock(&curseg->curseg_mutex); | 2754 | mutex_lock(&curseg->curseg_mutex); |
@@ -2823,7 +2833,7 @@ void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr) | |||
2823 | } | 2833 | } |
2824 | } | 2834 | } |
2825 | 2835 | ||
2826 | static int read_compacted_summaries(struct f2fs_sb_info *sbi) | 2836 | static void read_compacted_summaries(struct f2fs_sb_info *sbi) |
2827 | { | 2837 | { |
2828 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); | 2838 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); |
2829 | struct curseg_info *seg_i; | 2839 | struct curseg_info *seg_i; |
@@ -2880,7 +2890,6 @@ static int read_compacted_summaries(struct f2fs_sb_info *sbi) | |||
2880 | } | 2890 | } |
2881 | } | 2891 | } |
2882 | f2fs_put_page(page, 1); | 2892 | f2fs_put_page(page, 1); |
2883 | return 0; | ||
2884 | } | 2893 | } |
2885 | 2894 | ||
2886 | static int read_normal_summaries(struct f2fs_sb_info *sbi, int type) | 2895 | static int read_normal_summaries(struct f2fs_sb_info *sbi, int type) |
@@ -2926,13 +2935,7 @@ static int read_normal_summaries(struct f2fs_sb_info *sbi, int type) | |||
2926 | ns->ofs_in_node = 0; | 2935 | ns->ofs_in_node = 0; |
2927 | } | 2936 | } |
2928 | } else { | 2937 | } else { |
2929 | int err; | 2938 | restore_node_summary(sbi, segno, sum); |
2930 | |||
2931 | err = restore_node_summary(sbi, segno, sum); | ||
2932 | if (err) { | ||
2933 | f2fs_put_page(new, 1); | ||
2934 | return err; | ||
2935 | } | ||
2936 | } | 2939 | } |
2937 | } | 2940 | } |
2938 | 2941 | ||
@@ -2971,8 +2974,7 @@ static int restore_curseg_summaries(struct f2fs_sb_info *sbi) | |||
2971 | META_CP, true); | 2974 | META_CP, true); |
2972 | 2975 | ||
2973 | /* restore for compacted data summary */ | 2976 | /* restore for compacted data summary */ |
2974 | if (read_compacted_summaries(sbi)) | 2977 | read_compacted_summaries(sbi); |
2975 | return -EINVAL; | ||
2976 | type = CURSEG_HOT_NODE; | 2978 | type = CURSEG_HOT_NODE; |
2977 | } | 2979 | } |
2978 | 2980 | ||
@@ -3108,28 +3110,19 @@ static struct page *get_next_sit_page(struct f2fs_sb_info *sbi, | |||
3108 | unsigned int start) | 3110 | unsigned int start) |
3109 | { | 3111 | { |
3110 | struct sit_info *sit_i = SIT_I(sbi); | 3112 | struct sit_info *sit_i = SIT_I(sbi); |
3111 | struct page *src_page, *dst_page; | 3113 | struct page *page; |
3112 | pgoff_t src_off, dst_off; | 3114 | pgoff_t src_off, dst_off; |
3113 | void *src_addr, *dst_addr; | ||
3114 | 3115 | ||
3115 | src_off = current_sit_addr(sbi, start); | 3116 | src_off = current_sit_addr(sbi, start); |
3116 | dst_off = next_sit_addr(sbi, src_off); | 3117 | dst_off = next_sit_addr(sbi, src_off); |
3117 | 3118 | ||
3118 | /* get current sit block page without lock */ | 3119 | page = grab_meta_page(sbi, dst_off); |
3119 | src_page = get_meta_page(sbi, src_off); | 3120 | seg_info_to_sit_page(sbi, page, start); |
3120 | dst_page = grab_meta_page(sbi, dst_off); | ||
3121 | f2fs_bug_on(sbi, PageDirty(src_page)); | ||
3122 | |||
3123 | src_addr = page_address(src_page); | ||
3124 | dst_addr = page_address(dst_page); | ||
3125 | memcpy(dst_addr, src_addr, PAGE_SIZE); | ||
3126 | |||
3127 | set_page_dirty(dst_page); | ||
3128 | f2fs_put_page(src_page, 1); | ||
3129 | 3121 | ||
3122 | set_page_dirty(page); | ||
3130 | set_to_next_sit(sit_i, start); | 3123 | set_to_next_sit(sit_i, start); |
3131 | 3124 | ||
3132 | return dst_page; | 3125 | return page; |
3133 | } | 3126 | } |
3134 | 3127 | ||
3135 | static struct sit_entry_set *grab_sit_entry_set(void) | 3128 | static struct sit_entry_set *grab_sit_entry_set(void) |
@@ -3338,52 +3331,54 @@ static int build_sit_info(struct f2fs_sb_info *sbi) | |||
3338 | unsigned int bitmap_size; | 3331 | unsigned int bitmap_size; |
3339 | 3332 | ||
3340 | /* allocate memory for SIT information */ | 3333 | /* allocate memory for SIT information */ |
3341 | sit_i = kzalloc(sizeof(struct sit_info), GFP_KERNEL); | 3334 | sit_i = f2fs_kzalloc(sbi, sizeof(struct sit_info), GFP_KERNEL); |
3342 | if (!sit_i) | 3335 | if (!sit_i) |
3343 | return -ENOMEM; | 3336 | return -ENOMEM; |
3344 | 3337 | ||
3345 | SM_I(sbi)->sit_info = sit_i; | 3338 | SM_I(sbi)->sit_info = sit_i; |
3346 | 3339 | ||
3347 | sit_i->sentries = kvzalloc(MAIN_SEGS(sbi) * | 3340 | sit_i->sentries = f2fs_kvzalloc(sbi, MAIN_SEGS(sbi) * |
3348 | sizeof(struct seg_entry), GFP_KERNEL); | 3341 | sizeof(struct seg_entry), GFP_KERNEL); |
3349 | if (!sit_i->sentries) | 3342 | if (!sit_i->sentries) |
3350 | return -ENOMEM; | 3343 | return -ENOMEM; |
3351 | 3344 | ||
3352 | bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi)); | 3345 | bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi)); |
3353 | sit_i->dirty_sentries_bitmap = kvzalloc(bitmap_size, GFP_KERNEL); | 3346 | sit_i->dirty_sentries_bitmap = f2fs_kvzalloc(sbi, bitmap_size, |
3347 | GFP_KERNEL); | ||
3354 | if (!sit_i->dirty_sentries_bitmap) | 3348 | if (!sit_i->dirty_sentries_bitmap) |
3355 | return -ENOMEM; | 3349 | return -ENOMEM; |
3356 | 3350 | ||
3357 | for (start = 0; start < MAIN_SEGS(sbi); start++) { | 3351 | for (start = 0; start < MAIN_SEGS(sbi); start++) { |
3358 | sit_i->sentries[start].cur_valid_map | 3352 | sit_i->sentries[start].cur_valid_map |
3359 | = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 3353 | = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); |
3360 | sit_i->sentries[start].ckpt_valid_map | 3354 | sit_i->sentries[start].ckpt_valid_map |
3361 | = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 3355 | = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); |
3362 | if (!sit_i->sentries[start].cur_valid_map || | 3356 | if (!sit_i->sentries[start].cur_valid_map || |
3363 | !sit_i->sentries[start].ckpt_valid_map) | 3357 | !sit_i->sentries[start].ckpt_valid_map) |
3364 | return -ENOMEM; | 3358 | return -ENOMEM; |
3365 | 3359 | ||
3366 | #ifdef CONFIG_F2FS_CHECK_FS | 3360 | #ifdef CONFIG_F2FS_CHECK_FS |
3367 | sit_i->sentries[start].cur_valid_map_mir | 3361 | sit_i->sentries[start].cur_valid_map_mir |
3368 | = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 3362 | = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); |
3369 | if (!sit_i->sentries[start].cur_valid_map_mir) | 3363 | if (!sit_i->sentries[start].cur_valid_map_mir) |
3370 | return -ENOMEM; | 3364 | return -ENOMEM; |
3371 | #endif | 3365 | #endif |
3372 | 3366 | ||
3373 | if (f2fs_discard_en(sbi)) { | 3367 | if (f2fs_discard_en(sbi)) { |
3374 | sit_i->sentries[start].discard_map | 3368 | sit_i->sentries[start].discard_map |
3375 | = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 3369 | = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, |
3370 | GFP_KERNEL); | ||
3376 | if (!sit_i->sentries[start].discard_map) | 3371 | if (!sit_i->sentries[start].discard_map) |
3377 | return -ENOMEM; | 3372 | return -ENOMEM; |
3378 | } | 3373 | } |
3379 | } | 3374 | } |
3380 | 3375 | ||
3381 | sit_i->tmp_map = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 3376 | sit_i->tmp_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); |
3382 | if (!sit_i->tmp_map) | 3377 | if (!sit_i->tmp_map) |
3383 | return -ENOMEM; | 3378 | return -ENOMEM; |
3384 | 3379 | ||
3385 | if (sbi->segs_per_sec > 1) { | 3380 | if (sbi->segs_per_sec > 1) { |
3386 | sit_i->sec_entries = kvzalloc(MAIN_SECS(sbi) * | 3381 | sit_i->sec_entries = f2fs_kvzalloc(sbi, MAIN_SECS(sbi) * |
3387 | sizeof(struct sec_entry), GFP_KERNEL); | 3382 | sizeof(struct sec_entry), GFP_KERNEL); |
3388 | if (!sit_i->sec_entries) | 3383 | if (!sit_i->sec_entries) |
3389 | return -ENOMEM; | 3384 | return -ENOMEM; |
@@ -3427,19 +3422,19 @@ static int build_free_segmap(struct f2fs_sb_info *sbi) | |||
3427 | unsigned int bitmap_size, sec_bitmap_size; | 3422 | unsigned int bitmap_size, sec_bitmap_size; |
3428 | 3423 | ||
3429 | /* allocate memory for free segmap information */ | 3424 | /* allocate memory for free segmap information */ |
3430 | free_i = kzalloc(sizeof(struct free_segmap_info), GFP_KERNEL); | 3425 | free_i = f2fs_kzalloc(sbi, sizeof(struct free_segmap_info), GFP_KERNEL); |
3431 | if (!free_i) | 3426 | if (!free_i) |
3432 | return -ENOMEM; | 3427 | return -ENOMEM; |
3433 | 3428 | ||
3434 | SM_I(sbi)->free_info = free_i; | 3429 | SM_I(sbi)->free_info = free_i; |
3435 | 3430 | ||
3436 | bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi)); | 3431 | bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi)); |
3437 | free_i->free_segmap = kvmalloc(bitmap_size, GFP_KERNEL); | 3432 | free_i->free_segmap = f2fs_kvmalloc(sbi, bitmap_size, GFP_KERNEL); |
3438 | if (!free_i->free_segmap) | 3433 | if (!free_i->free_segmap) |
3439 | return -ENOMEM; | 3434 | return -ENOMEM; |
3440 | 3435 | ||
3441 | sec_bitmap_size = f2fs_bitmap_size(MAIN_SECS(sbi)); | 3436 | sec_bitmap_size = f2fs_bitmap_size(MAIN_SECS(sbi)); |
3442 | free_i->free_secmap = kvmalloc(sec_bitmap_size, GFP_KERNEL); | 3437 | free_i->free_secmap = f2fs_kvmalloc(sbi, sec_bitmap_size, GFP_KERNEL); |
3443 | if (!free_i->free_secmap) | 3438 | if (!free_i->free_secmap) |
3444 | return -ENOMEM; | 3439 | return -ENOMEM; |
3445 | 3440 | ||
@@ -3460,7 +3455,7 @@ static int build_curseg(struct f2fs_sb_info *sbi) | |||
3460 | struct curseg_info *array; | 3455 | struct curseg_info *array; |
3461 | int i; | 3456 | int i; |
3462 | 3457 | ||
3463 | array = kcalloc(NR_CURSEG_TYPE, sizeof(*array), GFP_KERNEL); | 3458 | array = f2fs_kzalloc(sbi, sizeof(*array) * NR_CURSEG_TYPE, GFP_KERNEL); |
3464 | if (!array) | 3459 | if (!array) |
3465 | return -ENOMEM; | 3460 | return -ENOMEM; |
3466 | 3461 | ||
@@ -3468,12 +3463,12 @@ static int build_curseg(struct f2fs_sb_info *sbi) | |||
3468 | 3463 | ||
3469 | for (i = 0; i < NR_CURSEG_TYPE; i++) { | 3464 | for (i = 0; i < NR_CURSEG_TYPE; i++) { |
3470 | mutex_init(&array[i].curseg_mutex); | 3465 | mutex_init(&array[i].curseg_mutex); |
3471 | array[i].sum_blk = kzalloc(PAGE_SIZE, GFP_KERNEL); | 3466 | array[i].sum_blk = f2fs_kzalloc(sbi, PAGE_SIZE, GFP_KERNEL); |
3472 | if (!array[i].sum_blk) | 3467 | if (!array[i].sum_blk) |
3473 | return -ENOMEM; | 3468 | return -ENOMEM; |
3474 | init_rwsem(&array[i].journal_rwsem); | 3469 | init_rwsem(&array[i].journal_rwsem); |
3475 | array[i].journal = kzalloc(sizeof(struct f2fs_journal), | 3470 | array[i].journal = f2fs_kzalloc(sbi, |
3476 | GFP_KERNEL); | 3471 | sizeof(struct f2fs_journal), GFP_KERNEL); |
3477 | if (!array[i].journal) | 3472 | if (!array[i].journal) |
3478 | return -ENOMEM; | 3473 | return -ENOMEM; |
3479 | array[i].segno = NULL_SEGNO; | 3474 | array[i].segno = NULL_SEGNO; |
@@ -3482,7 +3477,7 @@ static int build_curseg(struct f2fs_sb_info *sbi) | |||
3482 | return restore_curseg_summaries(sbi); | 3477 | return restore_curseg_summaries(sbi); |
3483 | } | 3478 | } |
3484 | 3479 | ||
3485 | static void build_sit_entries(struct f2fs_sb_info *sbi) | 3480 | static int build_sit_entries(struct f2fs_sb_info *sbi) |
3486 | { | 3481 | { |
3487 | struct sit_info *sit_i = SIT_I(sbi); | 3482 | struct sit_info *sit_i = SIT_I(sbi); |
3488 | struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA); | 3483 | struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_COLD_DATA); |
@@ -3492,6 +3487,7 @@ static void build_sit_entries(struct f2fs_sb_info *sbi) | |||
3492 | int sit_blk_cnt = SIT_BLK_CNT(sbi); | 3487 | int sit_blk_cnt = SIT_BLK_CNT(sbi); |
3493 | unsigned int i, start, end; | 3488 | unsigned int i, start, end; |
3494 | unsigned int readed, start_blk = 0; | 3489 | unsigned int readed, start_blk = 0; |
3490 | int err = 0; | ||
3495 | 3491 | ||
3496 | do { | 3492 | do { |
3497 | readed = ra_meta_pages(sbi, start_blk, BIO_MAX_PAGES, | 3493 | readed = ra_meta_pages(sbi, start_blk, BIO_MAX_PAGES, |
@@ -3510,7 +3506,9 @@ static void build_sit_entries(struct f2fs_sb_info *sbi) | |||
3510 | sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, start)]; | 3506 | sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, start)]; |
3511 | f2fs_put_page(page, 1); | 3507 | f2fs_put_page(page, 1); |
3512 | 3508 | ||
3513 | check_block_count(sbi, start, &sit); | 3509 | err = check_block_count(sbi, start, &sit); |
3510 | if (err) | ||
3511 | return err; | ||
3514 | seg_info_from_raw_sit(se, &sit); | 3512 | seg_info_from_raw_sit(se, &sit); |
3515 | 3513 | ||
3516 | /* build discard map only one time */ | 3514 | /* build discard map only one time */ |
@@ -3545,7 +3543,9 @@ static void build_sit_entries(struct f2fs_sb_info *sbi) | |||
3545 | 3543 | ||
3546 | old_valid_blocks = se->valid_blocks; | 3544 | old_valid_blocks = se->valid_blocks; |
3547 | 3545 | ||
3548 | check_block_count(sbi, start, &sit); | 3546 | err = check_block_count(sbi, start, &sit); |
3547 | if (err) | ||
3548 | break; | ||
3549 | seg_info_from_raw_sit(se, &sit); | 3549 | seg_info_from_raw_sit(se, &sit); |
3550 | 3550 | ||
3551 | if (f2fs_discard_en(sbi)) { | 3551 | if (f2fs_discard_en(sbi)) { |
@@ -3565,6 +3565,7 @@ static void build_sit_entries(struct f2fs_sb_info *sbi) | |||
3565 | se->valid_blocks - old_valid_blocks; | 3565 | se->valid_blocks - old_valid_blocks; |
3566 | } | 3566 | } |
3567 | up_read(&curseg->journal_rwsem); | 3567 | up_read(&curseg->journal_rwsem); |
3568 | return err; | ||
3568 | } | 3569 | } |
3569 | 3570 | ||
3570 | static void init_free_segmap(struct f2fs_sb_info *sbi) | 3571 | static void init_free_segmap(struct f2fs_sb_info *sbi) |
@@ -3619,7 +3620,7 @@ static int init_victim_secmap(struct f2fs_sb_info *sbi) | |||
3619 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); | 3620 | struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); |
3620 | unsigned int bitmap_size = f2fs_bitmap_size(MAIN_SECS(sbi)); | 3621 | unsigned int bitmap_size = f2fs_bitmap_size(MAIN_SECS(sbi)); |
3621 | 3622 | ||
3622 | dirty_i->victim_secmap = kvzalloc(bitmap_size, GFP_KERNEL); | 3623 | dirty_i->victim_secmap = f2fs_kvzalloc(sbi, bitmap_size, GFP_KERNEL); |
3623 | if (!dirty_i->victim_secmap) | 3624 | if (!dirty_i->victim_secmap) |
3624 | return -ENOMEM; | 3625 | return -ENOMEM; |
3625 | return 0; | 3626 | return 0; |
@@ -3631,7 +3632,8 @@ static int build_dirty_segmap(struct f2fs_sb_info *sbi) | |||
3631 | unsigned int bitmap_size, i; | 3632 | unsigned int bitmap_size, i; |
3632 | 3633 | ||
3633 | /* allocate memory for dirty segments list information */ | 3634 | /* allocate memory for dirty segments list information */ |
3634 | dirty_i = kzalloc(sizeof(struct dirty_seglist_info), GFP_KERNEL); | 3635 | dirty_i = f2fs_kzalloc(sbi, sizeof(struct dirty_seglist_info), |
3636 | GFP_KERNEL); | ||
3635 | if (!dirty_i) | 3637 | if (!dirty_i) |
3636 | return -ENOMEM; | 3638 | return -ENOMEM; |
3637 | 3639 | ||
@@ -3641,7 +3643,8 @@ static int build_dirty_segmap(struct f2fs_sb_info *sbi) | |||
3641 | bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi)); | 3643 | bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi)); |
3642 | 3644 | ||
3643 | for (i = 0; i < NR_DIRTY_TYPE; i++) { | 3645 | for (i = 0; i < NR_DIRTY_TYPE; i++) { |
3644 | dirty_i->dirty_segmap[i] = kvzalloc(bitmap_size, GFP_KERNEL); | 3646 | dirty_i->dirty_segmap[i] = f2fs_kvzalloc(sbi, bitmap_size, |
3647 | GFP_KERNEL); | ||
3645 | if (!dirty_i->dirty_segmap[i]) | 3648 | if (!dirty_i->dirty_segmap[i]) |
3646 | return -ENOMEM; | 3649 | return -ENOMEM; |
3647 | } | 3650 | } |
@@ -3685,7 +3688,7 @@ int build_segment_manager(struct f2fs_sb_info *sbi) | |||
3685 | struct f2fs_sm_info *sm_info; | 3688 | struct f2fs_sm_info *sm_info; |
3686 | int err; | 3689 | int err; |
3687 | 3690 | ||
3688 | sm_info = kzalloc(sizeof(struct f2fs_sm_info), GFP_KERNEL); | 3691 | sm_info = f2fs_kzalloc(sbi, sizeof(struct f2fs_sm_info), GFP_KERNEL); |
3689 | if (!sm_info) | 3692 | if (!sm_info) |
3690 | return -ENOMEM; | 3693 | return -ENOMEM; |
3691 | 3694 | ||
@@ -3737,7 +3740,9 @@ int build_segment_manager(struct f2fs_sb_info *sbi) | |||
3737 | return err; | 3740 | return err; |
3738 | 3741 | ||
3739 | /* reinit free segmap based on SIT */ | 3742 | /* reinit free segmap based on SIT */ |
3740 | build_sit_entries(sbi); | 3743 | err = build_sit_entries(sbi); |
3744 | if (err) | ||
3745 | return err; | ||
3741 | 3746 | ||
3742 | init_free_segmap(sbi); | 3747 | init_free_segmap(sbi); |
3743 | err = build_dirty_segmap(sbi); | 3748 | err = build_dirty_segmap(sbi); |
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index d1d394cdf61d..f11c4bc82c78 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h | |||
@@ -348,16 +348,41 @@ static inline void seg_info_from_raw_sit(struct seg_entry *se, | |||
348 | se->mtime = le64_to_cpu(rs->mtime); | 348 | se->mtime = le64_to_cpu(rs->mtime); |
349 | } | 349 | } |
350 | 350 | ||
351 | static inline void seg_info_to_raw_sit(struct seg_entry *se, | 351 | static inline void __seg_info_to_raw_sit(struct seg_entry *se, |
352 | struct f2fs_sit_entry *rs) | 352 | struct f2fs_sit_entry *rs) |
353 | { | 353 | { |
354 | unsigned short raw_vblocks = (se->type << SIT_VBLOCKS_SHIFT) | | 354 | unsigned short raw_vblocks = (se->type << SIT_VBLOCKS_SHIFT) | |
355 | se->valid_blocks; | 355 | se->valid_blocks; |
356 | rs->vblocks = cpu_to_le16(raw_vblocks); | 356 | rs->vblocks = cpu_to_le16(raw_vblocks); |
357 | memcpy(rs->valid_map, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE); | 357 | memcpy(rs->valid_map, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE); |
358 | rs->mtime = cpu_to_le64(se->mtime); | ||
359 | } | ||
360 | |||
361 | static inline void seg_info_to_sit_page(struct f2fs_sb_info *sbi, | ||
362 | struct page *page, unsigned int start) | ||
363 | { | ||
364 | struct f2fs_sit_block *raw_sit; | ||
365 | struct seg_entry *se; | ||
366 | struct f2fs_sit_entry *rs; | ||
367 | unsigned int end = min(start + SIT_ENTRY_PER_BLOCK, | ||
368 | (unsigned long)MAIN_SEGS(sbi)); | ||
369 | int i; | ||
370 | |||
371 | raw_sit = (struct f2fs_sit_block *)page_address(page); | ||
372 | for (i = 0; i < end - start; i++) { | ||
373 | rs = &raw_sit->entries[i]; | ||
374 | se = get_seg_entry(sbi, start + i); | ||
375 | __seg_info_to_raw_sit(se, rs); | ||
376 | } | ||
377 | } | ||
378 | |||
379 | static inline void seg_info_to_raw_sit(struct seg_entry *se, | ||
380 | struct f2fs_sit_entry *rs) | ||
381 | { | ||
382 | __seg_info_to_raw_sit(se, rs); | ||
383 | |||
358 | memcpy(se->ckpt_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE); | 384 | memcpy(se->ckpt_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE); |
359 | se->ckpt_valid_blocks = se->valid_blocks; | 385 | se->ckpt_valid_blocks = se->valid_blocks; |
360 | rs->mtime = cpu_to_le64(se->mtime); | ||
361 | } | 386 | } |
362 | 387 | ||
363 | static inline unsigned int find_next_inuse(struct free_segmap_info *free_i, | 388 | static inline unsigned int find_next_inuse(struct free_segmap_info *free_i, |
@@ -580,47 +605,6 @@ enum { | |||
580 | F2FS_IPU_ASYNC, | 605 | F2FS_IPU_ASYNC, |
581 | }; | 606 | }; |
582 | 607 | ||
583 | static inline bool need_inplace_update_policy(struct inode *inode, | ||
584 | struct f2fs_io_info *fio) | ||
585 | { | ||
586 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | ||
587 | unsigned int policy = SM_I(sbi)->ipu_policy; | ||
588 | |||
589 | if (test_opt(sbi, LFS)) | ||
590 | return false; | ||
591 | |||
592 | /* if this is cold file, we should overwrite to avoid fragmentation */ | ||
593 | if (file_is_cold(inode)) | ||
594 | return true; | ||
595 | |||
596 | if (policy & (0x1 << F2FS_IPU_FORCE)) | ||
597 | return true; | ||
598 | if (policy & (0x1 << F2FS_IPU_SSR) && need_SSR(sbi)) | ||
599 | return true; | ||
600 | if (policy & (0x1 << F2FS_IPU_UTIL) && | ||
601 | utilization(sbi) > SM_I(sbi)->min_ipu_util) | ||
602 | return true; | ||
603 | if (policy & (0x1 << F2FS_IPU_SSR_UTIL) && need_SSR(sbi) && | ||
604 | utilization(sbi) > SM_I(sbi)->min_ipu_util) | ||
605 | return true; | ||
606 | |||
607 | /* | ||
608 | * IPU for rewrite async pages | ||
609 | */ | ||
610 | if (policy & (0x1 << F2FS_IPU_ASYNC) && | ||
611 | fio && fio->op == REQ_OP_WRITE && | ||
612 | !(fio->op_flags & REQ_SYNC) && | ||
613 | !f2fs_encrypted_inode(inode)) | ||
614 | return true; | ||
615 | |||
616 | /* this is only set during fdatasync */ | ||
617 | if (policy & (0x1 << F2FS_IPU_FSYNC) && | ||
618 | is_inode_flag_set(inode, FI_NEED_IPU)) | ||
619 | return true; | ||
620 | |||
621 | return false; | ||
622 | } | ||
623 | |||
624 | static inline unsigned int curseg_segno(struct f2fs_sb_info *sbi, | 608 | static inline unsigned int curseg_segno(struct f2fs_sb_info *sbi, |
625 | int type) | 609 | int type) |
626 | { | 610 | { |
@@ -655,7 +639,7 @@ static inline void verify_block_addr(struct f2fs_sb_info *sbi, block_t blk_addr) | |||
655 | /* | 639 | /* |
656 | * Summary block is always treated as an invalid block | 640 | * Summary block is always treated as an invalid block |
657 | */ | 641 | */ |
658 | static inline void check_block_count(struct f2fs_sb_info *sbi, | 642 | static inline int check_block_count(struct f2fs_sb_info *sbi, |
659 | int segno, struct f2fs_sit_entry *raw_sit) | 643 | int segno, struct f2fs_sit_entry *raw_sit) |
660 | { | 644 | { |
661 | #ifdef CONFIG_F2FS_CHECK_FS | 645 | #ifdef CONFIG_F2FS_CHECK_FS |
@@ -677,11 +661,25 @@ static inline void check_block_count(struct f2fs_sb_info *sbi, | |||
677 | cur_pos = next_pos; | 661 | cur_pos = next_pos; |
678 | is_valid = !is_valid; | 662 | is_valid = !is_valid; |
679 | } while (cur_pos < sbi->blocks_per_seg); | 663 | } while (cur_pos < sbi->blocks_per_seg); |
680 | BUG_ON(GET_SIT_VBLOCKS(raw_sit) != valid_blocks); | 664 | |
665 | if (unlikely(GET_SIT_VBLOCKS(raw_sit) != valid_blocks)) { | ||
666 | f2fs_msg(sbi->sb, KERN_ERR, | ||
667 | "Mismatch valid blocks %d vs. %d", | ||
668 | GET_SIT_VBLOCKS(raw_sit), valid_blocks); | ||
669 | set_sbi_flag(sbi, SBI_NEED_FSCK); | ||
670 | return -EINVAL; | ||
671 | } | ||
681 | #endif | 672 | #endif |
682 | /* check segment usage, and check boundary of a given segment number */ | 673 | /* check segment usage, and check boundary of a given segment number */ |
683 | f2fs_bug_on(sbi, GET_SIT_VBLOCKS(raw_sit) > sbi->blocks_per_seg | 674 | if (unlikely(GET_SIT_VBLOCKS(raw_sit) > sbi->blocks_per_seg |
684 | || segno > TOTAL_SEGS(sbi) - 1); | 675 | || segno > TOTAL_SEGS(sbi) - 1)) { |
676 | f2fs_msg(sbi->sb, KERN_ERR, | ||
677 | "Wrong valid blocks %d or segno %u", | ||
678 | GET_SIT_VBLOCKS(raw_sit), segno); | ||
679 | set_sbi_flag(sbi, SBI_NEED_FSCK); | ||
680 | return -EINVAL; | ||
681 | } | ||
682 | return 0; | ||
685 | } | 683 | } |
686 | 684 | ||
687 | static inline pgoff_t current_sit_addr(struct f2fs_sb_info *sbi, | 685 | static inline pgoff_t current_sit_addr(struct f2fs_sb_info *sbi, |
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 708155d9c2e4..8173ae688814 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c | |||
@@ -43,6 +43,7 @@ static struct kmem_cache *f2fs_inode_cachep; | |||
43 | 43 | ||
44 | char *fault_name[FAULT_MAX] = { | 44 | char *fault_name[FAULT_MAX] = { |
45 | [FAULT_KMALLOC] = "kmalloc", | 45 | [FAULT_KMALLOC] = "kmalloc", |
46 | [FAULT_KVMALLOC] = "kvmalloc", | ||
46 | [FAULT_PAGE_ALLOC] = "page alloc", | 47 | [FAULT_PAGE_ALLOC] = "page alloc", |
47 | [FAULT_PAGE_GET] = "page get", | 48 | [FAULT_PAGE_GET] = "page get", |
48 | [FAULT_ALLOC_BIO] = "alloc bio", | 49 | [FAULT_ALLOC_BIO] = "alloc bio", |
@@ -106,6 +107,9 @@ enum { | |||
106 | Opt_noextent_cache, | 107 | Opt_noextent_cache, |
107 | Opt_noinline_data, | 108 | Opt_noinline_data, |
108 | Opt_data_flush, | 109 | Opt_data_flush, |
110 | Opt_reserve_root, | ||
111 | Opt_resgid, | ||
112 | Opt_resuid, | ||
109 | Opt_mode, | 113 | Opt_mode, |
110 | Opt_io_size_bits, | 114 | Opt_io_size_bits, |
111 | Opt_fault_injection, | 115 | Opt_fault_injection, |
@@ -156,6 +160,9 @@ static match_table_t f2fs_tokens = { | |||
156 | {Opt_noextent_cache, "noextent_cache"}, | 160 | {Opt_noextent_cache, "noextent_cache"}, |
157 | {Opt_noinline_data, "noinline_data"}, | 161 | {Opt_noinline_data, "noinline_data"}, |
158 | {Opt_data_flush, "data_flush"}, | 162 | {Opt_data_flush, "data_flush"}, |
163 | {Opt_reserve_root, "reserve_root=%u"}, | ||
164 | {Opt_resgid, "resgid=%u"}, | ||
165 | {Opt_resuid, "resuid=%u"}, | ||
159 | {Opt_mode, "mode=%s"}, | 166 | {Opt_mode, "mode=%s"}, |
160 | {Opt_io_size_bits, "io_bits=%u"}, | 167 | {Opt_io_size_bits, "io_bits=%u"}, |
161 | {Opt_fault_injection, "fault_injection=%u"}, | 168 | {Opt_fault_injection, "fault_injection=%u"}, |
@@ -190,6 +197,28 @@ void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...) | |||
190 | va_end(args); | 197 | va_end(args); |
191 | } | 198 | } |
192 | 199 | ||
200 | static inline void limit_reserve_root(struct f2fs_sb_info *sbi) | ||
201 | { | ||
202 | block_t limit = (sbi->user_block_count << 1) / 1000; | ||
203 | |||
204 | /* limit is 0.2% */ | ||
205 | if (test_opt(sbi, RESERVE_ROOT) && sbi->root_reserved_blocks > limit) { | ||
206 | sbi->root_reserved_blocks = limit; | ||
207 | f2fs_msg(sbi->sb, KERN_INFO, | ||
208 | "Reduce reserved blocks for root = %u", | ||
209 | sbi->root_reserved_blocks); | ||
210 | } | ||
211 | if (!test_opt(sbi, RESERVE_ROOT) && | ||
212 | (!uid_eq(sbi->s_resuid, | ||
213 | make_kuid(&init_user_ns, F2FS_DEF_RESUID)) || | ||
214 | !gid_eq(sbi->s_resgid, | ||
215 | make_kgid(&init_user_ns, F2FS_DEF_RESGID)))) | ||
216 | f2fs_msg(sbi->sb, KERN_INFO, | ||
217 | "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root", | ||
218 | from_kuid_munged(&init_user_ns, sbi->s_resuid), | ||
219 | from_kgid_munged(&init_user_ns, sbi->s_resgid)); | ||
220 | } | ||
221 | |||
193 | static void init_once(void *foo) | 222 | static void init_once(void *foo) |
194 | { | 223 | { |
195 | struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo; | 224 | struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo; |
@@ -320,6 +349,8 @@ static int parse_options(struct super_block *sb, char *options) | |||
320 | substring_t args[MAX_OPT_ARGS]; | 349 | substring_t args[MAX_OPT_ARGS]; |
321 | char *p, *name; | 350 | char *p, *name; |
322 | int arg = 0; | 351 | int arg = 0; |
352 | kuid_t uid; | ||
353 | kgid_t gid; | ||
323 | #ifdef CONFIG_QUOTA | 354 | #ifdef CONFIG_QUOTA |
324 | int ret; | 355 | int ret; |
325 | #endif | 356 | #endif |
@@ -487,6 +518,40 @@ static int parse_options(struct super_block *sb, char *options) | |||
487 | case Opt_data_flush: | 518 | case Opt_data_flush: |
488 | set_opt(sbi, DATA_FLUSH); | 519 | set_opt(sbi, DATA_FLUSH); |
489 | break; | 520 | break; |
521 | case Opt_reserve_root: | ||
522 | if (args->from && match_int(args, &arg)) | ||
523 | return -EINVAL; | ||
524 | if (test_opt(sbi, RESERVE_ROOT)) { | ||
525 | f2fs_msg(sb, KERN_INFO, | ||
526 | "Preserve previous reserve_root=%u", | ||
527 | sbi->root_reserved_blocks); | ||
528 | } else { | ||
529 | sbi->root_reserved_blocks = arg; | ||
530 | set_opt(sbi, RESERVE_ROOT); | ||
531 | } | ||
532 | break; | ||
533 | case Opt_resuid: | ||
534 | if (args->from && match_int(args, &arg)) | ||
535 | return -EINVAL; | ||
536 | uid = make_kuid(current_user_ns(), arg); | ||
537 | if (!uid_valid(uid)) { | ||
538 | f2fs_msg(sb, KERN_ERR, | ||
539 | "Invalid uid value %d", arg); | ||
540 | return -EINVAL; | ||
541 | } | ||
542 | sbi->s_resuid = uid; | ||
543 | break; | ||
544 | case Opt_resgid: | ||
545 | if (args->from && match_int(args, &arg)) | ||
546 | return -EINVAL; | ||
547 | gid = make_kgid(current_user_ns(), arg); | ||
548 | if (!gid_valid(gid)) { | ||
549 | f2fs_msg(sb, KERN_ERR, | ||
550 | "Invalid gid value %d", arg); | ||
551 | return -EINVAL; | ||
552 | } | ||
553 | sbi->s_resgid = gid; | ||
554 | break; | ||
490 | case Opt_mode: | 555 | case Opt_mode: |
491 | name = match_strdup(&args[0]); | 556 | name = match_strdup(&args[0]); |
492 | 557 | ||
@@ -993,22 +1058,25 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
993 | struct super_block *sb = dentry->d_sb; | 1058 | struct super_block *sb = dentry->d_sb; |
994 | struct f2fs_sb_info *sbi = F2FS_SB(sb); | 1059 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
995 | u64 id = huge_encode_dev(sb->s_bdev->bd_dev); | 1060 | u64 id = huge_encode_dev(sb->s_bdev->bd_dev); |
996 | block_t total_count, user_block_count, start_count, ovp_count; | 1061 | block_t total_count, user_block_count, start_count; |
997 | u64 avail_node_count; | 1062 | u64 avail_node_count; |
998 | 1063 | ||
999 | total_count = le64_to_cpu(sbi->raw_super->block_count); | 1064 | total_count = le64_to_cpu(sbi->raw_super->block_count); |
1000 | user_block_count = sbi->user_block_count; | 1065 | user_block_count = sbi->user_block_count; |
1001 | start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr); | 1066 | start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr); |
1002 | ovp_count = SM_I(sbi)->ovp_segments << sbi->log_blocks_per_seg; | ||
1003 | buf->f_type = F2FS_SUPER_MAGIC; | 1067 | buf->f_type = F2FS_SUPER_MAGIC; |
1004 | buf->f_bsize = sbi->blocksize; | 1068 | buf->f_bsize = sbi->blocksize; |
1005 | 1069 | ||
1006 | buf->f_blocks = total_count - start_count; | 1070 | buf->f_blocks = total_count - start_count; |
1007 | buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count; | 1071 | buf->f_bfree = user_block_count - valid_user_blocks(sbi) - |
1008 | buf->f_bavail = user_block_count - valid_user_blocks(sbi) - | ||
1009 | sbi->current_reserved_blocks; | 1072 | sbi->current_reserved_blocks; |
1073 | if (buf->f_bfree > sbi->root_reserved_blocks) | ||
1074 | buf->f_bavail = buf->f_bfree - sbi->root_reserved_blocks; | ||
1075 | else | ||
1076 | buf->f_bavail = 0; | ||
1010 | 1077 | ||
1011 | avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; | 1078 | avail_node_count = sbi->total_node_count - sbi->nquota_files - |
1079 | F2FS_RESERVED_NODE_NUM; | ||
1012 | 1080 | ||
1013 | if (avail_node_count > user_block_count) { | 1081 | if (avail_node_count > user_block_count) { |
1014 | buf->f_files = user_block_count; | 1082 | buf->f_files = user_block_count; |
@@ -1134,6 +1202,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root) | |||
1134 | else if (test_opt(sbi, LFS)) | 1202 | else if (test_opt(sbi, LFS)) |
1135 | seq_puts(seq, "lfs"); | 1203 | seq_puts(seq, "lfs"); |
1136 | seq_printf(seq, ",active_logs=%u", sbi->active_logs); | 1204 | seq_printf(seq, ",active_logs=%u", sbi->active_logs); |
1205 | if (test_opt(sbi, RESERVE_ROOT)) | ||
1206 | seq_printf(seq, ",reserve_root=%u,resuid=%u,resgid=%u", | ||
1207 | sbi->root_reserved_blocks, | ||
1208 | from_kuid_munged(&init_user_ns, sbi->s_resuid), | ||
1209 | from_kgid_munged(&init_user_ns, sbi->s_resgid)); | ||
1137 | if (F2FS_IO_SIZE_BITS(sbi)) | 1210 | if (F2FS_IO_SIZE_BITS(sbi)) |
1138 | seq_printf(seq, ",io_size=%uKB", F2FS_IO_SIZE_KB(sbi)); | 1211 | seq_printf(seq, ",io_size=%uKB", F2FS_IO_SIZE_KB(sbi)); |
1139 | #ifdef CONFIG_F2FS_FAULT_INJECTION | 1212 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
@@ -1263,7 +1336,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) | |||
1263 | err = dquot_suspend(sb, -1); | 1336 | err = dquot_suspend(sb, -1); |
1264 | if (err < 0) | 1337 | if (err < 0) |
1265 | goto restore_opts; | 1338 | goto restore_opts; |
1266 | } else { | 1339 | } else if (f2fs_readonly(sb) && !(*flags & MS_RDONLY)) { |
1267 | /* dquot_resume needs RW */ | 1340 | /* dquot_resume needs RW */ |
1268 | sb->s_flags &= ~SB_RDONLY; | 1341 | sb->s_flags &= ~SB_RDONLY; |
1269 | if (sb_any_quota_suspended(sb)) { | 1342 | if (sb_any_quota_suspended(sb)) { |
@@ -1332,6 +1405,7 @@ skip: | |||
1332 | sb->s_flags = (sb->s_flags & ~SB_POSIXACL) | | 1405 | sb->s_flags = (sb->s_flags & ~SB_POSIXACL) | |
1333 | (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); | 1406 | (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); |
1334 | 1407 | ||
1408 | limit_reserve_root(sbi); | ||
1335 | return 0; | 1409 | return 0; |
1336 | restore_gc: | 1410 | restore_gc: |
1337 | if (need_restart_gc) { | 1411 | if (need_restart_gc) { |
@@ -1656,7 +1730,7 @@ void f2fs_quota_off_umount(struct super_block *sb) | |||
1656 | f2fs_quota_off(sb, type); | 1730 | f2fs_quota_off(sb, type); |
1657 | } | 1731 | } |
1658 | 1732 | ||
1659 | int f2fs_get_projid(struct inode *inode, kprojid_t *projid) | 1733 | static int f2fs_get_projid(struct inode *inode, kprojid_t *projid) |
1660 | { | 1734 | { |
1661 | *projid = F2FS_I(inode)->i_projid; | 1735 | *projid = F2FS_I(inode)->i_projid; |
1662 | return 0; | 1736 | return 0; |
@@ -2148,14 +2222,15 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) | |||
2148 | if (nr_sectors & (bdev_zone_sectors(bdev) - 1)) | 2222 | if (nr_sectors & (bdev_zone_sectors(bdev) - 1)) |
2149 | FDEV(devi).nr_blkz++; | 2223 | FDEV(devi).nr_blkz++; |
2150 | 2224 | ||
2151 | FDEV(devi).blkz_type = kmalloc(FDEV(devi).nr_blkz, GFP_KERNEL); | 2225 | FDEV(devi).blkz_type = f2fs_kmalloc(sbi, FDEV(devi).nr_blkz, |
2226 | GFP_KERNEL); | ||
2152 | if (!FDEV(devi).blkz_type) | 2227 | if (!FDEV(devi).blkz_type) |
2153 | return -ENOMEM; | 2228 | return -ENOMEM; |
2154 | 2229 | ||
2155 | #define F2FS_REPORT_NR_ZONES 4096 | 2230 | #define F2FS_REPORT_NR_ZONES 4096 |
2156 | 2231 | ||
2157 | zones = kcalloc(F2FS_REPORT_NR_ZONES, sizeof(struct blk_zone), | 2232 | zones = f2fs_kzalloc(sbi, sizeof(struct blk_zone) * |
2158 | GFP_KERNEL); | 2233 | F2FS_REPORT_NR_ZONES, GFP_KERNEL); |
2159 | if (!zones) | 2234 | if (!zones) |
2160 | return -ENOMEM; | 2235 | return -ENOMEM; |
2161 | 2236 | ||
@@ -2295,8 +2370,8 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) | |||
2295 | * Initialize multiple devices information, or single | 2370 | * Initialize multiple devices information, or single |
2296 | * zoned block device information. | 2371 | * zoned block device information. |
2297 | */ | 2372 | */ |
2298 | sbi->devs = kcalloc(max_devices, sizeof(struct f2fs_dev_info), | 2373 | sbi->devs = f2fs_kzalloc(sbi, sizeof(struct f2fs_dev_info) * |
2299 | GFP_KERNEL); | 2374 | max_devices, GFP_KERNEL); |
2300 | if (!sbi->devs) | 2375 | if (!sbi->devs) |
2301 | return -ENOMEM; | 2376 | return -ENOMEM; |
2302 | 2377 | ||
@@ -2419,6 +2494,9 @@ try_onemore: | |||
2419 | sb->s_fs_info = sbi; | 2494 | sb->s_fs_info = sbi; |
2420 | sbi->raw_super = raw_super; | 2495 | sbi->raw_super = raw_super; |
2421 | 2496 | ||
2497 | sbi->s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID); | ||
2498 | sbi->s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID); | ||
2499 | |||
2422 | /* precompute checksum seed for metadata */ | 2500 | /* precompute checksum seed for metadata */ |
2423 | if (f2fs_sb_has_inode_chksum(sb)) | 2501 | if (f2fs_sb_has_inode_chksum(sb)) |
2424 | sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid, | 2502 | sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid, |
@@ -2462,6 +2540,13 @@ try_onemore: | |||
2462 | else | 2540 | else |
2463 | sb->s_qcop = &f2fs_quotactl_ops; | 2541 | sb->s_qcop = &f2fs_quotactl_ops; |
2464 | sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ; | 2542 | sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ; |
2543 | |||
2544 | if (f2fs_sb_has_quota_ino(sbi->sb)) { | ||
2545 | for (i = 0; i < MAXQUOTAS; i++) { | ||
2546 | if (f2fs_qf_ino(sbi->sb, i)) | ||
2547 | sbi->nquota_files++; | ||
2548 | } | ||
2549 | } | ||
2465 | #endif | 2550 | #endif |
2466 | 2551 | ||
2467 | sb->s_op = &f2fs_sops; | 2552 | sb->s_op = &f2fs_sops; |
@@ -2475,6 +2560,7 @@ try_onemore: | |||
2475 | sb->s_flags = (sb->s_flags & ~SB_POSIXACL) | | 2560 | sb->s_flags = (sb->s_flags & ~SB_POSIXACL) | |
2476 | (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); | 2561 | (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); |
2477 | memcpy(&sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid)); | 2562 | memcpy(&sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid)); |
2563 | sb->s_iflags |= SB_I_CGROUPWB; | ||
2478 | 2564 | ||
2479 | /* init f2fs-specific super block info */ | 2565 | /* init f2fs-specific super block info */ |
2480 | sbi->valid_super_block = valid_super_block; | 2566 | sbi->valid_super_block = valid_super_block; |
@@ -2495,8 +2581,9 @@ try_onemore: | |||
2495 | int n = (i == META) ? 1: NR_TEMP_TYPE; | 2581 | int n = (i == META) ? 1: NR_TEMP_TYPE; |
2496 | int j; | 2582 | int j; |
2497 | 2583 | ||
2498 | sbi->write_io[i] = kmalloc(n * sizeof(struct f2fs_bio_info), | 2584 | sbi->write_io[i] = f2fs_kmalloc(sbi, |
2499 | GFP_KERNEL); | 2585 | n * sizeof(struct f2fs_bio_info), |
2586 | GFP_KERNEL); | ||
2500 | if (!sbi->write_io[i]) { | 2587 | if (!sbi->write_io[i]) { |
2501 | err = -ENOMEM; | 2588 | err = -ENOMEM; |
2502 | goto free_options; | 2589 | goto free_options; |
@@ -2517,14 +2604,14 @@ try_onemore: | |||
2517 | 2604 | ||
2518 | err = init_percpu_info(sbi); | 2605 | err = init_percpu_info(sbi); |
2519 | if (err) | 2606 | if (err) |
2520 | goto free_options; | 2607 | goto free_bio_info; |
2521 | 2608 | ||
2522 | if (F2FS_IO_SIZE(sbi) > 1) { | 2609 | if (F2FS_IO_SIZE(sbi) > 1) { |
2523 | sbi->write_io_dummy = | 2610 | sbi->write_io_dummy = |
2524 | mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); | 2611 | mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); |
2525 | if (!sbi->write_io_dummy) { | 2612 | if (!sbi->write_io_dummy) { |
2526 | err = -ENOMEM; | 2613 | err = -ENOMEM; |
2527 | goto free_options; | 2614 | goto free_percpu; |
2528 | } | 2615 | } |
2529 | } | 2616 | } |
2530 | 2617 | ||
@@ -2559,6 +2646,7 @@ try_onemore: | |||
2559 | sbi->last_valid_block_count = sbi->total_valid_block_count; | 2646 | sbi->last_valid_block_count = sbi->total_valid_block_count; |
2560 | sbi->reserved_blocks = 0; | 2647 | sbi->reserved_blocks = 0; |
2561 | sbi->current_reserved_blocks = 0; | 2648 | sbi->current_reserved_blocks = 0; |
2649 | limit_reserve_root(sbi); | ||
2562 | 2650 | ||
2563 | for (i = 0; i < NR_INODE_TYPE; i++) { | 2651 | for (i = 0; i < NR_INODE_TYPE; i++) { |
2564 | INIT_LIST_HEAD(&sbi->inode_list[i]); | 2652 | INIT_LIST_HEAD(&sbi->inode_list[i]); |
@@ -2604,18 +2692,16 @@ try_onemore: | |||
2604 | goto free_nm; | 2692 | goto free_nm; |
2605 | } | 2693 | } |
2606 | 2694 | ||
2607 | f2fs_join_shrinker(sbi); | ||
2608 | |||
2609 | err = f2fs_build_stats(sbi); | 2695 | err = f2fs_build_stats(sbi); |
2610 | if (err) | 2696 | if (err) |
2611 | goto free_nm; | 2697 | goto free_node_inode; |
2612 | 2698 | ||
2613 | /* read root inode and dentry */ | 2699 | /* read root inode and dentry */ |
2614 | root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); | 2700 | root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); |
2615 | if (IS_ERR(root)) { | 2701 | if (IS_ERR(root)) { |
2616 | f2fs_msg(sb, KERN_ERR, "Failed to read root inode"); | 2702 | f2fs_msg(sb, KERN_ERR, "Failed to read root inode"); |
2617 | err = PTR_ERR(root); | 2703 | err = PTR_ERR(root); |
2618 | goto free_node_inode; | 2704 | goto free_stats; |
2619 | } | 2705 | } |
2620 | if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { | 2706 | if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { |
2621 | iput(root); | 2707 | iput(root); |
@@ -2711,6 +2797,8 @@ skip_recovery: | |||
2711 | sbi->valid_super_block ? 1 : 2, err); | 2797 | sbi->valid_super_block ? 1 : 2, err); |
2712 | } | 2798 | } |
2713 | 2799 | ||
2800 | f2fs_join_shrinker(sbi); | ||
2801 | |||
2714 | f2fs_msg(sbi->sb, KERN_NOTICE, "Mounted with checkpoint version = %llx", | 2802 | f2fs_msg(sbi->sb, KERN_NOTICE, "Mounted with checkpoint version = %llx", |
2715 | cur_cp_version(F2FS_CKPT(sbi))); | 2803 | cur_cp_version(F2FS_CKPT(sbi))); |
2716 | f2fs_update_time(sbi, CP_TIME); | 2804 | f2fs_update_time(sbi, CP_TIME); |
@@ -2737,14 +2825,12 @@ free_sysfs: | |||
2737 | free_root_inode: | 2825 | free_root_inode: |
2738 | dput(sb->s_root); | 2826 | dput(sb->s_root); |
2739 | sb->s_root = NULL; | 2827 | sb->s_root = NULL; |
2828 | free_stats: | ||
2829 | f2fs_destroy_stats(sbi); | ||
2740 | free_node_inode: | 2830 | free_node_inode: |
2741 | truncate_inode_pages_final(NODE_MAPPING(sbi)); | ||
2742 | mutex_lock(&sbi->umount_mutex); | ||
2743 | release_ino_entry(sbi, true); | 2831 | release_ino_entry(sbi, true); |
2744 | f2fs_leave_shrinker(sbi); | 2832 | truncate_inode_pages_final(NODE_MAPPING(sbi)); |
2745 | iput(sbi->node_inode); | 2833 | iput(sbi->node_inode); |
2746 | mutex_unlock(&sbi->umount_mutex); | ||
2747 | f2fs_destroy_stats(sbi); | ||
2748 | free_nm: | 2834 | free_nm: |
2749 | destroy_node_manager(sbi); | 2835 | destroy_node_manager(sbi); |
2750 | free_sm: | 2836 | free_sm: |
@@ -2757,10 +2843,12 @@ free_meta_inode: | |||
2757 | iput(sbi->meta_inode); | 2843 | iput(sbi->meta_inode); |
2758 | free_io_dummy: | 2844 | free_io_dummy: |
2759 | mempool_destroy(sbi->write_io_dummy); | 2845 | mempool_destroy(sbi->write_io_dummy); |
2760 | free_options: | 2846 | free_percpu: |
2847 | destroy_percpu_info(sbi); | ||
2848 | free_bio_info: | ||
2761 | for (i = 0; i < NR_PAGE_TYPE; i++) | 2849 | for (i = 0; i < NR_PAGE_TYPE; i++) |
2762 | kfree(sbi->write_io[i]); | 2850 | kfree(sbi->write_io[i]); |
2763 | destroy_percpu_info(sbi); | 2851 | free_options: |
2764 | #ifdef CONFIG_QUOTA | 2852 | #ifdef CONFIG_QUOTA |
2765 | for (i = 0; i < MAXQUOTAS; i++) | 2853 | for (i = 0; i < MAXQUOTAS; i++) |
2766 | kfree(sbi->s_qf_names[i]); | 2854 | kfree(sbi->s_qf_names[i]); |
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 9835348b6e5d..d978c7b6ea04 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c | |||
@@ -113,6 +113,9 @@ static ssize_t features_show(struct f2fs_attr *a, | |||
113 | if (f2fs_sb_has_quota_ino(sb)) | 113 | if (f2fs_sb_has_quota_ino(sb)) |
114 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", | 114 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
115 | len ? ", " : "", "quota_ino"); | 115 | len ? ", " : "", "quota_ino"); |
116 | if (f2fs_sb_has_inode_crtime(sb)) | ||
117 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", | ||
118 | len ? ", " : "", "inode_crtime"); | ||
116 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | 119 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
117 | return len; | 120 | return len; |
118 | } | 121 | } |
@@ -162,7 +165,8 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a, | |||
162 | #endif | 165 | #endif |
163 | if (a->struct_type == RESERVED_BLOCKS) { | 166 | if (a->struct_type == RESERVED_BLOCKS) { |
164 | spin_lock(&sbi->stat_lock); | 167 | spin_lock(&sbi->stat_lock); |
165 | if (t > (unsigned long)sbi->user_block_count) { | 168 | if (t > (unsigned long)(sbi->user_block_count - |
169 | sbi->root_reserved_blocks)) { | ||
166 | spin_unlock(&sbi->stat_lock); | 170 | spin_unlock(&sbi->stat_lock); |
167 | return -EINVAL; | 171 | return -EINVAL; |
168 | } | 172 | } |
@@ -231,6 +235,7 @@ enum feat_id { | |||
231 | FEAT_INODE_CHECKSUM, | 235 | FEAT_INODE_CHECKSUM, |
232 | FEAT_FLEXIBLE_INLINE_XATTR, | 236 | FEAT_FLEXIBLE_INLINE_XATTR, |
233 | FEAT_QUOTA_INO, | 237 | FEAT_QUOTA_INO, |
238 | FEAT_INODE_CRTIME, | ||
234 | }; | 239 | }; |
235 | 240 | ||
236 | static ssize_t f2fs_feature_show(struct f2fs_attr *a, | 241 | static ssize_t f2fs_feature_show(struct f2fs_attr *a, |
@@ -245,6 +250,7 @@ static ssize_t f2fs_feature_show(struct f2fs_attr *a, | |||
245 | case FEAT_INODE_CHECKSUM: | 250 | case FEAT_INODE_CHECKSUM: |
246 | case FEAT_FLEXIBLE_INLINE_XATTR: | 251 | case FEAT_FLEXIBLE_INLINE_XATTR: |
247 | case FEAT_QUOTA_INO: | 252 | case FEAT_QUOTA_INO: |
253 | case FEAT_INODE_CRTIME: | ||
248 | return snprintf(buf, PAGE_SIZE, "supported\n"); | 254 | return snprintf(buf, PAGE_SIZE, "supported\n"); |
249 | } | 255 | } |
250 | return 0; | 256 | return 0; |
@@ -299,6 +305,8 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level); | |||
299 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]); | 305 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]); |
300 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]); | 306 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]); |
301 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable); | 307 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable); |
308 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra); | ||
309 | F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold); | ||
302 | #ifdef CONFIG_F2FS_FAULT_INJECTION | 310 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
303 | F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate); | 311 | F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate); |
304 | F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type); | 312 | F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type); |
@@ -320,6 +328,7 @@ F2FS_FEATURE_RO_ATTR(project_quota, FEAT_PROJECT_QUOTA); | |||
320 | F2FS_FEATURE_RO_ATTR(inode_checksum, FEAT_INODE_CHECKSUM); | 328 | F2FS_FEATURE_RO_ATTR(inode_checksum, FEAT_INODE_CHECKSUM); |
321 | F2FS_FEATURE_RO_ATTR(flexible_inline_xattr, FEAT_FLEXIBLE_INLINE_XATTR); | 329 | F2FS_FEATURE_RO_ATTR(flexible_inline_xattr, FEAT_FLEXIBLE_INLINE_XATTR); |
322 | F2FS_FEATURE_RO_ATTR(quota_ino, FEAT_QUOTA_INO); | 330 | F2FS_FEATURE_RO_ATTR(quota_ino, FEAT_QUOTA_INO); |
331 | F2FS_FEATURE_RO_ATTR(inode_crtime, FEAT_INODE_CRTIME); | ||
323 | 332 | ||
324 | #define ATTR_LIST(name) (&f2fs_attr_##name.attr) | 333 | #define ATTR_LIST(name) (&f2fs_attr_##name.attr) |
325 | static struct attribute *f2fs_attrs[] = { | 334 | static struct attribute *f2fs_attrs[] = { |
@@ -346,6 +355,8 @@ static struct attribute *f2fs_attrs[] = { | |||
346 | ATTR_LIST(cp_interval), | 355 | ATTR_LIST(cp_interval), |
347 | ATTR_LIST(idle_interval), | 356 | ATTR_LIST(idle_interval), |
348 | ATTR_LIST(iostat_enable), | 357 | ATTR_LIST(iostat_enable), |
358 | ATTR_LIST(readdir_ra), | ||
359 | ATTR_LIST(gc_pin_file_thresh), | ||
349 | #ifdef CONFIG_F2FS_FAULT_INJECTION | 360 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
350 | ATTR_LIST(inject_rate), | 361 | ATTR_LIST(inject_rate), |
351 | ATTR_LIST(inject_type), | 362 | ATTR_LIST(inject_type), |
@@ -371,6 +382,7 @@ static struct attribute *f2fs_feat_attrs[] = { | |||
371 | ATTR_LIST(inode_checksum), | 382 | ATTR_LIST(inode_checksum), |
372 | ATTR_LIST(flexible_inline_xattr), | 383 | ATTR_LIST(flexible_inline_xattr), |
373 | ATTR_LIST(quota_ino), | 384 | ATTR_LIST(quota_ino), |
385 | ATTR_LIST(inode_crtime), | ||
374 | NULL, | 386 | NULL, |
375 | }; | 387 | }; |
376 | 388 | ||
diff --git a/fs/f2fs/trace.c b/fs/f2fs/trace.c index bccbbf2616d2..a1fcd00bbb2b 100644 --- a/fs/f2fs/trace.c +++ b/fs/f2fs/trace.c | |||
@@ -17,7 +17,7 @@ | |||
17 | #include "trace.h" | 17 | #include "trace.h" |
18 | 18 | ||
19 | static RADIX_TREE(pids, GFP_ATOMIC); | 19 | static RADIX_TREE(pids, GFP_ATOMIC); |
20 | static spinlock_t pids_lock; | 20 | static struct mutex pids_lock; |
21 | static struct last_io_info last_io; | 21 | static struct last_io_info last_io; |
22 | 22 | ||
23 | static inline void __print_last_io(void) | 23 | static inline void __print_last_io(void) |
@@ -64,7 +64,7 @@ void f2fs_trace_pid(struct page *page) | |||
64 | if (radix_tree_preload(GFP_NOFS)) | 64 | if (radix_tree_preload(GFP_NOFS)) |
65 | return; | 65 | return; |
66 | 66 | ||
67 | spin_lock(&pids_lock); | 67 | mutex_lock(&pids_lock); |
68 | p = radix_tree_lookup(&pids, pid); | 68 | p = radix_tree_lookup(&pids, pid); |
69 | if (p == current) | 69 | if (p == current) |
70 | goto out; | 70 | goto out; |
@@ -77,7 +77,7 @@ void f2fs_trace_pid(struct page *page) | |||
77 | MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev), | 77 | MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev), |
78 | pid, current->comm); | 78 | pid, current->comm); |
79 | out: | 79 | out: |
80 | spin_unlock(&pids_lock); | 80 | mutex_unlock(&pids_lock); |
81 | radix_tree_preload_end(); | 81 | radix_tree_preload_end(); |
82 | } | 82 | } |
83 | 83 | ||
@@ -122,7 +122,7 @@ void f2fs_trace_ios(struct f2fs_io_info *fio, int flush) | |||
122 | 122 | ||
123 | void f2fs_build_trace_ios(void) | 123 | void f2fs_build_trace_ios(void) |
124 | { | 124 | { |
125 | spin_lock_init(&pids_lock); | 125 | mutex_init(&pids_lock); |
126 | } | 126 | } |
127 | 127 | ||
128 | #define PIDVEC_SIZE 128 | 128 | #define PIDVEC_SIZE 128 |
@@ -150,7 +150,7 @@ void f2fs_destroy_trace_ios(void) | |||
150 | pid_t next_pid = 0; | 150 | pid_t next_pid = 0; |
151 | unsigned int found; | 151 | unsigned int found; |
152 | 152 | ||
153 | spin_lock(&pids_lock); | 153 | mutex_lock(&pids_lock); |
154 | while ((found = gang_lookup_pids(pid, next_pid, PIDVEC_SIZE))) { | 154 | while ((found = gang_lookup_pids(pid, next_pid, PIDVEC_SIZE))) { |
155 | unsigned idx; | 155 | unsigned idx; |
156 | 156 | ||
@@ -158,5 +158,5 @@ void f2fs_destroy_trace_ios(void) | |||
158 | for (idx = 0; idx < found; idx++) | 158 | for (idx = 0; idx < found; idx++) |
159 | radix_tree_delete(&pids, pid[idx]); | 159 | radix_tree_delete(&pids, pid[idx]); |
160 | } | 160 | } |
161 | spin_unlock(&pids_lock); | 161 | mutex_unlock(&pids_lock); |
162 | } | 162 | } |
diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index ec8961ef8cac..ae2dfa709f5d 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c | |||
@@ -298,8 +298,8 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage, | |||
298 | if (!size && !inline_size) | 298 | if (!size && !inline_size) |
299 | return -ENODATA; | 299 | return -ENODATA; |
300 | 300 | ||
301 | txattr_addr = kzalloc(inline_size + size + XATTR_PADDING_SIZE, | 301 | txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode), |
302 | GFP_F2FS_ZERO); | 302 | inline_size + size + XATTR_PADDING_SIZE, GFP_NOFS); |
303 | if (!txattr_addr) | 303 | if (!txattr_addr) |
304 | return -ENOMEM; | 304 | return -ENOMEM; |
305 | 305 | ||
@@ -351,8 +351,8 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage, | |||
351 | void *txattr_addr; | 351 | void *txattr_addr; |
352 | int err; | 352 | int err; |
353 | 353 | ||
354 | txattr_addr = kzalloc(inline_size + size + XATTR_PADDING_SIZE, | 354 | txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode), |
355 | GFP_F2FS_ZERO); | 355 | inline_size + size + XATTR_PADDING_SIZE, GFP_NOFS); |
356 | if (!txattr_addr) | 356 | if (!txattr_addr) |
357 | return -ENOMEM; | 357 | return -ENOMEM; |
358 | 358 | ||
@@ -433,6 +433,7 @@ static inline int write_all_xattrs(struct inode *inode, __u32 hsize, | |||
433 | if (F2FS_I(inode)->i_xattr_nid) { | 433 | if (F2FS_I(inode)->i_xattr_nid) { |
434 | xpage = get_node_page(sbi, F2FS_I(inode)->i_xattr_nid); | 434 | xpage = get_node_page(sbi, F2FS_I(inode)->i_xattr_nid); |
435 | if (IS_ERR(xpage)) { | 435 | if (IS_ERR(xpage)) { |
436 | err = PTR_ERR(xpage); | ||
436 | alloc_nid_failed(sbi, new_nid); | 437 | alloc_nid_failed(sbi, new_nid); |
437 | goto in_page_out; | 438 | goto in_page_out; |
438 | } | 439 | } |
@@ -443,6 +444,7 @@ static inline int write_all_xattrs(struct inode *inode, __u32 hsize, | |||
443 | set_new_dnode(&dn, inode, NULL, NULL, new_nid); | 444 | set_new_dnode(&dn, inode, NULL, NULL, new_nid); |
444 | xpage = new_node_page(&dn, XATTR_NODE_OFFSET); | 445 | xpage = new_node_page(&dn, XATTR_NODE_OFFSET); |
445 | if (IS_ERR(xpage)) { | 446 | if (IS_ERR(xpage)) { |
447 | err = PTR_ERR(xpage); | ||
446 | alloc_nid_failed(sbi, new_nid); | 448 | alloc_nid_failed(sbi, new_nid); |
447 | goto in_page_out; | 449 | goto in_page_out; |
448 | } | 450 | } |
@@ -598,7 +600,7 @@ static int __f2fs_setxattr(struct inode *inode, int index, | |||
598 | goto exit; | 600 | goto exit; |
599 | } | 601 | } |
600 | 602 | ||
601 | if (f2fs_xattr_value_same(here, value, size)) | 603 | if (value && f2fs_xattr_value_same(here, value, size)) |
602 | goto exit; | 604 | goto exit; |
603 | } else if ((flags & XATTR_REPLACE)) { | 605 | } else if ((flags & XATTR_REPLACE)) { |
604 | error = -ENODATA; | 606 | error = -ENODATA; |
diff --git a/fs/posix_acl.c b/fs/posix_acl.c index eebf5f6cf6d5..2fd0fde16fe1 100644 --- a/fs/posix_acl.c +++ b/fs/posix_acl.c | |||
@@ -43,7 +43,7 @@ struct posix_acl *get_cached_acl(struct inode *inode, int type) | |||
43 | rcu_read_lock(); | 43 | rcu_read_lock(); |
44 | acl = rcu_dereference(*p); | 44 | acl = rcu_dereference(*p); |
45 | if (!acl || is_uncached_acl(acl) || | 45 | if (!acl || is_uncached_acl(acl) || |
46 | atomic_inc_not_zero(&acl->a_refcount)) | 46 | refcount_inc_not_zero(&acl->a_refcount)) |
47 | break; | 47 | break; |
48 | rcu_read_unlock(); | 48 | rcu_read_unlock(); |
49 | cpu_relax(); | 49 | cpu_relax(); |
@@ -164,7 +164,7 @@ EXPORT_SYMBOL(get_acl); | |||
164 | void | 164 | void |
165 | posix_acl_init(struct posix_acl *acl, int count) | 165 | posix_acl_init(struct posix_acl *acl, int count) |
166 | { | 166 | { |
167 | atomic_set(&acl->a_refcount, 1); | 167 | refcount_set(&acl->a_refcount, 1); |
168 | acl->a_count = count; | 168 | acl->a_count = count; |
169 | } | 169 | } |
170 | EXPORT_SYMBOL(posix_acl_init); | 170 | EXPORT_SYMBOL(posix_acl_init); |
@@ -197,7 +197,7 @@ posix_acl_clone(const struct posix_acl *acl, gfp_t flags) | |||
197 | sizeof(struct posix_acl_entry); | 197 | sizeof(struct posix_acl_entry); |
198 | clone = kmemdup(acl, size, flags); | 198 | clone = kmemdup(acl, size, flags); |
199 | if (clone) | 199 | if (clone) |
200 | atomic_set(&clone->a_refcount, 1); | 200 | refcount_set(&clone->a_refcount, 1); |
201 | } | 201 | } |
202 | return clone; | 202 | return clone; |
203 | } | 203 | } |
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 43e98d30d2df..58aecb60ea51 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h | |||
@@ -117,6 +117,7 @@ struct f2fs_super_block { | |||
117 | /* | 117 | /* |
118 | * For checkpoint | 118 | * For checkpoint |
119 | */ | 119 | */ |
120 | #define CP_NOCRC_RECOVERY_FLAG 0x00000200 | ||
120 | #define CP_TRIMMED_FLAG 0x00000100 | 121 | #define CP_TRIMMED_FLAG 0x00000100 |
121 | #define CP_NAT_BITS_FLAG 0x00000080 | 122 | #define CP_NAT_BITS_FLAG 0x00000080 |
122 | #define CP_CRC_RECOVERY_FLAG 0x00000040 | 123 | #define CP_CRC_RECOVERY_FLAG 0x00000040 |
@@ -212,6 +213,7 @@ struct f2fs_extent { | |||
212 | #define F2FS_DATA_EXIST 0x08 /* file inline data exist flag */ | 213 | #define F2FS_DATA_EXIST 0x08 /* file inline data exist flag */ |
213 | #define F2FS_INLINE_DOTS 0x10 /* file having implicit dot dentries */ | 214 | #define F2FS_INLINE_DOTS 0x10 /* file having implicit dot dentries */ |
214 | #define F2FS_EXTRA_ATTR 0x20 /* file having extra attribute */ | 215 | #define F2FS_EXTRA_ATTR 0x20 /* file having extra attribute */ |
216 | #define F2FS_PIN_FILE 0x40 /* file should not be gced */ | ||
215 | 217 | ||
216 | struct f2fs_inode { | 218 | struct f2fs_inode { |
217 | __le16 i_mode; /* file mode */ | 219 | __le16 i_mode; /* file mode */ |
@@ -229,7 +231,13 @@ struct f2fs_inode { | |||
229 | __le32 i_ctime_nsec; /* change time in nano scale */ | 231 | __le32 i_ctime_nsec; /* change time in nano scale */ |
230 | __le32 i_mtime_nsec; /* modification time in nano scale */ | 232 | __le32 i_mtime_nsec; /* modification time in nano scale */ |
231 | __le32 i_generation; /* file version (for NFS) */ | 233 | __le32 i_generation; /* file version (for NFS) */ |
232 | __le32 i_current_depth; /* only for directory depth */ | 234 | union { |
235 | __le32 i_current_depth; /* only for directory depth */ | ||
236 | __le16 i_gc_failures; /* | ||
237 | * # of gc failures on pinned file. | ||
238 | * only for regular files. | ||
239 | */ | ||
240 | }; | ||
233 | __le32 i_xattr_nid; /* nid to save xattr */ | 241 | __le32 i_xattr_nid; /* nid to save xattr */ |
234 | __le32 i_flags; /* file attributes */ | 242 | __le32 i_flags; /* file attributes */ |
235 | __le32 i_pino; /* parent inode number */ | 243 | __le32 i_pino; /* parent inode number */ |
@@ -245,8 +253,10 @@ struct f2fs_inode { | |||
245 | __le16 i_inline_xattr_size; /* inline xattr size, unit: 4 bytes */ | 253 | __le16 i_inline_xattr_size; /* inline xattr size, unit: 4 bytes */ |
246 | __le32 i_projid; /* project id */ | 254 | __le32 i_projid; /* project id */ |
247 | __le32 i_inode_checksum;/* inode meta checksum */ | 255 | __le32 i_inode_checksum;/* inode meta checksum */ |
256 | __le64 i_crtime; /* creation time */ | ||
257 | __le32 i_crtime_nsec; /* creation time in nano scale */ | ||
248 | __le32 i_extra_end[0]; /* for attribute size calculation */ | 258 | __le32 i_extra_end[0]; /* for attribute size calculation */ |
249 | }; | 259 | } __packed; |
250 | __le32 i_addr[DEF_ADDRS_PER_INODE]; /* Pointers to data blocks */ | 260 | __le32 i_addr[DEF_ADDRS_PER_INODE]; /* Pointers to data blocks */ |
251 | }; | 261 | }; |
252 | __le32 i_nid[DEF_NIDS_PER_INODE]; /* direct(2), indirect(2), | 262 | __le32 i_nid[DEF_NIDS_PER_INODE]; /* direct(2), indirect(2), |
diff --git a/include/linux/posix_acl.h b/include/linux/posix_acl.h index b2b7255ec7f5..540595a321a7 100644 --- a/include/linux/posix_acl.h +++ b/include/linux/posix_acl.h | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/bug.h> | 12 | #include <linux/bug.h> |
13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
14 | #include <linux/rcupdate.h> | 14 | #include <linux/rcupdate.h> |
15 | #include <linux/refcount.h> | ||
15 | #include <uapi/linux/posix_acl.h> | 16 | #include <uapi/linux/posix_acl.h> |
16 | 17 | ||
17 | struct posix_acl_entry { | 18 | struct posix_acl_entry { |
@@ -24,7 +25,7 @@ struct posix_acl_entry { | |||
24 | }; | 25 | }; |
25 | 26 | ||
26 | struct posix_acl { | 27 | struct posix_acl { |
27 | atomic_t a_refcount; | 28 | refcount_t a_refcount; |
28 | struct rcu_head a_rcu; | 29 | struct rcu_head a_rcu; |
29 | unsigned int a_count; | 30 | unsigned int a_count; |
30 | struct posix_acl_entry a_entries[0]; | 31 | struct posix_acl_entry a_entries[0]; |
@@ -41,7 +42,7 @@ static inline struct posix_acl * | |||
41 | posix_acl_dup(struct posix_acl *acl) | 42 | posix_acl_dup(struct posix_acl *acl) |
42 | { | 43 | { |
43 | if (acl) | 44 | if (acl) |
44 | atomic_inc(&acl->a_refcount); | 45 | refcount_inc(&acl->a_refcount); |
45 | return acl; | 46 | return acl; |
46 | } | 47 | } |
47 | 48 | ||
@@ -51,7 +52,7 @@ posix_acl_dup(struct posix_acl *acl) | |||
51 | static inline void | 52 | static inline void |
52 | posix_acl_release(struct posix_acl *acl) | 53 | posix_acl_release(struct posix_acl *acl) |
53 | { | 54 | { |
54 | if (acl && atomic_dec_and_test(&acl->a_refcount)) | 55 | if (acl && refcount_dec_and_test(&acl->a_refcount)) |
55 | kfree_rcu(acl, a_rcu); | 56 | kfree_rcu(acl, a_rcu); |
56 | } | 57 | } |
57 | 58 | ||
diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h index 8f8dd42fa57b..06c87f9f720c 100644 --- a/include/trace/events/f2fs.h +++ b/include/trace/events/f2fs.h | |||
@@ -147,7 +147,8 @@ TRACE_DEFINE_ENUM(CP_TRIMMED); | |||
147 | { CP_NO_SPC_ROLL, "no space roll forward" }, \ | 147 | { CP_NO_SPC_ROLL, "no space roll forward" }, \ |
148 | { CP_NODE_NEED_CP, "node needs cp" }, \ | 148 | { CP_NODE_NEED_CP, "node needs cp" }, \ |
149 | { CP_FASTBOOT_MODE, "fastboot mode" }, \ | 149 | { CP_FASTBOOT_MODE, "fastboot mode" }, \ |
150 | { CP_SPEC_LOG_NUM, "log type is 2" }) | 150 | { CP_SPEC_LOG_NUM, "log type is 2" }, \ |
151 | { CP_RECOVER_DIR, "dir needs recovery" }) | ||
151 | 152 | ||
152 | struct victim_sel_policy; | 153 | struct victim_sel_policy; |
153 | struct f2fs_map_blocks; | 154 | struct f2fs_map_blocks; |