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

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

Pull f2fs updates from Jaegeuk Kim:
"In this round, we've mainly focused on fixing bugs and addressing
issues in recently introduced compression support.

Enhancement:
- add zstd support, and set LZ4 by default
- add ioctl() to show # of compressed blocks
- show mount time in debugfs
- replace rwsem with spinlock
- avoid lock contention in DIO reads

Some major bug fixes wrt compression:
- compressed block count
- memory access and leak
- remove obsolete fields
- flag controls

Other bug fixes and clean ups:
- fix overflow when handling .flags in inode_info
- fix SPO issue during resize FS flow
- fix compression with fsverity enabled
- potential deadlock when writing compressed pages
- show missing mount options"

* tag 'f2fs-for-5.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (66 commits)
f2fs: keep inline_data when compression conversion
f2fs: fix to disable compression on directory
f2fs: add missing CONFIG_F2FS_FS_COMPRESSION
f2fs: switch discard_policy.timeout to bool type
f2fs: fix to verify tpage before releasing in f2fs_free_dic()
f2fs: show compression in statx
f2fs: clean up dic->tpages assignment
f2fs: compress: support zstd compress algorithm
f2fs: compress: add .{init,destroy}_decompress_ctx callback
f2fs: compress: fix to call missing destroy_compress_ctx()
f2fs: change default compression algorithm
f2fs: clean up {cic,dic}.ref handling
f2fs: fix to use f2fs_readpage_limit() in f2fs_read_multi_pages()
f2fs: xattr.h: Make stub helpers inline
f2fs: fix to avoid double unlock
f2fs: fix potential .flags overflow on 32bit architecture
f2fs: fix NULL pointer dereference in f2fs_verity_work()
f2fs: fix to clear PG_error if fsverity failed
f2fs: don't call fscrypt_get_encryption_info() explicitly in f2fs_tmpfile()
f2fs: don't trigger data flush in foreground operation
...

+821 -429
+5
Documentation/ABI/testing/sysfs-fs-f2fs
··· 318 318 Contact: "Hridya Valsaraju" <hridya@google.com> 319 319 Description: Average number of valid blocks. 320 320 Available when CONFIG_F2FS_STAT_FS=y. 321 + 322 + What: /sys/fs/f2fs/<disk>/mounted_time_sec 323 + Date: February 2020 324 + Contact: "Jaegeuk Kim" <jaegeuk@kernel.org> 325 + Description: Show the mounted time in secs of this partition.
+2 -2
Documentation/filesystems/f2fs.rst
··· 243 243 hide up to all remaining free space. The actual space that 244 244 would be unusable can be viewed at /sys/fs/f2fs/<disk>/unusable 245 245 This space is reclaimed once checkpoint=enable. 246 - compress_algorithm=%s Control compress algorithm, currently f2fs supports "lzo" 247 - and "lz4" algorithm. 246 + compress_algorithm=%s Control compress algorithm, currently f2fs supports "lzo", 247 + "lz4" and "zstd" algorithm. 248 248 compress_log_size=%u Support configuring compress cluster size, the size will 249 249 be 4KB * (1 << %u), 16KB is minimum size, also it's 250 250 default size.
+9
fs/f2fs/Kconfig
··· 118 118 default y 119 119 help 120 120 Support LZ4 compress algorithm, if unsure, say Y. 121 + 122 + config F2FS_FS_ZSTD 123 + bool "ZSTD compression support" 124 + depends on F2FS_FS_COMPRESSION 125 + select ZSTD_COMPRESS 126 + select ZSTD_DECOMPRESS 127 + default y 128 + help 129 + Support ZSTD compress algorithm, if unsure, say Y.
+17 -25
fs/f2fs/checkpoint.c
··· 50 50 return page; 51 51 } 52 52 53 - /* 54 - * We guarantee no failure on the returned page. 55 - */ 56 53 static struct page *__get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index, 57 54 bool is_meta) 58 55 { ··· 203 206 } 204 207 205 208 /* 206 - * Readahead CP/NAT/SIT/SSA pages 209 + * Readahead CP/NAT/SIT/SSA/POR pages 207 210 */ 208 211 int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 209 212 int type, bool sync) ··· 895 898 return -ENOMEM; 896 899 /* 897 900 * Finding out valid cp block involves read both 898 - * sets( cp pack1 and cp pack 2) 901 + * sets( cp pack 1 and cp pack 2) 899 902 */ 900 903 cp_start_blk_no = le32_to_cpu(fsb->cp_blkaddr); 901 904 cp1 = validate_checkpoint(sbi, cp_start_blk_no, &cp1_version); ··· 1247 1250 f2fs_unlock_all(sbi); 1248 1251 } 1249 1252 1250 - void f2fs_wait_on_all_pages_writeback(struct f2fs_sb_info *sbi) 1253 + void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type) 1251 1254 { 1252 1255 DEFINE_WAIT(wait); 1253 1256 1254 1257 for (;;) { 1255 1258 prepare_to_wait(&sbi->cp_wait, &wait, TASK_UNINTERRUPTIBLE); 1256 1259 1257 - if (!get_pages(sbi, F2FS_WB_CP_DATA)) 1260 + if (!get_pages(sbi, type)) 1258 1261 break; 1259 1262 1260 1263 if (unlikely(f2fs_cp_error(sbi))) 1261 1264 break; 1262 1265 1263 - io_schedule_timeout(5*HZ); 1266 + io_schedule_timeout(DEFAULT_IO_TIMEOUT); 1264 1267 } 1265 1268 finish_wait(&sbi->cp_wait, &wait); 1266 1269 } ··· 1298 1301 else 1299 1302 __clear_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG); 1300 1303 1301 - if (is_sbi_flag_set(sbi, SBI_NEED_FSCK) || 1302 - is_sbi_flag_set(sbi, SBI_IS_RESIZEFS)) 1304 + if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) 1303 1305 __set_ckpt_flags(ckpt, CP_FSCK_FLAG); 1306 + 1307 + if (is_sbi_flag_set(sbi, SBI_IS_RESIZEFS)) 1308 + __set_ckpt_flags(ckpt, CP_RESIZEFS_FLAG); 1309 + else 1310 + __clear_ckpt_flags(ckpt, CP_RESIZEFS_FLAG); 1304 1311 1305 1312 if (is_sbi_flag_set(sbi, SBI_CP_DISABLED)) 1306 1313 __set_ckpt_flags(ckpt, CP_DISABLED_FLAG); ··· 1385 1384 1386 1385 /* Flush all the NAT/SIT pages */ 1387 1386 f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO); 1388 - f2fs_bug_on(sbi, get_pages(sbi, F2FS_DIRTY_META) && 1389 - !f2fs_cp_error(sbi)); 1390 1387 1391 - /* 1392 - * modify checkpoint 1393 - * version number is already updated 1394 - */ 1388 + /* start to update checkpoint, cp ver is already updated previously */ 1395 1389 ckpt->elapsed_time = cpu_to_le64(get_mtime(sbi, true)); 1396 1390 ckpt->free_segment_count = cpu_to_le32(free_segments(sbi)); 1397 1391 for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) { ··· 1489 1493 1490 1494 /* Here, we have one bio having CP pack except cp pack 2 page */ 1491 1495 f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO); 1492 - f2fs_bug_on(sbi, get_pages(sbi, F2FS_DIRTY_META) && 1493 - !f2fs_cp_error(sbi)); 1496 + /* Wait for all dirty meta pages to be submitted for IO */ 1497 + f2fs_wait_on_all_pages(sbi, F2FS_DIRTY_META); 1494 1498 1495 1499 /* wait for previous submitted meta pages writeback */ 1496 - f2fs_wait_on_all_pages_writeback(sbi); 1500 + f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA); 1497 1501 1498 1502 /* flush all device cache */ 1499 1503 err = f2fs_flush_device_cache(sbi); ··· 1502 1506 1503 1507 /* barrier and flush checkpoint cp pack 2 page if it can */ 1504 1508 commit_checkpoint(sbi, ckpt, start_blk); 1505 - f2fs_wait_on_all_pages_writeback(sbi); 1509 + f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA); 1506 1510 1507 1511 /* 1508 1512 * invalidate intermediate page cache borrowed from meta inode which are ··· 1539 1543 return unlikely(f2fs_cp_error(sbi)) ? -EIO : 0; 1540 1544 } 1541 1545 1542 - /* 1543 - * We guarantee that this checkpoint procedure will not fail. 1544 - */ 1545 1546 int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) 1546 1547 { 1547 1548 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); ··· 1606 1613 1607 1614 f2fs_flush_sit_entries(sbi, cpc); 1608 1615 1609 - /* unlock all the fs_lock[] in do_checkpoint() */ 1610 1616 err = do_checkpoint(sbi, cpc); 1611 1617 if (err) 1612 1618 f2fs_release_discard_addrs(sbi); ··· 1618 1626 if (cpc->reason & CP_RECOVERY) 1619 1627 f2fs_notice(sbi, "checkpoint: version = %llx", ckpt_ver); 1620 1628 1621 - /* do checkpoint periodically */ 1629 + /* update CP_TIME to trigger checkpoint periodically */ 1622 1630 f2fs_update_time(sbi, CP_TIME); 1623 1631 trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish checkpoint"); 1624 1632 out:
+261 -56
fs/f2fs/compress.c
··· 11 11 #include <linux/backing-dev.h> 12 12 #include <linux/lzo.h> 13 13 #include <linux/lz4.h> 14 + #include <linux/zstd.h> 14 15 15 16 #include "f2fs.h" 16 17 #include "node.h" ··· 21 20 int (*init_compress_ctx)(struct compress_ctx *cc); 22 21 void (*destroy_compress_ctx)(struct compress_ctx *cc); 23 22 int (*compress_pages)(struct compress_ctx *cc); 23 + int (*init_decompress_ctx)(struct decompress_io_ctx *dic); 24 + void (*destroy_decompress_ctx)(struct decompress_io_ctx *dic); 24 25 int (*decompress_pages)(struct decompress_io_ctx *dic); 25 26 }; 26 27 ··· 55 52 } 56 53 57 54 static void f2fs_set_compressed_page(struct page *page, 58 - struct inode *inode, pgoff_t index, void *data, refcount_t *r) 55 + struct inode *inode, pgoff_t index, void *data) 59 56 { 60 57 SetPagePrivate(page); 61 58 set_page_private(page, (unsigned long)data); ··· 63 60 /* i_crypto_info and iv index */ 64 61 page->index = index; 65 62 page->mapping = inode->i_mapping; 66 - if (r) 67 - refcount_inc(r); 68 63 } 69 64 70 65 static void f2fs_put_compressed_page(struct page *page) ··· 292 291 }; 293 292 #endif 294 293 294 + #ifdef CONFIG_F2FS_FS_ZSTD 295 + #define F2FS_ZSTD_DEFAULT_CLEVEL 1 296 + 297 + static int zstd_init_compress_ctx(struct compress_ctx *cc) 298 + { 299 + ZSTD_parameters params; 300 + ZSTD_CStream *stream; 301 + void *workspace; 302 + unsigned int workspace_size; 303 + 304 + params = ZSTD_getParams(F2FS_ZSTD_DEFAULT_CLEVEL, cc->rlen, 0); 305 + workspace_size = ZSTD_CStreamWorkspaceBound(params.cParams); 306 + 307 + workspace = f2fs_kvmalloc(F2FS_I_SB(cc->inode), 308 + workspace_size, GFP_NOFS); 309 + if (!workspace) 310 + return -ENOMEM; 311 + 312 + stream = ZSTD_initCStream(params, 0, workspace, workspace_size); 313 + if (!stream) { 314 + printk_ratelimited("%sF2FS-fs (%s): %s ZSTD_initCStream failed\n", 315 + KERN_ERR, F2FS_I_SB(cc->inode)->sb->s_id, 316 + __func__); 317 + kvfree(workspace); 318 + return -EIO; 319 + } 320 + 321 + cc->private = workspace; 322 + cc->private2 = stream; 323 + 324 + cc->clen = cc->rlen - PAGE_SIZE - COMPRESS_HEADER_SIZE; 325 + return 0; 326 + } 327 + 328 + static void zstd_destroy_compress_ctx(struct compress_ctx *cc) 329 + { 330 + kvfree(cc->private); 331 + cc->private = NULL; 332 + cc->private2 = NULL; 333 + } 334 + 335 + static int zstd_compress_pages(struct compress_ctx *cc) 336 + { 337 + ZSTD_CStream *stream = cc->private2; 338 + ZSTD_inBuffer inbuf; 339 + ZSTD_outBuffer outbuf; 340 + int src_size = cc->rlen; 341 + int dst_size = src_size - PAGE_SIZE - COMPRESS_HEADER_SIZE; 342 + int ret; 343 + 344 + inbuf.pos = 0; 345 + inbuf.src = cc->rbuf; 346 + inbuf.size = src_size; 347 + 348 + outbuf.pos = 0; 349 + outbuf.dst = cc->cbuf->cdata; 350 + outbuf.size = dst_size; 351 + 352 + ret = ZSTD_compressStream(stream, &outbuf, &inbuf); 353 + if (ZSTD_isError(ret)) { 354 + printk_ratelimited("%sF2FS-fs (%s): %s ZSTD_compressStream failed, ret: %d\n", 355 + KERN_ERR, F2FS_I_SB(cc->inode)->sb->s_id, 356 + __func__, ZSTD_getErrorCode(ret)); 357 + return -EIO; 358 + } 359 + 360 + ret = ZSTD_endStream(stream, &outbuf); 361 + if (ZSTD_isError(ret)) { 362 + printk_ratelimited("%sF2FS-fs (%s): %s ZSTD_endStream returned %d\n", 363 + KERN_ERR, F2FS_I_SB(cc->inode)->sb->s_id, 364 + __func__, ZSTD_getErrorCode(ret)); 365 + return -EIO; 366 + } 367 + 368 + cc->clen = outbuf.pos; 369 + return 0; 370 + } 371 + 372 + static int zstd_init_decompress_ctx(struct decompress_io_ctx *dic) 373 + { 374 + ZSTD_DStream *stream; 375 + void *workspace; 376 + unsigned int workspace_size; 377 + 378 + workspace_size = ZSTD_DStreamWorkspaceBound(MAX_COMPRESS_WINDOW_SIZE); 379 + 380 + workspace = f2fs_kvmalloc(F2FS_I_SB(dic->inode), 381 + workspace_size, GFP_NOFS); 382 + if (!workspace) 383 + return -ENOMEM; 384 + 385 + stream = ZSTD_initDStream(MAX_COMPRESS_WINDOW_SIZE, 386 + workspace, workspace_size); 387 + if (!stream) { 388 + printk_ratelimited("%sF2FS-fs (%s): %s ZSTD_initDStream failed\n", 389 + KERN_ERR, F2FS_I_SB(dic->inode)->sb->s_id, 390 + __func__); 391 + kvfree(workspace); 392 + return -EIO; 393 + } 394 + 395 + dic->private = workspace; 396 + dic->private2 = stream; 397 + 398 + return 0; 399 + } 400 + 401 + static void zstd_destroy_decompress_ctx(struct decompress_io_ctx *dic) 402 + { 403 + kvfree(dic->private); 404 + dic->private = NULL; 405 + dic->private2 = NULL; 406 + } 407 + 408 + static int zstd_decompress_pages(struct decompress_io_ctx *dic) 409 + { 410 + ZSTD_DStream *stream = dic->private2; 411 + ZSTD_inBuffer inbuf; 412 + ZSTD_outBuffer outbuf; 413 + int ret; 414 + 415 + inbuf.pos = 0; 416 + inbuf.src = dic->cbuf->cdata; 417 + inbuf.size = dic->clen; 418 + 419 + outbuf.pos = 0; 420 + outbuf.dst = dic->rbuf; 421 + outbuf.size = dic->rlen; 422 + 423 + ret = ZSTD_decompressStream(stream, &outbuf, &inbuf); 424 + if (ZSTD_isError(ret)) { 425 + printk_ratelimited("%sF2FS-fs (%s): %s ZSTD_compressStream failed, ret: %d\n", 426 + KERN_ERR, F2FS_I_SB(dic->inode)->sb->s_id, 427 + __func__, ZSTD_getErrorCode(ret)); 428 + return -EIO; 429 + } 430 + 431 + if (dic->rlen != outbuf.pos) { 432 + printk_ratelimited("%sF2FS-fs (%s): %s ZSTD invalid rlen:%zu, " 433 + "expected:%lu\n", KERN_ERR, 434 + F2FS_I_SB(dic->inode)->sb->s_id, 435 + __func__, dic->rlen, 436 + PAGE_SIZE << dic->log_cluster_size); 437 + return -EIO; 438 + } 439 + 440 + return 0; 441 + } 442 + 443 + static const struct f2fs_compress_ops f2fs_zstd_ops = { 444 + .init_compress_ctx = zstd_init_compress_ctx, 445 + .destroy_compress_ctx = zstd_destroy_compress_ctx, 446 + .compress_pages = zstd_compress_pages, 447 + .init_decompress_ctx = zstd_init_decompress_ctx, 448 + .destroy_decompress_ctx = zstd_destroy_decompress_ctx, 449 + .decompress_pages = zstd_decompress_pages, 450 + }; 451 + #endif 452 + 295 453 static const struct f2fs_compress_ops *f2fs_cops[COMPRESS_MAX] = { 296 454 #ifdef CONFIG_F2FS_FS_LZO 297 455 &f2fs_lzo_ops, ··· 459 299 #endif 460 300 #ifdef CONFIG_F2FS_FS_LZ4 461 301 &f2fs_lz4_ops, 302 + #else 303 + NULL, 304 + #endif 305 + #ifdef CONFIG_F2FS_FS_ZSTD 306 + &f2fs_zstd_ops, 462 307 #else 463 308 NULL, 464 309 #endif ··· 499 334 trace_f2fs_compress_pages_start(cc->inode, cc->cluster_idx, 500 335 cc->cluster_size, fi->i_compress_algorithm); 501 336 502 - ret = cops->init_compress_ctx(cc); 503 - if (ret) 504 - goto out; 337 + if (cops->init_compress_ctx) { 338 + ret = cops->init_compress_ctx(cc); 339 + if (ret) 340 + goto out; 341 + } 505 342 506 343 max_len = COMPRESS_HEADER_SIZE + cc->clen; 507 344 cc->nr_cpages = DIV_ROUND_UP(max_len, PAGE_SIZE); ··· 547 380 } 548 381 549 382 cc->cbuf->clen = cpu_to_le32(cc->clen); 550 - cc->cbuf->chksum = cpu_to_le32(0); 551 383 552 384 for (i = 0; i < COMPRESS_DATA_RESERVED_SIZE; i++) 553 385 cc->cbuf->reserved[i] = cpu_to_le32(0); 554 386 387 + nr_cpages = DIV_ROUND_UP(cc->clen + COMPRESS_HEADER_SIZE, PAGE_SIZE); 388 + 389 + /* zero out any unused part of the last page */ 390 + memset(&cc->cbuf->cdata[cc->clen], 0, 391 + (nr_cpages * PAGE_SIZE) - (cc->clen + COMPRESS_HEADER_SIZE)); 392 + 555 393 vunmap(cc->cbuf); 556 394 vunmap(cc->rbuf); 557 - 558 - nr_cpages = DIV_ROUND_UP(cc->clen + COMPRESS_HEADER_SIZE, PAGE_SIZE); 559 395 560 396 for (i = nr_cpages; i < cc->nr_cpages; i++) { 561 397 f2fs_put_compressed_page(cc->cpages[i]); 562 398 cc->cpages[i] = NULL; 563 399 } 400 + 401 + if (cops->destroy_compress_ctx) 402 + cops->destroy_compress_ctx(cc); 564 403 565 404 cc->nr_cpages = nr_cpages; 566 405 ··· 586 413 kfree(cc->cpages); 587 414 cc->cpages = NULL; 588 415 destroy_compress_ctx: 589 - cops->destroy_compress_ctx(cc); 416 + if (cops->destroy_compress_ctx) 417 + cops->destroy_compress_ctx(cc); 590 418 out: 591 419 trace_f2fs_compress_pages_end(cc->inode, cc->cluster_idx, 592 420 cc->clen, ret); ··· 621 447 goto out_free_dic; 622 448 } 623 449 450 + if (cops->init_decompress_ctx) { 451 + ret = cops->init_decompress_ctx(dic); 452 + if (ret) 453 + goto out_free_dic; 454 + } 455 + 624 456 dic->rbuf = vmap(dic->tpages, dic->cluster_size, VM_MAP, PAGE_KERNEL); 625 457 if (!dic->rbuf) { 626 458 ret = -ENOMEM; 627 - goto out_free_dic; 459 + goto destroy_decompress_ctx; 628 460 } 629 461 630 462 dic->cbuf = vmap(dic->cpages, dic->nr_cpages, VM_MAP, PAGE_KERNEL_RO); ··· 653 473 vunmap(dic->cbuf); 654 474 out_vunmap_rbuf: 655 475 vunmap(dic->rbuf); 476 + destroy_decompress_ctx: 477 + if (cops->destroy_decompress_ctx) 478 + cops->destroy_decompress_ctx(dic); 656 479 out_free_dic: 480 + if (verity) 481 + refcount_set(&dic->ref, dic->nr_cpages); 657 482 if (!verity) 658 483 f2fs_decompress_end_io(dic->rpages, dic->cluster_size, 659 484 ret, false); ··· 717 532 return true; 718 533 } 719 534 720 - /* return # of compressed block addresses */ 721 - static int f2fs_compressed_blocks(struct compress_ctx *cc) 535 + static int __f2fs_cluster_blocks(struct compress_ctx *cc, bool compr) 722 536 { 723 537 struct dnode_of_data dn; 724 538 int ret; ··· 738 554 for (i = 1; i < cc->cluster_size; i++) { 739 555 block_t blkaddr; 740 556 741 - blkaddr = datablock_addr(dn.inode, 557 + blkaddr = data_blkaddr(dn.inode, 742 558 dn.node_page, dn.ofs_in_node + i); 743 - if (blkaddr != NULL_ADDR) 744 - ret++; 559 + if (compr) { 560 + if (__is_valid_data_blkaddr(blkaddr)) 561 + ret++; 562 + } else { 563 + if (blkaddr != NULL_ADDR) 564 + ret++; 565 + } 745 566 } 746 567 } 747 568 fail: 748 569 f2fs_put_dnode(&dn); 749 570 return ret; 571 + } 572 + 573 + /* return # of compressed blocks in compressed cluster */ 574 + static int f2fs_compressed_blocks(struct compress_ctx *cc) 575 + { 576 + return __f2fs_cluster_blocks(cc, true); 577 + } 578 + 579 + /* return # of valid blocks in compressed cluster */ 580 + static int f2fs_cluster_blocks(struct compress_ctx *cc, bool compr) 581 + { 582 + return __f2fs_cluster_blocks(cc, false); 750 583 } 751 584 752 585 int f2fs_is_compressed_cluster(struct inode *inode, pgoff_t index) ··· 775 574 .cluster_idx = index >> F2FS_I(inode)->i_log_cluster_size, 776 575 }; 777 576 778 - return f2fs_compressed_blocks(&cc); 577 + return f2fs_cluster_blocks(&cc, false); 779 578 } 780 579 781 580 static bool cluster_may_compress(struct compress_ctx *cc) ··· 824 623 bool prealloc; 825 624 826 625 retry: 827 - ret = f2fs_compressed_blocks(cc); 626 + ret = f2fs_cluster_blocks(cc, false); 828 627 if (ret <= 0) 829 628 return ret; 830 629 ··· 854 653 struct bio *bio = NULL; 855 654 856 655 ret = f2fs_read_multi_pages(cc, &bio, cc->cluster_size, 857 - &last_block_in_bio, false); 656 + &last_block_in_bio, false, true); 858 657 f2fs_destroy_compress_ctx(cc); 859 658 if (ret) 860 659 goto release_pages; ··· 973 772 .encrypted_page = NULL, 974 773 .compressed_page = NULL, 975 774 .submitted = false, 976 - .need_lock = LOCK_RETRY, 977 775 .io_type = io_type, 978 776 .io_wbc = wbc, 979 777 .encrypted = f2fs_encrypted_file(cc->inode), ··· 985 785 loff_t psize; 986 786 int i, err; 987 787 988 - set_new_dnode(&dn, cc->inode, NULL, NULL, 0); 788 + if (!f2fs_trylock_op(sbi)) 789 + return -EAGAIN; 989 790 990 - f2fs_lock_op(sbi); 791 + set_new_dnode(&dn, cc->inode, NULL, NULL, 0); 991 792 992 793 err = f2fs_get_dnode_of_data(&dn, start_idx, LOOKUP_NODE); 993 794 if (err) 994 795 goto out_unlock_op; 995 796 996 797 for (i = 0; i < cc->cluster_size; i++) { 997 - if (datablock_addr(dn.inode, dn.node_page, 798 + if (data_blkaddr(dn.inode, dn.node_page, 998 799 dn.ofs_in_node + i) == NULL_ADDR) 999 800 goto out_put_dnode; 1000 801 } ··· 1014 813 1015 814 cic->magic = F2FS_COMPRESSED_PAGE_MAGIC; 1016 815 cic->inode = inode; 1017 - refcount_set(&cic->ref, 1); 816 + refcount_set(&cic->ref, cc->nr_cpages); 1018 817 cic->rpages = f2fs_kzalloc(sbi, sizeof(struct page *) << 1019 818 cc->log_cluster_size, GFP_NOFS); 1020 819 if (!cic->rpages) ··· 1024 823 1025 824 for (i = 0; i < cc->nr_cpages; i++) { 1026 825 f2fs_set_compressed_page(cc->cpages[i], inode, 1027 - cc->rpages[i + 1]->index, 1028 - cic, i ? &cic->ref : NULL); 826 + cc->rpages[i + 1]->index, cic); 1029 827 fio.compressed_page = cc->cpages[i]; 1030 828 if (fio.encrypted) { 1031 829 fio.page = cc->rpages[i + 1]; ··· 1043 843 for (i = 0; i < cc->cluster_size; i++, dn.ofs_in_node++) { 1044 844 block_t blkaddr; 1045 845 1046 - blkaddr = datablock_addr(dn.inode, dn.node_page, 1047 - dn.ofs_in_node); 1048 - fio.page = cic->rpages[i]; 846 + blkaddr = f2fs_data_blkaddr(&dn); 847 + fio.page = cc->rpages[i]; 1049 848 fio.old_blkaddr = blkaddr; 1050 849 1051 850 /* cluster header */ ··· 1094 895 f2fs_put_dnode(&dn); 1095 896 f2fs_unlock_op(sbi); 1096 897 1097 - down_write(&fi->i_sem); 898 + spin_lock(&fi->i_size_lock); 1098 899 if (fi->last_disk_size < psize) 1099 900 fi->last_disk_size = psize; 1100 - up_write(&fi->i_sem); 901 + spin_unlock(&fi->i_size_lock); 1101 902 1102 903 f2fs_put_rpages(cc); 1103 904 f2fs_destroy_compress_ctx(cc); ··· 1183 984 unlock_page(cc->rpages[i]); 1184 985 ret = 0; 1185 986 } else if (ret == -EAGAIN) { 987 + /* 988 + * for quota file, just redirty left pages to 989 + * avoid deadlock caused by cluster update race 990 + * from foreground operation. 991 + */ 992 + if (IS_NOQUOTA(cc->inode)) { 993 + err = 0; 994 + goto out_err; 995 + } 1186 996 ret = 0; 1187 997 cond_resched(); 1188 - congestion_wait(BLK_RW_ASYNC, HZ/50); 998 + congestion_wait(BLK_RW_ASYNC, 999 + DEFAULT_IO_TIMEOUT); 1189 1000 lock_page(cc->rpages[i]); 1190 1001 clear_page_dirty_for_io(cc->rpages[i]); 1191 1002 goto retry_write; 1192 1003 } 1193 1004 err = ret; 1194 - goto out_fail; 1005 + goto out_err; 1195 1006 } 1196 1007 1197 1008 *submitted += _submitted; 1198 1009 } 1199 1010 return 0; 1200 - 1201 - out_fail: 1202 - /* TODO: revoke partially updated block addresses */ 1203 - BUG_ON(compr_blocks); 1204 1011 out_err: 1205 1012 for (++i; i < cc->cluster_size; i++) { 1206 1013 if (!cc->rpages[i]) ··· 1274 1069 1275 1070 dic->magic = F2FS_COMPRESSED_PAGE_MAGIC; 1276 1071 dic->inode = cc->inode; 1277 - refcount_set(&dic->ref, 1); 1072 + refcount_set(&dic->ref, cc->nr_cpages); 1278 1073 dic->cluster_idx = cc->cluster_idx; 1279 1074 dic->cluster_size = cc->cluster_size; 1280 1075 dic->log_cluster_size = cc->log_cluster_size; ··· 1298 1093 goto out_free; 1299 1094 1300 1095 f2fs_set_compressed_page(page, cc->inode, 1301 - start_idx + i + 1, 1302 - dic, i ? &dic->ref : NULL); 1096 + start_idx + i + 1, dic); 1303 1097 dic->cpages[i] = page; 1304 1098 } 1305 1099 ··· 1308 1104 goto out_free; 1309 1105 1310 1106 for (i = 0; i < dic->cluster_size; i++) { 1311 - if (cc->rpages[i]) 1107 + if (cc->rpages[i]) { 1108 + dic->tpages[i] = cc->rpages[i]; 1312 1109 continue; 1110 + } 1313 1111 1314 1112 dic->tpages[i] = f2fs_grab_page(); 1315 1113 if (!dic->tpages[i]) 1316 1114 goto out_free; 1317 - } 1318 - 1319 - for (i = 0; i < dic->cluster_size; i++) { 1320 - if (dic->tpages[i]) 1321 - continue; 1322 - dic->tpages[i] = cc->rpages[i]; 1323 1115 } 1324 1116 1325 1117 return dic; ··· 1333 1133 for (i = 0; i < dic->cluster_size; i++) { 1334 1134 if (dic->rpages[i]) 1335 1135 continue; 1336 - f2fs_put_page(dic->tpages[i], 1); 1136 + if (!dic->tpages[i]) 1137 + continue; 1138 + unlock_page(dic->tpages[i]); 1139 + put_page(dic->tpages[i]); 1337 1140 } 1338 1141 kfree(dic->tpages); 1339 1142 } ··· 1365 1162 if (!rpage) 1366 1163 continue; 1367 1164 1368 - if (err || PageError(rpage)) { 1369 - ClearPageUptodate(rpage); 1370 - ClearPageError(rpage); 1371 - } else { 1372 - if (!verity || fsverity_verify_page(rpage)) 1373 - SetPageUptodate(rpage); 1374 - else 1375 - SetPageError(rpage); 1165 + if (err || PageError(rpage)) 1166 + goto clear_uptodate; 1167 + 1168 + if (!verity || fsverity_verify_page(rpage)) { 1169 + SetPageUptodate(rpage); 1170 + goto unlock; 1376 1171 } 1172 + clear_uptodate: 1173 + ClearPageUptodate(rpage); 1174 + ClearPageError(rpage); 1175 + unlock: 1377 1176 unlock_page(rpage); 1378 1177 } 1379 1178 }
+82 -61
fs/f2fs/data.c
··· 54 54 return bio_alloc_bioset(gfp_mask, nr_iovecs, &f2fs_bioset); 55 55 } 56 56 57 - struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, int npages, bool no_fail) 57 + struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, int npages, bool noio) 58 58 { 59 - struct bio *bio; 60 - 61 - if (no_fail) { 59 + if (noio) { 62 60 /* No failure on bio allocation */ 63 - bio = __f2fs_bio_alloc(GFP_NOIO, npages); 64 - if (!bio) 65 - bio = __f2fs_bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 66 - return bio; 61 + return __f2fs_bio_alloc(GFP_NOIO, npages); 67 62 } 63 + 68 64 if (time_to_inject(sbi, FAULT_ALLOC_BIO)) { 69 65 f2fs_show_injection_info(sbi, FAULT_ALLOC_BIO); 70 66 return NULL; ··· 139 143 f2fs_decompress_pages(bio, page, verity); 140 144 continue; 141 145 } 146 + if (verity) 147 + continue; 142 148 #endif 143 149 144 150 /* PG_error was set if any post_read step failed */ ··· 189 191 190 192 static void f2fs_verify_bio(struct bio *bio) 191 193 { 192 - struct page *page = bio_first_page_all(bio); 193 - struct decompress_io_ctx *dic = 194 - (struct decompress_io_ctx *)page_private(page); 194 + struct bio_vec *bv; 195 + struct bvec_iter_all iter_all; 195 196 196 - f2fs_verify_pages(dic->rpages, dic->cluster_size); 197 - f2fs_free_dic(dic); 197 + bio_for_each_segment_all(bv, bio, iter_all) { 198 + struct page *page = bv->bv_page; 199 + struct decompress_io_ctx *dic; 200 + 201 + dic = (struct decompress_io_ctx *)page_private(page); 202 + 203 + if (dic) { 204 + if (refcount_dec_not_one(&dic->ref)) 205 + continue; 206 + f2fs_verify_pages(dic->rpages, 207 + dic->cluster_size); 208 + f2fs_free_dic(dic); 209 + continue; 210 + } 211 + 212 + if (bio->bi_status || PageError(page)) 213 + goto clear_uptodate; 214 + 215 + if (fsverity_verify_page(page)) { 216 + SetPageUptodate(page); 217 + goto unlock; 218 + } 219 + clear_uptodate: 220 + ClearPageUptodate(page); 221 + ClearPageError(page); 222 + unlock: 223 + dec_page_count(F2FS_P_SB(page), __read_io_type(page)); 224 + unlock_page(page); 225 + } 198 226 } 199 227 #endif 200 228 ··· 388 364 bio_put(bio); 389 365 } 390 366 391 - /* 392 - * Return true, if pre_bio's bdev is same as its target device. 393 - */ 394 367 struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 395 368 block_t blk_addr, struct bio *bio) 396 369 { ··· 424 403 return 0; 425 404 } 426 405 406 + /* 407 + * Return true, if pre_bio's bdev is same as its target device. 408 + */ 427 409 static bool __same_bdev(struct f2fs_sb_info *sbi, 428 410 block_t blk_addr, struct bio *bio) 429 411 { ··· 434 410 return bio->bi_disk == b->bd_disk && bio->bi_partno == b->bd_partno; 435 411 } 436 412 437 - /* 438 - * Low-level block read/write IO operations. 439 - */ 440 413 static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages) 441 414 { 442 415 struct f2fs_sb_info *sbi = fio->sbi; ··· 466 445 if (type != DATA && type != NODE) 467 446 goto submit_io; 468 447 469 - if (test_opt(sbi, LFS) && current->plug) 448 + if (f2fs_lfs_mode(sbi) && current->plug) 470 449 blk_finish_plug(current->plug); 471 450 472 451 if (F2FS_IO_ALIGNED(sbi)) ··· 949 928 950 929 static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr, 951 930 unsigned nr_pages, unsigned op_flag, 952 - pgoff_t first_idx) 931 + pgoff_t first_idx, bool for_write) 953 932 { 954 933 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 955 934 struct bio *bio; 956 935 struct bio_post_read_ctx *ctx; 957 936 unsigned int post_read_steps = 0; 958 937 959 - bio = f2fs_bio_alloc(sbi, min_t(int, nr_pages, BIO_MAX_PAGES), false); 938 + bio = f2fs_bio_alloc(sbi, min_t(int, nr_pages, BIO_MAX_PAGES), 939 + for_write); 960 940 if (!bio) 961 941 return ERR_PTR(-ENOMEM); 962 942 f2fs_target_device(sbi, blkaddr, bio); ··· 992 970 993 971 /* This can handle encryption stuffs */ 994 972 static int f2fs_submit_page_read(struct inode *inode, struct page *page, 995 - block_t blkaddr) 973 + block_t blkaddr, bool for_write) 996 974 { 997 975 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 998 976 struct bio *bio; 999 977 1000 - bio = f2fs_grab_read_bio(inode, blkaddr, 1, 0, page->index); 978 + bio = f2fs_grab_read_bio(inode, blkaddr, 1, 0, page->index, for_write); 1001 979 if (IS_ERR(bio)) 1002 980 return PTR_ERR(bio); 1003 981 ··· 1069 1047 f2fs_wait_on_page_writeback(dn->node_page, NODE, true, true); 1070 1048 1071 1049 for (; count > 0; dn->ofs_in_node++) { 1072 - block_t blkaddr = datablock_addr(dn->inode, 1073 - dn->node_page, dn->ofs_in_node); 1050 + block_t blkaddr = f2fs_data_blkaddr(dn); 1074 1051 if (blkaddr == NULL_ADDR) { 1075 1052 dn->data_blkaddr = NEW_ADDR; 1076 1053 __set_data_blkaddr(dn); ··· 1183 1162 return page; 1184 1163 } 1185 1164 1186 - err = f2fs_submit_page_read(inode, page, dn.data_blkaddr); 1165 + err = f2fs_submit_page_read(inode, page, dn.data_blkaddr, for_write); 1187 1166 if (err) 1188 1167 goto put_err; 1189 1168 return page; ··· 1321 1300 if (err) 1322 1301 return err; 1323 1302 1324 - dn->data_blkaddr = datablock_addr(dn->inode, 1325 - dn->node_page, dn->ofs_in_node); 1303 + dn->data_blkaddr = f2fs_data_blkaddr(dn); 1326 1304 if (dn->data_blkaddr != NULL_ADDR) 1327 1305 goto alloc; 1328 1306 ··· 1408 1388 } 1409 1389 1410 1390 /* 1411 - * f2fs_map_blocks() now supported readahead/bmap/rw direct_IO with 1412 - * f2fs_map_blocks structure. 1413 - * If original data blocks are allocated, then give them to blockdev. 1414 - * Otherwise, 1415 - * a. preallocate requested block addresses 1416 - * b. do not use extent cache for better performance 1417 - * c. give the block addresses to blockdev 1391 + * f2fs_map_blocks() tries to find or build mapping relationship which 1392 + * maps continuous logical blocks to physical blocks, and return such 1393 + * info via f2fs_map_blocks structure. 1418 1394 */ 1419 1395 int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 1420 1396 int create, int flag) ··· 1438 1422 end = pgofs + maxblocks; 1439 1423 1440 1424 if (!create && f2fs_lookup_extent_cache(inode, pgofs, &ei)) { 1441 - if (test_opt(sbi, LFS) && flag == F2FS_GET_BLOCK_DIO && 1425 + if (f2fs_lfs_mode(sbi) && flag == F2FS_GET_BLOCK_DIO && 1442 1426 map->m_may_create) 1443 1427 goto next_dnode; 1444 1428 ··· 1483 1467 end_offset = ADDRS_PER_PAGE(dn.node_page, inode); 1484 1468 1485 1469 next_block: 1486 - blkaddr = datablock_addr(dn.inode, dn.node_page, dn.ofs_in_node); 1470 + blkaddr = f2fs_data_blkaddr(&dn); 1487 1471 1488 1472 if (__is_valid_data_blkaddr(blkaddr) && 1489 1473 !f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE)) { ··· 1493 1477 1494 1478 if (__is_valid_data_blkaddr(blkaddr)) { 1495 1479 /* use out-place-update for driect IO under LFS mode */ 1496 - if (test_opt(sbi, LFS) && flag == F2FS_GET_BLOCK_DIO && 1480 + if (f2fs_lfs_mode(sbi) && flag == F2FS_GET_BLOCK_DIO && 1497 1481 map->m_may_create) { 1498 1482 err = __allocate_data_block(&dn, map->m_seg_type); 1499 1483 if (err) ··· 1996 1980 } 1997 1981 if (bio == NULL) { 1998 1982 bio = f2fs_grab_read_bio(inode, block_nr, nr_pages, 1999 - is_readahead ? REQ_RAHEAD : 0, page->index); 1983 + is_readahead ? REQ_RAHEAD : 0, page->index, 1984 + false); 2000 1985 if (IS_ERR(bio)) { 2001 1986 ret = PTR_ERR(bio); 2002 1987 bio = NULL; ··· 2032 2015 #ifdef CONFIG_F2FS_FS_COMPRESSION 2033 2016 int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, 2034 2017 unsigned nr_pages, sector_t *last_block_in_bio, 2035 - bool is_readahead) 2018 + bool is_readahead, bool for_write) 2036 2019 { 2037 2020 struct dnode_of_data dn; 2038 2021 struct inode *inode = cc->inode; ··· 2048 2031 2049 2032 f2fs_bug_on(sbi, f2fs_cluster_is_empty(cc)); 2050 2033 2051 - last_block_in_file = (i_size_read(inode) + blocksize - 1) >> blkbits; 2034 + last_block_in_file = (f2fs_readpage_limit(inode) + 2035 + blocksize - 1) >> blkbits; 2052 2036 2053 2037 /* get rid of pages beyond EOF */ 2054 2038 for (i = 0; i < cc->cluster_size; i++) { ··· 2085 2067 for (i = 1; i < cc->cluster_size; i++) { 2086 2068 block_t blkaddr; 2087 2069 2088 - blkaddr = datablock_addr(dn.inode, dn.node_page, 2070 + blkaddr = data_blkaddr(dn.inode, dn.node_page, 2089 2071 dn.ofs_in_node + i); 2090 2072 2091 2073 if (!__is_valid_data_blkaddr(blkaddr)) ··· 2114 2096 struct page *page = dic->cpages[i]; 2115 2097 block_t blkaddr; 2116 2098 2117 - blkaddr = datablock_addr(dn.inode, dn.node_page, 2099 + blkaddr = data_blkaddr(dn.inode, dn.node_page, 2118 2100 dn.ofs_in_node + i + 1); 2119 2101 2120 2102 if (bio && !page_is_mergeable(sbi, bio, ··· 2127 2109 if (!bio) { 2128 2110 bio = f2fs_grab_read_bio(inode, blkaddr, nr_pages, 2129 2111 is_readahead ? REQ_RAHEAD : 0, 2130 - page->index); 2112 + page->index, for_write); 2131 2113 if (IS_ERR(bio)) { 2132 2114 ret = PTR_ERR(bio); 2133 2115 bio = NULL; ··· 2228 2210 ret = f2fs_read_multi_pages(&cc, &bio, 2229 2211 max_nr_pages, 2230 2212 &last_block_in_bio, 2231 - is_readahead); 2213 + is_readahead, false); 2232 2214 f2fs_destroy_compress_ctx(&cc); 2233 2215 if (ret) 2234 2216 goto set_error_page; ··· 2271 2253 ret = f2fs_read_multi_pages(&cc, &bio, 2272 2254 max_nr_pages, 2273 2255 &last_block_in_bio, 2274 - is_readahead); 2256 + is_readahead, false); 2275 2257 f2fs_destroy_compress_ctx(&cc); 2276 2258 } 2277 2259 } ··· 2344 2326 /* flush pending IOs and wait for a while in the ENOMEM case */ 2345 2327 if (PTR_ERR(fio->encrypted_page) == -ENOMEM) { 2346 2328 f2fs_flush_merged_writes(fio->sbi); 2347 - congestion_wait(BLK_RW_ASYNC, HZ/50); 2329 + congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT); 2348 2330 gfp_flags |= __GFP_NOFAIL; 2349 2331 goto retry_encrypt; 2350 2332 } ··· 2415 2397 { 2416 2398 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 2417 2399 2418 - if (test_opt(sbi, LFS)) 2400 + if (f2fs_lfs_mode(sbi)) 2419 2401 return true; 2420 2402 if (S_ISDIR(inode->i_mode)) 2421 2403 return true; ··· 2665 2647 if (err) { 2666 2648 file_set_keep_isize(inode); 2667 2649 } else { 2668 - down_write(&F2FS_I(inode)->i_sem); 2650 + spin_lock(&F2FS_I(inode)->i_size_lock); 2669 2651 if (F2FS_I(inode)->last_disk_size < psize) 2670 2652 F2FS_I(inode)->last_disk_size = psize; 2671 - up_write(&F2FS_I(inode)->i_sem); 2653 + spin_unlock(&F2FS_I(inode)->i_size_lock); 2672 2654 } 2673 2655 2674 2656 done: ··· 2935 2917 if (wbc->sync_mode == WB_SYNC_ALL) { 2936 2918 cond_resched(); 2937 2919 congestion_wait(BLK_RW_ASYNC, 2938 - HZ/50); 2920 + DEFAULT_IO_TIMEOUT); 2939 2921 goto retry_write; 2940 2922 } 2941 2923 goto next; ··· 2991 2973 static inline bool __should_serialize_io(struct inode *inode, 2992 2974 struct writeback_control *wbc) 2993 2975 { 2994 - if (!S_ISREG(inode->i_mode)) 2995 - return false; 2996 - if (f2fs_compressed_file(inode)) 2997 - return true; 2998 - if (IS_NOQUOTA(inode)) 2999 - return false; 3000 2976 /* to avoid deadlock in path of data flush */ 3001 2977 if (F2FS_I(inode)->cp_task) 3002 2978 return false; 2979 + 2980 + if (!S_ISREG(inode->i_mode)) 2981 + return false; 2982 + if (IS_NOQUOTA(inode)) 2983 + return false; 2984 + 2985 + if (f2fs_compressed_file(inode)) 2986 + return true; 3003 2987 if (wbc->sync_mode != WB_SYNC_ALL) 3004 2988 return true; 3005 2989 if (get_dirty_pages(inode) >= SM_I(F2FS_I_SB(inode))->min_seq_blocks) ··· 3303 3283 err = -EFSCORRUPTED; 3304 3284 goto fail; 3305 3285 } 3306 - err = f2fs_submit_page_read(inode, page, blkaddr); 3286 + err = f2fs_submit_page_read(inode, page, blkaddr, true); 3307 3287 if (err) 3308 3288 goto fail; 3309 3289 ··· 3484 3464 err = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, 3485 3465 iter, rw == WRITE ? get_data_block_dio_write : 3486 3466 get_data_block_dio, NULL, f2fs_dio_submit_bio, 3487 - DIO_LOCKING | DIO_SKIP_HOLES); 3467 + rw == WRITE ? DIO_LOCKING | DIO_SKIP_HOLES : 3468 + DIO_SKIP_HOLES); 3488 3469 3489 3470 if (do_opu) 3490 3471 up_read(&fi->i_gc_rwsem[READ]); ··· 3882 3861 3883 3862 int __init f2fs_init_bio_entry_cache(void) 3884 3863 { 3885 - bio_entry_slab = f2fs_kmem_cache_create("bio_entry_slab", 3864 + bio_entry_slab = f2fs_kmem_cache_create("f2fs_bio_entry_slab", 3886 3865 sizeof(struct bio_entry)); 3887 3866 if (!bio_entry_slab) 3888 3867 return -ENOMEM;
+3
fs/f2fs/debug.c
··· 301 301 si->ssa_area_segs, si->main_area_segs); 302 302 seq_printf(s, "(OverProv:%d Resv:%d)]\n\n", 303 303 si->overp_segs, si->rsvd_segs); 304 + seq_printf(s, "Current Time Sec: %llu / Mounted Time Sec: %llu\n\n", 305 + ktime_get_boottime_seconds(), 306 + SIT_I(si->sbi)->mounted_time); 304 307 if (test_opt(si->sbi, DISCARD)) 305 308 seq_printf(s, "Utilization: %u%% (%u valid blocks, %u discard blocks)\n", 306 309 si->utilization, si->valid_count, si->discard_blks);
+7 -9
fs/f2fs/dir.c
··· 471 471 struct page *dpage) 472 472 { 473 473 struct page *page; 474 - int dummy_encrypt = DUMMY_ENCRYPTION_ENABLED(F2FS_I_SB(dir)); 475 474 int err; 476 475 477 476 if (is_inode_flag_set(inode, FI_NEW_INODE)) { ··· 497 498 if (err) 498 499 goto put_error; 499 500 500 - if ((IS_ENCRYPTED(dir) || dummy_encrypt) && 501 - f2fs_may_encrypt(inode)) { 501 + if (IS_ENCRYPTED(inode)) { 502 502 err = fscrypt_inherit_context(dir, inode, page, false); 503 503 if (err) 504 504 goto put_error; ··· 848 850 0); 849 851 set_page_dirty(page); 850 852 851 - dir->i_ctime = dir->i_mtime = current_time(dir); 852 - f2fs_mark_inode_dirty_sync(dir, false); 853 - 854 - if (inode) 855 - f2fs_drop_nlink(dir, inode); 856 - 857 853 if (bit_pos == NR_DENTRY_IN_BLOCK && 858 854 !f2fs_truncate_hole(dir, page->index, page->index + 1)) { 859 855 f2fs_clear_page_cache_dirty_tag(page); ··· 859 867 f2fs_remove_dirty_inode(dir); 860 868 } 861 869 f2fs_put_page(page, 1); 870 + 871 + dir->i_ctime = dir->i_mtime = current_time(dir); 872 + f2fs_mark_inode_dirty_sync(dir, false); 873 + 874 + if (inode) 875 + f2fs_drop_nlink(dir, inode); 862 876 } 863 877 864 878 bool f2fs_empty_dir(struct inode *dir)
+117 -89
fs/f2fs/f2fs.h
··· 75 75 /* 76 76 * For mount options 77 77 */ 78 - #define F2FS_MOUNT_BG_GC 0x00000001 79 78 #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 80 79 #define F2FS_MOUNT_DISCARD 0x00000004 81 80 #define F2FS_MOUNT_NOHEAP 0x00000008 ··· 88 89 #define F2FS_MOUNT_NOBARRIER 0x00000800 89 90 #define F2FS_MOUNT_FASTBOOT 0x00001000 90 91 #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 91 - #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 92 92 #define F2FS_MOUNT_DATA_FLUSH 0x00008000 93 93 #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 94 - #define F2FS_MOUNT_ADAPTIVE 0x00020000 95 - #define F2FS_MOUNT_LFS 0x00040000 96 94 #define F2FS_MOUNT_USRQUOTA 0x00080000 97 95 #define F2FS_MOUNT_GRPQUOTA 0x00100000 98 96 #define F2FS_MOUNT_PRJQUOTA 0x00200000 ··· 97 101 #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 98 102 #define F2FS_MOUNT_RESERVE_ROOT 0x01000000 99 103 #define F2FS_MOUNT_DISABLE_CHECKPOINT 0x02000000 104 + #define F2FS_MOUNT_NORECOVERY 0x04000000 100 105 101 106 #define F2FS_OPTION(sbi) ((sbi)->mount_opt) 102 107 #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option) ··· 136 139 int whint_mode; 137 140 int alloc_mode; /* segment allocation policy */ 138 141 int fsync_mode; /* fsync policy */ 142 + int fs_mode; /* fs mode: LFS or ADAPTIVE */ 143 + int bggc_mode; /* bggc mode: off, on or sync */ 139 144 bool test_dummy_encryption; /* test dummy encryption */ 140 145 block_t unusable_cap; /* Amount of space allowed to be 141 146 * unusable when disabling checkpoint ··· 331 332 bool io_aware; /* issue discard in idle time */ 332 333 bool sync; /* submit discard with REQ_SYNC flag */ 333 334 bool ordered; /* issue discard by lba order */ 335 + bool timeout; /* discard timeout for put_super */ 334 336 unsigned int granularity; /* discard granularity */ 335 - int timeout; /* discard timeout for put_super */ 336 337 }; 337 338 338 339 struct discard_cmd_control { ··· 427 428 #define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32) 428 429 #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) 429 430 #define F2FS_IOC_RESIZE_FS _IOW(F2FS_IOCTL_MAGIC, 16, __u64) 431 + #define F2FS_IOC_GET_COMPRESS_BLOCKS _IOR(F2FS_IOCTL_MAGIC, 17, __u64) 430 432 431 433 #define F2FS_IOC_GET_VOLUME_NAME FS_IOC_GETFSLABEL 432 434 #define F2FS_IOC_SET_VOLUME_NAME FS_IOC_SETFSLABEL ··· 560 560 561 561 #define DEFAULT_RETRY_IO_COUNT 8 /* maximum retry read IO count */ 562 562 563 + /* congestion wait timeout value, default: 20ms */ 564 + #define DEFAULT_IO_TIMEOUT (msecs_to_jiffies(20)) 565 + 563 566 /* maximum retry quota flush count */ 564 567 #define DEFAULT_RETRY_QUOTA_FLUSH_COUNT 8 565 568 ··· 679 676 MAX_GC_FAILURE 680 677 }; 681 678 679 + /* used for f2fs_inode_info->flags */ 680 + enum { 681 + FI_NEW_INODE, /* indicate newly allocated inode */ 682 + FI_DIRTY_INODE, /* indicate inode is dirty or not */ 683 + FI_AUTO_RECOVER, /* indicate inode is recoverable */ 684 + FI_DIRTY_DIR, /* indicate directory has dirty pages */ 685 + FI_INC_LINK, /* need to increment i_nlink */ 686 + FI_ACL_MODE, /* indicate acl mode */ 687 + FI_NO_ALLOC, /* should not allocate any blocks */ 688 + FI_FREE_NID, /* free allocated nide */ 689 + FI_NO_EXTENT, /* not to use the extent cache */ 690 + FI_INLINE_XATTR, /* used for inline xattr */ 691 + FI_INLINE_DATA, /* used for inline data*/ 692 + FI_INLINE_DENTRY, /* used for inline dentry */ 693 + FI_APPEND_WRITE, /* inode has appended data */ 694 + FI_UPDATE_WRITE, /* inode has in-place-update data */ 695 + FI_NEED_IPU, /* used for ipu per file */ 696 + FI_ATOMIC_FILE, /* indicate atomic file */ 697 + FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 698 + FI_VOLATILE_FILE, /* indicate volatile file */ 699 + FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 700 + FI_DROP_CACHE, /* drop dirty page cache */ 701 + FI_DATA_EXIST, /* indicate data exists */ 702 + FI_INLINE_DOTS, /* indicate inline dot dentries */ 703 + FI_DO_DEFRAG, /* indicate defragment is running */ 704 + FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 705 + FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 706 + FI_HOT_DATA, /* indicate file is hot */ 707 + FI_EXTRA_ATTR, /* indicate file has extra attribute */ 708 + FI_PROJ_INHERIT, /* indicate file inherits projectid */ 709 + FI_PIN_FILE, /* indicate file should not be gced */ 710 + FI_ATOMIC_REVOKE_REQUEST, /* request to drop atomic data */ 711 + FI_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ 712 + FI_COMPRESSED_FILE, /* indicate file's data can be compressed */ 713 + FI_MMAP_FILE, /* indicate file was mmapped */ 714 + FI_MAX, /* max flag, never be used */ 715 + }; 716 + 682 717 struct f2fs_inode_info { 683 718 struct inode vfs_inode; /* serve a vfs inode */ 684 719 unsigned long i_flags; /* keep an inode flags for ioctl */ ··· 729 688 umode_t i_acl_mode; /* keep file acl mode temporarily */ 730 689 731 690 /* Use below internally in f2fs*/ 732 - unsigned long flags; /* use to pass per-file flags */ 691 + unsigned long flags[BITS_TO_LONGS(FI_MAX)]; /* use to pass per-file flags */ 733 692 struct rw_semaphore i_sem; /* protect fi info */ 734 693 atomic_t dirty_pages; /* # of dirty pages */ 735 694 f2fs_hash_t chash; /* hash value of given file name */ ··· 738 697 struct task_struct *cp_task; /* separate cp/wb IO stats*/ 739 698 nid_t i_xattr_nid; /* node id that contains xattrs */ 740 699 loff_t last_disk_size; /* lastly written file size */ 700 + spinlock_t i_size_lock; /* protect last_disk_size */ 741 701 742 702 #ifdef CONFIG_QUOTA 743 703 struct dquot *i_dquot[MAXQUOTAS]; ··· 1215 1173 }; 1216 1174 1217 1175 enum { 1176 + BGGC_MODE_ON, /* background gc is on */ 1177 + BGGC_MODE_OFF, /* background gc is off */ 1178 + BGGC_MODE_SYNC, /* 1179 + * background gc is on, migrating blocks 1180 + * like foreground gc 1181 + */ 1182 + }; 1183 + 1184 + enum { 1185 + FS_MODE_ADAPTIVE, /* use both lfs/ssr allocation */ 1186 + FS_MODE_LFS, /* use lfs allocation only */ 1187 + }; 1188 + 1189 + enum { 1218 1190 WHINT_MODE_OFF, /* not pass down write hints */ 1219 1191 WHINT_MODE_USER, /* try to pass down hints given by users */ 1220 1192 WHINT_MODE_FS, /* pass down hints with F2FS policy */ ··· 1268 1212 enum compress_algorithm_type { 1269 1213 COMPRESS_LZO, 1270 1214 COMPRESS_LZ4, 1215 + COMPRESS_ZSTD, 1271 1216 COMPRESS_MAX, 1272 1217 }; 1273 1218 1274 - #define COMPRESS_DATA_RESERVED_SIZE 4 1219 + #define COMPRESS_DATA_RESERVED_SIZE 5 1275 1220 struct compress_data { 1276 1221 __le32 clen; /* compressed data size */ 1277 - __le32 chksum; /* checksum of compressed data */ 1278 1222 __le32 reserved[COMPRESS_DATA_RESERVED_SIZE]; /* reserved */ 1279 1223 u8 cdata[]; /* compressed data */ 1280 1224 }; ··· 1298 1242 size_t rlen; /* valid data length in rbuf */ 1299 1243 size_t clen; /* valid data length in cbuf */ 1300 1244 void *private; /* payload buffer for specified compression algorithm */ 1245 + void *private2; /* extra payload buffer */ 1301 1246 }; 1302 1247 1303 1248 /* compress context for write IO path */ ··· 1328 1271 size_t clen; /* valid data length in cbuf */ 1329 1272 refcount_t ref; /* referrence count of compressed page */ 1330 1273 bool failed; /* indicate IO error during decompression */ 1274 + void *private; /* payload buffer for specified decompression algorithm */ 1275 + void *private2; /* extra payload buffer */ 1331 1276 }; 1332 1277 1333 1278 #define NULL_CLUSTER ((unsigned int)(~0)) 1334 1279 #define MIN_COMPRESS_LOG_SIZE 2 1335 1280 #define MAX_COMPRESS_LOG_SIZE 8 1281 + #define MAX_COMPRESS_WINDOW_SIZE ((PAGE_SIZE) << MAX_COMPRESS_LOG_SIZE) 1336 1282 1337 1283 struct f2fs_sb_info { 1338 1284 struct super_block *sb; /* pointer to VFS super block */ ··· 1531 1471 __u32 s_chksum_seed; 1532 1472 1533 1473 struct workqueue_struct *post_read_wq; /* post read workqueue */ 1474 + 1475 + struct kmem_cache *inline_xattr_slab; /* inline xattr entry */ 1476 + unsigned int inline_xattr_slab_size; /* default inline xattr slab size */ 1534 1477 }; 1535 1478 1536 1479 struct f2fs_private_dio { ··· 2274 2211 dquot_free_inode(inode); 2275 2212 } else { 2276 2213 if (unlikely(inode->i_blocks == 0)) { 2277 - f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu", 2214 + f2fs_warn(sbi, "dec_valid_node_count: inconsistent i_blocks, ino:%lu, iblocks:%llu", 2278 2215 inode->i_ino, 2279 2216 (unsigned long long)inode->i_blocks); 2280 2217 set_sbi_flag(sbi, SBI_NEED_FSCK); ··· 2442 2379 } 2443 2380 2444 2381 static inline int f2fs_has_extra_attr(struct inode *inode); 2445 - static inline block_t datablock_addr(struct inode *inode, 2382 + static inline block_t data_blkaddr(struct inode *inode, 2446 2383 struct page *node_page, unsigned int offset) 2447 2384 { 2448 2385 struct f2fs_node *raw_node; ··· 2452 2389 2453 2390 raw_node = F2FS_NODE(node_page); 2454 2391 2455 - /* from GC path only */ 2456 2392 if (is_inode) { 2457 2393 if (!inode) 2394 + /* from GC path only */ 2458 2395 base = offset_in_addr(&raw_node->i); 2459 2396 else if (f2fs_has_extra_attr(inode)) 2460 2397 base = get_extra_isize(inode); ··· 2462 2399 2463 2400 addr_array = blkaddr_in_node(raw_node); 2464 2401 return le32_to_cpu(addr_array[base + offset]); 2402 + } 2403 + 2404 + static inline block_t f2fs_data_blkaddr(struct dnode_of_data *dn) 2405 + { 2406 + return data_blkaddr(dn->inode, dn->node_page, dn->ofs_in_node); 2465 2407 } 2466 2408 2467 2409 static inline int f2fs_test_bit(unsigned int nr, char *addr) ··· 2566 2498 return flags & F2FS_OTHER_FLMASK; 2567 2499 } 2568 2500 2569 - /* used for f2fs_inode_info->flags */ 2570 - enum { 2571 - FI_NEW_INODE, /* indicate newly allocated inode */ 2572 - FI_DIRTY_INODE, /* indicate inode is dirty or not */ 2573 - FI_AUTO_RECOVER, /* indicate inode is recoverable */ 2574 - FI_DIRTY_DIR, /* indicate directory has dirty pages */ 2575 - FI_INC_LINK, /* need to increment i_nlink */ 2576 - FI_ACL_MODE, /* indicate acl mode */ 2577 - FI_NO_ALLOC, /* should not allocate any blocks */ 2578 - FI_FREE_NID, /* free allocated nide */ 2579 - FI_NO_EXTENT, /* not to use the extent cache */ 2580 - FI_INLINE_XATTR, /* used for inline xattr */ 2581 - FI_INLINE_DATA, /* used for inline data*/ 2582 - FI_INLINE_DENTRY, /* used for inline dentry */ 2583 - FI_APPEND_WRITE, /* inode has appended data */ 2584 - FI_UPDATE_WRITE, /* inode has in-place-update data */ 2585 - FI_NEED_IPU, /* used for ipu per file */ 2586 - FI_ATOMIC_FILE, /* indicate atomic file */ 2587 - FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 2588 - FI_VOLATILE_FILE, /* indicate volatile file */ 2589 - FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 2590 - FI_DROP_CACHE, /* drop dirty page cache */ 2591 - FI_DATA_EXIST, /* indicate data exists */ 2592 - FI_INLINE_DOTS, /* indicate inline dot dentries */ 2593 - FI_DO_DEFRAG, /* indicate defragment is running */ 2594 - FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 2595 - FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 2596 - FI_HOT_DATA, /* indicate file is hot */ 2597 - FI_EXTRA_ATTR, /* indicate file has extra attribute */ 2598 - FI_PROJ_INHERIT, /* indicate file inherits projectid */ 2599 - FI_PIN_FILE, /* indicate file should not be gced */ 2600 - FI_ATOMIC_REVOKE_REQUEST, /* request to drop atomic data */ 2601 - FI_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ 2602 - FI_COMPRESSED_FILE, /* indicate file's data can be compressed */ 2603 - FI_MMAP_FILE, /* indicate file was mmapped */ 2604 - }; 2605 - 2606 2501 static inline void __mark_inode_dirty_flag(struct inode *inode, 2607 2502 int flag, bool set) 2608 2503 { ··· 2580 2549 case FI_DATA_EXIST: 2581 2550 case FI_INLINE_DOTS: 2582 2551 case FI_PIN_FILE: 2583 - case FI_COMPRESSED_FILE: 2584 2552 f2fs_mark_inode_dirty_sync(inode, true); 2585 2553 } 2586 2554 } 2587 2555 2588 2556 static inline void set_inode_flag(struct inode *inode, int flag) 2589 2557 { 2590 - if (!test_bit(flag, &F2FS_I(inode)->flags)) 2591 - set_bit(flag, &F2FS_I(inode)->flags); 2558 + test_and_set_bit(flag, F2FS_I(inode)->flags); 2592 2559 __mark_inode_dirty_flag(inode, flag, true); 2593 2560 } 2594 2561 2595 2562 static inline int is_inode_flag_set(struct inode *inode, int flag) 2596 2563 { 2597 - return test_bit(flag, &F2FS_I(inode)->flags); 2564 + return test_bit(flag, F2FS_I(inode)->flags); 2598 2565 } 2599 2566 2600 2567 static inline void clear_inode_flag(struct inode *inode, int flag) 2601 2568 { 2602 - if (test_bit(flag, &F2FS_I(inode)->flags)) 2603 - clear_bit(flag, &F2FS_I(inode)->flags); 2569 + test_and_clear_bit(flag, F2FS_I(inode)->flags); 2604 2570 __mark_inode_dirty_flag(inode, flag, false); 2605 2571 } 2606 2572 ··· 2688 2660 struct f2fs_inode_info *fi = F2FS_I(inode); 2689 2661 2690 2662 if (ri->i_inline & F2FS_INLINE_XATTR) 2691 - set_bit(FI_INLINE_XATTR, &fi->flags); 2663 + set_bit(FI_INLINE_XATTR, fi->flags); 2692 2664 if (ri->i_inline & F2FS_INLINE_DATA) 2693 - set_bit(FI_INLINE_DATA, &fi->flags); 2665 + set_bit(FI_INLINE_DATA, fi->flags); 2694 2666 if (ri->i_inline & F2FS_INLINE_DENTRY) 2695 - set_bit(FI_INLINE_DENTRY, &fi->flags); 2667 + set_bit(FI_INLINE_DENTRY, fi->flags); 2696 2668 if (ri->i_inline & F2FS_DATA_EXIST) 2697 - set_bit(FI_DATA_EXIST, &fi->flags); 2669 + set_bit(FI_DATA_EXIST, fi->flags); 2698 2670 if (ri->i_inline & F2FS_INLINE_DOTS) 2699 - set_bit(FI_INLINE_DOTS, &fi->flags); 2671 + set_bit(FI_INLINE_DOTS, fi->flags); 2700 2672 if (ri->i_inline & F2FS_EXTRA_ATTR) 2701 - set_bit(FI_EXTRA_ATTR, &fi->flags); 2673 + set_bit(FI_EXTRA_ATTR, fi->flags); 2702 2674 if (ri->i_inline & F2FS_PIN_FILE) 2703 - set_bit(FI_PIN_FILE, &fi->flags); 2675 + set_bit(FI_PIN_FILE, fi->flags); 2704 2676 } 2705 2677 2706 2678 static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) ··· 2885 2857 if (!f2fs_is_time_consistent(inode)) 2886 2858 return false; 2887 2859 2888 - down_read(&F2FS_I(inode)->i_sem); 2860 + spin_lock(&F2FS_I(inode)->i_size_lock); 2889 2861 ret = F2FS_I(inode)->last_disk_size == i_size_read(inode); 2890 - up_read(&F2FS_I(inode)->i_sem); 2862 + spin_unlock(&F2FS_I(inode)->i_size_lock); 2891 2863 2892 2864 return ret; 2893 2865 } ··· 3241 3213 void f2fs_drop_inmem_page(struct inode *inode, struct page *page); 3242 3214 int f2fs_commit_inmem_pages(struct inode *inode); 3243 3215 void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 3244 - void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 3216 + void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg); 3245 3217 int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino); 3246 3218 int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi); 3247 3219 int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); ··· 3337 3309 void f2fs_update_dirty_page(struct inode *inode, struct page *page); 3338 3310 void f2fs_remove_dirty_inode(struct inode *inode); 3339 3311 int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 3340 - void f2fs_wait_on_all_pages_writeback(struct f2fs_sb_info *sbi); 3312 + void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type); 3341 3313 int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 3342 3314 void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi); 3343 3315 int __init f2fs_create_checkpoint_caches(void); ··· 3348 3320 */ 3349 3321 int __init f2fs_init_bioset(void); 3350 3322 void f2fs_destroy_bioset(void); 3351 - struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, int npages, bool no_fail); 3323 + struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, int npages, bool noio); 3352 3324 int f2fs_init_bio_entry_cache(void); 3353 3325 void f2fs_destroy_bio_entry_cache(void); 3354 3326 void f2fs_submit_bio(struct f2fs_sb_info *sbi, ··· 3804 3776 int f2fs_is_compressed_cluster(struct inode *inode, pgoff_t index); 3805 3777 int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, 3806 3778 unsigned nr_pages, sector_t *last_block_in_bio, 3807 - bool is_readahead); 3779 + bool is_readahead, bool for_write); 3808 3780 struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc); 3809 3781 void f2fs_free_dic(struct decompress_io_ctx *dic); 3810 3782 void f2fs_decompress_end_io(struct page **rpages, ··· 3841 3813 F2FS_I(inode)->i_flags |= F2FS_COMPR_FL; 3842 3814 set_inode_flag(inode, FI_COMPRESSED_FILE); 3843 3815 stat_inc_compr_inode(inode); 3816 + f2fs_mark_inode_dirty_sync(inode, true); 3844 3817 } 3845 3818 3846 3819 static inline u64 f2fs_disable_compressed_file(struct inode *inode) ··· 3850 3821 3851 3822 if (!f2fs_compressed_file(inode)) 3852 3823 return 0; 3853 - if (fi->i_compr_blocks) 3854 - return fi->i_compr_blocks; 3824 + if (S_ISREG(inode->i_mode)) { 3825 + if (get_dirty_pages(inode)) 3826 + return 1; 3827 + if (fi->i_compr_blocks) 3828 + return fi->i_compr_blocks; 3829 + } 3855 3830 3856 3831 fi->i_flags &= ~F2FS_COMPR_FL; 3857 - clear_inode_flag(inode, FI_COMPRESSED_FILE); 3858 3832 stat_dec_compr_inode(inode); 3833 + clear_inode_flag(inode, FI_COMPRESSED_FILE); 3834 + f2fs_mark_inode_dirty_sync(inode, true); 3859 3835 return 0; 3860 3836 } 3861 3837 ··· 3937 3903 return false; 3938 3904 } 3939 3905 3940 - 3941 - static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 3906 + static inline bool f2fs_lfs_mode(struct f2fs_sb_info *sbi) 3942 3907 { 3943 - clear_opt(sbi, ADAPTIVE); 3944 - clear_opt(sbi, LFS); 3945 - 3946 - switch (mt) { 3947 - case F2FS_MOUNT_ADAPTIVE: 3948 - set_opt(sbi, ADAPTIVE); 3949 - break; 3950 - case F2FS_MOUNT_LFS: 3951 - set_opt(sbi, LFS); 3952 - break; 3953 - } 3908 + return F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS; 3954 3909 } 3955 3910 3956 - static inline bool f2fs_may_encrypt(struct inode *inode) 3911 + static inline bool f2fs_may_encrypt(struct inode *dir, struct inode *inode) 3957 3912 { 3958 3913 #ifdef CONFIG_FS_ENCRYPTION 3914 + struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 3959 3915 umode_t mode = inode->i_mode; 3960 3916 3961 - return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 3962 - #else 3963 - return false; 3917 + /* 3918 + * If the directory encrypted or dummy encryption enabled, 3919 + * then we should encrypt the inode. 3920 + */ 3921 + if (IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) 3922 + return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 3964 3923 #endif 3924 + return false; 3965 3925 } 3966 3926 3967 3927 static inline bool f2fs_may_compress(struct inode *inode) ··· 3999 3971 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4000 3972 int rw = iov_iter_rw(iter); 4001 3973 4002 - return (test_opt(sbi, LFS) && (rw == WRITE) && 3974 + return (f2fs_lfs_mode(sbi) && (rw == WRITE) && 4003 3975 !block_unaligned_IO(inode, iocb, iter)); 4004 3976 } 4005 3977 ··· 4021 3993 */ 4022 3994 if (f2fs_sb_has_blkzoned(sbi)) 4023 3995 return true; 4024 - if (test_opt(sbi, LFS) && (rw == WRITE)) { 3996 + if (f2fs_lfs_mode(sbi) && (rw == WRITE)) { 4025 3997 if (block_unaligned_IO(inode, iocb, iter)) 4026 3998 return true; 4027 3999 if (F2FS_IO_ALIGNED(sbi))
+57 -34
fs/f2fs/file.c
··· 106 106 err = f2fs_get_block(&dn, page->index); 107 107 f2fs_put_dnode(&dn); 108 108 __do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false); 109 - if (err) { 110 - unlock_page(page); 111 - goto out_sem; 112 - } 113 109 } 114 110 115 - /* fill the page */ 111 + #ifdef CONFIG_F2FS_FS_COMPRESSION 112 + if (!need_alloc) { 113 + set_new_dnode(&dn, inode, NULL, NULL, 0); 114 + err = f2fs_get_dnode_of_data(&dn, page->index, LOOKUP_NODE); 115 + f2fs_put_dnode(&dn); 116 + } 117 + #endif 118 + if (err) { 119 + unlock_page(page); 120 + goto out_sem; 121 + } 122 + 116 123 f2fs_wait_on_page_writeback(page, DATA, false, true); 117 124 118 125 /* wait for GCed page writeback via META_MAPPING */ ··· 455 448 data_ofs = (loff_t)pgofs << PAGE_SHIFT) { 456 449 block_t blkaddr; 457 450 458 - blkaddr = datablock_addr(dn.inode, 459 - dn.node_page, dn.ofs_in_node); 451 + blkaddr = f2fs_data_blkaddr(&dn); 460 452 461 453 if (__is_valid_data_blkaddr(blkaddr) && 462 454 !f2fs_is_valid_blkaddr(F2FS_I_SB(inode), ··· 799 793 } 800 794 801 795 flags = fi->i_flags; 796 + if (flags & F2FS_COMPR_FL) 797 + stat->attributes |= STATX_ATTR_COMPRESSED; 802 798 if (flags & F2FS_APPEND_FL) 803 799 stat->attributes |= STATX_ATTR_APPEND; 804 800 if (IS_ENCRYPTED(inode)) ··· 812 804 if (IS_VERITY(inode)) 813 805 stat->attributes |= STATX_ATTR_VERITY; 814 806 815 - stat->attributes_mask |= (STATX_ATTR_APPEND | 807 + stat->attributes_mask |= (STATX_ATTR_COMPRESSED | 808 + STATX_ATTR_APPEND | 816 809 STATX_ATTR_ENCRYPTED | 817 810 STATX_ATTR_IMMUTABLE | 818 811 STATX_ATTR_NODUMP | ··· 938 929 if (err) 939 930 return err; 940 931 941 - down_write(&F2FS_I(inode)->i_sem); 932 + spin_lock(&F2FS_I(inode)->i_size_lock); 942 933 inode->i_mtime = inode->i_ctime = current_time(inode); 943 934 F2FS_I(inode)->last_disk_size = i_size_read(inode); 944 - up_write(&F2FS_I(inode)->i_sem); 935 + spin_unlock(&F2FS_I(inode)->i_size_lock); 945 936 } 946 937 947 938 __setattr_copy(inode, attr); ··· 1118 1109 done = min((pgoff_t)ADDRS_PER_PAGE(dn.node_page, inode) - 1119 1110 dn.ofs_in_node, len); 1120 1111 for (i = 0; i < done; i++, blkaddr++, do_replace++, dn.ofs_in_node++) { 1121 - *blkaddr = datablock_addr(dn.inode, 1122 - dn.node_page, dn.ofs_in_node); 1112 + *blkaddr = f2fs_data_blkaddr(&dn); 1123 1113 1124 1114 if (__is_valid_data_blkaddr(*blkaddr) && 1125 1115 !f2fs_is_valid_blkaddr(sbi, *blkaddr, ··· 1129 1121 1130 1122 if (!f2fs_is_checkpointed_data(sbi, *blkaddr)) { 1131 1123 1132 - if (test_opt(sbi, LFS)) { 1124 + if (f2fs_lfs_mode(sbi)) { 1133 1125 f2fs_put_dnode(&dn); 1134 1126 return -EOPNOTSUPP; 1135 1127 } ··· 1207 1199 ADDRS_PER_PAGE(dn.node_page, dst_inode) - 1208 1200 dn.ofs_in_node, len - i); 1209 1201 do { 1210 - dn.data_blkaddr = datablock_addr(dn.inode, 1211 - dn.node_page, dn.ofs_in_node); 1202 + dn.data_blkaddr = f2fs_data_blkaddr(&dn); 1212 1203 f2fs_truncate_data_blocks_range(&dn, 1); 1213 1204 1214 1205 if (do_replace[i]) { ··· 1383 1376 int ret; 1384 1377 1385 1378 for (; index < end; index++, dn->ofs_in_node++) { 1386 - if (datablock_addr(dn->inode, dn->node_page, 1387 - dn->ofs_in_node) == NULL_ADDR) 1379 + if (f2fs_data_blkaddr(dn) == NULL_ADDR) 1388 1380 count++; 1389 1381 } 1390 1382 ··· 1394 1388 1395 1389 dn->ofs_in_node = ofs_in_node; 1396 1390 for (index = start; index < end; index++, dn->ofs_in_node++) { 1397 - dn->data_blkaddr = datablock_addr(dn->inode, 1398 - dn->node_page, dn->ofs_in_node); 1391 + dn->data_blkaddr = f2fs_data_blkaddr(dn); 1399 1392 /* 1400 1393 * f2fs_reserve_new_blocks will not guarantee entire block 1401 1394 * allocation. ··· 1792 1787 static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask) 1793 1788 { 1794 1789 struct f2fs_inode_info *fi = F2FS_I(inode); 1790 + u32 masked_flags = fi->i_flags & mask; 1791 + 1792 + f2fs_bug_on(F2FS_I_SB(inode), (iflags & ~mask)); 1795 1793 1796 1794 /* Is it quota file? Do not allow user to mess with it */ 1797 1795 if (IS_NOQUOTA(inode)) 1798 1796 return -EPERM; 1799 1797 1800 - if ((iflags ^ fi->i_flags) & F2FS_CASEFOLD_FL) { 1798 + if ((iflags ^ masked_flags) & F2FS_CASEFOLD_FL) { 1801 1799 if (!f2fs_sb_has_casefold(F2FS_I_SB(inode))) 1802 1800 return -EOPNOTSUPP; 1803 1801 if (!f2fs_empty_dir(inode)) ··· 1814 1806 return -EINVAL; 1815 1807 } 1816 1808 1817 - if ((iflags ^ fi->i_flags) & F2FS_COMPR_FL) { 1818 - if (S_ISREG(inode->i_mode) && 1819 - (fi->i_flags & F2FS_COMPR_FL || i_size_read(inode) || 1820 - F2FS_HAS_BLOCKS(inode))) 1821 - return -EINVAL; 1809 + if ((iflags ^ masked_flags) & F2FS_COMPR_FL) { 1810 + if (masked_flags & F2FS_COMPR_FL) { 1811 + if (f2fs_disable_compressed_file(inode)) 1812 + return -EINVAL; 1813 + } 1822 1814 if (iflags & F2FS_NOCOMP_FL) 1823 1815 return -EINVAL; 1824 1816 if (iflags & F2FS_COMPR_FL) { 1825 - int err = f2fs_convert_inline_inode(inode); 1826 - 1827 - if (err) 1828 - return err; 1829 - 1830 1817 if (!f2fs_may_compress(inode)) 1831 1818 return -EINVAL; 1832 1819 1833 1820 set_compress_context(inode); 1834 1821 } 1835 1822 } 1836 - if ((iflags ^ fi->i_flags) & F2FS_NOCOMP_FL) { 1837 - if (fi->i_flags & F2FS_COMPR_FL) 1823 + if ((iflags ^ masked_flags) & F2FS_NOCOMP_FL) { 1824 + if (masked_flags & F2FS_COMPR_FL) 1838 1825 return -EINVAL; 1839 1826 } 1840 1827 ··· 3404 3401 return err; 3405 3402 } 3406 3403 3404 + static int f2fs_get_compress_blocks(struct file *filp, unsigned long arg) 3405 + { 3406 + struct inode *inode = file_inode(filp); 3407 + __u64 blocks; 3408 + 3409 + if (!f2fs_sb_has_compression(F2FS_I_SB(inode))) 3410 + return -EOPNOTSUPP; 3411 + 3412 + if (!f2fs_compressed_file(inode)) 3413 + return -EINVAL; 3414 + 3415 + blocks = F2FS_I(inode)->i_compr_blocks; 3416 + return put_user(blocks, (u64 __user *)arg); 3417 + } 3418 + 3407 3419 long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 3408 3420 { 3409 3421 if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) ··· 3499 3481 return f2fs_get_volume_name(filp, arg); 3500 3482 case F2FS_IOC_SET_VOLUME_NAME: 3501 3483 return f2fs_set_volume_name(filp, arg); 3484 + case F2FS_IOC_GET_COMPRESS_BLOCKS: 3485 + return f2fs_get_compress_blocks(filp, arg); 3502 3486 default: 3503 3487 return -ENOTTY; 3504 3488 } ··· 3528 3508 goto out; 3529 3509 } 3530 3510 3531 - if (!f2fs_is_compress_backend_ready(inode)) 3532 - return -EOPNOTSUPP; 3511 + if (!f2fs_is_compress_backend_ready(inode)) { 3512 + ret = -EOPNOTSUPP; 3513 + goto out; 3514 + } 3533 3515 3534 3516 if (iocb->ki_flags & IOCB_NOWAIT) { 3535 3517 if (!inode_trylock(inode)) { ··· 3661 3639 case FS_IOC_MEASURE_VERITY: 3662 3640 case F2FS_IOC_GET_VOLUME_NAME: 3663 3641 case F2FS_IOC_SET_VOLUME_NAME: 3642 + case F2FS_IOC_GET_COMPRESS_BLOCKS: 3664 3643 break; 3665 3644 default: 3666 3645 return -ENOIOCTLCMD;
+37 -14
fs/f2fs/gc.c
··· 31 31 32 32 set_freezable(); 33 33 do { 34 + bool sync_mode; 35 + 34 36 wait_event_interruptible_timeout(*wq, 35 37 kthread_should_stop() || freezing(current) || 36 38 gc_th->gc_wake, ··· 103 101 do_gc: 104 102 stat_inc_bggc_count(sbi->stat_info); 105 103 104 + sync_mode = F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC; 105 + 106 106 /* if return value is not zero, no victim was selected */ 107 - if (f2fs_gc(sbi, test_opt(sbi, FORCE_FG_GC), true, NULL_SEGNO)) 107 + if (f2fs_gc(sbi, sync_mode, true, NULL_SEGNO)) 108 108 wait_ms = gc_th->no_gc_sleep_time; 109 109 110 110 trace_f2fs_background_gc(sbi->sb, wait_ms, 111 111 prefree_segments(sbi), free_segments(sbi)); 112 112 113 113 /* balancing f2fs's metadata periodically */ 114 - f2fs_balance_fs_bg(sbi); 114 + f2fs_balance_fs_bg(sbi, true); 115 115 next: 116 116 sb_end_write(sbi->sb); 117 117 ··· 196 192 p->ofs_unit = sbi->segs_per_sec; 197 193 } 198 194 199 - /* we need to check every dirty segments in the FG_GC case */ 195 + /* 196 + * adjust candidates range, should select all dirty segments for 197 + * foreground GC and urgent GC cases. 198 + */ 200 199 if (gc_type != FG_GC && 201 200 (sbi->gc_mode != GC_URGENT) && 202 201 p->max_search > sbi->max_victim_search) ··· 641 634 } 642 635 643 636 *nofs = ofs_of_node(node_page); 644 - source_blkaddr = datablock_addr(NULL, node_page, ofs_in_node); 637 + source_blkaddr = data_blkaddr(NULL, node_page, ofs_in_node); 645 638 f2fs_put_page(node_page, 1); 646 639 647 640 if (source_blkaddr != blkaddr) { ··· 769 762 struct page *page, *mpage; 770 763 block_t newaddr; 771 764 int err = 0; 772 - bool lfs_mode = test_opt(fio.sbi, LFS); 765 + bool lfs_mode = f2fs_lfs_mode(fio.sbi); 773 766 774 767 /* do not read out */ 775 768 page = f2fs_grab_cache_page(inode->i_mapping, bidx, false); ··· 977 970 if (err) { 978 971 clear_cold_data(page); 979 972 if (err == -ENOMEM) { 980 - congestion_wait(BLK_RW_ASYNC, HZ/50); 973 + congestion_wait(BLK_RW_ASYNC, 974 + DEFAULT_IO_TIMEOUT); 981 975 goto retry; 982 976 } 983 977 if (is_dirty) ··· 1026 1018 * race condition along with SSR block allocation. 1027 1019 */ 1028 1020 if ((gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) || 1029 - get_valid_blocks(sbi, segno, false) == 1030 - sbi->blocks_per_seg) 1021 + get_valid_blocks(sbi, segno, true) == 1022 + BLKS_PER_SEC(sbi)) 1031 1023 return submitted; 1032 1024 1033 1025 if (check_valid_map(sbi, segno, off) == 0) ··· 1211 1203 1212 1204 if (get_valid_blocks(sbi, segno, false) == 0) 1213 1205 goto freed; 1214 - if (__is_large_section(sbi) && 1206 + if (gc_type == BG_GC && __is_large_section(sbi) && 1215 1207 migrated >= sbi->migration_granularity) 1216 1208 goto skip; 1217 1209 if (!PageUptodate(sum_page) || unlikely(f2fs_cp_error(sbi))) ··· 1241 1233 segno, gc_type); 1242 1234 1243 1235 stat_inc_seg_count(sbi, type, gc_type); 1236 + migrated++; 1244 1237 1245 1238 freed: 1246 1239 if (gc_type == FG_GC && 1247 1240 get_valid_blocks(sbi, segno, false) == 0) 1248 1241 seg_freed++; 1249 - migrated++; 1250 1242 1251 1243 if (__is_large_section(sbi) && segno + 1 < end_segno) 1252 1244 sbi->next_victim_seg[gc_type] = segno + 1; ··· 1442 1434 static void update_sb_metadata(struct f2fs_sb_info *sbi, int secs) 1443 1435 { 1444 1436 struct f2fs_super_block *raw_sb = F2FS_RAW_SUPER(sbi); 1445 - int section_count = le32_to_cpu(raw_sb->section_count); 1446 - int segment_count = le32_to_cpu(raw_sb->segment_count); 1447 - int segment_count_main = le32_to_cpu(raw_sb->segment_count_main); 1448 - long long block_count = le64_to_cpu(raw_sb->block_count); 1437 + int section_count; 1438 + int segment_count; 1439 + int segment_count_main; 1440 + long long block_count; 1449 1441 int segs = secs * sbi->segs_per_sec; 1442 + 1443 + down_write(&sbi->sb_lock); 1444 + 1445 + section_count = le32_to_cpu(raw_sb->section_count); 1446 + segment_count = le32_to_cpu(raw_sb->segment_count); 1447 + segment_count_main = le32_to_cpu(raw_sb->segment_count_main); 1448 + block_count = le64_to_cpu(raw_sb->block_count); 1450 1449 1451 1450 raw_sb->section_count = cpu_to_le32(section_count + secs); 1452 1451 raw_sb->segment_count = cpu_to_le32(segment_count + segs); ··· 1468 1453 raw_sb->devs[last_dev].total_segments = 1469 1454 cpu_to_le32(dev_segs + segs); 1470 1455 } 1456 + 1457 + up_write(&sbi->sb_lock); 1471 1458 } 1472 1459 1473 1460 static void update_fs_metadata(struct f2fs_sb_info *sbi, int secs) ··· 1587 1570 goto out; 1588 1571 } 1589 1572 1573 + mutex_lock(&sbi->cp_mutex); 1590 1574 update_fs_metadata(sbi, -secs); 1591 1575 clear_sbi_flag(sbi, SBI_IS_RESIZEFS); 1576 + set_sbi_flag(sbi, SBI_IS_DIRTY); 1577 + mutex_unlock(&sbi->cp_mutex); 1578 + 1592 1579 err = f2fs_sync_fs(sbi->sb, 1); 1593 1580 if (err) { 1581 + mutex_lock(&sbi->cp_mutex); 1594 1582 update_fs_metadata(sbi, secs); 1583 + mutex_unlock(&sbi->cp_mutex); 1595 1584 update_sb_metadata(sbi, secs); 1596 1585 f2fs_commit_super(sbi, false); 1597 1586 }
+23 -6
fs/f2fs/inode.c
··· 291 291 fi->i_flags & F2FS_COMPR_FL && 292 292 F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, 293 293 i_log_cluster_size)) { 294 - if (ri->i_compress_algorithm >= COMPRESS_MAX) 294 + if (ri->i_compress_algorithm >= COMPRESS_MAX) { 295 + f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported " 296 + "compress algorithm: %u, run fsck to fix", 297 + __func__, inode->i_ino, 298 + ri->i_compress_algorithm); 295 299 return false; 296 - if (le64_to_cpu(ri->i_compr_blocks) > inode->i_blocks) 300 + } 301 + if (le64_to_cpu(ri->i_compr_blocks) > 302 + SECTOR_TO_BLOCK(inode->i_blocks)) { 303 + f2fs_warn(sbi, "%s: inode (ino=%lx) has inconsistent " 304 + "i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix", 305 + __func__, inode->i_ino, 306 + le64_to_cpu(ri->i_compr_blocks), 307 + SECTOR_TO_BLOCK(inode->i_blocks)); 297 308 return false; 309 + } 298 310 if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE || 299 - ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) 311 + ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) { 312 + f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported " 313 + "log cluster size: %u, run fsck to fix", 314 + __func__, inode->i_ino, 315 + ri->i_log_cluster_size); 300 316 return false; 317 + } 301 318 } 302 319 303 320 return true; ··· 362 345 fi->i_flags = le32_to_cpu(ri->i_flags); 363 346 if (S_ISREG(inode->i_mode)) 364 347 fi->i_flags &= ~F2FS_PROJINHERIT_FL; 365 - fi->flags = 0; 348 + bitmap_zero(fi->flags, FI_MAX); 366 349 fi->i_advise = ri->i_advise; 367 350 fi->i_pino = le32_to_cpu(ri->i_pino); 368 351 fi->i_dir_level = ri->i_dir_level; ··· 535 518 inode = f2fs_iget(sb, ino); 536 519 if (IS_ERR(inode)) { 537 520 if (PTR_ERR(inode) == -ENOMEM) { 538 - congestion_wait(BLK_RW_ASYNC, HZ/50); 521 + congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT); 539 522 goto retry; 540 523 } 541 524 } ··· 776 759 else 777 760 f2fs_inode_synced(inode); 778 761 779 - /* ino == 0, if f2fs_new_inode() was failed t*/ 762 + /* for the case f2fs_new_inode() was failed, .i_ino is zero, skip it */ 780 763 if (inode->i_ino) 781 764 invalidate_mapping_pages(NODE_MAPPING(sbi), inode->i_ino, 782 765 inode->i_ino);
+2 -10
fs/f2fs/namei.c
··· 75 75 76 76 set_inode_flag(inode, FI_NEW_INODE); 77 77 78 - /* If the directory encrypted, then we should encrypt the inode. */ 79 - if ((IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) && 80 - f2fs_may_encrypt(inode)) 78 + if (f2fs_may_encrypt(dir, inode)) 81 79 f2fs_set_encrypted_inode(inode); 82 80 83 81 if (f2fs_sb_has_extra_attr(sbi)) { ··· 175 177 } 176 178 177 179 /* 178 - * Set multimedia files as cold files for hot/cold data separation 180 + * Set file's temperature for hot/cold data separation 179 181 */ 180 182 static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *inode, 181 183 const unsigned char *name) ··· 873 875 return -EIO; 874 876 if (!f2fs_is_checkpoint_ready(sbi)) 875 877 return -ENOSPC; 876 - 877 - if (IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) { 878 - int err = fscrypt_get_encryption_info(dir); 879 - if (err) 880 - return err; 881 - } 882 878 883 879 return __f2fs_tmpfile(dir, dentry, mode, NULL); 884 880 }
+15 -18
fs/f2fs/node.c
··· 510 510 return nr - nr_shrink; 511 511 } 512 512 513 - /* 514 - * This function always returns success 515 - */ 516 513 int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, 517 514 struct node_info *ni) 518 515 { ··· 713 716 /* 714 717 * Caller should call f2fs_put_dnode(dn). 715 718 * Also, it should grab and release a rwsem by calling f2fs_lock_op() and 716 - * f2fs_unlock_op() only if ro is not set RDONLY_NODE. 717 - * In the case of RDONLY_NODE, we don't need to care about mutex. 719 + * f2fs_unlock_op() only if mode is set with ALLOC_NODE. 718 720 */ 719 721 int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode) 720 722 { ··· 805 809 dn->nid = nids[level]; 806 810 dn->ofs_in_node = offset[level]; 807 811 dn->node_page = npage[level]; 808 - dn->data_blkaddr = datablock_addr(dn->inode, 809 - dn->node_page, dn->ofs_in_node); 812 + dn->data_blkaddr = f2fs_data_blkaddr(dn); 810 813 return 0; 811 814 812 815 release_pages: ··· 1183 1188 } 1184 1189 1185 1190 if (unlikely(inode->i_blocks != 0 && inode->i_blocks != 8)) { 1186 - f2fs_warn(F2FS_I_SB(inode), "Inconsistent i_blocks, ino:%lu, iblocks:%llu", 1187 - inode->i_ino, (unsigned long long)inode->i_blocks); 1191 + f2fs_warn(F2FS_I_SB(inode), 1192 + "f2fs_remove_inode_page: inconsistent i_blocks, ino:%lu, iblocks:%llu", 1193 + inode->i_ino, (unsigned long long)inode->i_blocks); 1188 1194 set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK); 1189 1195 } 1190 1196 ··· 1558 1562 if (atomic && !test_opt(sbi, NOBARRIER)) 1559 1563 fio.op_flags |= REQ_PREFLUSH | REQ_FUA; 1560 1564 1561 - set_page_writeback(page); 1562 - ClearPageError(page); 1563 - 1565 + /* should add to global list before clearing PAGECACHE status */ 1564 1566 if (f2fs_in_warm_node_list(sbi, page)) { 1565 1567 seq = f2fs_add_fsync_node_entry(sbi, page); 1566 1568 if (seq_id) 1567 1569 *seq_id = seq; 1568 1570 } 1571 + 1572 + set_page_writeback(page); 1573 + ClearPageError(page); 1569 1574 1570 1575 fio.old_blkaddr = ni.blk_addr; 1571 1576 f2fs_do_write_node_page(nid, &fio); ··· 1976 1979 goto skip_write; 1977 1980 1978 1981 /* balancing f2fs's metadata in background */ 1979 - f2fs_balance_fs_bg(sbi); 1982 + f2fs_balance_fs_bg(sbi, true); 1980 1983 1981 1984 /* collect a number of dirty node pages and write together */ 1982 1985 if (wbc->sync_mode != WB_SYNC_ALL && ··· 2599 2602 retry: 2600 2603 ipage = f2fs_grab_cache_page(NODE_MAPPING(sbi), ino, false); 2601 2604 if (!ipage) { 2602 - congestion_wait(BLK_RW_ASYNC, HZ/50); 2605 + congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT); 2603 2606 goto retry; 2604 2607 } 2605 2608 ··· 3190 3193 3191 3194 int __init f2fs_create_node_manager_caches(void) 3192 3195 { 3193 - nat_entry_slab = f2fs_kmem_cache_create("nat_entry", 3196 + nat_entry_slab = f2fs_kmem_cache_create("f2fs_nat_entry", 3194 3197 sizeof(struct nat_entry)); 3195 3198 if (!nat_entry_slab) 3196 3199 goto fail; 3197 3200 3198 - free_nid_slab = f2fs_kmem_cache_create("free_nid", 3201 + free_nid_slab = f2fs_kmem_cache_create("f2fs_free_nid", 3199 3202 sizeof(struct free_nid)); 3200 3203 if (!free_nid_slab) 3201 3204 goto destroy_nat_entry; 3202 3205 3203 - nat_entry_set_slab = f2fs_kmem_cache_create("nat_entry_set", 3206 + nat_entry_set_slab = f2fs_kmem_cache_create("f2fs_nat_entry_set", 3204 3207 sizeof(struct nat_entry_set)); 3205 3208 if (!nat_entry_set_slab) 3206 3209 goto destroy_free_nid; 3207 3210 3208 - fsync_node_entry_slab = f2fs_kmem_cache_create("fsync_node_entry", 3211 + fsync_node_entry_slab = f2fs_kmem_cache_create("f2fs_fsync_node_entry", 3209 3212 sizeof(struct fsync_node_entry)); 3210 3213 if (!fsync_node_entry_slab) 3211 3214 goto destroy_nat_entry_set;
+6 -6
fs/f2fs/recovery.c
··· 496 496 return 0; 497 497 498 498 truncate_out: 499 - if (datablock_addr(tdn.inode, tdn.node_page, 500 - tdn.ofs_in_node) == blkaddr) 499 + if (f2fs_data_blkaddr(&tdn) == blkaddr) 501 500 f2fs_truncate_data_blocks_range(&tdn, 1); 502 501 if (dn->inode->i_ino == nid && !dn->inode_page_locked) 503 502 unlock_page(dn->inode_page); ··· 534 535 err = f2fs_get_dnode_of_data(&dn, start, ALLOC_NODE); 535 536 if (err) { 536 537 if (err == -ENOMEM) { 537 - congestion_wait(BLK_RW_ASYNC, HZ/50); 538 + congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT); 538 539 goto retry_dn; 539 540 } 540 541 goto out; ··· 559 560 for (; start < end; start++, dn.ofs_in_node++) { 560 561 block_t src, dest; 561 562 562 - src = datablock_addr(dn.inode, dn.node_page, dn.ofs_in_node); 563 - dest = datablock_addr(dn.inode, page, dn.ofs_in_node); 563 + src = f2fs_data_blkaddr(&dn); 564 + dest = data_blkaddr(dn.inode, page, dn.ofs_in_node); 564 565 565 566 if (__is_valid_data_blkaddr(src) && 566 567 !f2fs_is_valid_blkaddr(sbi, src, META_POR)) { ··· 617 618 err = check_index_in_prev_nodes(sbi, dest, &dn); 618 619 if (err) { 619 620 if (err == -ENOMEM) { 620 - congestion_wait(BLK_RW_ASYNC, HZ/50); 621 + congestion_wait(BLK_RW_ASYNC, 622 + DEFAULT_IO_TIMEOUT); 621 623 goto retry_prev; 622 624 } 623 625 goto err;
+28 -26
fs/f2fs/segment.c
··· 172 172 int dent_secs = get_blocktype_secs(sbi, F2FS_DIRTY_DENTS); 173 173 int imeta_secs = get_blocktype_secs(sbi, F2FS_DIRTY_IMETA); 174 174 175 - if (test_opt(sbi, LFS)) 175 + if (f2fs_lfs_mode(sbi)) 176 176 return false; 177 177 if (sbi->gc_mode == GC_URGENT) 178 178 return true; ··· 245 245 LOOKUP_NODE); 246 246 if (err) { 247 247 if (err == -ENOMEM) { 248 - congestion_wait(BLK_RW_ASYNC, HZ/50); 248 + congestion_wait(BLK_RW_ASYNC, 249 + DEFAULT_IO_TIMEOUT); 249 250 cond_resched(); 250 251 goto retry; 251 252 } ··· 313 312 skip: 314 313 iput(inode); 315 314 } 316 - congestion_wait(BLK_RW_ASYNC, HZ/50); 315 + congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT); 317 316 cond_resched(); 318 317 if (gc_failure) { 319 318 if (++looped >= count) ··· 416 415 err = f2fs_do_write_data_page(&fio); 417 416 if (err) { 418 417 if (err == -ENOMEM) { 419 - congestion_wait(BLK_RW_ASYNC, HZ/50); 418 + congestion_wait(BLK_RW_ASYNC, 419 + DEFAULT_IO_TIMEOUT); 420 420 cond_resched(); 421 421 goto retry; 422 422 } ··· 496 494 497 495 /* balance_fs_bg is able to be pending */ 498 496 if (need && excess_cached_nats(sbi)) 499 - f2fs_balance_fs_bg(sbi); 497 + f2fs_balance_fs_bg(sbi, false); 500 498 501 499 if (!f2fs_is_checkpoint_ready(sbi)) 502 500 return; ··· 511 509 } 512 510 } 513 511 514 - void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi) 512 + void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg) 515 513 { 516 514 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) 517 515 return; ··· 540 538 excess_dirty_nats(sbi) || 541 539 excess_dirty_nodes(sbi) || 542 540 f2fs_time_over(sbi, CP_TIME)) { 543 - if (test_opt(sbi, DATA_FLUSH)) { 541 + if (test_opt(sbi, DATA_FLUSH) && from_bg) { 544 542 struct blk_plug plug; 545 543 546 544 mutex_lock(&sbi->flush_lock); ··· 1080 1078 1081 1079 dpolicy->max_requests = DEF_MAX_DISCARD_REQUEST; 1082 1080 dpolicy->io_aware_gran = MAX_PLIST_NUM; 1083 - dpolicy->timeout = 0; 1081 + dpolicy->timeout = false; 1084 1082 1085 1083 if (discard_type == DPOLICY_BG) { 1086 1084 dpolicy->min_interval = DEF_MIN_DISCARD_ISSUE_TIME; ··· 1105 1103 dpolicy->io_aware = false; 1106 1104 /* we need to issue all to keep CP_TRIMMED_FLAG */ 1107 1105 dpolicy->granularity = 1; 1106 + dpolicy->timeout = true; 1108 1107 } 1109 1108 } 1110 1109 ··· 1474 1471 int i, issued = 0; 1475 1472 bool io_interrupted = false; 1476 1473 1477 - if (dpolicy->timeout != 0) 1478 - f2fs_update_time(sbi, dpolicy->timeout); 1474 + if (dpolicy->timeout) 1475 + f2fs_update_time(sbi, UMOUNT_DISCARD_TIMEOUT); 1479 1476 1480 1477 for (i = MAX_PLIST_NUM - 1; i >= 0; i--) { 1481 - if (dpolicy->timeout != 0 && 1482 - f2fs_time_over(sbi, dpolicy->timeout)) 1478 + if (dpolicy->timeout && 1479 + f2fs_time_over(sbi, UMOUNT_DISCARD_TIMEOUT)) 1483 1480 break; 1484 1481 1485 1482 if (i + 1 < dpolicy->granularity) ··· 1500 1497 list_for_each_entry_safe(dc, tmp, pend_list, list) { 1501 1498 f2fs_bug_on(sbi, dc->state != D_PREP); 1502 1499 1503 - if (dpolicy->timeout != 0 && 1504 - f2fs_time_over(sbi, dpolicy->timeout)) 1500 + if (dpolicy->timeout && 1501 + f2fs_time_over(sbi, UMOUNT_DISCARD_TIMEOUT)) 1505 1502 break; 1506 1503 1507 1504 if (dpolicy->io_aware && i < dpolicy->io_aware_gran && ··· 1680 1677 1681 1678 __init_discard_policy(sbi, &dpolicy, DPOLICY_UMOUNT, 1682 1679 dcc->discard_granularity); 1683 - dpolicy.timeout = UMOUNT_DISCARD_TIMEOUT; 1684 1680 __issue_discard_cmd(sbi, &dpolicy); 1685 1681 dropped = __drop_discard_cmd(sbi); 1686 1682 ··· 1942 1940 unsigned int start = 0, end = -1; 1943 1941 unsigned int secno, start_segno; 1944 1942 bool force = (cpc->reason & CP_DISCARD); 1945 - bool need_align = test_opt(sbi, LFS) && __is_large_section(sbi); 1943 + bool need_align = f2fs_lfs_mode(sbi) && __is_large_section(sbi); 1946 1944 1947 1945 mutex_lock(&dirty_i->seglist_lock); 1948 1946 ··· 1974 1972 (end - 1) <= cpc->trim_end) 1975 1973 continue; 1976 1974 1977 - if (!test_opt(sbi, LFS) || !__is_large_section(sbi)) { 1975 + if (!f2fs_lfs_mode(sbi) || !__is_large_section(sbi)) { 1978 1976 f2fs_issue_discard(sbi, START_BLOCK(sbi, start), 1979 1977 (end - start) << sbi->log_blocks_per_seg); 1980 1978 continue; ··· 2803 2801 blk_finish_plug(&plug); 2804 2802 mutex_unlock(&dcc->cmd_lock); 2805 2803 trimmed += __wait_all_discard_cmd(sbi, NULL); 2806 - congestion_wait(BLK_RW_ASYNC, HZ/50); 2804 + congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT); 2807 2805 goto next; 2808 2806 } 2809 2807 skip: ··· 2832 2830 struct discard_policy dpolicy; 2833 2831 unsigned long long trimmed = 0; 2834 2832 int err = 0; 2835 - bool need_align = test_opt(sbi, LFS) && __is_large_section(sbi); 2833 + bool need_align = f2fs_lfs_mode(sbi) && __is_large_section(sbi); 2836 2834 2837 2835 if (start >= MAX_BLKADDR(sbi) || range->len < sbi->blocksize) 2838 2836 return -EINVAL; ··· 3195 3193 static void do_write_page(struct f2fs_summary *sum, struct f2fs_io_info *fio) 3196 3194 { 3197 3195 int type = __get_segment_type(fio); 3198 - bool keep_order = (test_opt(fio->sbi, LFS) && type == CURSEG_COLD_DATA); 3196 + bool keep_order = (f2fs_lfs_mode(fio->sbi) && type == CURSEG_COLD_DATA); 3199 3197 3200 3198 if (keep_order) 3201 3199 down_read(&fio->sbi->io_order_lock); ··· 4073 4071 sit_i->dirty_sentries = 0; 4074 4072 sit_i->sents_per_block = SIT_ENTRY_PER_BLOCK; 4075 4073 sit_i->elapsed_time = le64_to_cpu(sbi->ckpt->elapsed_time); 4076 - sit_i->mounted_time = ktime_get_real_seconds(); 4074 + sit_i->mounted_time = ktime_get_boottime_seconds(); 4077 4075 init_rwsem(&sit_i->sentry_lock); 4078 4076 return 0; 4079 4077 } ··· 4680 4678 if (sm_info->rec_prefree_segments > DEF_MAX_RECLAIM_PREFREE_SEGMENTS) 4681 4679 sm_info->rec_prefree_segments = DEF_MAX_RECLAIM_PREFREE_SEGMENTS; 4682 4680 4683 - if (!test_opt(sbi, LFS)) 4681 + if (!f2fs_lfs_mode(sbi)) 4684 4682 sm_info->ipu_policy = 1 << F2FS_IPU_FSYNC; 4685 4683 sm_info->min_ipu_util = DEF_MIN_IPU_UTIL; 4686 4684 sm_info->min_fsync_blocks = DEF_MIN_FSYNC_BLOCKS; ··· 4832 4830 4833 4831 int __init f2fs_create_segment_manager_caches(void) 4834 4832 { 4835 - discard_entry_slab = f2fs_kmem_cache_create("discard_entry", 4833 + discard_entry_slab = f2fs_kmem_cache_create("f2fs_discard_entry", 4836 4834 sizeof(struct discard_entry)); 4837 4835 if (!discard_entry_slab) 4838 4836 goto fail; 4839 4837 4840 - discard_cmd_slab = f2fs_kmem_cache_create("discard_cmd", 4838 + discard_cmd_slab = f2fs_kmem_cache_create("f2fs_discard_cmd", 4841 4839 sizeof(struct discard_cmd)); 4842 4840 if (!discard_cmd_slab) 4843 4841 goto destroy_discard_entry; 4844 4842 4845 - sit_entry_set_slab = f2fs_kmem_cache_create("sit_entry_set", 4843 + sit_entry_set_slab = f2fs_kmem_cache_create("f2fs_sit_entry_set", 4846 4844 sizeof(struct sit_entry_set)); 4847 4845 if (!sit_entry_set_slab) 4848 4846 goto destroy_discard_cmd; 4849 4847 4850 - inmem_entry_slab = f2fs_kmem_cache_create("inmem_page_entry", 4848 + inmem_entry_slab = f2fs_kmem_cache_create("f2fs_inmem_page_entry", 4851 4849 sizeof(struct inmem_pages)); 4852 4850 if (!inmem_entry_slab) 4853 4851 goto destroy_sit_entry_set;
+1 -1
fs/f2fs/segment.h
··· 756 756 bool base_time) 757 757 { 758 758 struct sit_info *sit_i = SIT_I(sbi); 759 - time64_t diff, now = ktime_get_real_seconds(); 759 + time64_t diff, now = ktime_get_boottime_seconds(); 760 760 761 761 if (now >= sit_i->mounted_time) 762 762 return sit_i->elapsed_time + now - sit_i->mounted_time;
+1 -1
fs/f2fs/shrinker.c
··· 58 58 /* count extent cache entries */ 59 59 count += __count_extent_cache(sbi); 60 60 61 - /* shrink clean nat cache entries */ 61 + /* count clean nat cache entries */ 62 62 count += __count_nat_entries(sbi); 63 63 64 64 /* count free nids cache entries */
+54 -35
fs/f2fs/super.c
··· 428 428 if (!name) 429 429 return -ENOMEM; 430 430 if (strlen(name) == 2 && !strncmp(name, "on", 2)) { 431 - set_opt(sbi, BG_GC); 432 - clear_opt(sbi, FORCE_FG_GC); 431 + F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; 433 432 } else if (strlen(name) == 3 && !strncmp(name, "off", 3)) { 434 - clear_opt(sbi, BG_GC); 435 - clear_opt(sbi, FORCE_FG_GC); 433 + F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF; 436 434 } else if (strlen(name) == 4 && !strncmp(name, "sync", 4)) { 437 - set_opt(sbi, BG_GC); 438 - set_opt(sbi, FORCE_FG_GC); 435 + F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC; 439 436 } else { 440 437 kvfree(name); 441 438 return -EINVAL; ··· 444 447 break; 445 448 case Opt_norecovery: 446 449 /* this option mounts f2fs with ro */ 447 - set_opt(sbi, DISABLE_ROLL_FORWARD); 450 + set_opt(sbi, NORECOVERY); 448 451 if (!f2fs_readonly(sb)) 449 452 return -EINVAL; 450 453 break; ··· 598 601 kvfree(name); 599 602 return -EINVAL; 600 603 } 601 - set_opt_mode(sbi, F2FS_MOUNT_ADAPTIVE); 604 + F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; 602 605 } else if (strlen(name) == 3 && 603 606 !strncmp(name, "lfs", 3)) { 604 - set_opt_mode(sbi, F2FS_MOUNT_LFS); 607 + F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; 605 608 } else { 606 609 kvfree(name); 607 610 return -EINVAL; ··· 830 833 !strcmp(name, "lz4")) { 831 834 F2FS_OPTION(sbi).compress_algorithm = 832 835 COMPRESS_LZ4; 836 + } else if (strlen(name) == 4 && 837 + !strcmp(name, "zstd")) { 838 + F2FS_OPTION(sbi).compress_algorithm = 839 + COMPRESS_ZSTD; 833 840 } else { 834 841 kfree(name); 835 842 return -EINVAL; ··· 906 905 } 907 906 #endif 908 907 909 - if (F2FS_IO_SIZE_BITS(sbi) && !test_opt(sbi, LFS)) { 908 + if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) { 910 909 f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO", 911 910 F2FS_IO_SIZE_KB(sbi)); 912 911 return -EINVAL; ··· 936 935 } 937 936 } 938 937 939 - if (test_opt(sbi, DISABLE_CHECKPOINT) && test_opt(sbi, LFS)) { 938 + if (test_opt(sbi, DISABLE_CHECKPOINT) && f2fs_lfs_mode(sbi)) { 940 939 f2fs_err(sbi, "LFS not compatible with checkpoint=disable\n"); 941 940 return -EINVAL; 942 941 } ··· 962 961 /* Initialize f2fs-specific inode info */ 963 962 atomic_set(&fi->dirty_pages, 0); 964 963 init_rwsem(&fi->i_sem); 964 + spin_lock_init(&fi->i_size_lock); 965 965 INIT_LIST_HEAD(&fi->dirty_list); 966 966 INIT_LIST_HEAD(&fi->gdirty_list); 967 967 INIT_LIST_HEAD(&fi->inmem_ilist); ··· 1175 1173 /* our cp_error case, we can wait for any writeback page */ 1176 1174 f2fs_flush_merged_writes(sbi); 1177 1175 1178 - f2fs_wait_on_all_pages_writeback(sbi); 1176 + f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA); 1179 1177 1180 1178 f2fs_bug_on(sbi, sbi->fsync_node_num); 1181 1179 ··· 1207 1205 kvfree(sbi->raw_super); 1208 1206 1209 1207 destroy_device_list(sbi); 1208 + f2fs_destroy_xattr_caches(sbi); 1210 1209 mempool_destroy(sbi->write_io_dummy); 1211 1210 #ifdef CONFIG_QUOTA 1212 1211 for (i = 0; i < MAXQUOTAS; i++) ··· 1424 1421 case COMPRESS_LZ4: 1425 1422 algtype = "lz4"; 1426 1423 break; 1424 + case COMPRESS_ZSTD: 1425 + algtype = "zstd"; 1426 + break; 1427 1427 } 1428 1428 seq_printf(seq, ",compress_algorithm=%s", algtype); 1429 1429 ··· 1443 1437 { 1444 1438 struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb); 1445 1439 1446 - if (!f2fs_readonly(sbi->sb) && test_opt(sbi, BG_GC)) { 1447 - if (test_opt(sbi, FORCE_FG_GC)) 1448 - seq_printf(seq, ",background_gc=%s", "sync"); 1449 - else 1450 - seq_printf(seq, ",background_gc=%s", "on"); 1451 - } else { 1440 + if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC) 1441 + seq_printf(seq, ",background_gc=%s", "sync"); 1442 + else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON) 1443 + seq_printf(seq, ",background_gc=%s", "on"); 1444 + else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF) 1452 1445 seq_printf(seq, ",background_gc=%s", "off"); 1453 - } 1446 + 1454 1447 if (test_opt(sbi, DISABLE_ROLL_FORWARD)) 1455 1448 seq_puts(seq, ",disable_roll_forward"); 1449 + if (test_opt(sbi, NORECOVERY)) 1450 + seq_puts(seq, ",norecovery"); 1456 1451 if (test_opt(sbi, DISCARD)) 1457 1452 seq_puts(seq, ",discard"); 1458 1453 else ··· 1505 1498 seq_puts(seq, ",data_flush"); 1506 1499 1507 1500 seq_puts(seq, ",mode="); 1508 - if (test_opt(sbi, ADAPTIVE)) 1501 + if (F2FS_OPTION(sbi).fs_mode == FS_MODE_ADAPTIVE) 1509 1502 seq_puts(seq, "adaptive"); 1510 - else if (test_opt(sbi, LFS)) 1503 + else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS) 1511 1504 seq_puts(seq, "lfs"); 1512 1505 seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs); 1513 1506 if (test_opt(sbi, RESERVE_ROOT)) ··· 1578 1571 F2FS_OPTION(sbi).test_dummy_encryption = false; 1579 1572 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID); 1580 1573 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID); 1581 - F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZO; 1574 + F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4; 1582 1575 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE; 1583 1576 F2FS_OPTION(sbi).compress_ext_cnt = 0; 1577 + F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; 1584 1578 1585 - set_opt(sbi, BG_GC); 1586 1579 set_opt(sbi, INLINE_XATTR); 1587 1580 set_opt(sbi, INLINE_DATA); 1588 1581 set_opt(sbi, INLINE_DENTRY); ··· 1594 1587 set_opt(sbi, FLUSH_MERGE); 1595 1588 set_opt(sbi, DISCARD); 1596 1589 if (f2fs_sb_has_blkzoned(sbi)) 1597 - set_opt_mode(sbi, F2FS_MOUNT_LFS); 1590 + F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; 1598 1591 else 1599 - set_opt_mode(sbi, F2FS_MOUNT_ADAPTIVE); 1592 + F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; 1600 1593 1601 1594 #ifdef CONFIG_F2FS_FS_XATTR 1602 1595 set_opt(sbi, XATTR_USER); ··· 1665 1658 out_unlock: 1666 1659 up_write(&sbi->gc_lock); 1667 1660 restore_flag: 1668 - sbi->sb->s_flags = s_flags; /* Restore MS_RDONLY status */ 1661 + sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */ 1669 1662 return err; 1670 1663 } 1671 1664 ··· 1788 1781 * or if background_gc = off is passed in mount 1789 1782 * option. Also sync the filesystem. 1790 1783 */ 1791 - if ((*flags & SB_RDONLY) || !test_opt(sbi, BG_GC)) { 1784 + if ((*flags & SB_RDONLY) || 1785 + F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF) { 1792 1786 if (sbi->gc_thread) { 1793 1787 f2fs_stop_gc_thread(sbi); 1794 1788 need_restart_gc = true; ··· 1894 1886 page = read_cache_page_gfp(mapping, blkidx, GFP_NOFS); 1895 1887 if (IS_ERR(page)) { 1896 1888 if (PTR_ERR(page) == -ENOMEM) { 1897 - congestion_wait(BLK_RW_ASYNC, HZ/50); 1889 + congestion_wait(BLK_RW_ASYNC, 1890 + DEFAULT_IO_TIMEOUT); 1898 1891 goto repeat; 1899 1892 } 1900 1893 set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR); ··· 1937 1928 int offset = off & (sb->s_blocksize - 1); 1938 1929 size_t towrite = len; 1939 1930 struct page *page; 1931 + void *fsdata = NULL; 1940 1932 char *kaddr; 1941 1933 int err = 0; 1942 1934 int tocopy; ··· 1947 1937 towrite); 1948 1938 retry: 1949 1939 err = a_ops->write_begin(NULL, mapping, off, tocopy, 0, 1950 - &page, NULL); 1940 + &page, &fsdata); 1951 1941 if (unlikely(err)) { 1952 1942 if (err == -ENOMEM) { 1953 - congestion_wait(BLK_RW_ASYNC, HZ/50); 1943 + congestion_wait(BLK_RW_ASYNC, 1944 + DEFAULT_IO_TIMEOUT); 1954 1945 goto retry; 1955 1946 } 1956 1947 set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR); ··· 1964 1953 flush_dcache_page(page); 1965 1954 1966 1955 a_ops->write_end(NULL, mapping, off, tocopy, tocopy, 1967 - page, NULL); 1956 + page, fsdata); 1968 1957 offset = 0; 1969 1958 towrite -= tocopy; 1970 1959 off += tocopy; ··· 3468 3457 } 3469 3458 } 3470 3459 3460 + /* init per sbi slab cache */ 3461 + err = f2fs_init_xattr_caches(sbi); 3462 + if (err) 3463 + goto free_io_dummy; 3464 + 3471 3465 /* get an inode for meta space */ 3472 3466 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); 3473 3467 if (IS_ERR(sbi->meta_inode)) { 3474 3468 f2fs_err(sbi, "Failed to read F2FS meta data inode"); 3475 3469 err = PTR_ERR(sbi->meta_inode); 3476 - goto free_io_dummy; 3470 + goto free_xattr_cache; 3477 3471 } 3478 3472 3479 3473 err = f2fs_get_valid_checkpoint(sbi); ··· 3606 3590 f2fs_err(sbi, "Cannot turn on quotas: error %d", err); 3607 3591 } 3608 3592 #endif 3609 - /* if there are nt orphan nodes free them */ 3593 + /* if there are any orphan inodes, free them */ 3610 3594 err = f2fs_recover_orphan_inodes(sbi); 3611 3595 if (err) 3612 3596 goto free_meta; ··· 3615 3599 goto reset_checkpoint; 3616 3600 3617 3601 /* recover fsynced data */ 3618 - if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { 3602 + if (!test_opt(sbi, DISABLE_ROLL_FORWARD) && 3603 + !test_opt(sbi, NORECOVERY)) { 3619 3604 /* 3620 3605 * mount should be failed, when device has readonly mode, and 3621 3606 * previous checkpoint was not done by clean system shutdown. ··· 3682 3665 * If filesystem is not mounted as read-only then 3683 3666 * do start the gc_thread. 3684 3667 */ 3685 - if (test_opt(sbi, BG_GC) && !f2fs_readonly(sb)) { 3668 + if (F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF && !f2fs_readonly(sb)) { 3686 3669 /* After POR, we can run background GC thread.*/ 3687 3670 err = f2fs_start_gc_thread(sbi); 3688 3671 if (err) ··· 3751 3734 make_bad_inode(sbi->meta_inode); 3752 3735 iput(sbi->meta_inode); 3753 3736 sbi->meta_inode = NULL; 3737 + free_xattr_cache: 3738 + f2fs_destroy_xattr_caches(sbi); 3754 3739 free_io_dummy: 3755 3740 mempool_destroy(sbi->write_io_dummy); 3756 3741 free_percpu:
+31 -19
fs/f2fs/sysfs.c
··· 109 109 return sprintf(buf, "0\n"); 110 110 111 111 if (f2fs_sb_has_encrypt(sbi)) 112 - len += snprintf(buf, PAGE_SIZE - len, "%s", 112 + len += scnprintf(buf, PAGE_SIZE - len, "%s", 113 113 "encryption"); 114 114 if (f2fs_sb_has_blkzoned(sbi)) 115 - len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 115 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 116 116 len ? ", " : "", "blkzoned"); 117 117 if (f2fs_sb_has_extra_attr(sbi)) 118 - len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 118 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 119 119 len ? ", " : "", "extra_attr"); 120 120 if (f2fs_sb_has_project_quota(sbi)) 121 - len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 121 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 122 122 len ? ", " : "", "projquota"); 123 123 if (f2fs_sb_has_inode_chksum(sbi)) 124 - len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 124 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 125 125 len ? ", " : "", "inode_checksum"); 126 126 if (f2fs_sb_has_flexible_inline_xattr(sbi)) 127 - len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 127 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 128 128 len ? ", " : "", "flexible_inline_xattr"); 129 129 if (f2fs_sb_has_quota_ino(sbi)) 130 - len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 130 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 131 131 len ? ", " : "", "quota_ino"); 132 132 if (f2fs_sb_has_inode_crtime(sbi)) 133 - len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 133 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 134 134 len ? ", " : "", "inode_crtime"); 135 135 if (f2fs_sb_has_lost_found(sbi)) 136 - len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 136 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 137 137 len ? ", " : "", "lost_found"); 138 138 if (f2fs_sb_has_verity(sbi)) 139 - len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 139 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 140 140 len ? ", " : "", "verity"); 141 141 if (f2fs_sb_has_sb_chksum(sbi)) 142 - len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 142 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 143 143 len ? ", " : "", "sb_checksum"); 144 144 if (f2fs_sb_has_casefold(sbi)) 145 - len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 145 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 146 146 len ? ", " : "", "casefold"); 147 147 if (f2fs_sb_has_compression(sbi)) 148 - len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 148 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 149 149 len ? ", " : "", "compression"); 150 - len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 150 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s%s", 151 151 len ? ", " : "", "pin_file"); 152 - len += snprintf(buf + len, PAGE_SIZE - len, "\n"); 152 + len += scnprintf(buf + len, PAGE_SIZE - len, "\n"); 153 153 return len; 154 154 } 155 155 ··· 183 183 sbi->s_encoding->version & 0xff); 184 184 #endif 185 185 return sprintf(buf, "(none)"); 186 + } 187 + 188 + static ssize_t mounted_time_sec_show(struct f2fs_attr *a, 189 + struct f2fs_sb_info *sbi, char *buf) 190 + { 191 + return sprintf(buf, "%llu", SIT_I(sbi)->mounted_time); 186 192 } 187 193 188 194 #ifdef CONFIG_F2FS_STAT_FS ··· 239 233 int hot_count = sbi->raw_super->hot_ext_count; 240 234 int len = 0, i; 241 235 242 - len += snprintf(buf + len, PAGE_SIZE - len, 236 + len += scnprintf(buf + len, PAGE_SIZE - len, 243 237 "cold file extension:\n"); 244 238 for (i = 0; i < cold_count; i++) 245 - len += snprintf(buf + len, PAGE_SIZE - len, "%s\n", 239 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s\n", 246 240 extlist[i]); 247 241 248 - len += snprintf(buf + len, PAGE_SIZE - len, 242 + len += scnprintf(buf + len, PAGE_SIZE - len, 249 243 "hot file extension:\n"); 250 244 for (i = cold_count; i < cold_count + hot_count; i++) 251 - len += snprintf(buf + len, PAGE_SIZE - len, "%s\n", 245 + len += scnprintf(buf + len, PAGE_SIZE - len, "%s\n", 252 246 extlist[i]); 253 247 return len; 254 248 } ··· 550 544 F2FS_GENERAL_RO_ATTR(current_reserved_blocks); 551 545 F2FS_GENERAL_RO_ATTR(unusable); 552 546 F2FS_GENERAL_RO_ATTR(encoding); 547 + F2FS_GENERAL_RO_ATTR(mounted_time_sec); 553 548 #ifdef CONFIG_F2FS_STAT_FS 554 549 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_foreground_calls, cp_count); 555 550 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_background_calls, bg_cp_count); ··· 580 573 #endif 581 574 F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM); 582 575 F2FS_FEATURE_RO_ATTR(casefold, FEAT_CASEFOLD); 576 + #ifdef CONFIG_F2FS_FS_COMPRESSION 583 577 F2FS_FEATURE_RO_ATTR(compression, FEAT_COMPRESSION); 578 + #endif 584 579 585 580 #define ATTR_LIST(name) (&f2fs_attr_##name.attr) 586 581 static struct attribute *f2fs_attrs[] = { ··· 630 621 ATTR_LIST(reserved_blocks), 631 622 ATTR_LIST(current_reserved_blocks), 632 623 ATTR_LIST(encoding), 624 + ATTR_LIST(mounted_time_sec), 633 625 #ifdef CONFIG_F2FS_STAT_FS 634 626 ATTR_LIST(cp_foreground_calls), 635 627 ATTR_LIST(cp_background_calls), ··· 664 654 #endif 665 655 ATTR_LIST(sb_checksum), 666 656 ATTR_LIST(casefold), 657 + #ifdef CONFIG_F2FS_FS_COMPRESSION 667 658 ATTR_LIST(compression), 659 + #endif 668 660 NULL, 669 661 }; 670 662 ATTRIBUTE_GROUPS(f2fs_feat);
+53 -14
fs/f2fs/xattr.c
··· 23 23 #include "xattr.h" 24 24 #include "segment.h" 25 25 26 + static void *xattr_alloc(struct f2fs_sb_info *sbi, int size, bool *is_inline) 27 + { 28 + if (likely(size == sbi->inline_xattr_slab_size)) { 29 + *is_inline = true; 30 + return kmem_cache_zalloc(sbi->inline_xattr_slab, GFP_NOFS); 31 + } 32 + *is_inline = false; 33 + return f2fs_kzalloc(sbi, size, GFP_NOFS); 34 + } 35 + 36 + static void xattr_free(struct f2fs_sb_info *sbi, void *xattr_addr, 37 + bool is_inline) 38 + { 39 + if (is_inline) 40 + kmem_cache_free(sbi->inline_xattr_slab, xattr_addr); 41 + else 42 + kvfree(xattr_addr); 43 + } 44 + 26 45 static int f2fs_xattr_generic_get(const struct xattr_handler *handler, 27 46 struct dentry *unused, struct inode *inode, 28 47 const char *name, void *buffer, size_t size) ··· 320 301 static int lookup_all_xattrs(struct inode *inode, struct page *ipage, 321 302 unsigned int index, unsigned int len, 322 303 const char *name, struct f2fs_xattr_entry **xe, 323 - void **base_addr, int *base_size) 304 + void **base_addr, int *base_size, 305 + bool *is_inline) 324 306 { 325 307 void *cur_addr, *txattr_addr, *last_txattr_addr; 326 308 void *last_addr = NULL; ··· 332 312 if (!xnid && !inline_size) 333 313 return -ENODATA; 334 314 335 - *base_size = XATTR_SIZE(xnid, inode) + XATTR_PADDING_SIZE; 336 - txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode), *base_size, GFP_NOFS); 315 + *base_size = XATTR_SIZE(inode) + XATTR_PADDING_SIZE; 316 + txattr_addr = xattr_alloc(F2FS_I_SB(inode), *base_size, is_inline); 337 317 if (!txattr_addr) 338 318 return -ENOMEM; 339 319 340 - last_txattr_addr = (void *)txattr_addr + XATTR_SIZE(xnid, inode); 320 + last_txattr_addr = (void *)txattr_addr + XATTR_SIZE(inode); 341 321 342 322 /* read from inline xattr */ 343 323 if (inline_size) { ··· 382 362 *base_addr = txattr_addr; 383 363 return 0; 384 364 out: 385 - kvfree(txattr_addr); 365 + xattr_free(F2FS_I_SB(inode), txattr_addr, *is_inline); 386 366 return err; 387 367 } 388 368 ··· 519 499 unsigned int size, len; 520 500 void *base_addr = NULL; 521 501 int base_size; 502 + bool is_inline; 522 503 523 504 if (name == NULL) 524 505 return -EINVAL; ··· 530 509 531 510 down_read(&F2FS_I(inode)->i_xattr_sem); 532 511 error = lookup_all_xattrs(inode, ipage, index, len, name, 533 - &entry, &base_addr, &base_size); 512 + &entry, &base_addr, &base_size, &is_inline); 534 513 up_read(&F2FS_I(inode)->i_xattr_sem); 535 514 if (error) 536 515 return error; ··· 553 532 } 554 533 error = size; 555 534 out: 556 - kvfree(base_addr); 535 + xattr_free(F2FS_I_SB(inode), base_addr, is_inline); 557 536 return error; 558 537 } 559 538 560 539 ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) 561 540 { 562 541 struct inode *inode = d_inode(dentry); 563 - nid_t xnid = F2FS_I(inode)->i_xattr_nid; 564 542 struct f2fs_xattr_entry *entry; 565 543 void *base_addr, *last_base_addr; 566 544 int error = 0; ··· 571 551 if (error) 572 552 return error; 573 553 574 - last_base_addr = (void *)base_addr + XATTR_SIZE(xnid, inode); 554 + last_base_addr = (void *)base_addr + XATTR_SIZE(inode); 575 555 576 556 list_for_each_xattr(entry, base_addr) { 577 557 const struct xattr_handler *handler = ··· 629 609 { 630 610 struct f2fs_xattr_entry *here, *last; 631 611 void *base_addr, *last_base_addr; 632 - nid_t xnid = F2FS_I(inode)->i_xattr_nid; 633 612 int found, newsize; 634 613 size_t len; 635 614 __u32 new_hsize; ··· 652 633 if (error) 653 634 return error; 654 635 655 - last_base_addr = (void *)base_addr + XATTR_SIZE(xnid, inode); 636 + last_base_addr = (void *)base_addr + XATTR_SIZE(inode); 656 637 657 638 /* find entry with wanted name. */ 658 639 here = __find_xattr(base_addr, last_base_addr, index, len, name); ··· 777 758 f2fs_balance_fs(sbi, true); 778 759 779 760 f2fs_lock_op(sbi); 780 - /* protect xattr_ver */ 781 - down_write(&F2FS_I(inode)->i_sem); 782 761 down_write(&F2FS_I(inode)->i_xattr_sem); 783 762 err = __f2fs_setxattr(inode, index, name, value, size, ipage, flags); 784 763 up_write(&F2FS_I(inode)->i_xattr_sem); 785 - up_write(&F2FS_I(inode)->i_sem); 786 764 f2fs_unlock_op(sbi); 787 765 788 766 f2fs_update_time(sbi, REQ_TIME); 789 767 return err; 768 + } 769 + 770 + int f2fs_init_xattr_caches(struct f2fs_sb_info *sbi) 771 + { 772 + dev_t dev = sbi->sb->s_bdev->bd_dev; 773 + char slab_name[32]; 774 + 775 + sprintf(slab_name, "f2fs_xattr_entry-%u:%u", MAJOR(dev), MINOR(dev)); 776 + 777 + sbi->inline_xattr_slab_size = F2FS_OPTION(sbi).inline_xattr_size * 778 + sizeof(__le32) + XATTR_PADDING_SIZE; 779 + 780 + sbi->inline_xattr_slab = f2fs_kmem_cache_create(slab_name, 781 + sbi->inline_xattr_slab_size); 782 + if (!sbi->inline_xattr_slab) 783 + return -ENOMEM; 784 + 785 + return 0; 786 + } 787 + 788 + void f2fs_destroy_xattr_caches(struct f2fs_sb_info *sbi) 789 + { 790 + kmem_cache_destroy(sbi->inline_xattr_slab); 790 791 }
+7 -2
fs/f2fs/xattr.h
··· 49 49 __u8 e_name_index; 50 50 __u8 e_name_len; 51 51 __le16 e_value_size; /* size of attribute value */ 52 - char e_name[0]; /* attribute name */ 52 + char e_name[]; /* attribute name */ 53 53 }; 54 54 55 55 #define XATTR_HDR(ptr) ((struct f2fs_xattr_header *)(ptr)) ··· 73 73 entry = XATTR_NEXT_ENTRY(entry)) 74 74 #define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer)) 75 75 #define XATTR_PADDING_SIZE (sizeof(__u32)) 76 - #define XATTR_SIZE(x,i) (((x) ? VALID_XATTR_BLOCK_SIZE : 0) + \ 76 + #define XATTR_SIZE(i) ((F2FS_I(i)->i_xattr_nid ? \ 77 + VALID_XATTR_BLOCK_SIZE : 0) + \ 77 78 (inline_xattr_size(i))) 78 79 #define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \ 79 80 VALID_XATTR_BLOCK_SIZE) ··· 131 130 extern int f2fs_getxattr(struct inode *, int, const char *, void *, 132 131 size_t, struct page *); 133 132 extern ssize_t f2fs_listxattr(struct dentry *, char *, size_t); 133 + extern int f2fs_init_xattr_caches(struct f2fs_sb_info *); 134 + extern void f2fs_destroy_xattr_caches(struct f2fs_sb_info *); 134 135 #else 135 136 136 137 #define f2fs_xattr_handlers NULL ··· 153 150 { 154 151 return -EOPNOTSUPP; 155 152 } 153 + static inline int f2fs_init_xattr_caches(struct f2fs_sb_info *sbi) { return 0; } 154 + static inline void f2fs_destroy_xattr_caches(struct f2fs_sb_info *sbi) { } 156 155 #endif 157 156 158 157 #ifdef CONFIG_F2FS_FS_SECURITY
+1
include/linux/f2fs_fs.h
··· 125 125 /* 126 126 * For checkpoint 127 127 */ 128 + #define CP_RESIZEFS_FLAG 0x00004000 128 129 #define CP_DISABLED_QUICK_FLAG 0x00002000 129 130 #define CP_DISABLED_FLAG 0x00001000 130 131 #define CP_QUOTA_NEED_FSCK_FLAG 0x00000800
+2 -1
include/trace/events/f2fs.h
··· 153 153 #define show_compress_algorithm(type) \ 154 154 __print_symbolic(type, \ 155 155 { COMPRESS_LZO, "LZO" }, \ 156 - { COMPRESS_LZ4, "LZ4" }) 156 + { COMPRESS_LZ4, "LZ4" }, \ 157 + { COMPRESS_ZSTD, "ZSTD" }) 157 158 158 159 struct f2fs_sb_info; 159 160 struct f2fs_io_info;