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.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

Pull f2fs updates from Jaegeuk Kim:
"A pretty small update including mostly minor bug fixes in zoned
storage along with the large section support.

Enhancements:
- add support for FS_IOC_GETFSSYSFSPATH
- enable atgc dynamically if conditions are met
- use new ioprio Macro to get ckpt thread ioprio level
- remove unreachable lazytime mount option parsing

Bug fixes:
- fix null reference error when checking end of zone
- fix start segno of large section
- fix to cover read extent cache access with lock
- don't dirty inode for readonly filesystem
- allocate a new section if curseg is not the first seg in its zone
- only fragment segment in the same section
- truncate preallocated blocks in f2fs_file_open()
- fix to avoid use SSR allocate when do defragment
- fix to force buffered IO on inline_data inode

And some minor code clean-ups and sanity checks"

* tag 'f2fs-for-6.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (26 commits)
f2fs: clean up addrs_per_{inode,block}()
f2fs: clean up F2FS_I()
f2fs: use meta inode for GC of COW file
f2fs: use meta inode for GC of atomic file
f2fs: only fragment segment in the same section
f2fs: fix to update user block counts in block_operations()
f2fs: remove unreachable lazytime mount option parsing
f2fs: fix null reference error when checking end of zone
f2fs: fix start segno of large section
f2fs: remove redundant sanity check in sanity_check_inode()
f2fs: assign CURSEG_ALL_DATA_ATGC if blkaddr is valid
f2fs: fix to use mnt_{want,drop}_write_file replace file_{start,end}_wrtie
f2fs: clean up set REQ_RAHEAD given rac
f2fs: enable atgc dynamically if conditions are met
f2fs: fix to truncate preallocated blocks in f2fs_file_open()
f2fs: fix to cover read extent cache access with lock
f2fs: fix return value of f2fs_convert_inline_inode()
f2fs: use new ioprio Macro to get ckpt thread ioprio level
f2fs: fix to don't dirty inode for readonly filesystem
f2fs: fix to avoid use SSR allocate when do defragment
...

+330 -227
+6 -5
fs/f2fs/checkpoint.c
··· 1186 1186 ckpt->valid_node_count = cpu_to_le32(valid_node_count(sbi)); 1187 1187 ckpt->valid_inode_count = cpu_to_le32(valid_inode_count(sbi)); 1188 1188 ckpt->next_free_nid = cpu_to_le32(last_nid); 1189 + 1190 + /* update user_block_counts */ 1191 + sbi->last_valid_block_count = sbi->total_valid_block_count; 1192 + percpu_counter_set(&sbi->alloc_valid_block_count, 0); 1193 + percpu_counter_set(&sbi->rf_node_block_count, 0); 1189 1194 } 1190 1195 1191 1196 static bool __need_flush_quota(struct f2fs_sb_info *sbi) ··· 1580 1575 start_blk += NR_CURSEG_NODE_TYPE; 1581 1576 } 1582 1577 1583 - /* update user_block_counts */ 1584 - sbi->last_valid_block_count = sbi->total_valid_block_count; 1585 - percpu_counter_set(&sbi->alloc_valid_block_count, 0); 1586 - percpu_counter_set(&sbi->rf_node_block_count, 0); 1587 - 1588 1578 /* Here, we have one bio having CP pack except cp pack 2 page */ 1589 1579 f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO); 1590 1580 /* Wait for all dirty meta pages to be submitted for IO */ ··· 1718 1718 } 1719 1719 1720 1720 f2fs_restore_inmem_curseg(sbi); 1721 + f2fs_reinit_atgc_curseg(sbi); 1721 1722 stat_inc_cp_count(sbi); 1722 1723 stop: 1723 1724 unblock_operations(sbi);
+1 -1
fs/f2fs/compress.c
··· 1100 1100 struct bio *bio = NULL; 1101 1101 1102 1102 ret = f2fs_read_multi_pages(cc, &bio, cc->cluster_size, 1103 - &last_block_in_bio, false, true); 1103 + &last_block_in_bio, NULL, true); 1104 1104 f2fs_put_rpages(cc); 1105 1105 f2fs_destroy_compress_ctx(cc, true); 1106 1106 if (ret)
+17 -10
fs/f2fs/data.c
··· 925 925 #ifdef CONFIG_BLK_DEV_ZONED 926 926 static bool is_end_zone_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr) 927 927 { 928 + struct block_device *bdev = sbi->sb->s_bdev; 928 929 int devi = 0; 929 930 930 931 if (f2fs_is_multi_device(sbi)) { ··· 936 935 return false; 937 936 } 938 937 blkaddr -= FDEV(devi).start_blk; 938 + bdev = FDEV(devi).bdev; 939 939 } 940 - return bdev_is_zoned(FDEV(devi).bdev) && 940 + return bdev_is_zoned(bdev) && 941 941 f2fs_blkz_is_seq(sbi, devi, blkaddr) && 942 942 (blkaddr % sbi->blocks_per_blkz == sbi->blocks_per_blkz - 1); 943 943 } ··· 2069 2067 return i_size_read(inode); 2070 2068 } 2071 2069 2070 + static inline blk_opf_t f2fs_ra_op_flags(struct readahead_control *rac) 2071 + { 2072 + return rac ? REQ_RAHEAD : 0; 2073 + } 2074 + 2072 2075 static int f2fs_read_single_page(struct inode *inode, struct folio *folio, 2073 2076 unsigned nr_pages, 2074 2077 struct f2fs_map_blocks *map, 2075 2078 struct bio **bio_ret, 2076 2079 sector_t *last_block_in_bio, 2077 - bool is_readahead) 2080 + struct readahead_control *rac) 2078 2081 { 2079 2082 struct bio *bio = *bio_ret; 2080 2083 const unsigned blocksize = blks_to_bytes(inode, 1); ··· 2155 2148 } 2156 2149 if (bio == NULL) { 2157 2150 bio = f2fs_grab_read_bio(inode, block_nr, nr_pages, 2158 - is_readahead ? REQ_RAHEAD : 0, index, 2151 + f2fs_ra_op_flags(rac), index, 2159 2152 false); 2160 2153 if (IS_ERR(bio)) { 2161 2154 ret = PTR_ERR(bio); ··· 2185 2178 #ifdef CONFIG_F2FS_FS_COMPRESSION 2186 2179 int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, 2187 2180 unsigned nr_pages, sector_t *last_block_in_bio, 2188 - bool is_readahead, bool for_write) 2181 + struct readahead_control *rac, bool for_write) 2189 2182 { 2190 2183 struct dnode_of_data dn; 2191 2184 struct inode *inode = cc->inode; ··· 2308 2301 2309 2302 if (!bio) { 2310 2303 bio = f2fs_grab_read_bio(inode, blkaddr, nr_pages, 2311 - is_readahead ? REQ_RAHEAD : 0, 2304 + f2fs_ra_op_flags(rac), 2312 2305 page->index, for_write); 2313 2306 if (IS_ERR(bio)) { 2314 2307 ret = PTR_ERR(bio); ··· 2406 2399 ret = f2fs_read_multi_pages(&cc, &bio, 2407 2400 max_nr_pages, 2408 2401 &last_block_in_bio, 2409 - rac != NULL, false); 2402 + rac, false); 2410 2403 f2fs_destroy_compress_ctx(&cc, false); 2411 2404 if (ret) 2412 2405 goto set_error_page; ··· 2456 2449 ret = f2fs_read_multi_pages(&cc, &bio, 2457 2450 max_nr_pages, 2458 2451 &last_block_in_bio, 2459 - rac != NULL, false); 2452 + rac, false); 2460 2453 f2fs_destroy_compress_ctx(&cc, false); 2461 2454 } 2462 2455 } ··· 2608 2601 return true; 2609 2602 if (IS_NOQUOTA(inode)) 2610 2603 return true; 2611 - if (f2fs_is_atomic_file(inode)) 2604 + if (f2fs_used_in_atomic_write(inode)) 2612 2605 return true; 2613 2606 /* rewrite low ratio compress data w/ OPU mode to avoid fragmentation */ 2614 2607 if (f2fs_compressed_file(inode) && ··· 2695 2688 } 2696 2689 2697 2690 /* wait for GCed page writeback via META_MAPPING */ 2698 - if (fio->post_read) 2691 + if (fio->meta_gc) 2699 2692 f2fs_wait_on_block_writeback(inode, fio->old_blkaddr); 2700 2693 2701 2694 /* ··· 2790 2783 .submitted = 0, 2791 2784 .compr_blocks = compr_blocks, 2792 2785 .need_lock = compr_blocks ? LOCK_DONE : LOCK_RETRY, 2793 - .post_read = f2fs_post_read_required(inode) ? 1 : 0, 2786 + .meta_gc = f2fs_meta_inode_gc_required(inode) ? 1 : 0, 2794 2787 .io_type = io_type, 2795 2788 .io_wbc = wbc, 2796 2789 .bio = bio,
+20 -30
fs/f2fs/extent_cache.c
··· 19 19 #include "node.h" 20 20 #include <trace/events/f2fs.h> 21 21 22 - bool sanity_check_extent_cache(struct inode *inode) 22 + bool sanity_check_extent_cache(struct inode *inode, struct page *ipage) 23 23 { 24 24 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 25 - struct f2fs_inode_info *fi = F2FS_I(inode); 26 - struct extent_tree *et = fi->extent_tree[EX_READ]; 27 - struct extent_info *ei; 25 + struct f2fs_extent *i_ext = &F2FS_INODE(ipage)->i_ext; 26 + struct extent_info ei; 28 27 29 - if (!et) 28 + get_read_extent_info(&ei, i_ext); 29 + 30 + if (!ei.len) 30 31 return true; 31 32 32 - ei = &et->largest; 33 - if (!ei->len) 34 - return true; 35 - 36 - /* Let's drop, if checkpoint got corrupted. */ 37 - if (is_set_ckpt_flags(sbi, CP_ERROR_FLAG)) { 38 - ei->len = 0; 39 - et->largest_updated = true; 40 - return true; 41 - } 42 - 43 - if (!f2fs_is_valid_blkaddr(sbi, ei->blk, DATA_GENERIC_ENHANCE) || 44 - !f2fs_is_valid_blkaddr(sbi, ei->blk + ei->len - 1, 33 + if (!f2fs_is_valid_blkaddr(sbi, ei.blk, DATA_GENERIC_ENHANCE) || 34 + !f2fs_is_valid_blkaddr(sbi, ei.blk + ei.len - 1, 45 35 DATA_GENERIC_ENHANCE)) { 46 36 f2fs_warn(sbi, "%s: inode (ino=%lx) extent info [%u, %u, %u] is incorrect, run fsck to fix", 47 37 __func__, inode->i_ino, 48 - ei->blk, ei->fofs, ei->len); 38 + ei.blk, ei.fofs, ei.len); 49 39 return false; 50 40 } 51 41 return true; ··· 384 394 385 395 if (!__may_extent_tree(inode, EX_READ)) { 386 396 /* drop largest read extent */ 387 - if (i_ext && i_ext->len) { 397 + if (i_ext->len) { 388 398 f2fs_wait_on_page_writeback(ipage, NODE, true, true); 389 399 i_ext->len = 0; 390 400 set_page_dirty(ipage); 391 401 } 392 - goto out; 402 + set_inode_flag(inode, FI_NO_EXTENT); 403 + return; 393 404 } 394 405 395 406 et = __grab_extent_tree(inode, EX_READ); 396 407 397 - if (!i_ext || !i_ext->len) 398 - goto out; 399 - 400 408 get_read_extent_info(&ei, i_ext); 401 409 402 410 write_lock(&et->lock); 403 - if (atomic_read(&et->node_cnt)) 404 - goto unlock_out; 411 + if (atomic_read(&et->node_cnt) || !ei.len) 412 + goto skip; 405 413 406 414 en = __attach_extent_node(sbi, et, &ei, NULL, 407 415 &et->root.rb_root.rb_node, true); ··· 411 423 list_add_tail(&en->list, &eti->extent_list); 412 424 spin_unlock(&eti->extent_lock); 413 425 } 414 - unlock_out: 426 + skip: 427 + /* Let's drop, if checkpoint got corrupted. */ 428 + if (f2fs_cp_error(sbi)) { 429 + et->largest.len = 0; 430 + et->largest_updated = true; 431 + } 415 432 write_unlock(&et->lock); 416 - out: 417 - if (!F2FS_I(inode)->extent_tree[EX_READ]) 418 - set_inode_flag(inode, FI_NO_EXTENT); 419 433 } 420 434 421 435 void f2fs_init_age_extent_tree(struct inode *inode)
+42 -36
fs/f2fs/f2fs.h
··· 803 803 FI_COW_FILE, /* indicate COW file */ 804 804 FI_ATOMIC_COMMITTED, /* indicate atomic commit completed except disk sync */ 805 805 FI_ATOMIC_REPLACE, /* indicate atomic replace */ 806 + FI_OPENED_FILE, /* indicate file has been opened */ 806 807 FI_MAX, /* max flag, never be used */ 807 808 }; 808 809 ··· 843 842 struct task_struct *atomic_write_task; /* store atomic write task */ 844 843 struct extent_tree *extent_tree[NR_EXTENT_CACHES]; 845 844 /* cached extent_tree entry */ 846 - struct inode *cow_inode; /* copy-on-write inode for atomic write */ 845 + union { 846 + struct inode *cow_inode; /* copy-on-write inode for atomic write */ 847 + struct inode *atomic_inode; 848 + /* point to atomic_inode, available only for cow_inode */ 849 + }; 847 850 848 851 /* avoid racing between foreground op and gc */ 849 852 struct f2fs_rwsem i_gc_rwsem[2]; ··· 1215 1210 unsigned int in_list:1; /* indicate fio is in io_list */ 1216 1211 unsigned int is_por:1; /* indicate IO is from recovery or not */ 1217 1212 unsigned int encrypted:1; /* indicate file is encrypted */ 1218 - unsigned int post_read:1; /* require post read */ 1213 + unsigned int meta_gc:1; /* require meta inode GC */ 1219 1214 enum iostat_type io_type; /* io type */ 1220 1215 struct writeback_control *io_wbc; /* writeback control */ 1221 1216 struct bio **bio; /* bio for ipu */ ··· 3227 3222 return false; 3228 3223 } 3229 3224 3230 - static inline unsigned int addrs_per_inode(struct inode *inode) 3225 + static inline unsigned int addrs_per_page(struct inode *inode, 3226 + bool is_inode) 3231 3227 { 3232 - unsigned int addrs = CUR_ADDRS_PER_INODE(inode) - 3233 - get_inline_xattr_addrs(inode); 3228 + unsigned int addrs = is_inode ? (CUR_ADDRS_PER_INODE(inode) - 3229 + get_inline_xattr_addrs(inode)) : DEF_ADDRS_PER_BLOCK; 3234 3230 3235 - if (!f2fs_compressed_file(inode)) 3236 - return addrs; 3237 - return ALIGN_DOWN(addrs, F2FS_I(inode)->i_cluster_size); 3238 - } 3239 - 3240 - static inline unsigned int addrs_per_block(struct inode *inode) 3241 - { 3242 - if (!f2fs_compressed_file(inode)) 3243 - return DEF_ADDRS_PER_BLOCK; 3244 - return ALIGN_DOWN(DEF_ADDRS_PER_BLOCK, F2FS_I(inode)->i_cluster_size); 3231 + if (f2fs_compressed_file(inode)) 3232 + return ALIGN_DOWN(addrs, F2FS_I(inode)->i_cluster_size); 3233 + return addrs; 3245 3234 } 3246 3235 3247 3236 static inline void *inline_xattr_addr(struct inode *inode, struct page *page) ··· 3705 3706 int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 3706 3707 bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno); 3707 3708 int f2fs_init_inmem_curseg(struct f2fs_sb_info *sbi); 3709 + int f2fs_reinit_atgc_curseg(struct f2fs_sb_info *sbi); 3708 3710 void f2fs_save_inmem_curseg(struct f2fs_sb_info *sbi); 3709 3711 void f2fs_restore_inmem_curseg(struct f2fs_sb_info *sbi); 3710 3712 int f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, ··· 4163 4163 * inline.c 4164 4164 */ 4165 4165 bool f2fs_may_inline_data(struct inode *inode); 4166 - bool f2fs_sanity_check_inline_data(struct inode *inode); 4166 + bool f2fs_sanity_check_inline_data(struct inode *inode, struct page *ipage); 4167 4167 bool f2fs_may_inline_dentry(struct inode *inode); 4168 4168 void f2fs_do_read_inline_data(struct folio *folio, struct page *ipage); 4169 4169 void f2fs_truncate_inline_inode(struct inode *inode, ··· 4204 4204 /* 4205 4205 * extent_cache.c 4206 4206 */ 4207 - bool sanity_check_extent_cache(struct inode *inode); 4207 + bool sanity_check_extent_cache(struct inode *inode, struct page *ipage); 4208 4208 void f2fs_init_extent_tree(struct inode *inode); 4209 4209 void f2fs_drop_extent_tree(struct inode *inode); 4210 4210 void f2fs_destroy_extent_node(struct inode *inode); ··· 4275 4275 f2fs_compressed_file(inode); 4276 4276 } 4277 4277 4278 + static inline bool f2fs_used_in_atomic_write(struct inode *inode) 4279 + { 4280 + return f2fs_is_atomic_file(inode) || f2fs_is_cow_file(inode); 4281 + } 4282 + 4283 + static inline bool f2fs_meta_inode_gc_required(struct inode *inode) 4284 + { 4285 + return f2fs_post_read_required(inode) || f2fs_used_in_atomic_write(inode); 4286 + } 4287 + 4278 4288 /* 4279 4289 * compress.c 4280 4290 */ ··· 4320 4310 unsigned int llen, unsigned int c_len); 4321 4311 int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, 4322 4312 unsigned nr_pages, sector_t *last_block_in_bio, 4323 - bool is_readahead, bool for_write); 4313 + struct readahead_control *rac, bool for_write); 4324 4314 struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc); 4325 4315 void f2fs_decompress_end_io(struct decompress_io_ctx *dic, bool failed, 4326 4316 bool in_task); ··· 4411 4401 { 4412 4402 #ifdef CONFIG_F2FS_FS_COMPRESSION 4413 4403 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4404 + struct f2fs_inode_info *fi = F2FS_I(inode); 4414 4405 4415 - F2FS_I(inode)->i_compress_algorithm = 4416 - F2FS_OPTION(sbi).compress_algorithm; 4417 - F2FS_I(inode)->i_log_cluster_size = 4418 - F2FS_OPTION(sbi).compress_log_size; 4419 - F2FS_I(inode)->i_compress_flag = 4420 - F2FS_OPTION(sbi).compress_chksum ? 4421 - BIT(COMPRESS_CHKSUM) : 0; 4422 - F2FS_I(inode)->i_cluster_size = 4423 - BIT(F2FS_I(inode)->i_log_cluster_size); 4424 - if ((F2FS_I(inode)->i_compress_algorithm == COMPRESS_LZ4 || 4425 - F2FS_I(inode)->i_compress_algorithm == COMPRESS_ZSTD) && 4406 + fi->i_compress_algorithm = F2FS_OPTION(sbi).compress_algorithm; 4407 + fi->i_log_cluster_size = F2FS_OPTION(sbi).compress_log_size; 4408 + fi->i_compress_flag = F2FS_OPTION(sbi).compress_chksum ? 4409 + BIT(COMPRESS_CHKSUM) : 0; 4410 + fi->i_cluster_size = BIT(fi->i_log_cluster_size); 4411 + if ((fi->i_compress_algorithm == COMPRESS_LZ4 || 4412 + fi->i_compress_algorithm == COMPRESS_ZSTD) && 4426 4413 F2FS_OPTION(sbi).compress_level) 4427 - F2FS_I(inode)->i_compress_level = 4428 - F2FS_OPTION(sbi).compress_level; 4429 - F2FS_I(inode)->i_flags |= F2FS_COMPR_FL; 4414 + fi->i_compress_level = F2FS_OPTION(sbi).compress_level; 4415 + fi->i_flags |= F2FS_COMPR_FL; 4430 4416 set_inode_flag(inode, FI_COMPRESSED_FILE); 4431 4417 stat_inc_compr_inode(inode); 4432 4418 inc_compr_inode_stat(inode); ··· 4437 4431 { 4438 4432 struct f2fs_inode_info *fi = F2FS_I(inode); 4439 4433 4440 - f2fs_down_write(&F2FS_I(inode)->i_sem); 4434 + f2fs_down_write(&fi->i_sem); 4441 4435 4442 4436 if (!f2fs_compressed_file(inode)) { 4443 - f2fs_up_write(&F2FS_I(inode)->i_sem); 4437 + f2fs_up_write(&fi->i_sem); 4444 4438 return true; 4445 4439 } 4446 4440 if (f2fs_is_mmap_file(inode) || 4447 4441 (S_ISREG(inode->i_mode) && F2FS_HAS_BLOCKS(inode))) { 4448 - f2fs_up_write(&F2FS_I(inode)->i_sem); 4442 + f2fs_up_write(&fi->i_sem); 4449 4443 return false; 4450 4444 } 4451 4445 ··· 4454 4448 clear_inode_flag(inode, FI_COMPRESSED_FILE); 4455 4449 f2fs_mark_inode_dirty_sync(inode, true); 4456 4450 4457 - f2fs_up_write(&F2FS_I(inode)->i_sem); 4451 + f2fs_up_write(&fi->i_sem); 4458 4452 return true; 4459 4453 } 4460 4454
+96 -39
fs/f2fs/file.c
··· 554 554 return 0; 555 555 } 556 556 557 + static int finish_preallocate_blocks(struct inode *inode) 558 + { 559 + int ret; 560 + 561 + inode_lock(inode); 562 + if (is_inode_flag_set(inode, FI_OPENED_FILE)) { 563 + inode_unlock(inode); 564 + return 0; 565 + } 566 + 567 + if (!file_should_truncate(inode)) { 568 + set_inode_flag(inode, FI_OPENED_FILE); 569 + inode_unlock(inode); 570 + return 0; 571 + } 572 + 573 + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 574 + filemap_invalidate_lock(inode->i_mapping); 575 + 576 + truncate_setsize(inode, i_size_read(inode)); 577 + ret = f2fs_truncate(inode); 578 + 579 + filemap_invalidate_unlock(inode->i_mapping); 580 + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 581 + 582 + if (!ret) 583 + set_inode_flag(inode, FI_OPENED_FILE); 584 + 585 + inode_unlock(inode); 586 + if (ret) 587 + return ret; 588 + 589 + file_dont_truncate(inode); 590 + return 0; 591 + } 592 + 557 593 static int f2fs_file_open(struct inode *inode, struct file *filp) 558 594 { 559 595 int err = fscrypt_file_open(inode, filp); ··· 607 571 filp->f_mode |= FMODE_NOWAIT; 608 572 filp->f_mode |= FMODE_CAN_ODIRECT; 609 573 610 - return dquot_file_open(inode, filp); 574 + err = dquot_file_open(inode, filp); 575 + if (err) 576 + return err; 577 + 578 + return finish_preallocate_blocks(inode); 611 579 } 612 580 613 581 void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) ··· 865 825 return true; 866 826 if (f2fs_compressed_file(inode)) 867 827 return true; 828 + if (f2fs_has_inline_data(inode)) 829 + return true; 868 830 869 831 /* disallow direct IO if any of devices has unaligned blksize */ 870 832 if (f2fs_is_multi_device(sbi) && !sbi->aligned_blksize) ··· 979 937 struct iattr *attr) 980 938 { 981 939 struct inode *inode = d_inode(dentry); 940 + struct f2fs_inode_info *fi = F2FS_I(inode); 982 941 int err; 983 942 984 943 if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) ··· 998 955 return -EOPNOTSUPP; 999 956 if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED) && 1000 957 !IS_ALIGNED(attr->ia_size, 1001 - F2FS_BLK_TO_BYTES(F2FS_I(inode)->i_cluster_size))) 958 + F2FS_BLK_TO_BYTES(fi->i_cluster_size))) 1002 959 return -EINVAL; 1003 960 } 1004 961 ··· 1052 1009 return err; 1053 1010 } 1054 1011 1055 - f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 1012 + f2fs_down_write(&fi->i_gc_rwsem[WRITE]); 1056 1013 filemap_invalidate_lock(inode->i_mapping); 1057 1014 1058 1015 truncate_setsize(inode, attr->ia_size); ··· 1064 1021 * larger than i_size. 1065 1022 */ 1066 1023 filemap_invalidate_unlock(inode->i_mapping); 1067 - f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 1024 + f2fs_up_write(&fi->i_gc_rwsem[WRITE]); 1068 1025 if (err) 1069 1026 return err; 1070 1027 1071 - spin_lock(&F2FS_I(inode)->i_size_lock); 1028 + spin_lock(&fi->i_size_lock); 1072 1029 inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); 1073 - F2FS_I(inode)->last_disk_size = i_size_read(inode); 1074 - spin_unlock(&F2FS_I(inode)->i_size_lock); 1030 + fi->last_disk_size = i_size_read(inode); 1031 + spin_unlock(&fi->i_size_lock); 1075 1032 } 1076 1033 1077 1034 __setattr_copy(idmap, inode, attr); ··· 1081 1038 1082 1039 if (is_inode_flag_set(inode, FI_ACL_MODE)) { 1083 1040 if (!err) 1084 - inode->i_mode = F2FS_I(inode)->i_acl_mode; 1041 + inode->i_mode = fi->i_acl_mode; 1085 1042 clear_inode_flag(inode, FI_ACL_MODE); 1086 1043 } 1087 1044 } ··· 1989 1946 if (err) 1990 1947 return err; 1991 1948 1992 - f2fs_down_write(&F2FS_I(inode)->i_sem); 1949 + f2fs_down_write(&fi->i_sem); 1993 1950 if (!f2fs_may_compress(inode) || 1994 1951 (S_ISREG(inode->i_mode) && 1995 1952 F2FS_HAS_BLOCKS(inode))) { 1996 - f2fs_up_write(&F2FS_I(inode)->i_sem); 1953 + f2fs_up_write(&fi->i_sem); 1997 1954 return -EINVAL; 1998 1955 } 1999 1956 err = set_compress_context(inode); 2000 - f2fs_up_write(&F2FS_I(inode)->i_sem); 1957 + f2fs_up_write(&fi->i_sem); 2001 1958 2002 1959 if (err) 2003 1960 return err; ··· 2182 2139 2183 2140 set_inode_flag(fi->cow_inode, FI_COW_FILE); 2184 2141 clear_inode_flag(fi->cow_inode, FI_INLINE_DATA); 2142 + 2143 + /* Set the COW inode's atomic_inode to the atomic inode */ 2144 + F2FS_I(fi->cow_inode)->atomic_inode = inode; 2185 2145 } else { 2186 2146 /* Reuse the already created COW inode */ 2187 2147 ret = f2fs_do_truncate_blocks(fi->cow_inode, 0, true); ··· 3587 3541 static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) 3588 3542 { 3589 3543 struct inode *inode = file_inode(filp); 3544 + struct f2fs_inode_info *fi = F2FS_I(inode); 3590 3545 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 3591 3546 pgoff_t page_idx = 0, last_idx; 3592 3547 unsigned int released_blocks = 0; ··· 3625 3578 if (ret) 3626 3579 goto out; 3627 3580 3628 - if (!atomic_read(&F2FS_I(inode)->i_compr_blocks)) { 3581 + if (!atomic_read(&fi->i_compr_blocks)) { 3629 3582 ret = -EPERM; 3630 3583 goto out; 3631 3584 } ··· 3634 3587 inode_set_ctime_current(inode); 3635 3588 f2fs_mark_inode_dirty_sync(inode, true); 3636 3589 3637 - f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 3590 + f2fs_down_write(&fi->i_gc_rwsem[WRITE]); 3638 3591 filemap_invalidate_lock(inode->i_mapping); 3639 3592 3640 3593 last_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); ··· 3660 3613 3661 3614 end_offset = ADDRS_PER_PAGE(dn.node_page, inode); 3662 3615 count = min(end_offset - dn.ofs_in_node, last_idx - page_idx); 3663 - count = round_up(count, F2FS_I(inode)->i_cluster_size); 3616 + count = round_up(count, fi->i_cluster_size); 3664 3617 3665 3618 ret = release_compress_blocks(&dn, count); 3666 3619 ··· 3676 3629 } 3677 3630 3678 3631 filemap_invalidate_unlock(inode->i_mapping); 3679 - f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 3632 + f2fs_up_write(&fi->i_gc_rwsem[WRITE]); 3680 3633 out: 3681 3634 if (released_blocks) 3682 3635 f2fs_update_time(sbi, REQ_TIME); ··· 3687 3640 if (ret >= 0) { 3688 3641 ret = put_user(released_blocks, (u64 __user *)arg); 3689 3642 } else if (released_blocks && 3690 - atomic_read(&F2FS_I(inode)->i_compr_blocks)) { 3643 + atomic_read(&fi->i_compr_blocks)) { 3691 3644 set_sbi_flag(sbi, SBI_NEED_FSCK); 3692 3645 f2fs_warn(sbi, "%s: partial blocks were released i_ino=%lx " 3693 3646 "iblocks=%llu, released=%u, compr_blocks=%u, " 3694 3647 "run fsck to fix.", 3695 3648 __func__, inode->i_ino, inode->i_blocks, 3696 3649 released_blocks, 3697 - atomic_read(&F2FS_I(inode)->i_compr_blocks)); 3650 + atomic_read(&fi->i_compr_blocks)); 3698 3651 } 3699 3652 3700 3653 return ret; ··· 3783 3736 static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) 3784 3737 { 3785 3738 struct inode *inode = file_inode(filp); 3739 + struct f2fs_inode_info *fi = F2FS_I(inode); 3786 3740 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 3787 3741 pgoff_t page_idx = 0, last_idx; 3788 3742 unsigned int reserved_blocks = 0; ··· 3809 3761 goto unlock_inode; 3810 3762 } 3811 3763 3812 - if (atomic_read(&F2FS_I(inode)->i_compr_blocks)) 3764 + if (atomic_read(&fi->i_compr_blocks)) 3813 3765 goto unlock_inode; 3814 3766 3815 - f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 3767 + f2fs_down_write(&fi->i_gc_rwsem[WRITE]); 3816 3768 filemap_invalidate_lock(inode->i_mapping); 3817 3769 3818 3770 last_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); ··· 3838 3790 3839 3791 end_offset = ADDRS_PER_PAGE(dn.node_page, inode); 3840 3792 count = min(end_offset - dn.ofs_in_node, last_idx - page_idx); 3841 - count = round_up(count, F2FS_I(inode)->i_cluster_size); 3793 + count = round_up(count, fi->i_cluster_size); 3842 3794 3843 3795 ret = reserve_compress_blocks(&dn, count, &reserved_blocks); 3844 3796 ··· 3853 3805 } 3854 3806 3855 3807 filemap_invalidate_unlock(inode->i_mapping); 3856 - f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 3808 + f2fs_up_write(&fi->i_gc_rwsem[WRITE]); 3857 3809 3858 3810 if (!ret) { 3859 3811 clear_inode_flag(inode, FI_COMPRESS_RELEASED); ··· 3869 3821 if (!ret) { 3870 3822 ret = put_user(reserved_blocks, (u64 __user *)arg); 3871 3823 } else if (reserved_blocks && 3872 - atomic_read(&F2FS_I(inode)->i_compr_blocks)) { 3824 + atomic_read(&fi->i_compr_blocks)) { 3873 3825 set_sbi_flag(sbi, SBI_NEED_FSCK); 3874 3826 f2fs_warn(sbi, "%s: partial blocks were reserved i_ino=%lx " 3875 3827 "iblocks=%llu, reserved=%u, compr_blocks=%u, " 3876 3828 "run fsck to fix.", 3877 3829 __func__, inode->i_ino, inode->i_blocks, 3878 3830 reserved_blocks, 3879 - atomic_read(&F2FS_I(inode)->i_compr_blocks)); 3831 + atomic_read(&fi->i_compr_blocks)); 3880 3832 } 3881 3833 3882 3834 return ret; ··· 3939 3891 IS_ENCRYPTED(inode) && f2fs_is_multi_device(sbi))) 3940 3892 return -EOPNOTSUPP; 3941 3893 3942 - file_start_write(filp); 3894 + ret = mnt_want_write_file(filp); 3895 + if (ret) 3896 + return ret; 3943 3897 inode_lock(inode); 3944 3898 3945 3899 if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode) || ··· 4067 4017 f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 4068 4018 err: 4069 4019 inode_unlock(inode); 4070 - file_end_write(filp); 4020 + mnt_drop_write_file(filp); 4071 4021 4072 4022 return ret; 4073 4023 } ··· 4102 4052 static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg) 4103 4053 { 4104 4054 struct inode *inode = file_inode(filp); 4055 + struct f2fs_inode_info *fi = F2FS_I(inode); 4105 4056 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4106 4057 struct f2fs_comp_option option; 4107 4058 int ret = 0; ··· 4122 4071 option.algorithm >= COMPRESS_MAX) 4123 4072 return -EINVAL; 4124 4073 4125 - file_start_write(filp); 4074 + ret = mnt_want_write_file(filp); 4075 + if (ret) 4076 + return ret; 4126 4077 inode_lock(inode); 4127 4078 4128 4079 f2fs_down_write(&F2FS_I(inode)->i_sem); ··· 4143 4090 goto out; 4144 4091 } 4145 4092 4146 - F2FS_I(inode)->i_compress_algorithm = option.algorithm; 4147 - F2FS_I(inode)->i_log_cluster_size = option.log_cluster_size; 4148 - F2FS_I(inode)->i_cluster_size = BIT(option.log_cluster_size); 4093 + fi->i_compress_algorithm = option.algorithm; 4094 + fi->i_log_cluster_size = option.log_cluster_size; 4095 + fi->i_cluster_size = BIT(option.log_cluster_size); 4149 4096 /* Set default level */ 4150 - if (F2FS_I(inode)->i_compress_algorithm == COMPRESS_ZSTD) 4151 - F2FS_I(inode)->i_compress_level = F2FS_ZSTD_DEFAULT_CLEVEL; 4097 + if (fi->i_compress_algorithm == COMPRESS_ZSTD) 4098 + fi->i_compress_level = F2FS_ZSTD_DEFAULT_CLEVEL; 4152 4099 else 4153 - F2FS_I(inode)->i_compress_level = 0; 4100 + fi->i_compress_level = 0; 4154 4101 /* Adjust mount option level */ 4155 4102 if (option.algorithm == F2FS_OPTION(sbi).compress_algorithm && 4156 4103 F2FS_OPTION(sbi).compress_level) 4157 - F2FS_I(inode)->i_compress_level = F2FS_OPTION(sbi).compress_level; 4104 + fi->i_compress_level = F2FS_OPTION(sbi).compress_level; 4158 4105 f2fs_mark_inode_dirty_sync(inode, true); 4159 4106 4160 4107 if (!f2fs_is_compress_backend_ready(inode)) 4161 4108 f2fs_warn(sbi, "compression algorithm is successfully set, " 4162 4109 "but current kernel doesn't support this algorithm."); 4163 4110 out: 4164 - f2fs_up_write(&F2FS_I(inode)->i_sem); 4111 + f2fs_up_write(&fi->i_sem); 4165 4112 inode_unlock(inode); 4166 - file_end_write(filp); 4113 + mnt_drop_write_file(filp); 4167 4114 4168 4115 return ret; 4169 4116 } ··· 4220 4167 4221 4168 f2fs_balance_fs(sbi, true); 4222 4169 4223 - file_start_write(filp); 4170 + ret = mnt_want_write_file(filp); 4171 + if (ret) 4172 + return ret; 4224 4173 inode_lock(inode); 4225 4174 4226 4175 if (!f2fs_is_compress_backend_ready(inode)) { ··· 4277 4222 f2fs_update_time(sbi, REQ_TIME); 4278 4223 out: 4279 4224 inode_unlock(inode); 4280 - file_end_write(filp); 4225 + mnt_drop_write_file(filp); 4281 4226 4282 4227 return ret; 4283 4228 } ··· 4299 4244 4300 4245 f2fs_balance_fs(sbi, true); 4301 4246 4302 - file_start_write(filp); 4247 + ret = mnt_want_write_file(filp); 4248 + if (ret) 4249 + return ret; 4303 4250 inode_lock(inode); 4304 4251 4305 4252 if (!f2fs_is_compress_backend_ready(inode)) { ··· 4357 4300 f2fs_update_time(sbi, REQ_TIME); 4358 4301 out: 4359 4302 inode_unlock(inode); 4360 - file_end_write(filp); 4303 + mnt_drop_write_file(filp); 4361 4304 4362 4305 return ret; 4363 4306 }
+18 -6
fs/f2fs/gc.c
··· 1171 1171 static int ra_data_block(struct inode *inode, pgoff_t index) 1172 1172 { 1173 1173 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 1174 - struct address_space *mapping = inode->i_mapping; 1174 + struct address_space *mapping = f2fs_is_cow_file(inode) ? 1175 + F2FS_I(inode)->atomic_inode->i_mapping : inode->i_mapping; 1175 1176 struct dnode_of_data dn; 1176 1177 struct page *page; 1177 1178 struct f2fs_io_info fio = { ··· 1261 1260 static int move_data_block(struct inode *inode, block_t bidx, 1262 1261 int gc_type, unsigned int segno, int off) 1263 1262 { 1263 + struct address_space *mapping = f2fs_is_cow_file(inode) ? 1264 + F2FS_I(inode)->atomic_inode->i_mapping : inode->i_mapping; 1264 1265 struct f2fs_io_info fio = { 1265 1266 .sbi = F2FS_I_SB(inode), 1266 1267 .ino = inode->i_ino, ··· 1285 1282 CURSEG_ALL_DATA_ATGC : CURSEG_COLD_DATA; 1286 1283 1287 1284 /* do not read out */ 1288 - page = f2fs_grab_cache_page(inode->i_mapping, bidx, false); 1285 + page = f2fs_grab_cache_page(mapping, bidx, false); 1289 1286 if (!page) 1290 1287 return -ENOMEM; 1291 1288 ··· 1566 1563 continue; 1567 1564 } 1568 1565 1566 + if (f2fs_has_inline_data(inode)) { 1567 + iput(inode); 1568 + set_sbi_flag(sbi, SBI_NEED_FSCK); 1569 + f2fs_err_ratelimited(sbi, 1570 + "inode %lx has both inline_data flag and " 1571 + "data block, nid=%u, ofs_in_node=%u", 1572 + inode->i_ino, dni.nid, ofs_in_node); 1573 + continue; 1574 + } 1575 + 1569 1576 err = f2fs_gc_pinned_control(inode, gc_type, segno); 1570 1577 if (err == -EAGAIN) { 1571 1578 iput(inode); ··· 1592 1579 start_bidx = f2fs_start_bidx_of_node(nofs, inode) + 1593 1580 ofs_in_node; 1594 1581 1595 - if (f2fs_post_read_required(inode)) { 1582 + if (f2fs_meta_inode_gc_required(inode)) { 1596 1583 int err = ra_data_block(inode, start_bidx); 1597 1584 1598 1585 f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); ··· 1643 1630 1644 1631 start_bidx = f2fs_start_bidx_of_node(nofs, inode) 1645 1632 + ofs_in_node; 1646 - if (f2fs_post_read_required(inode)) 1633 + if (f2fs_meta_inode_gc_required(inode)) 1647 1634 err = move_data_block(inode, start_bidx, 1648 1635 gc_type, segno, off); 1649 1636 else ··· 1651 1638 segno, off); 1652 1639 1653 1640 if (!err && (gc_type == FG_GC || 1654 - f2fs_post_read_required(inode))) 1641 + f2fs_meta_inode_gc_required(inode))) 1655 1642 submitted++; 1656 1643 1657 1644 if (locked) { ··· 1755 1742 if (type != GET_SUM_TYPE((&sum->footer))) { 1756 1743 f2fs_err(sbi, "Inconsistent segment (%u) type [%d, %d] in SSA and SIT", 1757 1744 segno, type, GET_SUM_TYPE((&sum->footer))); 1758 - set_sbi_flag(sbi, SBI_NEED_FSCK); 1759 1745 f2fs_stop_checkpoint(sbi, false, 1760 1746 STOP_CP_REASON_CORRUPTED_SUMMARY); 1761 1747 goto skip;
+24 -4
fs/f2fs/inline.c
··· 16 16 17 17 static bool support_inline_data(struct inode *inode) 18 18 { 19 - if (f2fs_is_atomic_file(inode)) 19 + if (f2fs_used_in_atomic_write(inode)) 20 20 return false; 21 21 if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode)) 22 22 return false; ··· 33 33 return !f2fs_post_read_required(inode); 34 34 } 35 35 36 - bool f2fs_sanity_check_inline_data(struct inode *inode) 36 + static bool inode_has_blocks(struct inode *inode, struct page *ipage) 37 + { 38 + struct f2fs_inode *ri = F2FS_INODE(ipage); 39 + int i; 40 + 41 + if (F2FS_HAS_BLOCKS(inode)) 42 + return true; 43 + 44 + for (i = 0; i < DEF_NIDS_PER_INODE; i++) { 45 + if (ri->i_nid[i]) 46 + return true; 47 + } 48 + return false; 49 + } 50 + 51 + bool f2fs_sanity_check_inline_data(struct inode *inode, struct page *ipage) 37 52 { 38 53 if (!f2fs_has_inline_data(inode)) 54 + return false; 55 + 56 + if (inode_has_blocks(inode, ipage)) 39 57 return false; 40 58 41 59 if (!support_inline_data(inode)) ··· 221 203 struct page *ipage, *page; 222 204 int err = 0; 223 205 224 - if (!f2fs_has_inline_data(inode) || 225 - f2fs_hw_is_readonly(sbi) || f2fs_readonly(sbi->sb)) 206 + if (f2fs_hw_is_readonly(sbi) || f2fs_readonly(sbi->sb)) 207 + return -EROFS; 208 + 209 + if (!f2fs_has_inline_data(inode)) 226 210 return 0; 227 211 228 212 err = f2fs_dquot_initialize(inode);
+34 -50
fs/f2fs/inode.c
··· 29 29 if (is_inode_flag_set(inode, FI_NEW_INODE)) 30 30 return; 31 31 32 + if (f2fs_readonly(F2FS_I_SB(inode)->sb)) 33 + return; 34 + 32 35 if (f2fs_inode_dirtied(inode, sync)) 33 36 return; 34 37 ··· 313 310 if (!sanity_check_compress_inode(inode, ri)) 314 311 return false; 315 312 } 316 - } else if (f2fs_sb_has_flexible_inline_xattr(sbi)) { 317 - f2fs_warn(sbi, "%s: corrupted inode ino=%lx, run fsck to fix.", 318 - __func__, inode->i_ino); 319 - return false; 320 313 } 321 314 322 315 if (!f2fs_sb_has_extra_attr(sbi)) { ··· 343 344 } 344 345 } 345 346 346 - if (f2fs_sanity_check_inline_data(inode)) { 347 + if (f2fs_sanity_check_inline_data(inode, node_page)) { 347 348 f2fs_warn(sbi, "%s: inode (ino=%lx, mode=%u) should not have inline_data, run fsck to fix", 348 349 __func__, inode->i_ino, inode->i_mode); 349 350 return false; ··· 507 508 508 509 init_idisk_time(inode); 509 510 510 - /* Need all the flag bits */ 511 - f2fs_init_read_extent_tree(inode, node_page); 512 - f2fs_init_age_extent_tree(inode); 513 - 514 - if (!sanity_check_extent_cache(inode)) { 511 + if (!sanity_check_extent_cache(inode, node_page)) { 515 512 f2fs_put_page(node_page, 1); 516 513 f2fs_handle_error(sbi, ERROR_CORRUPTED_INODE); 517 514 return -EFSCORRUPTED; 518 515 } 516 + 517 + /* Need all the flag bits */ 518 + f2fs_init_read_extent_tree(inode, node_page); 519 + f2fs_init_age_extent_tree(inode); 519 520 520 521 f2fs_put_page(node_page, 1); 521 522 ··· 609 610 } 610 611 f2fs_set_inode_flags(inode); 611 612 612 - if (file_should_truncate(inode) && 613 - !is_sbi_flag_set(sbi, SBI_POR_DOING)) { 614 - ret = f2fs_truncate(inode); 615 - if (ret) 616 - goto bad_inode; 617 - file_dont_truncate(inode); 618 - } 619 - 620 613 unlock_new_inode(inode); 621 614 trace_f2fs_iget(inode); 622 615 return inode; ··· 636 645 637 646 void f2fs_update_inode(struct inode *inode, struct page *node_page) 638 647 { 648 + struct f2fs_inode_info *fi = F2FS_I(inode); 639 649 struct f2fs_inode *ri; 640 - struct extent_tree *et = F2FS_I(inode)->extent_tree[EX_READ]; 650 + struct extent_tree *et = fi->extent_tree[EX_READ]; 641 651 642 652 f2fs_wait_on_page_writeback(node_page, NODE, true, true); 643 653 set_page_dirty(node_page); ··· 648 656 ri = F2FS_INODE(node_page); 649 657 650 658 ri->i_mode = cpu_to_le16(inode->i_mode); 651 - ri->i_advise = F2FS_I(inode)->i_advise; 659 + ri->i_advise = fi->i_advise; 652 660 ri->i_uid = cpu_to_le32(i_uid_read(inode)); 653 661 ri->i_gid = cpu_to_le32(i_gid_read(inode)); 654 662 ri->i_links = cpu_to_le32(inode->i_nlink); ··· 674 682 ri->i_ctime_nsec = cpu_to_le32(inode_get_ctime_nsec(inode)); 675 683 ri->i_mtime_nsec = cpu_to_le32(inode_get_mtime_nsec(inode)); 676 684 if (S_ISDIR(inode->i_mode)) 677 - ri->i_current_depth = 678 - cpu_to_le32(F2FS_I(inode)->i_current_depth); 685 + ri->i_current_depth = cpu_to_le32(fi->i_current_depth); 679 686 else if (S_ISREG(inode->i_mode)) 680 - ri->i_gc_failures = cpu_to_le16(F2FS_I(inode)->i_gc_failures); 681 - ri->i_xattr_nid = cpu_to_le32(F2FS_I(inode)->i_xattr_nid); 682 - ri->i_flags = cpu_to_le32(F2FS_I(inode)->i_flags); 683 - ri->i_pino = cpu_to_le32(F2FS_I(inode)->i_pino); 687 + ri->i_gc_failures = cpu_to_le16(fi->i_gc_failures); 688 + ri->i_xattr_nid = cpu_to_le32(fi->i_xattr_nid); 689 + ri->i_flags = cpu_to_le32(fi->i_flags); 690 + ri->i_pino = cpu_to_le32(fi->i_pino); 684 691 ri->i_generation = cpu_to_le32(inode->i_generation); 685 - ri->i_dir_level = F2FS_I(inode)->i_dir_level; 692 + ri->i_dir_level = fi->i_dir_level; 686 693 687 694 if (f2fs_has_extra_attr(inode)) { 688 - ri->i_extra_isize = cpu_to_le16(F2FS_I(inode)->i_extra_isize); 695 + ri->i_extra_isize = cpu_to_le16(fi->i_extra_isize); 689 696 690 697 if (f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(inode))) 691 698 ri->i_inline_xattr_size = 692 - cpu_to_le16(F2FS_I(inode)->i_inline_xattr_size); 699 + cpu_to_le16(fi->i_inline_xattr_size); 693 700 694 701 if (f2fs_sb_has_project_quota(F2FS_I_SB(inode)) && 695 - F2FS_FITS_IN_INODE(ri, F2FS_I(inode)->i_extra_isize, 696 - i_projid)) { 702 + F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, i_projid)) { 697 703 projid_t i_projid; 698 704 699 - i_projid = from_kprojid(&init_user_ns, 700 - F2FS_I(inode)->i_projid); 705 + i_projid = from_kprojid(&init_user_ns, fi->i_projid); 701 706 ri->i_projid = cpu_to_le32(i_projid); 702 707 } 703 708 704 709 if (f2fs_sb_has_inode_crtime(F2FS_I_SB(inode)) && 705 - F2FS_FITS_IN_INODE(ri, F2FS_I(inode)->i_extra_isize, 706 - i_crtime)) { 707 - ri->i_crtime = 708 - cpu_to_le64(F2FS_I(inode)->i_crtime.tv_sec); 709 - ri->i_crtime_nsec = 710 - cpu_to_le32(F2FS_I(inode)->i_crtime.tv_nsec); 710 + F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, i_crtime)) { 711 + ri->i_crtime = cpu_to_le64(fi->i_crtime.tv_sec); 712 + ri->i_crtime_nsec = cpu_to_le32(fi->i_crtime.tv_nsec); 711 713 } 712 714 713 715 if (f2fs_sb_has_compression(F2FS_I_SB(inode)) && 714 - F2FS_FITS_IN_INODE(ri, F2FS_I(inode)->i_extra_isize, 716 + F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, 715 717 i_compress_flag)) { 716 718 unsigned short compress_flag; 717 719 718 - ri->i_compr_blocks = 719 - cpu_to_le64(atomic_read( 720 - &F2FS_I(inode)->i_compr_blocks)); 721 - ri->i_compress_algorithm = 722 - F2FS_I(inode)->i_compress_algorithm; 723 - compress_flag = F2FS_I(inode)->i_compress_flag | 724 - F2FS_I(inode)->i_compress_level << 720 + ri->i_compr_blocks = cpu_to_le64( 721 + atomic_read(&fi->i_compr_blocks)); 722 + ri->i_compress_algorithm = fi->i_compress_algorithm; 723 + compress_flag = fi->i_compress_flag | 724 + fi->i_compress_level << 725 725 COMPRESS_LEVEL_OFFSET; 726 726 ri->i_compress_flag = cpu_to_le16(compress_flag); 727 - ri->i_log_cluster_size = 728 - F2FS_I(inode)->i_log_cluster_size; 727 + ri->i_log_cluster_size = fi->i_log_cluster_size; 729 728 } 730 729 } 731 730 ··· 796 813 797 814 f2fs_abort_atomic_write(inode, true); 798 815 799 - if (fi->cow_inode) { 816 + if (fi->cow_inode && f2fs_is_cow_file(fi->cow_inode)) { 800 817 clear_inode_flag(fi->cow_inode, FI_COW_FILE); 818 + F2FS_I(fi->cow_inode)->atomic_inode = NULL; 801 819 iput(fi->cow_inode); 802 820 fi->cow_inode = NULL; 803 821 }
+11 -9
fs/f2fs/namei.c
··· 221 221 const char *name) 222 222 { 223 223 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 224 + struct f2fs_inode_info *fi; 224 225 nid_t ino; 225 226 struct inode *inode; 226 227 bool nid_free = false; ··· 242 241 243 242 inode_init_owner(idmap, inode, dir, mode); 244 243 244 + fi = F2FS_I(inode); 245 245 inode->i_ino = ino; 246 246 inode->i_blocks = 0; 247 247 simple_inode_init_ts(inode); 248 - F2FS_I(inode)->i_crtime = inode_get_mtime(inode); 248 + fi->i_crtime = inode_get_mtime(inode); 249 249 inode->i_generation = get_random_u32(); 250 250 251 251 if (S_ISDIR(inode->i_mode)) 252 - F2FS_I(inode)->i_current_depth = 1; 252 + fi->i_current_depth = 1; 253 253 254 254 err = insert_inode_locked(inode); 255 255 if (err) { ··· 260 258 261 259 if (f2fs_sb_has_project_quota(sbi) && 262 260 (F2FS_I(dir)->i_flags & F2FS_PROJINHERIT_FL)) 263 - F2FS_I(inode)->i_projid = F2FS_I(dir)->i_projid; 261 + fi->i_projid = F2FS_I(dir)->i_projid; 264 262 else 265 - F2FS_I(inode)->i_projid = make_kprojid(&init_user_ns, 263 + fi->i_projid = make_kprojid(&init_user_ns, 266 264 F2FS_DEF_PROJID); 267 265 268 266 err = fscrypt_prepare_new_inode(dir, inode, &encrypt); ··· 280 278 281 279 if (f2fs_sb_has_extra_attr(sbi)) { 282 280 set_inode_flag(inode, FI_EXTRA_ATTR); 283 - F2FS_I(inode)->i_extra_isize = F2FS_TOTAL_EXTRA_ATTR_SIZE; 281 + fi->i_extra_isize = F2FS_TOTAL_EXTRA_ATTR_SIZE; 284 282 } 285 283 286 284 if (test_opt(sbi, INLINE_XATTR)) ··· 298 296 f2fs_has_inline_dentry(inode)) { 299 297 xattr_size = DEFAULT_INLINE_XATTR_ADDRS; 300 298 } 301 - F2FS_I(inode)->i_inline_xattr_size = xattr_size; 299 + fi->i_inline_xattr_size = xattr_size; 302 300 303 - F2FS_I(inode)->i_flags = 301 + fi->i_flags = 304 302 f2fs_mask_flags(mode, F2FS_I(dir)->i_flags & F2FS_FL_INHERITED); 305 303 306 304 if (S_ISDIR(inode->i_mode)) 307 - F2FS_I(inode)->i_flags |= F2FS_INDEX_FL; 305 + fi->i_flags |= F2FS_INDEX_FL; 308 306 309 - if (F2FS_I(inode)->i_flags & F2FS_PROJINHERIT_FL) 307 + if (fi->i_flags & F2FS_PROJINHERIT_FL) 310 308 set_inode_flag(inode, FI_PROJ_INHERIT); 311 309 312 310 /* Check compression first. */
+6 -5
fs/f2fs/recovery.c
··· 280 280 static int recover_inode(struct inode *inode, struct page *page) 281 281 { 282 282 struct f2fs_inode *raw = F2FS_INODE(page); 283 + struct f2fs_inode_info *fi = F2FS_I(inode); 283 284 char *name; 284 285 int err; 285 286 ··· 303 302 i_projid = (projid_t)le32_to_cpu(raw->i_projid); 304 303 kprojid = make_kprojid(&init_user_ns, i_projid); 305 304 306 - if (!projid_eq(kprojid, F2FS_I(inode)->i_projid)) { 305 + if (!projid_eq(kprojid, fi->i_projid)) { 307 306 err = f2fs_transfer_project_quota(inode, 308 307 kprojid); 309 308 if (err) 310 309 return err; 311 - F2FS_I(inode)->i_projid = kprojid; 310 + fi->i_projid = kprojid; 312 311 } 313 312 } 314 313 } ··· 321 320 inode_set_mtime(inode, le64_to_cpu(raw->i_mtime), 322 321 le32_to_cpu(raw->i_mtime_nsec)); 323 322 324 - F2FS_I(inode)->i_advise = raw->i_advise; 325 - F2FS_I(inode)->i_flags = le32_to_cpu(raw->i_flags); 323 + fi->i_advise = raw->i_advise; 324 + fi->i_flags = le32_to_cpu(raw->i_flags); 326 325 f2fs_set_inode_flags(inode); 327 - F2FS_I(inode)->i_gc_failures = le16_to_cpu(raw->i_gc_failures); 326 + fi->i_gc_failures = le16_to_cpu(raw->i_gc_failures); 328 327 329 328 recover_inline_flags(inode, raw); 330 329
+43 -11
fs/f2fs/segment.c
··· 2784 2784 unsigned short seg_type = curseg->seg_type; 2785 2785 2786 2786 sanity_check_seg_type(sbi, seg_type); 2787 - if (f2fs_need_rand_seg(sbi)) 2788 - return get_random_u32_below(MAIN_SECS(sbi) * SEGS_PER_SEC(sbi)); 2787 + if (__is_large_section(sbi)) { 2788 + if (f2fs_need_rand_seg(sbi)) { 2789 + unsigned int hint = GET_SEC_FROM_SEG(sbi, curseg->segno); 2789 2790 2790 - if (__is_large_section(sbi)) 2791 + if (GET_SEC_FROM_SEG(sbi, curseg->segno + 1) != hint) 2792 + return curseg->segno; 2793 + return get_random_u32_inclusive(curseg->segno + 1, 2794 + GET_SEG_FROM_SEC(sbi, hint + 1) - 1); 2795 + } 2791 2796 return curseg->segno; 2797 + } else if (f2fs_need_rand_seg(sbi)) { 2798 + return get_random_u32_below(MAIN_SECS(sbi) * SEGS_PER_SEC(sbi)); 2799 + } 2792 2800 2793 2801 /* inmem log may not locate on any segment after mount */ 2794 2802 if (!curseg->inited) ··· 2939 2931 return ret; 2940 2932 } 2941 2933 2942 - static int __f2fs_init_atgc_curseg(struct f2fs_sb_info *sbi) 2934 + static int __f2fs_init_atgc_curseg(struct f2fs_sb_info *sbi, bool force) 2943 2935 { 2944 2936 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_ALL_DATA_ATGC); 2945 2937 int ret = 0; 2946 2938 2947 - if (!sbi->am.atgc_enabled) 2939 + if (!sbi->am.atgc_enabled && !force) 2948 2940 return 0; 2949 2941 2950 2942 f2fs_down_read(&SM_I(sbi)->curseg_lock); ··· 2961 2953 f2fs_up_read(&SM_I(sbi)->curseg_lock); 2962 2954 return ret; 2963 2955 } 2956 + 2964 2957 int f2fs_init_inmem_curseg(struct f2fs_sb_info *sbi) 2965 2958 { 2966 - return __f2fs_init_atgc_curseg(sbi); 2959 + return __f2fs_init_atgc_curseg(sbi, false); 2960 + } 2961 + 2962 + int f2fs_reinit_atgc_curseg(struct f2fs_sb_info *sbi) 2963 + { 2964 + int ret; 2965 + 2966 + if (!test_opt(sbi, ATGC)) 2967 + return 0; 2968 + if (sbi->am.atgc_enabled) 2969 + return 0; 2970 + if (le64_to_cpu(F2FS_CKPT(sbi)->elapsed_time) < 2971 + sbi->am.age_threshold) 2972 + return 0; 2973 + 2974 + ret = __f2fs_init_atgc_curseg(sbi, true); 2975 + if (!ret) { 2976 + sbi->am.atgc_enabled = true; 2977 + f2fs_info(sbi, "reenabled age threshold GC"); 2978 + } 2979 + return ret; 2967 2980 } 2968 2981 2969 2982 static void __f2fs_save_inmem_curseg(struct f2fs_sb_info *sbi, int type) ··· 3512 3483 if (page_private_gcing(fio->page)) { 3513 3484 if (fio->sbi->am.atgc_enabled && 3514 3485 (fio->io_type == FS_DATA_IO) && 3515 - (fio->sbi->gc_mode != GC_URGENT_HIGH)) 3486 + (fio->sbi->gc_mode != GC_URGENT_HIGH) && 3487 + __is_valid_data_blkaddr(fio->old_blkaddr) && 3488 + !is_inode_flag_set(inode, FI_OPU_WRITE)) 3516 3489 return CURSEG_ALL_DATA_ATGC; 3517 3490 else 3518 3491 return CURSEG_COLD_DATA; ··· 3859 3828 goto drop_bio; 3860 3829 } 3861 3830 3862 - if (fio->post_read) 3831 + if (fio->meta_gc) 3863 3832 f2fs_truncate_meta_inode_pages(sbi, fio->new_blkaddr, 1); 3864 3833 3865 3834 stat_inc_inplace_blocks(fio->sbi); ··· 4029 3998 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4030 3999 struct page *cpage; 4031 4000 4032 - if (!f2fs_post_read_required(inode)) 4001 + if (!f2fs_meta_inode_gc_required(inode)) 4033 4002 return; 4034 4003 4035 4004 if (!__is_valid_data_blkaddr(blkaddr)) ··· 4048 4017 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4049 4018 block_t i; 4050 4019 4051 - if (!f2fs_post_read_required(inode)) 4020 + if (!f2fs_meta_inode_gc_required(inode)) 4052 4021 return; 4053 4022 4054 4023 for (i = 0; i < len; i++) ··· 5218 5187 } 5219 5188 5220 5189 /* Allocate a new section if it's not new. */ 5221 - if (cs->next_blkoff) { 5190 + if (cs->next_blkoff || 5191 + cs->segno != GET_SEG_FROM_SEC(sbi, GET_ZONE_FROM_SEC(sbi, cs_section))) { 5222 5192 unsigned int old_segno = cs->segno, old_blkoff = cs->next_blkoff; 5223 5193 5224 5194 f2fs_allocate_new_section(sbi, type, true);
+2 -1
fs/f2fs/segment.h
··· 347 347 unsigned int segno, bool use_section) 348 348 { 349 349 if (use_section && __is_large_section(sbi)) { 350 - unsigned int start_segno = START_SEGNO(segno); 350 + unsigned int secno = GET_SEC_FROM_SEG(sbi, segno); 351 + unsigned int start_segno = GET_SEG_FROM_SEC(sbi, secno); 351 352 unsigned int blocks = 0; 352 353 int i; 353 354
+1 -10
fs/f2fs/super.c
··· 151 151 Opt_mode, 152 152 Opt_fault_injection, 153 153 Opt_fault_type, 154 - Opt_lazytime, 155 - Opt_nolazytime, 156 154 Opt_quota, 157 155 Opt_noquota, 158 156 Opt_usrquota, ··· 227 229 {Opt_mode, "mode=%s"}, 228 230 {Opt_fault_injection, "fault_injection=%u"}, 229 231 {Opt_fault_type, "fault_type=%u"}, 230 - {Opt_lazytime, "lazytime"}, 231 - {Opt_nolazytime, "nolazytime"}, 232 232 {Opt_quota, "quota"}, 233 233 {Opt_noquota, "noquota"}, 234 234 {Opt_usrquota, "usrquota"}, ··· 914 918 f2fs_info(sbi, "fault_type options not supported"); 915 919 break; 916 920 #endif 917 - case Opt_lazytime: 918 - sb->s_flags |= SB_LAZYTIME; 919 - break; 920 - case Opt_nolazytime: 921 - sb->s_flags &= ~SB_LAZYTIME; 922 - break; 923 921 #ifdef CONFIG_QUOTA 924 922 case Opt_quota: 925 923 case Opt_usrquota: ··· 4471 4481 sb->s_flags = (sb->s_flags & ~SB_POSIXACL) | 4472 4482 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); 4473 4483 super_set_uuid(sb, (void *) raw_super->uuid, sizeof(raw_super->uuid)); 4484 + super_set_sysfs_name_bdev(sb); 4474 4485 sb->s_iflags |= SB_I_CGROUPWB; 4475 4486 4476 4487 /* init f2fs-specific super block info */
+6 -6
fs/f2fs/sysfs.c
··· 340 340 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) { 341 341 struct ckpt_req_control *cprc = &sbi->cprc_info; 342 342 int class = IOPRIO_PRIO_CLASS(cprc->ckpt_thread_ioprio); 343 - int data = IOPRIO_PRIO_DATA(cprc->ckpt_thread_ioprio); 343 + int level = IOPRIO_PRIO_LEVEL(cprc->ckpt_thread_ioprio); 344 344 345 345 if (class != IOPRIO_CLASS_RT && class != IOPRIO_CLASS_BE) 346 346 return -EINVAL; 347 347 348 348 return sysfs_emit(buf, "%s,%d\n", 349 - class == IOPRIO_CLASS_RT ? "rt" : "be", data); 349 + class == IOPRIO_CLASS_RT ? "rt" : "be", level); 350 350 } 351 351 352 352 #ifdef CONFIG_F2FS_FS_COMPRESSION ··· 450 450 const char *name = strim((char *)buf); 451 451 struct ckpt_req_control *cprc = &sbi->cprc_info; 452 452 int class; 453 - long data; 453 + long level; 454 454 int ret; 455 455 456 456 if (!strncmp(name, "rt,", 3)) ··· 461 461 return -EINVAL; 462 462 463 463 name += 3; 464 - ret = kstrtol(name, 10, &data); 464 + ret = kstrtol(name, 10, &level); 465 465 if (ret) 466 466 return ret; 467 - if (data >= IOPRIO_NR_LEVELS || data < 0) 467 + if (level >= IOPRIO_NR_LEVELS || level < 0) 468 468 return -EINVAL; 469 469 470 - cprc->ckpt_thread_ioprio = IOPRIO_PRIO_VALUE(class, data); 470 + cprc->ckpt_thread_ioprio = IOPRIO_PRIO_VALUE(class, level); 471 471 if (test_opt(sbi, MERGE_CHECKPOINT)) { 472 472 ret = set_task_ioprio(cprc->f2fs_issue_ckpt, 473 473 cprc->ckpt_thread_ioprio);
+3 -4
include/linux/f2fs_fs.h
··· 259 259 #define CUR_ADDRS_PER_INODE(inode) (DEF_ADDRS_PER_INODE - \ 260 260 get_extra_isize(inode)) 261 261 #define DEF_NIDS_PER_INODE 5 /* Node IDs in an Inode */ 262 - #define ADDRS_PER_INODE(inode) addrs_per_inode(inode) 262 + #define ADDRS_PER_INODE(inode) addrs_per_page(inode, true) 263 263 /* Address Pointers in a Direct Block */ 264 264 #define DEF_ADDRS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32)) 265 - #define ADDRS_PER_BLOCK(inode) addrs_per_block(inode) 265 + #define ADDRS_PER_BLOCK(inode) addrs_per_page(inode, false) 266 266 /* Node IDs in an Indirect Block */ 267 267 #define NIDS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32)) 268 268 269 - #define ADDRS_PER_PAGE(page, inode) \ 270 - (IS_INODE(page) ? ADDRS_PER_INODE(inode) : ADDRS_PER_BLOCK(inode)) 269 + #define ADDRS_PER_PAGE(page, inode) (addrs_per_page(inode, IS_INODE(page))) 271 270 272 271 #define NODE_DIR1_BLOCK (DEF_ADDRS_PER_INODE + 1) 273 272 #define NODE_DIR2_BLOCK (DEF_ADDRS_PER_INODE + 2)