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

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

Pull f2fs updates from Jaegeuk Kim:
"In this round, we've tried to address some performance issues on zoned
storage such as direct IO and write_hints. In addition, we've migrated
some IO paths using folio. Meanwhile, there are multiple bug fixes in
the compression paths, sanity check conditions, and error handlers.

Enhancements:
- allow direct io of pinned files for zoned storage
- assign the write hint per stream by default
- convert read paths and test_writeback to folio
- avoid allocating WARM_DATA segment for direct IO

Bug fixes:
- fix false alarm on invalid block address
- fix to add missing iput() in gc_data_segment()
- fix to release node block count in error path of
f2fs_new_node_page()
- compress:
- don't allow unaligned truncation on released compress inode
- cover {reserve,release}_compress_blocks() w/ cp_rwsem lock
- fix error path of inc_valid_block_count()
- fix to update i_compr_blocks correctly
- fix block migration when section is not aligned to pow2
- don't trigger OPU on pinfile for direct IO
- fix to do sanity check on i_xattr_nid in sanity_check_inode()
- write missing last sum blk of file pinning section
- clear writeback when compression failed
- fix to adjust appropirate defragment pg_end

As usual, there are several minor code clean-ups, and fixes to manage
missing corner cases in the error paths"

* tag 'f2fs-for-6.10.rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (50 commits)
f2fs: initialize last_block_in_bio variable
f2fs: Add inline to f2fs_build_fault_attr() stub
f2fs: fix some ambiguous comments
f2fs: fix to add missing iput() in gc_data_segment()
f2fs: allow dirty sections with zero valid block for checkpoint disabled
f2fs: compress: don't allow unaligned truncation on released compress inode
f2fs: fix to release node block count in error path of f2fs_new_node_page()
f2fs: compress: fix to cover {reserve,release}_compress_blocks() w/ cp_rwsem lock
f2fs: compress: fix error path of inc_valid_block_count()
f2fs: compress: fix typo in f2fs_reserve_compress_blocks()
f2fs: compress: fix to update i_compr_blocks correctly
f2fs: check validation of fault attrs in f2fs_build_fault_attr()
f2fs: fix to limit gc_pin_file_threshold
f2fs: remove unused GC_FAILURE_PIN
f2fs: use f2fs_{err,info}_ratelimited() for cleanup
f2fs: fix block migration when section is not aligned to pow2
f2fs: zone: fix to don't trigger OPU on pinfile for direct IO
f2fs: fix to do sanity check on i_xattr_nid in sanity_check_inode()
f2fs: fix to avoid allocating WARM_DATA segment for direct IO
f2fs: remove redundant parameter in is_next_segment_free()
...

+689 -375
+1 -1
Documentation/ABI/testing/sysfs-fs-f2fs
··· 331 331 Contact: Jaegeuk Kim <jaegeuk@kernel.org> 332 332 Description: This indicates how many GC can be failed for the pinned 333 333 file. If it exceeds this, F2FS doesn't guarantee its pinning 334 - state. 2048 trials is set by default. 334 + state. 2048 trials is set by default, and 65535 as maximum. 335 335 336 336 What: /sys/fs/f2fs/<disk>/extension_list 337 337 Date: February 2018
+29
Documentation/filesystems/f2fs.rst
··· 774 774 F2FS manages a bitmap. Each bit represents the validity of a block, and the 775 775 bitmap is composed of a bit stream covering whole blocks in main area. 776 776 777 + Write-hint Policy 778 + ----------------- 779 + 780 + F2FS sets the whint all the time with the below policy. 781 + 782 + ===================== ======================== =================== 783 + User F2FS Block 784 + ===================== ======================== =================== 785 + N/A META WRITE_LIFE_NONE|REQ_META 786 + N/A HOT_NODE WRITE_LIFE_NONE 787 + N/A WARM_NODE WRITE_LIFE_MEDIUM 788 + N/A COLD_NODE WRITE_LIFE_LONG 789 + ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME 790 + extension list " " 791 + 792 + -- buffered io 793 + N/A COLD_DATA WRITE_LIFE_EXTREME 794 + N/A HOT_DATA WRITE_LIFE_SHORT 795 + N/A WARM_DATA WRITE_LIFE_NOT_SET 796 + 797 + -- direct io 798 + WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME 799 + WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT 800 + WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET 801 + WRITE_LIFE_NONE " WRITE_LIFE_NONE 802 + WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM 803 + WRITE_LIFE_LONG " WRITE_LIFE_LONG 804 + ===================== ======================== =================== 805 + 777 806 Fallocate(2) Policy 778 807 ------------------- 779 808
+7 -6
fs/f2fs/checkpoint.c
··· 179 179 break; 180 180 case META_SIT: 181 181 if (unlikely(blkaddr >= SIT_BLK_CNT(sbi))) 182 - goto err; 182 + goto check_only; 183 183 break; 184 184 case META_SSA: 185 185 if (unlikely(blkaddr >= MAIN_BLKADDR(sbi) || 186 186 blkaddr < SM_I(sbi)->ssa_blkaddr)) 187 - goto err; 187 + goto check_only; 188 188 break; 189 189 case META_CP: 190 190 if (unlikely(blkaddr >= SIT_I(sbi)->sit_base_addr || 191 191 blkaddr < __start_cp_addr(sbi))) 192 - goto err; 192 + goto check_only; 193 193 break; 194 194 case META_POR: 195 195 if (unlikely(blkaddr >= MAX_BLKADDR(sbi) || 196 196 blkaddr < MAIN_BLKADDR(sbi))) 197 - goto err; 197 + goto check_only; 198 198 break; 199 199 case DATA_GENERIC: 200 200 case DATA_GENERIC_ENHANCE: ··· 228 228 return true; 229 229 err: 230 230 f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR); 231 + check_only: 231 232 return false; 232 233 } 233 234 ··· 346 345 { 347 346 struct f2fs_sb_info *sbi = F2FS_P_SB(page); 348 347 349 - trace_f2fs_writepage(page, META); 348 + trace_f2fs_writepage(page_folio(page), META); 350 349 351 350 if (unlikely(f2fs_cp_error(sbi))) { 352 351 if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) { ··· 493 492 static bool f2fs_dirty_meta_folio(struct address_space *mapping, 494 493 struct folio *folio) 495 494 { 496 - trace_f2fs_set_page_dirty(&folio->page, META); 495 + trace_f2fs_set_page_dirty(folio, META); 497 496 498 497 if (!folio_test_uptodate(folio)) 499 498 folio_mark_uptodate(folio);
+63 -33
fs/f2fs/compress.c
··· 198 198 ret = lzo1x_1_compress(cc->rbuf, cc->rlen, cc->cbuf->cdata, 199 199 &cc->clen, cc->private); 200 200 if (ret != LZO_E_OK) { 201 - printk_ratelimited("%sF2FS-fs (%s): lzo compress failed, ret:%d\n", 202 - KERN_ERR, F2FS_I_SB(cc->inode)->sb->s_id, ret); 201 + f2fs_err_ratelimited(F2FS_I_SB(cc->inode), 202 + "lzo compress failed, ret:%d", ret); 203 203 return -EIO; 204 204 } 205 205 return 0; ··· 212 212 ret = lzo1x_decompress_safe(dic->cbuf->cdata, dic->clen, 213 213 dic->rbuf, &dic->rlen); 214 214 if (ret != LZO_E_OK) { 215 - printk_ratelimited("%sF2FS-fs (%s): lzo decompress failed, ret:%d\n", 216 - KERN_ERR, F2FS_I_SB(dic->inode)->sb->s_id, ret); 215 + f2fs_err_ratelimited(F2FS_I_SB(dic->inode), 216 + "lzo decompress failed, ret:%d", ret); 217 217 return -EIO; 218 218 } 219 219 220 220 if (dic->rlen != PAGE_SIZE << dic->log_cluster_size) { 221 - printk_ratelimited("%sF2FS-fs (%s): lzo invalid rlen:%zu, " 222 - "expected:%lu\n", KERN_ERR, 223 - F2FS_I_SB(dic->inode)->sb->s_id, 224 - dic->rlen, 225 - PAGE_SIZE << dic->log_cluster_size); 221 + f2fs_err_ratelimited(F2FS_I_SB(dic->inode), 222 + "lzo invalid rlen:%zu, expected:%lu", 223 + dic->rlen, PAGE_SIZE << dic->log_cluster_size); 226 224 return -EIO; 227 225 } 228 226 return 0; ··· 292 294 ret = LZ4_decompress_safe(dic->cbuf->cdata, dic->rbuf, 293 295 dic->clen, dic->rlen); 294 296 if (ret < 0) { 295 - printk_ratelimited("%sF2FS-fs (%s): lz4 decompress failed, ret:%d\n", 296 - KERN_ERR, F2FS_I_SB(dic->inode)->sb->s_id, ret); 297 + f2fs_err_ratelimited(F2FS_I_SB(dic->inode), 298 + "lz4 decompress failed, ret:%d", ret); 297 299 return -EIO; 298 300 } 299 301 300 302 if (ret != PAGE_SIZE << dic->log_cluster_size) { 301 - printk_ratelimited("%sF2FS-fs (%s): lz4 invalid ret:%d, " 302 - "expected:%lu\n", KERN_ERR, 303 - F2FS_I_SB(dic->inode)->sb->s_id, ret, 304 - PAGE_SIZE << dic->log_cluster_size); 303 + f2fs_err_ratelimited(F2FS_I_SB(dic->inode), 304 + "lz4 invalid ret:%d, expected:%lu", 305 + ret, PAGE_SIZE << dic->log_cluster_size); 305 306 return -EIO; 306 307 } 307 308 return 0; ··· 347 350 348 351 stream = zstd_init_cstream(&params, 0, workspace, workspace_size); 349 352 if (!stream) { 350 - printk_ratelimited("%sF2FS-fs (%s): %s zstd_init_cstream failed\n", 351 - KERN_ERR, F2FS_I_SB(cc->inode)->sb->s_id, 352 - __func__); 353 + f2fs_err_ratelimited(F2FS_I_SB(cc->inode), 354 + "%s zstd_init_cstream failed", __func__); 353 355 kvfree(workspace); 354 356 return -EIO; 355 357 } ··· 386 390 387 391 ret = zstd_compress_stream(stream, &outbuf, &inbuf); 388 392 if (zstd_is_error(ret)) { 389 - printk_ratelimited("%sF2FS-fs (%s): %s zstd_compress_stream failed, ret: %d\n", 390 - KERN_ERR, F2FS_I_SB(cc->inode)->sb->s_id, 393 + f2fs_err_ratelimited(F2FS_I_SB(cc->inode), 394 + "%s zstd_compress_stream failed, ret: %d", 391 395 __func__, zstd_get_error_code(ret)); 392 396 return -EIO; 393 397 } 394 398 395 399 ret = zstd_end_stream(stream, &outbuf); 396 400 if (zstd_is_error(ret)) { 397 - printk_ratelimited("%sF2FS-fs (%s): %s zstd_end_stream returned %d\n", 398 - KERN_ERR, F2FS_I_SB(cc->inode)->sb->s_id, 401 + f2fs_err_ratelimited(F2FS_I_SB(cc->inode), 402 + "%s zstd_end_stream returned %d", 399 403 __func__, zstd_get_error_code(ret)); 400 404 return -EIO; 401 405 } ··· 428 432 429 433 stream = zstd_init_dstream(max_window_size, workspace, workspace_size); 430 434 if (!stream) { 431 - printk_ratelimited("%sF2FS-fs (%s): %s zstd_init_dstream failed\n", 432 - KERN_ERR, F2FS_I_SB(dic->inode)->sb->s_id, 433 - __func__); 435 + f2fs_err_ratelimited(F2FS_I_SB(dic->inode), 436 + "%s zstd_init_dstream failed", __func__); 434 437 kvfree(workspace); 435 438 return -EIO; 436 439 } ··· 464 469 465 470 ret = zstd_decompress_stream(stream, &outbuf, &inbuf); 466 471 if (zstd_is_error(ret)) { 467 - printk_ratelimited("%sF2FS-fs (%s): %s zstd_decompress_stream failed, ret: %d\n", 468 - KERN_ERR, F2FS_I_SB(dic->inode)->sb->s_id, 472 + f2fs_err_ratelimited(F2FS_I_SB(dic->inode), 473 + "%s zstd_decompress_stream failed, ret: %d", 469 474 __func__, zstd_get_error_code(ret)); 470 475 return -EIO; 471 476 } 472 477 473 478 if (dic->rlen != outbuf.pos) { 474 - printk_ratelimited("%sF2FS-fs (%s): %s ZSTD invalid rlen:%zu, " 475 - "expected:%lu\n", KERN_ERR, 476 - F2FS_I_SB(dic->inode)->sb->s_id, 479 + f2fs_err_ratelimited(F2FS_I_SB(dic->inode), 480 + "%s ZSTD invalid rlen:%zu, expected:%lu", 477 481 __func__, dic->rlen, 478 482 PAGE_SIZE << dic->log_cluster_size); 479 483 return -EIO; ··· 1025 1031 } 1026 1032 } 1027 1033 1034 + static void cancel_cluster_writeback(struct compress_ctx *cc, 1035 + struct compress_io_ctx *cic, int submitted) 1036 + { 1037 + int i; 1038 + 1039 + /* Wait for submitted IOs. */ 1040 + if (submitted > 1) { 1041 + f2fs_submit_merged_write(F2FS_I_SB(cc->inode), DATA); 1042 + while (atomic_read(&cic->pending_pages) != 1043 + (cc->valid_nr_cpages - submitted + 1)) 1044 + f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT); 1045 + } 1046 + 1047 + /* Cancel writeback and stay locked. */ 1048 + for (i = 0; i < cc->cluster_size; i++) { 1049 + if (i < submitted) { 1050 + inode_inc_dirty_pages(cc->inode); 1051 + lock_page(cc->rpages[i]); 1052 + } 1053 + clear_page_private_gcing(cc->rpages[i]); 1054 + if (folio_test_writeback(page_folio(cc->rpages[i]))) 1055 + end_page_writeback(cc->rpages[i]); 1056 + } 1057 + } 1058 + 1028 1059 static void set_cluster_dirty(struct compress_ctx *cc) 1029 1060 { 1030 1061 int i; ··· 1251 1232 .page = NULL, 1252 1233 .encrypted_page = NULL, 1253 1234 .compressed_page = NULL, 1254 - .submitted = 0, 1255 1235 .io_type = io_type, 1256 1236 .io_wbc = wbc, 1257 1237 .encrypted = fscrypt_inode_uses_fs_layer_crypto(cc->inode) ? ··· 1376 1358 fio.compressed_page = cc->cpages[i - 1]; 1377 1359 1378 1360 cc->cpages[i - 1] = NULL; 1361 + fio.submitted = 0; 1379 1362 f2fs_outplace_write_data(&dn, &fio); 1363 + if (unlikely(!fio.submitted)) { 1364 + cancel_cluster_writeback(cc, cic, i); 1365 + 1366 + /* To call fscrypt_finalize_bounce_page */ 1367 + i = cc->valid_nr_cpages; 1368 + *submitted = 0; 1369 + goto out_destroy_crypt; 1370 + } 1380 1371 (*submitted)++; 1381 1372 unlock_continue: 1382 1373 inode_dec_dirty_pages(cc->inode); ··· 1419 1392 out_destroy_crypt: 1420 1393 page_array_free(cc->inode, cic->rpages, cc->cluster_size); 1421 1394 1422 - for (--i; i >= 0; i--) 1395 + for (--i; i >= 0; i--) { 1396 + if (!cc->cpages[i]) 1397 + continue; 1423 1398 fscrypt_finalize_bounce_page(&cc->cpages[i]); 1399 + } 1424 1400 out_put_cic: 1425 1401 kmem_cache_free(cic_entry_slab, cic); 1426 1402 out_put_dnode: ··· 1514 1484 if (!PageDirty(cc->rpages[i])) 1515 1485 goto continue_unlock; 1516 1486 1517 - if (PageWriteback(cc->rpages[i])) { 1487 + if (folio_test_writeback(page_folio(cc->rpages[i]))) { 1518 1488 if (wbc->sync_mode == WB_SYNC_NONE) 1519 1489 goto continue_unlock; 1520 1490 f2fs_wait_on_page_writeback(cc->rpages[i], DATA, true, true);
+133 -100
fs/f2fs/data.c
··· 465 465 } else { 466 466 bio->bi_end_io = f2fs_write_end_io; 467 467 bio->bi_private = sbi; 468 + bio->bi_write_hint = f2fs_io_type_to_rw_hint(sbi, 469 + fio->type, fio->temp); 468 470 } 469 471 iostat_alloc_and_bind_ctx(sbi, bio, NULL); 470 472 ··· 595 593 return -ENOMEM; 596 594 597 595 for (j = HOT; j < n; j++) { 598 - init_f2fs_rwsem(&sbi->write_io[i][j].io_rwsem); 599 - sbi->write_io[i][j].sbi = sbi; 600 - sbi->write_io[i][j].bio = NULL; 601 - spin_lock_init(&sbi->write_io[i][j].io_lock); 602 - INIT_LIST_HEAD(&sbi->write_io[i][j].io_list); 603 - INIT_LIST_HEAD(&sbi->write_io[i][j].bio_list); 604 - init_f2fs_rwsem(&sbi->write_io[i][j].bio_list_lock); 596 + struct f2fs_bio_info *io = &sbi->write_io[i][j]; 597 + 598 + init_f2fs_rwsem(&io->io_rwsem); 599 + io->sbi = sbi; 600 + io->bio = NULL; 601 + io->last_block_in_bio = 0; 602 + spin_lock_init(&io->io_lock); 603 + INIT_LIST_HEAD(&io->io_list); 604 + INIT_LIST_HEAD(&io->bio_list); 605 + init_f2fs_rwsem(&io->bio_list_lock); 605 606 #ifdef CONFIG_BLK_DEV_ZONED 606 - init_completion(&sbi->write_io[i][j].zone_wait); 607 - sbi->write_io[i][j].zone_pending_bio = NULL; 608 - sbi->write_io[i][j].bi_private = NULL; 607 + init_completion(&io->zone_wait); 608 + io->zone_pending_bio = NULL; 609 + io->bi_private = NULL; 609 610 #endif 610 611 } 611 612 } ··· 1512 1507 return true; 1513 1508 } 1514 1509 1510 + static bool map_is_mergeable(struct f2fs_sb_info *sbi, 1511 + struct f2fs_map_blocks *map, 1512 + block_t blkaddr, int flag, int bidx, 1513 + int ofs) 1514 + { 1515 + if (map->m_multidev_dio && map->m_bdev != FDEV(bidx).bdev) 1516 + return false; 1517 + if (map->m_pblk != NEW_ADDR && blkaddr == (map->m_pblk + ofs)) 1518 + return true; 1519 + if (map->m_pblk == NEW_ADDR && blkaddr == NEW_ADDR) 1520 + return true; 1521 + if (flag == F2FS_GET_BLOCK_PRE_DIO) 1522 + return true; 1523 + if (flag == F2FS_GET_BLOCK_DIO && 1524 + map->m_pblk == NULL_ADDR && blkaddr == NULL_ADDR) 1525 + return true; 1526 + return false; 1527 + } 1528 + 1515 1529 /* 1516 1530 * f2fs_map_blocks() tries to find or build mapping relationship which 1517 1531 * maps continuous logical blocks to physical blocks, and return such ··· 1598 1574 } 1599 1575 1600 1576 /* use out-place-update for direct IO under LFS mode */ 1601 - if (map->m_may_create && 1602 - (is_hole || (f2fs_lfs_mode(sbi) && flag == F2FS_GET_BLOCK_DIO))) { 1577 + if (map->m_may_create && (is_hole || 1578 + (flag == F2FS_GET_BLOCK_DIO && f2fs_lfs_mode(sbi) && 1579 + !f2fs_is_pinned_file(inode)))) { 1603 1580 if (unlikely(f2fs_cp_error(sbi))) { 1604 1581 err = -EIO; 1605 1582 goto sync_out; ··· 1653 1628 goto sync_out; 1654 1629 } 1655 1630 break; 1631 + case F2FS_GET_BLOCK_DIO: 1632 + if (map->m_next_pgofs) 1633 + *map->m_next_pgofs = pgofs + 1; 1634 + break; 1656 1635 default: 1657 1636 /* for defragment case */ 1658 1637 if (map->m_next_pgofs) ··· 1675 1646 /* reserved delalloc block should be mapped for fiemap. */ 1676 1647 if (blkaddr == NEW_ADDR) 1677 1648 map->m_flags |= F2FS_MAP_DELALLOC; 1678 - map->m_flags |= F2FS_MAP_MAPPED; 1649 + if (flag != F2FS_GET_BLOCK_DIO || !is_hole) 1650 + map->m_flags |= F2FS_MAP_MAPPED; 1679 1651 1680 1652 map->m_pblk = blkaddr; 1681 1653 map->m_len = 1; 1682 1654 1683 1655 if (map->m_multidev_dio) 1684 1656 map->m_bdev = FDEV(bidx).bdev; 1685 - } else if ((map->m_pblk != NEW_ADDR && 1686 - blkaddr == (map->m_pblk + ofs)) || 1687 - (map->m_pblk == NEW_ADDR && blkaddr == NEW_ADDR) || 1688 - flag == F2FS_GET_BLOCK_PRE_DIO) { 1689 - if (map->m_multidev_dio && map->m_bdev != FDEV(bidx).bdev) 1690 - goto sync_out; 1657 + } else if (map_is_mergeable(sbi, map, blkaddr, flag, bidx, ofs)) { 1691 1658 ofs++; 1692 1659 map->m_len++; 1693 1660 } else { ··· 2067 2042 return i_size_read(inode); 2068 2043 } 2069 2044 2070 - static int f2fs_read_single_page(struct inode *inode, struct page *page, 2045 + static int f2fs_read_single_page(struct inode *inode, struct folio *folio, 2071 2046 unsigned nr_pages, 2072 2047 struct f2fs_map_blocks *map, 2073 2048 struct bio **bio_ret, ··· 2080 2055 sector_t last_block; 2081 2056 sector_t last_block_in_file; 2082 2057 sector_t block_nr; 2058 + pgoff_t index = folio_index(folio); 2083 2059 int ret = 0; 2084 2060 2085 - block_in_file = (sector_t)page_index(page); 2061 + block_in_file = (sector_t)index; 2086 2062 last_block = block_in_file + nr_pages; 2087 2063 last_block_in_file = bytes_to_blks(inode, 2088 2064 f2fs_readpage_limit(inode) + blocksize - 1); ··· 2114 2088 got_it: 2115 2089 if ((map->m_flags & F2FS_MAP_MAPPED)) { 2116 2090 block_nr = map->m_pblk + block_in_file - map->m_lblk; 2117 - SetPageMappedToDisk(page); 2091 + folio_set_mappedtodisk(folio); 2118 2092 2119 2093 if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr, 2120 2094 DATA_GENERIC_ENHANCE_READ)) { ··· 2123 2097 } 2124 2098 } else { 2125 2099 zero_out: 2126 - zero_user_segment(page, 0, PAGE_SIZE); 2127 - if (f2fs_need_verity(inode, page->index) && 2128 - !fsverity_verify_page(page)) { 2100 + folio_zero_segment(folio, 0, folio_size(folio)); 2101 + if (f2fs_need_verity(inode, index) && 2102 + !fsverity_verify_folio(folio)) { 2129 2103 ret = -EIO; 2130 2104 goto out; 2131 2105 } 2132 - if (!PageUptodate(page)) 2133 - SetPageUptodate(page); 2134 - unlock_page(page); 2106 + if (!folio_test_uptodate(folio)) 2107 + folio_mark_uptodate(folio); 2108 + folio_unlock(folio); 2135 2109 goto out; 2136 2110 } 2137 2111 ··· 2141 2115 */ 2142 2116 if (bio && (!page_is_mergeable(F2FS_I_SB(inode), bio, 2143 2117 *last_block_in_bio, block_nr) || 2144 - !f2fs_crypt_mergeable_bio(bio, inode, page->index, NULL))) { 2118 + !f2fs_crypt_mergeable_bio(bio, inode, index, NULL))) { 2145 2119 submit_and_realloc: 2146 2120 f2fs_submit_read_bio(F2FS_I_SB(inode), bio, DATA); 2147 2121 bio = NULL; 2148 2122 } 2149 2123 if (bio == NULL) { 2150 2124 bio = f2fs_grab_read_bio(inode, block_nr, nr_pages, 2151 - is_readahead ? REQ_RAHEAD : 0, page->index, 2125 + is_readahead ? REQ_RAHEAD : 0, index, 2152 2126 false); 2153 2127 if (IS_ERR(bio)) { 2154 2128 ret = PTR_ERR(bio); ··· 2163 2137 */ 2164 2138 f2fs_wait_on_block_writeback(inode, block_nr); 2165 2139 2166 - if (bio_add_page(bio, page, blocksize, 0) < blocksize) 2140 + if (!bio_add_folio(bio, folio, blocksize, 0)) 2167 2141 goto submit_and_realloc; 2168 2142 2169 2143 inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA); ··· 2350 2324 * Major change was from block_size == page_size in f2fs by default. 2351 2325 */ 2352 2326 static int f2fs_mpage_readpages(struct inode *inode, 2353 - struct readahead_control *rac, struct page *page) 2327 + struct readahead_control *rac, struct folio *folio) 2354 2328 { 2355 2329 struct bio *bio = NULL; 2356 2330 sector_t last_block_in_bio = 0; ··· 2370 2344 #endif 2371 2345 unsigned nr_pages = rac ? readahead_count(rac) : 1; 2372 2346 unsigned max_nr_pages = nr_pages; 2347 + pgoff_t index; 2373 2348 int ret = 0; 2374 2349 2375 2350 map.m_pblk = 0; ··· 2384 2357 2385 2358 for (; nr_pages; nr_pages--) { 2386 2359 if (rac) { 2387 - page = readahead_page(rac); 2388 - prefetchw(&page->flags); 2360 + folio = readahead_folio(rac); 2361 + prefetchw(&folio->flags); 2389 2362 } 2363 + 2364 + index = folio_index(folio); 2390 2365 2391 2366 #ifdef CONFIG_F2FS_FS_COMPRESSION 2392 - if (f2fs_compressed_file(inode)) { 2393 - /* there are remained compressed pages, submit them */ 2394 - if (!f2fs_cluster_can_merge_page(&cc, page->index)) { 2395 - ret = f2fs_read_multi_pages(&cc, &bio, 2396 - max_nr_pages, 2397 - &last_block_in_bio, 2398 - rac != NULL, false); 2399 - f2fs_destroy_compress_ctx(&cc, false); 2400 - if (ret) 2401 - goto set_error_page; 2402 - } 2403 - if (cc.cluster_idx == NULL_CLUSTER) { 2404 - if (nc_cluster_idx == 2405 - page->index >> cc.log_cluster_size) { 2406 - goto read_single_page; 2407 - } 2367 + if (!f2fs_compressed_file(inode)) 2368 + goto read_single_page; 2408 2369 2409 - ret = f2fs_is_compressed_cluster(inode, page->index); 2410 - if (ret < 0) 2411 - goto set_error_page; 2412 - else if (!ret) { 2413 - nc_cluster_idx = 2414 - page->index >> cc.log_cluster_size; 2415 - goto read_single_page; 2416 - } 2417 - 2418 - nc_cluster_idx = NULL_CLUSTER; 2419 - } 2420 - ret = f2fs_init_compress_ctx(&cc); 2370 + /* there are remained compressed pages, submit them */ 2371 + if (!f2fs_cluster_can_merge_page(&cc, index)) { 2372 + ret = f2fs_read_multi_pages(&cc, &bio, 2373 + max_nr_pages, 2374 + &last_block_in_bio, 2375 + rac != NULL, false); 2376 + f2fs_destroy_compress_ctx(&cc, false); 2421 2377 if (ret) 2422 2378 goto set_error_page; 2423 - 2424 - f2fs_compress_ctx_add_page(&cc, page); 2425 - 2426 - goto next_page; 2427 2379 } 2380 + if (cc.cluster_idx == NULL_CLUSTER) { 2381 + if (nc_cluster_idx == index >> cc.log_cluster_size) 2382 + goto read_single_page; 2383 + 2384 + ret = f2fs_is_compressed_cluster(inode, index); 2385 + if (ret < 0) 2386 + goto set_error_page; 2387 + else if (!ret) { 2388 + nc_cluster_idx = 2389 + index >> cc.log_cluster_size; 2390 + goto read_single_page; 2391 + } 2392 + 2393 + nc_cluster_idx = NULL_CLUSTER; 2394 + } 2395 + ret = f2fs_init_compress_ctx(&cc); 2396 + if (ret) 2397 + goto set_error_page; 2398 + 2399 + f2fs_compress_ctx_add_page(&cc, &folio->page); 2400 + 2401 + goto next_page; 2428 2402 read_single_page: 2429 2403 #endif 2430 2404 2431 - ret = f2fs_read_single_page(inode, page, max_nr_pages, &map, 2405 + ret = f2fs_read_single_page(inode, folio, max_nr_pages, &map, 2432 2406 &bio, &last_block_in_bio, rac); 2433 2407 if (ret) { 2434 2408 #ifdef CONFIG_F2FS_FS_COMPRESSION 2435 2409 set_error_page: 2436 2410 #endif 2437 - zero_user_segment(page, 0, PAGE_SIZE); 2438 - unlock_page(page); 2411 + folio_zero_segment(folio, 0, folio_size(folio)); 2412 + folio_unlock(folio); 2439 2413 } 2440 2414 #ifdef CONFIG_F2FS_FS_COMPRESSION 2441 2415 next_page: 2442 2416 #endif 2443 - if (rac) 2444 - put_page(page); 2445 2417 2446 2418 #ifdef CONFIG_F2FS_FS_COMPRESSION 2447 2419 if (f2fs_compressed_file(inode)) { ··· 2462 2436 2463 2437 static int f2fs_read_data_folio(struct file *file, struct folio *folio) 2464 2438 { 2465 - struct page *page = &folio->page; 2466 - struct inode *inode = page_file_mapping(page)->host; 2439 + struct inode *inode = folio_file_mapping(folio)->host; 2467 2440 int ret = -EAGAIN; 2468 2441 2469 - trace_f2fs_readpage(page, DATA); 2442 + trace_f2fs_readpage(folio, DATA); 2470 2443 2471 2444 if (!f2fs_is_compress_backend_ready(inode)) { 2472 - unlock_page(page); 2445 + folio_unlock(folio); 2473 2446 return -EOPNOTSUPP; 2474 2447 } 2475 2448 2476 2449 /* If the file has inline data, try to read it directly */ 2477 2450 if (f2fs_has_inline_data(inode)) 2478 - ret = f2fs_read_inline_data(inode, page); 2451 + ret = f2fs_read_inline_data(inode, folio); 2479 2452 if (ret == -EAGAIN) 2480 - ret = f2fs_mpage_readpages(inode, NULL, page); 2453 + ret = f2fs_mpage_readpages(inode, NULL, folio); 2481 2454 return ret; 2482 2455 } 2483 2456 ··· 2710 2685 if (err) { 2711 2686 if (fscrypt_inode_uses_fs_layer_crypto(inode)) 2712 2687 fscrypt_finalize_bounce_page(&fio->encrypted_page); 2713 - if (PageWriteback(page)) 2714 - end_page_writeback(page); 2688 + end_page_writeback(page); 2715 2689 } else { 2716 2690 set_inode_flag(inode, FI_UPDATE_WRITE); 2717 2691 } 2718 - trace_f2fs_do_write_data_page(fio->page, IPU); 2692 + trace_f2fs_do_write_data_page(page_folio(page), IPU); 2719 2693 return err; 2720 2694 } 2721 2695 ··· 2743 2719 2744 2720 /* LFS mode write path */ 2745 2721 f2fs_outplace_write_data(&dn, fio); 2746 - trace_f2fs_do_write_data_page(page, OPU); 2722 + trace_f2fs_do_write_data_page(page_folio(page), OPU); 2747 2723 set_inode_flag(inode, FI_APPEND_WRITE); 2748 2724 out_writepage: 2749 2725 f2fs_put_dnode(&dn); ··· 2790 2766 .last_block = last_block, 2791 2767 }; 2792 2768 2793 - trace_f2fs_writepage(page, DATA); 2769 + trace_f2fs_writepage(page_folio(page), DATA); 2794 2770 2795 2771 /* we should bypass data pages to proceed the kworker jobs */ 2796 2772 if (unlikely(f2fs_cp_error(sbi))) { ··· 3403 3379 3404 3380 if (f2fs_has_inline_data(inode)) { 3405 3381 if (pos + len <= MAX_INLINE_DATA(inode)) { 3406 - f2fs_do_read_inline_data(page, ipage); 3382 + f2fs_do_read_inline_data(page_folio(page), ipage); 3407 3383 set_inode_flag(inode, FI_DATA_EXIST); 3408 3384 if (inode->i_nlink) 3409 3385 set_page_private_inline(ipage); ··· 3764 3740 { 3765 3741 struct inode *inode = mapping->host; 3766 3742 3767 - trace_f2fs_set_page_dirty(&folio->page, DATA); 3743 + trace_f2fs_set_page_dirty(folio, DATA); 3768 3744 3769 3745 if (!folio_test_uptodate(folio)) 3770 3746 folio_mark_uptodate(folio); ··· 3920 3896 struct address_space *mapping = swap_file->f_mapping; 3921 3897 struct inode *inode = mapping->host; 3922 3898 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 3923 - sector_t cur_lblock; 3924 - sector_t last_lblock; 3925 - sector_t pblock; 3926 - sector_t lowest_pblock = -1; 3927 - sector_t highest_pblock = 0; 3899 + block_t cur_lblock; 3900 + block_t last_lblock; 3901 + block_t pblock; 3902 + block_t lowest_pblock = -1; 3903 + block_t highest_pblock = 0; 3928 3904 int nr_extents = 0; 3929 - unsigned long nr_pblocks; 3905 + unsigned int nr_pblocks; 3930 3906 unsigned int blks_per_sec = BLKS_PER_SEC(sbi); 3931 - unsigned int sec_blks_mask = BLKS_PER_SEC(sbi) - 1; 3932 3907 unsigned int not_aligned = 0; 3933 3908 int ret = 0; 3934 3909 ··· 3965 3942 pblock = map.m_pblk; 3966 3943 nr_pblocks = map.m_len; 3967 3944 3968 - if ((pblock - SM_I(sbi)->main_blkaddr) & sec_blks_mask || 3969 - nr_pblocks & sec_blks_mask || 3945 + if ((pblock - SM_I(sbi)->main_blkaddr) % blks_per_sec || 3946 + nr_pblocks % blks_per_sec || 3970 3947 !f2fs_valid_pinned_area(sbi, pblock)) { 3971 3948 bool last_extent = false; 3972 3949 ··· 4183 4160 map.m_lblk = bytes_to_blks(inode, offset); 4184 4161 map.m_len = bytes_to_blks(inode, offset + length - 1) - map.m_lblk + 1; 4185 4162 map.m_next_pgofs = &next_pgofs; 4186 - map.m_seg_type = f2fs_rw_hint_to_seg_type(inode->i_write_hint); 4163 + map.m_seg_type = f2fs_rw_hint_to_seg_type(F2FS_I_SB(inode), 4164 + inode->i_write_hint); 4187 4165 if (flags & IOMAP_WRITE) 4188 4166 map.m_may_create = true; 4189 4167 ··· 4205 4181 * We should never see delalloc or compressed extents here based on 4206 4182 * prior flushing and checks. 4207 4183 */ 4208 - if (WARN_ON_ONCE(map.m_pblk == NEW_ADDR)) 4209 - return -EINVAL; 4210 4184 if (WARN_ON_ONCE(map.m_pblk == COMPRESS_ADDR)) 4211 4185 return -EINVAL; 4212 4186 4213 - if (map.m_pblk != NULL_ADDR) { 4187 + if (map.m_flags & F2FS_MAP_MAPPED) { 4188 + if (WARN_ON_ONCE(map.m_pblk == NEW_ADDR)) 4189 + return -EINVAL; 4190 + 4214 4191 iomap->length = blks_to_bytes(inode, map.m_len); 4215 4192 iomap->type = IOMAP_MAPPED; 4216 4193 iomap->flags |= IOMAP_F_MERGED; ··· 4220 4195 } else { 4221 4196 if (flags & IOMAP_WRITE) 4222 4197 return -ENOTBLK; 4223 - iomap->length = blks_to_bytes(inode, next_pgofs) - 4224 - iomap->offset; 4225 - iomap->type = IOMAP_HOLE; 4198 + 4199 + if (map.m_pblk == NULL_ADDR) { 4200 + iomap->length = blks_to_bytes(inode, next_pgofs) - 4201 + iomap->offset; 4202 + iomap->type = IOMAP_HOLE; 4203 + } else if (map.m_pblk == NEW_ADDR) { 4204 + iomap->length = blks_to_bytes(inode, map.m_len); 4205 + iomap->type = IOMAP_UNWRITTEN; 4206 + } else { 4207 + f2fs_bug_on(F2FS_I_SB(inode), 1); 4208 + } 4226 4209 iomap->addr = IOMAP_NULL_ADDR; 4227 4210 } 4228 4211
+32 -25
fs/f2fs/f2fs.h
··· 72 72 73 73 struct f2fs_fault_info { 74 74 atomic_t inject_ops; 75 - unsigned int inject_rate; 75 + int inject_rate; 76 76 unsigned int inject_type; 77 77 }; 78 78 ··· 765 765 766 766 #define DEF_DIR_LEVEL 0 767 767 768 - enum { 769 - GC_FAILURE_PIN, 770 - MAX_GC_FAILURE 771 - }; 772 - 773 768 /* used for f2fs_inode_info->flags */ 774 769 enum { 775 770 FI_NEW_INODE, /* indicate newly allocated inode */ ··· 811 816 unsigned long i_flags; /* keep an inode flags for ioctl */ 812 817 unsigned char i_advise; /* use to give file attribute hints */ 813 818 unsigned char i_dir_level; /* use for dentry level for large dir */ 814 - unsigned int i_current_depth; /* only for directory depth */ 815 - /* for gc failure statistic */ 816 - unsigned int i_gc_failures[MAX_GC_FAILURE]; 819 + union { 820 + unsigned int i_current_depth; /* only for directory depth */ 821 + unsigned short i_gc_failures; /* for gc failure statistic */ 822 + }; 817 823 unsigned int i_pino; /* parent inode number */ 818 824 umode_t i_acl_mode; /* keep file acl mode temporarily */ 819 825 ··· 1553 1557 1554 1558 #ifdef CONFIG_BLK_DEV_ZONED 1555 1559 unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 1560 + unsigned int max_open_zones; /* max open zone resources of the zoned device */ 1556 1561 #endif 1557 1562 1558 1563 /* for node-related operations */ ··· 1673 1676 unsigned long long skipped_gc_rwsem; /* FG_GC only */ 1674 1677 1675 1678 /* threshold for gc trials on pinned files */ 1676 - u64 gc_pin_file_threshold; 1679 + unsigned short gc_pin_file_threshold; 1677 1680 struct f2fs_rwsem pin_sem; 1678 1681 1679 1682 /* maximum # of trials to find a victim segment for SSR and GC */ ··· 2306 2309 static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 2307 2310 struct inode *inode, blkcnt_t *count, bool partial) 2308 2311 { 2309 - blkcnt_t diff = 0, release = 0; 2312 + long long diff = 0, release = 0; 2310 2313 block_t avail_user_block_count; 2311 2314 int ret; 2312 2315 ··· 2326 2329 percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 2327 2330 2328 2331 spin_lock(&sbi->stat_lock); 2329 - sbi->total_valid_block_count += (block_t)(*count); 2330 - avail_user_block_count = get_available_block_count(sbi, inode, true); 2331 2332 2332 - if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 2333 + avail_user_block_count = get_available_block_count(sbi, inode, true); 2334 + diff = (long long)sbi->total_valid_block_count + *count - 2335 + avail_user_block_count; 2336 + if (unlikely(diff > 0)) { 2333 2337 if (!partial) { 2334 2338 spin_unlock(&sbi->stat_lock); 2339 + release = *count; 2335 2340 goto enospc; 2336 2341 } 2337 - 2338 - diff = sbi->total_valid_block_count - avail_user_block_count; 2339 2342 if (diff > *count) 2340 2343 diff = *count; 2341 2344 *count -= diff; 2342 2345 release = diff; 2343 - sbi->total_valid_block_count -= diff; 2344 2346 if (!*count) { 2345 2347 spin_unlock(&sbi->stat_lock); 2346 2348 goto enospc; 2347 2349 } 2348 2350 } 2351 + sbi->total_valid_block_count += (block_t)(*count); 2352 + 2349 2353 spin_unlock(&sbi->stat_lock); 2350 2354 2351 2355 if (unlikely(release)) { ··· 3130 3132 static inline void f2fs_i_gc_failures_write(struct inode *inode, 3131 3133 unsigned int count) 3132 3134 { 3133 - F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] = count; 3135 + F2FS_I(inode)->i_gc_failures = count; 3134 3136 f2fs_mark_inode_dirty_sync(inode, true); 3135 3137 } 3136 3138 ··· 3495 3497 struct iattr *attr); 3496 3498 int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 3497 3499 void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count); 3500 + int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag, 3501 + bool readonly); 3498 3502 int f2fs_precache_extents(struct inode *inode); 3499 3503 int f2fs_fileattr_get(struct dentry *dentry, struct fileattr *fa); 3500 3504 int f2fs_fileattr_set(struct mnt_idmap *idmap, ··· 3719 3719 block_t old_addr, block_t new_addr, 3720 3720 unsigned char version, bool recover_curseg, 3721 3721 bool recover_newaddr); 3722 + int f2fs_get_segment_temp(int seg_type); 3722 3723 int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 3723 3724 block_t old_blkaddr, block_t *new_blkaddr, 3724 3725 struct f2fs_summary *sum, int type, ··· 3742 3741 void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi); 3743 3742 int __init f2fs_create_segment_manager_caches(void); 3744 3743 void f2fs_destroy_segment_manager_caches(void); 3745 - int f2fs_rw_hint_to_seg_type(enum rw_hint hint); 3744 + int f2fs_rw_hint_to_seg_type(struct f2fs_sb_info *sbi, enum rw_hint hint); 3745 + enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi, 3746 + enum page_type type, enum temp_type temp); 3746 3747 unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi, 3747 3748 unsigned int segno); 3748 3749 unsigned int f2fs_usable_blks_in_seg(struct f2fs_sb_info *sbi, ··· 4151 4148 bool f2fs_may_inline_data(struct inode *inode); 4152 4149 bool f2fs_sanity_check_inline_data(struct inode *inode); 4153 4150 bool f2fs_may_inline_dentry(struct inode *inode); 4154 - void f2fs_do_read_inline_data(struct page *page, struct page *ipage); 4151 + void f2fs_do_read_inline_data(struct folio *folio, struct page *ipage); 4155 4152 void f2fs_truncate_inline_inode(struct inode *inode, 4156 4153 struct page *ipage, u64 from); 4157 - int f2fs_read_inline_data(struct inode *inode, struct page *page); 4154 + int f2fs_read_inline_data(struct inode *inode, struct folio *folio); 4158 4155 int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 4159 4156 int f2fs_convert_inline_inode(struct inode *inode); 4160 4157 int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry); ··· 4599 4596 } 4600 4597 4601 4598 #ifdef CONFIG_F2FS_FAULT_INJECTION 4602 - extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, 4603 - unsigned int type); 4599 + extern int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate, 4600 + unsigned long type); 4604 4601 #else 4605 - #define f2fs_build_fault_attr(sbi, rate, type) do { } while (0) 4602 + static inline int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, 4603 + unsigned long rate, unsigned long type) 4604 + { 4605 + return 0; 4606 + } 4606 4607 #endif 4607 4608 4608 4609 static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) ··· 4664 4657 4665 4658 page = find_get_page(META_MAPPING(sbi), blkaddr + i); 4666 4659 if (page) { 4667 - if (PageWriteback(page)) 4660 + if (folio_test_writeback(page_folio(page))) 4668 4661 need_submit = true; 4669 4662 f2fs_put_page(page, 0); 4670 4663 }
+162 -94
fs/f2fs/file.c
··· 58 58 struct inode *inode = file_inode(vmf->vma->vm_file); 59 59 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 60 60 struct dnode_of_data dn; 61 - bool need_alloc = true; 61 + bool need_alloc = !f2fs_is_pinned_file(inode); 62 62 int err = 0; 63 63 vm_fault_t ret; 64 64 ··· 115 115 goto out_sem; 116 116 } 117 117 118 + set_new_dnode(&dn, inode, NULL, NULL, 0); 118 119 if (need_alloc) { 119 120 /* block allocation */ 120 - set_new_dnode(&dn, inode, NULL, NULL, 0); 121 121 err = f2fs_get_block_locked(&dn, page->index); 122 - } 123 - 124 - #ifdef CONFIG_F2FS_FS_COMPRESSION 125 - if (!need_alloc) { 126 - set_new_dnode(&dn, inode, NULL, NULL, 0); 122 + } else { 127 123 err = f2fs_get_dnode_of_data(&dn, page->index, LOOKUP_NODE); 128 124 f2fs_put_dnode(&dn); 125 + if (f2fs_is_pinned_file(inode) && 126 + !__is_valid_data_blkaddr(dn.data_blkaddr)) 127 + err = -EIO; 129 128 } 130 - #endif 129 + 131 130 if (err) { 132 131 unlock_page(page); 133 132 goto out_sem; ··· 833 834 * for blkzoned device, fallback direct IO to buffered IO, so 834 835 * all IOs can be serialized by log-structured write. 835 836 */ 836 - if (f2fs_sb_has_blkzoned(sbi) && (rw == WRITE)) 837 + if (f2fs_sb_has_blkzoned(sbi) && (rw == WRITE) && 838 + !f2fs_is_pinned_file(inode)) 837 839 return true; 838 840 if (is_sbi_flag_set(sbi, SBI_CP_DISABLED)) 839 841 return true; ··· 952 952 ATTR_GID | ATTR_TIMES_SET)))) 953 953 return -EPERM; 954 954 955 - if ((attr->ia_valid & ATTR_SIZE) && 956 - !f2fs_is_compress_backend_ready(inode)) 957 - return -EOPNOTSUPP; 955 + if ((attr->ia_valid & ATTR_SIZE)) { 956 + if (!f2fs_is_compress_backend_ready(inode)) 957 + return -EOPNOTSUPP; 958 + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED) && 959 + !IS_ALIGNED(attr->ia_size, 960 + F2FS_BLK_TO_BYTES(F2FS_I(inode)->i_cluster_size))) 961 + return -EINVAL; 962 + } 958 963 959 964 err = setattr_prepare(idmap, dentry, attr); 960 965 if (err) ··· 1330 1325 f2fs_put_page(psrc, 1); 1331 1326 return PTR_ERR(pdst); 1332 1327 } 1328 + 1329 + f2fs_wait_on_page_writeback(pdst, DATA, true, true); 1330 + 1333 1331 memcpy_page(pdst, 0, psrc, 0, PAGE_SIZE); 1334 1332 set_page_dirty(pdst); 1335 1333 set_page_private_gcing(pdst); ··· 1825 1817 (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE))) 1826 1818 return -EOPNOTSUPP; 1827 1819 1828 - /* 1829 - * Pinned file should not support partial truncation since the block 1830 - * can be used by applications. 1831 - */ 1832 - if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) && 1833 - (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE | 1834 - FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE))) 1835 - return -EOPNOTSUPP; 1836 - 1837 1820 if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | 1838 1821 FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | 1839 1822 FALLOC_FL_INSERT_RANGE)) 1840 1823 return -EOPNOTSUPP; 1841 1824 1842 1825 inode_lock(inode); 1826 + 1827 + /* 1828 + * Pinned file should not support partial truncation since the block 1829 + * can be used by applications. 1830 + */ 1831 + if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) && 1832 + (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE | 1833 + FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE))) { 1834 + ret = -EOPNOTSUPP; 1835 + goto out; 1836 + } 1843 1837 1844 1838 ret = file_modified(file); 1845 1839 if (ret) ··· 2234 2224 return ret; 2235 2225 } 2236 2226 2237 - static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg) 2227 + int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag, 2228 + bool readonly) 2238 2229 { 2239 - struct inode *inode = file_inode(filp); 2240 - struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 2241 2230 struct super_block *sb = sbi->sb; 2242 - __u32 in; 2243 2231 int ret = 0; 2244 2232 2245 - if (!capable(CAP_SYS_ADMIN)) 2246 - return -EPERM; 2247 - 2248 - if (get_user(in, (__u32 __user *)arg)) 2249 - return -EFAULT; 2250 - 2251 - if (in != F2FS_GOING_DOWN_FULLSYNC) { 2252 - ret = mnt_want_write_file(filp); 2253 - if (ret) { 2254 - if (ret == -EROFS) { 2255 - ret = 0; 2256 - f2fs_stop_checkpoint(sbi, false, 2257 - STOP_CP_REASON_SHUTDOWN); 2258 - trace_f2fs_shutdown(sbi, in, ret); 2259 - } 2260 - return ret; 2261 - } 2262 - } 2263 - 2264 - switch (in) { 2233 + switch (flag) { 2265 2234 case F2FS_GOING_DOWN_FULLSYNC: 2266 2235 ret = bdev_freeze(sb->s_bdev); 2267 2236 if (ret) ··· 2279 2290 goto out; 2280 2291 } 2281 2292 2293 + if (readonly) 2294 + goto out; 2295 + 2282 2296 f2fs_stop_gc_thread(sbi); 2283 2297 f2fs_stop_discard_thread(sbi); 2284 2298 ··· 2290 2298 2291 2299 f2fs_update_time(sbi, REQ_TIME); 2292 2300 out: 2293 - if (in != F2FS_GOING_DOWN_FULLSYNC) 2294 - mnt_drop_write_file(filp); 2295 2301 2296 - trace_f2fs_shutdown(sbi, in, ret); 2302 + trace_f2fs_shutdown(sbi, flag, ret); 2303 + 2304 + return ret; 2305 + } 2306 + 2307 + static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg) 2308 + { 2309 + struct inode *inode = file_inode(filp); 2310 + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 2311 + __u32 in; 2312 + int ret; 2313 + bool need_drop = false, readonly = false; 2314 + 2315 + if (!capable(CAP_SYS_ADMIN)) 2316 + return -EPERM; 2317 + 2318 + if (get_user(in, (__u32 __user *)arg)) 2319 + return -EFAULT; 2320 + 2321 + if (in != F2FS_GOING_DOWN_FULLSYNC) { 2322 + ret = mnt_want_write_file(filp); 2323 + if (ret) { 2324 + if (ret != -EROFS) 2325 + return ret; 2326 + 2327 + /* fallback to nosync shutdown for readonly fs */ 2328 + in = F2FS_GOING_DOWN_NOSYNC; 2329 + readonly = true; 2330 + } else { 2331 + need_drop = true; 2332 + } 2333 + } 2334 + 2335 + ret = f2fs_do_shutdown(sbi, in, readonly); 2336 + 2337 + if (need_drop) 2338 + mnt_drop_write_file(filp); 2297 2339 2298 2340 return ret; 2299 2341 } ··· 2380 2354 static int f2fs_ioc_set_encryption_policy(struct file *filp, unsigned long arg) 2381 2355 { 2382 2356 struct inode *inode = file_inode(filp); 2357 + int ret; 2383 2358 2384 2359 if (!f2fs_sb_has_encrypt(F2FS_I_SB(inode))) 2385 2360 return -EOPNOTSUPP; 2386 2361 2362 + ret = fscrypt_ioctl_set_policy(filp, (const void __user *)arg); 2387 2363 f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); 2388 - 2389 - return fscrypt_ioctl_set_policy(filp, (const void __user *)arg); 2364 + return ret; 2390 2365 } 2391 2366 2392 2367 static int f2fs_ioc_get_encryption_policy(struct file *filp, unsigned long arg) ··· 2634 2607 bool fragmented = false; 2635 2608 int err; 2636 2609 2637 - pg_start = range->start >> PAGE_SHIFT; 2638 - pg_end = (range->start + range->len) >> PAGE_SHIFT; 2639 - 2640 2610 f2fs_balance_fs(sbi, true); 2641 2611 2642 2612 inode_lock(inode); 2613 + pg_start = range->start >> PAGE_SHIFT; 2614 + pg_end = min_t(pgoff_t, 2615 + (range->start + range->len) >> PAGE_SHIFT, 2616 + DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE)); 2643 2617 2644 2618 if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { 2645 2619 err = -EINVAL; ··· 2655 2627 } 2656 2628 2657 2629 /* writeback all dirty pages in the range */ 2658 - err = filemap_write_and_wait_range(inode->i_mapping, range->start, 2659 - range->start + range->len - 1); 2630 + err = filemap_write_and_wait_range(inode->i_mapping, 2631 + pg_start << PAGE_SHIFT, 2632 + (pg_end << PAGE_SHIFT) - 1); 2660 2633 if (err) 2661 2634 goto out; 2662 2635 ··· 2815 2786 err = f2fs_defragment_range(sbi, filp, &range); 2816 2787 mnt_drop_write_file(filp); 2817 2788 2818 - f2fs_update_time(sbi, REQ_TIME); 2789 + if (range.len) 2790 + f2fs_update_time(sbi, REQ_TIME); 2819 2791 if (err < 0) 2820 2792 return err; 2821 2793 ··· 2867 2837 goto out; 2868 2838 } 2869 2839 2870 - if (f2fs_compressed_file(src) || f2fs_compressed_file(dst)) { 2840 + if (f2fs_compressed_file(src) || f2fs_compressed_file(dst) || 2841 + f2fs_is_pinned_file(src) || f2fs_is_pinned_file(dst)) { 2871 2842 ret = -EOPNOTSUPP; 2872 2843 goto out_unlock; 2873 2844 } ··· 3220 3189 struct f2fs_inode_info *fi = F2FS_I(inode); 3221 3190 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 3222 3191 3223 - /* Use i_gc_failures for normal file as a risk signal. */ 3224 - if (inc) 3225 - f2fs_i_gc_failures_write(inode, 3226 - fi->i_gc_failures[GC_FAILURE_PIN] + 1); 3227 - 3228 - if (fi->i_gc_failures[GC_FAILURE_PIN] > sbi->gc_pin_file_threshold) { 3192 + if (fi->i_gc_failures >= sbi->gc_pin_file_threshold) { 3229 3193 f2fs_warn(sbi, "%s: Enable GC = ino %lx after %x GC trials", 3230 - __func__, inode->i_ino, 3231 - fi->i_gc_failures[GC_FAILURE_PIN]); 3194 + __func__, inode->i_ino, fi->i_gc_failures); 3232 3195 clear_inode_flag(inode, FI_PIN_FILE); 3233 3196 return -EAGAIN; 3234 3197 } 3198 + 3199 + /* Use i_gc_failures for normal file as a risk signal. */ 3200 + if (inc) 3201 + f2fs_i_gc_failures_write(inode, fi->i_gc_failures + 1); 3202 + 3235 3203 return 0; 3236 3204 } 3237 3205 ··· 3264 3234 goto done; 3265 3235 } 3266 3236 3267 - if (f2fs_sb_has_blkzoned(sbi) && F2FS_HAS_BLOCKS(inode)) { 3237 + if (F2FS_HAS_BLOCKS(inode)) { 3268 3238 ret = -EFBIG; 3269 3239 goto out; 3270 3240 } ··· 3291 3261 } 3292 3262 3293 3263 set_inode_flag(inode, FI_PIN_FILE); 3294 - ret = F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN]; 3264 + ret = F2FS_I(inode)->i_gc_failures; 3295 3265 done: 3296 3266 f2fs_update_time(sbi, REQ_TIME); 3297 3267 out: ··· 3306 3276 __u32 pin = 0; 3307 3277 3308 3278 if (is_inode_flag_set(inode, FI_PIN_FILE)) 3309 - pin = F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN]; 3279 + pin = F2FS_I(inode)->i_gc_failures; 3310 3280 return put_user(pin, (u32 __user *)arg); 3311 3281 } 3312 3282 ··· 3552 3522 if (!f2fs_sb_has_compression(sbi)) 3553 3523 return -EOPNOTSUPP; 3554 3524 3555 - if (!f2fs_compressed_file(inode)) 3556 - return -EINVAL; 3557 - 3558 3525 if (f2fs_readonly(sbi->sb)) 3559 3526 return -EROFS; 3560 3527 ··· 3570 3543 goto out; 3571 3544 } 3572 3545 3573 - if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { 3546 + if (!f2fs_compressed_file(inode) || 3547 + is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { 3574 3548 ret = -EINVAL; 3575 3549 goto out; 3576 3550 } ··· 3598 3570 struct dnode_of_data dn; 3599 3571 pgoff_t end_offset, count; 3600 3572 3573 + f2fs_lock_op(sbi); 3574 + 3601 3575 set_new_dnode(&dn, inode, NULL, NULL, 0); 3602 3576 ret = f2fs_get_dnode_of_data(&dn, page_idx, LOOKUP_NODE); 3603 3577 if (ret) { 3578 + f2fs_unlock_op(sbi); 3604 3579 if (ret == -ENOENT) { 3605 3580 page_idx = f2fs_get_next_page_offset(&dn, 3606 3581 page_idx); ··· 3621 3590 3622 3591 f2fs_put_dnode(&dn); 3623 3592 3593 + f2fs_unlock_op(sbi); 3594 + 3624 3595 if (ret < 0) 3625 3596 break; 3626 3597 ··· 3633 3600 filemap_invalidate_unlock(inode->i_mapping); 3634 3601 f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); 3635 3602 out: 3603 + if (released_blocks) 3604 + f2fs_update_time(sbi, REQ_TIME); 3636 3605 inode_unlock(inode); 3637 3606 3638 3607 mnt_drop_write_file(filp); ··· 3676 3641 3677 3642 while (count) { 3678 3643 int compr_blocks = 0; 3679 - blkcnt_t reserved; 3644 + blkcnt_t reserved = 0; 3645 + blkcnt_t to_reserved; 3680 3646 int ret; 3681 3647 3682 3648 for (i = 0; i < cluster_size; i++) { ··· 3697 3661 * fails in release_compress_blocks(), so NEW_ADDR 3698 3662 * is a possible case. 3699 3663 */ 3700 - if (blkaddr == NEW_ADDR || 3701 - __is_valid_data_blkaddr(blkaddr)) { 3664 + if (blkaddr == NEW_ADDR) { 3665 + reserved++; 3666 + continue; 3667 + } 3668 + if (__is_valid_data_blkaddr(blkaddr)) { 3702 3669 compr_blocks++; 3703 3670 continue; 3704 3671 } 3705 3672 } 3706 3673 3707 - reserved = cluster_size - compr_blocks; 3674 + to_reserved = cluster_size - compr_blocks - reserved; 3708 3675 3709 3676 /* for the case all blocks in cluster were reserved */ 3710 - if (reserved == 1) 3677 + if (to_reserved == 1) { 3678 + dn->ofs_in_node += cluster_size; 3711 3679 goto next; 3680 + } 3712 3681 3713 - ret = inc_valid_block_count(sbi, dn->inode, &reserved, false); 3682 + ret = inc_valid_block_count(sbi, dn->inode, 3683 + &to_reserved, false); 3714 3684 if (unlikely(ret)) 3715 3685 return ret; 3716 3686 ··· 3727 3685 3728 3686 f2fs_i_compr_blocks_update(dn->inode, compr_blocks, true); 3729 3687 3730 - *reserved_blocks += reserved; 3688 + *reserved_blocks += to_reserved; 3731 3689 next: 3732 3690 count -= cluster_size; 3733 3691 } ··· 3746 3704 if (!f2fs_sb_has_compression(sbi)) 3747 3705 return -EOPNOTSUPP; 3748 3706 3749 - if (!f2fs_compressed_file(inode)) 3750 - return -EINVAL; 3751 - 3752 3707 if (f2fs_readonly(sbi->sb)) 3753 3708 return -EROFS; 3754 3709 ··· 3757 3718 3758 3719 inode_lock(inode); 3759 3720 3760 - if (!is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { 3721 + if (!f2fs_compressed_file(inode) || 3722 + !is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { 3761 3723 ret = -EINVAL; 3762 3724 goto unlock_inode; 3763 3725 } ··· 3775 3735 struct dnode_of_data dn; 3776 3736 pgoff_t end_offset, count; 3777 3737 3738 + f2fs_lock_op(sbi); 3739 + 3778 3740 set_new_dnode(&dn, inode, NULL, NULL, 0); 3779 3741 ret = f2fs_get_dnode_of_data(&dn, page_idx, LOOKUP_NODE); 3780 3742 if (ret) { 3743 + f2fs_unlock_op(sbi); 3781 3744 if (ret == -ENOENT) { 3782 3745 page_idx = f2fs_get_next_page_offset(&dn, 3783 3746 page_idx); ··· 3798 3755 3799 3756 f2fs_put_dnode(&dn); 3800 3757 3758 + f2fs_unlock_op(sbi); 3759 + 3801 3760 if (ret < 0) 3802 3761 break; 3803 3762 ··· 3815 3770 f2fs_mark_inode_dirty_sync(inode, true); 3816 3771 } 3817 3772 unlock_inode: 3773 + if (reserved_blocks) 3774 + f2fs_update_time(sbi, REQ_TIME); 3818 3775 inode_unlock(inode); 3819 3776 mnt_drop_write_file(filp); 3820 3777 ··· 3825 3778 } else if (reserved_blocks && 3826 3779 atomic_read(&F2FS_I(inode)->i_compr_blocks)) { 3827 3780 set_sbi_flag(sbi, SBI_NEED_FSCK); 3828 - f2fs_warn(sbi, "%s: partial blocks were released i_ino=%lx " 3781 + f2fs_warn(sbi, "%s: partial blocks were reserved i_ino=%lx " 3829 3782 "iblocks=%llu, reserved=%u, compr_blocks=%u, " 3830 3783 "run fsck to fix.", 3831 3784 __func__, inode->i_ino, inode->i_blocks, ··· 4013 3966 if (len) 4014 3967 ret = f2fs_secure_erase(prev_bdev, inode, prev_index, 4015 3968 prev_block, len, range.flags); 3969 + f2fs_update_time(sbi, REQ_TIME); 4016 3970 out: 4017 3971 filemap_invalidate_unlock(mapping); 4018 3972 f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); ··· 4167 4119 if (!(filp->f_mode & FMODE_WRITE)) 4168 4120 return -EBADF; 4169 4121 4170 - if (!f2fs_compressed_file(inode)) 4171 - return -EINVAL; 4172 - 4173 4122 f2fs_balance_fs(sbi, true); 4174 4123 4175 4124 file_start_write(filp); ··· 4177 4132 goto out; 4178 4133 } 4179 4134 4180 - if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { 4135 + if (!f2fs_compressed_file(inode) || 4136 + is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { 4181 4137 ret = -EINVAL; 4182 4138 goto out; 4183 4139 } ··· 4221 4175 if (ret) 4222 4176 f2fs_warn(sbi, "%s: The file might be partially decompressed (errno=%d). Please delete the file.", 4223 4177 __func__, ret); 4178 + f2fs_update_time(sbi, REQ_TIME); 4224 4179 out: 4225 4180 inode_unlock(inode); 4226 4181 file_end_write(filp); ··· 4244 4197 if (!(filp->f_mode & FMODE_WRITE)) 4245 4198 return -EBADF; 4246 4199 4247 - if (!f2fs_compressed_file(inode)) 4248 - return -EINVAL; 4249 - 4250 4200 f2fs_balance_fs(sbi, true); 4251 4201 4252 4202 file_start_write(filp); ··· 4254 4210 goto out; 4255 4211 } 4256 4212 4257 - if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { 4213 + if (!f2fs_compressed_file(inode) || 4214 + is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { 4258 4215 ret = -EINVAL; 4259 4216 goto out; 4260 4217 } ··· 4299 4254 if (ret) 4300 4255 f2fs_warn(sbi, "%s: The file might be partially compressed (errno=%d). Please delete the file.", 4301 4256 __func__, ret); 4257 + f2fs_update_time(sbi, REQ_TIME); 4302 4258 out: 4303 4259 inode_unlock(inode); 4304 4260 file_end_write(filp); ··· 4658 4612 4659 4613 map.m_may_create = true; 4660 4614 if (dio) { 4661 - map.m_seg_type = f2fs_rw_hint_to_seg_type(inode->i_write_hint); 4615 + map.m_seg_type = f2fs_rw_hint_to_seg_type(sbi, 4616 + inode->i_write_hint); 4662 4617 flag = F2FS_GET_BLOCK_PRE_DIO; 4663 4618 } else { 4664 4619 map.m_seg_type = NO_CHECK_TYPE; ··· 4707 4660 return 0; 4708 4661 } 4709 4662 4663 + static void f2fs_dio_write_submit_io(const struct iomap_iter *iter, 4664 + struct bio *bio, loff_t file_offset) 4665 + { 4666 + struct inode *inode = iter->inode; 4667 + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4668 + int seg_type = f2fs_rw_hint_to_seg_type(sbi, inode->i_write_hint); 4669 + enum temp_type temp = f2fs_get_segment_temp(seg_type); 4670 + 4671 + bio->bi_write_hint = f2fs_io_type_to_rw_hint(sbi, DATA, temp); 4672 + submit_bio(bio); 4673 + } 4674 + 4710 4675 static const struct iomap_dio_ops f2fs_iomap_dio_write_ops = { 4711 - .end_io = f2fs_dio_write_end_io, 4676 + .end_io = f2fs_dio_write_end_io, 4677 + .submit_io = f2fs_dio_write_submit_io, 4712 4678 }; 4713 4679 4714 4680 static void f2fs_flush_buffered_write(struct address_space *mapping, ··· 4858 4798 bool dio; 4859 4799 bool may_need_sync = true; 4860 4800 int preallocated; 4801 + const loff_t pos = iocb->ki_pos; 4802 + const ssize_t count = iov_iter_count(from); 4861 4803 ssize_t ret; 4862 4804 4863 4805 if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) { ··· 4879 4817 } 4880 4818 } else { 4881 4819 inode_lock(inode); 4820 + } 4821 + 4822 + if (f2fs_is_pinned_file(inode) && 4823 + !f2fs_overwrite_io(inode, pos, count)) { 4824 + ret = -EIO; 4825 + goto out_unlock; 4882 4826 } 4883 4827 4884 4828 ret = f2fs_write_checks(iocb, from);
+8 -3
fs/f2fs/gc.c
··· 1434 1434 goto out; 1435 1435 1436 1436 if (gc_type == BG_GC) { 1437 - if (PageWriteback(page)) { 1437 + if (folio_test_writeback(page_folio(page))) { 1438 1438 err = -EAGAIN; 1439 1439 goto out; 1440 1440 } ··· 1554 1554 int err; 1555 1555 1556 1556 inode = f2fs_iget(sb, dni.ino); 1557 - if (IS_ERR(inode) || is_bad_inode(inode) || 1558 - special_file(inode->i_mode)) 1557 + if (IS_ERR(inode)) 1559 1558 continue; 1559 + 1560 + if (is_bad_inode(inode) || 1561 + special_file(inode->i_mode)) { 1562 + iput(inode); 1563 + continue; 1564 + } 1560 1565 1561 1566 err = f2fs_gc_pinned_control(inode, gc_type, segno); 1562 1567 if (err == -EAGAIN) {
+1
fs/f2fs/gc.h
··· 26 26 #define LIMIT_FREE_BLOCK 40 /* percentage over invalid + free space */ 27 27 28 28 #define DEF_GC_FAILED_PINNED_FILES 2048 29 + #define MAX_GC_FAILED_PINNED_FILES USHRT_MAX 29 30 30 31 /* Search max. number of dirty segments to select a victim segment */ 31 32 #define DEF_MAX_VICTIM_SEARCH 4096 /* covers 8GB */
+18 -18
fs/f2fs/inline.c
··· 61 61 return true; 62 62 } 63 63 64 - void f2fs_do_read_inline_data(struct page *page, struct page *ipage) 64 + void f2fs_do_read_inline_data(struct folio *folio, struct page *ipage) 65 65 { 66 - struct inode *inode = page->mapping->host; 66 + struct inode *inode = folio_file_mapping(folio)->host; 67 67 68 - if (PageUptodate(page)) 68 + if (folio_test_uptodate(folio)) 69 69 return; 70 70 71 - f2fs_bug_on(F2FS_P_SB(page), page->index); 71 + f2fs_bug_on(F2FS_I_SB(inode), folio_index(folio)); 72 72 73 - zero_user_segment(page, MAX_INLINE_DATA(inode), PAGE_SIZE); 73 + folio_zero_segment(folio, MAX_INLINE_DATA(inode), folio_size(folio)); 74 74 75 75 /* Copy the whole inline data block */ 76 - memcpy_to_page(page, 0, inline_data_addr(inode, ipage), 76 + memcpy_to_folio(folio, 0, inline_data_addr(inode, ipage), 77 77 MAX_INLINE_DATA(inode)); 78 - if (!PageUptodate(page)) 79 - SetPageUptodate(page); 78 + if (!folio_test_uptodate(folio)) 79 + folio_mark_uptodate(folio); 80 80 } 81 81 82 82 void f2fs_truncate_inline_inode(struct inode *inode, ··· 97 97 clear_inode_flag(inode, FI_DATA_EXIST); 98 98 } 99 99 100 - int f2fs_read_inline_data(struct inode *inode, struct page *page) 100 + int f2fs_read_inline_data(struct inode *inode, struct folio *folio) 101 101 { 102 102 struct page *ipage; 103 103 104 104 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino); 105 105 if (IS_ERR(ipage)) { 106 - unlock_page(page); 106 + folio_unlock(folio); 107 107 return PTR_ERR(ipage); 108 108 } 109 109 ··· 112 112 return -EAGAIN; 113 113 } 114 114 115 - if (page->index) 116 - zero_user_segment(page, 0, PAGE_SIZE); 115 + if (folio_index(folio)) 116 + folio_zero_segment(folio, 0, folio_size(folio)); 117 117 else 118 - f2fs_do_read_inline_data(page, ipage); 118 + f2fs_do_read_inline_data(folio, ipage); 119 119 120 - if (!PageUptodate(page)) 121 - SetPageUptodate(page); 120 + if (!folio_test_uptodate(folio)) 121 + folio_mark_uptodate(folio); 122 122 f2fs_put_page(ipage, 1); 123 - unlock_page(page); 123 + folio_unlock(folio); 124 124 return 0; 125 125 } 126 126 ··· 164 164 return -EFSCORRUPTED; 165 165 } 166 166 167 - f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page)); 167 + f2fs_bug_on(F2FS_P_SB(page), folio_test_writeback(page_folio(page))); 168 168 169 - f2fs_do_read_inline_data(page, dn->inode_page); 169 + f2fs_do_read_inline_data(page_folio(page), dn->inode_page); 170 170 set_page_dirty(page); 171 171 172 172 /* clear dirty state */
+15 -7
fs/f2fs/inode.c
··· 161 161 if (!f2fs_enable_inode_chksum(sbi, page)) 162 162 #else 163 163 if (!f2fs_enable_inode_chksum(sbi, page) || 164 - PageDirty(page) || PageWriteback(page)) 164 + PageDirty(page) || 165 + folio_test_writeback(page_folio(page))) 165 166 #endif 166 167 return true; 167 168 ··· 362 361 return false; 363 362 } 364 363 364 + if (fi->i_xattr_nid && f2fs_check_nid_range(sbi, fi->i_xattr_nid)) { 365 + f2fs_warn(sbi, "%s: inode (ino=%lx) has corrupted i_xattr_nid: %u, run fsck to fix.", 366 + __func__, inode->i_ino, fi->i_xattr_nid); 367 + return false; 368 + } 369 + 365 370 return true; 366 371 } 367 372 ··· 415 408 if (S_ISDIR(inode->i_mode)) 416 409 fi->i_current_depth = le32_to_cpu(ri->i_current_depth); 417 410 else if (S_ISREG(inode->i_mode)) 418 - fi->i_gc_failures[GC_FAILURE_PIN] = 419 - le16_to_cpu(ri->i_gc_failures); 411 + fi->i_gc_failures = le16_to_cpu(ri->i_gc_failures); 420 412 fi->i_xattr_nid = le32_to_cpu(ri->i_xattr_nid); 421 413 fi->i_flags = le32_to_cpu(ri->i_flags); 422 414 if (S_ISREG(inode->i_mode)) ··· 685 679 ri->i_current_depth = 686 680 cpu_to_le32(F2FS_I(inode)->i_current_depth); 687 681 else if (S_ISREG(inode->i_mode)) 688 - ri->i_gc_failures = 689 - cpu_to_le16(F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN]); 682 + ri->i_gc_failures = cpu_to_le16(F2FS_I(inode)->i_gc_failures); 690 683 ri->i_xattr_nid = cpu_to_le32(F2FS_I(inode)->i_xattr_nid); 691 684 ri->i_flags = cpu_to_le32(F2FS_I(inode)->i_flags); 692 685 ri->i_pino = cpu_to_le32(F2FS_I(inode)->i_pino); ··· 809 804 struct f2fs_inode_info *fi = F2FS_I(inode); 810 805 nid_t xnid = fi->i_xattr_nid; 811 806 int err = 0; 807 + bool freeze_protected = false; 812 808 813 809 f2fs_abort_atomic_write(inode, true); 814 810 ··· 849 843 f2fs_remove_ino_entry(sbi, inode->i_ino, UPDATE_INO); 850 844 f2fs_remove_ino_entry(sbi, inode->i_ino, FLUSH_INO); 851 845 852 - if (!is_sbi_flag_set(sbi, SBI_IS_FREEZING)) 846 + if (!is_sbi_flag_set(sbi, SBI_IS_FREEZING)) { 853 847 sb_start_intwrite(inode->i_sb); 848 + freeze_protected = true; 849 + } 854 850 set_inode_flag(inode, FI_NO_ALLOC); 855 851 i_size_write(inode, 0); 856 852 retry: ··· 895 887 if (dquot_initialize_needed(inode)) 896 888 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); 897 889 } 898 - if (!is_sbi_flag_set(sbi, SBI_IS_FREEZING)) 890 + if (freeze_protected) 899 891 sb_end_intwrite(inode->i_sb); 900 892 no_delete: 901 893 dquot_drop(inode);
+15 -5
fs/f2fs/node.c
··· 1187 1187 default: 1188 1188 BUG(); 1189 1189 } 1190 - if (err < 0 && err != -ENOENT) 1190 + if (err == -ENOENT) { 1191 + set_sbi_flag(F2FS_P_SB(page), SBI_NEED_FSCK); 1192 + f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR); 1193 + f2fs_err_ratelimited(sbi, 1194 + "truncate node fail, ino:%lu, nid:%u, " 1195 + "offset[0]:%d, offset[1]:%d, nofs:%d", 1196 + inode->i_ino, dn.nid, offset[0], 1197 + offset[1], nofs); 1198 + err = 0; 1199 + } 1200 + if (err < 0) 1191 1201 goto fail; 1192 1202 if (offset[1] == 0 && 1193 1203 ri->i_nid[offset[0] - NODE_DIR1_BLOCK]) { ··· 1329 1319 } 1330 1320 if (unlikely(new_ni.blk_addr != NULL_ADDR)) { 1331 1321 err = -EFSCORRUPTED; 1322 + dec_valid_node_count(sbi, dn->inode, !ofs); 1332 1323 set_sbi_flag(sbi, SBI_NEED_FSCK); 1333 1324 f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR); 1334 1325 goto fail; ··· 1356 1345 if (ofs == 0) 1357 1346 inc_valid_inode_count(sbi); 1358 1347 return page; 1359 - 1360 1348 fail: 1361 1349 clear_node_page_dirty(page); 1362 1350 f2fs_put_page(page, 1); ··· 1624 1614 }; 1625 1615 unsigned int seq; 1626 1616 1627 - trace_f2fs_writepage(page, NODE); 1617 + trace_f2fs_writepage(page_folio(page), NODE); 1628 1618 1629 1619 if (unlikely(f2fs_cp_error(sbi))) { 1630 1620 /* keep node pages in remount-ro mode */ ··· 1743 1733 goto release_page; 1744 1734 } else { 1745 1735 /* set page dirty and write it */ 1746 - if (!PageWriteback(node_page)) 1736 + if (!folio_test_writeback(page_folio(node_page))) 1747 1737 set_page_dirty(node_page); 1748 1738 } 1749 1739 out_page: ··· 2171 2161 static bool f2fs_dirty_node_folio(struct address_space *mapping, 2172 2162 struct folio *folio) 2173 2163 { 2174 - trace_f2fs_set_page_dirty(&folio->page, NODE); 2164 + trace_f2fs_set_page_dirty(folio, NODE); 2175 2165 2176 2166 if (!folio_test_uptodate(folio)) 2177 2167 folio_mark_uptodate(folio);
+1 -2
fs/f2fs/recovery.c
··· 330 330 F2FS_I(inode)->i_advise = raw->i_advise; 331 331 F2FS_I(inode)->i_flags = le32_to_cpu(raw->i_flags); 332 332 f2fs_set_inode_flags(inode); 333 - F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] = 334 - le16_to_cpu(raw->i_gc_failures); 333 + F2FS_I(inode)->i_gc_failures = le16_to_cpu(raw->i_gc_failures); 335 334 336 335 recover_inline_flags(inode, raw); 337 336
+97 -35
fs/f2fs/segment.c
··· 771 771 block_t valid_blocks = 772 772 get_valid_blocks(sbi, segno, true); 773 773 774 - f2fs_bug_on(sbi, unlikely(!valid_blocks || 775 - valid_blocks == CAP_BLKS_PER_SEC(sbi))); 774 + f2fs_bug_on(sbi, 775 + (!is_sbi_flag_set(sbi, SBI_CP_DISABLED) && 776 + !valid_blocks) || 777 + valid_blocks == CAP_BLKS_PER_SEC(sbi)); 776 778 777 779 if (!IS_CURSEC(sbi, secno)) 778 780 set_bit(secno, dirty_i->dirty_secmap); ··· 1111 1109 dc->error = 0; 1112 1110 1113 1111 if (dc->error) 1114 - printk_ratelimited( 1115 - "%sF2FS-fs (%s): Issue discard(%u, %u, %u) failed, ret: %d", 1116 - KERN_INFO, sbi->sb->s_id, 1112 + f2fs_info_ratelimited(sbi, 1113 + "Issue discard(%u, %u, %u) failed, ret: %d", 1117 1114 dc->di.lstart, dc->di.start, dc->di.len, dc->error); 1118 1115 __detach_discard_cmd(dcc, dc); 1119 1116 } ··· 2646 2645 } 2647 2646 2648 2647 static int is_next_segment_free(struct f2fs_sb_info *sbi, 2649 - struct curseg_info *curseg, int type) 2648 + struct curseg_info *curseg) 2650 2649 { 2651 2650 unsigned int segno = curseg->segno + 1; 2652 2651 struct free_segmap_info *free_i = FREE_I(sbi); ··· 3074 3073 if (!is_set_ckpt_flags(sbi, CP_CRC_RECOVERY_FLAG) && 3075 3074 curseg->seg_type == CURSEG_WARM_NODE) 3076 3075 return true; 3077 - if (curseg->alloc_type == LFS && 3078 - is_next_segment_free(sbi, curseg, type) && 3076 + if (curseg->alloc_type == LFS && is_next_segment_free(sbi, curseg) && 3079 3077 likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED))) 3080 3078 return true; 3081 3079 if (!f2fs_need_SSR(sbi) || !get_ssr_segment(sbi, type, SSR, 0)) ··· 3352 3352 return err; 3353 3353 } 3354 3354 3355 - int f2fs_rw_hint_to_seg_type(enum rw_hint hint) 3355 + int f2fs_rw_hint_to_seg_type(struct f2fs_sb_info *sbi, enum rw_hint hint) 3356 3356 { 3357 + if (F2FS_OPTION(sbi).active_logs == 2) 3358 + return CURSEG_HOT_DATA; 3359 + else if (F2FS_OPTION(sbi).active_logs == 4) 3360 + return CURSEG_COLD_DATA; 3361 + 3362 + /* active_log == 6 */ 3357 3363 switch (hint) { 3358 3364 case WRITE_LIFE_SHORT: 3359 3365 return CURSEG_HOT_DATA; ··· 3367 3361 return CURSEG_COLD_DATA; 3368 3362 default: 3369 3363 return CURSEG_WARM_DATA; 3364 + } 3365 + } 3366 + 3367 + /* 3368 + * This returns write hints for each segment type. This hints will be 3369 + * passed down to block layer as below by default. 3370 + * 3371 + * User F2FS Block 3372 + * ---- ---- ----- 3373 + * META WRITE_LIFE_NONE|REQ_META 3374 + * HOT_NODE WRITE_LIFE_NONE 3375 + * WARM_NODE WRITE_LIFE_MEDIUM 3376 + * COLD_NODE WRITE_LIFE_LONG 3377 + * ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME 3378 + * extension list " " 3379 + * 3380 + * -- buffered io 3381 + * COLD_DATA WRITE_LIFE_EXTREME 3382 + * HOT_DATA WRITE_LIFE_SHORT 3383 + * WARM_DATA WRITE_LIFE_NOT_SET 3384 + * 3385 + * -- direct io 3386 + * WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME 3387 + * WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT 3388 + * WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET 3389 + * WRITE_LIFE_NONE " WRITE_LIFE_NONE 3390 + * WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM 3391 + * WRITE_LIFE_LONG " WRITE_LIFE_LONG 3392 + */ 3393 + enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi, 3394 + enum page_type type, enum temp_type temp) 3395 + { 3396 + switch (type) { 3397 + case DATA: 3398 + switch (temp) { 3399 + case WARM: 3400 + return WRITE_LIFE_NOT_SET; 3401 + case HOT: 3402 + return WRITE_LIFE_SHORT; 3403 + case COLD: 3404 + return WRITE_LIFE_EXTREME; 3405 + default: 3406 + return WRITE_LIFE_NONE; 3407 + } 3408 + case NODE: 3409 + switch (temp) { 3410 + case WARM: 3411 + return WRITE_LIFE_MEDIUM; 3412 + case HOT: 3413 + return WRITE_LIFE_NONE; 3414 + case COLD: 3415 + return WRITE_LIFE_LONG; 3416 + default: 3417 + return WRITE_LIFE_NONE; 3418 + } 3419 + case META: 3420 + return WRITE_LIFE_NONE; 3421 + default: 3422 + return WRITE_LIFE_NONE; 3370 3423 } 3371 3424 } 3372 3425 ··· 3499 3434 is_inode_flag_set(inode, FI_HOT_DATA) || 3500 3435 f2fs_is_cow_file(inode)) 3501 3436 return CURSEG_HOT_DATA; 3502 - return f2fs_rw_hint_to_seg_type(inode->i_write_hint); 3437 + return f2fs_rw_hint_to_seg_type(F2FS_I_SB(inode), 3438 + inode->i_write_hint); 3503 3439 } else { 3504 3440 if (IS_DNODE(fio->page)) 3505 3441 return is_cold_node(fio->page) ? CURSEG_WARM_NODE : 3506 3442 CURSEG_HOT_NODE; 3507 3443 return CURSEG_COLD_NODE; 3508 3444 } 3445 + } 3446 + 3447 + int f2fs_get_segment_temp(int seg_type) 3448 + { 3449 + if (IS_HOT(seg_type)) 3450 + return HOT; 3451 + else if (IS_WARM(seg_type)) 3452 + return WARM; 3453 + return COLD; 3509 3454 } 3510 3455 3511 3456 static int __get_segment_type(struct f2fs_io_info *fio) ··· 3536 3461 f2fs_bug_on(fio->sbi, true); 3537 3462 } 3538 3463 3539 - if (IS_HOT(type)) 3540 - fio->temp = HOT; 3541 - else if (IS_WARM(type)) 3542 - fio->temp = WARM; 3543 - else 3544 - fio->temp = COLD; 3464 + fio->temp = f2fs_get_segment_temp(type); 3465 + 3545 3466 return type; 3546 3467 } 3547 3468 ··· 3630 3559 if (segment_full) { 3631 3560 if (type == CURSEG_COLD_DATA_PINNED && 3632 3561 !((curseg->segno + 1) % sbi->segs_per_sec)) { 3562 + write_sum_page(sbi, curseg->sum_blk, 3563 + GET_SUM_BLOCK(sbi, curseg->segno)); 3633 3564 reset_curseg_fields(curseg); 3634 3565 goto skip_new_segment; 3635 3566 } ··· 3685 3612 mutex_unlock(&curseg->curseg_mutex); 3686 3613 f2fs_up_read(&SM_I(sbi)->curseg_lock); 3687 3614 return 0; 3615 + 3688 3616 out_err: 3689 3617 *new_blkaddr = NULL_ADDR; 3690 3618 up_write(&sit_i->sentry_lock); 3691 3619 mutex_unlock(&curseg->curseg_mutex); 3692 3620 f2fs_up_read(&SM_I(sbi)->curseg_lock); 3693 3621 return ret; 3694 - 3695 3622 } 3696 3623 3697 3624 void f2fs_update_device_state(struct f2fs_sb_info *sbi, nid_t ino, ··· 3733 3660 &fio->new_blkaddr, sum, type, fio)) { 3734 3661 if (fscrypt_inode_uses_fs_layer_crypto(fio->page->mapping->host)) 3735 3662 fscrypt_finalize_bounce_page(&fio->encrypted_page); 3736 - if (PageWriteback(fio->page)) 3737 - end_page_writeback(fio->page); 3663 + end_page_writeback(fio->page); 3738 3664 if (f2fs_in_warm_node_list(fio->sbi, fio->page)) 3739 3665 f2fs_del_fsync_node_entry(fio->sbi, fio->page); 3740 3666 goto out; ··· 3976 3904 void f2fs_wait_on_page_writeback(struct page *page, 3977 3905 enum page_type type, bool ordered, bool locked) 3978 3906 { 3979 - if (PageWriteback(page)) { 3907 + if (folio_test_writeback(page_folio(page))) { 3980 3908 struct f2fs_sb_info *sbi = F2FS_P_SB(page); 3981 3909 3982 3910 /* submit cached LFS IO */ ··· 3985 3913 f2fs_submit_merged_ipu_write(sbi, NULL, page); 3986 3914 if (ordered) { 3987 3915 wait_on_page_writeback(page); 3988 - f2fs_bug_on(sbi, locked && PageWriteback(page)); 3916 + f2fs_bug_on(sbi, locked && 3917 + folio_test_writeback(page_folio(page))); 3989 3918 } else { 3990 3919 wait_for_stable_page(page); 3991 3920 } ··· 5032 4959 } 5033 4960 5034 4961 #ifdef CONFIG_BLK_DEV_ZONED 5035 - static const char *f2fs_zone_status[BLK_ZONE_COND_OFFLINE + 1] = { 5036 - [BLK_ZONE_COND_NOT_WP] = "NOT_WP", 5037 - [BLK_ZONE_COND_EMPTY] = "EMPTY", 5038 - [BLK_ZONE_COND_IMP_OPEN] = "IMPLICIT_OPEN", 5039 - [BLK_ZONE_COND_EXP_OPEN] = "EXPLICIT_OPEN", 5040 - [BLK_ZONE_COND_CLOSED] = "CLOSED", 5041 - [BLK_ZONE_COND_READONLY] = "READONLY", 5042 - [BLK_ZONE_COND_FULL] = "FULL", 5043 - [BLK_ZONE_COND_OFFLINE] = "OFFLINE", 5044 - }; 5045 - 5046 4962 static int check_zone_write_pointer(struct f2fs_sb_info *sbi, 5047 4963 struct f2fs_dev_info *fdev, 5048 4964 struct blk_zone *zone) ··· 5062 5000 if (IS_CURSEC(sbi, GET_SEC_FROM_SEG(sbi, zone_segno))) { 5063 5001 f2fs_notice(sbi, "Open zones: valid block[0x%x,0x%x] cond[%s]", 5064 5002 zone_segno, valid_block_cnt, 5065 - f2fs_zone_status[zone->cond]); 5003 + blk_zone_cond_str(zone->cond)); 5066 5004 return 0; 5067 5005 } 5068 5006 ··· 5073 5011 if (!valid_block_cnt) { 5074 5012 f2fs_notice(sbi, "Zone without valid block has non-zero write " 5075 5013 "pointer. Reset the write pointer: cond[%s]", 5076 - f2fs_zone_status[zone->cond]); 5014 + blk_zone_cond_str(zone->cond)); 5077 5015 ret = __f2fs_issue_discard_zone(sbi, fdev->bdev, zone_block, 5078 5016 zone->len >> log_sectors_per_block); 5079 5017 if (ret) ··· 5091 5029 */ 5092 5030 f2fs_notice(sbi, "Valid blocks are not aligned with write " 5093 5031 "pointer: valid block[0x%x,0x%x] cond[%s]", 5094 - zone_segno, valid_block_cnt, f2fs_zone_status[zone->cond]); 5032 + zone_segno, valid_block_cnt, blk_zone_cond_str(zone->cond)); 5095 5033 5096 5034 nofs_flags = memalloc_nofs_save(); 5097 5035 ret = blkdev_zone_mgmt(fdev->bdev, REQ_OP_ZONE_FINISH,
+62 -18
fs/f2fs/super.c
··· 66 66 [FAULT_NO_SEGMENT] = "no free segment", 67 67 }; 68 68 69 - void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, 70 - unsigned int type) 69 + int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate, 70 + unsigned long type) 71 71 { 72 72 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; 73 73 74 74 if (rate) { 75 + if (rate > INT_MAX) 76 + return -EINVAL; 75 77 atomic_set(&ffi->inject_ops, 0); 76 - ffi->inject_rate = rate; 78 + ffi->inject_rate = (int)rate; 77 79 } 78 80 79 - if (type) 80 - ffi->inject_type = type; 81 + if (type) { 82 + if (type >= BIT(FAULT_MAX)) 83 + return -EINVAL; 84 + ffi->inject_type = (unsigned int)type; 85 + } 81 86 82 87 if (!rate && !type) 83 88 memset(ffi, 0, sizeof(struct f2fs_fault_info)); 89 + else 90 + f2fs_info(sbi, 91 + "build fault injection attr: rate: %lu, type: 0x%lx", 92 + rate, type); 93 + return 0; 84 94 } 85 95 #endif 86 96 ··· 896 886 case Opt_fault_injection: 897 887 if (args->from && match_int(args, &arg)) 898 888 return -EINVAL; 899 - f2fs_build_fault_attr(sbi, arg, F2FS_ALL_FAULT_TYPE); 889 + if (f2fs_build_fault_attr(sbi, arg, 890 + F2FS_ALL_FAULT_TYPE)) 891 + return -EINVAL; 900 892 set_opt(sbi, FAULT_INJECTION); 901 893 break; 902 894 903 895 case Opt_fault_type: 904 896 if (args->from && match_int(args, &arg)) 905 897 return -EINVAL; 906 - f2fs_build_fault_attr(sbi, 0, arg); 898 + if (f2fs_build_fault_attr(sbi, 0, arg)) 899 + return -EINVAL; 907 900 set_opt(sbi, FAULT_INJECTION); 908 901 break; 909 902 #else ··· 2145 2132 F2FS_OPTION(sbi).memory_mode = MEMORY_MODE_NORMAL; 2146 2133 F2FS_OPTION(sbi).errors = MOUNT_ERRORS_CONTINUE; 2147 2134 2148 - sbi->sb->s_flags &= ~SB_INLINECRYPT; 2149 - 2150 2135 set_opt(sbi, INLINE_XATTR); 2151 2136 set_opt(sbi, INLINE_DATA); 2152 2137 set_opt(sbi, INLINE_DENTRY); ··· 2336 2325 err = parse_options(sb, data, true); 2337 2326 if (err) 2338 2327 goto restore_opts; 2328 + 2329 + #ifdef CONFIG_BLK_DEV_ZONED 2330 + if (f2fs_sb_has_blkzoned(sbi) && 2331 + sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) { 2332 + f2fs_err(sbi, 2333 + "zoned: max open zones %u is too small, need at least %u open zones", 2334 + sbi->max_open_zones, F2FS_OPTION(sbi).active_logs); 2335 + err = -EINVAL; 2336 + goto restore_opts; 2337 + } 2338 + #endif 2339 2339 2340 2340 /* flush outstanding errors before changing fs state */ 2341 2341 flush_work(&sbi->s_error_work); ··· 2567 2545 sbi->mount_opt = org_mount_opt; 2568 2546 sb->s_flags = old_sb_flags; 2569 2547 return err; 2548 + } 2549 + 2550 + static void f2fs_shutdown(struct super_block *sb) 2551 + { 2552 + f2fs_do_shutdown(F2FS_SB(sb), F2FS_GOING_DOWN_NOSYNC, false); 2570 2553 } 2571 2554 2572 2555 #ifdef CONFIG_QUOTA ··· 3173 3146 .unfreeze_fs = f2fs_unfreeze, 3174 3147 .statfs = f2fs_statfs, 3175 3148 .remount_fs = f2fs_remount, 3149 + .shutdown = f2fs_shutdown, 3176 3150 }; 3177 3151 3178 3152 #ifdef CONFIG_FS_ENCRYPTION ··· 3469 3441 } 3470 3442 } 3471 3443 3472 - /* Currently, support only 4KB block size */ 3444 + /* only support block_size equals to PAGE_SIZE */ 3473 3445 if (le32_to_cpu(raw_super->log_blocksize) != F2FS_BLKSIZE_BITS) { 3474 3446 f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u", 3475 3447 le32_to_cpu(raw_super->log_blocksize), ··· 3890 3862 sector_t nr_sectors = bdev_nr_sectors(bdev); 3891 3863 struct f2fs_report_zones_args rep_zone_arg; 3892 3864 u64 zone_sectors; 3865 + unsigned int max_open_zones; 3893 3866 int ret; 3894 3867 3895 3868 if (!f2fs_sb_has_blkzoned(sbi)) 3896 3869 return 0; 3870 + 3871 + if (bdev_is_zoned(FDEV(devi).bdev)) { 3872 + max_open_zones = bdev_max_open_zones(bdev); 3873 + if (max_open_zones && (max_open_zones < sbi->max_open_zones)) 3874 + sbi->max_open_zones = max_open_zones; 3875 + if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) { 3876 + f2fs_err(sbi, 3877 + "zoned: max open zones %u is too small, need at least %u open zones", 3878 + sbi->max_open_zones, F2FS_OPTION(sbi).active_logs); 3879 + return -EINVAL; 3880 + } 3881 + } 3897 3882 3898 3883 zone_sectors = bdev_zone_sectors(bdev); 3899 3884 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != ··· 4172 4131 if (shutdown) 4173 4132 set_sbi_flag(sbi, SBI_IS_SHUTDOWN); 4174 4133 4175 - /* continue filesystem operators if errors=continue */ 4176 - if (continue_fs || f2fs_readonly(sb)) 4134 + /* 4135 + * Continue filesystem operators if errors=continue. Should not set 4136 + * RO by shutdown, since RO bypasses thaw_super which can hang the 4137 + * system. 4138 + */ 4139 + if (continue_fs || f2fs_readonly(sb) || shutdown) { 4140 + f2fs_warn(sbi, "Stopped filesystem due to reason: %d", reason); 4177 4141 return; 4142 + } 4178 4143 4179 4144 f2fs_warn(sbi, "Remounting filesystem read-only"); 4180 4145 /* ··· 4227 4180 4228 4181 logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev); 4229 4182 sbi->aligned_blksize = true; 4183 + #ifdef CONFIG_BLK_DEV_ZONED 4184 + sbi->max_open_zones = UINT_MAX; 4185 + #endif 4230 4186 4231 4187 for (i = 0; i < max_devices; i++) { 4232 4188 if (i == 0) ··· 4943 4893 static int __init init_f2fs_fs(void) 4944 4894 { 4945 4895 int err; 4946 - 4947 - if (PAGE_SIZE != F2FS_BLKSIZE) { 4948 - printk("F2FS not supported on PAGE_SIZE(%lu) != BLOCK_SIZE(%lu)\n", 4949 - PAGE_SIZE, F2FS_BLKSIZE); 4950 - return -EINVAL; 4951 - } 4952 4896 4953 4897 err = init_inodecache(); 4954 4898 if (err)
+17 -4
fs/f2fs/sysfs.c
··· 484 484 if (ret < 0) 485 485 return ret; 486 486 #ifdef CONFIG_F2FS_FAULT_INJECTION 487 - if (a->struct_type == FAULT_INFO_TYPE && t >= BIT(FAULT_MAX)) 488 - return -EINVAL; 489 - if (a->struct_type == FAULT_INFO_RATE && t >= UINT_MAX) 490 - return -EINVAL; 487 + if (a->struct_type == FAULT_INFO_TYPE) { 488 + if (f2fs_build_fault_attr(sbi, 0, t)) 489 + return -EINVAL; 490 + return count; 491 + } 492 + if (a->struct_type == FAULT_INFO_RATE) { 493 + if (f2fs_build_fault_attr(sbi, t, 0)) 494 + return -EINVAL; 495 + return count; 496 + } 491 497 #endif 492 498 if (a->struct_type == RESERVED_BLOCKS) { 493 499 spin_lock(&sbi->stat_lock); ··· 678 672 sbi->gc_segment_mode = t; 679 673 else 680 674 return -EINVAL; 675 + return count; 676 + } 677 + 678 + if (!strcmp(a->attr.name, "gc_pin_file_threshold")) { 679 + if (t > MAX_GC_FAILED_PINNED_FILES) 680 + return -EINVAL; 681 + sbi->gc_pin_file_threshold = t; 681 682 return count; 682 683 } 683 684
+7 -3
include/linux/f2fs_fs.h
··· 394 394 395 395 /* 396 396 * F2FS uses 4 bytes to represent block address. As a result, supported size of 397 - * disk is 16 TB and it equals to 16 * 1024 * 1024 / 2 segments. 397 + * disk is 16 TB for a 4K page size and 64 TB for a 16K page size and it equals 398 + * to 16 * 1024 * 1024 / 2 segments. 398 399 */ 399 400 #define F2FS_MAX_SEGMENT ((16 * 1024 * 1024) / 2) 400 401 ··· 425 424 /* 426 425 * For segment summary 427 426 * 428 - * One summary block contains exactly 512 summary entries, which represents 429 - * exactly one segment by default. Not allow to change the basic units. 427 + * One summary block with 4KB size contains exactly 512 summary entries, which 428 + * represents exactly one segment with 2MB size. 429 + * Similarly, in the case of block with 16KB size, it represents one segment with 8MB size. 430 + * Not allow to change the basic units. 430 431 * 431 432 * NOTE: For initializing fields, you must use set_summary 432 433 * ··· 559 556 560 557 /* 561 558 * space utilization of regular dentry and inline dentry (w/o extra reservation) 559 + * when block size is 4KB. 562 560 * regular dentry inline dentry (def) inline dentry (min) 563 561 * bitmap 1 * 27 = 27 1 * 23 = 23 1 * 1 = 1 564 562 * reserved 1 * 3 = 3 1 * 7 = 7 1 * 1 = 1
+21 -21
include/trace/events/f2fs.h
··· 1304 1304 __entry->copied) 1305 1305 ); 1306 1306 1307 - DECLARE_EVENT_CLASS(f2fs__page, 1307 + DECLARE_EVENT_CLASS(f2fs__folio, 1308 1308 1309 - TP_PROTO(struct page *page, int type), 1309 + TP_PROTO(struct folio *folio, int type), 1310 1310 1311 - TP_ARGS(page, type), 1311 + TP_ARGS(folio, type), 1312 1312 1313 1313 TP_STRUCT__entry( 1314 1314 __field(dev_t, dev) ··· 1321 1321 ), 1322 1322 1323 1323 TP_fast_assign( 1324 - __entry->dev = page_file_mapping(page)->host->i_sb->s_dev; 1325 - __entry->ino = page_file_mapping(page)->host->i_ino; 1324 + __entry->dev = folio_file_mapping(folio)->host->i_sb->s_dev; 1325 + __entry->ino = folio_file_mapping(folio)->host->i_ino; 1326 1326 __entry->type = type; 1327 1327 __entry->dir = 1328 - S_ISDIR(page_file_mapping(page)->host->i_mode); 1329 - __entry->index = page->index; 1330 - __entry->dirty = PageDirty(page); 1331 - __entry->uptodate = PageUptodate(page); 1328 + S_ISDIR(folio_file_mapping(folio)->host->i_mode); 1329 + __entry->index = folio_index(folio); 1330 + __entry->dirty = folio_test_dirty(folio); 1331 + __entry->uptodate = folio_test_uptodate(folio); 1332 1332 ), 1333 1333 1334 1334 TP_printk("dev = (%d,%d), ino = %lu, %s, %s, index = %lu, " ··· 1341 1341 __entry->uptodate) 1342 1342 ); 1343 1343 1344 - DEFINE_EVENT(f2fs__page, f2fs_writepage, 1344 + DEFINE_EVENT(f2fs__folio, f2fs_writepage, 1345 1345 1346 - TP_PROTO(struct page *page, int type), 1346 + TP_PROTO(struct folio *folio, int type), 1347 1347 1348 - TP_ARGS(page, type) 1348 + TP_ARGS(folio, type) 1349 1349 ); 1350 1350 1351 - DEFINE_EVENT(f2fs__page, f2fs_do_write_data_page, 1351 + DEFINE_EVENT(f2fs__folio, f2fs_do_write_data_page, 1352 1352 1353 - TP_PROTO(struct page *page, int type), 1353 + TP_PROTO(struct folio *folio, int type), 1354 1354 1355 - TP_ARGS(page, type) 1355 + TP_ARGS(folio, type) 1356 1356 ); 1357 1357 1358 - DEFINE_EVENT(f2fs__page, f2fs_readpage, 1358 + DEFINE_EVENT(f2fs__folio, f2fs_readpage, 1359 1359 1360 - TP_PROTO(struct page *page, int type), 1360 + TP_PROTO(struct folio *folio, int type), 1361 1361 1362 - TP_ARGS(page, type) 1362 + TP_ARGS(folio, type) 1363 1363 ); 1364 1364 1365 - DEFINE_EVENT(f2fs__page, f2fs_set_page_dirty, 1365 + DEFINE_EVENT(f2fs__folio, f2fs_set_page_dirty, 1366 1366 1367 - TP_PROTO(struct page *page, int type), 1367 + TP_PROTO(struct folio *folio, int type), 1368 1368 1369 - TP_ARGS(page, type) 1369 + TP_ARGS(folio, type) 1370 1370 ); 1371 1371 1372 1372 TRACE_EVENT(f2fs_replace_atomic_write_block,