aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-04-05 22:12:55 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-04-05 22:12:55 -0400
commit274c0e74e508c939a4ae5ef3890fddb4af537b76 (patch)
tree14d210cf61e2563d6085743bd324222a831e6a88
parent052c220da392c4dcbc628852d04970447a315683 (diff)
parent214c2461a864a46b11856426b80dc7db453043c5 (diff)
Merge tag 'f2fs-for-4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
Pull f2fs update from Jaegeuk Kim: "In this round, we've mainly focused on performance tuning and critical bug fixes occurred in low-end devices. Sheng Yong introduced lost_found feature to keep missing files during recovery instead of thrashing them. We're preparing coming fsverity implementation. And, we've got more features to communicate with users for better performance. In low-end devices, some memory-related issues were fixed, and subtle race condtions and corner cases were addressed as well. Enhancements: - large nat bitmaps for more free node ids - add three block allocation policies to pass down write hints given by user - expose extension list to user and introduce hot file extension - tune small devices seamlessly for low-end devices - set readdir_ra by default - give more resources under gc_urgent mode regarding to discard and cleaning - introduce fsync_mode to enforce posix or not - nowait aio support - add lost_found feature to keep dangling inodes - reserve bits for future fsverity feature - add test_dummy_encryption for FBE Bug fixes: - don't use highmem for dentry pages - align memory boundary for bitops - truncate preallocated blocks in write errors - guarantee i_times on fsync call - clear CP_TRIMMED_FLAG correctly - prevent node chain loop during recovery - avoid data race between atomic write and background cleaning - avoid unnecessary selinux violation warnings on resgid option - GFP_NOFS to avoid deadlock in quota and read paths - fix f2fs_skip_inode_update to allow i_size recovery In addition to the above, there are several minor bug fixes and clean-ups" * tag 'f2fs-for-4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (50 commits) f2fs: remain written times to update inode during fsync f2fs: make assignment of t->dentry_bitmap more readable f2fs: truncate preallocated blocks in error case f2fs: fix a wrong condition in f2fs_skip_inode_update f2fs: reserve bits for fs-verity f2fs: Add a segment type check in inplace write f2fs: no need to initialize zero value for GFP_F2FS_ZERO f2fs: don't track new nat entry in nat set f2fs: clean up with F2FS_BLK_ALIGN f2fs: check blkaddr more accuratly before issue a bio f2fs: Set GF_NOFS in read_cache_page_gfp while doing f2fs_quota_read f2fs: introduce a new mount option test_dummy_encryption f2fs: introduce F2FS_FEATURE_LOST_FOUND feature f2fs: release locks before return in f2fs_ioc_gc_range() f2fs: align memory boundary for bitops f2fs: remove unneeded set_cold_node() f2fs: add nowait aio support f2fs: wrap all options with f2fs_sb_info.mount_opt f2fs: Don't overwrite all types of node to keep node chain f2fs: introduce mount option for fsync mode ...
-rw-r--r--Documentation/ABI/testing/sysfs-fs-f2fs11
-rw-r--r--Documentation/filesystems/f2fs.txt77
-rw-r--r--fs/f2fs/checkpoint.c101
-rw-r--r--fs/f2fs/data.c85
-rw-r--r--fs/f2fs/dir.c32
-rw-r--r--fs/f2fs/extent_cache.c5
-rw-r--r--fs/f2fs/f2fs.h188
-rw-r--r--fs/f2fs/file.c94
-rw-r--r--fs/f2fs/gc.c23
-rw-r--r--fs/f2fs/inline.c3
-rw-r--r--fs/f2fs/inode.c11
-rw-r--r--fs/f2fs/namei.c147
-rw-r--r--fs/f2fs/node.c55
-rw-r--r--fs/f2fs/node.h5
-rw-r--r--fs/f2fs/recovery.c25
-rw-r--r--fs/f2fs/segment.c133
-rw-r--r--fs/f2fs/segment.h27
-rw-r--r--fs/f2fs/super.c348
-rw-r--r--fs/f2fs/sysfs.c73
-rw-r--r--include/linux/f2fs_fs.h20
20 files changed, 1081 insertions, 382 deletions
diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index d870b5514d15..540553c933b6 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -192,3 +192,14 @@ Date: November 2017
192Contact: "Sheng Yong" <shengyong1@huawei.com> 192Contact: "Sheng Yong" <shengyong1@huawei.com>
193Description: 193Description:
194 Controls readahead inode block in readdir. 194 Controls readahead inode block in readdir.
195
196What: /sys/fs/f2fs/<disk>/extension_list
197Date: Feburary 2018
198Contact: "Chao Yu" <yuchao0@huawei.com>
199Description:
200 Used to control configure extension list:
201 - Query: cat /sys/fs/f2fs/<disk>/extension_list
202 - Add: echo '[h/c]extension' > /sys/fs/f2fs/<disk>/extension_list
203 - Del: echo '[h/c]!extension' > /sys/fs/f2fs/<disk>/extension_list
204 - [h] means add/del hot file extension
205 - [c] means add/del cold file extension
diff --git a/Documentation/filesystems/f2fs.txt b/Documentation/filesystems/f2fs.txt
index 13c2ff034348..12a147c9f87f 100644
--- a/Documentation/filesystems/f2fs.txt
+++ b/Documentation/filesystems/f2fs.txt
@@ -174,6 +174,23 @@ offgrpjquota Turn off group journelled quota.
174offprjjquota Turn off project journelled quota. 174offprjjquota Turn off project journelled quota.
175quota Enable plain user disk quota accounting. 175quota Enable plain user disk quota accounting.
176noquota Disable all plain disk quota option. 176noquota Disable all plain disk quota option.
177whint_mode=%s Control which write hints are passed down to block
178 layer. This supports "off", "user-based", and
179 "fs-based". In "off" mode (default), f2fs does not pass
180 down hints. In "user-based" mode, f2fs tries to pass
181 down hints given by users. And in "fs-based" mode, f2fs
182 passes down hints with its policy.
183alloc_mode=%s Adjust block allocation policy, which supports "reuse"
184 and "default".
185fsync_mode=%s Control the policy of fsync. Currently supports "posix"
186 and "strict". In "posix" mode, which is default, fsync
187 will follow POSIX semantics and does a light operation
188 to improve the filesystem performance. In "strict" mode,
189 fsync will be heavy and behaves in line with xfs, ext4
190 and btrfs, where xfstest generic/342 will pass, but the
191 performance will regress.
192test_dummy_encryption Enable dummy encryption, which provides a fake fscrypt
193 context. The fake fscrypt context is used by xfstests.
177 194
178================================================================================ 195================================================================================
179DEBUGFS ENTRIES 196DEBUGFS ENTRIES
@@ -611,3 +628,63 @@ algorithm.
611In order to identify whether the data in the victim segment are valid or not, 628In order to identify whether the data in the victim segment are valid or not,
612F2FS manages a bitmap. Each bit represents the validity of a block, and the 629F2FS manages a bitmap. Each bit represents the validity of a block, and the
613bitmap is composed of a bit stream covering whole blocks in main area. 630bitmap is composed of a bit stream covering whole blocks in main area.
631
632Write-hint Policy
633-----------------
634
6351) whint_mode=off. F2FS only passes down WRITE_LIFE_NOT_SET.
636
6372) whint_mode=user-based. F2FS tries to pass down hints given by
638users.
639
640User F2FS Block
641---- ---- -----
642 META WRITE_LIFE_NOT_SET
643 HOT_NODE "
644 WARM_NODE "
645 COLD_NODE "
646*ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME
647*extension list " "
648
649-- buffered io
650WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME
651WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT
652WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET
653WRITE_LIFE_NONE " "
654WRITE_LIFE_MEDIUM " "
655WRITE_LIFE_LONG " "
656
657-- direct io
658WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME
659WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT
660WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET
661WRITE_LIFE_NONE " WRITE_LIFE_NONE
662WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM
663WRITE_LIFE_LONG " WRITE_LIFE_LONG
664
6653) whint_mode=fs-based. F2FS passes down hints with its policy.
666
667User F2FS Block
668---- ---- -----
669 META WRITE_LIFE_MEDIUM;
670 HOT_NODE WRITE_LIFE_NOT_SET
671 WARM_NODE "
672 COLD_NODE WRITE_LIFE_NONE
673ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME
674extension list " "
675
676-- buffered io
677WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME
678WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT
679WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_LONG
680WRITE_LIFE_NONE " "
681WRITE_LIFE_MEDIUM " "
682WRITE_LIFE_LONG " "
683
684-- direct io
685WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME
686WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT
687WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET
688WRITE_LIFE_NONE " WRITE_LIFE_NONE
689WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM
690WRITE_LIFE_LONG " WRITE_LIFE_LONG
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 512dca8abc7d..bf779461df13 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -68,6 +68,7 @@ static struct page *__get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index,
68 .old_blkaddr = index, 68 .old_blkaddr = index,
69 .new_blkaddr = index, 69 .new_blkaddr = index,
70 .encrypted_page = NULL, 70 .encrypted_page = NULL,
71 .is_meta = is_meta,
71 }; 72 };
72 73
73 if (unlikely(!is_meta)) 74 if (unlikely(!is_meta))
@@ -162,6 +163,7 @@ int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
162 .op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD, 163 .op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD,
163 .encrypted_page = NULL, 164 .encrypted_page = NULL,
164 .in_list = false, 165 .in_list = false,
166 .is_meta = (type != META_POR),
165 }; 167 };
166 struct blk_plug plug; 168 struct blk_plug plug;
167 169
@@ -569,13 +571,8 @@ static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
569 struct node_info ni; 571 struct node_info ni;
570 int err = acquire_orphan_inode(sbi); 572 int err = acquire_orphan_inode(sbi);
571 573
572 if (err) { 574 if (err)
573 set_sbi_flag(sbi, SBI_NEED_FSCK); 575 goto err_out;
574 f2fs_msg(sbi->sb, KERN_WARNING,
575 "%s: orphan failed (ino=%x), run fsck to fix.",
576 __func__, ino);
577 return err;
578 }
579 576
580 __add_ino_entry(sbi, ino, 0, ORPHAN_INO); 577 __add_ino_entry(sbi, ino, 0, ORPHAN_INO);
581 578
@@ -589,6 +586,11 @@ static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
589 return PTR_ERR(inode); 586 return PTR_ERR(inode);
590 } 587 }
591 588
589 err = dquot_initialize(inode);
590 if (err)
591 goto err_out;
592
593 dquot_initialize(inode);
592 clear_nlink(inode); 594 clear_nlink(inode);
593 595
594 /* truncate all the data during iput */ 596 /* truncate all the data during iput */
@@ -598,14 +600,18 @@ static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
598 600
599 /* ENOMEM was fully retried in f2fs_evict_inode. */ 601 /* ENOMEM was fully retried in f2fs_evict_inode. */
600 if (ni.blk_addr != NULL_ADDR) { 602 if (ni.blk_addr != NULL_ADDR) {
601 set_sbi_flag(sbi, SBI_NEED_FSCK); 603 err = -EIO;
602 f2fs_msg(sbi->sb, KERN_WARNING, 604 goto err_out;
603 "%s: orphan failed (ino=%x) by kernel, retry mount.",
604 __func__, ino);
605 return -EIO;
606 } 605 }
607 __remove_ino_entry(sbi, ino, ORPHAN_INO); 606 __remove_ino_entry(sbi, ino, ORPHAN_INO);
608 return 0; 607 return 0;
608
609err_out:
610 set_sbi_flag(sbi, SBI_NEED_FSCK);
611 f2fs_msg(sbi->sb, KERN_WARNING,
612 "%s: orphan failed (ino=%x), run fsck to fix.",
613 __func__, ino);
614 return err;
609} 615}
610 616
611int recover_orphan_inodes(struct f2fs_sb_info *sbi) 617int recover_orphan_inodes(struct f2fs_sb_info *sbi)
@@ -1136,6 +1142,8 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1136 1142
1137 if (cpc->reason & CP_TRIMMED) 1143 if (cpc->reason & CP_TRIMMED)
1138 __set_ckpt_flags(ckpt, CP_TRIMMED_FLAG); 1144 __set_ckpt_flags(ckpt, CP_TRIMMED_FLAG);
1145 else
1146 __clear_ckpt_flags(ckpt, CP_TRIMMED_FLAG);
1139 1147
1140 if (cpc->reason & CP_UMOUNT) 1148 if (cpc->reason & CP_UMOUNT)
1141 __set_ckpt_flags(ckpt, CP_UMOUNT_FLAG); 1149 __set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
@@ -1162,6 +1170,39 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1162 spin_unlock_irqrestore(&sbi->cp_lock, flags); 1170 spin_unlock_irqrestore(&sbi->cp_lock, flags);
1163} 1171}
1164 1172
1173static void commit_checkpoint(struct f2fs_sb_info *sbi,
1174 void *src, block_t blk_addr)
1175{
1176 struct writeback_control wbc = {
1177 .for_reclaim = 0,
1178 };
1179
1180 /*
1181 * pagevec_lookup_tag and lock_page again will take
1182 * some extra time. Therefore, update_meta_pages and
1183 * sync_meta_pages are combined in this function.
1184 */
1185 struct page *page = grab_meta_page(sbi, blk_addr);
1186 int err;
1187
1188 memcpy(page_address(page), src, PAGE_SIZE);
1189 set_page_dirty(page);
1190
1191 f2fs_wait_on_page_writeback(page, META, true);
1192 f2fs_bug_on(sbi, PageWriteback(page));
1193 if (unlikely(!clear_page_dirty_for_io(page)))
1194 f2fs_bug_on(sbi, 1);
1195
1196 /* writeout cp pack 2 page */
1197 err = __f2fs_write_meta_page(page, &wbc, FS_CP_META_IO);
1198 f2fs_bug_on(sbi, err);
1199
1200 f2fs_put_page(page, 0);
1201
1202 /* submit checkpoint (with barrier if NOBARRIER is not set) */
1203 f2fs_submit_merged_write(sbi, META_FLUSH);
1204}
1205
1165static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) 1206static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1166{ 1207{
1167 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1208 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
@@ -1264,16 +1305,6 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1264 } 1305 }
1265 } 1306 }
1266 1307
1267 /* need to wait for end_io results */
1268 wait_on_all_pages_writeback(sbi);
1269 if (unlikely(f2fs_cp_error(sbi)))
1270 return -EIO;
1271
1272 /* flush all device cache */
1273 err = f2fs_flush_device_cache(sbi);
1274 if (err)
1275 return err;
1276
1277 /* write out checkpoint buffer at block 0 */ 1308 /* write out checkpoint buffer at block 0 */
1278 update_meta_page(sbi, ckpt, start_blk++); 1309 update_meta_page(sbi, ckpt, start_blk++);
1279 1310
@@ -1301,26 +1332,26 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1301 start_blk += NR_CURSEG_NODE_TYPE; 1332 start_blk += NR_CURSEG_NODE_TYPE;
1302 } 1333 }
1303 1334
1304 /* writeout checkpoint block */ 1335 /* update user_block_counts */
1305 update_meta_page(sbi, ckpt, start_blk); 1336 sbi->last_valid_block_count = sbi->total_valid_block_count;
1337 percpu_counter_set(&sbi->alloc_valid_block_count, 0);
1338
1339 /* Here, we have one bio having CP pack except cp pack 2 page */
1340 sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO);
1306 1341
1307 /* wait for previous submitted node/meta pages writeback */ 1342 /* wait for previous submitted meta pages writeback */
1308 wait_on_all_pages_writeback(sbi); 1343 wait_on_all_pages_writeback(sbi);
1309 1344
1310 if (unlikely(f2fs_cp_error(sbi))) 1345 if (unlikely(f2fs_cp_error(sbi)))
1311 return -EIO; 1346 return -EIO;
1312 1347
1313 filemap_fdatawait_range(NODE_MAPPING(sbi), 0, LLONG_MAX); 1348 /* flush all device cache */
1314 filemap_fdatawait_range(META_MAPPING(sbi), 0, LLONG_MAX); 1349 err = f2fs_flush_device_cache(sbi);
1315 1350 if (err)
1316 /* update user_block_counts */ 1351 return err;
1317 sbi->last_valid_block_count = sbi->total_valid_block_count;
1318 percpu_counter_set(&sbi->alloc_valid_block_count, 0);
1319
1320 /* Here, we only have one bio having CP pack */
1321 sync_meta_pages(sbi, META_FLUSH, LONG_MAX, FS_CP_META_IO);
1322 1352
1323 /* wait for previous submitted meta pages writeback */ 1353 /* barrier and flush checkpoint cp pack 2 page if it can */
1354 commit_checkpoint(sbi, ckpt, start_blk);
1324 wait_on_all_pages_writeback(sbi); 1355 wait_on_all_pages_writeback(sbi);
1325 1356
1326 release_ino_entry(sbi, false); 1357 release_ino_entry(sbi, false);
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 7578ed1a85e0..db50686f5096 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -175,15 +175,22 @@ static bool __same_bdev(struct f2fs_sb_info *sbi,
175 */ 175 */
176static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr, 176static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr,
177 struct writeback_control *wbc, 177 struct writeback_control *wbc,
178 int npages, bool is_read) 178 int npages, bool is_read,
179 enum page_type type, enum temp_type temp)
179{ 180{
180 struct bio *bio; 181 struct bio *bio;
181 182
182 bio = f2fs_bio_alloc(sbi, npages, true); 183 bio = f2fs_bio_alloc(sbi, npages, true);
183 184
184 f2fs_target_device(sbi, blk_addr, bio); 185 f2fs_target_device(sbi, blk_addr, bio);
185 bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io; 186 if (is_read) {
186 bio->bi_private = is_read ? NULL : sbi; 187 bio->bi_end_io = f2fs_read_end_io;
188 bio->bi_private = NULL;
189 } else {
190 bio->bi_end_io = f2fs_write_end_io;
191 bio->bi_private = sbi;
192 bio->bi_write_hint = io_type_to_rw_hint(sbi, type, temp);
193 }
187 if (wbc) 194 if (wbc)
188 wbc_init_bio(wbc, bio); 195 wbc_init_bio(wbc, bio);
189 196
@@ -196,13 +203,12 @@ static inline void __submit_bio(struct f2fs_sb_info *sbi,
196 if (!is_read_io(bio_op(bio))) { 203 if (!is_read_io(bio_op(bio))) {
197 unsigned int start; 204 unsigned int start;
198 205
199 if (f2fs_sb_mounted_blkzoned(sbi->sb) &&
200 current->plug && (type == DATA || type == NODE))
201 blk_finish_plug(current->plug);
202
203 if (type != DATA && type != NODE) 206 if (type != DATA && type != NODE)
204 goto submit_io; 207 goto submit_io;
205 208
209 if (f2fs_sb_has_blkzoned(sbi->sb) && current->plug)
210 blk_finish_plug(current->plug);
211
206 start = bio->bi_iter.bi_size >> F2FS_BLKSIZE_BITS; 212 start = bio->bi_iter.bi_size >> F2FS_BLKSIZE_BITS;
207 start %= F2FS_IO_SIZE(sbi); 213 start %= F2FS_IO_SIZE(sbi);
208 214
@@ -377,12 +383,13 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
377 struct page *page = fio->encrypted_page ? 383 struct page *page = fio->encrypted_page ?
378 fio->encrypted_page : fio->page; 384 fio->encrypted_page : fio->page;
379 385
386 verify_block_addr(fio, fio->new_blkaddr);
380 trace_f2fs_submit_page_bio(page, fio); 387 trace_f2fs_submit_page_bio(page, fio);
381 f2fs_trace_ios(fio, 0); 388 f2fs_trace_ios(fio, 0);
382 389
383 /* Allocate a new bio */ 390 /* Allocate a new bio */
384 bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc, 391 bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc,
385 1, is_read_io(fio->op)); 392 1, is_read_io(fio->op), fio->type, fio->temp);
386 393
387 if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { 394 if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
388 bio_put(bio); 395 bio_put(bio);
@@ -422,8 +429,8 @@ next:
422 } 429 }
423 430
424 if (fio->old_blkaddr != NEW_ADDR) 431 if (fio->old_blkaddr != NEW_ADDR)
425 verify_block_addr(sbi, fio->old_blkaddr); 432 verify_block_addr(fio, fio->old_blkaddr);
426 verify_block_addr(sbi, fio->new_blkaddr); 433 verify_block_addr(fio, fio->new_blkaddr);
427 434
428 bio_page = fio->encrypted_page ? fio->encrypted_page : fio->page; 435 bio_page = fio->encrypted_page ? fio->encrypted_page : fio->page;
429 436
@@ -445,7 +452,8 @@ alloc_new:
445 goto out_fail; 452 goto out_fail;
446 } 453 }
447 io->bio = __bio_alloc(sbi, fio->new_blkaddr, fio->io_wbc, 454 io->bio = __bio_alloc(sbi, fio->new_blkaddr, fio->io_wbc,
448 BIO_MAX_PAGES, false); 455 BIO_MAX_PAGES, false,
456 fio->type, fio->temp);
449 io->fio = *fio; 457 io->fio = *fio;
450 } 458 }
451 459
@@ -832,13 +840,6 @@ alloc:
832 return 0; 840 return 0;
833} 841}
834 842
835static inline bool __force_buffered_io(struct inode *inode, int rw)
836{
837 return (f2fs_encrypted_file(inode) ||
838 (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) ||
839 F2FS_I_SB(inode)->s_ndevs);
840}
841
842int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from) 843int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
843{ 844{
844 struct inode *inode = file_inode(iocb->ki_filp); 845 struct inode *inode = file_inode(iocb->ki_filp);
@@ -870,7 +871,7 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
870 871
871 if (direct_io) { 872 if (direct_io) {
872 map.m_seg_type = rw_hint_to_seg_type(iocb->ki_hint); 873 map.m_seg_type = rw_hint_to_seg_type(iocb->ki_hint);
873 flag = __force_buffered_io(inode, WRITE) ? 874 flag = f2fs_force_buffered_io(inode, WRITE) ?
874 F2FS_GET_BLOCK_PRE_AIO : 875 F2FS_GET_BLOCK_PRE_AIO :
875 F2FS_GET_BLOCK_PRE_DIO; 876 F2FS_GET_BLOCK_PRE_DIO;
876 goto map_blocks; 877 goto map_blocks;
@@ -1114,6 +1115,31 @@ out:
1114 return err; 1115 return err;
1115} 1116}
1116 1117
1118bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len)
1119{
1120 struct f2fs_map_blocks map;
1121 block_t last_lblk;
1122 int err;
1123
1124 if (pos + len > i_size_read(inode))
1125 return false;
1126
1127 map.m_lblk = F2FS_BYTES_TO_BLK(pos);
1128 map.m_next_pgofs = NULL;
1129 map.m_next_extent = NULL;
1130 map.m_seg_type = NO_CHECK_TYPE;
1131 last_lblk = F2FS_BLK_ALIGN(pos + len);
1132
1133 while (map.m_lblk < last_lblk) {
1134 map.m_len = last_lblk - map.m_lblk;
1135 err = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_DEFAULT);
1136 if (err || map.m_len == 0)
1137 return false;
1138 map.m_lblk += map.m_len;
1139 }
1140 return true;
1141}
1142
1117static int __get_data_block(struct inode *inode, sector_t iblock, 1143static int __get_data_block(struct inode *inode, sector_t iblock,
1118 struct buffer_head *bh, int create, int flag, 1144 struct buffer_head *bh, int create, int flag,
1119 pgoff_t *next_pgofs, int seg_type) 1145 pgoff_t *next_pgofs, int seg_type)
@@ -2287,25 +2313,41 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
2287{ 2313{
2288 struct address_space *mapping = iocb->ki_filp->f_mapping; 2314 struct address_space *mapping = iocb->ki_filp->f_mapping;
2289 struct inode *inode = mapping->host; 2315 struct inode *inode = mapping->host;
2316 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
2290 size_t count = iov_iter_count(iter); 2317 size_t count = iov_iter_count(iter);
2291 loff_t offset = iocb->ki_pos; 2318 loff_t offset = iocb->ki_pos;
2292 int rw = iov_iter_rw(iter); 2319 int rw = iov_iter_rw(iter);
2293 int err; 2320 int err;
2321 enum rw_hint hint = iocb->ki_hint;
2322 int whint_mode = F2FS_OPTION(sbi).whint_mode;
2294 2323
2295 err = check_direct_IO(inode, iter, offset); 2324 err = check_direct_IO(inode, iter, offset);
2296 if (err) 2325 if (err)
2297 return err; 2326 return err;
2298 2327
2299 if (__force_buffered_io(inode, rw)) 2328 if (f2fs_force_buffered_io(inode, rw))
2300 return 0; 2329 return 0;
2301 2330
2302 trace_f2fs_direct_IO_enter(inode, offset, count, rw); 2331 trace_f2fs_direct_IO_enter(inode, offset, count, rw);
2303 2332
2304 down_read(&F2FS_I(inode)->dio_rwsem[rw]); 2333 if (rw == WRITE && whint_mode == WHINT_MODE_OFF)
2334 iocb->ki_hint = WRITE_LIFE_NOT_SET;
2335
2336 if (!down_read_trylock(&F2FS_I(inode)->dio_rwsem[rw])) {
2337 if (iocb->ki_flags & IOCB_NOWAIT) {
2338 iocb->ki_hint = hint;
2339 err = -EAGAIN;
2340 goto out;
2341 }
2342 down_read(&F2FS_I(inode)->dio_rwsem[rw]);
2343 }
2344
2305 err = blockdev_direct_IO(iocb, inode, iter, get_data_block_dio); 2345 err = blockdev_direct_IO(iocb, inode, iter, get_data_block_dio);
2306 up_read(&F2FS_I(inode)->dio_rwsem[rw]); 2346 up_read(&F2FS_I(inode)->dio_rwsem[rw]);
2307 2347
2308 if (rw == WRITE) { 2348 if (rw == WRITE) {
2349 if (whint_mode == WHINT_MODE_OFF)
2350 iocb->ki_hint = hint;
2309 if (err > 0) { 2351 if (err > 0) {
2310 f2fs_update_iostat(F2FS_I_SB(inode), APP_DIRECT_IO, 2352 f2fs_update_iostat(F2FS_I_SB(inode), APP_DIRECT_IO,
2311 err); 2353 err);
@@ -2315,6 +2357,7 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
2315 } 2357 }
2316 } 2358 }
2317 2359
2360out:
2318 trace_f2fs_direct_IO_exit(inode, offset, count, rw, err); 2361 trace_f2fs_direct_IO_exit(inode, offset, count, rw, err);
2319 2362
2320 return err; 2363 return err;
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index f00b5ed8c011..fe661274ff10 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -94,14 +94,12 @@ static struct f2fs_dir_entry *find_in_block(struct page *dentry_page,
94 struct f2fs_dir_entry *de; 94 struct f2fs_dir_entry *de;
95 struct f2fs_dentry_ptr d; 95 struct f2fs_dentry_ptr d;
96 96
97 dentry_blk = (struct f2fs_dentry_block *)kmap(dentry_page); 97 dentry_blk = (struct f2fs_dentry_block *)page_address(dentry_page);
98 98
99 make_dentry_ptr_block(NULL, &d, dentry_blk); 99 make_dentry_ptr_block(NULL, &d, dentry_blk);
100 de = find_target_dentry(fname, namehash, max_slots, &d); 100 de = find_target_dentry(fname, namehash, max_slots, &d);
101 if (de) 101 if (de)
102 *res_page = dentry_page; 102 *res_page = dentry_page;
103 else
104 kunmap(dentry_page);
105 103
106 return de; 104 return de;
107} 105}
@@ -287,7 +285,6 @@ ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr,
287 de = f2fs_find_entry(dir, qstr, page); 285 de = f2fs_find_entry(dir, qstr, page);
288 if (de) { 286 if (de) {
289 res = le32_to_cpu(de->ino); 287 res = le32_to_cpu(de->ino);
290 f2fs_dentry_kunmap(dir, *page);
291 f2fs_put_page(*page, 0); 288 f2fs_put_page(*page, 0);
292 } 289 }
293 290
@@ -302,7 +299,6 @@ void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
302 f2fs_wait_on_page_writeback(page, type, true); 299 f2fs_wait_on_page_writeback(page, type, true);
303 de->ino = cpu_to_le32(inode->i_ino); 300 de->ino = cpu_to_le32(inode->i_ino);
304 set_de_type(de, inode->i_mode); 301 set_de_type(de, inode->i_mode);
305 f2fs_dentry_kunmap(dir, page);
306 set_page_dirty(page); 302 set_page_dirty(page);
307 303
308 dir->i_mtime = dir->i_ctime = current_time(dir); 304 dir->i_mtime = dir->i_ctime = current_time(dir);
@@ -350,13 +346,11 @@ static int make_empty_dir(struct inode *inode,
350 if (IS_ERR(dentry_page)) 346 if (IS_ERR(dentry_page))
351 return PTR_ERR(dentry_page); 347 return PTR_ERR(dentry_page);
352 348
353 dentry_blk = kmap_atomic(dentry_page); 349 dentry_blk = page_address(dentry_page);
354 350
355 make_dentry_ptr_block(NULL, &d, dentry_blk); 351 make_dentry_ptr_block(NULL, &d, dentry_blk);
356 do_make_empty_dir(inode, parent, &d); 352 do_make_empty_dir(inode, parent, &d);
357 353
358 kunmap_atomic(dentry_blk);
359
360 set_page_dirty(dentry_page); 354 set_page_dirty(dentry_page);
361 f2fs_put_page(dentry_page, 1); 355 f2fs_put_page(dentry_page, 1);
362 return 0; 356 return 0;
@@ -367,6 +361,7 @@ struct page *init_inode_metadata(struct inode *inode, struct inode *dir,
367 struct page *dpage) 361 struct page *dpage)
368{ 362{
369 struct page *page; 363 struct page *page;
364 int dummy_encrypt = DUMMY_ENCRYPTION_ENABLED(F2FS_I_SB(dir));
370 int err; 365 int err;
371 366
372 if (is_inode_flag_set(inode, FI_NEW_INODE)) { 367 if (is_inode_flag_set(inode, FI_NEW_INODE)) {
@@ -393,7 +388,8 @@ struct page *init_inode_metadata(struct inode *inode, struct inode *dir,
393 if (err) 388 if (err)
394 goto put_error; 389 goto put_error;
395 390
396 if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode)) { 391 if ((f2fs_encrypted_inode(dir) || dummy_encrypt) &&
392 f2fs_may_encrypt(inode)) {
397 err = fscrypt_inherit_context(dir, inode, page, false); 393 err = fscrypt_inherit_context(dir, inode, page, false);
398 if (err) 394 if (err)
399 goto put_error; 395 goto put_error;
@@ -402,8 +398,6 @@ struct page *init_inode_metadata(struct inode *inode, struct inode *dir,
402 page = get_node_page(F2FS_I_SB(dir), inode->i_ino); 398 page = get_node_page(F2FS_I_SB(dir), inode->i_ino);
403 if (IS_ERR(page)) 399 if (IS_ERR(page))
404 return page; 400 return page;
405
406 set_cold_node(inode, page);
407 } 401 }
408 402
409 if (new_name) { 403 if (new_name) {
@@ -547,13 +541,12 @@ start:
547 if (IS_ERR(dentry_page)) 541 if (IS_ERR(dentry_page))
548 return PTR_ERR(dentry_page); 542 return PTR_ERR(dentry_page);
549 543
550 dentry_blk = kmap(dentry_page); 544 dentry_blk = page_address(dentry_page);
551 bit_pos = room_for_filename(&dentry_blk->dentry_bitmap, 545 bit_pos = room_for_filename(&dentry_blk->dentry_bitmap,
552 slots, NR_DENTRY_IN_BLOCK); 546 slots, NR_DENTRY_IN_BLOCK);
553 if (bit_pos < NR_DENTRY_IN_BLOCK) 547 if (bit_pos < NR_DENTRY_IN_BLOCK)
554 goto add_dentry; 548 goto add_dentry;
555 549
556 kunmap(dentry_page);
557 f2fs_put_page(dentry_page, 1); 550 f2fs_put_page(dentry_page, 1);
558 } 551 }
559 552
@@ -588,7 +581,6 @@ fail:
588 if (inode) 581 if (inode)
589 up_write(&F2FS_I(inode)->i_sem); 582 up_write(&F2FS_I(inode)->i_sem);
590 583
591 kunmap(dentry_page);
592 f2fs_put_page(dentry_page, 1); 584 f2fs_put_page(dentry_page, 1);
593 585
594 return err; 586 return err;
@@ -642,7 +634,6 @@ int __f2fs_add_link(struct inode *dir, const struct qstr *name,
642 F2FS_I(dir)->task = NULL; 634 F2FS_I(dir)->task = NULL;
643 } 635 }
644 if (de) { 636 if (de) {
645 f2fs_dentry_kunmap(dir, page);
646 f2fs_put_page(page, 0); 637 f2fs_put_page(page, 0);
647 err = -EEXIST; 638 err = -EEXIST;
648 } else if (IS_ERR(page)) { 639 } else if (IS_ERR(page)) {
@@ -713,7 +704,8 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
713 704
714 f2fs_update_time(F2FS_I_SB(dir), REQ_TIME); 705 f2fs_update_time(F2FS_I_SB(dir), REQ_TIME);
715 706
716 add_ino_entry(F2FS_I_SB(dir), dir->i_ino, TRANS_DIR_INO); 707 if (F2FS_OPTION(F2FS_I_SB(dir)).fsync_mode == FSYNC_MODE_STRICT)
708 add_ino_entry(F2FS_I_SB(dir), dir->i_ino, TRANS_DIR_INO);
717 709
718 if (f2fs_has_inline_dentry(dir)) 710 if (f2fs_has_inline_dentry(dir))
719 return f2fs_delete_inline_entry(dentry, page, dir, inode); 711 return f2fs_delete_inline_entry(dentry, page, dir, inode);
@@ -730,7 +722,6 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
730 bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap, 722 bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap,
731 NR_DENTRY_IN_BLOCK, 723 NR_DENTRY_IN_BLOCK,
732 0); 724 0);
733 kunmap(page); /* kunmap - pair of f2fs_find_entry */
734 set_page_dirty(page); 725 set_page_dirty(page);
735 726
736 dir->i_ctime = dir->i_mtime = current_time(dir); 727 dir->i_ctime = dir->i_mtime = current_time(dir);
@@ -775,7 +766,7 @@ bool f2fs_empty_dir(struct inode *dir)
775 return false; 766 return false;
776 } 767 }
777 768
778 dentry_blk = kmap_atomic(dentry_page); 769 dentry_blk = page_address(dentry_page);
779 if (bidx == 0) 770 if (bidx == 0)
780 bit_pos = 2; 771 bit_pos = 2;
781 else 772 else
@@ -783,7 +774,6 @@ bool f2fs_empty_dir(struct inode *dir)
783 bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap, 774 bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap,
784 NR_DENTRY_IN_BLOCK, 775 NR_DENTRY_IN_BLOCK,
785 bit_pos); 776 bit_pos);
786 kunmap_atomic(dentry_blk);
787 777
788 f2fs_put_page(dentry_page, 1); 778 f2fs_put_page(dentry_page, 1);
789 779
@@ -901,19 +891,17 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
901 } 891 }
902 } 892 }
903 893
904 dentry_blk = kmap(dentry_page); 894 dentry_blk = page_address(dentry_page);
905 895
906 make_dentry_ptr_block(inode, &d, dentry_blk); 896 make_dentry_ptr_block(inode, &d, dentry_blk);
907 897
908 err = f2fs_fill_dentries(ctx, &d, 898 err = f2fs_fill_dentries(ctx, &d,
909 n * NR_DENTRY_IN_BLOCK, &fstr); 899 n * NR_DENTRY_IN_BLOCK, &fstr);
910 if (err) { 900 if (err) {
911 kunmap(dentry_page);
912 f2fs_put_page(dentry_page, 1); 901 f2fs_put_page(dentry_page, 1);
913 break; 902 break;
914 } 903 }
915 904
916 kunmap(dentry_page);
917 f2fs_put_page(dentry_page, 1); 905 f2fs_put_page(dentry_page, 1);
918 } 906 }
919out_free: 907out_free:
diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index ff2352a0ed15..d5a861bf2b42 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -460,7 +460,7 @@ static struct extent_node *__insert_extent_tree(struct inode *inode,
460 struct rb_node *insert_parent) 460 struct rb_node *insert_parent)
461{ 461{
462 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 462 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
463 struct rb_node **p = &et->root.rb_node; 463 struct rb_node **p;
464 struct rb_node *parent = NULL; 464 struct rb_node *parent = NULL;
465 struct extent_node *en = NULL; 465 struct extent_node *en = NULL;
466 466
@@ -706,6 +706,9 @@ void f2fs_drop_extent_tree(struct inode *inode)
706 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 706 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
707 struct extent_tree *et = F2FS_I(inode)->extent_tree; 707 struct extent_tree *et = F2FS_I(inode)->extent_tree;
708 708
709 if (!f2fs_may_extent_tree(inode))
710 return;
711
709 set_inode_flag(inode, FI_NO_EXTENT); 712 set_inode_flag(inode, FI_NO_EXTENT);
710 713
711 write_lock(&et->lock); 714 write_lock(&et->lock);
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 6300ac5bcbe4..1df7f10476d6 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -98,9 +98,10 @@ extern char *fault_name[FAULT_MAX];
98#define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 98#define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000
99#define F2FS_MOUNT_RESERVE_ROOT 0x01000000 99#define F2FS_MOUNT_RESERVE_ROOT 0x01000000
100 100
101#define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option) 101#define F2FS_OPTION(sbi) ((sbi)->mount_opt)
102#define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option) 102#define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option)
103#define test_opt(sbi, option) ((sbi)->mount_opt.opt & F2FS_MOUNT_##option) 103#define set_opt(sbi, option) (F2FS_OPTION(sbi).opt |= F2FS_MOUNT_##option)
104#define test_opt(sbi, option) (F2FS_OPTION(sbi).opt & F2FS_MOUNT_##option)
104 105
105#define ver_after(a, b) (typecheck(unsigned long long, a) && \ 106#define ver_after(a, b) (typecheck(unsigned long long, a) && \
106 typecheck(unsigned long long, b) && \ 107 typecheck(unsigned long long, b) && \
@@ -113,7 +114,26 @@ typedef u32 block_t; /*
113typedef u32 nid_t; 114typedef u32 nid_t;
114 115
115struct f2fs_mount_info { 116struct f2fs_mount_info {
116 unsigned int opt; 117 unsigned int opt;
118 int write_io_size_bits; /* Write IO size bits */
119 block_t root_reserved_blocks; /* root reserved blocks */
120 kuid_t s_resuid; /* reserved blocks for uid */
121 kgid_t s_resgid; /* reserved blocks for gid */
122 int active_logs; /* # of active logs */
123 int inline_xattr_size; /* inline xattr size */
124#ifdef CONFIG_F2FS_FAULT_INJECTION
125 struct f2fs_fault_info fault_info; /* For fault injection */
126#endif
127#ifdef CONFIG_QUOTA
128 /* Names of quota files with journalled quota */
129 char *s_qf_names[MAXQUOTAS];
130 int s_jquota_fmt; /* Format of quota to use */
131#endif
132 /* For which write hints are passed down to block layer */
133 int whint_mode;
134 int alloc_mode; /* segment allocation policy */
135 int fsync_mode; /* fsync policy */
136 bool test_dummy_encryption; /* test dummy encryption */
117}; 137};
118 138
119#define F2FS_FEATURE_ENCRYPT 0x0001 139#define F2FS_FEATURE_ENCRYPT 0x0001
@@ -125,6 +145,8 @@ struct f2fs_mount_info {
125#define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 145#define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040
126#define F2FS_FEATURE_QUOTA_INO 0x0080 146#define F2FS_FEATURE_QUOTA_INO 0x0080
127#define F2FS_FEATURE_INODE_CRTIME 0x0100 147#define F2FS_FEATURE_INODE_CRTIME 0x0100
148#define F2FS_FEATURE_LOST_FOUND 0x0200
149#define F2FS_FEATURE_VERITY 0x0400 /* reserved */
128 150
129#define F2FS_HAS_FEATURE(sb, mask) \ 151#define F2FS_HAS_FEATURE(sb, mask) \
130 ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 152 ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -450,7 +472,7 @@ static inline void make_dentry_ptr_block(struct inode *inode,
450 d->inode = inode; 472 d->inode = inode;
451 d->max = NR_DENTRY_IN_BLOCK; 473 d->max = NR_DENTRY_IN_BLOCK;
452 d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; 474 d->nr_bitmap = SIZE_OF_DENTRY_BITMAP;
453 d->bitmap = &t->dentry_bitmap; 475 d->bitmap = t->dentry_bitmap;
454 d->dentry = t->dentry; 476 d->dentry = t->dentry;
455 d->filename = t->filename; 477 d->filename = t->filename;
456} 478}
@@ -576,6 +598,8 @@ enum {
576#define FADVISE_ENCRYPT_BIT 0x04 598#define FADVISE_ENCRYPT_BIT 0x04
577#define FADVISE_ENC_NAME_BIT 0x08 599#define FADVISE_ENC_NAME_BIT 0x08
578#define FADVISE_KEEP_SIZE_BIT 0x10 600#define FADVISE_KEEP_SIZE_BIT 0x10
601#define FADVISE_HOT_BIT 0x20
602#define FADVISE_VERITY_BIT 0x40 /* reserved */
579 603
580#define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 604#define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT)
581#define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 605#define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT)
@@ -590,6 +614,9 @@ enum {
590#define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 614#define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
591#define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 615#define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT)
592#define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 616#define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT)
617#define file_is_hot(inode) is_file(inode, FADVISE_HOT_BIT)
618#define file_set_hot(inode) set_file(inode, FADVISE_HOT_BIT)
619#define file_clear_hot(inode) clear_file(inode, FADVISE_HOT_BIT)
593 620
594#define DEF_DIR_LEVEL 0 621#define DEF_DIR_LEVEL 0
595 622
@@ -637,6 +664,7 @@ struct f2fs_inode_info {
637 kprojid_t i_projid; /* id for project quota */ 664 kprojid_t i_projid; /* id for project quota */
638 int i_inline_xattr_size; /* inline xattr size */ 665 int i_inline_xattr_size; /* inline xattr size */
639 struct timespec i_crtime; /* inode creation time */ 666 struct timespec i_crtime; /* inode creation time */
667 struct timespec i_disk_time[4]; /* inode disk times */
640}; 668};
641 669
642static inline void get_extent_info(struct extent_info *ext, 670static inline void get_extent_info(struct extent_info *ext,
@@ -743,7 +771,7 @@ struct f2fs_nm_info {
743 unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ 771 unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */
744 spinlock_t nid_list_lock; /* protect nid lists ops */ 772 spinlock_t nid_list_lock; /* protect nid lists ops */
745 struct mutex build_lock; /* lock for build free nids */ 773 struct mutex build_lock; /* lock for build free nids */
746 unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 774 unsigned char **free_nid_bitmap;
747 unsigned char *nat_block_bitmap; 775 unsigned char *nat_block_bitmap;
748 unsigned short *free_nid_count; /* free nid count of NAT block */ 776 unsigned short *free_nid_count; /* free nid count of NAT block */
749 777
@@ -976,6 +1004,7 @@ struct f2fs_io_info {
976 bool submitted; /* indicate IO submission */ 1004 bool submitted; /* indicate IO submission */
977 int need_lock; /* indicate we need to lock cp_rwsem */ 1005 int need_lock; /* indicate we need to lock cp_rwsem */
978 bool in_list; /* indicate fio is in io_list */ 1006 bool in_list; /* indicate fio is in io_list */
1007 bool is_meta; /* indicate borrow meta inode mapping or not */
979 enum iostat_type io_type; /* io type */ 1008 enum iostat_type io_type; /* io type */
980 struct writeback_control *io_wbc; /* writeback control */ 1009 struct writeback_control *io_wbc; /* writeback control */
981}; 1010};
@@ -1037,10 +1066,34 @@ enum {
1037 MAX_TIME, 1066 MAX_TIME,
1038}; 1067};
1039 1068
1069enum {
1070 WHINT_MODE_OFF, /* not pass down write hints */
1071 WHINT_MODE_USER, /* try to pass down hints given by users */
1072 WHINT_MODE_FS, /* pass down hints with F2FS policy */
1073};
1074
1075enum {
1076 ALLOC_MODE_DEFAULT, /* stay default */
1077 ALLOC_MODE_REUSE, /* reuse segments as much as possible */
1078};
1079
1080enum fsync_mode {
1081 FSYNC_MODE_POSIX, /* fsync follows posix semantics */
1082 FSYNC_MODE_STRICT, /* fsync behaves in line with ext4 */
1083};
1084
1085#ifdef CONFIG_F2FS_FS_ENCRYPTION
1086#define DUMMY_ENCRYPTION_ENABLED(sbi) \
1087 (unlikely(F2FS_OPTION(sbi).test_dummy_encryption))
1088#else
1089#define DUMMY_ENCRYPTION_ENABLED(sbi) (0)
1090#endif
1091
1040struct f2fs_sb_info { 1092struct f2fs_sb_info {
1041 struct super_block *sb; /* pointer to VFS super block */ 1093 struct super_block *sb; /* pointer to VFS super block */
1042 struct proc_dir_entry *s_proc; /* proc entry */ 1094 struct proc_dir_entry *s_proc; /* proc entry */
1043 struct f2fs_super_block *raw_super; /* raw super block pointer */ 1095 struct f2fs_super_block *raw_super; /* raw super block pointer */
1096 struct rw_semaphore sb_lock; /* lock for raw super block */
1044 int valid_super_block; /* valid super block no */ 1097 int valid_super_block; /* valid super block no */
1045 unsigned long s_flag; /* flags for sbi */ 1098 unsigned long s_flag; /* flags for sbi */
1046 1099
@@ -1060,7 +1113,6 @@ struct f2fs_sb_info {
1060 struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 1113 struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */
1061 struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE]; 1114 struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE];
1062 /* bio ordering for NODE/DATA */ 1115 /* bio ordering for NODE/DATA */
1063 int write_io_size_bits; /* Write IO size bits */
1064 mempool_t *write_io_dummy; /* Dummy pages */ 1116 mempool_t *write_io_dummy; /* Dummy pages */
1065 1117
1066 /* for checkpoint */ 1118 /* for checkpoint */
@@ -1110,9 +1162,7 @@ struct f2fs_sb_info {
1110 unsigned int total_node_count; /* total node block count */ 1162 unsigned int total_node_count; /* total node block count */
1111 unsigned int total_valid_node_count; /* valid node block count */ 1163 unsigned int total_valid_node_count; /* valid node block count */
1112 loff_t max_file_blocks; /* max block index of file */ 1164 loff_t max_file_blocks; /* max block index of file */
1113 int active_logs; /* # of active logs */
1114 int dir_level; /* directory level */ 1165 int dir_level; /* directory level */
1115 int inline_xattr_size; /* inline xattr size */
1116 unsigned int trigger_ssr_threshold; /* threshold to trigger ssr */ 1166 unsigned int trigger_ssr_threshold; /* threshold to trigger ssr */
1117 int readdir_ra; /* readahead inode in readdir */ 1167 int readdir_ra; /* readahead inode in readdir */
1118 1168
@@ -1122,9 +1172,6 @@ struct f2fs_sb_info {
1122 block_t last_valid_block_count; /* for recovery */ 1172 block_t last_valid_block_count; /* for recovery */
1123 block_t reserved_blocks; /* configurable reserved blocks */ 1173 block_t reserved_blocks; /* configurable reserved blocks */
1124 block_t current_reserved_blocks; /* current reserved blocks */ 1174 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 1175
1129 unsigned int nquota_files; /* # of quota sysfile */ 1176 unsigned int nquota_files; /* # of quota sysfile */
1130 1177
@@ -1209,17 +1256,6 @@ struct f2fs_sb_info {
1209 1256
1210 /* Precomputed FS UUID checksum for seeding other checksums */ 1257 /* Precomputed FS UUID checksum for seeding other checksums */
1211 __u32 s_chksum_seed; 1258 __u32 s_chksum_seed;
1212
1213 /* For fault injection */
1214#ifdef CONFIG_F2FS_FAULT_INJECTION
1215 struct f2fs_fault_info fault_info;
1216#endif
1217
1218#ifdef CONFIG_QUOTA
1219 /* Names of quota files with journalled quota */
1220 char *s_qf_names[MAXQUOTAS];
1221 int s_jquota_fmt; /* Format of quota to use */
1222#endif
1223}; 1259};
1224 1260
1225#ifdef CONFIG_F2FS_FAULT_INJECTION 1261#ifdef CONFIG_F2FS_FAULT_INJECTION
@@ -1229,7 +1265,7 @@ struct f2fs_sb_info {
1229 __func__, __builtin_return_address(0)) 1265 __func__, __builtin_return_address(0))
1230static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 1266static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
1231{ 1267{
1232 struct f2fs_fault_info *ffi = &sbi->fault_info; 1268 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
1233 1269
1234 if (!ffi->inject_rate) 1270 if (!ffi->inject_rate)
1235 return false; 1271 return false;
@@ -1586,12 +1622,12 @@ static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi,
1586 return false; 1622 return false;
1587 if (IS_NOQUOTA(inode)) 1623 if (IS_NOQUOTA(inode))
1588 return true; 1624 return true;
1589 if (capable(CAP_SYS_RESOURCE)) 1625 if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid()))
1590 return true; 1626 return true;
1591 if (uid_eq(sbi->s_resuid, current_fsuid())) 1627 if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) &&
1628 in_group_p(F2FS_OPTION(sbi).s_resgid))
1592 return true; 1629 return true;
1593 if (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && 1630 if (capable(CAP_SYS_RESOURCE))
1594 in_group_p(sbi->s_resgid))
1595 return true; 1631 return true;
1596 return false; 1632 return false;
1597} 1633}
@@ -1627,7 +1663,7 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
1627 sbi->current_reserved_blocks; 1663 sbi->current_reserved_blocks;
1628 1664
1629 if (!__allow_reserved_blocks(sbi, inode)) 1665 if (!__allow_reserved_blocks(sbi, inode))
1630 avail_user_block_count -= sbi->root_reserved_blocks; 1666 avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks;
1631 1667
1632 if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 1668 if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
1633 diff = sbi->total_valid_block_count - avail_user_block_count; 1669 diff = sbi->total_valid_block_count - avail_user_block_count;
@@ -1762,6 +1798,12 @@ static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
1762 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1798 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1763 int offset; 1799 int offset;
1764 1800
1801 if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) {
1802 offset = (flag == SIT_BITMAP) ?
1803 le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0;
1804 return &ckpt->sit_nat_version_bitmap + offset;
1805 }
1806
1765 if (__cp_payload(sbi) > 0) { 1807 if (__cp_payload(sbi) > 0) {
1766 if (flag == NAT_BITMAP) 1808 if (flag == NAT_BITMAP)
1767 return &ckpt->sit_nat_version_bitmap; 1809 return &ckpt->sit_nat_version_bitmap;
@@ -1828,7 +1870,7 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
1828 sbi->current_reserved_blocks + 1; 1870 sbi->current_reserved_blocks + 1;
1829 1871
1830 if (!__allow_reserved_blocks(sbi, inode)) 1872 if (!__allow_reserved_blocks(sbi, inode))
1831 valid_block_count += sbi->root_reserved_blocks; 1873 valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks;
1832 1874
1833 if (unlikely(valid_block_count > sbi->user_block_count)) { 1875 if (unlikely(valid_block_count > sbi->user_block_count)) {
1834 spin_unlock(&sbi->stat_lock); 1876 spin_unlock(&sbi->stat_lock);
@@ -2399,12 +2441,6 @@ static inline int f2fs_has_inline_dentry(struct inode *inode)
2399 return is_inode_flag_set(inode, FI_INLINE_DENTRY); 2441 return is_inode_flag_set(inode, FI_INLINE_DENTRY);
2400} 2442}
2401 2443
2402static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page)
2403{
2404 if (!f2fs_has_inline_dentry(dir))
2405 kunmap(page);
2406}
2407
2408static inline int is_file(struct inode *inode, int type) 2444static inline int is_file(struct inode *inode, int type)
2409{ 2445{
2410 return F2FS_I(inode)->i_advise & type; 2446 return F2FS_I(inode)->i_advise & type;
@@ -2436,7 +2472,17 @@ static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
2436 } 2472 }
2437 if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 2473 if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) ||
2438 file_keep_isize(inode) || 2474 file_keep_isize(inode) ||
2439 i_size_read(inode) & PAGE_MASK) 2475 i_size_read(inode) & ~PAGE_MASK)
2476 return false;
2477
2478 if (!timespec_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime))
2479 return false;
2480 if (!timespec_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime))
2481 return false;
2482 if (!timespec_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime))
2483 return false;
2484 if (!timespec_equal(F2FS_I(inode)->i_disk_time + 3,
2485 &F2FS_I(inode)->i_crtime))
2440 return false; 2486 return false;
2441 2487
2442 down_read(&F2FS_I(inode)->i_sem); 2488 down_read(&F2FS_I(inode)->i_sem);
@@ -2446,9 +2492,9 @@ static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
2446 return ret; 2492 return ret;
2447} 2493}
2448 2494
2449static inline int f2fs_readonly(struct super_block *sb) 2495static inline bool f2fs_readonly(struct super_block *sb)
2450{ 2496{
2451 return sb->s_flags & SB_RDONLY; 2497 return sb_rdonly(sb);
2452} 2498}
2453 2499
2454static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 2500static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
@@ -2596,6 +2642,8 @@ void handle_failed_inode(struct inode *inode);
2596/* 2642/*
2597 * namei.c 2643 * namei.c
2598 */ 2644 */
2645int update_extension_list(struct f2fs_sb_info *sbi, const char *name,
2646 bool hot, bool set);
2599struct dentry *f2fs_get_parent(struct dentry *child); 2647struct dentry *f2fs_get_parent(struct dentry *child);
2600 2648
2601/* 2649/*
@@ -2768,6 +2816,8 @@ void destroy_segment_manager(struct f2fs_sb_info *sbi);
2768int __init create_segment_manager_caches(void); 2816int __init create_segment_manager_caches(void);
2769void destroy_segment_manager_caches(void); 2817void destroy_segment_manager_caches(void);
2770int rw_hint_to_seg_type(enum rw_hint hint); 2818int rw_hint_to_seg_type(enum rw_hint hint);
2819enum rw_hint io_type_to_rw_hint(struct f2fs_sb_info *sbi, enum page_type type,
2820 enum temp_type temp);
2771 2821
2772/* 2822/*
2773 * checkpoint.c 2823 * checkpoint.c
@@ -2850,6 +2900,7 @@ int f2fs_release_page(struct page *page, gfp_t wait);
2850int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2900int f2fs_migrate_page(struct address_space *mapping, struct page *newpage,
2851 struct page *page, enum migrate_mode mode); 2901 struct page *page, enum migrate_mode mode);
2852#endif 2902#endif
2903bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len);
2853 2904
2854/* 2905/*
2855 * gc.c 2906 * gc.c
@@ -3172,45 +3223,21 @@ static inline bool f2fs_bio_encrypted(struct bio *bio)
3172 return bio->bi_private != NULL; 3223 return bio->bi_private != NULL;
3173} 3224}
3174 3225
3175static inline int f2fs_sb_has_crypto(struct super_block *sb) 3226#define F2FS_FEATURE_FUNCS(name, flagname) \
3176{ 3227static inline int f2fs_sb_has_##name(struct super_block *sb) \
3177 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 3228{ \
3178} 3229 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_##flagname); \
3179
3180static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb)
3181{
3182 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED);
3183}
3184
3185static inline int f2fs_sb_has_extra_attr(struct super_block *sb)
3186{
3187 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_EXTRA_ATTR);
3188}
3189
3190static inline int f2fs_sb_has_project_quota(struct super_block *sb)
3191{
3192 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_PRJQUOTA);
3193}
3194
3195static inline int f2fs_sb_has_inode_chksum(struct super_block *sb)
3196{
3197 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_INODE_CHKSUM);
3198}
3199
3200static inline int f2fs_sb_has_flexible_inline_xattr(struct super_block *sb)
3201{
3202 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_FLEXIBLE_INLINE_XATTR);
3203}
3204
3205static inline int f2fs_sb_has_quota_ino(struct super_block *sb)
3206{
3207 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_QUOTA_INO);
3208} 3230}
3209 3231
3210static inline int f2fs_sb_has_inode_crtime(struct super_block *sb) 3232F2FS_FEATURE_FUNCS(encrypt, ENCRYPT);
3211{ 3233F2FS_FEATURE_FUNCS(blkzoned, BLKZONED);
3212 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_INODE_CRTIME); 3234F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR);
3213} 3235F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA);
3236F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM);
3237F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR);
3238F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO);
3239F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME);
3240F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND);
3214 3241
3215#ifdef CONFIG_BLK_DEV_ZONED 3242#ifdef CONFIG_BLK_DEV_ZONED
3216static inline int get_blkz_type(struct f2fs_sb_info *sbi, 3243static inline int get_blkz_type(struct f2fs_sb_info *sbi,
@@ -3230,7 +3257,7 @@ static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi)
3230{ 3257{
3231 struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 3258 struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev);
3232 3259
3233 return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 3260 return blk_queue_discard(q) || f2fs_sb_has_blkzoned(sbi->sb);
3234} 3261}
3235 3262
3236static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 3263static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt)
@@ -3259,4 +3286,11 @@ static inline bool f2fs_may_encrypt(struct inode *inode)
3259#endif 3286#endif
3260} 3287}
3261 3288
3289static inline bool f2fs_force_buffered_io(struct inode *inode, int rw)
3290{
3291 return (f2fs_encrypted_file(inode) ||
3292 (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) ||
3293 F2FS_I_SB(inode)->s_ndevs);
3294}
3295
3262#endif 3296#endif
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 672a542e5464..6b94f19b3fa8 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -163,9 +163,10 @@ static inline enum cp_reason_type need_do_checkpoint(struct inode *inode)
163 cp_reason = CP_NODE_NEED_CP; 163 cp_reason = CP_NODE_NEED_CP;
164 else if (test_opt(sbi, FASTBOOT)) 164 else if (test_opt(sbi, FASTBOOT))
165 cp_reason = CP_FASTBOOT_MODE; 165 cp_reason = CP_FASTBOOT_MODE;
166 else if (sbi->active_logs == 2) 166 else if (F2FS_OPTION(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) && 168 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT &&
169 need_dentry_mark(sbi, inode->i_ino) &&
169 exist_written_data(sbi, F2FS_I(inode)->i_pino, TRANS_DIR_INO)) 170 exist_written_data(sbi, F2FS_I(inode)->i_pino, TRANS_DIR_INO))
170 cp_reason = CP_RECOVER_DIR; 171 cp_reason = CP_RECOVER_DIR;
171 172
@@ -479,6 +480,9 @@ static int f2fs_file_open(struct inode *inode, struct file *filp)
479 480
480 if (err) 481 if (err)
481 return err; 482 return err;
483
484 filp->f_mode |= FMODE_NOWAIT;
485
482 return dquot_file_open(inode, filp); 486 return dquot_file_open(inode, filp);
483} 487}
484 488
@@ -569,7 +573,6 @@ truncate_out:
569int truncate_blocks(struct inode *inode, u64 from, bool lock) 573int truncate_blocks(struct inode *inode, u64 from, bool lock)
570{ 574{
571 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 575 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
572 unsigned int blocksize = inode->i_sb->s_blocksize;
573 struct dnode_of_data dn; 576 struct dnode_of_data dn;
574 pgoff_t free_from; 577 pgoff_t free_from;
575 int count = 0, err = 0; 578 int count = 0, err = 0;
@@ -578,7 +581,7 @@ int truncate_blocks(struct inode *inode, u64 from, bool lock)
578 581
579 trace_f2fs_truncate_blocks_enter(inode, from); 582 trace_f2fs_truncate_blocks_enter(inode, from);
580 583
581 free_from = (pgoff_t)F2FS_BYTES_TO_BLK(from + blocksize - 1); 584 free_from = (pgoff_t)F2FS_BLK_ALIGN(from);
582 585
583 if (free_from >= sbi->max_file_blocks) 586 if (free_from >= sbi->max_file_blocks)
584 goto free_partial; 587 goto free_partial;
@@ -1348,8 +1351,12 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
1348 } 1351 }
1349 1352
1350out: 1353out:
1351 if (!(mode & FALLOC_FL_KEEP_SIZE) && i_size_read(inode) < new_size) 1354 if (new_size > i_size_read(inode)) {
1352 f2fs_i_size_write(inode, new_size); 1355 if (mode & FALLOC_FL_KEEP_SIZE)
1356 file_set_keep_isize(inode);
1357 else
1358 f2fs_i_size_write(inode, new_size);
1359 }
1353out_sem: 1360out_sem:
1354 up_write(&F2FS_I(inode)->i_mmap_sem); 1361 up_write(&F2FS_I(inode)->i_mmap_sem);
1355 1362
@@ -1711,6 +1718,8 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp)
1711 1718
1712 inode_lock(inode); 1719 inode_lock(inode);
1713 1720
1721 down_write(&F2FS_I(inode)->dio_rwsem[WRITE]);
1722
1714 if (f2fs_is_volatile_file(inode)) 1723 if (f2fs_is_volatile_file(inode))
1715 goto err_out; 1724 goto err_out;
1716 1725
@@ -1729,6 +1738,7 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp)
1729 ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 1, false); 1738 ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 1, false);
1730 } 1739 }
1731err_out: 1740err_out:
1741 up_write(&F2FS_I(inode)->dio_rwsem[WRITE]);
1732 inode_unlock(inode); 1742 inode_unlock(inode);
1733 mnt_drop_write_file(filp); 1743 mnt_drop_write_file(filp);
1734 return ret; 1744 return ret;
@@ -1938,7 +1948,7 @@ static int f2fs_ioc_set_encryption_policy(struct file *filp, unsigned long arg)
1938{ 1948{
1939 struct inode *inode = file_inode(filp); 1949 struct inode *inode = file_inode(filp);
1940 1950
1941 if (!f2fs_sb_has_crypto(inode->i_sb)) 1951 if (!f2fs_sb_has_encrypt(inode->i_sb))
1942 return -EOPNOTSUPP; 1952 return -EOPNOTSUPP;
1943 1953
1944 f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); 1954 f2fs_update_time(F2FS_I_SB(inode), REQ_TIME);
@@ -1948,7 +1958,7 @@ static int f2fs_ioc_set_encryption_policy(struct file *filp, unsigned long arg)
1948 1958
1949static int f2fs_ioc_get_encryption_policy(struct file *filp, unsigned long arg) 1959static int f2fs_ioc_get_encryption_policy(struct file *filp, unsigned long arg)
1950{ 1960{
1951 if (!f2fs_sb_has_crypto(file_inode(filp)->i_sb)) 1961 if (!f2fs_sb_has_encrypt(file_inode(filp)->i_sb))
1952 return -EOPNOTSUPP; 1962 return -EOPNOTSUPP;
1953 return fscrypt_ioctl_get_policy(filp, (void __user *)arg); 1963 return fscrypt_ioctl_get_policy(filp, (void __user *)arg);
1954} 1964}
@@ -1959,16 +1969,18 @@ static int f2fs_ioc_get_encryption_pwsalt(struct file *filp, unsigned long arg)
1959 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 1969 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1960 int err; 1970 int err;
1961 1971
1962 if (!f2fs_sb_has_crypto(inode->i_sb)) 1972 if (!f2fs_sb_has_encrypt(inode->i_sb))
1963 return -EOPNOTSUPP; 1973 return -EOPNOTSUPP;
1964 1974
1965 if (uuid_is_nonzero(sbi->raw_super->encrypt_pw_salt))
1966 goto got_it;
1967
1968 err = mnt_want_write_file(filp); 1975 err = mnt_want_write_file(filp);
1969 if (err) 1976 if (err)
1970 return err; 1977 return err;
1971 1978
1979 down_write(&sbi->sb_lock);
1980
1981 if (uuid_is_nonzero(sbi->raw_super->encrypt_pw_salt))
1982 goto got_it;
1983
1972 /* update superblock with uuid */ 1984 /* update superblock with uuid */
1973 generate_random_uuid(sbi->raw_super->encrypt_pw_salt); 1985 generate_random_uuid(sbi->raw_super->encrypt_pw_salt);
1974 1986
@@ -1976,15 +1988,16 @@ static int f2fs_ioc_get_encryption_pwsalt(struct file *filp, unsigned long arg)
1976 if (err) { 1988 if (err) {
1977 /* undo new data */ 1989 /* undo new data */
1978 memset(sbi->raw_super->encrypt_pw_salt, 0, 16); 1990 memset(sbi->raw_super->encrypt_pw_salt, 0, 16);
1979 mnt_drop_write_file(filp); 1991 goto out_err;
1980 return err;
1981 } 1992 }
1982 mnt_drop_write_file(filp);
1983got_it: 1993got_it:
1984 if (copy_to_user((__u8 __user *)arg, sbi->raw_super->encrypt_pw_salt, 1994 if (copy_to_user((__u8 __user *)arg, sbi->raw_super->encrypt_pw_salt,
1985 16)) 1995 16))
1986 return -EFAULT; 1996 err = -EFAULT;
1987 return 0; 1997out_err:
1998 up_write(&sbi->sb_lock);
1999 mnt_drop_write_file(filp);
2000 return err;
1988} 2001}
1989 2002
1990static int f2fs_ioc_gc(struct file *filp, unsigned long arg) 2003static int f2fs_ioc_gc(struct file *filp, unsigned long arg)
@@ -2045,8 +2058,10 @@ static int f2fs_ioc_gc_range(struct file *filp, unsigned long arg)
2045 return ret; 2058 return ret;
2046 2059
2047 end = range.start + range.len; 2060 end = range.start + range.len;
2048 if (range.start < MAIN_BLKADDR(sbi) || end >= MAX_BLKADDR(sbi)) 2061 if (range.start < MAIN_BLKADDR(sbi) || end >= MAX_BLKADDR(sbi)) {
2049 return -EINVAL; 2062 ret = -EINVAL;
2063 goto out;
2064 }
2050do_more: 2065do_more:
2051 if (!range.sync) { 2066 if (!range.sync) {
2052 if (!mutex_trylock(&sbi->gc_mutex)) { 2067 if (!mutex_trylock(&sbi->gc_mutex)) {
@@ -2885,25 +2900,54 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
2885 if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) 2900 if (unlikely(f2fs_cp_error(F2FS_I_SB(inode))))
2886 return -EIO; 2901 return -EIO;
2887 2902
2888 inode_lock(inode); 2903 if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT))
2904 return -EINVAL;
2905
2906 if (!inode_trylock(inode)) {
2907 if (iocb->ki_flags & IOCB_NOWAIT)
2908 return -EAGAIN;
2909 inode_lock(inode);
2910 }
2911
2889 ret = generic_write_checks(iocb, from); 2912 ret = generic_write_checks(iocb, from);
2890 if (ret > 0) { 2913 if (ret > 0) {
2914 bool preallocated = false;
2915 size_t target_size = 0;
2891 int err; 2916 int err;
2892 2917
2893 if (iov_iter_fault_in_readable(from, iov_iter_count(from))) 2918 if (iov_iter_fault_in_readable(from, iov_iter_count(from)))
2894 set_inode_flag(inode, FI_NO_PREALLOC); 2919 set_inode_flag(inode, FI_NO_PREALLOC);
2895 2920
2896 err = f2fs_preallocate_blocks(iocb, from); 2921 if ((iocb->ki_flags & IOCB_NOWAIT) &&
2897 if (err) { 2922 (iocb->ki_flags & IOCB_DIRECT)) {
2898 clear_inode_flag(inode, FI_NO_PREALLOC); 2923 if (!f2fs_overwrite_io(inode, iocb->ki_pos,
2899 inode_unlock(inode); 2924 iov_iter_count(from)) ||
2900 return err; 2925 f2fs_has_inline_data(inode) ||
2926 f2fs_force_buffered_io(inode, WRITE)) {
2927 inode_unlock(inode);
2928 return -EAGAIN;
2929 }
2930
2931 } else {
2932 preallocated = true;
2933 target_size = iocb->ki_pos + iov_iter_count(from);
2934
2935 err = f2fs_preallocate_blocks(iocb, from);
2936 if (err) {
2937 clear_inode_flag(inode, FI_NO_PREALLOC);
2938 inode_unlock(inode);
2939 return err;
2940 }
2901 } 2941 }
2902 blk_start_plug(&plug); 2942 blk_start_plug(&plug);
2903 ret = __generic_file_write_iter(iocb, from); 2943 ret = __generic_file_write_iter(iocb, from);
2904 blk_finish_plug(&plug); 2944 blk_finish_plug(&plug);
2905 clear_inode_flag(inode, FI_NO_PREALLOC); 2945 clear_inode_flag(inode, FI_NO_PREALLOC);
2906 2946
2947 /* if we couldn't write data, we should deallocate blocks. */
2948 if (preallocated && i_size_read(inode) < target_size)
2949 f2fs_truncate(inode);
2950
2907 if (ret > 0) 2951 if (ret > 0)
2908 f2fs_update_iostat(F2FS_I_SB(inode), APP_WRITE_IO, ret); 2952 f2fs_update_iostat(F2FS_I_SB(inode), APP_WRITE_IO, ret);
2909 } 2953 }
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index aa720cc44509..bfb7a4a3a929 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -76,14 +76,15 @@ static int gc_thread_func(void *data)
76 * invalidated soon after by user update or deletion. 76 * invalidated soon after by user update or deletion.
77 * So, I'd like to wait some time to collect dirty segments. 77 * So, I'd like to wait some time to collect dirty segments.
78 */ 78 */
79 if (!mutex_trylock(&sbi->gc_mutex))
80 goto next;
81
82 if (gc_th->gc_urgent) { 79 if (gc_th->gc_urgent) {
83 wait_ms = gc_th->urgent_sleep_time; 80 wait_ms = gc_th->urgent_sleep_time;
81 mutex_lock(&sbi->gc_mutex);
84 goto do_gc; 82 goto do_gc;
85 } 83 }
86 84
85 if (!mutex_trylock(&sbi->gc_mutex))
86 goto next;
87
87 if (!is_idle(sbi)) { 88 if (!is_idle(sbi)) {
88 increase_sleep_time(gc_th, &wait_ms); 89 increase_sleep_time(gc_th, &wait_ms);
89 mutex_unlock(&sbi->gc_mutex); 90 mutex_unlock(&sbi->gc_mutex);
@@ -161,12 +162,17 @@ static int select_gc_type(struct f2fs_gc_kthread *gc_th, int gc_type)
161{ 162{
162 int gc_mode = (gc_type == BG_GC) ? GC_CB : GC_GREEDY; 163 int gc_mode = (gc_type == BG_GC) ? GC_CB : GC_GREEDY;
163 164
164 if (gc_th && gc_th->gc_idle) { 165 if (!gc_th)
166 return gc_mode;
167
168 if (gc_th->gc_idle) {
165 if (gc_th->gc_idle == 1) 169 if (gc_th->gc_idle == 1)
166 gc_mode = GC_CB; 170 gc_mode = GC_CB;
167 else if (gc_th->gc_idle == 2) 171 else if (gc_th->gc_idle == 2)
168 gc_mode = GC_GREEDY; 172 gc_mode = GC_GREEDY;
169 } 173 }
174 if (gc_th->gc_urgent)
175 gc_mode = GC_GREEDY;
170 return gc_mode; 176 return gc_mode;
171} 177}
172 178
@@ -188,11 +194,14 @@ static void select_policy(struct f2fs_sb_info *sbi, int gc_type,
188 } 194 }
189 195
190 /* we need to check every dirty segments in the FG_GC case */ 196 /* we need to check every dirty segments in the FG_GC case */
191 if (gc_type != FG_GC && p->max_search > sbi->max_victim_search) 197 if (gc_type != FG_GC &&
198 (sbi->gc_thread && !sbi->gc_thread->gc_urgent) &&
199 p->max_search > sbi->max_victim_search)
192 p->max_search = sbi->max_victim_search; 200 p->max_search = sbi->max_victim_search;
193 201
194 /* let's select beginning hot/small space first */ 202 /* let's select beginning hot/small space first in no_heap mode*/
195 if (type == CURSEG_HOT_DATA || IS_NODESEG(type)) 203 if (test_opt(sbi, NOHEAP) &&
204 (type == CURSEG_HOT_DATA || IS_NODESEG(type)))
196 p->offset = 0; 205 p->offset = 0;
197 else 206 else
198 p->offset = SIT_I(sbi)->last_victim[p->gc_mode]; 207 p->offset = SIT_I(sbi)->last_victim[p->gc_mode];
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index 90e38d8ea688..3b77d6421218 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -369,7 +369,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage,
369 f2fs_wait_on_page_writeback(page, DATA, true); 369 f2fs_wait_on_page_writeback(page, DATA, true);
370 zero_user_segment(page, MAX_INLINE_DATA(dir), PAGE_SIZE); 370 zero_user_segment(page, MAX_INLINE_DATA(dir), PAGE_SIZE);
371 371
372 dentry_blk = kmap_atomic(page); 372 dentry_blk = page_address(page);
373 373
374 make_dentry_ptr_inline(dir, &src, inline_dentry); 374 make_dentry_ptr_inline(dir, &src, inline_dentry);
375 make_dentry_ptr_block(dir, &dst, dentry_blk); 375 make_dentry_ptr_block(dir, &dst, dentry_blk);
@@ -386,7 +386,6 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage,
386 memcpy(dst.dentry, src.dentry, SIZE_OF_DIR_ENTRY * src.max); 386 memcpy(dst.dentry, src.dentry, SIZE_OF_DIR_ENTRY * src.max);
387 memcpy(dst.filename, src.filename, src.max * F2FS_SLOT_LEN); 387 memcpy(dst.filename, src.filename, src.max * F2FS_SLOT_LEN);
388 388
389 kunmap_atomic(dentry_blk);
390 if (!PageUptodate(page)) 389 if (!PageUptodate(page))
391 SetPageUptodate(page); 390 SetPageUptodate(page);
392 set_page_dirty(page); 391 set_page_dirty(page);
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 205add3d0f3a..e0d9e8f27ed2 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -284,6 +284,10 @@ static int do_read_inode(struct inode *inode)
284 fi->i_crtime.tv_nsec = le32_to_cpu(ri->i_crtime_nsec); 284 fi->i_crtime.tv_nsec = le32_to_cpu(ri->i_crtime_nsec);
285 } 285 }
286 286
287 F2FS_I(inode)->i_disk_time[0] = inode->i_atime;
288 F2FS_I(inode)->i_disk_time[1] = inode->i_ctime;
289 F2FS_I(inode)->i_disk_time[2] = inode->i_mtime;
290 F2FS_I(inode)->i_disk_time[3] = F2FS_I(inode)->i_crtime;
287 f2fs_put_page(node_page, 1); 291 f2fs_put_page(node_page, 1);
288 292
289 stat_inc_inline_xattr(inode); 293 stat_inc_inline_xattr(inode);
@@ -328,7 +332,7 @@ make_now:
328 inode->i_op = &f2fs_dir_inode_operations; 332 inode->i_op = &f2fs_dir_inode_operations;
329 inode->i_fop = &f2fs_dir_operations; 333 inode->i_fop = &f2fs_dir_operations;
330 inode->i_mapping->a_ops = &f2fs_dblock_aops; 334 inode->i_mapping->a_ops = &f2fs_dblock_aops;
331 mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_HIGH_ZERO); 335 inode_nohighmem(inode);
332 } else if (S_ISLNK(inode->i_mode)) { 336 } else if (S_ISLNK(inode->i_mode)) {
333 if (f2fs_encrypted_inode(inode)) 337 if (f2fs_encrypted_inode(inode))
334 inode->i_op = &f2fs_encrypted_symlink_inode_operations; 338 inode->i_op = &f2fs_encrypted_symlink_inode_operations;
@@ -439,12 +443,15 @@ void update_inode(struct inode *inode, struct page *node_page)
439 } 443 }
440 444
441 __set_inode_rdev(inode, ri); 445 __set_inode_rdev(inode, ri);
442 set_cold_node(inode, node_page);
443 446
444 /* deleted inode */ 447 /* deleted inode */
445 if (inode->i_nlink == 0) 448 if (inode->i_nlink == 0)
446 clear_inline_node(node_page); 449 clear_inline_node(node_page);
447 450
451 F2FS_I(inode)->i_disk_time[0] = inode->i_atime;
452 F2FS_I(inode)->i_disk_time[1] = inode->i_ctime;
453 F2FS_I(inode)->i_disk_time[2] = inode->i_mtime;
454 F2FS_I(inode)->i_disk_time[3] = F2FS_I(inode)->i_crtime;
448} 455}
449 456
450void update_inode_page(struct inode *inode) 457void update_inode_page(struct inode *inode)
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index b68e7b03959f..d5098efe577c 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -78,7 +78,8 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
78 set_inode_flag(inode, FI_NEW_INODE); 78 set_inode_flag(inode, FI_NEW_INODE);
79 79
80 /* If the directory encrypted, then we should encrypt the inode. */ 80 /* If the directory encrypted, then we should encrypt the inode. */
81 if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode)) 81 if ((f2fs_encrypted_inode(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) &&
82 f2fs_may_encrypt(inode))
82 f2fs_set_encrypted_inode(inode); 83 f2fs_set_encrypted_inode(inode);
83 84
84 if (f2fs_sb_has_extra_attr(sbi->sb)) { 85 if (f2fs_sb_has_extra_attr(sbi->sb)) {
@@ -97,7 +98,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
97 if (f2fs_sb_has_flexible_inline_xattr(sbi->sb)) { 98 if (f2fs_sb_has_flexible_inline_xattr(sbi->sb)) {
98 f2fs_bug_on(sbi, !f2fs_has_extra_attr(inode)); 99 f2fs_bug_on(sbi, !f2fs_has_extra_attr(inode));
99 if (f2fs_has_inline_xattr(inode)) 100 if (f2fs_has_inline_xattr(inode))
100 xattr_size = sbi->inline_xattr_size; 101 xattr_size = F2FS_OPTION(sbi).inline_xattr_size;
101 /* Otherwise, will be 0 */ 102 /* Otherwise, will be 0 */
102 } else if (f2fs_has_inline_xattr(inode) || 103 } else if (f2fs_has_inline_xattr(inode) ||
103 f2fs_has_inline_dentry(inode)) { 104 f2fs_has_inline_dentry(inode)) {
@@ -142,7 +143,7 @@ fail_drop:
142 return ERR_PTR(err); 143 return ERR_PTR(err);
143} 144}
144 145
145static int is_multimedia_file(const unsigned char *s, const char *sub) 146static int is_extension_exist(const unsigned char *s, const char *sub)
146{ 147{
147 size_t slen = strlen(s); 148 size_t slen = strlen(s);
148 size_t sublen = strlen(sub); 149 size_t sublen = strlen(sub);
@@ -168,19 +169,94 @@ static int is_multimedia_file(const unsigned char *s, const char *sub)
168/* 169/*
169 * Set multimedia files as cold files for hot/cold data separation 170 * Set multimedia files as cold files for hot/cold data separation
170 */ 171 */
171static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode, 172static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *inode,
172 const unsigned char *name) 173 const unsigned char *name)
173{ 174{
174 int i; 175 __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
175 __u8 (*extlist)[8] = sbi->raw_super->extension_list; 176 int i, cold_count, hot_count;
177
178 down_read(&sbi->sb_lock);
179
180 cold_count = le32_to_cpu(sbi->raw_super->extension_count);
181 hot_count = sbi->raw_super->hot_ext_count;
176 182
177 int count = le32_to_cpu(sbi->raw_super->extension_count); 183 for (i = 0; i < cold_count + hot_count; i++) {
178 for (i = 0; i < count; i++) { 184 if (!is_extension_exist(name, extlist[i]))
179 if (is_multimedia_file(name, extlist[i])) { 185 continue;
186 if (i < cold_count)
180 file_set_cold(inode); 187 file_set_cold(inode);
181 break; 188 else
182 } 189 file_set_hot(inode);
190 break;
183 } 191 }
192
193 up_read(&sbi->sb_lock);
194}
195
196int update_extension_list(struct f2fs_sb_info *sbi, const char *name,
197 bool hot, bool set)
198{
199 __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
200 int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
201 int hot_count = sbi->raw_super->hot_ext_count;
202 int total_count = cold_count + hot_count;
203 int start, count;
204 int i;
205
206 if (set) {
207 if (total_count == F2FS_MAX_EXTENSION)
208 return -EINVAL;
209 } else {
210 if (!hot && !cold_count)
211 return -EINVAL;
212 if (hot && !hot_count)
213 return -EINVAL;
214 }
215
216 if (hot) {
217 start = cold_count;
218 count = total_count;
219 } else {
220 start = 0;
221 count = cold_count;
222 }
223
224 for (i = start; i < count; i++) {
225 if (strcmp(name, extlist[i]))
226 continue;
227
228 if (set)
229 return -EINVAL;
230
231 memcpy(extlist[i], extlist[i + 1],
232 F2FS_EXTENSION_LEN * (total_count - i - 1));
233 memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN);
234 if (hot)
235 sbi->raw_super->hot_ext_count = hot_count - 1;
236 else
237 sbi->raw_super->extension_count =
238 cpu_to_le32(cold_count - 1);
239 return 0;
240 }
241
242 if (!set)
243 return -EINVAL;
244
245 if (hot) {
246 strncpy(extlist[count], name, strlen(name));
247 sbi->raw_super->hot_ext_count = hot_count + 1;
248 } else {
249 char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN];
250
251 memcpy(buf, &extlist[cold_count],
252 F2FS_EXTENSION_LEN * hot_count);
253 memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN);
254 strncpy(extlist[cold_count], name, strlen(name));
255 memcpy(&extlist[cold_count + 1], buf,
256 F2FS_EXTENSION_LEN * hot_count);
257 sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1);
258 }
259 return 0;
184} 260}
185 261
186static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode, 262static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
@@ -203,7 +279,7 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
203 return PTR_ERR(inode); 279 return PTR_ERR(inode);
204 280
205 if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) 281 if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
206 set_cold_files(sbi, inode, dentry->d_name.name); 282 set_file_temperature(sbi, inode, dentry->d_name.name);
207 283
208 inode->i_op = &f2fs_file_inode_operations; 284 inode->i_op = &f2fs_file_inode_operations;
209 inode->i_fop = &f2fs_file_operations; 285 inode->i_fop = &f2fs_file_operations;
@@ -317,7 +393,6 @@ static int __recover_dot_dentries(struct inode *dir, nid_t pino)
317 393
318 de = f2fs_find_entry(dir, &dot, &page); 394 de = f2fs_find_entry(dir, &dot, &page);
319 if (de) { 395 if (de) {
320 f2fs_dentry_kunmap(dir, page);
321 f2fs_put_page(page, 0); 396 f2fs_put_page(page, 0);
322 } else if (IS_ERR(page)) { 397 } else if (IS_ERR(page)) {
323 err = PTR_ERR(page); 398 err = PTR_ERR(page);
@@ -329,14 +404,12 @@ static int __recover_dot_dentries(struct inode *dir, nid_t pino)
329 } 404 }
330 405
331 de = f2fs_find_entry(dir, &dotdot, &page); 406 de = f2fs_find_entry(dir, &dotdot, &page);
332 if (de) { 407 if (de)
333 f2fs_dentry_kunmap(dir, page);
334 f2fs_put_page(page, 0); 408 f2fs_put_page(page, 0);
335 } else if (IS_ERR(page)) { 409 else if (IS_ERR(page))
336 err = PTR_ERR(page); 410 err = PTR_ERR(page);
337 } else { 411 else
338 err = __f2fs_add_link(dir, &dotdot, NULL, pino, S_IFDIR); 412 err = __f2fs_add_link(dir, &dotdot, NULL, pino, S_IFDIR);
339 }
340out: 413out:
341 if (!err) 414 if (!err)
342 clear_inode_flag(dir, FI_INLINE_DOTS); 415 clear_inode_flag(dir, FI_INLINE_DOTS);
@@ -377,7 +450,6 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
377 } 450 }
378 451
379 ino = le32_to_cpu(de->ino); 452 ino = le32_to_cpu(de->ino);
380 f2fs_dentry_kunmap(dir, page);
381 f2fs_put_page(page, 0); 453 f2fs_put_page(page, 0);
382 454
383 inode = f2fs_iget(dir->i_sb, ino); 455 inode = f2fs_iget(dir->i_sb, ino);
@@ -452,7 +524,6 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
452 err = acquire_orphan_inode(sbi); 524 err = acquire_orphan_inode(sbi);
453 if (err) { 525 if (err) {
454 f2fs_unlock_op(sbi); 526 f2fs_unlock_op(sbi);
455 f2fs_dentry_kunmap(dir, page);
456 f2fs_put_page(page, 0); 527 f2fs_put_page(page, 0);
457 goto fail; 528 goto fail;
458 } 529 }
@@ -579,7 +650,7 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
579 inode->i_op = &f2fs_dir_inode_operations; 650 inode->i_op = &f2fs_dir_inode_operations;
580 inode->i_fop = &f2fs_dir_operations; 651 inode->i_fop = &f2fs_dir_operations;
581 inode->i_mapping->a_ops = &f2fs_dblock_aops; 652 inode->i_mapping->a_ops = &f2fs_dblock_aops;
582 mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_HIGH_ZERO); 653 inode_nohighmem(inode);
583 654
584 set_inode_flag(inode, FI_INC_LINK); 655 set_inode_flag(inode, FI_INC_LINK);
585 f2fs_lock_op(sbi); 656 f2fs_lock_op(sbi);
@@ -717,10 +788,12 @@ out:
717 788
718static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) 789static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
719{ 790{
720 if (unlikely(f2fs_cp_error(F2FS_I_SB(dir)))) 791 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
792
793 if (unlikely(f2fs_cp_error(sbi)))
721 return -EIO; 794 return -EIO;
722 795
723 if (f2fs_encrypted_inode(dir)) { 796 if (f2fs_encrypted_inode(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) {
724 int err = fscrypt_get_encryption_info(dir); 797 int err = fscrypt_get_encryption_info(dir);
725 if (err) 798 if (err)
726 return err; 799 return err;
@@ -893,16 +966,15 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
893 } 966 }
894 967
895 if (old_dir_entry) { 968 if (old_dir_entry) {
896 if (old_dir != new_dir && !whiteout) { 969 if (old_dir != new_dir && !whiteout)
897 f2fs_set_link(old_inode, old_dir_entry, 970 f2fs_set_link(old_inode, old_dir_entry,
898 old_dir_page, new_dir); 971 old_dir_page, new_dir);
899 } else { 972 else
900 f2fs_dentry_kunmap(old_inode, old_dir_page);
901 f2fs_put_page(old_dir_page, 0); 973 f2fs_put_page(old_dir_page, 0);
902 }
903 f2fs_i_links_write(old_dir, false); 974 f2fs_i_links_write(old_dir, false);
904 } 975 }
905 add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO); 976 if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT)
977 add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO);
906 978
907 f2fs_unlock_op(sbi); 979 f2fs_unlock_op(sbi);
908 980
@@ -912,20 +984,15 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
912 984
913put_out_dir: 985put_out_dir:
914 f2fs_unlock_op(sbi); 986 f2fs_unlock_op(sbi);
915 if (new_page) { 987 if (new_page)
916 f2fs_dentry_kunmap(new_dir, new_page);
917 f2fs_put_page(new_page, 0); 988 f2fs_put_page(new_page, 0);
918 }
919out_whiteout: 989out_whiteout:
920 if (whiteout) 990 if (whiteout)
921 iput(whiteout); 991 iput(whiteout);
922out_dir: 992out_dir:
923 if (old_dir_entry) { 993 if (old_dir_entry)
924 f2fs_dentry_kunmap(old_inode, old_dir_page);
925 f2fs_put_page(old_dir_page, 0); 994 f2fs_put_page(old_dir_page, 0);
926 }
927out_old: 995out_old:
928 f2fs_dentry_kunmap(old_dir, old_page);
929 f2fs_put_page(old_page, 0); 996 f2fs_put_page(old_page, 0);
930out: 997out:
931 return err; 998 return err;
@@ -1057,8 +1124,10 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
1057 } 1124 }
1058 f2fs_mark_inode_dirty_sync(new_dir, false); 1125 f2fs_mark_inode_dirty_sync(new_dir, false);
1059 1126
1060 add_ino_entry(sbi, old_dir->i_ino, TRANS_DIR_INO); 1127 if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) {
1061 add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO); 1128 add_ino_entry(sbi, old_dir->i_ino, TRANS_DIR_INO);
1129 add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO);
1130 }
1062 1131
1063 f2fs_unlock_op(sbi); 1132 f2fs_unlock_op(sbi);
1064 1133
@@ -1067,19 +1136,15 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
1067 return 0; 1136 return 0;
1068out_new_dir: 1137out_new_dir:
1069 if (new_dir_entry) { 1138 if (new_dir_entry) {
1070 f2fs_dentry_kunmap(new_inode, new_dir_page);
1071 f2fs_put_page(new_dir_page, 0); 1139 f2fs_put_page(new_dir_page, 0);
1072 } 1140 }
1073out_old_dir: 1141out_old_dir:
1074 if (old_dir_entry) { 1142 if (old_dir_entry) {
1075 f2fs_dentry_kunmap(old_inode, old_dir_page);
1076 f2fs_put_page(old_dir_page, 0); 1143 f2fs_put_page(old_dir_page, 0);
1077 } 1144 }
1078out_new: 1145out_new:
1079 f2fs_dentry_kunmap(new_dir, new_page);
1080 f2fs_put_page(new_page, 0); 1146 f2fs_put_page(new_page, 0);
1081out_old: 1147out_old:
1082 f2fs_dentry_kunmap(old_dir, old_page);
1083 f2fs_put_page(old_page, 0); 1148 f2fs_put_page(old_page, 0);
1084out: 1149out:
1085 return err; 1150 return err;
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 177c438e4a56..9a99243054ba 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -193,8 +193,8 @@ static void __del_from_nat_cache(struct f2fs_nm_info *nm_i, struct nat_entry *e)
193 __free_nat_entry(e); 193 __free_nat_entry(e);
194} 194}
195 195
196static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, 196static struct nat_entry_set *__grab_nat_entry_set(struct f2fs_nm_info *nm_i,
197 struct nat_entry *ne) 197 struct nat_entry *ne)
198{ 198{
199 nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid); 199 nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid);
200 struct nat_entry_set *head; 200 struct nat_entry_set *head;
@@ -209,15 +209,36 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
209 head->entry_cnt = 0; 209 head->entry_cnt = 0;
210 f2fs_radix_tree_insert(&nm_i->nat_set_root, set, head); 210 f2fs_radix_tree_insert(&nm_i->nat_set_root, set, head);
211 } 211 }
212 return head;
213}
214
215static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
216 struct nat_entry *ne)
217{
218 struct nat_entry_set *head;
219 bool new_ne = nat_get_blkaddr(ne) == NEW_ADDR;
220
221 if (!new_ne)
222 head = __grab_nat_entry_set(nm_i, ne);
223
224 /*
225 * update entry_cnt in below condition:
226 * 1. update NEW_ADDR to valid block address;
227 * 2. update old block address to new one;
228 */
229 if (!new_ne && (get_nat_flag(ne, IS_PREALLOC) ||
230 !get_nat_flag(ne, IS_DIRTY)))
231 head->entry_cnt++;
232
233 set_nat_flag(ne, IS_PREALLOC, new_ne);
212 234
213 if (get_nat_flag(ne, IS_DIRTY)) 235 if (get_nat_flag(ne, IS_DIRTY))
214 goto refresh_list; 236 goto refresh_list;
215 237
216 nm_i->dirty_nat_cnt++; 238 nm_i->dirty_nat_cnt++;
217 head->entry_cnt++;
218 set_nat_flag(ne, IS_DIRTY, true); 239 set_nat_flag(ne, IS_DIRTY, true);
219refresh_list: 240refresh_list:
220 if (nat_get_blkaddr(ne) == NEW_ADDR) 241 if (new_ne)
221 list_del_init(&ne->list); 242 list_del_init(&ne->list);
222 else 243 else
223 list_move_tail(&ne->list, &head->entry_list); 244 list_move_tail(&ne->list, &head->entry_list);
@@ -1076,7 +1097,7 @@ struct page *new_node_page(struct dnode_of_data *dn, unsigned int ofs)
1076 1097
1077 f2fs_wait_on_page_writeback(page, NODE, true); 1098 f2fs_wait_on_page_writeback(page, NODE, true);
1078 fill_node_footer(page, dn->nid, dn->inode->i_ino, ofs, true); 1099 fill_node_footer(page, dn->nid, dn->inode->i_ino, ofs, true);
1079 set_cold_node(dn->inode, page); 1100 set_cold_node(page, S_ISDIR(dn->inode->i_mode));
1080 if (!PageUptodate(page)) 1101 if (!PageUptodate(page))
1081 SetPageUptodate(page); 1102 SetPageUptodate(page);
1082 if (set_page_dirty(page)) 1103 if (set_page_dirty(page))
@@ -2291,6 +2312,7 @@ retry:
2291 if (!PageUptodate(ipage)) 2312 if (!PageUptodate(ipage))
2292 SetPageUptodate(ipage); 2313 SetPageUptodate(ipage);
2293 fill_node_footer(ipage, ino, ino, 0, true); 2314 fill_node_footer(ipage, ino, ino, 0, true);
2315 set_cold_node(page, false);
2294 2316
2295 src = F2FS_INODE(page); 2317 src = F2FS_INODE(page);
2296 dst = F2FS_INODE(ipage); 2318 dst = F2FS_INODE(ipage);
@@ -2580,8 +2602,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)
2580 if (!enabled_nat_bits(sbi, NULL)) 2602 if (!enabled_nat_bits(sbi, NULL))
2581 return 0; 2603 return 0;
2582 2604
2583 nm_i->nat_bits_blocks = F2FS_BYTES_TO_BLK((nat_bits_bytes << 1) + 8 + 2605 nm_i->nat_bits_blocks = F2FS_BLK_ALIGN((nat_bits_bytes << 1) + 8);
2584 F2FS_BLKSIZE - 1);
2585 nm_i->nat_bits = f2fs_kzalloc(sbi, 2606 nm_i->nat_bits = f2fs_kzalloc(sbi,
2586 nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS, GFP_KERNEL); 2607 nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS, GFP_KERNEL);
2587 if (!nm_i->nat_bits) 2608 if (!nm_i->nat_bits)
@@ -2707,12 +2728,20 @@ static int init_node_manager(struct f2fs_sb_info *sbi)
2707static int init_free_nid_cache(struct f2fs_sb_info *sbi) 2728static int init_free_nid_cache(struct f2fs_sb_info *sbi)
2708{ 2729{
2709 struct f2fs_nm_info *nm_i = NM_I(sbi); 2730 struct f2fs_nm_info *nm_i = NM_I(sbi);
2731 int i;
2710 2732
2711 nm_i->free_nid_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks * 2733 nm_i->free_nid_bitmap = f2fs_kzalloc(sbi, nm_i->nat_blocks *
2712 NAT_ENTRY_BITMAP_SIZE, GFP_KERNEL); 2734 sizeof(unsigned char *), GFP_KERNEL);
2713 if (!nm_i->free_nid_bitmap) 2735 if (!nm_i->free_nid_bitmap)
2714 return -ENOMEM; 2736 return -ENOMEM;
2715 2737
2738 for (i = 0; i < nm_i->nat_blocks; i++) {
2739 nm_i->free_nid_bitmap[i] = f2fs_kvzalloc(sbi,
2740 NAT_ENTRY_BITMAP_SIZE_ALIGNED, GFP_KERNEL);
2741 if (!nm_i->free_nid_bitmap)
2742 return -ENOMEM;
2743 }
2744
2716 nm_i->nat_block_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks / 8, 2745 nm_i->nat_block_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks / 8,
2717 GFP_KERNEL); 2746 GFP_KERNEL);
2718 if (!nm_i->nat_block_bitmap) 2747 if (!nm_i->nat_block_bitmap)
@@ -2803,7 +2832,13 @@ void destroy_node_manager(struct f2fs_sb_info *sbi)
2803 up_write(&nm_i->nat_tree_lock); 2832 up_write(&nm_i->nat_tree_lock);
2804 2833
2805 kvfree(nm_i->nat_block_bitmap); 2834 kvfree(nm_i->nat_block_bitmap);
2806 kvfree(nm_i->free_nid_bitmap); 2835 if (nm_i->free_nid_bitmap) {
2836 int i;
2837
2838 for (i = 0; i < nm_i->nat_blocks; i++)
2839 kvfree(nm_i->free_nid_bitmap[i]);
2840 kfree(nm_i->free_nid_bitmap);
2841 }
2807 kvfree(nm_i->free_nid_count); 2842 kvfree(nm_i->free_nid_count);
2808 2843
2809 kfree(nm_i->nat_bitmap); 2844 kfree(nm_i->nat_bitmap);
diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h
index 081ef0d672bf..b95e49e4a928 100644
--- a/fs/f2fs/node.h
+++ b/fs/f2fs/node.h
@@ -44,6 +44,7 @@ enum {
44 HAS_FSYNCED_INODE, /* is the inode fsynced before? */ 44 HAS_FSYNCED_INODE, /* is the inode fsynced before? */
45 HAS_LAST_FSYNC, /* has the latest node fsync mark? */ 45 HAS_LAST_FSYNC, /* has the latest node fsync mark? */
46 IS_DIRTY, /* this nat entry is dirty? */ 46 IS_DIRTY, /* this nat entry is dirty? */
47 IS_PREALLOC, /* nat entry is preallocated */
47}; 48};
48 49
49/* 50/*
@@ -422,12 +423,12 @@ static inline void clear_inline_node(struct page *page)
422 ClearPageChecked(page); 423 ClearPageChecked(page);
423} 424}
424 425
425static inline void set_cold_node(struct inode *inode, struct page *page) 426static inline void set_cold_node(struct page *page, bool is_dir)
426{ 427{
427 struct f2fs_node *rn = F2FS_NODE(page); 428 struct f2fs_node *rn = F2FS_NODE(page);
428 unsigned int flag = le32_to_cpu(rn->footer.flag); 429 unsigned int flag = le32_to_cpu(rn->footer.flag);
429 430
430 if (S_ISDIR(inode->i_mode)) 431 if (is_dir)
431 flag &= ~(0x1 << COLD_BIT_SHIFT); 432 flag &= ~(0x1 << COLD_BIT_SHIFT);
432 else 433 else
433 flag |= (0x1 << COLD_BIT_SHIFT); 434 flag |= (0x1 << COLD_BIT_SHIFT);
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
index 337f3363f48f..1b23d3febe4c 100644
--- a/fs/f2fs/recovery.c
+++ b/fs/f2fs/recovery.c
@@ -144,7 +144,7 @@ static int recover_dentry(struct inode *inode, struct page *ipage,
144retry: 144retry:
145 de = __f2fs_find_entry(dir, &fname, &page); 145 de = __f2fs_find_entry(dir, &fname, &page);
146 if (de && inode->i_ino == le32_to_cpu(de->ino)) 146 if (de && inode->i_ino == le32_to_cpu(de->ino))
147 goto out_unmap_put; 147 goto out_put;
148 148
149 if (de) { 149 if (de) {
150 einode = f2fs_iget_retry(inode->i_sb, le32_to_cpu(de->ino)); 150 einode = f2fs_iget_retry(inode->i_sb, le32_to_cpu(de->ino));
@@ -153,19 +153,19 @@ retry:
153 err = PTR_ERR(einode); 153 err = PTR_ERR(einode);
154 if (err == -ENOENT) 154 if (err == -ENOENT)
155 err = -EEXIST; 155 err = -EEXIST;
156 goto out_unmap_put; 156 goto out_put;
157 } 157 }
158 158
159 err = dquot_initialize(einode); 159 err = dquot_initialize(einode);
160 if (err) { 160 if (err) {
161 iput(einode); 161 iput(einode);
162 goto out_unmap_put; 162 goto out_put;
163 } 163 }
164 164
165 err = acquire_orphan_inode(F2FS_I_SB(inode)); 165 err = acquire_orphan_inode(F2FS_I_SB(inode));
166 if (err) { 166 if (err) {
167 iput(einode); 167 iput(einode);
168 goto out_unmap_put; 168 goto out_put;
169 } 169 }
170 f2fs_delete_entry(de, page, dir, einode); 170 f2fs_delete_entry(de, page, dir, einode);
171 iput(einode); 171 iput(einode);
@@ -180,8 +180,7 @@ retry:
180 goto retry; 180 goto retry;
181 goto out; 181 goto out;
182 182
183out_unmap_put: 183out_put:
184 f2fs_dentry_kunmap(dir, page);
185 f2fs_put_page(page, 0); 184 f2fs_put_page(page, 0);
186out: 185out:
187 if (file_enc_name(inode)) 186 if (file_enc_name(inode))
@@ -243,6 +242,9 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
243 struct curseg_info *curseg; 242 struct curseg_info *curseg;
244 struct page *page = NULL; 243 struct page *page = NULL;
245 block_t blkaddr; 244 block_t blkaddr;
245 unsigned int loop_cnt = 0;
246 unsigned int free_blocks = sbi->user_block_count -
247 valid_user_blocks(sbi);
246 int err = 0; 248 int err = 0;
247 249
248 /* get node pages in the current segment */ 250 /* get node pages in the current segment */
@@ -295,6 +297,17 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
295 if (IS_INODE(page) && is_dent_dnode(page)) 297 if (IS_INODE(page) && is_dent_dnode(page))
296 entry->last_dentry = blkaddr; 298 entry->last_dentry = blkaddr;
297next: 299next:
300 /* sanity check in order to detect looped node chain */
301 if (++loop_cnt >= free_blocks ||
302 blkaddr == next_blkaddr_of_node(page)) {
303 f2fs_msg(sbi->sb, KERN_NOTICE,
304 "%s: detect looped node chain, "
305 "blkaddr:%u, next:%u",
306 __func__, blkaddr, next_blkaddr_of_node(page));
307 err = -EINVAL;
308 break;
309 }
310
298 /* check next segment */ 311 /* check next segment */
299 blkaddr = next_blkaddr_of_node(page); 312 blkaddr = next_blkaddr_of_node(page);
300 f2fs_put_page(page, 1); 313 f2fs_put_page(page, 1);
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index b16a8e6625aa..5854cc4e1d67 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1411,12 +1411,11 @@ static int issue_discard_thread(void *data)
1411 if (kthread_should_stop()) 1411 if (kthread_should_stop())
1412 return 0; 1412 return 0;
1413 1413
1414 if (dcc->discard_wake) { 1414 if (dcc->discard_wake)
1415 dcc->discard_wake = 0; 1415 dcc->discard_wake = 0;
1416 if (sbi->gc_thread && sbi->gc_thread->gc_urgent) 1416
1417 init_discard_policy(&dpolicy, 1417 if (sbi->gc_thread && sbi->gc_thread->gc_urgent)
1418 DPOLICY_FORCE, 1); 1418 init_discard_policy(&dpolicy, DPOLICY_FORCE, 1);
1419 }
1420 1419
1421 sb_start_intwrite(sbi->sb); 1420 sb_start_intwrite(sbi->sb);
1422 1421
@@ -1485,7 +1484,7 @@ static int __issue_discard_async(struct f2fs_sb_info *sbi,
1485 struct block_device *bdev, block_t blkstart, block_t blklen) 1484 struct block_device *bdev, block_t blkstart, block_t blklen)
1486{ 1485{
1487#ifdef CONFIG_BLK_DEV_ZONED 1486#ifdef CONFIG_BLK_DEV_ZONED
1488 if (f2fs_sb_mounted_blkzoned(sbi->sb) && 1487 if (f2fs_sb_has_blkzoned(sbi->sb) &&
1489 bdev_zoned_model(bdev) != BLK_ZONED_NONE) 1488 bdev_zoned_model(bdev) != BLK_ZONED_NONE)
1490 return __f2fs_issue_discard_zone(sbi, bdev, blkstart, blklen); 1489 return __f2fs_issue_discard_zone(sbi, bdev, blkstart, blklen);
1491#endif 1490#endif
@@ -1683,7 +1682,7 @@ find_next:
1683 sbi->blocks_per_seg, cur_pos); 1682 sbi->blocks_per_seg, cur_pos);
1684 len = next_pos - cur_pos; 1683 len = next_pos - cur_pos;
1685 1684
1686 if (f2fs_sb_mounted_blkzoned(sbi->sb) || 1685 if (f2fs_sb_has_blkzoned(sbi->sb) ||
1687 (force && len < cpc->trim_minlen)) 1686 (force && len < cpc->trim_minlen))
1688 goto skip; 1687 goto skip;
1689 1688
@@ -1727,7 +1726,7 @@ void init_discard_policy(struct discard_policy *dpolicy,
1727 } else if (discard_type == DPOLICY_FORCE) { 1726 } else if (discard_type == DPOLICY_FORCE) {
1728 dpolicy->min_interval = DEF_MIN_DISCARD_ISSUE_TIME; 1727 dpolicy->min_interval = DEF_MIN_DISCARD_ISSUE_TIME;
1729 dpolicy->max_interval = DEF_MAX_DISCARD_ISSUE_TIME; 1728 dpolicy->max_interval = DEF_MAX_DISCARD_ISSUE_TIME;
1730 dpolicy->io_aware = true; 1729 dpolicy->io_aware = false;
1731 } else if (discard_type == DPOLICY_FSTRIM) { 1730 } else if (discard_type == DPOLICY_FSTRIM) {
1732 dpolicy->io_aware = false; 1731 dpolicy->io_aware = false;
1733 } else if (discard_type == DPOLICY_UMOUNT) { 1732 } else if (discard_type == DPOLICY_UMOUNT) {
@@ -1863,7 +1862,7 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
1863 sbi->discard_blks--; 1862 sbi->discard_blks--;
1864 1863
1865 /* don't overwrite by SSR to keep node chain */ 1864 /* don't overwrite by SSR to keep node chain */
1866 if (se->type == CURSEG_WARM_NODE) { 1865 if (IS_NODESEG(se->type)) {
1867 if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map)) 1866 if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map))
1868 se->ckpt_valid_blocks++; 1867 se->ckpt_valid_blocks++;
1869 } 1868 }
@@ -2164,11 +2163,17 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)
2164 if (sbi->segs_per_sec != 1) 2163 if (sbi->segs_per_sec != 1)
2165 return CURSEG_I(sbi, type)->segno; 2164 return CURSEG_I(sbi, type)->segno;
2166 2165
2167 if (type == CURSEG_HOT_DATA || IS_NODESEG(type)) 2166 if (test_opt(sbi, NOHEAP) &&
2167 (type == CURSEG_HOT_DATA || IS_NODESEG(type)))
2168 return 0; 2168 return 0;
2169 2169
2170 if (SIT_I(sbi)->last_victim[ALLOC_NEXT]) 2170 if (SIT_I(sbi)->last_victim[ALLOC_NEXT])
2171 return SIT_I(sbi)->last_victim[ALLOC_NEXT]; 2171 return SIT_I(sbi)->last_victim[ALLOC_NEXT];
2172
2173 /* find segments from 0 to reuse freed segments */
2174 if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE)
2175 return 0;
2176
2172 return CURSEG_I(sbi, type)->segno; 2177 return CURSEG_I(sbi, type)->segno;
2173} 2178}
2174 2179
@@ -2455,6 +2460,101 @@ int rw_hint_to_seg_type(enum rw_hint hint)
2455 } 2460 }
2456} 2461}
2457 2462
2463/* This returns write hints for each segment type. This hints will be
2464 * passed down to block layer. There are mapping tables which depend on
2465 * the mount option 'whint_mode'.
2466 *
2467 * 1) whint_mode=off. F2FS only passes down WRITE_LIFE_NOT_SET.
2468 *
2469 * 2) whint_mode=user-based. F2FS tries to pass down hints given by users.
2470 *
2471 * User F2FS Block
2472 * ---- ---- -----
2473 * META WRITE_LIFE_NOT_SET
2474 * HOT_NODE "
2475 * WARM_NODE "
2476 * COLD_NODE "
2477 * ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME
2478 * extension list " "
2479 *
2480 * -- buffered io
2481 * WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME
2482 * WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT
2483 * WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET
2484 * WRITE_LIFE_NONE " "
2485 * WRITE_LIFE_MEDIUM " "
2486 * WRITE_LIFE_LONG " "
2487 *
2488 * -- direct io
2489 * WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME
2490 * WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT
2491 * WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET
2492 * WRITE_LIFE_NONE " WRITE_LIFE_NONE
2493 * WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM
2494 * WRITE_LIFE_LONG " WRITE_LIFE_LONG
2495 *
2496 * 3) whint_mode=fs-based. F2FS passes down hints with its policy.
2497 *
2498 * User F2FS Block
2499 * ---- ---- -----
2500 * META WRITE_LIFE_MEDIUM;
2501 * HOT_NODE WRITE_LIFE_NOT_SET
2502 * WARM_NODE "
2503 * COLD_NODE WRITE_LIFE_NONE
2504 * ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME
2505 * extension list " "
2506 *
2507 * -- buffered io
2508 * WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME
2509 * WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT
2510 * WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_LONG
2511 * WRITE_LIFE_NONE " "
2512 * WRITE_LIFE_MEDIUM " "
2513 * WRITE_LIFE_LONG " "
2514 *
2515 * -- direct io
2516 * WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME
2517 * WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT
2518 * WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET
2519 * WRITE_LIFE_NONE " WRITE_LIFE_NONE
2520 * WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM
2521 * WRITE_LIFE_LONG " WRITE_LIFE_LONG
2522 */
2523
2524enum rw_hint io_type_to_rw_hint(struct f2fs_sb_info *sbi,
2525 enum page_type type, enum temp_type temp)
2526{
2527 if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_USER) {
2528 if (type == DATA) {
2529 if (temp == WARM)
2530 return WRITE_LIFE_NOT_SET;
2531 else if (temp == HOT)
2532 return WRITE_LIFE_SHORT;
2533 else if (temp == COLD)
2534 return WRITE_LIFE_EXTREME;
2535 } else {
2536 return WRITE_LIFE_NOT_SET;
2537 }
2538 } else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS) {
2539 if (type == DATA) {
2540 if (temp == WARM)
2541 return WRITE_LIFE_LONG;
2542 else if (temp == HOT)
2543 return WRITE_LIFE_SHORT;
2544 else if (temp == COLD)
2545 return WRITE_LIFE_EXTREME;
2546 } else if (type == NODE) {
2547 if (temp == WARM || temp == HOT)
2548 return WRITE_LIFE_NOT_SET;
2549 else if (temp == COLD)
2550 return WRITE_LIFE_NONE;
2551 } else if (type == META) {
2552 return WRITE_LIFE_MEDIUM;
2553 }
2554 }
2555 return WRITE_LIFE_NOT_SET;
2556}
2557
2458static int __get_segment_type_2(struct f2fs_io_info *fio) 2558static int __get_segment_type_2(struct f2fs_io_info *fio)
2459{ 2559{
2460 if (fio->type == DATA) 2560 if (fio->type == DATA)
@@ -2487,7 +2587,8 @@ static int __get_segment_type_6(struct f2fs_io_info *fio)
2487 2587
2488 if (is_cold_data(fio->page) || file_is_cold(inode)) 2588 if (is_cold_data(fio->page) || file_is_cold(inode))
2489 return CURSEG_COLD_DATA; 2589 return CURSEG_COLD_DATA;
2490 if (is_inode_flag_set(inode, FI_HOT_DATA)) 2590 if (file_is_hot(inode) ||
2591 is_inode_flag_set(inode, FI_HOT_DATA))
2491 return CURSEG_HOT_DATA; 2592 return CURSEG_HOT_DATA;
2492 return rw_hint_to_seg_type(inode->i_write_hint); 2593 return rw_hint_to_seg_type(inode->i_write_hint);
2493 } else { 2594 } else {
@@ -2502,7 +2603,7 @@ static int __get_segment_type(struct f2fs_io_info *fio)
2502{ 2603{
2503 int type = 0; 2604 int type = 0;
2504 2605
2505 switch (fio->sbi->active_logs) { 2606 switch (F2FS_OPTION(fio->sbi).active_logs) {
2506 case 2: 2607 case 2:
2507 type = __get_segment_type_2(fio); 2608 type = __get_segment_type_2(fio);
2508 break; 2609 break;
@@ -2642,6 +2743,7 @@ void write_meta_page(struct f2fs_sb_info *sbi, struct page *page,
2642 struct f2fs_io_info fio = { 2743 struct f2fs_io_info fio = {
2643 .sbi = sbi, 2744 .sbi = sbi,
2644 .type = META, 2745 .type = META,
2746 .temp = HOT,
2645 .op = REQ_OP_WRITE, 2747 .op = REQ_OP_WRITE,
2646 .op_flags = REQ_SYNC | REQ_META | REQ_PRIO, 2748 .op_flags = REQ_SYNC | REQ_META | REQ_PRIO,
2647 .old_blkaddr = page->index, 2749 .old_blkaddr = page->index,
@@ -2688,8 +2790,15 @@ void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio)
2688int rewrite_data_page(struct f2fs_io_info *fio) 2790int rewrite_data_page(struct f2fs_io_info *fio)
2689{ 2791{
2690 int err; 2792 int err;
2793 struct f2fs_sb_info *sbi = fio->sbi;
2691 2794
2692 fio->new_blkaddr = fio->old_blkaddr; 2795 fio->new_blkaddr = fio->old_blkaddr;
2796 /* i/o temperature is needed for passing down write hints */
2797 __get_segment_type(fio);
2798
2799 f2fs_bug_on(sbi, !IS_DATASEG(get_seg_entry(sbi,
2800 GET_SEGNO(sbi, fio->new_blkaddr))->type));
2801
2693 stat_inc_inplace_blocks(fio->sbi); 2802 stat_inc_inplace_blocks(fio->sbi);
2694 2803
2695 err = f2fs_submit_page_bio(fio); 2804 err = f2fs_submit_page_bio(fio);
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index f11c4bc82c78..3325d0769723 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -53,13 +53,19 @@
53 ((secno) == CURSEG_I(sbi, CURSEG_COLD_NODE)->segno / \ 53 ((secno) == CURSEG_I(sbi, CURSEG_COLD_NODE)->segno / \
54 (sbi)->segs_per_sec)) \ 54 (sbi)->segs_per_sec)) \
55 55
56#define MAIN_BLKADDR(sbi) (SM_I(sbi)->main_blkaddr) 56#define MAIN_BLKADDR(sbi) \
57#define SEG0_BLKADDR(sbi) (SM_I(sbi)->seg0_blkaddr) 57 (SM_I(sbi) ? SM_I(sbi)->main_blkaddr : \
58 le32_to_cpu(F2FS_RAW_SUPER(sbi)->main_blkaddr))
59#define SEG0_BLKADDR(sbi) \
60 (SM_I(sbi) ? SM_I(sbi)->seg0_blkaddr : \
61 le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment0_blkaddr))
58 62
59#define MAIN_SEGS(sbi) (SM_I(sbi)->main_segments) 63#define MAIN_SEGS(sbi) (SM_I(sbi)->main_segments)
60#define MAIN_SECS(sbi) ((sbi)->total_sections) 64#define MAIN_SECS(sbi) ((sbi)->total_sections)
61 65
62#define TOTAL_SEGS(sbi) (SM_I(sbi)->segment_count) 66#define TOTAL_SEGS(sbi) \
67 (SM_I(sbi) ? SM_I(sbi)->segment_count : \
68 le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count))
63#define TOTAL_BLKS(sbi) (TOTAL_SEGS(sbi) << (sbi)->log_blocks_per_seg) 69#define TOTAL_BLKS(sbi) (TOTAL_SEGS(sbi) << (sbi)->log_blocks_per_seg)
64 70
65#define MAX_BLKADDR(sbi) (SEG0_BLKADDR(sbi) + TOTAL_BLKS(sbi)) 71#define MAX_BLKADDR(sbi) (SEG0_BLKADDR(sbi) + TOTAL_BLKS(sbi))
@@ -596,6 +602,8 @@ static inline int utilization(struct f2fs_sb_info *sbi)
596#define DEF_MIN_FSYNC_BLOCKS 8 602#define DEF_MIN_FSYNC_BLOCKS 8
597#define DEF_MIN_HOT_BLOCKS 16 603#define DEF_MIN_HOT_BLOCKS 16
598 604
605#define SMALL_VOLUME_SEGMENTS (16 * 512) /* 16GB */
606
599enum { 607enum {
600 F2FS_IPU_FORCE, 608 F2FS_IPU_FORCE,
601 F2FS_IPU_SSR, 609 F2FS_IPU_SSR,
@@ -630,10 +638,17 @@ static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
630 f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1); 638 f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1);
631} 639}
632 640
633static inline void verify_block_addr(struct f2fs_sb_info *sbi, block_t blk_addr) 641static inline void verify_block_addr(struct f2fs_io_info *fio, block_t blk_addr)
634{ 642{
635 BUG_ON(blk_addr < SEG0_BLKADDR(sbi) 643 struct f2fs_sb_info *sbi = fio->sbi;
636 || blk_addr >= MAX_BLKADDR(sbi)); 644
645 if (PAGE_TYPE_OF_BIO(fio->type) == META &&
646 (!is_read_io(fio->op) || fio->is_meta))
647 BUG_ON(blk_addr < SEG0_BLKADDR(sbi) ||
648 blk_addr >= MAIN_BLKADDR(sbi));
649 else
650 BUG_ON(blk_addr < MAIN_BLKADDR(sbi) ||
651 blk_addr >= MAX_BLKADDR(sbi));
637} 652}
638 653
639/* 654/*
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 8173ae688814..42d564c5ccd0 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -60,7 +60,7 @@ char *fault_name[FAULT_MAX] = {
60static void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, 60static void f2fs_build_fault_attr(struct f2fs_sb_info *sbi,
61 unsigned int rate) 61 unsigned int rate)
62{ 62{
63 struct f2fs_fault_info *ffi = &sbi->fault_info; 63 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
64 64
65 if (rate) { 65 if (rate) {
66 atomic_set(&ffi->inject_ops, 0); 66 atomic_set(&ffi->inject_ops, 0);
@@ -129,6 +129,10 @@ enum {
129 Opt_jqfmt_vfsold, 129 Opt_jqfmt_vfsold,
130 Opt_jqfmt_vfsv0, 130 Opt_jqfmt_vfsv0,
131 Opt_jqfmt_vfsv1, 131 Opt_jqfmt_vfsv1,
132 Opt_whint,
133 Opt_alloc,
134 Opt_fsync,
135 Opt_test_dummy_encryption,
132 Opt_err, 136 Opt_err,
133}; 137};
134 138
@@ -182,6 +186,10 @@ static match_table_t f2fs_tokens = {
182 {Opt_jqfmt_vfsold, "jqfmt=vfsold"}, 186 {Opt_jqfmt_vfsold, "jqfmt=vfsold"},
183 {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, 187 {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"},
184 {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"}, 188 {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"},
189 {Opt_whint, "whint_mode=%s"},
190 {Opt_alloc, "alloc_mode=%s"},
191 {Opt_fsync, "fsync_mode=%s"},
192 {Opt_test_dummy_encryption, "test_dummy_encryption"},
185 {Opt_err, NULL}, 193 {Opt_err, NULL},
186}; 194};
187 195
@@ -202,21 +210,24 @@ static inline void limit_reserve_root(struct f2fs_sb_info *sbi)
202 block_t limit = (sbi->user_block_count << 1) / 1000; 210 block_t limit = (sbi->user_block_count << 1) / 1000;
203 211
204 /* limit is 0.2% */ 212 /* limit is 0.2% */
205 if (test_opt(sbi, RESERVE_ROOT) && sbi->root_reserved_blocks > limit) { 213 if (test_opt(sbi, RESERVE_ROOT) &&
206 sbi->root_reserved_blocks = limit; 214 F2FS_OPTION(sbi).root_reserved_blocks > limit) {
215 F2FS_OPTION(sbi).root_reserved_blocks = limit;
207 f2fs_msg(sbi->sb, KERN_INFO, 216 f2fs_msg(sbi->sb, KERN_INFO,
208 "Reduce reserved blocks for root = %u", 217 "Reduce reserved blocks for root = %u",
209 sbi->root_reserved_blocks); 218 F2FS_OPTION(sbi).root_reserved_blocks);
210 } 219 }
211 if (!test_opt(sbi, RESERVE_ROOT) && 220 if (!test_opt(sbi, RESERVE_ROOT) &&
212 (!uid_eq(sbi->s_resuid, 221 (!uid_eq(F2FS_OPTION(sbi).s_resuid,
213 make_kuid(&init_user_ns, F2FS_DEF_RESUID)) || 222 make_kuid(&init_user_ns, F2FS_DEF_RESUID)) ||
214 !gid_eq(sbi->s_resgid, 223 !gid_eq(F2FS_OPTION(sbi).s_resgid,
215 make_kgid(&init_user_ns, F2FS_DEF_RESGID)))) 224 make_kgid(&init_user_ns, F2FS_DEF_RESGID))))
216 f2fs_msg(sbi->sb, KERN_INFO, 225 f2fs_msg(sbi->sb, KERN_INFO,
217 "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root", 226 "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
218 from_kuid_munged(&init_user_ns, sbi->s_resuid), 227 from_kuid_munged(&init_user_ns,
219 from_kgid_munged(&init_user_ns, sbi->s_resgid)); 228 F2FS_OPTION(sbi).s_resuid),
229 from_kgid_munged(&init_user_ns,
230 F2FS_OPTION(sbi).s_resgid));
220} 231}
221 232
222static void init_once(void *foo) 233static void init_once(void *foo)
@@ -236,7 +247,7 @@ static int f2fs_set_qf_name(struct super_block *sb, int qtype,
236 char *qname; 247 char *qname;
237 int ret = -EINVAL; 248 int ret = -EINVAL;
238 249
239 if (sb_any_quota_loaded(sb) && !sbi->s_qf_names[qtype]) { 250 if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) {
240 f2fs_msg(sb, KERN_ERR, 251 f2fs_msg(sb, KERN_ERR,
241 "Cannot change journaled " 252 "Cannot change journaled "
242 "quota options when quota turned on"); 253 "quota options when quota turned on");
@@ -254,8 +265,8 @@ static int f2fs_set_qf_name(struct super_block *sb, int qtype,
254 "Not enough memory for storing quotafile name"); 265 "Not enough memory for storing quotafile name");
255 return -EINVAL; 266 return -EINVAL;
256 } 267 }
257 if (sbi->s_qf_names[qtype]) { 268 if (F2FS_OPTION(sbi).s_qf_names[qtype]) {
258 if (strcmp(sbi->s_qf_names[qtype], qname) == 0) 269 if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0)
259 ret = 0; 270 ret = 0;
260 else 271 else
261 f2fs_msg(sb, KERN_ERR, 272 f2fs_msg(sb, KERN_ERR,
@@ -268,7 +279,7 @@ static int f2fs_set_qf_name(struct super_block *sb, int qtype,
268 "quotafile must be on filesystem root"); 279 "quotafile must be on filesystem root");
269 goto errout; 280 goto errout;
270 } 281 }
271 sbi->s_qf_names[qtype] = qname; 282 F2FS_OPTION(sbi).s_qf_names[qtype] = qname;
272 set_opt(sbi, QUOTA); 283 set_opt(sbi, QUOTA);
273 return 0; 284 return 0;
274errout: 285errout:
@@ -280,13 +291,13 @@ static int f2fs_clear_qf_name(struct super_block *sb, int qtype)
280{ 291{
281 struct f2fs_sb_info *sbi = F2FS_SB(sb); 292 struct f2fs_sb_info *sbi = F2FS_SB(sb);
282 293
283 if (sb_any_quota_loaded(sb) && sbi->s_qf_names[qtype]) { 294 if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) {
284 f2fs_msg(sb, KERN_ERR, "Cannot change journaled quota options" 295 f2fs_msg(sb, KERN_ERR, "Cannot change journaled quota options"
285 " when quota turned on"); 296 " when quota turned on");
286 return -EINVAL; 297 return -EINVAL;
287 } 298 }
288 kfree(sbi->s_qf_names[qtype]); 299 kfree(F2FS_OPTION(sbi).s_qf_names[qtype]);
289 sbi->s_qf_names[qtype] = NULL; 300 F2FS_OPTION(sbi).s_qf_names[qtype] = NULL;
290 return 0; 301 return 0;
291} 302}
292 303
@@ -302,15 +313,19 @@ static int f2fs_check_quota_options(struct f2fs_sb_info *sbi)
302 "Cannot enable project quota enforcement."); 313 "Cannot enable project quota enforcement.");
303 return -1; 314 return -1;
304 } 315 }
305 if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA] || 316 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] ||
306 sbi->s_qf_names[PRJQUOTA]) { 317 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] ||
307 if (test_opt(sbi, USRQUOTA) && sbi->s_qf_names[USRQUOTA]) 318 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) {
319 if (test_opt(sbi, USRQUOTA) &&
320 F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
308 clear_opt(sbi, USRQUOTA); 321 clear_opt(sbi, USRQUOTA);
309 322
310 if (test_opt(sbi, GRPQUOTA) && sbi->s_qf_names[GRPQUOTA]) 323 if (test_opt(sbi, GRPQUOTA) &&
324 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
311 clear_opt(sbi, GRPQUOTA); 325 clear_opt(sbi, GRPQUOTA);
312 326
313 if (test_opt(sbi, PRJQUOTA) && sbi->s_qf_names[PRJQUOTA]) 327 if (test_opt(sbi, PRJQUOTA) &&
328 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
314 clear_opt(sbi, PRJQUOTA); 329 clear_opt(sbi, PRJQUOTA);
315 330
316 if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) || 331 if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) ||
@@ -320,19 +335,19 @@ static int f2fs_check_quota_options(struct f2fs_sb_info *sbi)
320 return -1; 335 return -1;
321 } 336 }
322 337
323 if (!sbi->s_jquota_fmt) { 338 if (!F2FS_OPTION(sbi).s_jquota_fmt) {
324 f2fs_msg(sbi->sb, KERN_ERR, "journaled quota format " 339 f2fs_msg(sbi->sb, KERN_ERR, "journaled quota format "
325 "not specified"); 340 "not specified");
326 return -1; 341 return -1;
327 } 342 }
328 } 343 }
329 344
330 if (f2fs_sb_has_quota_ino(sbi->sb) && sbi->s_jquota_fmt) { 345 if (f2fs_sb_has_quota_ino(sbi->sb) && F2FS_OPTION(sbi).s_jquota_fmt) {
331 f2fs_msg(sbi->sb, KERN_INFO, 346 f2fs_msg(sbi->sb, KERN_INFO,
332 "QUOTA feature is enabled, so ignore jquota_fmt"); 347 "QUOTA feature is enabled, so ignore jquota_fmt");
333 sbi->s_jquota_fmt = 0; 348 F2FS_OPTION(sbi).s_jquota_fmt = 0;
334 } 349 }
335 if (f2fs_sb_has_quota_ino(sbi->sb) && sb_rdonly(sbi->sb)) { 350 if (f2fs_sb_has_quota_ino(sbi->sb) && f2fs_readonly(sbi->sb)) {
336 f2fs_msg(sbi->sb, KERN_INFO, 351 f2fs_msg(sbi->sb, KERN_INFO,
337 "Filesystem with quota feature cannot be mounted RDWR " 352 "Filesystem with quota feature cannot be mounted RDWR "
338 "without CONFIG_QUOTA"); 353 "without CONFIG_QUOTA");
@@ -403,14 +418,14 @@ static int parse_options(struct super_block *sb, char *options)
403 q = bdev_get_queue(sb->s_bdev); 418 q = bdev_get_queue(sb->s_bdev);
404 if (blk_queue_discard(q)) { 419 if (blk_queue_discard(q)) {
405 set_opt(sbi, DISCARD); 420 set_opt(sbi, DISCARD);
406 } else if (!f2fs_sb_mounted_blkzoned(sb)) { 421 } else if (!f2fs_sb_has_blkzoned(sb)) {
407 f2fs_msg(sb, KERN_WARNING, 422 f2fs_msg(sb, KERN_WARNING,
408 "mounting with \"discard\" option, but " 423 "mounting with \"discard\" option, but "
409 "the device does not support discard"); 424 "the device does not support discard");
410 } 425 }
411 break; 426 break;
412 case Opt_nodiscard: 427 case Opt_nodiscard:
413 if (f2fs_sb_mounted_blkzoned(sb)) { 428 if (f2fs_sb_has_blkzoned(sb)) {
414 f2fs_msg(sb, KERN_WARNING, 429 f2fs_msg(sb, KERN_WARNING,
415 "discard is required for zoned block devices"); 430 "discard is required for zoned block devices");
416 return -EINVAL; 431 return -EINVAL;
@@ -440,7 +455,7 @@ static int parse_options(struct super_block *sb, char *options)
440 if (args->from && match_int(args, &arg)) 455 if (args->from && match_int(args, &arg))
441 return -EINVAL; 456 return -EINVAL;
442 set_opt(sbi, INLINE_XATTR_SIZE); 457 set_opt(sbi, INLINE_XATTR_SIZE);
443 sbi->inline_xattr_size = arg; 458 F2FS_OPTION(sbi).inline_xattr_size = arg;
444 break; 459 break;
445#else 460#else
446 case Opt_user_xattr: 461 case Opt_user_xattr:
@@ -480,7 +495,7 @@ static int parse_options(struct super_block *sb, char *options)
480 return -EINVAL; 495 return -EINVAL;
481 if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE) 496 if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE)
482 return -EINVAL; 497 return -EINVAL;
483 sbi->active_logs = arg; 498 F2FS_OPTION(sbi).active_logs = arg;
484 break; 499 break;
485 case Opt_disable_ext_identify: 500 case Opt_disable_ext_identify:
486 set_opt(sbi, DISABLE_EXT_IDENTIFY); 501 set_opt(sbi, DISABLE_EXT_IDENTIFY);
@@ -524,9 +539,9 @@ static int parse_options(struct super_block *sb, char *options)
524 if (test_opt(sbi, RESERVE_ROOT)) { 539 if (test_opt(sbi, RESERVE_ROOT)) {
525 f2fs_msg(sb, KERN_INFO, 540 f2fs_msg(sb, KERN_INFO,
526 "Preserve previous reserve_root=%u", 541 "Preserve previous reserve_root=%u",
527 sbi->root_reserved_blocks); 542 F2FS_OPTION(sbi).root_reserved_blocks);
528 } else { 543 } else {
529 sbi->root_reserved_blocks = arg; 544 F2FS_OPTION(sbi).root_reserved_blocks = arg;
530 set_opt(sbi, RESERVE_ROOT); 545 set_opt(sbi, RESERVE_ROOT);
531 } 546 }
532 break; 547 break;
@@ -539,7 +554,7 @@ static int parse_options(struct super_block *sb, char *options)
539 "Invalid uid value %d", arg); 554 "Invalid uid value %d", arg);
540 return -EINVAL; 555 return -EINVAL;
541 } 556 }
542 sbi->s_resuid = uid; 557 F2FS_OPTION(sbi).s_resuid = uid;
543 break; 558 break;
544 case Opt_resgid: 559 case Opt_resgid:
545 if (args->from && match_int(args, &arg)) 560 if (args->from && match_int(args, &arg))
@@ -550,7 +565,7 @@ static int parse_options(struct super_block *sb, char *options)
550 "Invalid gid value %d", arg); 565 "Invalid gid value %d", arg);
551 return -EINVAL; 566 return -EINVAL;
552 } 567 }
553 sbi->s_resgid = gid; 568 F2FS_OPTION(sbi).s_resgid = gid;
554 break; 569 break;
555 case Opt_mode: 570 case Opt_mode:
556 name = match_strdup(&args[0]); 571 name = match_strdup(&args[0]);
@@ -559,7 +574,7 @@ static int parse_options(struct super_block *sb, char *options)
559 return -ENOMEM; 574 return -ENOMEM;
560 if (strlen(name) == 8 && 575 if (strlen(name) == 8 &&
561 !strncmp(name, "adaptive", 8)) { 576 !strncmp(name, "adaptive", 8)) {
562 if (f2fs_sb_mounted_blkzoned(sb)) { 577 if (f2fs_sb_has_blkzoned(sb)) {
563 f2fs_msg(sb, KERN_WARNING, 578 f2fs_msg(sb, KERN_WARNING,
564 "adaptive mode is not allowed with " 579 "adaptive mode is not allowed with "
565 "zoned block device feature"); 580 "zoned block device feature");
@@ -585,7 +600,7 @@ static int parse_options(struct super_block *sb, char *options)
585 1 << arg, BIO_MAX_PAGES); 600 1 << arg, BIO_MAX_PAGES);
586 return -EINVAL; 601 return -EINVAL;
587 } 602 }
588 sbi->write_io_size_bits = arg; 603 F2FS_OPTION(sbi).write_io_size_bits = arg;
589 break; 604 break;
590 case Opt_fault_injection: 605 case Opt_fault_injection:
591 if (args->from && match_int(args, &arg)) 606 if (args->from && match_int(args, &arg))
@@ -646,13 +661,13 @@ static int parse_options(struct super_block *sb, char *options)
646 return ret; 661 return ret;
647 break; 662 break;
648 case Opt_jqfmt_vfsold: 663 case Opt_jqfmt_vfsold:
649 sbi->s_jquota_fmt = QFMT_VFS_OLD; 664 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_OLD;
650 break; 665 break;
651 case Opt_jqfmt_vfsv0: 666 case Opt_jqfmt_vfsv0:
652 sbi->s_jquota_fmt = QFMT_VFS_V0; 667 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V0;
653 break; 668 break;
654 case Opt_jqfmt_vfsv1: 669 case Opt_jqfmt_vfsv1:
655 sbi->s_jquota_fmt = QFMT_VFS_V1; 670 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V1;
656 break; 671 break;
657 case Opt_noquota: 672 case Opt_noquota:
658 clear_opt(sbi, QUOTA); 673 clear_opt(sbi, QUOTA);
@@ -679,6 +694,73 @@ static int parse_options(struct super_block *sb, char *options)
679 "quota operations not supported"); 694 "quota operations not supported");
680 break; 695 break;
681#endif 696#endif
697 case Opt_whint:
698 name = match_strdup(&args[0]);
699 if (!name)
700 return -ENOMEM;
701 if (strlen(name) == 10 &&
702 !strncmp(name, "user-based", 10)) {
703 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_USER;
704 } else if (strlen(name) == 3 &&
705 !strncmp(name, "off", 3)) {
706 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
707 } else if (strlen(name) == 8 &&
708 !strncmp(name, "fs-based", 8)) {
709 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS;
710 } else {
711 kfree(name);
712 return -EINVAL;
713 }
714 kfree(name);
715 break;
716 case Opt_alloc:
717 name = match_strdup(&args[0]);
718 if (!name)
719 return -ENOMEM;
720
721 if (strlen(name) == 7 &&
722 !strncmp(name, "default", 7)) {
723 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
724 } else if (strlen(name) == 5 &&
725 !strncmp(name, "reuse", 5)) {
726 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
727 } else {
728 kfree(name);
729 return -EINVAL;
730 }
731 kfree(name);
732 break;
733 case Opt_fsync:
734 name = match_strdup(&args[0]);
735 if (!name)
736 return -ENOMEM;
737 if (strlen(name) == 5 &&
738 !strncmp(name, "posix", 5)) {
739 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
740 } else if (strlen(name) == 6 &&
741 !strncmp(name, "strict", 6)) {
742 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT;
743 } else {
744 kfree(name);
745 return -EINVAL;
746 }
747 kfree(name);
748 break;
749 case Opt_test_dummy_encryption:
750#ifdef CONFIG_F2FS_FS_ENCRYPTION
751 if (!f2fs_sb_has_encrypt(sb)) {
752 f2fs_msg(sb, KERN_ERR, "Encrypt feature is off");
753 return -EINVAL;
754 }
755
756 F2FS_OPTION(sbi).test_dummy_encryption = true;
757 f2fs_msg(sb, KERN_INFO,
758 "Test dummy encryption mode enabled");
759#else
760 f2fs_msg(sb, KERN_INFO,
761 "Test dummy encryption mount option ignored");
762#endif
763 break;
682 default: 764 default:
683 f2fs_msg(sb, KERN_ERR, 765 f2fs_msg(sb, KERN_ERR,
684 "Unrecognized mount option \"%s\" or missing value", 766 "Unrecognized mount option \"%s\" or missing value",
@@ -699,14 +781,22 @@ static int parse_options(struct super_block *sb, char *options)
699 } 781 }
700 782
701 if (test_opt(sbi, INLINE_XATTR_SIZE)) { 783 if (test_opt(sbi, INLINE_XATTR_SIZE)) {
784 if (!f2fs_sb_has_extra_attr(sb) ||
785 !f2fs_sb_has_flexible_inline_xattr(sb)) {
786 f2fs_msg(sb, KERN_ERR,
787 "extra_attr or flexible_inline_xattr "
788 "feature is off");
789 return -EINVAL;
790 }
702 if (!test_opt(sbi, INLINE_XATTR)) { 791 if (!test_opt(sbi, INLINE_XATTR)) {
703 f2fs_msg(sb, KERN_ERR, 792 f2fs_msg(sb, KERN_ERR,
704 "inline_xattr_size option should be " 793 "inline_xattr_size option should be "
705 "set with inline_xattr option"); 794 "set with inline_xattr option");
706 return -EINVAL; 795 return -EINVAL;
707 } 796 }
708 if (!sbi->inline_xattr_size || 797 if (!F2FS_OPTION(sbi).inline_xattr_size ||
709 sbi->inline_xattr_size >= DEF_ADDRS_PER_INODE - 798 F2FS_OPTION(sbi).inline_xattr_size >=
799 DEF_ADDRS_PER_INODE -
710 F2FS_TOTAL_EXTRA_ATTR_SIZE - 800 F2FS_TOTAL_EXTRA_ATTR_SIZE -
711 DEF_INLINE_RESERVED_SIZE - 801 DEF_INLINE_RESERVED_SIZE -
712 DEF_MIN_INLINE_SIZE) { 802 DEF_MIN_INLINE_SIZE) {
@@ -715,6 +805,12 @@ static int parse_options(struct super_block *sb, char *options)
715 return -EINVAL; 805 return -EINVAL;
716 } 806 }
717 } 807 }
808
809 /* Not pass down write hints if the number of active logs is lesser
810 * than NR_CURSEG_TYPE.
811 */
812 if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
813 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
718 return 0; 814 return 0;
719} 815}
720 816
@@ -731,7 +827,6 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)
731 /* Initialize f2fs-specific inode info */ 827 /* Initialize f2fs-specific inode info */
732 atomic_set(&fi->dirty_pages, 0); 828 atomic_set(&fi->dirty_pages, 0);
733 fi->i_current_depth = 1; 829 fi->i_current_depth = 1;
734 fi->i_advise = 0;
735 init_rwsem(&fi->i_sem); 830 init_rwsem(&fi->i_sem);
736 INIT_LIST_HEAD(&fi->dirty_list); 831 INIT_LIST_HEAD(&fi->dirty_list);
737 INIT_LIST_HEAD(&fi->gdirty_list); 832 INIT_LIST_HEAD(&fi->gdirty_list);
@@ -743,10 +838,6 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)
743 init_rwsem(&fi->i_mmap_sem); 838 init_rwsem(&fi->i_mmap_sem);
744 init_rwsem(&fi->i_xattr_sem); 839 init_rwsem(&fi->i_xattr_sem);
745 840
746#ifdef CONFIG_QUOTA
747 memset(&fi->i_dquot, 0, sizeof(fi->i_dquot));
748 fi->i_reserved_quota = 0;
749#endif
750 /* Will be used by directory only */ 841 /* Will be used by directory only */
751 fi->i_dir_level = F2FS_SB(sb)->dir_level; 842 fi->i_dir_level = F2FS_SB(sb)->dir_level;
752 843
@@ -956,7 +1047,7 @@ static void f2fs_put_super(struct super_block *sb)
956 mempool_destroy(sbi->write_io_dummy); 1047 mempool_destroy(sbi->write_io_dummy);
957#ifdef CONFIG_QUOTA 1048#ifdef CONFIG_QUOTA
958 for (i = 0; i < MAXQUOTAS; i++) 1049 for (i = 0; i < MAXQUOTAS; i++)
959 kfree(sbi->s_qf_names[i]); 1050 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
960#endif 1051#endif
961 destroy_percpu_info(sbi); 1052 destroy_percpu_info(sbi);
962 for (i = 0; i < NR_PAGE_TYPE; i++) 1053 for (i = 0; i < NR_PAGE_TYPE; i++)
@@ -1070,8 +1161,9 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
1070 buf->f_blocks = total_count - start_count; 1161 buf->f_blocks = total_count - start_count;
1071 buf->f_bfree = user_block_count - valid_user_blocks(sbi) - 1162 buf->f_bfree = user_block_count - valid_user_blocks(sbi) -
1072 sbi->current_reserved_blocks; 1163 sbi->current_reserved_blocks;
1073 if (buf->f_bfree > sbi->root_reserved_blocks) 1164 if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks)
1074 buf->f_bavail = buf->f_bfree - sbi->root_reserved_blocks; 1165 buf->f_bavail = buf->f_bfree -
1166 F2FS_OPTION(sbi).root_reserved_blocks;
1075 else 1167 else
1076 buf->f_bavail = 0; 1168 buf->f_bavail = 0;
1077 1169
@@ -1106,10 +1198,10 @@ static inline void f2fs_show_quota_options(struct seq_file *seq,
1106#ifdef CONFIG_QUOTA 1198#ifdef CONFIG_QUOTA
1107 struct f2fs_sb_info *sbi = F2FS_SB(sb); 1199 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1108 1200
1109 if (sbi->s_jquota_fmt) { 1201 if (F2FS_OPTION(sbi).s_jquota_fmt) {
1110 char *fmtname = ""; 1202 char *fmtname = "";
1111 1203
1112 switch (sbi->s_jquota_fmt) { 1204 switch (F2FS_OPTION(sbi).s_jquota_fmt) {
1113 case QFMT_VFS_OLD: 1205 case QFMT_VFS_OLD:
1114 fmtname = "vfsold"; 1206 fmtname = "vfsold";
1115 break; 1207 break;
@@ -1123,14 +1215,17 @@ static inline void f2fs_show_quota_options(struct seq_file *seq,
1123 seq_printf(seq, ",jqfmt=%s", fmtname); 1215 seq_printf(seq, ",jqfmt=%s", fmtname);
1124 } 1216 }
1125 1217
1126 if (sbi->s_qf_names[USRQUOTA]) 1218 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
1127 seq_show_option(seq, "usrjquota", sbi->s_qf_names[USRQUOTA]); 1219 seq_show_option(seq, "usrjquota",
1220 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]);
1128 1221
1129 if (sbi->s_qf_names[GRPQUOTA]) 1222 if (F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
1130 seq_show_option(seq, "grpjquota", sbi->s_qf_names[GRPQUOTA]); 1223 seq_show_option(seq, "grpjquota",
1224 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]);
1131 1225
1132 if (sbi->s_qf_names[PRJQUOTA]) 1226 if (F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
1133 seq_show_option(seq, "prjjquota", sbi->s_qf_names[PRJQUOTA]); 1227 seq_show_option(seq, "prjjquota",
1228 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]);
1134#endif 1229#endif
1135} 1230}
1136 1231
@@ -1165,7 +1260,7 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
1165 seq_puts(seq, ",noinline_xattr"); 1260 seq_puts(seq, ",noinline_xattr");
1166 if (test_opt(sbi, INLINE_XATTR_SIZE)) 1261 if (test_opt(sbi, INLINE_XATTR_SIZE))
1167 seq_printf(seq, ",inline_xattr_size=%u", 1262 seq_printf(seq, ",inline_xattr_size=%u",
1168 sbi->inline_xattr_size); 1263 F2FS_OPTION(sbi).inline_xattr_size);
1169#endif 1264#endif
1170#ifdef CONFIG_F2FS_FS_POSIX_ACL 1265#ifdef CONFIG_F2FS_FS_POSIX_ACL
1171 if (test_opt(sbi, POSIX_ACL)) 1266 if (test_opt(sbi, POSIX_ACL))
@@ -1201,18 +1296,20 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
1201 seq_puts(seq, "adaptive"); 1296 seq_puts(seq, "adaptive");
1202 else if (test_opt(sbi, LFS)) 1297 else if (test_opt(sbi, LFS))
1203 seq_puts(seq, "lfs"); 1298 seq_puts(seq, "lfs");
1204 seq_printf(seq, ",active_logs=%u", sbi->active_logs); 1299 seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs);
1205 if (test_opt(sbi, RESERVE_ROOT)) 1300 if (test_opt(sbi, RESERVE_ROOT))
1206 seq_printf(seq, ",reserve_root=%u,resuid=%u,resgid=%u", 1301 seq_printf(seq, ",reserve_root=%u,resuid=%u,resgid=%u",
1207 sbi->root_reserved_blocks, 1302 F2FS_OPTION(sbi).root_reserved_blocks,
1208 from_kuid_munged(&init_user_ns, sbi->s_resuid), 1303 from_kuid_munged(&init_user_ns,
1209 from_kgid_munged(&init_user_ns, sbi->s_resgid)); 1304 F2FS_OPTION(sbi).s_resuid),
1305 from_kgid_munged(&init_user_ns,
1306 F2FS_OPTION(sbi).s_resgid));
1210 if (F2FS_IO_SIZE_BITS(sbi)) 1307 if (F2FS_IO_SIZE_BITS(sbi))
1211 seq_printf(seq, ",io_size=%uKB", F2FS_IO_SIZE_KB(sbi)); 1308 seq_printf(seq, ",io_size=%uKB", F2FS_IO_SIZE_KB(sbi));
1212#ifdef CONFIG_F2FS_FAULT_INJECTION 1309#ifdef CONFIG_F2FS_FAULT_INJECTION
1213 if (test_opt(sbi, FAULT_INJECTION)) 1310 if (test_opt(sbi, FAULT_INJECTION))
1214 seq_printf(seq, ",fault_injection=%u", 1311 seq_printf(seq, ",fault_injection=%u",
1215 sbi->fault_info.inject_rate); 1312 F2FS_OPTION(sbi).fault_info.inject_rate);
1216#endif 1313#endif
1217#ifdef CONFIG_QUOTA 1314#ifdef CONFIG_QUOTA
1218 if (test_opt(sbi, QUOTA)) 1315 if (test_opt(sbi, QUOTA))
@@ -1225,15 +1322,37 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
1225 seq_puts(seq, ",prjquota"); 1322 seq_puts(seq, ",prjquota");
1226#endif 1323#endif
1227 f2fs_show_quota_options(seq, sbi->sb); 1324 f2fs_show_quota_options(seq, sbi->sb);
1325 if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_USER)
1326 seq_printf(seq, ",whint_mode=%s", "user-based");
1327 else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS)
1328 seq_printf(seq, ",whint_mode=%s", "fs-based");
1329#ifdef CONFIG_F2FS_FS_ENCRYPTION
1330 if (F2FS_OPTION(sbi).test_dummy_encryption)
1331 seq_puts(seq, ",test_dummy_encryption");
1332#endif
1333
1334 if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_DEFAULT)
1335 seq_printf(seq, ",alloc_mode=%s", "default");
1336 else if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE)
1337 seq_printf(seq, ",alloc_mode=%s", "reuse");
1228 1338
1339 if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX)
1340 seq_printf(seq, ",fsync_mode=%s", "posix");
1341 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT)
1342 seq_printf(seq, ",fsync_mode=%s", "strict");
1229 return 0; 1343 return 0;
1230} 1344}
1231 1345
1232static void default_options(struct f2fs_sb_info *sbi) 1346static void default_options(struct f2fs_sb_info *sbi)
1233{ 1347{
1234 /* init some FS parameters */ 1348 /* init some FS parameters */
1235 sbi->active_logs = NR_CURSEG_TYPE; 1349 F2FS_OPTION(sbi).active_logs = NR_CURSEG_TYPE;
1236 sbi->inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS; 1350 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
1351 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
1352 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
1353 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
1354 F2FS_OPTION(sbi).test_dummy_encryption = false;
1355 sbi->readdir_ra = 1;
1237 1356
1238 set_opt(sbi, BG_GC); 1357 set_opt(sbi, BG_GC);
1239 set_opt(sbi, INLINE_XATTR); 1358 set_opt(sbi, INLINE_XATTR);
@@ -1243,7 +1362,7 @@ static void default_options(struct f2fs_sb_info *sbi)
1243 set_opt(sbi, NOHEAP); 1362 set_opt(sbi, NOHEAP);
1244 sbi->sb->s_flags |= SB_LAZYTIME; 1363 sbi->sb->s_flags |= SB_LAZYTIME;
1245 set_opt(sbi, FLUSH_MERGE); 1364 set_opt(sbi, FLUSH_MERGE);
1246 if (f2fs_sb_mounted_blkzoned(sbi->sb)) { 1365 if (f2fs_sb_has_blkzoned(sbi->sb)) {
1247 set_opt_mode(sbi, F2FS_MOUNT_LFS); 1366 set_opt_mode(sbi, F2FS_MOUNT_LFS);
1248 set_opt(sbi, DISCARD); 1367 set_opt(sbi, DISCARD);
1249 } else { 1368 } else {
@@ -1270,16 +1389,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
1270 struct f2fs_sb_info *sbi = F2FS_SB(sb); 1389 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1271 struct f2fs_mount_info org_mount_opt; 1390 struct f2fs_mount_info org_mount_opt;
1272 unsigned long old_sb_flags; 1391 unsigned long old_sb_flags;
1273 int err, active_logs; 1392 int err;
1274 bool need_restart_gc = false; 1393 bool need_restart_gc = false;
1275 bool need_stop_gc = false; 1394 bool need_stop_gc = false;
1276 bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE); 1395 bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE);
1277#ifdef CONFIG_F2FS_FAULT_INJECTION
1278 struct f2fs_fault_info ffi = sbi->fault_info;
1279#endif
1280#ifdef CONFIG_QUOTA 1396#ifdef CONFIG_QUOTA
1281 int s_jquota_fmt;
1282 char *s_qf_names[MAXQUOTAS];
1283 int i, j; 1397 int i, j;
1284#endif 1398#endif
1285 1399
@@ -1289,21 +1403,21 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
1289 */ 1403 */
1290 org_mount_opt = sbi->mount_opt; 1404 org_mount_opt = sbi->mount_opt;
1291 old_sb_flags = sb->s_flags; 1405 old_sb_flags = sb->s_flags;
1292 active_logs = sbi->active_logs;
1293 1406
1294#ifdef CONFIG_QUOTA 1407#ifdef CONFIG_QUOTA
1295 s_jquota_fmt = sbi->s_jquota_fmt; 1408 org_mount_opt.s_jquota_fmt = F2FS_OPTION(sbi).s_jquota_fmt;
1296 for (i = 0; i < MAXQUOTAS; i++) { 1409 for (i = 0; i < MAXQUOTAS; i++) {
1297 if (sbi->s_qf_names[i]) { 1410 if (F2FS_OPTION(sbi).s_qf_names[i]) {
1298 s_qf_names[i] = kstrdup(sbi->s_qf_names[i], 1411 org_mount_opt.s_qf_names[i] =
1299 GFP_KERNEL); 1412 kstrdup(F2FS_OPTION(sbi).s_qf_names[i],
1300 if (!s_qf_names[i]) { 1413 GFP_KERNEL);
1414 if (!org_mount_opt.s_qf_names[i]) {
1301 for (j = 0; j < i; j++) 1415 for (j = 0; j < i; j++)
1302 kfree(s_qf_names[j]); 1416 kfree(org_mount_opt.s_qf_names[j]);
1303 return -ENOMEM; 1417 return -ENOMEM;
1304 } 1418 }
1305 } else { 1419 } else {
1306 s_qf_names[i] = NULL; 1420 org_mount_opt.s_qf_names[i] = NULL;
1307 } 1421 }
1308 } 1422 }
1309#endif 1423#endif
@@ -1373,7 +1487,8 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
1373 need_stop_gc = true; 1487 need_stop_gc = true;
1374 } 1488 }
1375 1489
1376 if (*flags & SB_RDONLY) { 1490 if (*flags & SB_RDONLY ||
1491 F2FS_OPTION(sbi).whint_mode != org_mount_opt.whint_mode) {
1377 writeback_inodes_sb(sb, WB_REASON_SYNC); 1492 writeback_inodes_sb(sb, WB_REASON_SYNC);
1378 sync_inodes_sb(sb); 1493 sync_inodes_sb(sb);
1379 1494
@@ -1399,7 +1514,7 @@ skip:
1399#ifdef CONFIG_QUOTA 1514#ifdef CONFIG_QUOTA
1400 /* Release old quota file names */ 1515 /* Release old quota file names */
1401 for (i = 0; i < MAXQUOTAS; i++) 1516 for (i = 0; i < MAXQUOTAS; i++)
1402 kfree(s_qf_names[i]); 1517 kfree(org_mount_opt.s_qf_names[i]);
1403#endif 1518#endif
1404 /* Update the POSIXACL Flag */ 1519 /* Update the POSIXACL Flag */
1405 sb->s_flags = (sb->s_flags & ~SB_POSIXACL) | 1520 sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
@@ -1417,18 +1532,14 @@ restore_gc:
1417 } 1532 }
1418restore_opts: 1533restore_opts:
1419#ifdef CONFIG_QUOTA 1534#ifdef CONFIG_QUOTA
1420 sbi->s_jquota_fmt = s_jquota_fmt; 1535 F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt;
1421 for (i = 0; i < MAXQUOTAS; i++) { 1536 for (i = 0; i < MAXQUOTAS; i++) {
1422 kfree(sbi->s_qf_names[i]); 1537 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
1423 sbi->s_qf_names[i] = s_qf_names[i]; 1538 F2FS_OPTION(sbi).s_qf_names[i] = org_mount_opt.s_qf_names[i];
1424 } 1539 }
1425#endif 1540#endif
1426 sbi->mount_opt = org_mount_opt; 1541 sbi->mount_opt = org_mount_opt;
1427 sbi->active_logs = active_logs;
1428 sb->s_flags = old_sb_flags; 1542 sb->s_flags = old_sb_flags;
1429#ifdef CONFIG_F2FS_FAULT_INJECTION
1430 sbi->fault_info = ffi;
1431#endif
1432 return err; 1543 return err;
1433} 1544}
1434 1545
@@ -1456,7 +1567,7 @@ static ssize_t f2fs_quota_read(struct super_block *sb, int type, char *data,
1456 while (toread > 0) { 1567 while (toread > 0) {
1457 tocopy = min_t(unsigned long, sb->s_blocksize - offset, toread); 1568 tocopy = min_t(unsigned long, sb->s_blocksize - offset, toread);
1458repeat: 1569repeat:
1459 page = read_mapping_page(mapping, blkidx, NULL); 1570 page = read_cache_page_gfp(mapping, blkidx, GFP_NOFS);
1460 if (IS_ERR(page)) { 1571 if (IS_ERR(page)) {
1461 if (PTR_ERR(page) == -ENOMEM) { 1572 if (PTR_ERR(page) == -ENOMEM) {
1462 congestion_wait(BLK_RW_ASYNC, HZ/50); 1573 congestion_wait(BLK_RW_ASYNC, HZ/50);
@@ -1550,8 +1661,8 @@ static qsize_t *f2fs_get_reserved_space(struct inode *inode)
1550 1661
1551static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type) 1662static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type)
1552{ 1663{
1553 return dquot_quota_on_mount(sbi->sb, sbi->s_qf_names[type], 1664 return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type],
1554 sbi->s_jquota_fmt, type); 1665 F2FS_OPTION(sbi).s_jquota_fmt, type);
1555} 1666}
1556 1667
1557int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly) 1668int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
@@ -1570,7 +1681,7 @@ int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
1570 } 1681 }
1571 1682
1572 for (i = 0; i < MAXQUOTAS; i++) { 1683 for (i = 0; i < MAXQUOTAS; i++) {
1573 if (sbi->s_qf_names[i]) { 1684 if (F2FS_OPTION(sbi).s_qf_names[i]) {
1574 err = f2fs_quota_on_mount(sbi, i); 1685 err = f2fs_quota_on_mount(sbi, i);
1575 if (!err) { 1686 if (!err) {
1576 enabled = 1; 1687 enabled = 1;
@@ -1797,11 +1908,28 @@ static int f2fs_get_context(struct inode *inode, void *ctx, size_t len)
1797static int f2fs_set_context(struct inode *inode, const void *ctx, size_t len, 1908static int f2fs_set_context(struct inode *inode, const void *ctx, size_t len,
1798 void *fs_data) 1909 void *fs_data)
1799{ 1910{
1911 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1912
1913 /*
1914 * Encrypting the root directory is not allowed because fsck
1915 * expects lost+found directory to exist and remain unencrypted
1916 * if LOST_FOUND feature is enabled.
1917 *
1918 */
1919 if (f2fs_sb_has_lost_found(sbi->sb) &&
1920 inode->i_ino == F2FS_ROOT_INO(sbi))
1921 return -EPERM;
1922
1800 return f2fs_setxattr(inode, F2FS_XATTR_INDEX_ENCRYPTION, 1923 return f2fs_setxattr(inode, F2FS_XATTR_INDEX_ENCRYPTION,
1801 F2FS_XATTR_NAME_ENCRYPTION_CONTEXT, 1924 F2FS_XATTR_NAME_ENCRYPTION_CONTEXT,
1802 ctx, len, fs_data, XATTR_CREATE); 1925 ctx, len, fs_data, XATTR_CREATE);
1803} 1926}
1804 1927
1928static bool f2fs_dummy_context(struct inode *inode)
1929{
1930 return DUMMY_ENCRYPTION_ENABLED(F2FS_I_SB(inode));
1931}
1932
1805static unsigned f2fs_max_namelen(struct inode *inode) 1933static unsigned f2fs_max_namelen(struct inode *inode)
1806{ 1934{
1807 return S_ISLNK(inode->i_mode) ? 1935 return S_ISLNK(inode->i_mode) ?
@@ -1812,6 +1940,7 @@ static const struct fscrypt_operations f2fs_cryptops = {
1812 .key_prefix = "f2fs:", 1940 .key_prefix = "f2fs:",
1813 .get_context = f2fs_get_context, 1941 .get_context = f2fs_get_context,
1814 .set_context = f2fs_set_context, 1942 .set_context = f2fs_set_context,
1943 .dummy_context = f2fs_dummy_context,
1815 .empty_dir = f2fs_empty_dir, 1944 .empty_dir = f2fs_empty_dir,
1816 .max_namelen = f2fs_max_namelen, 1945 .max_namelen = f2fs_max_namelen,
1817}; 1946};
@@ -1894,7 +2023,6 @@ static int __f2fs_commit_super(struct buffer_head *bh,
1894 lock_buffer(bh); 2023 lock_buffer(bh);
1895 if (super) 2024 if (super)
1896 memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super)); 2025 memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
1897 set_buffer_uptodate(bh);
1898 set_buffer_dirty(bh); 2026 set_buffer_dirty(bh);
1899 unlock_buffer(bh); 2027 unlock_buffer(bh);
1900 2028
@@ -2181,6 +2309,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
2181 2309
2182 sbi->dirty_device = 0; 2310 sbi->dirty_device = 0;
2183 spin_lock_init(&sbi->dev_lock); 2311 spin_lock_init(&sbi->dev_lock);
2312
2313 init_rwsem(&sbi->sb_lock);
2184} 2314}
2185 2315
2186static int init_percpu_info(struct f2fs_sb_info *sbi) 2316static int init_percpu_info(struct f2fs_sb_info *sbi)
@@ -2206,7 +2336,7 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
2206 unsigned int n = 0; 2336 unsigned int n = 0;
2207 int err = -EIO; 2337 int err = -EIO;
2208 2338
2209 if (!f2fs_sb_mounted_blkzoned(sbi->sb)) 2339 if (!f2fs_sb_has_blkzoned(sbi->sb))
2210 return 0; 2340 return 0;
2211 2341
2212 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != 2342 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=
@@ -2334,7 +2464,7 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
2334 } 2464 }
2335 2465
2336 /* write back-up superblock first */ 2466 /* write back-up superblock first */
2337 bh = sb_getblk(sbi->sb, sbi->valid_super_block ? 0: 1); 2467 bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1);
2338 if (!bh) 2468 if (!bh)
2339 return -EIO; 2469 return -EIO;
2340 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); 2470 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
@@ -2345,7 +2475,7 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
2345 return err; 2475 return err;
2346 2476
2347 /* write current valid superblock */ 2477 /* write current valid superblock */
2348 bh = sb_getblk(sbi->sb, sbi->valid_super_block); 2478 bh = sb_bread(sbi->sb, sbi->valid_super_block);
2349 if (!bh) 2479 if (!bh)
2350 return -EIO; 2480 return -EIO;
2351 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); 2481 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
@@ -2413,7 +2543,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
2413 2543
2414#ifdef CONFIG_BLK_DEV_ZONED 2544#ifdef CONFIG_BLK_DEV_ZONED
2415 if (bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HM && 2545 if (bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HM &&
2416 !f2fs_sb_mounted_blkzoned(sbi->sb)) { 2546 !f2fs_sb_has_blkzoned(sbi->sb)) {
2417 f2fs_msg(sbi->sb, KERN_ERR, 2547 f2fs_msg(sbi->sb, KERN_ERR,
2418 "Zoned block device feature not enabled\n"); 2548 "Zoned block device feature not enabled\n");
2419 return -EINVAL; 2549 return -EINVAL;
@@ -2447,6 +2577,18 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
2447 return 0; 2577 return 0;
2448} 2578}
2449 2579
2580static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi)
2581{
2582 struct f2fs_sm_info *sm_i = SM_I(sbi);
2583
2584 /* adjust parameters according to the volume size */
2585 if (sm_i->main_segments <= SMALL_VOLUME_SEGMENTS) {
2586 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
2587 sm_i->dcc_info->discard_granularity = 1;
2588 sm_i->ipu_policy = 1 << F2FS_IPU_FORCE;
2589 }
2590}
2591
2450static int f2fs_fill_super(struct super_block *sb, void *data, int silent) 2592static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
2451{ 2593{
2452 struct f2fs_sb_info *sbi; 2594 struct f2fs_sb_info *sbi;
@@ -2494,8 +2636,8 @@ try_onemore:
2494 sb->s_fs_info = sbi; 2636 sb->s_fs_info = sbi;
2495 sbi->raw_super = raw_super; 2637 sbi->raw_super = raw_super;
2496 2638
2497 sbi->s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID); 2639 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID);
2498 sbi->s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID); 2640 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID);
2499 2641
2500 /* precompute checksum seed for metadata */ 2642 /* precompute checksum seed for metadata */
2501 if (f2fs_sb_has_inode_chksum(sb)) 2643 if (f2fs_sb_has_inode_chksum(sb))
@@ -2508,7 +2650,7 @@ try_onemore:
2508 * devices, but mandatory for host-managed zoned block devices. 2650 * devices, but mandatory for host-managed zoned block devices.
2509 */ 2651 */
2510#ifndef CONFIG_BLK_DEV_ZONED 2652#ifndef CONFIG_BLK_DEV_ZONED
2511 if (f2fs_sb_mounted_blkzoned(sb)) { 2653 if (f2fs_sb_has_blkzoned(sb)) {
2512 f2fs_msg(sb, KERN_ERR, 2654 f2fs_msg(sb, KERN_ERR,
2513 "Zoned block device support is not enabled\n"); 2655 "Zoned block device support is not enabled\n");
2514 err = -EOPNOTSUPP; 2656 err = -EOPNOTSUPP;
@@ -2724,7 +2866,7 @@ try_onemore:
2724 * Turn on quotas which were not enabled for read-only mounts if 2866 * Turn on quotas which were not enabled for read-only mounts if
2725 * filesystem has quota feature, so that they are updated correctly. 2867 * filesystem has quota feature, so that they are updated correctly.
2726 */ 2868 */
2727 if (f2fs_sb_has_quota_ino(sb) && !sb_rdonly(sb)) { 2869 if (f2fs_sb_has_quota_ino(sb) && !f2fs_readonly(sb)) {
2728 err = f2fs_enable_quotas(sb); 2870 err = f2fs_enable_quotas(sb);
2729 if (err) { 2871 if (err) {
2730 f2fs_msg(sb, KERN_ERR, 2872 f2fs_msg(sb, KERN_ERR,
@@ -2799,6 +2941,8 @@ skip_recovery:
2799 2941
2800 f2fs_join_shrinker(sbi); 2942 f2fs_join_shrinker(sbi);
2801 2943
2944 f2fs_tuning_parameters(sbi);
2945
2802 f2fs_msg(sbi->sb, KERN_NOTICE, "Mounted with checkpoint version = %llx", 2946 f2fs_msg(sbi->sb, KERN_NOTICE, "Mounted with checkpoint version = %llx",
2803 cur_cp_version(F2FS_CKPT(sbi))); 2947 cur_cp_version(F2FS_CKPT(sbi)));
2804 f2fs_update_time(sbi, CP_TIME); 2948 f2fs_update_time(sbi, CP_TIME);
@@ -2807,7 +2951,7 @@ skip_recovery:
2807 2951
2808free_meta: 2952free_meta:
2809#ifdef CONFIG_QUOTA 2953#ifdef CONFIG_QUOTA
2810 if (f2fs_sb_has_quota_ino(sb) && !sb_rdonly(sb)) 2954 if (f2fs_sb_has_quota_ino(sb) && !f2fs_readonly(sb))
2811 f2fs_quota_off_umount(sbi->sb); 2955 f2fs_quota_off_umount(sbi->sb);
2812#endif 2956#endif
2813 f2fs_sync_inode_meta(sbi); 2957 f2fs_sync_inode_meta(sbi);
@@ -2851,7 +2995,7 @@ free_bio_info:
2851free_options: 2995free_options:
2852#ifdef CONFIG_QUOTA 2996#ifdef CONFIG_QUOTA
2853 for (i = 0; i < MAXQUOTAS; i++) 2997 for (i = 0; i < MAXQUOTAS; i++)
2854 kfree(sbi->s_qf_names[i]); 2998 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
2855#endif 2999#endif
2856 kfree(options); 3000 kfree(options);
2857free_sb_buf: 3001free_sb_buf:
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index d978c7b6ea04..f33a56d6e6dd 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -58,7 +58,7 @@ static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
58#ifdef CONFIG_F2FS_FAULT_INJECTION 58#ifdef CONFIG_F2FS_FAULT_INJECTION
59 else if (struct_type == FAULT_INFO_RATE || 59 else if (struct_type == FAULT_INFO_RATE ||
60 struct_type == FAULT_INFO_TYPE) 60 struct_type == FAULT_INFO_TYPE)
61 return (unsigned char *)&sbi->fault_info; 61 return (unsigned char *)&F2FS_OPTION(sbi).fault_info;
62#endif 62#endif
63 return NULL; 63 return NULL;
64} 64}
@@ -92,10 +92,10 @@ static ssize_t features_show(struct f2fs_attr *a,
92 if (!sb->s_bdev->bd_part) 92 if (!sb->s_bdev->bd_part)
93 return snprintf(buf, PAGE_SIZE, "0\n"); 93 return snprintf(buf, PAGE_SIZE, "0\n");
94 94
95 if (f2fs_sb_has_crypto(sb)) 95 if (f2fs_sb_has_encrypt(sb))
96 len += snprintf(buf, PAGE_SIZE - len, "%s", 96 len += snprintf(buf, PAGE_SIZE - len, "%s",
97 "encryption"); 97 "encryption");
98 if (f2fs_sb_mounted_blkzoned(sb)) 98 if (f2fs_sb_has_blkzoned(sb))
99 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 99 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
100 len ? ", " : "", "blkzoned"); 100 len ? ", " : "", "blkzoned");
101 if (f2fs_sb_has_extra_attr(sb)) 101 if (f2fs_sb_has_extra_attr(sb))
@@ -116,6 +116,9 @@ static ssize_t features_show(struct f2fs_attr *a,
116 if (f2fs_sb_has_inode_crtime(sb)) 116 if (f2fs_sb_has_inode_crtime(sb))
117 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 117 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
118 len ? ", " : "", "inode_crtime"); 118 len ? ", " : "", "inode_crtime");
119 if (f2fs_sb_has_lost_found(sb))
120 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
121 len ? ", " : "", "lost_found");
119 len += snprintf(buf + len, PAGE_SIZE - len, "\n"); 122 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
120 return len; 123 return len;
121} 124}
@@ -136,6 +139,27 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
136 if (!ptr) 139 if (!ptr)
137 return -EINVAL; 140 return -EINVAL;
138 141
142 if (!strcmp(a->attr.name, "extension_list")) {
143 __u8 (*extlist)[F2FS_EXTENSION_LEN] =
144 sbi->raw_super->extension_list;
145 int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
146 int hot_count = sbi->raw_super->hot_ext_count;
147 int len = 0, i;
148
149 len += snprintf(buf + len, PAGE_SIZE - len,
150 "cold file extenstion:\n");
151 for (i = 0; i < cold_count; i++)
152 len += snprintf(buf + len, PAGE_SIZE - len, "%s\n",
153 extlist[i]);
154
155 len += snprintf(buf + len, PAGE_SIZE - len,
156 "hot file extenstion:\n");
157 for (i = cold_count; i < cold_count + hot_count; i++)
158 len += snprintf(buf + len, PAGE_SIZE - len, "%s\n",
159 extlist[i]);
160 return len;
161 }
162
139 ui = (unsigned int *)(ptr + a->offset); 163 ui = (unsigned int *)(ptr + a->offset);
140 164
141 return snprintf(buf, PAGE_SIZE, "%u\n", *ui); 165 return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
@@ -154,6 +178,41 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
154 if (!ptr) 178 if (!ptr)
155 return -EINVAL; 179 return -EINVAL;
156 180
181 if (!strcmp(a->attr.name, "extension_list")) {
182 const char *name = strim((char *)buf);
183 bool set = true, hot;
184
185 if (!strncmp(name, "[h]", 3))
186 hot = true;
187 else if (!strncmp(name, "[c]", 3))
188 hot = false;
189 else
190 return -EINVAL;
191
192 name += 3;
193
194 if (*name == '!') {
195 name++;
196 set = false;
197 }
198
199 if (strlen(name) >= F2FS_EXTENSION_LEN)
200 return -EINVAL;
201
202 down_write(&sbi->sb_lock);
203
204 ret = update_extension_list(sbi, name, hot, set);
205 if (ret)
206 goto out;
207
208 ret = f2fs_commit_super(sbi, false);
209 if (ret)
210 update_extension_list(sbi, name, hot, !set);
211out:
212 up_write(&sbi->sb_lock);
213 return ret ? ret : count;
214 }
215
157 ui = (unsigned int *)(ptr + a->offset); 216 ui = (unsigned int *)(ptr + a->offset);
158 217
159 ret = kstrtoul(skip_spaces(buf), 0, &t); 218 ret = kstrtoul(skip_spaces(buf), 0, &t);
@@ -166,7 +225,7 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
166 if (a->struct_type == RESERVED_BLOCKS) { 225 if (a->struct_type == RESERVED_BLOCKS) {
167 spin_lock(&sbi->stat_lock); 226 spin_lock(&sbi->stat_lock);
168 if (t > (unsigned long)(sbi->user_block_count - 227 if (t > (unsigned long)(sbi->user_block_count -
169 sbi->root_reserved_blocks)) { 228 F2FS_OPTION(sbi).root_reserved_blocks)) {
170 spin_unlock(&sbi->stat_lock); 229 spin_unlock(&sbi->stat_lock);
171 return -EINVAL; 230 return -EINVAL;
172 } 231 }
@@ -236,6 +295,7 @@ enum feat_id {
236 FEAT_FLEXIBLE_INLINE_XATTR, 295 FEAT_FLEXIBLE_INLINE_XATTR,
237 FEAT_QUOTA_INO, 296 FEAT_QUOTA_INO,
238 FEAT_INODE_CRTIME, 297 FEAT_INODE_CRTIME,
298 FEAT_LOST_FOUND,
239}; 299};
240 300
241static ssize_t f2fs_feature_show(struct f2fs_attr *a, 301static ssize_t f2fs_feature_show(struct f2fs_attr *a,
@@ -251,6 +311,7 @@ static ssize_t f2fs_feature_show(struct f2fs_attr *a,
251 case FEAT_FLEXIBLE_INLINE_XATTR: 311 case FEAT_FLEXIBLE_INLINE_XATTR:
252 case FEAT_QUOTA_INO: 312 case FEAT_QUOTA_INO:
253 case FEAT_INODE_CRTIME: 313 case FEAT_INODE_CRTIME:
314 case FEAT_LOST_FOUND:
254 return snprintf(buf, PAGE_SIZE, "supported\n"); 315 return snprintf(buf, PAGE_SIZE, "supported\n");
255 } 316 }
256 return 0; 317 return 0;
@@ -307,6 +368,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
307F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable); 368F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
308F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra); 369F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
309F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold); 370F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold);
371F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list);
310#ifdef CONFIG_F2FS_FAULT_INJECTION 372#ifdef CONFIG_F2FS_FAULT_INJECTION
311F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate); 373F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
312F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type); 374F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
@@ -329,6 +391,7 @@ F2FS_FEATURE_RO_ATTR(inode_checksum, FEAT_INODE_CHECKSUM);
329F2FS_FEATURE_RO_ATTR(flexible_inline_xattr, FEAT_FLEXIBLE_INLINE_XATTR); 391F2FS_FEATURE_RO_ATTR(flexible_inline_xattr, FEAT_FLEXIBLE_INLINE_XATTR);
330F2FS_FEATURE_RO_ATTR(quota_ino, FEAT_QUOTA_INO); 392F2FS_FEATURE_RO_ATTR(quota_ino, FEAT_QUOTA_INO);
331F2FS_FEATURE_RO_ATTR(inode_crtime, FEAT_INODE_CRTIME); 393F2FS_FEATURE_RO_ATTR(inode_crtime, FEAT_INODE_CRTIME);
394F2FS_FEATURE_RO_ATTR(lost_found, FEAT_LOST_FOUND);
332 395
333#define ATTR_LIST(name) (&f2fs_attr_##name.attr) 396#define ATTR_LIST(name) (&f2fs_attr_##name.attr)
334static struct attribute *f2fs_attrs[] = { 397static struct attribute *f2fs_attrs[] = {
@@ -357,6 +420,7 @@ static struct attribute *f2fs_attrs[] = {
357 ATTR_LIST(iostat_enable), 420 ATTR_LIST(iostat_enable),
358 ATTR_LIST(readdir_ra), 421 ATTR_LIST(readdir_ra),
359 ATTR_LIST(gc_pin_file_thresh), 422 ATTR_LIST(gc_pin_file_thresh),
423 ATTR_LIST(extension_list),
360#ifdef CONFIG_F2FS_FAULT_INJECTION 424#ifdef CONFIG_F2FS_FAULT_INJECTION
361 ATTR_LIST(inject_rate), 425 ATTR_LIST(inject_rate),
362 ATTR_LIST(inject_type), 426 ATTR_LIST(inject_type),
@@ -383,6 +447,7 @@ static struct attribute *f2fs_feat_attrs[] = {
383 ATTR_LIST(flexible_inline_xattr), 447 ATTR_LIST(flexible_inline_xattr),
384 ATTR_LIST(quota_ino), 448 ATTR_LIST(quota_ino),
385 ATTR_LIST(inode_crtime), 449 ATTR_LIST(inode_crtime),
450 ATTR_LIST(lost_found),
386 NULL, 451 NULL,
387}; 452};
388 453
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
index 58aecb60ea51..aa5db8b5521a 100644
--- a/include/linux/f2fs_fs.h
+++ b/include/linux/f2fs_fs.h
@@ -21,6 +21,7 @@
21#define F2FS_BLKSIZE 4096 /* support only 4KB block */ 21#define F2FS_BLKSIZE 4096 /* support only 4KB block */
22#define F2FS_BLKSIZE_BITS 12 /* bits for F2FS_BLKSIZE */ 22#define F2FS_BLKSIZE_BITS 12 /* bits for F2FS_BLKSIZE */
23#define F2FS_MAX_EXTENSION 64 /* # of extension entries */ 23#define F2FS_MAX_EXTENSION 64 /* # of extension entries */
24#define F2FS_EXTENSION_LEN 8 /* max size of extension */
24#define F2FS_BLK_ALIGN(x) (((x) + F2FS_BLKSIZE - 1) >> F2FS_BLKSIZE_BITS) 25#define F2FS_BLK_ALIGN(x) (((x) + F2FS_BLKSIZE - 1) >> F2FS_BLKSIZE_BITS)
25 26
26#define NULL_ADDR ((block_t)0) /* used as block_t addresses */ 27#define NULL_ADDR ((block_t)0) /* used as block_t addresses */
@@ -38,15 +39,14 @@
38 39
39#define F2FS_MAX_QUOTAS 3 40#define F2FS_MAX_QUOTAS 3
40 41
41#define F2FS_IO_SIZE(sbi) (1 << (sbi)->write_io_size_bits) /* Blocks */ 42#define F2FS_IO_SIZE(sbi) (1 << F2FS_OPTION(sbi).write_io_size_bits) /* Blocks */
42#define F2FS_IO_SIZE_KB(sbi) (1 << ((sbi)->write_io_size_bits + 2)) /* KB */ 43#define F2FS_IO_SIZE_KB(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 2)) /* KB */
43#define F2FS_IO_SIZE_BYTES(sbi) (1 << ((sbi)->write_io_size_bits + 12)) /* B */ 44#define F2FS_IO_SIZE_BYTES(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 12)) /* B */
44#define F2FS_IO_SIZE_BITS(sbi) ((sbi)->write_io_size_bits) /* power of 2 */ 45#define F2FS_IO_SIZE_BITS(sbi) (F2FS_OPTION(sbi).write_io_size_bits) /* power of 2 */
45#define F2FS_IO_SIZE_MASK(sbi) (F2FS_IO_SIZE(sbi) - 1) 46#define F2FS_IO_SIZE_MASK(sbi) (F2FS_IO_SIZE(sbi) - 1)
46 47
47/* This flag is used by node and meta inodes, and by recovery */ 48/* This flag is used by node and meta inodes, and by recovery */
48#define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO) 49#define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO)
49#define GFP_F2FS_HIGH_ZERO (GFP_NOFS | __GFP_ZERO | __GFP_HIGHMEM)
50 50
51/* 51/*
52 * For further optimization on multi-head logs, on-disk layout supports maximum 52 * For further optimization on multi-head logs, on-disk layout supports maximum
@@ -102,7 +102,7 @@ struct f2fs_super_block {
102 __u8 uuid[16]; /* 128-bit uuid for volume */ 102 __u8 uuid[16]; /* 128-bit uuid for volume */
103 __le16 volume_name[MAX_VOLUME_NAME]; /* volume name */ 103 __le16 volume_name[MAX_VOLUME_NAME]; /* volume name */
104 __le32 extension_count; /* # of extensions below */ 104 __le32 extension_count; /* # of extensions below */
105 __u8 extension_list[F2FS_MAX_EXTENSION][8]; /* extension array */ 105 __u8 extension_list[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN];/* extension array */
106 __le32 cp_payload; 106 __le32 cp_payload;
107 __u8 version[VERSION_LEN]; /* the kernel version */ 107 __u8 version[VERSION_LEN]; /* the kernel version */
108 __u8 init_version[VERSION_LEN]; /* the initial kernel version */ 108 __u8 init_version[VERSION_LEN]; /* the initial kernel version */
@@ -111,12 +111,14 @@ struct f2fs_super_block {
111 __u8 encrypt_pw_salt[16]; /* Salt used for string2key algorithm */ 111 __u8 encrypt_pw_salt[16]; /* Salt used for string2key algorithm */
112 struct f2fs_device devs[MAX_DEVICES]; /* device list */ 112 struct f2fs_device devs[MAX_DEVICES]; /* device list */
113 __le32 qf_ino[F2FS_MAX_QUOTAS]; /* quota inode numbers */ 113 __le32 qf_ino[F2FS_MAX_QUOTAS]; /* quota inode numbers */
114 __u8 reserved[315]; /* valid reserved region */ 114 __u8 hot_ext_count; /* # of hot file extension */
115 __u8 reserved[314]; /* valid reserved region */
115} __packed; 116} __packed;
116 117
117/* 118/*
118 * For checkpoint 119 * For checkpoint
119 */ 120 */
121#define CP_LARGE_NAT_BITMAP_FLAG 0x00000400
120#define CP_NOCRC_RECOVERY_FLAG 0x00000200 122#define CP_NOCRC_RECOVERY_FLAG 0x00000200
121#define CP_TRIMMED_FLAG 0x00000100 123#define CP_TRIMMED_FLAG 0x00000100
122#define CP_NAT_BITS_FLAG 0x00000080 124#define CP_NAT_BITS_FLAG 0x00000080
@@ -303,6 +305,10 @@ struct f2fs_node {
303 */ 305 */
304#define NAT_ENTRY_PER_BLOCK (PAGE_SIZE / sizeof(struct f2fs_nat_entry)) 306#define NAT_ENTRY_PER_BLOCK (PAGE_SIZE / sizeof(struct f2fs_nat_entry))
305#define NAT_ENTRY_BITMAP_SIZE ((NAT_ENTRY_PER_BLOCK + 7) / 8) 307#define NAT_ENTRY_BITMAP_SIZE ((NAT_ENTRY_PER_BLOCK + 7) / 8)
308#define NAT_ENTRY_BITMAP_SIZE_ALIGNED \
309 ((NAT_ENTRY_BITMAP_SIZE + BITS_PER_LONG - 1) / \
310 BITS_PER_LONG * BITS_PER_LONG)
311
306 312
307struct f2fs_nat_entry { 313struct f2fs_nat_entry {
308 __u8 version; /* latest version of cached nat entry */ 314 __u8 version; /* latest version of cached nat entry */