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

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull f2fs updates from Jaegeuk Kim:
"In this cycle, we've mainly investigated the zoned block device
support along with patches such as correcting write pointers between
f2fs and storage, adding asynchronous zone reset flow, and managing
the number of open zones.

Other than them, f2fs adds another mount option, "errors=x" to specify
how to handle when it detects an unexpected behavior at runtime.

Enhancements:
- support 'errors=remount-ro|continue|panic' mount option
- enforce some inode flag policies
- allow .tmp compression given extensions
- add some ioctls to manage the f2fs compression
- improve looped node chain flow
- avoid issuing small-sized discard commands during checkpoint
- implement an asynchronous zone reset

Bug fixes:
- fix deadlock in xattr and inode page lock
- fix and add sanity check in some error paths
- fix to avoid NULL pointer dereference f2fs_write_end_io() along
with put_super
- set proper flags to quota files
- fix potential deadlock due to unpaired node_write lock use
- fix over-estimating free section during FG GC
- fix the wrong condition to determine atomic context

As usual, also there are a number of patches with code refactoring and
minor clean-ups"

* tag 'f2fs-for-6.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (46 commits)
f2fs: fix to do sanity check on direct node in truncate_dnode()
f2fs: only set release for file that has compressed data
f2fs: fix compile warning in f2fs_destroy_node_manager()
f2fs: fix error path handling in truncate_dnode()
f2fs: fix deadlock in i_xattr_sem and inode page lock
f2fs: remove unneeded page uptodate check/set
f2fs: update mtime and ctime in move file range method
f2fs: compress tmp files given extension
f2fs: refactor struct f2fs_attr macro
f2fs: convert to use sbi directly
f2fs: remove redundant assignment to variable err
f2fs: do not issue small discard commands during checkpoint
f2fs: check zone write pointer points to the end of zone
f2fs: add f2fs_ioc_get_compress_blocks
f2fs: cleanup MIN_INLINE_XATTR_SIZE
f2fs: add helper to check compression level
f2fs: set FMODE_CAN_ODIRECT instead of a dummy direct_IO method
f2fs: do more sanity check on inode
f2fs: compress: fix to check validity of i_compress_flag field
f2fs: add sanity compress level check for compressed file
...

+1071 -409
+16
Documentation/filesystems/f2fs.rst
··· 351 351 data block update frequency of the extent per inode, in 352 352 order to provide better temperature hints for data block 353 353 allocation. 354 + errors=%s Specify f2fs behavior on critical errors. This supports modes: 355 + "panic", "continue" and "remount-ro", respectively, trigger 356 + panic immediately, continue without doing anything, and remount 357 + the partition in read-only mode. By default it uses "continue" 358 + mode. 359 + ====================== =============== =============== ======== 360 + mode continue remount-ro panic 361 + ====================== =============== =============== ======== 362 + access ops normal noraml N/A 363 + syscall errors -EIO -EROFS N/A 364 + mount option rw ro N/A 365 + pending dir write keep keep N/A 366 + pending non-dir write drop keep N/A 367 + pending node write drop keep N/A 368 + pending meta write keep keep N/A 369 + ====================== =============== =============== ======== 354 370 ======================== ============================================================ 355 371 356 372 Debugfs Entries
+2 -5
fs/f2fs/checkpoint.c
··· 30 30 unsigned char reason) 31 31 { 32 32 f2fs_build_fault_attr(sbi, 0, 0); 33 - set_ckpt_flags(sbi, CP_ERROR_FLAG); 34 - if (!end_io) { 33 + if (!end_io) 35 34 f2fs_flush_merged_writes(sbi); 36 - 37 - f2fs_handle_stop(sbi, reason); 38 - } 35 + f2fs_handle_critical_error(sbi, reason, end_io); 39 36 } 40 37 41 38 /*
+34 -7
fs/f2fs/compress.c
··· 55 55 int (*init_decompress_ctx)(struct decompress_io_ctx *dic); 56 56 void (*destroy_decompress_ctx)(struct decompress_io_ctx *dic); 57 57 int (*decompress_pages)(struct decompress_io_ctx *dic); 58 + bool (*is_level_valid)(int level); 58 59 }; 59 60 60 61 static unsigned int offset_in_cluster(struct compress_ctx *cc, pgoff_t index) ··· 309 308 return 0; 310 309 } 311 310 311 + static bool lz4_is_level_valid(int lvl) 312 + { 313 + #ifdef CONFIG_F2FS_FS_LZ4HC 314 + return !lvl || (lvl >= LZ4HC_MIN_CLEVEL && lvl <= LZ4HC_MAX_CLEVEL); 315 + #else 316 + return lvl == 0; 317 + #endif 318 + } 319 + 312 320 static const struct f2fs_compress_ops f2fs_lz4_ops = { 313 321 .init_compress_ctx = lz4_init_compress_ctx, 314 322 .destroy_compress_ctx = lz4_destroy_compress_ctx, 315 323 .compress_pages = lz4_compress_pages, 316 324 .decompress_pages = lz4_decompress_pages, 325 + .is_level_valid = lz4_is_level_valid, 317 326 }; 318 327 #endif 319 328 320 329 #ifdef CONFIG_F2FS_FS_ZSTD 321 - #define F2FS_ZSTD_DEFAULT_CLEVEL 1 322 - 323 330 static int zstd_init_compress_ctx(struct compress_ctx *cc) 324 331 { 325 332 zstd_parameters params; ··· 336 327 unsigned int workspace_size; 337 328 unsigned char level = F2FS_I(cc->inode)->i_compress_level; 338 329 330 + /* Need to remain this for backward compatibility */ 339 331 if (!level) 340 332 level = F2FS_ZSTD_DEFAULT_CLEVEL; 341 333 ··· 487 477 return 0; 488 478 } 489 479 480 + static bool zstd_is_level_valid(int lvl) 481 + { 482 + return lvl >= zstd_min_clevel() && lvl <= zstd_max_clevel(); 483 + } 484 + 490 485 static const struct f2fs_compress_ops f2fs_zstd_ops = { 491 486 .init_compress_ctx = zstd_init_compress_ctx, 492 487 .destroy_compress_ctx = zstd_destroy_compress_ctx, ··· 499 484 .init_decompress_ctx = zstd_init_decompress_ctx, 500 485 .destroy_decompress_ctx = zstd_destroy_decompress_ctx, 501 486 .decompress_pages = zstd_decompress_pages, 487 + .is_level_valid = zstd_is_level_valid, 502 488 }; 503 489 #endif 504 490 ··· 556 540 if (!f2fs_compressed_file(inode)) 557 541 return true; 558 542 return f2fs_cops[F2FS_I(inode)->i_compress_algorithm]; 543 + } 544 + 545 + bool f2fs_is_compress_level_valid(int alg, int lvl) 546 + { 547 + const struct f2fs_compress_ops *cops = f2fs_cops[alg]; 548 + 549 + if (cops->is_level_valid) 550 + return cops->is_level_valid(lvl); 551 + 552 + return lvl == 0; 559 553 } 560 554 561 555 static mempool_t *compress_page_pool; ··· 769 743 ret = -EFSCORRUPTED; 770 744 771 745 /* Avoid f2fs_commit_super in irq context */ 772 - if (in_task) 773 - f2fs_save_errors(sbi, ERROR_FAIL_DECOMPRESSION); 746 + if (!in_task) 747 + f2fs_handle_error_async(sbi, ERROR_FAIL_DECOMPRESSION); 774 748 else 775 749 f2fs_handle_error(sbi, ERROR_FAIL_DECOMPRESSION); 776 750 goto out_release; ··· 1241 1215 unsigned int last_index = cc->cluster_size - 1; 1242 1216 loff_t psize; 1243 1217 int i, err; 1218 + bool quota_inode = IS_NOQUOTA(inode); 1244 1219 1245 1220 /* we should bypass data pages to proceed the kworker jobs */ 1246 1221 if (unlikely(f2fs_cp_error(sbi))) { ··· 1249 1222 goto out_free; 1250 1223 } 1251 1224 1252 - if (IS_NOQUOTA(inode)) { 1225 + if (quota_inode) { 1253 1226 /* 1254 1227 * We need to wait for node_write to avoid block allocation during 1255 1228 * checkpoint. This can only happen to quota writes which can cause ··· 1371 1344 set_inode_flag(inode, FI_FIRST_BLOCK_WRITTEN); 1372 1345 1373 1346 f2fs_put_dnode(&dn); 1374 - if (IS_NOQUOTA(inode)) 1347 + if (quota_inode) 1375 1348 f2fs_up_read(&sbi->node_write); 1376 1349 else 1377 1350 f2fs_unlock_op(sbi); ··· 1397 1370 out_put_dnode: 1398 1371 f2fs_put_dnode(&dn); 1399 1372 out_unlock_op: 1400 - if (IS_NOQUOTA(inode)) 1373 + if (quota_inode) 1401 1374 f2fs_up_read(&sbi->node_write); 1402 1375 else 1403 1376 f2fs_unlock_op(sbi);
+66 -5
fs/f2fs/data.c
··· 383 383 bio_put(bio); 384 384 } 385 385 386 + #ifdef CONFIG_BLK_DEV_ZONED 387 + static void f2fs_zone_write_end_io(struct bio *bio) 388 + { 389 + struct f2fs_bio_info *io = (struct f2fs_bio_info *)bio->bi_private; 390 + 391 + bio->bi_private = io->bi_private; 392 + complete(&io->zone_wait); 393 + f2fs_write_end_io(bio); 394 + } 395 + #endif 396 + 386 397 struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 387 398 block_t blk_addr, sector_t *sector) 388 399 { ··· 650 639 INIT_LIST_HEAD(&sbi->write_io[i][j].io_list); 651 640 INIT_LIST_HEAD(&sbi->write_io[i][j].bio_list); 652 641 init_f2fs_rwsem(&sbi->write_io[i][j].bio_list_lock); 642 + #ifdef CONFIG_BLK_DEV_ZONED 643 + init_completion(&sbi->write_io[i][j].zone_wait); 644 + sbi->write_io[i][j].zone_pending_bio = NULL; 645 + sbi->write_io[i][j].bi_private = NULL; 646 + #endif 653 647 } 654 648 } 655 649 ··· 981 965 return 0; 982 966 } 983 967 968 + #ifdef CONFIG_BLK_DEV_ZONED 969 + static bool is_end_zone_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr) 970 + { 971 + int devi = 0; 972 + 973 + if (f2fs_is_multi_device(sbi)) { 974 + devi = f2fs_target_device_index(sbi, blkaddr); 975 + if (blkaddr < FDEV(devi).start_blk || 976 + blkaddr > FDEV(devi).end_blk) { 977 + f2fs_err(sbi, "Invalid block %x", blkaddr); 978 + return false; 979 + } 980 + blkaddr -= FDEV(devi).start_blk; 981 + } 982 + return bdev_zoned_model(FDEV(devi).bdev) == BLK_ZONED_HM && 983 + f2fs_blkz_is_seq(sbi, devi, blkaddr) && 984 + (blkaddr % sbi->blocks_per_blkz == sbi->blocks_per_blkz - 1); 985 + } 986 + #endif 987 + 984 988 void f2fs_submit_page_write(struct f2fs_io_info *fio) 985 989 { 986 990 struct f2fs_sb_info *sbi = fio->sbi; ··· 1011 975 f2fs_bug_on(sbi, is_read_io(fio->op)); 1012 976 1013 977 f2fs_down_write(&io->io_rwsem); 978 + 979 + #ifdef CONFIG_BLK_DEV_ZONED 980 + if (f2fs_sb_has_blkzoned(sbi) && btype < META && io->zone_pending_bio) { 981 + wait_for_completion_io(&io->zone_wait); 982 + bio_put(io->zone_pending_bio); 983 + io->zone_pending_bio = NULL; 984 + io->bi_private = NULL; 985 + } 986 + #endif 987 + 1014 988 next: 1015 989 if (fio->in_list) { 1016 990 spin_lock(&io->io_lock); ··· 1084 1038 if (fio->in_list) 1085 1039 goto next; 1086 1040 out: 1041 + #ifdef CONFIG_BLK_DEV_ZONED 1042 + if (f2fs_sb_has_blkzoned(sbi) && btype < META && 1043 + is_end_zone_blkaddr(sbi, fio->new_blkaddr)) { 1044 + bio_get(io->bio); 1045 + reinit_completion(&io->zone_wait); 1046 + io->bi_private = io->bio->bi_private; 1047 + io->bio->bi_private = io; 1048 + io->bio->bi_end_io = f2fs_zone_write_end_io; 1049 + io->zone_pending_bio = io->bio; 1050 + __submit_merged_bio(io); 1051 + } 1052 + #endif 1087 1053 if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) || 1088 1054 !f2fs_is_checkpoint_ready(sbi)) 1089 1055 __submit_merged_bio(io); ··· 2231 2173 f2fs_update_iostat(F2FS_I_SB(inode), NULL, FS_DATA_READ_IO, 2232 2174 F2FS_BLKSIZE); 2233 2175 *last_block_in_bio = block_nr; 2234 - goto out; 2235 2176 out: 2236 2177 *bio_ret = bio; 2237 2178 return ret; ··· 2832 2775 loff_t psize = (loff_t)(page->index + 1) << PAGE_SHIFT; 2833 2776 unsigned offset = 0; 2834 2777 bool need_balance_fs = false; 2778 + bool quota_inode = IS_NOQUOTA(inode); 2835 2779 int err = 0; 2836 2780 struct f2fs_io_info fio = { 2837 2781 .sbi = sbi, ··· 2865 2807 if (S_ISDIR(inode->i_mode) && 2866 2808 !is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 2867 2809 goto redirty_out; 2810 + 2811 + /* keep data pages in remount-ro mode */ 2812 + if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_READONLY) 2813 + goto redirty_out; 2868 2814 goto out; 2869 2815 } 2870 2816 ··· 2894 2832 goto out; 2895 2833 2896 2834 /* Dentry/quota blocks are controlled by checkpoint */ 2897 - if (S_ISDIR(inode->i_mode) || IS_NOQUOTA(inode)) { 2835 + if (S_ISDIR(inode->i_mode) || quota_inode) { 2898 2836 /* 2899 2837 * We need to wait for node_write to avoid block allocation during 2900 2838 * checkpoint. This can only happen to quota writes which can cause 2901 2839 * the below discard race condition. 2902 2840 */ 2903 - if (IS_NOQUOTA(inode)) 2841 + if (quota_inode) 2904 2842 f2fs_down_read(&sbi->node_write); 2905 2843 2906 2844 fio.need_lock = LOCK_DONE; 2907 2845 err = f2fs_do_write_data_page(&fio); 2908 2846 2909 - if (IS_NOQUOTA(inode)) 2847 + if (quota_inode) 2910 2848 f2fs_up_read(&sbi->node_write); 2911 2849 2912 2850 goto done; ··· 4129 4067 .migrate_folio = filemap_migrate_folio, 4130 4068 .invalidate_folio = f2fs_invalidate_folio, 4131 4069 .release_folio = f2fs_release_folio, 4132 - .direct_IO = noop_direct_IO, 4133 4070 .bmap = f2fs_bmap, 4134 4071 .swap_activate = f2fs_swap_activate, 4135 4072 .swap_deactivate = f2fs_swap_deactivate,
+8 -1
fs/f2fs/dir.c
··· 775 775 { 776 776 int err = -EAGAIN; 777 777 778 - if (f2fs_has_inline_dentry(dir)) 778 + if (f2fs_has_inline_dentry(dir)) { 779 + /* 780 + * Should get i_xattr_sem to keep the lock order: 781 + * i_xattr_sem -> inode_page lock used by f2fs_setxattr. 782 + */ 783 + f2fs_down_read(&F2FS_I(dir)->i_xattr_sem); 779 784 err = f2fs_add_inline_entry(dir, fname, inode, ino, mode); 785 + f2fs_up_read(&F2FS_I(dir)->i_xattr_sem); 786 + } 780 787 if (err == -EAGAIN) 781 788 err = f2fs_add_regular_entry(dir, fname, inode, ino, mode); 782 789
+76 -48
fs/f2fs/f2fs.h
··· 80 80 /* 81 81 * For mount options 82 82 */ 83 - #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 84 - #define F2FS_MOUNT_DISCARD 0x00000004 85 - #define F2FS_MOUNT_NOHEAP 0x00000008 86 - #define F2FS_MOUNT_XATTR_USER 0x00000010 87 - #define F2FS_MOUNT_POSIX_ACL 0x00000020 88 - #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 89 - #define F2FS_MOUNT_INLINE_XATTR 0x00000080 90 - #define F2FS_MOUNT_INLINE_DATA 0x00000100 91 - #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 92 - #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 93 - #define F2FS_MOUNT_NOBARRIER 0x00000800 94 - #define F2FS_MOUNT_FASTBOOT 0x00001000 95 - #define F2FS_MOUNT_READ_EXTENT_CACHE 0x00002000 96 - #define F2FS_MOUNT_DATA_FLUSH 0x00008000 97 - #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 98 - #define F2FS_MOUNT_USRQUOTA 0x00080000 99 - #define F2FS_MOUNT_GRPQUOTA 0x00100000 100 - #define F2FS_MOUNT_PRJQUOTA 0x00200000 101 - #define F2FS_MOUNT_QUOTA 0x00400000 102 - #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 103 - #define F2FS_MOUNT_RESERVE_ROOT 0x01000000 104 - #define F2FS_MOUNT_DISABLE_CHECKPOINT 0x02000000 105 - #define F2FS_MOUNT_NORECOVERY 0x04000000 106 - #define F2FS_MOUNT_ATGC 0x08000000 107 - #define F2FS_MOUNT_MERGE_CHECKPOINT 0x10000000 108 - #define F2FS_MOUNT_GC_MERGE 0x20000000 109 - #define F2FS_MOUNT_COMPRESS_CACHE 0x40000000 110 - #define F2FS_MOUNT_AGE_EXTENT_CACHE 0x80000000 83 + #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000001 84 + #define F2FS_MOUNT_DISCARD 0x00000002 85 + #define F2FS_MOUNT_NOHEAP 0x00000004 86 + #define F2FS_MOUNT_XATTR_USER 0x00000008 87 + #define F2FS_MOUNT_POSIX_ACL 0x00000010 88 + #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000020 89 + #define F2FS_MOUNT_INLINE_XATTR 0x00000040 90 + #define F2FS_MOUNT_INLINE_DATA 0x00000080 91 + #define F2FS_MOUNT_INLINE_DENTRY 0x00000100 92 + #define F2FS_MOUNT_FLUSH_MERGE 0x00000200 93 + #define F2FS_MOUNT_NOBARRIER 0x00000400 94 + #define F2FS_MOUNT_FASTBOOT 0x00000800 95 + #define F2FS_MOUNT_READ_EXTENT_CACHE 0x00001000 96 + #define F2FS_MOUNT_DATA_FLUSH 0x00002000 97 + #define F2FS_MOUNT_FAULT_INJECTION 0x00004000 98 + #define F2FS_MOUNT_USRQUOTA 0x00008000 99 + #define F2FS_MOUNT_GRPQUOTA 0x00010000 100 + #define F2FS_MOUNT_PRJQUOTA 0x00020000 101 + #define F2FS_MOUNT_QUOTA 0x00040000 102 + #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00080000 103 + #define F2FS_MOUNT_RESERVE_ROOT 0x00100000 104 + #define F2FS_MOUNT_DISABLE_CHECKPOINT 0x00200000 105 + #define F2FS_MOUNT_NORECOVERY 0x00400000 106 + #define F2FS_MOUNT_ATGC 0x00800000 107 + #define F2FS_MOUNT_MERGE_CHECKPOINT 0x01000000 108 + #define F2FS_MOUNT_GC_MERGE 0x02000000 109 + #define F2FS_MOUNT_COMPRESS_CACHE 0x04000000 110 + #define F2FS_MOUNT_AGE_EXTENT_CACHE 0x08000000 111 111 112 112 #define F2FS_OPTION(sbi) ((sbi)->mount_opt) 113 113 #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option) ··· 162 162 int fs_mode; /* fs mode: LFS or ADAPTIVE */ 163 163 int bggc_mode; /* bggc mode: off, on or sync */ 164 164 int memory_mode; /* memory mode */ 165 + int errors; /* errors parameter */ 165 166 int discard_unit; /* 166 167 * discard command's offset/size should 167 168 * be aligned to this unit: block, ··· 186 185 unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */ 187 186 }; 188 187 189 - #define F2FS_FEATURE_ENCRYPT 0x0001 190 - #define F2FS_FEATURE_BLKZONED 0x0002 191 - #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 192 - #define F2FS_FEATURE_EXTRA_ATTR 0x0008 193 - #define F2FS_FEATURE_PRJQUOTA 0x0010 194 - #define F2FS_FEATURE_INODE_CHKSUM 0x0020 195 - #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 196 - #define F2FS_FEATURE_QUOTA_INO 0x0080 197 - #define F2FS_FEATURE_INODE_CRTIME 0x0100 198 - #define F2FS_FEATURE_LOST_FOUND 0x0200 199 - #define F2FS_FEATURE_VERITY 0x0400 200 - #define F2FS_FEATURE_SB_CHKSUM 0x0800 201 - #define F2FS_FEATURE_CASEFOLD 0x1000 202 - #define F2FS_FEATURE_COMPRESSION 0x2000 203 - #define F2FS_FEATURE_RO 0x4000 188 + #define F2FS_FEATURE_ENCRYPT 0x00000001 189 + #define F2FS_FEATURE_BLKZONED 0x00000002 190 + #define F2FS_FEATURE_ATOMIC_WRITE 0x00000004 191 + #define F2FS_FEATURE_EXTRA_ATTR 0x00000008 192 + #define F2FS_FEATURE_PRJQUOTA 0x00000010 193 + #define F2FS_FEATURE_INODE_CHKSUM 0x00000020 194 + #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x00000040 195 + #define F2FS_FEATURE_QUOTA_INO 0x00000080 196 + #define F2FS_FEATURE_INODE_CRTIME 0x00000100 197 + #define F2FS_FEATURE_LOST_FOUND 0x00000200 198 + #define F2FS_FEATURE_VERITY 0x00000400 199 + #define F2FS_FEATURE_SB_CHKSUM 0x00000800 200 + #define F2FS_FEATURE_CASEFOLD 0x00001000 201 + #define F2FS_FEATURE_COMPRESSION 0x00002000 202 + #define F2FS_FEATURE_RO 0x00004000 204 203 205 204 #define __F2FS_HAS_FEATURE(raw_super, mask) \ 206 205 ((raw_super->feature & cpu_to_le32(mask)) != 0) ··· 1176 1175 /* other */ 1177 1176 FS_DISCARD_IO, /* discard */ 1178 1177 FS_FLUSH_IO, /* flush */ 1178 + FS_ZONE_RESET_IO, /* zone reset */ 1179 1179 NR_IO_TYPE, 1180 1180 }; 1181 1181 ··· 1219 1217 struct bio *bio; /* bios to merge */ 1220 1218 sector_t last_block_in_bio; /* last block number */ 1221 1219 struct f2fs_io_info fio; /* store buffered io info. */ 1220 + #ifdef CONFIG_BLK_DEV_ZONED 1221 + struct completion zone_wait; /* condition value for the previous open zone to close */ 1222 + struct bio *zone_pending_bio; /* pending bio for the previous zone */ 1223 + void *bi_private; /* previous bi_private for pending bio */ 1224 + #endif 1222 1225 struct f2fs_rwsem io_rwsem; /* blocking op for bio */ 1223 1226 spinlock_t io_lock; /* serialize DATA/NODE IOs */ 1224 1227 struct list_head io_list; /* track fios */ ··· 1377 1370 MEMORY_MODE_LOW, /* memory mode for low memry devices */ 1378 1371 }; 1379 1372 1373 + enum errors_option { 1374 + MOUNT_ERRORS_READONLY, /* remount fs ro on errors */ 1375 + MOUNT_ERRORS_CONTINUE, /* continue on errors */ 1376 + MOUNT_ERRORS_PANIC, /* panic on errors */ 1377 + }; 1378 + 1380 1379 static inline int f2fs_test_bit(unsigned int nr, char *addr); 1381 1380 static inline void f2fs_set_bit(unsigned int nr, char *addr); 1382 1381 static inline void f2fs_clear_bit(unsigned int nr, char *addr); ··· 1439 1426 #define COMPRESS_HEADER_SIZE (sizeof(struct compress_data)) 1440 1427 1441 1428 #define F2FS_COMPRESSED_PAGE_MAGIC 0xF5F2C000 1429 + 1430 + #define F2FS_ZSTD_DEFAULT_CLEVEL 1 1442 1431 1443 1432 #define COMPRESS_LEVEL_OFFSET 8 1444 1433 ··· 1736 1721 1737 1722 struct workqueue_struct *post_read_wq; /* post read workqueue */ 1738 1723 1739 - unsigned char errors[MAX_F2FS_ERRORS]; /* error flags */ 1740 - spinlock_t error_lock; /* protect errors array */ 1724 + /* 1725 + * If we are in irq context, let's update error information into 1726 + * on-disk superblock in the work. 1727 + */ 1728 + struct work_struct s_error_work; 1729 + unsigned char errors[MAX_F2FS_ERRORS]; /* error flags */ 1730 + unsigned char stop_reason[MAX_STOP_REASON]; /* stop reason */ 1731 + spinlock_t error_lock; /* protect errors/stop_reason array */ 1741 1732 bool error_dirty; /* errors of sb is dirty */ 1742 1733 1743 1734 struct kmem_cache *inline_xattr_slab; /* inline xattr entry */ ··· 2962 2941 #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ 2963 2942 #define F2FS_CASEFOLD_FL 0x40000000 /* Casefolded file */ 2964 2943 2944 + #define F2FS_QUOTA_DEFAULT_FL (F2FS_NOATIME_FL | F2FS_IMMUTABLE_FL) 2945 + 2965 2946 /* Flags that should be inherited by new inodes from their parent. */ 2966 2947 #define F2FS_FL_INHERITED (F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL | \ 2967 2948 F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ ··· 3417 3394 ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 3418 3395 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 3419 3396 3397 + #define F2FS_MIN_EXTRA_ATTR_SIZE (sizeof(__le32)) 3398 + 3420 3399 #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ 3421 3400 (offsetof(struct f2fs_inode, i_extra_end) - \ 3422 3401 offsetof(struct f2fs_inode, i_extra_isize)) \ ··· 3457 3432 * file.c 3458 3433 */ 3459 3434 int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 3460 - void f2fs_truncate_data_blocks(struct dnode_of_data *dn); 3461 3435 int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock); 3462 3436 int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock); 3463 3437 int f2fs_truncate(struct inode *inode); ··· 3565 3541 int f2fs_quota_sync(struct super_block *sb, int type); 3566 3542 loff_t max_file_blocks(struct inode *inode); 3567 3543 void f2fs_quota_off_umount(struct super_block *sb); 3568 - void f2fs_handle_stop(struct f2fs_sb_info *sbi, unsigned char reason); 3569 3544 void f2fs_save_errors(struct f2fs_sb_info *sbi, unsigned char flag); 3545 + void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason, 3546 + bool irq_context); 3570 3547 void f2fs_handle_error(struct f2fs_sb_info *sbi, unsigned char error); 3548 + void f2fs_handle_error_async(struct f2fs_sb_info *sbi, unsigned char error); 3571 3549 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 3572 3550 int f2fs_sync_fs(struct super_block *sb, int sync); 3573 3551 int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); ··· 3841 3815 block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 3842 3816 int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control); 3843 3817 void f2fs_build_gc_manager(struct f2fs_sb_info *sbi); 3844 - int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count); 3818 + int f2fs_resize_fs(struct file *filp, __u64 block_count); 3845 3819 int __init f2fs_create_garbage_collection_cache(void); 3846 3820 void f2fs_destroy_garbage_collection_cache(void); 3847 3821 /* victim selection function for cleaning and SSR */ ··· 4239 4213 int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool lock); 4240 4214 void f2fs_compress_write_end_io(struct bio *bio, struct page *page); 4241 4215 bool f2fs_is_compress_backend_ready(struct inode *inode); 4216 + bool f2fs_is_compress_level_valid(int alg, int lvl); 4242 4217 int __init f2fs_init_compress_mempool(void); 4243 4218 void f2fs_destroy_compress_mempool(void); 4244 4219 void f2fs_decompress_cluster(struct decompress_io_ctx *dic, bool in_task); ··· 4304 4277 /* not support compression */ 4305 4278 return false; 4306 4279 } 4280 + static inline bool f2fs_is_compress_level_valid(int alg, int lvl) { return false; } 4307 4281 static inline struct page *f2fs_compress_control_page(struct page *page) 4308 4282 { 4309 4283 WARN_ON_ONCE(1);
+48 -29
fs/f2fs/file.c
··· 149 149 zero_user_segment(page, offset, PAGE_SIZE); 150 150 } 151 151 set_page_dirty(page); 152 - if (!PageUptodate(page)) 153 - SetPageUptodate(page); 154 152 155 153 f2fs_update_iostat(sbi, inode, APP_MAPPED_IO, F2FS_BLKSIZE); 156 154 f2fs_update_time(sbi, REQ_TIME); ··· 544 546 if (err) 545 547 return err; 546 548 547 - filp->f_mode |= FMODE_NOWAIT; 549 + filp->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC; 550 + filp->f_mode |= FMODE_CAN_ODIRECT; 548 551 549 552 return dquot_file_open(inode, filp); 550 553 } ··· 624 625 f2fs_update_time(sbi, REQ_TIME); 625 626 trace_f2fs_truncate_data_blocks_range(dn->inode, dn->nid, 626 627 dn->ofs_in_node, nr_free); 627 - } 628 - 629 - void f2fs_truncate_data_blocks(struct dnode_of_data *dn) 630 - { 631 - f2fs_truncate_data_blocks_range(dn, ADDRS_PER_BLOCK(dn->inode)); 632 628 } 633 629 634 630 static int truncate_partial_data_page(struct inode *inode, u64 from, ··· 2219 2225 ret = 0; 2220 2226 f2fs_stop_checkpoint(sbi, false, 2221 2227 STOP_CP_REASON_SHUTDOWN); 2222 - set_sbi_flag(sbi, SBI_IS_SHUTDOWN); 2223 2228 trace_f2fs_shutdown(sbi, in, ret); 2224 2229 } 2225 2230 return ret; ··· 2231 2238 if (ret) 2232 2239 goto out; 2233 2240 f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_SHUTDOWN); 2234 - set_sbi_flag(sbi, SBI_IS_SHUTDOWN); 2235 2241 thaw_bdev(sb->s_bdev); 2236 2242 break; 2237 2243 case F2FS_GOING_DOWN_METASYNC: ··· 2239 2247 if (ret) 2240 2248 goto out; 2241 2249 f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_SHUTDOWN); 2242 - set_sbi_flag(sbi, SBI_IS_SHUTDOWN); 2243 2250 break; 2244 2251 case F2FS_GOING_DOWN_NOSYNC: 2245 2252 f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_SHUTDOWN); 2246 - set_sbi_flag(sbi, SBI_IS_SHUTDOWN); 2247 2253 break; 2248 2254 case F2FS_GOING_DOWN_METAFLUSH: 2249 2255 f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_META_IO); 2250 2256 f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_SHUTDOWN); 2251 - set_sbi_flag(sbi, SBI_IS_SHUTDOWN); 2252 2257 break; 2253 2258 case F2FS_GOING_DOWN_NEED_FSCK: 2254 2259 set_sbi_flag(sbi, SBI_NEED_FSCK); ··· 2582 2593 2583 2594 inode_lock(inode); 2584 2595 2596 + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { 2597 + err = -EINVAL; 2598 + goto unlock_out; 2599 + } 2600 + 2585 2601 /* if in-place-update policy is enabled, don't waste time here */ 2586 2602 set_inode_flag(inode, FI_OPU_WRITE); 2587 2603 if (f2fs_should_update_inplace(inode, NULL)) { ··· 2711 2717 clear_inode_flag(inode, FI_SKIP_WRITES); 2712 2718 out: 2713 2719 clear_inode_flag(inode, FI_OPU_WRITE); 2720 + unlock_out: 2714 2721 inode_unlock(inode); 2715 2722 if (!err) 2716 2723 range->len = (u64)total << PAGE_SHIFT; ··· 2871 2876 f2fs_up_write(&F2FS_I(dst)->i_gc_rwsem[WRITE]); 2872 2877 out_src: 2873 2878 f2fs_up_write(&F2FS_I(src)->i_gc_rwsem[WRITE]); 2879 + if (ret) 2880 + goto out_unlock; 2881 + 2882 + src->i_mtime = src->i_ctime = current_time(src); 2883 + f2fs_mark_inode_dirty_sync(src, false); 2884 + if (src != dst) { 2885 + dst->i_mtime = dst->i_ctime = current_time(dst); 2886 + f2fs_mark_inode_dirty_sync(dst, false); 2887 + } 2888 + f2fs_update_time(sbi, REQ_TIME); 2889 + 2874 2890 out_unlock: 2875 2891 if (src != dst) 2876 2892 inode_unlock(dst); ··· 3284 3278 sizeof(block_count))) 3285 3279 return -EFAULT; 3286 3280 3287 - return f2fs_resize_fs(sbi, block_count); 3281 + return f2fs_resize_fs(filp, block_count); 3288 3282 } 3289 3283 3290 3284 static int f2fs_ioc_enable_verity(struct file *filp, unsigned long arg) ··· 3381 3375 return err; 3382 3376 } 3383 3377 3384 - static int f2fs_get_compress_blocks(struct file *filp, unsigned long arg) 3378 + static int f2fs_get_compress_blocks(struct inode *inode, __u64 *blocks) 3385 3379 { 3386 - struct inode *inode = file_inode(filp); 3387 - __u64 blocks; 3388 - 3389 3380 if (!f2fs_sb_has_compression(F2FS_I_SB(inode))) 3390 3381 return -EOPNOTSUPP; 3391 3382 3392 3383 if (!f2fs_compressed_file(inode)) 3393 3384 return -EINVAL; 3394 3385 3395 - blocks = atomic_read(&F2FS_I(inode)->i_compr_blocks); 3386 + *blocks = atomic_read(&F2FS_I(inode)->i_compr_blocks); 3387 + 3388 + return 0; 3389 + } 3390 + 3391 + static int f2fs_ioc_get_compress_blocks(struct file *filp, unsigned long arg) 3392 + { 3393 + struct inode *inode = file_inode(filp); 3394 + __u64 blocks; 3395 + int ret; 3396 + 3397 + ret = f2fs_get_compress_blocks(inode, &blocks); 3398 + if (ret < 0) 3399 + return ret; 3400 + 3396 3401 return put_user(blocks, (u64 __user *)arg); 3397 3402 } 3398 3403 ··· 3472 3455 int ret; 3473 3456 int writecount; 3474 3457 3475 - if (!f2fs_sb_has_compression(F2FS_I_SB(inode))) 3458 + if (!f2fs_sb_has_compression(sbi)) 3476 3459 return -EOPNOTSUPP; 3477 3460 3478 3461 if (!f2fs_compressed_file(inode)) ··· 3485 3468 if (ret) 3486 3469 return ret; 3487 3470 3488 - f2fs_balance_fs(F2FS_I_SB(inode), true); 3471 + f2fs_balance_fs(sbi, true); 3489 3472 3490 3473 inode_lock(inode); 3491 3474 ··· 3505 3488 if (ret) 3506 3489 goto out; 3507 3490 3491 + if (!atomic_read(&F2FS_I(inode)->i_compr_blocks)) { 3492 + ret = -EPERM; 3493 + goto out; 3494 + } 3495 + 3508 3496 set_inode_flag(inode, FI_COMPRESS_RELEASED); 3509 3497 inode->i_ctime = current_time(inode); 3510 3498 f2fs_mark_inode_dirty_sync(inode, true); 3511 - 3512 - if (!atomic_read(&F2FS_I(inode)->i_compr_blocks)) 3513 - goto out; 3514 3499 3515 3500 f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 3516 3501 filemap_invalidate_lock(inode->i_mapping); ··· 3644 3625 unsigned int reserved_blocks = 0; 3645 3626 int ret; 3646 3627 3647 - if (!f2fs_sb_has_compression(F2FS_I_SB(inode))) 3628 + if (!f2fs_sb_has_compression(sbi)) 3648 3629 return -EOPNOTSUPP; 3649 3630 3650 3631 if (!f2fs_compressed_file(inode)) ··· 3660 3641 if (atomic_read(&F2FS_I(inode)->i_compr_blocks)) 3661 3642 goto out; 3662 3643 3663 - f2fs_balance_fs(F2FS_I_SB(inode), true); 3644 + f2fs_balance_fs(sbi, true); 3664 3645 3665 3646 inode_lock(inode); 3666 3647 ··· 4054 4035 if (!f2fs_compressed_file(inode)) 4055 4036 return -EINVAL; 4056 4037 4057 - f2fs_balance_fs(F2FS_I_SB(inode), true); 4038 + f2fs_balance_fs(sbi, true); 4058 4039 4059 4040 file_start_write(filp); 4060 4041 inode_lock(inode); ··· 4129 4110 if (!f2fs_compressed_file(inode)) 4130 4111 return -EINVAL; 4131 4112 4132 - f2fs_balance_fs(F2FS_I_SB(inode), true); 4113 + f2fs_balance_fs(sbi, true); 4133 4114 4134 4115 file_start_write(filp); 4135 4116 inode_lock(inode); ··· 4257 4238 case FS_IOC_SETFSLABEL: 4258 4239 return f2fs_ioc_setfslabel(filp, arg); 4259 4240 case F2FS_IOC_GET_COMPRESS_BLOCKS: 4260 - return f2fs_get_compress_blocks(filp, arg); 4241 + return f2fs_ioc_get_compress_blocks(filp, arg); 4261 4242 case F2FS_IOC_RELEASE_COMPRESS_BLOCKS: 4262 4243 return f2fs_release_compress_blocks(filp, arg); 4263 4244 case F2FS_IOC_RESERVE_COMPRESS_BLOCKS:
+33 -10
fs/f2fs/gc.c
··· 59 59 if (gc_th->gc_wake) 60 60 gc_th->gc_wake = false; 61 61 62 - if (try_to_freeze()) { 62 + if (try_to_freeze() || f2fs_readonly(sbi->sb)) { 63 63 stat_other_skip_bggc_count(sbi); 64 64 continue; 65 65 } ··· 1797 1797 { 1798 1798 int gc_type = gc_control->init_gc_type; 1799 1799 unsigned int segno = gc_control->victim_segno; 1800 - int sec_freed = 0, seg_freed = 0, total_freed = 0; 1800 + int sec_freed = 0, seg_freed = 0, total_freed = 0, total_sec_freed = 0; 1801 1801 int ret = 0; 1802 1802 struct cp_control cpc; 1803 1803 struct gc_inode_list gc_list = { ··· 1842 1842 ret = f2fs_write_checkpoint(sbi, &cpc); 1843 1843 if (ret) 1844 1844 goto stop; 1845 + /* Reset due to checkpoint */ 1846 + sec_freed = 0; 1845 1847 } 1846 1848 } 1847 1849 ··· 1868 1866 gc_control->should_migrate_blocks); 1869 1867 total_freed += seg_freed; 1870 1868 1871 - if (seg_freed == f2fs_usable_segs_in_sec(sbi, segno)) 1869 + if (seg_freed == f2fs_usable_segs_in_sec(sbi, segno)) { 1872 1870 sec_freed++; 1871 + total_sec_freed++; 1872 + } 1873 1873 1874 1874 if (gc_type == FG_GC) { 1875 1875 sbi->cur_victim_sec = NULL_SEGNO; 1876 1876 1877 1877 if (has_enough_free_secs(sbi, sec_freed, 0)) { 1878 1878 if (!gc_control->no_bg_gc && 1879 - sec_freed < gc_control->nr_free_secs) 1879 + total_sec_freed < gc_control->nr_free_secs) 1880 1880 goto go_gc_more; 1881 1881 goto stop; 1882 1882 } ··· 1905 1901 ret = f2fs_write_checkpoint(sbi, &cpc); 1906 1902 if (ret) 1907 1903 goto stop; 1904 + /* Reset due to checkpoint */ 1905 + sec_freed = 0; 1908 1906 } 1909 1907 go_gc_more: 1910 1908 segno = NULL_SEGNO; ··· 1919 1913 if (gc_type == FG_GC) 1920 1914 f2fs_unpin_all_sections(sbi, true); 1921 1915 1922 - trace_f2fs_gc_end(sbi->sb, ret, total_freed, sec_freed, 1916 + trace_f2fs_gc_end(sbi->sb, ret, total_freed, total_sec_freed, 1923 1917 get_pages(sbi, F2FS_DIRTY_NODES), 1924 1918 get_pages(sbi, F2FS_DIRTY_DENTS), 1925 1919 get_pages(sbi, F2FS_DIRTY_IMETA), ··· 1933 1927 put_gc_inode(&gc_list); 1934 1928 1935 1929 if (gc_control->err_gc_skipped && !ret) 1936 - ret = sec_freed ? 0 : -EAGAIN; 1930 + ret = total_sec_freed ? 0 : -EAGAIN; 1937 1931 return ret; 1938 1932 } 1939 1933 ··· 2105 2099 } 2106 2100 } 2107 2101 2108 - int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count) 2102 + int f2fs_resize_fs(struct file *filp, __u64 block_count) 2109 2103 { 2104 + struct f2fs_sb_info *sbi = F2FS_I_SB(file_inode(filp)); 2110 2105 __u64 old_block_count, shrunk_blocks; 2111 2106 struct cp_control cpc = { CP_RESIZE, 0, 0, 0 }; 2112 2107 unsigned int secs; ··· 2145 2138 return -EINVAL; 2146 2139 } 2147 2140 2141 + err = mnt_want_write_file(filp); 2142 + if (err) 2143 + return err; 2144 + 2148 2145 shrunk_blocks = old_block_count - block_count; 2149 2146 secs = div_u64(shrunk_blocks, BLKS_PER_SEC(sbi)); 2150 2147 2151 2148 /* stop other GC */ 2152 - if (!f2fs_down_write_trylock(&sbi->gc_lock)) 2153 - return -EAGAIN; 2149 + if (!f2fs_down_write_trylock(&sbi->gc_lock)) { 2150 + err = -EAGAIN; 2151 + goto out_drop_write; 2152 + } 2154 2153 2155 2154 /* stop CP to protect MAIN_SEC in free_segment_range */ 2156 2155 f2fs_lock_op(sbi); ··· 2176 2163 out_unlock: 2177 2164 f2fs_unlock_op(sbi); 2178 2165 f2fs_up_write(&sbi->gc_lock); 2166 + out_drop_write: 2167 + mnt_drop_write_file(filp); 2179 2168 if (err) 2180 2169 return err; 2181 2170 2182 - freeze_super(sbi->sb); 2171 + err = freeze_super(sbi->sb); 2172 + if (err) 2173 + return err; 2174 + 2175 + if (f2fs_readonly(sbi->sb)) { 2176 + thaw_super(sbi->sb); 2177 + return -EROFS; 2178 + } 2179 + 2183 2180 f2fs_down_write(&sbi->gc_lock); 2184 2181 f2fs_down_write(&sbi->cp_global_sem); 2185 2182
+143 -64
fs/f2fs/inode.c
··· 10 10 #include <linux/buffer_head.h> 11 11 #include <linux/writeback.h> 12 12 #include <linux/sched/mm.h> 13 + #include <linux/lz4.h> 14 + #include <linux/zstd.h> 13 15 14 16 #include "f2fs.h" 15 17 #include "node.h" ··· 204 202 ri->i_inode_checksum = cpu_to_le32(f2fs_inode_chksum(sbi, page)); 205 203 } 206 204 205 + static bool sanity_check_compress_inode(struct inode *inode, 206 + struct f2fs_inode *ri) 207 + { 208 + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 209 + unsigned char clevel; 210 + 211 + if (ri->i_compress_algorithm >= COMPRESS_MAX) { 212 + f2fs_warn(sbi, 213 + "%s: inode (ino=%lx) has unsupported compress algorithm: %u, run fsck to fix", 214 + __func__, inode->i_ino, ri->i_compress_algorithm); 215 + goto err; 216 + } 217 + if (le64_to_cpu(ri->i_compr_blocks) > 218 + SECTOR_TO_BLOCK(inode->i_blocks)) { 219 + f2fs_warn(sbi, 220 + "%s: inode (ino=%lx) has inconsistent i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix", 221 + __func__, inode->i_ino, le64_to_cpu(ri->i_compr_blocks), 222 + SECTOR_TO_BLOCK(inode->i_blocks)); 223 + goto err; 224 + } 225 + if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE || 226 + ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) { 227 + f2fs_warn(sbi, 228 + "%s: inode (ino=%lx) has unsupported log cluster size: %u, run fsck to fix", 229 + __func__, inode->i_ino, ri->i_log_cluster_size); 230 + goto err; 231 + } 232 + 233 + clevel = le16_to_cpu(ri->i_compress_flag) >> 234 + COMPRESS_LEVEL_OFFSET; 235 + switch (ri->i_compress_algorithm) { 236 + case COMPRESS_LZO: 237 + #ifdef CONFIG_F2FS_FS_LZO 238 + if (clevel) 239 + goto err_level; 240 + #endif 241 + break; 242 + case COMPRESS_LZORLE: 243 + #ifdef CONFIG_F2FS_FS_LZORLE 244 + if (clevel) 245 + goto err_level; 246 + #endif 247 + break; 248 + case COMPRESS_LZ4: 249 + #ifdef CONFIG_F2FS_FS_LZ4 250 + #ifdef CONFIG_F2FS_FS_LZ4HC 251 + if (clevel && 252 + (clevel < LZ4HC_MIN_CLEVEL || clevel > LZ4HC_MAX_CLEVEL)) 253 + goto err_level; 254 + #else 255 + if (clevel) 256 + goto err_level; 257 + #endif 258 + #endif 259 + break; 260 + case COMPRESS_ZSTD: 261 + #ifdef CONFIG_F2FS_FS_ZSTD 262 + if (clevel < zstd_min_clevel() || clevel > zstd_max_clevel()) 263 + goto err_level; 264 + #endif 265 + break; 266 + default: 267 + goto err_level; 268 + } 269 + 270 + return true; 271 + err_level: 272 + f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported compress level: %u, run fsck to fix", 273 + __func__, inode->i_ino, clevel); 274 + err: 275 + set_sbi_flag(sbi, SBI_NEED_FSCK); 276 + return false; 277 + } 278 + 207 279 static bool sanity_check_inode(struct inode *inode, struct page *node_page) 208 280 { 209 281 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); ··· 301 225 return false; 302 226 } 303 227 304 - if (f2fs_sb_has_flexible_inline_xattr(sbi) 305 - && !f2fs_has_extra_attr(inode)) { 228 + if (f2fs_has_extra_attr(inode)) { 229 + if (!f2fs_sb_has_extra_attr(sbi)) { 230 + set_sbi_flag(sbi, SBI_NEED_FSCK); 231 + f2fs_warn(sbi, "%s: inode (ino=%lx) is with extra_attr, but extra_attr feature is off", 232 + __func__, inode->i_ino); 233 + return false; 234 + } 235 + if (fi->i_extra_isize > F2FS_TOTAL_EXTRA_ATTR_SIZE || 236 + fi->i_extra_isize < F2FS_MIN_EXTRA_ATTR_SIZE || 237 + fi->i_extra_isize % sizeof(__le32)) { 238 + set_sbi_flag(sbi, SBI_NEED_FSCK); 239 + f2fs_warn(sbi, "%s: inode (ino=%lx) has corrupted i_extra_isize: %d, max: %zu", 240 + __func__, inode->i_ino, fi->i_extra_isize, 241 + F2FS_TOTAL_EXTRA_ATTR_SIZE); 242 + return false; 243 + } 244 + if (f2fs_sb_has_flexible_inline_xattr(sbi) && 245 + f2fs_has_inline_xattr(inode) && 246 + (!fi->i_inline_xattr_size || 247 + fi->i_inline_xattr_size > MAX_INLINE_XATTR_SIZE)) { 248 + set_sbi_flag(sbi, SBI_NEED_FSCK); 249 + f2fs_warn(sbi, "%s: inode (ino=%lx) has corrupted i_inline_xattr_size: %d, max: %zu", 250 + __func__, inode->i_ino, fi->i_inline_xattr_size, 251 + MAX_INLINE_XATTR_SIZE); 252 + return false; 253 + } 254 + if (f2fs_sb_has_compression(sbi) && 255 + fi->i_flags & F2FS_COMPR_FL && 256 + F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, 257 + i_compress_flag)) { 258 + if (!sanity_check_compress_inode(inode, ri)) 259 + return false; 260 + } 261 + } else if (f2fs_sb_has_flexible_inline_xattr(sbi)) { 306 262 set_sbi_flag(sbi, SBI_NEED_FSCK); 307 263 f2fs_warn(sbi, "%s: corrupted inode ino=%lx, run fsck to fix.", 308 264 __func__, inode->i_ino); 309 265 return false; 310 266 } 311 267 312 - if (f2fs_has_extra_attr(inode) && 313 - !f2fs_sb_has_extra_attr(sbi)) { 314 - set_sbi_flag(sbi, SBI_NEED_FSCK); 315 - f2fs_warn(sbi, "%s: inode (ino=%lx) is with extra_attr, but extra_attr feature is off", 316 - __func__, inode->i_ino); 317 - return false; 318 - } 319 - 320 - if (fi->i_extra_isize > F2FS_TOTAL_EXTRA_ATTR_SIZE || 321 - fi->i_extra_isize % sizeof(__le32)) { 322 - set_sbi_flag(sbi, SBI_NEED_FSCK); 323 - f2fs_warn(sbi, "%s: inode (ino=%lx) has corrupted i_extra_isize: %d, max: %zu", 324 - __func__, inode->i_ino, fi->i_extra_isize, 325 - F2FS_TOTAL_EXTRA_ATTR_SIZE); 326 - return false; 327 - } 328 - 329 - if (f2fs_has_extra_attr(inode) && 330 - f2fs_sb_has_flexible_inline_xattr(sbi) && 331 - f2fs_has_inline_xattr(inode) && 332 - (!fi->i_inline_xattr_size || 333 - fi->i_inline_xattr_size > MAX_INLINE_XATTR_SIZE)) { 334 - set_sbi_flag(sbi, SBI_NEED_FSCK); 335 - f2fs_warn(sbi, "%s: inode (ino=%lx) has corrupted i_inline_xattr_size: %d, max: %zu", 336 - __func__, inode->i_ino, fi->i_inline_xattr_size, 337 - MAX_INLINE_XATTR_SIZE); 338 - return false; 268 + if (!f2fs_sb_has_extra_attr(sbi)) { 269 + if (f2fs_sb_has_project_quota(sbi)) { 270 + set_sbi_flag(sbi, SBI_NEED_FSCK); 271 + f2fs_warn(sbi, "%s: corrupted inode ino=%lx, wrong feature flag: %u, run fsck to fix.", 272 + __func__, inode->i_ino, F2FS_FEATURE_PRJQUOTA); 273 + return false; 274 + } 275 + if (f2fs_sb_has_inode_chksum(sbi)) { 276 + set_sbi_flag(sbi, SBI_NEED_FSCK); 277 + f2fs_warn(sbi, "%s: corrupted inode ino=%lx, wrong feature flag: %u, run fsck to fix.", 278 + __func__, inode->i_ino, F2FS_FEATURE_INODE_CHKSUM); 279 + return false; 280 + } 281 + if (f2fs_sb_has_flexible_inline_xattr(sbi)) { 282 + set_sbi_flag(sbi, SBI_NEED_FSCK); 283 + f2fs_warn(sbi, "%s: corrupted inode ino=%lx, wrong feature flag: %u, run fsck to fix.", 284 + __func__, inode->i_ino, F2FS_FEATURE_FLEXIBLE_INLINE_XATTR); 285 + return false; 286 + } 287 + if (f2fs_sb_has_inode_crtime(sbi)) { 288 + set_sbi_flag(sbi, SBI_NEED_FSCK); 289 + f2fs_warn(sbi, "%s: corrupted inode ino=%lx, wrong feature flag: %u, run fsck to fix.", 290 + __func__, inode->i_ino, F2FS_FEATURE_INODE_CRTIME); 291 + return false; 292 + } 293 + if (f2fs_sb_has_compression(sbi)) { 294 + set_sbi_flag(sbi, SBI_NEED_FSCK); 295 + f2fs_warn(sbi, "%s: corrupted inode ino=%lx, wrong feature flag: %u, run fsck to fix.", 296 + __func__, inode->i_ino, F2FS_FEATURE_COMPRESSION); 297 + return false; 298 + } 339 299 } 340 300 341 301 if (f2fs_sanity_check_inline_data(inode)) { ··· 393 281 f2fs_warn(sbi, "%s: inode (ino=%lx) has casefold flag, but casefold feature is off", 394 282 __func__, inode->i_ino); 395 283 return false; 396 - } 397 - 398 - if (f2fs_has_extra_attr(inode) && f2fs_sb_has_compression(sbi) && 399 - fi->i_flags & F2FS_COMPR_FL && 400 - F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, 401 - i_log_cluster_size)) { 402 - if (ri->i_compress_algorithm >= COMPRESS_MAX) { 403 - set_sbi_flag(sbi, SBI_NEED_FSCK); 404 - f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported " 405 - "compress algorithm: %u, run fsck to fix", 406 - __func__, inode->i_ino, 407 - ri->i_compress_algorithm); 408 - return false; 409 - } 410 - if (le64_to_cpu(ri->i_compr_blocks) > 411 - SECTOR_TO_BLOCK(inode->i_blocks)) { 412 - set_sbi_flag(sbi, SBI_NEED_FSCK); 413 - f2fs_warn(sbi, "%s: inode (ino=%lx) has inconsistent " 414 - "i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix", 415 - __func__, inode->i_ino, 416 - le64_to_cpu(ri->i_compr_blocks), 417 - SECTOR_TO_BLOCK(inode->i_blocks)); 418 - return false; 419 - } 420 - if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE || 421 - ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) { 422 - set_sbi_flag(sbi, SBI_NEED_FSCK); 423 - f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported " 424 - "log cluster size: %u, run fsck to fix", 425 - __func__, inode->i_ino, 426 - ri->i_log_cluster_size); 427 - return false; 428 - } 429 284 } 430 285 431 286 return true; ··· 521 442 if (f2fs_has_extra_attr(inode) && f2fs_sb_has_compression(sbi) && 522 443 (fi->i_flags & F2FS_COMPR_FL)) { 523 444 if (F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, 524 - i_log_cluster_size)) { 445 + i_compress_flag)) { 525 446 unsigned short compress_flag; 526 447 527 448 atomic_set(&fi->i_compr_blocks, ··· 759 680 760 681 if (f2fs_sb_has_compression(F2FS_I_SB(inode)) && 761 682 F2FS_FITS_IN_INODE(ri, F2FS_I(inode)->i_extra_isize, 762 - i_log_cluster_size)) { 683 + i_compress_flag)) { 763 684 unsigned short compress_flag; 764 685 765 686 ri->i_compr_blocks =
+1
fs/f2fs/iostat.c
··· 80 80 seq_puts(seq, "[OTHER]\n"); 81 81 IOSTAT_INFO_SHOW("fs discard", FS_DISCARD_IO); 82 82 IOSTAT_INFO_SHOW("fs flush", FS_FLUSH_IO); 83 + IOSTAT_INFO_SHOW("fs zone reset", FS_ZONE_RESET_IO); 83 84 84 85 return 0; 85 86 }
+23 -9
fs/f2fs/namei.c
··· 23 23 #include <trace/events/f2fs.h> 24 24 25 25 static inline bool is_extension_exist(const unsigned char *s, const char *sub, 26 - bool tmp_ext) 26 + bool tmp_ext, bool tmp_dot) 27 27 { 28 28 size_t slen = strlen(s); 29 29 size_t sublen = strlen(sub); ··· 49 49 for (i = 1; i < slen - sublen; i++) { 50 50 if (s[i] != '.') 51 51 continue; 52 - if (!strncasecmp(s + i + 1, sub, sublen)) 53 - return true; 52 + if (!strncasecmp(s + i + 1, sub, sublen)) { 53 + if (!tmp_dot) 54 + return true; 55 + if (i == slen - sublen - 1 || s[i + 1 + sublen] == '.') 56 + return true; 57 + } 54 58 } 55 59 56 60 return false; 61 + } 62 + 63 + static inline bool is_temperature_extension(const unsigned char *s, const char *sub) 64 + { 65 + return is_extension_exist(s, sub, true, false); 66 + } 67 + 68 + static inline bool is_compress_extension(const unsigned char *s, const char *sub) 69 + { 70 + return is_extension_exist(s, sub, true, true); 57 71 } 58 72 59 73 int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, ··· 162 148 cold_count = le32_to_cpu(sbi->raw_super->extension_count); 163 149 hot_count = sbi->raw_super->hot_ext_count; 164 150 for (i = cold_count; i < cold_count + hot_count; i++) 165 - if (is_extension_exist(name, extlist[i], false)) 151 + if (is_temperature_extension(name, extlist[i])) 166 152 break; 167 153 f2fs_up_read(&sbi->sb_lock); 168 154 if (i < (cold_count + hot_count)) ··· 170 156 171 157 /* Don't compress unallowed extension. */ 172 158 for (i = 0; i < noext_cnt; i++) 173 - if (is_extension_exist(name, noext[i], false)) 159 + if (is_compress_extension(name, noext[i])) 174 160 return; 175 161 176 162 /* Compress wanting extension. */ 177 163 for (i = 0; i < ext_cnt; i++) { 178 - if (is_extension_exist(name, ext[i], false)) { 164 + if (is_compress_extension(name, ext[i])) { 179 165 set_compress_context(inode); 180 166 return; 181 167 } ··· 203 189 cold_count = le32_to_cpu(sbi->raw_super->extension_count); 204 190 hot_count = sbi->raw_super->hot_ext_count; 205 191 for (i = 0; i < cold_count + hot_count; i++) 206 - if (is_extension_exist(name, extlist[i], true)) 192 + if (is_temperature_extension(name, extlist[i])) 207 193 break; 208 194 f2fs_up_read(&sbi->sb_lock); 209 195 ··· 590 576 } 591 577 #endif 592 578 new = d_splice_alias(inode, dentry); 593 - err = PTR_ERR_OR_ZERO(new); 594 - trace_f2fs_lookup_end(dir, dentry, ino, !new ? -ENOENT : err); 579 + trace_f2fs_lookup_end(dir, !IS_ERR_OR_NULL(new) ? new : dentry, 580 + ino, IS_ERR(new) ? PTR_ERR(new) : err); 595 581 return new; 596 582 out_iput: 597 583 iput(inode);
+27 -18
fs/f2fs/node.c
··· 925 925 926 926 static int truncate_dnode(struct dnode_of_data *dn) 927 927 { 928 + struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); 928 929 struct page *page; 929 930 int err; 930 931 ··· 933 932 return 1; 934 933 935 934 /* get direct node */ 936 - page = f2fs_get_node_page(F2FS_I_SB(dn->inode), dn->nid); 935 + page = f2fs_get_node_page(sbi, dn->nid); 937 936 if (PTR_ERR(page) == -ENOENT) 938 937 return 1; 939 938 else if (IS_ERR(page)) 940 939 return PTR_ERR(page); 941 940 941 + if (IS_INODE(page) || ino_of_node(page) != dn->inode->i_ino) { 942 + f2fs_err(sbi, "incorrect node reference, ino: %lu, nid: %u, ino_of_node: %u", 943 + dn->inode->i_ino, dn->nid, ino_of_node(page)); 944 + set_sbi_flag(sbi, SBI_NEED_FSCK); 945 + f2fs_handle_error(sbi, ERROR_INVALID_NODE_REFERENCE); 946 + f2fs_put_page(page, 1); 947 + return -EFSCORRUPTED; 948 + } 949 + 942 950 /* Make dnode_of_data for parameter */ 943 951 dn->node_page = page; 944 952 dn->ofs_in_node = 0; 945 - f2fs_truncate_data_blocks(dn); 953 + f2fs_truncate_data_blocks_range(dn, ADDRS_PER_BLOCK(dn->inode)); 946 954 err = truncate_node(dn); 947 - if (err) 955 + if (err) { 956 + f2fs_put_page(page, 1); 948 957 return err; 958 + } 949 959 950 960 return 1; 951 961 } ··· 1608 1596 trace_f2fs_writepage(page, NODE); 1609 1597 1610 1598 if (unlikely(f2fs_cp_error(sbi))) { 1599 + /* keep node pages in remount-ro mode */ 1600 + if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_READONLY) 1601 + goto redirty_out; 1611 1602 ClearPageUptodate(page); 1612 1603 dec_page_count(sbi, F2FS_DIRTY_NODES); 1613 1604 unlock_page(page); ··· 2078 2063 struct list_head *head = &sbi->fsync_node_list; 2079 2064 unsigned long flags; 2080 2065 unsigned int cur_seq_id = 0; 2081 - int ret2, ret = 0; 2082 2066 2083 2067 while (seq_id && cur_seq_id < seq_id) { 2084 2068 spin_lock_irqsave(&sbi->fsync_node_lock, flags); ··· 2098 2084 f2fs_wait_on_page_writeback(page, NODE, true, false); 2099 2085 2100 2086 put_page(page); 2101 - 2102 - if (ret) 2103 - break; 2104 2087 } 2105 2088 2106 - ret2 = filemap_check_errors(NODE_MAPPING(sbi)); 2107 - if (!ret) 2108 - ret = ret2; 2109 - 2110 - return ret; 2089 + return filemap_check_errors(NODE_MAPPING(sbi)); 2111 2090 } 2112 2091 2113 2092 static int f2fs_write_node_pages(struct address_space *mapping, ··· 3072 3065 struct f2fs_nm_info *nm_i = NM_I(sbi); 3073 3066 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); 3074 3067 struct f2fs_journal *journal = curseg->journal; 3075 - struct nat_entry_set *setvec[SETVEC_SIZE]; 3068 + struct nat_entry_set *setvec[NAT_VEC_SIZE]; 3076 3069 struct nat_entry_set *set, *tmp; 3077 3070 unsigned int found; 3078 3071 nid_t set_idx = 0; ··· 3105 3098 remove_nats_in_journal(sbi); 3106 3099 3107 3100 while ((found = __gang_lookup_nat_set(nm_i, 3108 - set_idx, SETVEC_SIZE, setvec))) { 3101 + set_idx, NAT_VEC_SIZE, setvec))) { 3109 3102 unsigned idx; 3110 3103 3111 3104 set_idx = setvec[found - 1]->set + 1; ··· 3326 3319 { 3327 3320 struct f2fs_nm_info *nm_i = NM_I(sbi); 3328 3321 struct free_nid *i, *next_i; 3329 - struct nat_entry *natvec[NATVEC_SIZE]; 3330 - struct nat_entry_set *setvec[SETVEC_SIZE]; 3322 + void *vec[NAT_VEC_SIZE]; 3323 + struct nat_entry **natvec = (struct nat_entry **)vec; 3324 + struct nat_entry_set **setvec = (struct nat_entry_set **)vec; 3331 3325 nid_t nid = 0; 3332 3326 unsigned int found; 3333 3327 ··· 3351 3343 /* destroy nat cache */ 3352 3344 f2fs_down_write(&nm_i->nat_tree_lock); 3353 3345 while ((found = __gang_lookup_nat_cache(nm_i, 3354 - nid, NATVEC_SIZE, natvec))) { 3346 + nid, NAT_VEC_SIZE, natvec))) { 3355 3347 unsigned idx; 3356 3348 3357 3349 nid = nat_get_nid(natvec[found - 1]) + 1; ··· 3367 3359 3368 3360 /* destroy nat set cache */ 3369 3361 nid = 0; 3362 + memset(vec, 0, sizeof(void *) * NAT_VEC_SIZE); 3370 3363 while ((found = __gang_lookup_nat_set(nm_i, 3371 - nid, SETVEC_SIZE, setvec))) { 3364 + nid, NAT_VEC_SIZE, setvec))) { 3372 3365 unsigned idx; 3373 3366 3374 3367 nid = setvec[found - 1]->set + 1;
+1 -2
fs/f2fs/node.h
··· 35 35 #define DEF_RF_NODE_BLOCKS 0 36 36 37 37 /* vector size for gang look-up from nat cache that consists of radix tree */ 38 - #define NATVEC_SIZE 64 39 - #define SETVEC_SIZE 32 38 + #define NAT_VEC_SIZE 32 40 39 41 40 /* return value for read_node_page */ 42 41 #define LOCKED_PAGE 1
+52 -23
fs/f2fs/recovery.c
··· 360 360 return ra_blocks; 361 361 } 362 362 363 + /* Detect looped node chain with Floyd's cycle detection algorithm. */ 364 + static int sanity_check_node_chain(struct f2fs_sb_info *sbi, block_t blkaddr, 365 + block_t *blkaddr_fast, bool *is_detecting) 366 + { 367 + unsigned int ra_blocks = RECOVERY_MAX_RA_BLOCKS; 368 + struct page *page = NULL; 369 + int i; 370 + 371 + if (!*is_detecting) 372 + return 0; 373 + 374 + for (i = 0; i < 2; i++) { 375 + if (!f2fs_is_valid_blkaddr(sbi, *blkaddr_fast, META_POR)) { 376 + *is_detecting = false; 377 + return 0; 378 + } 379 + 380 + page = f2fs_get_tmp_page(sbi, *blkaddr_fast); 381 + if (IS_ERR(page)) 382 + return PTR_ERR(page); 383 + 384 + if (!is_recoverable_dnode(page)) { 385 + f2fs_put_page(page, 1); 386 + *is_detecting = false; 387 + return 0; 388 + } 389 + 390 + ra_blocks = adjust_por_ra_blocks(sbi, ra_blocks, *blkaddr_fast, 391 + next_blkaddr_of_node(page)); 392 + 393 + *blkaddr_fast = next_blkaddr_of_node(page); 394 + f2fs_put_page(page, 1); 395 + 396 + f2fs_ra_meta_pages_cond(sbi, *blkaddr_fast, ra_blocks); 397 + } 398 + 399 + if (*blkaddr_fast == blkaddr) { 400 + f2fs_notice(sbi, "%s: Detect looped node chain on blkaddr:%u." 401 + " Run fsck to fix it.", __func__, blkaddr); 402 + return -EINVAL; 403 + } 404 + return 0; 405 + } 406 + 363 407 static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head, 364 408 bool check_only) 365 409 { 366 410 struct curseg_info *curseg; 367 411 struct page *page = NULL; 368 - block_t blkaddr; 369 - unsigned int loop_cnt = 0; 370 - unsigned int ra_blocks = RECOVERY_MAX_RA_BLOCKS; 371 - unsigned int free_blocks = MAIN_SEGS(sbi) * sbi->blocks_per_seg - 372 - valid_user_blocks(sbi); 412 + block_t blkaddr, blkaddr_fast; 413 + bool is_detecting = true; 373 414 int err = 0; 374 415 375 416 /* get node pages in the current segment */ 376 417 curseg = CURSEG_I(sbi, CURSEG_WARM_NODE); 377 418 blkaddr = NEXT_FREE_BLKADDR(sbi, curseg); 419 + blkaddr_fast = blkaddr; 378 420 379 421 while (1) { 380 422 struct fsync_inode_entry *entry; ··· 460 418 quota_inode); 461 419 if (IS_ERR(entry)) { 462 420 err = PTR_ERR(entry); 463 - if (err == -ENOENT) { 464 - err = 0; 421 + if (err == -ENOENT) 465 422 goto next; 466 - } 467 423 f2fs_put_page(page, 1); 468 424 break; 469 425 } ··· 471 431 if (IS_INODE(page) && is_dent_dnode(page)) 472 432 entry->last_dentry = blkaddr; 473 433 next: 474 - /* sanity check in order to detect looped node chain */ 475 - if (++loop_cnt >= free_blocks || 476 - blkaddr == next_blkaddr_of_node(page)) { 477 - f2fs_notice(sbi, "%s: detect looped node chain, blkaddr:%u, next:%u", 478 - __func__, blkaddr, 479 - next_blkaddr_of_node(page)); 480 - f2fs_put_page(page, 1); 481 - err = -EINVAL; 482 - break; 483 - } 484 - 485 - ra_blocks = adjust_por_ra_blocks(sbi, ra_blocks, blkaddr, 486 - next_blkaddr_of_node(page)); 487 - 488 434 /* check next segment */ 489 435 blkaddr = next_blkaddr_of_node(page); 490 436 f2fs_put_page(page, 1); 491 437 492 - f2fs_ra_meta_pages_cond(sbi, blkaddr, ra_blocks); 438 + err = sanity_check_node_chain(sbi, blkaddr, &blkaddr_fast, 439 + &is_detecting); 440 + if (err) 441 + break; 493 442 } 494 443 return err; 495 444 }
+126 -36
fs/f2fs/segment.c
··· 1196 1196 static void __update_discard_tree_range(struct f2fs_sb_info *sbi, 1197 1197 struct block_device *bdev, block_t lstart, 1198 1198 block_t start, block_t len); 1199 + 1200 + #ifdef CONFIG_BLK_DEV_ZONED 1201 + static void __submit_zone_reset_cmd(struct f2fs_sb_info *sbi, 1202 + struct discard_cmd *dc, blk_opf_t flag, 1203 + struct list_head *wait_list, 1204 + unsigned int *issued) 1205 + { 1206 + struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 1207 + struct block_device *bdev = dc->bdev; 1208 + struct bio *bio = bio_alloc(bdev, 0, REQ_OP_ZONE_RESET | flag, GFP_NOFS); 1209 + unsigned long flags; 1210 + 1211 + trace_f2fs_issue_reset_zone(bdev, dc->di.start); 1212 + 1213 + spin_lock_irqsave(&dc->lock, flags); 1214 + dc->state = D_SUBMIT; 1215 + dc->bio_ref++; 1216 + spin_unlock_irqrestore(&dc->lock, flags); 1217 + 1218 + if (issued) 1219 + (*issued)++; 1220 + 1221 + atomic_inc(&dcc->queued_discard); 1222 + dc->queued++; 1223 + list_move_tail(&dc->list, wait_list); 1224 + 1225 + /* sanity check on discard range */ 1226 + __check_sit_bitmap(sbi, dc->di.lstart, dc->di.lstart + dc->di.len); 1227 + 1228 + bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(dc->di.start); 1229 + bio->bi_private = dc; 1230 + bio->bi_end_io = f2fs_submit_discard_endio; 1231 + submit_bio(bio); 1232 + 1233 + atomic_inc(&dcc->issued_discard); 1234 + f2fs_update_iostat(sbi, NULL, FS_ZONE_RESET_IO, dc->di.len * F2FS_BLKSIZE); 1235 + } 1236 + #endif 1237 + 1199 1238 /* this function is copied from blkdev_issue_discard from block/blk-lib.c */ 1200 1239 static int __submit_discard_cmd(struct f2fs_sb_info *sbi, 1201 1240 struct discard_policy *dpolicy, ··· 1255 1216 1256 1217 if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) 1257 1218 return 0; 1219 + 1220 + #ifdef CONFIG_BLK_DEV_ZONED 1221 + if (f2fs_sb_has_blkzoned(sbi) && bdev_is_zoned(bdev)) { 1222 + __submit_zone_reset_cmd(sbi, dc, flag, wait_list, issued); 1223 + return 0; 1224 + } 1225 + #endif 1258 1226 1259 1227 trace_f2fs_issue_discard(bdev, dc->di.start, dc->di.len); 1260 1228 ··· 1506 1460 next_dc = rb_entry_safe(node, struct discard_cmd, rb_node); 1507 1461 } 1508 1462 } 1463 + 1464 + #ifdef CONFIG_BLK_DEV_ZONED 1465 + static void __queue_zone_reset_cmd(struct f2fs_sb_info *sbi, 1466 + struct block_device *bdev, block_t blkstart, block_t lblkstart, 1467 + block_t blklen) 1468 + { 1469 + trace_f2fs_queue_reset_zone(bdev, blkstart); 1470 + 1471 + mutex_lock(&SM_I(sbi)->dcc_info->cmd_lock); 1472 + __insert_discard_cmd(sbi, bdev, lblkstart, blkstart, blklen); 1473 + mutex_unlock(&SM_I(sbi)->dcc_info->cmd_lock); 1474 + } 1475 + #endif 1509 1476 1510 1477 static void __queue_discard_cmd(struct f2fs_sb_info *sbi, 1511 1478 struct block_device *bdev, block_t blkstart, block_t blklen) ··· 1783 1724 1784 1725 mutex_lock(&dcc->cmd_lock); 1785 1726 dc = __lookup_discard_cmd(sbi, blkaddr); 1727 + #ifdef CONFIG_BLK_DEV_ZONED 1728 + if (dc && f2fs_sb_has_blkzoned(sbi) && bdev_is_zoned(dc->bdev)) { 1729 + /* force submit zone reset */ 1730 + if (dc->state == D_PREP) 1731 + __submit_zone_reset_cmd(sbi, dc, REQ_SYNC, 1732 + &dcc->wait_list, NULL); 1733 + dc->ref++; 1734 + mutex_unlock(&dcc->cmd_lock); 1735 + /* wait zone reset */ 1736 + __wait_one_discard_bio(sbi, dc); 1737 + return; 1738 + } 1739 + #endif 1786 1740 if (dc) { 1787 1741 if (dc->state == D_PREP) { 1788 1742 __punch_discard_cmd(sbi, dc, blkaddr); ··· 1948 1876 blkstart, blklen); 1949 1877 return -EIO; 1950 1878 } 1951 - trace_f2fs_issue_reset_zone(bdev, blkstart); 1952 - return blkdev_zone_mgmt(bdev, REQ_OP_ZONE_RESET, 1953 - sector, nr_sects, GFP_NOFS); 1879 + 1880 + if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) { 1881 + trace_f2fs_issue_reset_zone(bdev, blkstart); 1882 + return blkdev_zone_mgmt(bdev, REQ_OP_ZONE_RESET, 1883 + sector, nr_sects, GFP_NOFS); 1884 + } 1885 + 1886 + __queue_zone_reset_cmd(sbi, bdev, blkstart, lblkstart, blklen); 1887 + return 0; 1954 1888 } 1955 1889 1956 1890 /* For conventional zones, use regular discard if supported */ ··· 2193 2115 len = next_pos - cur_pos; 2194 2116 2195 2117 if (f2fs_sb_has_blkzoned(sbi) || 2196 - (force && len < cpc->trim_minlen)) 2118 + !force || len < cpc->trim_minlen) 2197 2119 goto skip; 2198 2120 2199 2121 f2fs_issue_discard(sbi, entry->start_blkaddr + cur_pos, ··· 4846 4768 { 4847 4769 unsigned int wp_segno, wp_blkoff, zone_secno, zone_segno, segno; 4848 4770 block_t zone_block, wp_block, last_valid_block; 4849 - unsigned int log_sectors_per_block = sbi->log_blocksize - SECTOR_SHIFT; 4850 4771 int i, s, b, ret; 4851 4772 struct seg_entry *se; 4852 4773 4853 4774 if (zone->type != BLK_ZONE_TYPE_SEQWRITE_REQ) 4854 4775 return 0; 4855 4776 4856 - wp_block = fdev->start_blk + (zone->wp >> log_sectors_per_block); 4777 + wp_block = fdev->start_blk + (zone->wp >> sbi->log_sectors_per_block); 4857 4778 wp_segno = GET_SEGNO(sbi, wp_block); 4858 4779 wp_blkoff = wp_block - START_BLOCK(sbi, wp_segno); 4859 - zone_block = fdev->start_blk + (zone->start >> log_sectors_per_block); 4780 + zone_block = fdev->start_blk + (zone->start >> 4781 + sbi->log_sectors_per_block); 4860 4782 zone_segno = GET_SEGNO(sbi, zone_block); 4861 4783 zone_secno = GET_SEC_FROM_SEG(sbi, zone_segno); 4862 4784 ··· 4889 4811 } 4890 4812 4891 4813 /* 4892 - * If last valid block is beyond the write pointer, report the 4893 - * inconsistency. This inconsistency does not cause write error 4894 - * because the zone will not be selected for write operation until 4895 - * it get discarded. Just report it. 4814 + * The write pointer matches with the valid blocks or 4815 + * already points to the end of the zone. 4896 4816 */ 4897 - if (last_valid_block >= wp_block) { 4898 - f2fs_notice(sbi, "Valid block beyond write pointer: " 4899 - "valid block[0x%x,0x%x] wp[0x%x,0x%x]", 4900 - GET_SEGNO(sbi, last_valid_block), 4901 - GET_BLKOFF_FROM_SEG0(sbi, last_valid_block), 4902 - wp_segno, wp_blkoff); 4817 + if ((last_valid_block + 1 == wp_block) || 4818 + (zone->wp == zone->start + zone->len)) 4903 4819 return 0; 4904 - } 4905 4820 4906 - /* 4907 - * If there is no valid block in the zone and if write pointer is 4908 - * not at zone start, reset the write pointer. 4909 - */ 4910 - if (last_valid_block + 1 == zone_block && zone->wp != zone->start) { 4821 + if (last_valid_block + 1 == zone_block) { 4822 + /* 4823 + * If there is no valid block in the zone and if write pointer 4824 + * is not at zone start, reset the write pointer. 4825 + */ 4911 4826 f2fs_notice(sbi, 4912 4827 "Zone without valid block has non-zero write " 4913 4828 "pointer. Reset the write pointer: wp[0x%x,0x%x]", 4914 4829 wp_segno, wp_blkoff); 4915 4830 ret = __f2fs_issue_discard_zone(sbi, fdev->bdev, zone_block, 4916 - zone->len >> log_sectors_per_block); 4917 - if (ret) { 4831 + zone->len >> sbi->log_sectors_per_block); 4832 + if (ret) 4918 4833 f2fs_err(sbi, "Discard zone failed: %s (errno=%d)", 4919 4834 fdev->path, ret); 4920 - return ret; 4921 - } 4835 + 4836 + return ret; 4922 4837 } 4923 4838 4924 - return 0; 4839 + /* 4840 + * If there are valid blocks and the write pointer doesn't 4841 + * match with them, we need to report the inconsistency and 4842 + * fill the zone till the end to close the zone. This inconsistency 4843 + * does not cause write error because the zone will not be selected 4844 + * for write operation until it get discarded. 4845 + */ 4846 + f2fs_notice(sbi, "Valid blocks are not aligned with write pointer: " 4847 + "valid block[0x%x,0x%x] wp[0x%x,0x%x]", 4848 + GET_SEGNO(sbi, last_valid_block), 4849 + GET_BLKOFF_FROM_SEG0(sbi, last_valid_block), 4850 + wp_segno, wp_blkoff); 4851 + 4852 + ret = blkdev_issue_zeroout(fdev->bdev, zone->wp, 4853 + zone->len - (zone->wp - zone->start), 4854 + GFP_NOFS, 0); 4855 + if (ret) 4856 + f2fs_err(sbi, "Fill up zone failed: %s (errno=%d)", 4857 + fdev->path, ret); 4858 + 4859 + return ret; 4925 4860 } 4926 4861 4927 4862 static struct f2fs_dev_info *get_target_zoned_dev(struct f2fs_sb_info *sbi, ··· 4967 4876 struct blk_zone zone; 4968 4877 unsigned int cs_section, wp_segno, wp_blkoff, wp_sector_off; 4969 4878 block_t cs_zone_block, wp_block; 4970 - unsigned int log_sectors_per_block = sbi->log_blocksize - SECTOR_SHIFT; 4971 4879 sector_t zone_sector; 4972 4880 int err; 4973 4881 ··· 4978 4888 return 0; 4979 4889 4980 4890 /* report zone for the sector the curseg points to */ 4981 - zone_sector = (sector_t)(cs_zone_block - zbd->start_blk) 4982 - << log_sectors_per_block; 4891 + zone_sector = (sector_t)(cs_zone_block - zbd->start_blk) << 4892 + sbi->log_sectors_per_block; 4983 4893 err = blkdev_report_zones(zbd->bdev, zone_sector, 1, 4984 4894 report_one_zone_cb, &zone); 4985 4895 if (err != 1) { ··· 4991 4901 if (zone.type != BLK_ZONE_TYPE_SEQWRITE_REQ) 4992 4902 return 0; 4993 4903 4994 - wp_block = zbd->start_blk + (zone.wp >> log_sectors_per_block); 4904 + wp_block = zbd->start_blk + (zone.wp >> sbi->log_sectors_per_block); 4995 4905 wp_segno = GET_SEGNO(sbi, wp_block); 4996 4906 wp_blkoff = wp_block - START_BLOCK(sbi, wp_segno); 4997 - wp_sector_off = zone.wp & GENMASK(log_sectors_per_block - 1, 0); 4907 + wp_sector_off = zone.wp & GENMASK(sbi->log_sectors_per_block - 1, 0); 4998 4908 4999 4909 if (cs->segno == wp_segno && cs->next_blkoff == wp_blkoff && 5000 4910 wp_sector_off == 0) ··· 5021 4931 if (!zbd) 5022 4932 return 0; 5023 4933 5024 - zone_sector = (sector_t)(cs_zone_block - zbd->start_blk) 5025 - << log_sectors_per_block; 4934 + zone_sector = (sector_t)(cs_zone_block - zbd->start_blk) << 4935 + sbi->log_sectors_per_block; 5026 4936 err = blkdev_report_zones(zbd->bdev, zone_sector, 1, 5027 4937 report_one_zone_cb, &zone); 5028 4938 if (err != 1) { ··· 5040 4950 "Reset the zone: curseg[0x%x,0x%x]", 5041 4951 type, cs->segno, cs->next_blkoff); 5042 4952 err = __f2fs_issue_discard_zone(sbi, zbd->bdev, cs_zone_block, 5043 - zone.len >> log_sectors_per_block); 4953 + zone.len >> sbi->log_sectors_per_block); 5044 4954 if (err) { 5045 4955 f2fs_err(sbi, "Discard zone failed: %s (errno=%d)", 5046 4956 zbd->path, err);
+214 -38
fs/f2fs/super.c
··· 164 164 Opt_discard_unit, 165 165 Opt_memory_mode, 166 166 Opt_age_extent_cache, 167 + Opt_errors, 167 168 Opt_err, 168 169 }; 169 170 ··· 244 243 {Opt_discard_unit, "discard_unit=%s"}, 245 244 {Opt_memory_mode, "memory=%s"}, 246 245 {Opt_age_extent_cache, "age_extent_cache"}, 246 + {Opt_errors, "errors=%s"}, 247 247 {Opt_err, NULL}, 248 248 }; 249 249 ··· 589 587 { 590 588 #ifdef CONFIG_F2FS_FS_LZ4HC 591 589 unsigned int level; 592 - #endif 593 590 594 591 if (strlen(str) == 3) { 595 - F2FS_OPTION(sbi).compress_level = 0; 592 + F2FS_OPTION(sbi).compress_level = LZ4HC_DEFAULT_CLEVEL; 596 593 return 0; 597 594 } 598 595 599 - #ifdef CONFIG_F2FS_FS_LZ4HC 600 596 str += 3; 601 597 602 598 if (str[0] != ':') { ··· 604 604 if (kstrtouint(str + 1, 10, &level)) 605 605 return -EINVAL; 606 606 607 - if (level < LZ4HC_MIN_CLEVEL || level > LZ4HC_MAX_CLEVEL) { 607 + if (!f2fs_is_compress_level_valid(COMPRESS_LZ4, level)) { 608 608 f2fs_info(sbi, "invalid lz4hc compress level: %d", level); 609 609 return -EINVAL; 610 610 } ··· 612 612 F2FS_OPTION(sbi).compress_level = level; 613 613 return 0; 614 614 #else 615 + if (strlen(str) == 3) { 616 + F2FS_OPTION(sbi).compress_level = 0; 617 + return 0; 618 + } 615 619 f2fs_info(sbi, "kernel doesn't support lz4hc compression"); 616 620 return -EINVAL; 617 621 #endif ··· 629 625 int len = 4; 630 626 631 627 if (strlen(str) == len) { 632 - F2FS_OPTION(sbi).compress_level = 0; 628 + F2FS_OPTION(sbi).compress_level = F2FS_ZSTD_DEFAULT_CLEVEL; 633 629 return 0; 634 630 } 635 631 ··· 642 638 if (kstrtouint(str + 1, 10, &level)) 643 639 return -EINVAL; 644 640 645 - if (!level || level > zstd_max_clevel()) { 641 + if (!f2fs_is_compress_level_valid(COMPRESS_ZSTD, level)) { 646 642 f2fs_info(sbi, "invalid zstd compress level: %d", level); 647 643 return -EINVAL; 648 644 } ··· 1272 1268 case Opt_age_extent_cache: 1273 1269 set_opt(sbi, AGE_EXTENT_CACHE); 1274 1270 break; 1271 + case Opt_errors: 1272 + name = match_strdup(&args[0]); 1273 + if (!name) 1274 + return -ENOMEM; 1275 + if (!strcmp(name, "remount-ro")) { 1276 + F2FS_OPTION(sbi).errors = 1277 + MOUNT_ERRORS_READONLY; 1278 + } else if (!strcmp(name, "continue")) { 1279 + F2FS_OPTION(sbi).errors = 1280 + MOUNT_ERRORS_CONTINUE; 1281 + } else if (!strcmp(name, "panic")) { 1282 + F2FS_OPTION(sbi).errors = 1283 + MOUNT_ERRORS_PANIC; 1284 + } else { 1285 + kfree(name); 1286 + return -EINVAL; 1287 + } 1288 + kfree(name); 1289 + break; 1275 1290 default: 1276 1291 f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value", 1277 1292 p); ··· 1363 1340 return -EINVAL; 1364 1341 } 1365 1342 1366 - min_size = sizeof(struct f2fs_xattr_header) / sizeof(__le32); 1343 + min_size = MIN_INLINE_XATTR_SIZE; 1367 1344 max_size = MAX_INLINE_XATTR_SIZE; 1368 1345 1369 1346 if (F2FS_OPTION(sbi).inline_xattr_size < min_size || ··· 1573 1550 { 1574 1551 struct f2fs_sb_info *sbi = F2FS_SB(sb); 1575 1552 int i; 1553 + int err = 0; 1576 1554 bool done; 1577 1555 1578 1556 /* unregister procfs/sysfs entries in advance to avoid race case */ ··· 1600 1576 struct cp_control cpc = { 1601 1577 .reason = CP_UMOUNT, 1602 1578 }; 1603 - f2fs_write_checkpoint(sbi, &cpc); 1579 + err = f2fs_write_checkpoint(sbi, &cpc); 1604 1580 } 1605 1581 1606 1582 /* be sure to wait for any on-going discard commands */ ··· 1609 1585 struct cp_control cpc = { 1610 1586 .reason = CP_UMOUNT | CP_TRIMMED, 1611 1587 }; 1612 - f2fs_write_checkpoint(sbi, &cpc); 1588 + err = f2fs_write_checkpoint(sbi, &cpc); 1613 1589 } 1614 1590 1615 1591 /* ··· 1625 1601 f2fs_flush_merged_writes(sbi); 1626 1602 1627 1603 f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA); 1604 + 1605 + if (err) { 1606 + truncate_inode_pages_final(NODE_MAPPING(sbi)); 1607 + truncate_inode_pages_final(META_MAPPING(sbi)); 1608 + } 1609 + 1610 + for (i = 0; i < NR_COUNT_TYPE; i++) { 1611 + if (!get_pages(sbi, i)) 1612 + continue; 1613 + f2fs_err(sbi, "detect filesystem reference count leak during " 1614 + "umount, type: %d, count: %lld", i, get_pages(sbi, i)); 1615 + f2fs_bug_on(sbi, 1); 1616 + } 1628 1617 1629 1618 f2fs_bug_on(sbi, sbi->fsync_node_num); 1630 1619 ··· 1658 1621 /* destroy f2fs internal modules */ 1659 1622 f2fs_destroy_node_manager(sbi); 1660 1623 f2fs_destroy_segment_manager(sbi); 1624 + 1625 + /* flush s_error_work before sbi destroy */ 1626 + flush_work(&sbi->s_error_work); 1661 1627 1662 1628 f2fs_destroy_post_read_wq(sbi); 1663 1629 ··· 2092 2052 else if (F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_LOW) 2093 2053 seq_printf(seq, ",memory=%s", "low"); 2094 2054 2055 + if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_READONLY) 2056 + seq_printf(seq, ",errors=%s", "remount-ro"); 2057 + else if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_CONTINUE) 2058 + seq_printf(seq, ",errors=%s", "continue"); 2059 + else if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_PANIC) 2060 + seq_printf(seq, ",errors=%s", "panic"); 2061 + 2095 2062 return 0; 2096 2063 } 2097 2064 2098 - static void default_options(struct f2fs_sb_info *sbi) 2065 + static void default_options(struct f2fs_sb_info *sbi, bool remount) 2099 2066 { 2100 2067 /* init some FS parameters */ 2068 + if (!remount) { 2069 + set_opt(sbi, READ_EXTENT_CACHE); 2070 + clear_opt(sbi, DISABLE_CHECKPOINT); 2071 + 2072 + if (f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) 2073 + set_opt(sbi, DISCARD); 2074 + 2075 + if (f2fs_sb_has_blkzoned(sbi)) 2076 + F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_SECTION; 2077 + else 2078 + F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_BLOCK; 2079 + } 2080 + 2101 2081 if (f2fs_sb_has_readonly(sbi)) 2102 2082 F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE; 2103 2083 else ··· 2140 2080 } 2141 2081 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; 2142 2082 F2FS_OPTION(sbi).memory_mode = MEMORY_MODE_NORMAL; 2083 + F2FS_OPTION(sbi).errors = MOUNT_ERRORS_CONTINUE; 2143 2084 2144 2085 sbi->sb->s_flags &= ~SB_INLINECRYPT; 2145 2086 2146 2087 set_opt(sbi, INLINE_XATTR); 2147 2088 set_opt(sbi, INLINE_DATA); 2148 2089 set_opt(sbi, INLINE_DENTRY); 2149 - set_opt(sbi, READ_EXTENT_CACHE); 2150 2090 set_opt(sbi, NOHEAP); 2151 - clear_opt(sbi, DISABLE_CHECKPOINT); 2152 2091 set_opt(sbi, MERGE_CHECKPOINT); 2153 2092 F2FS_OPTION(sbi).unusable_cap = 0; 2154 2093 sbi->sb->s_flags |= SB_LAZYTIME; 2155 2094 if (!f2fs_is_readonly(sbi)) 2156 2095 set_opt(sbi, FLUSH_MERGE); 2157 - if (f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) 2158 - set_opt(sbi, DISCARD); 2159 - if (f2fs_sb_has_blkzoned(sbi)) { 2096 + if (f2fs_sb_has_blkzoned(sbi)) 2160 2097 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; 2161 - F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_SECTION; 2162 - } else { 2098 + else 2163 2099 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; 2164 - F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_BLOCK; 2165 - } 2166 2100 2167 2101 #ifdef CONFIG_F2FS_FS_XATTR 2168 2102 set_opt(sbi, XATTR_USER); ··· 2328 2274 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE); 2329 2275 } 2330 2276 2331 - default_options(sbi); 2277 + default_options(sbi, true); 2332 2278 2333 2279 /* parse mount options */ 2334 2280 err = parse_options(sb, data, true); 2335 2281 if (err) 2336 2282 goto restore_opts; 2283 + 2284 + /* flush outstanding errors before changing fs state */ 2285 + flush_work(&sbi->s_error_work); 2337 2286 2338 2287 /* 2339 2288 * Previous and new state of filesystem is RO, ··· 2770 2713 { 2771 2714 struct inode *qf_inode; 2772 2715 unsigned long qf_inum; 2716 + unsigned long qf_flag = F2FS_QUOTA_DEFAULT_FL; 2773 2717 int err; 2774 2718 2775 2719 BUG_ON(!f2fs_sb_has_quota_ino(F2FS_SB(sb))); ··· 2786 2728 } 2787 2729 2788 2730 /* Don't account quota for quota files to avoid recursion */ 2731 + inode_lock(qf_inode); 2789 2732 qf_inode->i_flags |= S_NOQUOTA; 2733 + 2734 + if ((F2FS_I(qf_inode)->i_flags & qf_flag) != qf_flag) { 2735 + F2FS_I(qf_inode)->i_flags |= qf_flag; 2736 + f2fs_set_inode_flags(qf_inode); 2737 + } 2738 + inode_unlock(qf_inode); 2739 + 2790 2740 err = dquot_load_quota_inode(qf_inode, type, format_id, flags); 2791 2741 iput(qf_inode); 2792 2742 return err; ··· 2925 2859 return -EBUSY; 2926 2860 } 2927 2861 2862 + if (path->dentry->d_sb != sb) 2863 + return -EXDEV; 2864 + 2928 2865 err = f2fs_quota_sync(sb, type); 2866 + if (err) 2867 + return err; 2868 + 2869 + inode = d_inode(path->dentry); 2870 + 2871 + err = filemap_fdatawrite(inode->i_mapping); 2872 + if (err) 2873 + return err; 2874 + 2875 + err = filemap_fdatawait(inode->i_mapping); 2929 2876 if (err) 2930 2877 return err; 2931 2878 ··· 2946 2867 if (err) 2947 2868 return err; 2948 2869 2949 - inode = d_inode(path->dentry); 2950 - 2951 2870 inode_lock(inode); 2952 - F2FS_I(inode)->i_flags |= F2FS_NOATIME_FL | F2FS_IMMUTABLE_FL; 2871 + F2FS_I(inode)->i_flags |= F2FS_QUOTA_DEFAULT_FL; 2953 2872 f2fs_set_inode_flags(inode); 2954 2873 inode_unlock(inode); 2955 2874 f2fs_mark_inode_dirty_sync(inode, false); ··· 2972 2895 goto out_put; 2973 2896 2974 2897 inode_lock(inode); 2975 - F2FS_I(inode)->i_flags &= ~(F2FS_NOATIME_FL | F2FS_IMMUTABLE_FL); 2898 + F2FS_I(inode)->i_flags &= ~F2FS_QUOTA_DEFAULT_FL; 2976 2899 f2fs_set_inode_flags(inode); 2977 2900 inode_unlock(inode); 2978 2901 f2fs_mark_inode_dirty_sync(inode, false); ··· 4003 3926 return err; 4004 3927 } 4005 3928 4006 - void f2fs_handle_stop(struct f2fs_sb_info *sbi, unsigned char reason) 3929 + static void save_stop_reason(struct f2fs_sb_info *sbi, unsigned char reason) 3930 + { 3931 + unsigned long flags; 3932 + 3933 + spin_lock_irqsave(&sbi->error_lock, flags); 3934 + if (sbi->stop_reason[reason] < GENMASK(BITS_PER_BYTE - 1, 0)) 3935 + sbi->stop_reason[reason]++; 3936 + spin_unlock_irqrestore(&sbi->error_lock, flags); 3937 + } 3938 + 3939 + static void f2fs_record_stop_reason(struct f2fs_sb_info *sbi) 4007 3940 { 4008 3941 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); 3942 + unsigned long flags; 4009 3943 int err; 4010 3944 4011 3945 f2fs_down_write(&sbi->sb_lock); 4012 3946 4013 - if (raw_super->s_stop_reason[reason] < GENMASK(BITS_PER_BYTE - 1, 0)) 4014 - raw_super->s_stop_reason[reason]++; 3947 + spin_lock_irqsave(&sbi->error_lock, flags); 3948 + if (sbi->error_dirty) { 3949 + memcpy(F2FS_RAW_SUPER(sbi)->s_errors, sbi->errors, 3950 + MAX_F2FS_ERRORS); 3951 + sbi->error_dirty = false; 3952 + } 3953 + memcpy(raw_super->s_stop_reason, sbi->stop_reason, MAX_STOP_REASON); 3954 + spin_unlock_irqrestore(&sbi->error_lock, flags); 4015 3955 4016 3956 err = f2fs_commit_super(sbi, false); 4017 - if (err) 4018 - f2fs_err(sbi, "f2fs_commit_super fails to record reason:%u err:%d", 4019 - reason, err); 3957 + 4020 3958 f2fs_up_write(&sbi->sb_lock); 3959 + if (err) 3960 + f2fs_err(sbi, "f2fs_commit_super fails to record err:%d", err); 4021 3961 } 4022 3962 4023 3963 void f2fs_save_errors(struct f2fs_sb_info *sbi, unsigned char flag) 4024 3964 { 4025 - spin_lock(&sbi->error_lock); 3965 + unsigned long flags; 3966 + 3967 + spin_lock_irqsave(&sbi->error_lock, flags); 4026 3968 if (!test_bit(flag, (unsigned long *)sbi->errors)) { 4027 3969 set_bit(flag, (unsigned long *)sbi->errors); 4028 3970 sbi->error_dirty = true; 4029 3971 } 4030 - spin_unlock(&sbi->error_lock); 3972 + spin_unlock_irqrestore(&sbi->error_lock, flags); 4031 3973 } 4032 3974 4033 3975 static bool f2fs_update_errors(struct f2fs_sb_info *sbi) 4034 3976 { 3977 + unsigned long flags; 4035 3978 bool need_update = false; 4036 3979 4037 - spin_lock(&sbi->error_lock); 3980 + spin_lock_irqsave(&sbi->error_lock, flags); 4038 3981 if (sbi->error_dirty) { 4039 3982 memcpy(F2FS_RAW_SUPER(sbi)->s_errors, sbi->errors, 4040 3983 MAX_F2FS_ERRORS); 4041 3984 sbi->error_dirty = false; 4042 3985 need_update = true; 4043 3986 } 4044 - spin_unlock(&sbi->error_lock); 3987 + spin_unlock_irqrestore(&sbi->error_lock, flags); 4045 3988 4046 3989 return need_update; 4047 3990 } 4048 3991 4049 - void f2fs_handle_error(struct f2fs_sb_info *sbi, unsigned char error) 3992 + static void f2fs_record_errors(struct f2fs_sb_info *sbi, unsigned char error) 4050 3993 { 4051 3994 int err; 4052 - 4053 - f2fs_save_errors(sbi, error); 4054 3995 4055 3996 f2fs_down_write(&sbi->sb_lock); 4056 3997 ··· 4081 3986 error, err); 4082 3987 out_unlock: 4083 3988 f2fs_up_write(&sbi->sb_lock); 3989 + } 3990 + 3991 + void f2fs_handle_error(struct f2fs_sb_info *sbi, unsigned char error) 3992 + { 3993 + f2fs_save_errors(sbi, error); 3994 + f2fs_record_errors(sbi, error); 3995 + } 3996 + 3997 + void f2fs_handle_error_async(struct f2fs_sb_info *sbi, unsigned char error) 3998 + { 3999 + f2fs_save_errors(sbi, error); 4000 + 4001 + if (!sbi->error_dirty) 4002 + return; 4003 + if (!test_bit(error, (unsigned long *)sbi->errors)) 4004 + return; 4005 + schedule_work(&sbi->s_error_work); 4006 + } 4007 + 4008 + static bool system_going_down(void) 4009 + { 4010 + return system_state == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF 4011 + || system_state == SYSTEM_RESTART; 4012 + } 4013 + 4014 + void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason, 4015 + bool irq_context) 4016 + { 4017 + struct super_block *sb = sbi->sb; 4018 + bool shutdown = reason == STOP_CP_REASON_SHUTDOWN; 4019 + bool continue_fs = !shutdown && 4020 + F2FS_OPTION(sbi).errors == MOUNT_ERRORS_CONTINUE; 4021 + 4022 + set_ckpt_flags(sbi, CP_ERROR_FLAG); 4023 + 4024 + if (!f2fs_hw_is_readonly(sbi)) { 4025 + save_stop_reason(sbi, reason); 4026 + 4027 + if (irq_context && !shutdown) 4028 + schedule_work(&sbi->s_error_work); 4029 + else 4030 + f2fs_record_stop_reason(sbi); 4031 + } 4032 + 4033 + /* 4034 + * We force ERRORS_RO behavior when system is rebooting. Otherwise we 4035 + * could panic during 'reboot -f' as the underlying device got already 4036 + * disabled. 4037 + */ 4038 + if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_PANIC && 4039 + !shutdown && !system_going_down() && 4040 + !is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN)) 4041 + panic("F2FS-fs (device %s): panic forced after error\n", 4042 + sb->s_id); 4043 + 4044 + if (shutdown) 4045 + set_sbi_flag(sbi, SBI_IS_SHUTDOWN); 4046 + 4047 + /* continue filesystem operators if errors=continue */ 4048 + if (continue_fs || f2fs_readonly(sb)) 4049 + return; 4050 + 4051 + f2fs_warn(sbi, "Remounting filesystem read-only"); 4052 + /* 4053 + * Make sure updated value of ->s_mount_flags will be visible before 4054 + * ->s_flags update 4055 + */ 4056 + smp_wmb(); 4057 + sb->s_flags |= SB_RDONLY; 4058 + } 4059 + 4060 + static void f2fs_record_error_work(struct work_struct *work) 4061 + { 4062 + struct f2fs_sb_info *sbi = container_of(work, 4063 + struct f2fs_sb_info, s_error_work); 4064 + 4065 + f2fs_record_stop_reason(sbi); 4084 4066 } 4085 4067 4086 4068 static int f2fs_scan_devices(struct f2fs_sb_info *sbi) ··· 4392 4220 sb->s_fs_info = sbi; 4393 4221 sbi->raw_super = raw_super; 4394 4222 4223 + INIT_WORK(&sbi->s_error_work, f2fs_record_error_work); 4395 4224 memcpy(sbi->errors, raw_super->s_errors, MAX_F2FS_ERRORS); 4225 + memcpy(sbi->stop_reason, raw_super->s_stop_reason, MAX_STOP_REASON); 4396 4226 4397 4227 /* precompute checksum seed for metadata */ 4398 4228 if (f2fs_sb_has_inode_chksum(sbi)) 4399 4229 sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid, 4400 4230 sizeof(raw_super->uuid)); 4401 4231 4402 - default_options(sbi); 4232 + default_options(sbi, false); 4403 4233 /* parse mount options */ 4404 4234 options = kstrdup((const char *)data, GFP_KERNEL); 4405 4235 if (data && !options) { ··· 4791 4617 f2fs_destroy_segment_manager(sbi); 4792 4618 stop_ckpt_thread: 4793 4619 f2fs_stop_ckpt_thread(sbi); 4620 + /* flush s_error_work before sbi destroy */ 4621 + flush_work(&sbi->s_error_work); 4794 4622 f2fs_destroy_post_read_wq(sbi); 4795 4623 free_devices: 4796 4624 destroy_device_list(sbi);
+174 -109
fs/f2fs/sysfs.c
··· 842 842 #define F2FS_GENERAL_RO_ATTR(name) \ 843 843 static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL) 844 844 845 - #define F2FS_STAT_ATTR(_struct_type, _struct_name, _name, _elname) \ 846 - static struct f2fs_attr f2fs_attr_##_name = { \ 847 - .attr = {.name = __stringify(_name), .mode = 0444 }, \ 848 - .show = f2fs_sbi_show, \ 849 - .struct_type = _struct_type, \ 850 - .offset = offsetof(struct _struct_name, _elname), \ 851 - } 845 + #ifdef CONFIG_F2FS_STAT_FS 846 + #define STAT_INFO_RO_ATTR(name, elname) \ 847 + F2FS_RO_ATTR(STAT_INFO, f2fs_stat_info, name, elname) 848 + #endif 852 849 853 - F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent_sleep_time, 854 - urgent_sleep_time); 855 - F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time); 856 - F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time); 857 - F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time); 858 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle, gc_mode); 859 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent, gc_mode); 860 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments); 861 - F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards); 862 - F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard_request, max_discard_request); 863 - F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, min_discard_issue_time, min_discard_issue_time); 864 - F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, mid_discard_issue_time, mid_discard_issue_time); 865 - F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_discard_issue_time, max_discard_issue_time); 866 - F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_io_aware_gran, discard_io_aware_gran); 867 - F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_urgent_util, discard_urgent_util); 868 - F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_granularity); 869 - F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_ordered_discard, max_ordered_discard); 870 - F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks); 871 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy); 872 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util); 873 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks); 874 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_seq_blocks, min_seq_blocks); 875 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks); 876 - F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ssr_sections, min_ssr_sections); 877 - F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh); 878 - F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages); 879 - F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio); 880 - F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, max_roll_forward_node_blocks, max_rf_node_blocks); 881 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search); 882 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, migration_granularity, migration_granularity); 883 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level); 884 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]); 885 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]); 886 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, discard_idle_interval, 887 - interval_time[DISCARD_TIME]); 888 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle_interval, interval_time[GC_TIME]); 889 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, 890 - umount_discard_timeout, interval_time[UMOUNT_DISCARD_TIMEOUT]); 891 - #ifdef CONFIG_F2FS_IOSTAT 892 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable); 893 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_period_ms, iostat_period_ms); 894 - #endif 895 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra); 896 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_io_bytes, max_io_bytes); 897 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold); 898 - F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list); 850 + #define GC_THREAD_RW_ATTR(name, elname) \ 851 + F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, name, elname) 852 + 853 + #define SM_INFO_RW_ATTR(name, elname) \ 854 + F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, name, elname) 855 + 856 + #define SM_INFO_GENERAL_RW_ATTR(elname) \ 857 + SM_INFO_RW_ATTR(elname, elname) 858 + 859 + #define DCC_INFO_RW_ATTR(name, elname) \ 860 + F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, name, elname) 861 + 862 + #define DCC_INFO_GENERAL_RW_ATTR(elname) \ 863 + DCC_INFO_RW_ATTR(elname, elname) 864 + 865 + #define NM_INFO_RW_ATTR(name, elname) \ 866 + F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, name, elname) 867 + 868 + #define NM_INFO_GENERAL_RW_ATTR(elname) \ 869 + NM_INFO_RW_ATTR(elname, elname) 870 + 871 + #define F2FS_SBI_RW_ATTR(name, elname) \ 872 + F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, name, elname) 873 + 874 + #define F2FS_SBI_GENERAL_RW_ATTR(elname) \ 875 + F2FS_SBI_RW_ATTR(elname, elname) 876 + 877 + #define F2FS_SBI_GENERAL_RO_ATTR(elname) \ 878 + F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, elname, elname) 879 + 899 880 #ifdef CONFIG_F2FS_FAULT_INJECTION 900 - F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate); 901 - F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type); 881 + #define FAULT_INFO_GENERAL_RW_ATTR(type, elname) \ 882 + F2FS_RW_ATTR(type, f2fs_fault_info, elname, elname) 902 883 #endif 903 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, data_io_flag, data_io_flag); 904 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, node_io_flag, node_io_flag); 905 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_remaining_trials, gc_remaining_trials); 906 - F2FS_RW_ATTR(CPRC_INFO, ckpt_req_control, ckpt_thread_ioprio, ckpt_thread_ioprio); 884 + 885 + #define RESERVED_BLOCKS_GENERAL_RW_ATTR(elname) \ 886 + F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, elname, elname) 887 + 888 + #define CPRC_INFO_GENERAL_RW_ATTR(elname) \ 889 + F2FS_RW_ATTR(CPRC_INFO, ckpt_req_control, elname, elname) 890 + 891 + #define ATGC_INFO_RW_ATTR(name, elname) \ 892 + F2FS_RW_ATTR(ATGC_INFO, atgc_management, name, elname) 893 + 894 + /* GC_THREAD ATTR */ 895 + GC_THREAD_RW_ATTR(gc_urgent_sleep_time, urgent_sleep_time); 896 + GC_THREAD_RW_ATTR(gc_min_sleep_time, min_sleep_time); 897 + GC_THREAD_RW_ATTR(gc_max_sleep_time, max_sleep_time); 898 + GC_THREAD_RW_ATTR(gc_no_gc_sleep_time, no_gc_sleep_time); 899 + 900 + /* SM_INFO ATTR */ 901 + SM_INFO_RW_ATTR(reclaim_segments, rec_prefree_segments); 902 + SM_INFO_GENERAL_RW_ATTR(ipu_policy); 903 + SM_INFO_GENERAL_RW_ATTR(min_ipu_util); 904 + SM_INFO_GENERAL_RW_ATTR(min_fsync_blocks); 905 + SM_INFO_GENERAL_RW_ATTR(min_seq_blocks); 906 + SM_INFO_GENERAL_RW_ATTR(min_hot_blocks); 907 + SM_INFO_GENERAL_RW_ATTR(min_ssr_sections); 908 + 909 + /* DCC_INFO ATTR */ 910 + DCC_INFO_RW_ATTR(max_small_discards, max_discards); 911 + DCC_INFO_GENERAL_RW_ATTR(max_discard_request); 912 + DCC_INFO_GENERAL_RW_ATTR(min_discard_issue_time); 913 + DCC_INFO_GENERAL_RW_ATTR(mid_discard_issue_time); 914 + DCC_INFO_GENERAL_RW_ATTR(max_discard_issue_time); 915 + DCC_INFO_GENERAL_RW_ATTR(discard_io_aware_gran); 916 + DCC_INFO_GENERAL_RW_ATTR(discard_urgent_util); 917 + DCC_INFO_GENERAL_RW_ATTR(discard_granularity); 918 + DCC_INFO_GENERAL_RW_ATTR(max_ordered_discard); 919 + 920 + /* NM_INFO ATTR */ 921 + NM_INFO_RW_ATTR(max_roll_forward_node_blocks, max_rf_node_blocks); 922 + NM_INFO_GENERAL_RW_ATTR(ram_thresh); 923 + NM_INFO_GENERAL_RW_ATTR(ra_nid_pages); 924 + NM_INFO_GENERAL_RW_ATTR(dirty_nats_ratio); 925 + 926 + /* F2FS_SBI ATTR */ 927 + F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list); 928 + F2FS_SBI_RW_ATTR(gc_idle, gc_mode); 929 + F2FS_SBI_RW_ATTR(gc_urgent, gc_mode); 930 + F2FS_SBI_RW_ATTR(cp_interval, interval_time[CP_TIME]); 931 + F2FS_SBI_RW_ATTR(idle_interval, interval_time[REQ_TIME]); 932 + F2FS_SBI_RW_ATTR(discard_idle_interval, interval_time[DISCARD_TIME]); 933 + F2FS_SBI_RW_ATTR(gc_idle_interval, interval_time[GC_TIME]); 934 + F2FS_SBI_RW_ATTR(umount_discard_timeout, interval_time[UMOUNT_DISCARD_TIMEOUT]); 935 + F2FS_SBI_RW_ATTR(gc_pin_file_thresh, gc_pin_file_threshold); 936 + F2FS_SBI_RW_ATTR(gc_reclaimed_segments, gc_reclaimed_segs); 937 + F2FS_SBI_GENERAL_RW_ATTR(max_victim_search); 938 + F2FS_SBI_GENERAL_RW_ATTR(migration_granularity); 939 + F2FS_SBI_GENERAL_RW_ATTR(dir_level); 940 + #ifdef CONFIG_F2FS_IOSTAT 941 + F2FS_SBI_GENERAL_RW_ATTR(iostat_enable); 942 + F2FS_SBI_GENERAL_RW_ATTR(iostat_period_ms); 943 + #endif 944 + F2FS_SBI_GENERAL_RW_ATTR(readdir_ra); 945 + F2FS_SBI_GENERAL_RW_ATTR(max_io_bytes); 946 + F2FS_SBI_GENERAL_RW_ATTR(data_io_flag); 947 + F2FS_SBI_GENERAL_RW_ATTR(node_io_flag); 948 + F2FS_SBI_GENERAL_RW_ATTR(gc_remaining_trials); 949 + F2FS_SBI_GENERAL_RW_ATTR(seq_file_ra_mul); 950 + F2FS_SBI_GENERAL_RW_ATTR(gc_segment_mode); 951 + F2FS_SBI_GENERAL_RW_ATTR(max_fragment_chunk); 952 + F2FS_SBI_GENERAL_RW_ATTR(max_fragment_hole); 953 + #ifdef CONFIG_F2FS_FS_COMPRESSION 954 + F2FS_SBI_GENERAL_RW_ATTR(compr_written_block); 955 + F2FS_SBI_GENERAL_RW_ATTR(compr_saved_block); 956 + F2FS_SBI_GENERAL_RW_ATTR(compr_new_inode); 957 + F2FS_SBI_GENERAL_RW_ATTR(compress_percent); 958 + F2FS_SBI_GENERAL_RW_ATTR(compress_watermark); 959 + #endif 960 + /* atomic write */ 961 + F2FS_SBI_GENERAL_RO_ATTR(current_atomic_write); 962 + F2FS_SBI_GENERAL_RW_ATTR(peak_atomic_write); 963 + F2FS_SBI_GENERAL_RW_ATTR(committed_atomic_block); 964 + F2FS_SBI_GENERAL_RW_ATTR(revoked_atomic_block); 965 + /* block age extent cache */ 966 + F2FS_SBI_GENERAL_RW_ATTR(hot_data_age_threshold); 967 + F2FS_SBI_GENERAL_RW_ATTR(warm_data_age_threshold); 968 + F2FS_SBI_GENERAL_RW_ATTR(last_age_weight); 969 + #ifdef CONFIG_BLK_DEV_ZONED 970 + F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec); 971 + #endif 972 + 973 + /* STAT_INFO ATTR */ 974 + #ifdef CONFIG_F2FS_STAT_FS 975 + STAT_INFO_RO_ATTR(cp_foreground_calls, cp_count); 976 + STAT_INFO_RO_ATTR(cp_background_calls, bg_cp_count); 977 + STAT_INFO_RO_ATTR(gc_foreground_calls, call_count); 978 + STAT_INFO_RO_ATTR(gc_background_calls, bg_gc); 979 + #endif 980 + 981 + /* FAULT_INFO ATTR */ 982 + #ifdef CONFIG_F2FS_FAULT_INJECTION 983 + FAULT_INFO_GENERAL_RW_ATTR(FAULT_INFO_RATE, inject_rate); 984 + FAULT_INFO_GENERAL_RW_ATTR(FAULT_INFO_TYPE, inject_type); 985 + #endif 986 + 987 + /* RESERVED_BLOCKS ATTR */ 988 + RESERVED_BLOCKS_GENERAL_RW_ATTR(reserved_blocks); 989 + 990 + /* CPRC_INFO ATTR */ 991 + CPRC_INFO_GENERAL_RW_ATTR(ckpt_thread_ioprio); 992 + 993 + /* ATGC_INFO ATTR */ 994 + ATGC_INFO_RW_ATTR(atgc_candidate_ratio, candidate_ratio); 995 + ATGC_INFO_RW_ATTR(atgc_candidate_count, max_candidate_count); 996 + ATGC_INFO_RW_ATTR(atgc_age_weight, age_weight); 997 + ATGC_INFO_RW_ATTR(atgc_age_threshold, age_threshold); 998 + 907 999 F2FS_GENERAL_RO_ATTR(dirty_segments); 908 1000 F2FS_GENERAL_RO_ATTR(free_segments); 909 1001 F2FS_GENERAL_RO_ATTR(ovp_segments); ··· 1009 917 F2FS_GENERAL_RO_ATTR(pending_discard); 1010 918 F2FS_GENERAL_RO_ATTR(gc_mode); 1011 919 #ifdef CONFIG_F2FS_STAT_FS 1012 - F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_foreground_calls, cp_count); 1013 - F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_background_calls, bg_cp_count); 1014 - F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_foreground_calls, call_count); 1015 - F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_background_calls, bg_gc); 1016 920 F2FS_GENERAL_RO_ATTR(moved_blocks_background); 1017 921 F2FS_GENERAL_RO_ATTR(moved_blocks_foreground); 1018 922 F2FS_GENERAL_RO_ATTR(avg_vblocks); ··· 1023 935 #endif /* CONFIG_FS_ENCRYPTION */ 1024 936 #ifdef CONFIG_BLK_DEV_ZONED 1025 937 F2FS_FEATURE_RO_ATTR(block_zoned); 1026 - F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, unusable_blocks_per_sec, 1027 - unusable_blocks_per_sec); 1028 938 #endif 1029 939 F2FS_FEATURE_RO_ATTR(atomic_write); 1030 940 F2FS_FEATURE_RO_ATTR(extra_attr); ··· 1042 956 F2FS_FEATURE_RO_ATTR(readonly); 1043 957 #ifdef CONFIG_F2FS_FS_COMPRESSION 1044 958 F2FS_FEATURE_RO_ATTR(compression); 1045 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_written_block, compr_written_block); 1046 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_saved_block, compr_saved_block); 1047 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compr_new_inode, compr_new_inode); 1048 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compress_percent, compress_percent); 1049 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, compress_watermark, compress_watermark); 1050 959 #endif 1051 960 F2FS_FEATURE_RO_ATTR(pin_file); 1052 - 1053 - /* For ATGC */ 1054 - F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_ratio, candidate_ratio); 1055 - F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_count); 1056 - F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight); 1057 - F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold); 1058 - 1059 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, seq_file_ra_mul, seq_file_ra_mul); 1060 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_segment_mode, gc_segment_mode); 1061 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_reclaimed_segments, gc_reclaimed_segs); 1062 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_chunk, max_fragment_chunk); 1063 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_fragment_hole, max_fragment_hole); 1064 - 1065 - /* For atomic write */ 1066 - F2FS_RO_ATTR(F2FS_SBI, f2fs_sb_info, current_atomic_write, current_atomic_write); 1067 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, peak_atomic_write, peak_atomic_write); 1068 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, committed_atomic_block, committed_atomic_block); 1069 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, revoked_atomic_block, revoked_atomic_block); 1070 - 1071 - /* For block age extent cache */ 1072 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, hot_data_age_threshold, hot_data_age_threshold); 1073 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, warm_data_age_threshold, warm_data_age_threshold); 1074 - F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, last_age_weight, last_age_weight); 1075 961 1076 962 #define ATTR_LIST(name) (&f2fs_attr_##name.attr) 1077 963 static struct attribute *f2fs_attrs[] = { ··· 1444 1386 1445 1387 ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype, 1446 1388 NULL, "features"); 1447 - if (ret) { 1448 - kobject_put(&f2fs_feat); 1449 - kset_unregister(&f2fs_kset); 1450 - } else { 1451 - f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); 1389 + if (ret) 1390 + goto put_kobject; 1391 + 1392 + f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); 1393 + if (!f2fs_proc_root) { 1394 + ret = -ENOMEM; 1395 + goto put_kobject; 1452 1396 } 1397 + 1398 + return 0; 1399 + put_kobject: 1400 + kobject_put(&f2fs_feat); 1401 + kset_unregister(&f2fs_kset); 1453 1402 return ret; 1454 1403 } 1455 1404 ··· 1495 1430 if (err) 1496 1431 goto put_feature_list_kobj; 1497 1432 1498 - if (f2fs_proc_root) 1499 - sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); 1433 + sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); 1434 + if (!sbi->s_proc) { 1435 + err = -ENOMEM; 1436 + goto put_feature_list_kobj; 1437 + } 1500 1438 1501 - if (sbi->s_proc) { 1502 - proc_create_single_data("segment_info", 0444, sbi->s_proc, 1439 + proc_create_single_data("segment_info", 0444, sbi->s_proc, 1503 1440 segment_info_seq_show, sb); 1504 - proc_create_single_data("segment_bits", 0444, sbi->s_proc, 1441 + proc_create_single_data("segment_bits", 0444, sbi->s_proc, 1505 1442 segment_bits_seq_show, sb); 1506 1443 #ifdef CONFIG_F2FS_IOSTAT 1507 - proc_create_single_data("iostat_info", 0444, sbi->s_proc, 1444 + proc_create_single_data("iostat_info", 0444, sbi->s_proc, 1508 1445 iostat_info_seq_show, sb); 1509 1446 #endif 1510 - proc_create_single_data("victim_bits", 0444, sbi->s_proc, 1447 + proc_create_single_data("victim_bits", 0444, sbi->s_proc, 1511 1448 victim_bits_seq_show, sb); 1512 - proc_create_single_data("discard_plist_info", 0444, sbi->s_proc, 1449 + proc_create_single_data("discard_plist_info", 0444, sbi->s_proc, 1513 1450 discard_plist_seq_show, sb); 1514 - } 1515 1451 return 0; 1516 1452 put_feature_list_kobj: 1517 1453 kobject_put(&sbi->s_feature_list_kobj); ··· 1528 1462 1529 1463 void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) 1530 1464 { 1531 - if (sbi->s_proc) 1532 - remove_proc_subtree(sbi->sb->s_id, f2fs_proc_root); 1465 + remove_proc_subtree(sbi->sb->s_id, f2fs_proc_root); 1533 1466 1534 1467 kobject_put(&sbi->s_stat_kobj); 1535 1468 wait_for_completion(&sbi->s_stat_kobj_unregister);
+4 -2
fs/f2fs/xattr.c
··· 528 528 if (len > F2FS_NAME_LEN) 529 529 return -ERANGE; 530 530 531 - f2fs_down_read(&F2FS_I(inode)->i_xattr_sem); 531 + if (!ipage) 532 + f2fs_down_read(&F2FS_I(inode)->i_xattr_sem); 532 533 error = lookup_all_xattrs(inode, ipage, index, len, name, 533 534 &entry, &base_addr, &base_size, &is_inline); 534 - f2fs_up_read(&F2FS_I(inode)->i_xattr_sem); 535 + if (!ipage) 536 + f2fs_up_read(&F2FS_I(inode)->i_xattr_sem); 535 537 if (error) 536 538 return error; 537 539
+1
fs/f2fs/xattr.h
··· 83 83 sizeof(struct f2fs_xattr_header) - \ 84 84 sizeof(struct f2fs_xattr_entry)) 85 85 86 + #define MIN_INLINE_XATTR_SIZE (sizeof(struct f2fs_xattr_header) / sizeof(__le32)) 86 87 #define MAX_INLINE_XATTR_SIZE \ 87 88 (DEF_ADDRS_PER_INODE - \ 88 89 F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \
+1
include/linux/f2fs_fs.h
··· 103 103 ERROR_INCONSISTENT_SIT, 104 104 ERROR_CORRUPTED_VERITY_XATTR, 105 105 ERROR_CORRUPTED_XATTR, 106 + ERROR_INVALID_NODE_REFERENCE, 106 107 ERROR_MAX, 107 108 }; 108 109
+21 -3
include/trace/events/f2fs.h
··· 1512 1512 TP_ARGS(dev, blkstart, blklen) 1513 1513 ); 1514 1514 1515 - TRACE_EVENT(f2fs_issue_reset_zone, 1515 + DECLARE_EVENT_CLASS(f2fs_reset_zone, 1516 1516 1517 1517 TP_PROTO(struct block_device *dev, block_t blkstart), 1518 1518 ··· 1528 1528 __entry->blkstart = blkstart; 1529 1529 ), 1530 1530 1531 - TP_printk("dev = (%d,%d), reset zone at block = 0x%llx", 1531 + TP_printk("dev = (%d,%d), zone at block = 0x%llx", 1532 1532 show_dev(__entry->dev), 1533 1533 (unsigned long long)__entry->blkstart) 1534 + ); 1535 + 1536 + DEFINE_EVENT(f2fs_reset_zone, f2fs_queue_reset_zone, 1537 + 1538 + TP_PROTO(struct block_device *dev, block_t blkstart), 1539 + 1540 + TP_ARGS(dev, blkstart) 1541 + ); 1542 + 1543 + DEFINE_EVENT(f2fs_reset_zone, f2fs_issue_reset_zone, 1544 + 1545 + TP_PROTO(struct block_device *dev, block_t blkstart), 1546 + 1547 + TP_ARGS(dev, blkstart) 1534 1548 ); 1535 1549 1536 1550 TRACE_EVENT(f2fs_issue_flush, ··· 1993 1979 __field(unsigned long long, fs_nrio) 1994 1980 __field(unsigned long long, fs_mrio) 1995 1981 __field(unsigned long long, fs_discard) 1982 + __field(unsigned long long, fs_reset_zone) 1996 1983 ), 1997 1984 1998 1985 TP_fast_assign( ··· 2025 2010 __entry->fs_nrio = iostat[FS_NODE_READ_IO]; 2026 2011 __entry->fs_mrio = iostat[FS_META_READ_IO]; 2027 2012 __entry->fs_discard = iostat[FS_DISCARD_IO]; 2013 + __entry->fs_reset_zone = iostat[FS_ZONE_RESET_IO]; 2028 2014 ), 2029 2015 2030 2016 TP_printk("dev = (%d,%d), " 2031 2017 "app [write=%llu (direct=%llu, buffered=%llu), mapped=%llu, " 2032 2018 "compr(buffered=%llu, mapped=%llu)], " 2033 - "fs [data=%llu, cdata=%llu, node=%llu, meta=%llu, discard=%llu], " 2019 + "fs [data=%llu, cdata=%llu, node=%llu, meta=%llu, discard=%llu, " 2020 + "reset_zone=%llu], " 2034 2021 "gc [data=%llu, node=%llu], " 2035 2022 "cp [data=%llu, node=%llu, meta=%llu], " 2036 2023 "app [read=%llu (direct=%llu, buffered=%llu), mapped=%llu], " ··· 2043 2026 __entry->app_bio, __entry->app_mio, __entry->app_bcdio, 2044 2027 __entry->app_mcdio, __entry->fs_dio, __entry->fs_cdio, 2045 2028 __entry->fs_nio, __entry->fs_mio, __entry->fs_discard, 2029 + __entry->fs_reset_zone, 2046 2030 __entry->fs_gc_dio, __entry->fs_gc_nio, __entry->fs_cp_dio, 2047 2031 __entry->fs_cp_nio, __entry->fs_cp_mio, 2048 2032 __entry->app_rio, __entry->app_drio, __entry->app_brio,