Pull f2fs updates from Jaegeuk Kim: "In this round, we introduced casefolding support in f2fs, and fixed various bugs in individual features such as IO alignment, checkpoint=disable, quota, and swapfile. Enhancement: - support casefolding w/ enhancement in ext4 - support fiemap for directory - support FS_IO_GET|SET_FSLABEL Bug fix: - fix IO stuck during checkpoint=disable - avoid infinite GC loop - fix panic/overflow related to IO alignment feature - fix livelock in swap file - fix discard command leak - disallow dio for atomic_write" * tag 'f2fs-for-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (51 commits) f2fs: add a condition to detect overflow in f2fs_ioc_gc_range() f2fs: fix to add missing F2FS_IO_ALIGNED() condition f2fs: fix to fallback to buffered IO in IO aligned mode f2fs: fix to handle error path correctly in f2fs_map_blocks f2fs: fix extent corrupotion during directIO in LFS mode f2fs: check all the data segments against all node ones f2fs: Add a small clarification to CONFIG_FS_F2FS_FS_SECURITY f2fs: fix inode rwsem regression f2fs: fix to avoid accessing uninitialized field of inode page in is_alive() f2fs: avoid infinite GC loop due to stale atomic files f2fs: Fix indefinite loop in f2fs_gc() f2fs: convert inline_data in prior to i_size_write f2fs: fix error path of f2fs_convert_inline_page() f2fs: add missing documents of reserve_root/resuid/resgid f2fs: fix flushing node pages when checkpoint is disabled f2fs: enhance f2fs_is_checkpoint_ready()'s readability f2fs: clean up __bio_alloc()'s parameter f2fs: fix wrong error injection path in inc_valid_block_count() f2fs: fix to writeout dirty inode during node flush f2fs: optimize case-insensitive lookups ...
Unified · Split
| @@ -251,3 +251,10 @@ Description: · 250 unmodified lines | ||
| 251 | 251 | If checkpoint=disable, it displays the number of blocks that are unusable. |
| 252 | 252 | If checkpoint=enable it displays the enumber of blocks that would be unusable |
| 253 | 253 | if checkpoint=disable were to be set. |
| 254 | + | |
| 255 | +What: /sys/fs/f2fs/<disk>/encoding | |
| 256 | +Date July 2019 | |
| 257 | +Contact: "Daniel Rosenberg" <drosen@google.com> | |
| 258 | +Description: | |
| 259 | + Displays name and version of the encoding set for the filesystem. | |
| 260 | + If no encoding is set, displays (none) | |
| @@ -157,6 +157,11 @@ noinline_data Disable the inline data feature, inline data feature is · 156 unmodified lines | ||
| 157 | 157 | enabled by default. |
| 158 | 158 | data_flush Enable data flushing before checkpoint in order to |
| 159 | 159 | persist data of regular and symlink. |
| 160 | +reserve_root=%d Support configuring reserved space which is used for | |
| 161 | + allocation from a privileged user with specified uid or | |
| 162 | + gid, unit: 4KB, the default limit is 0.2% of user blocks. | |
| 163 | +resuid=%d The user ID which may use the reserved blocks. | |
| 164 | +resgid=%d The group ID which may use the reserved blocks. | |
| 160 | 165 | fault_injection=%d Enable fault injection in all supported types with |
| 161 | 166 | specified injection rate. |
| 162 | 167 | fault_type=%d Support configuring fault injection type, should be |
| @@ -413,6 +418,9 @@ Files in /sys/fs/f2fs/<devname> · 250 unmodified lines | ||
| 413 | 418 | that would be unusable if checkpoint=disable were |
| 414 | 419 | to be set. |
| 415 | 420 | |
| 421 | +encoding This shows the encoding used for casefolding. | |
| 422 | + If casefolding is not enabled, returns (none) | |
| 423 | + | |
| 416 | 424 | ================================================================================ |
| 417 | 425 | USAGE |
| 418 | 426 | ================================================================================ |
| @@ -2,6 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | config F2FS_FS |
| 3 | 3 | tristate "F2FS filesystem support" |
| 4 | 4 | depends on BLOCK |
| 5 | + select NLS | |
| 5 | 6 | select CRYPTO |
| 6 | 7 | select CRYPTO_CRC32 |
| 7 | 8 | select F2FS_FS_XATTR if FS_ENCRYPTION |
| @@ -60,7 +61,9 @@ config F2FS_FS_SECURITY · 52 unmodified lines | ||
| 60 | 61 | Security Models (LSMs) accepted by AppArmor, SELinux, Smack and TOMOYO |
| 61 | 62 | Linux. This option enables an extended attribute handler for file |
| 62 | 63 | security labels in the f2fs filesystem, so that it requires enabling |
| 63 | − the extended attribute support in advance. | |
| 64 | + the extended attribute support in advance. In particular you need this | |
| 65 | + option if you use the setcap command to assign initial process capabi- | |
| 66 | + lities to executables (the security.* extended attributes). | |
| 64 | 67 | |
| 65 | 68 | If you are not using a security module, say N. |
| 66 | 69 | |
| @@ -283,26 +283,25 @@ static bool __same_bdev(struct f2fs_sb_info *sbi, · 282 unmodified lines | ||
| 283 | 283 | /* |
| 284 | 284 | * Low-level block read/write IO operations. |
| 285 | 285 | */ |
| 286 | −static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr, | |
| 287 | − struct writeback_control *wbc, | |
| 288 | − int npages, bool is_read, | |
| 289 | − enum page_type type, enum temp_type temp) | |
| 286 | +static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages) | |
| 290 | 287 | { |
| 288 | + struct f2fs_sb_info *sbi = fio->sbi; | |
| 291 | 289 | struct bio *bio; |
| 292 | 290 | |
| 293 | 291 | bio = f2fs_bio_alloc(sbi, npages, true); |
| 294 | 292 | |
| 295 | − f2fs_target_device(sbi, blk_addr, bio); | |
| 296 | − if (is_read) { | |
| 293 | + f2fs_target_device(sbi, fio->new_blkaddr, bio); | |
| 294 | + if (is_read_io(fio->op)) { | |
| 297 | 295 | bio->bi_end_io = f2fs_read_end_io; |
| 298 | 296 | bio->bi_private = NULL; |
| 299 | 297 | } else { |
| 300 | 298 | bio->bi_end_io = f2fs_write_end_io; |
| 301 | 299 | bio->bi_private = sbi; |
| 302 | − bio->bi_write_hint = f2fs_io_type_to_rw_hint(sbi, type, temp); | |
| 300 | + bio->bi_write_hint = f2fs_io_type_to_rw_hint(sbi, | |
| 301 | + fio->type, fio->temp); | |
| 303 | 302 | } |
| 304 | − if (wbc) | |
| 305 | − wbc_init_bio(wbc, bio); | |
| 303 | + if (fio->io_wbc) | |
| 304 | + wbc_init_bio(fio->io_wbc, bio); | |
| 306 | 305 | |
| 307 | 306 | return bio; |
| 308 | 307 | } |
| @@ -319,6 +318,9 @@ static inline void __submit_bio(struct f2fs_sb_info *sbi, · 10 unmodified lines | ||
| 319 | 318 | if (test_opt(sbi, LFS) && current->plug) |
| 320 | 319 | blk_finish_plug(current->plug); |
| 321 | 320 | |
| 321 | + if (F2FS_IO_ALIGNED(sbi)) | |
| 322 | + goto submit_io; | |
| 323 | + | |
| 322 | 324 | start = bio->bi_iter.bi_size >> F2FS_BLKSIZE_BITS; |
| 323 | 325 | start %= F2FS_IO_SIZE(sbi); |
| 324 | 326 | |
| @@ -485,8 +487,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) · 160 unmodified lines | ||
| 485 | 487 | f2fs_trace_ios(fio, 0); |
| 486 | 488 | |
| 487 | 489 | /* Allocate a new bio */ |
| 488 | − bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc, | |
| 489 | − 1, is_read_io(fio->op), fio->type, fio->temp); | |
| 490 | + bio = __bio_alloc(fio, 1); | |
| 490 | 491 | |
| 491 | 492 | if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { |
| 492 | 493 | bio_put(bio); |
| @@ -505,6 +506,43 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) · 12 unmodified lines | ||
| 505 | 506 | return 0; |
| 506 | 507 | } |
| 507 | 508 | |
| 509 | +static bool page_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio, | |
| 510 | + block_t last_blkaddr, block_t cur_blkaddr) | |
| 511 | +{ | |
| 512 | + if (last_blkaddr + 1 != cur_blkaddr) | |
| 513 | + return false; | |
| 514 | + return __same_bdev(sbi, cur_blkaddr, bio); | |
| 515 | +} | |
| 516 | + | |
| 517 | +static bool io_type_is_mergeable(struct f2fs_bio_info *io, | |
| 518 | + struct f2fs_io_info *fio) | |
| 519 | +{ | |
| 520 | + if (io->fio.op != fio->op) | |
| 521 | + return false; | |
| 522 | + return io->fio.op_flags == fio->op_flags; | |
| 523 | +} | |
| 524 | + | |
| 525 | +static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio, | |
| 526 | + struct f2fs_bio_info *io, | |
| 527 | + struct f2fs_io_info *fio, | |
| 528 | + block_t last_blkaddr, | |
| 529 | + block_t cur_blkaddr) | |
| 530 | +{ | |
| 531 | + if (F2FS_IO_ALIGNED(sbi) && (fio->type == DATA || fio->type == NODE)) { | |
| 532 | + unsigned int filled_blocks = | |
| 533 | + F2FS_BYTES_TO_BLK(bio->bi_iter.bi_size); | |
| 534 | + unsigned int io_size = F2FS_IO_SIZE(sbi); | |
| 535 | + unsigned int left_vecs = bio->bi_max_vecs - bio->bi_vcnt; | |
| 536 | + | |
| 537 | + /* IOs in bio is aligned and left space of vectors is not enough */ | |
| 538 | + if (!(filled_blocks % io_size) && left_vecs < io_size) | |
| 539 | + return false; | |
| 540 | + } | |
| 541 | + if (!page_is_mergeable(sbi, bio, last_blkaddr, cur_blkaddr)) | |
| 542 | + return false; | |
| 543 | + return io_type_is_mergeable(io, fio); | |
| 544 | +} | |
| 545 | + | |
| 508 | 546 | int f2fs_merge_page_bio(struct f2fs_io_info *fio) |
| 509 | 547 | { |
| 510 | 548 | struct bio *bio = *fio->bio; |
| @@ -518,15 +556,14 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) · 7 unmodified lines | ||
| 518 | 556 | trace_f2fs_submit_page_bio(page, fio); |
| 519 | 557 | f2fs_trace_ios(fio, 0); |
| 520 | 558 | |
| 521 | − if (bio && (*fio->last_block + 1 != fio->new_blkaddr || | |
| 522 | − !__same_bdev(fio->sbi, fio->new_blkaddr, bio))) { | |
| 559 | + if (bio && !page_is_mergeable(fio->sbi, bio, *fio->last_block, | |
| 560 | + fio->new_blkaddr)) { | |
| 523 | 561 | __submit_bio(fio->sbi, bio, fio->type); |
| 524 | 562 | bio = NULL; |
| 525 | 563 | } |
| 526 | 564 | alloc_new: |
| 527 | 565 | if (!bio) { |
| 528 | − bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc, | |
| 529 | − BIO_MAX_PAGES, false, fio->type, fio->temp); | |
| 566 | + bio = __bio_alloc(fio, BIO_MAX_PAGES); | |
| 530 | 567 | bio_set_op_attrs(bio, fio->op, fio->op_flags); |
| 531 | 568 | } |
| 532 | 569 | |
| @@ -592,21 +629,19 @@ next: · 59 unmodified lines | ||
| 592 | 629 | |
| 593 | 630 | inc_page_count(sbi, WB_DATA_TYPE(bio_page)); |
| 594 | 631 | |
| 595 | − if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 || | |
| 596 | − (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags) || | |
| 597 | − !__same_bdev(sbi, fio->new_blkaddr, io->bio))) | |
| 632 | + if (io->bio && !io_is_mergeable(sbi, io->bio, io, fio, | |
| 633 | + io->last_block_in_bio, fio->new_blkaddr)) | |
| 598 | 634 | __submit_merged_bio(io); |
| 599 | 635 | alloc_new: |
| 600 | 636 | if (io->bio == NULL) { |
| 601 | − if ((fio->type == DATA || fio->type == NODE) && | |
| 637 | + if (F2FS_IO_ALIGNED(sbi) && | |
| 638 | + (fio->type == DATA || fio->type == NODE) && | |
| 602 | 639 | fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { |
| 603 | 640 | dec_page_count(sbi, WB_DATA_TYPE(bio_page)); |
| 604 | 641 | fio->retry = true; |
| 605 | 642 | goto skip; |
| 606 | 643 | } |
| 607 | − io->bio = __bio_alloc(sbi, fio->new_blkaddr, fio->io_wbc, | |
| 608 | − BIO_MAX_PAGES, false, | |
| 609 | − fio->type, fio->temp); | |
| 644 | + io->bio = __bio_alloc(fio, BIO_MAX_PAGES); | |
| 610 | 645 | io->fio = *fio; |
| 611 | 646 | } |
| 612 | 647 | |
| @@ -627,7 +662,7 @@ skip: · 14 unmodified lines | ||
| 627 | 662 | goto next; |
| 628 | 663 | out: |
| 629 | 664 | if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) || |
| 630 | − f2fs_is_checkpoint_ready(sbi)) | |
| 665 | + !f2fs_is_checkpoint_ready(sbi)) | |
| 631 | 666 | __submit_merged_bio(io); |
| 632 | 667 | up_write(&io->io_rwsem); |
| 633 | 668 | } |
| @@ -1022,7 +1057,7 @@ alloc: · 388 unmodified lines | ||
| 1022 | 1057 | if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) |
| 1023 | 1058 | invalidate_mapping_pages(META_MAPPING(sbi), |
| 1024 | 1059 | old_blkaddr, old_blkaddr); |
| 1025 | − f2fs_set_data_blkaddr(dn); | |
| 1060 | + f2fs_update_data_blkaddr(dn, dn->data_blkaddr); | |
| 1026 | 1061 | |
| 1027 | 1062 | /* |
| 1028 | 1063 | * i_size will be updated by direct_IO. Otherwise, we'll get stale |
| @@ -1199,10 +1234,10 @@ next_block: · 170 unmodified lines | ||
| 1199 | 1234 | if (test_opt(sbi, LFS) && flag == F2FS_GET_BLOCK_DIO && |
| 1200 | 1235 | map->m_may_create) { |
| 1201 | 1236 | err = __allocate_data_block(&dn, map->m_seg_type); |
| 1202 | − if (!err) { | |
| 1203 | − blkaddr = dn.data_blkaddr; | |
| 1204 | − set_inode_flag(inode, FI_APPEND_WRITE); | |
| 1205 | − } | |
| 1237 | + if (err) | |
| 1238 | + goto sync_out; | |
| 1239 | + blkaddr = dn.data_blkaddr; | |
| 1240 | + set_inode_flag(inode, FI_APPEND_WRITE); | |
| 1206 | 1241 | } |
| 1207 | 1242 | } else { |
| 1208 | 1243 | if (create) { |
| @@ -1407,7 +1442,7 @@ static int get_data_block_dio_write(struct inode *inode, sector_t iblock, · 198 unmodified lines | ||
| 1407 | 1442 | return __get_data_block(inode, iblock, bh_result, create, |
| 1408 | 1443 | F2FS_GET_BLOCK_DIO, NULL, |
| 1409 | 1444 | f2fs_rw_hint_to_seg_type(inode->i_write_hint), |
| 1410 | − true); | |
| 1445 | + IS_SWAPFILE(inode) ? false : true); | |
| 1411 | 1446 | } |
| 1412 | 1447 | |
| 1413 | 1448 | static int get_data_block_dio(struct inode *inode, sector_t iblock, |
| @@ -1538,7 +1573,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · 124 unmodified lines | ||
| 1538 | 1573 | goto out; |
| 1539 | 1574 | } |
| 1540 | 1575 | |
| 1541 | − if (f2fs_has_inline_data(inode)) { | |
| 1576 | + if (f2fs_has_inline_data(inode) || f2fs_has_inline_dentry(inode)) { | |
| 1542 | 1577 | ret = f2fs_inline_data_fiemap(inode, fieinfo, start, len); |
| 1543 | 1578 | if (ret != -EAGAIN) |
| 1544 | 1579 | goto out; |
| @@ -1691,8 +1726,8 @@ zero_out: · 146 unmodified lines | ||
| 1691 | 1726 | * This page will go to BIO. Do we need to send this |
| 1692 | 1727 | * BIO off first? |
| 1693 | 1728 | */ |
| 1694 | − if (bio && (*last_block_in_bio != block_nr - 1 || | |
| 1695 | − !__same_bdev(F2FS_I_SB(inode), block_nr, bio))) { | |
| 1729 | + if (bio && !page_is_mergeable(F2FS_I_SB(inode), bio, | |
| 1730 | + *last_block_in_bio, block_nr)) { | |
| 1696 | 1731 | submit_and_realloc: |
| 1697 | 1732 | __submit_bio(F2FS_I_SB(inode), bio, DATA); |
| 1698 | 1733 | bio = NULL; |
| @@ -2590,9 +2625,10 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, · 891 unmodified lines | ||
| 2590 | 2625 | |
| 2591 | 2626 | trace_f2fs_write_begin(inode, pos, len, flags); |
| 2592 | 2627 | |
| 2593 | − err = f2fs_is_checkpoint_ready(sbi); | |
| 2594 | − if (err) | |
| 2628 | + if (!f2fs_is_checkpoint_ready(sbi)) { | |
| 2629 | + err = -ENOSPC; | |
| 2595 | 2630 | goto fail; |
| 2631 | + } | |
| 2596 | 2632 | |
| 2597 | 2633 | if ((f2fs_is_atomic_file(inode) && |
| 2598 | 2634 | !f2fs_available_free_memory(sbi, INMEM_PAGES)) || |
| @@ -67,7 +67,7 @@ static void update_general_status(struct f2fs_sb_info *sbi) · 66 unmodified lines | ||
| 67 | 67 | si->nr_rd_data = get_pages(sbi, F2FS_RD_DATA); |
| 68 | 68 | si->nr_rd_node = get_pages(sbi, F2FS_RD_NODE); |
| 69 | 69 | si->nr_rd_meta = get_pages(sbi, F2FS_RD_META); |
| 70 | − if (SM_I(sbi) && SM_I(sbi)->fcc_info) { | |
| 70 | + if (SM_I(sbi)->fcc_info) { | |
| 71 | 71 | si->nr_flushed = |
| 72 | 72 | atomic_read(&SM_I(sbi)->fcc_info->issued_flush); |
| 73 | 73 | si->nr_flushing = |
| @@ -75,7 +75,7 @@ static void update_general_status(struct f2fs_sb_info *sbi) · 1 unmodified line | ||
| 75 | 75 | si->flush_list_empty = |
| 76 | 76 | llist_empty(&SM_I(sbi)->fcc_info->issue_list); |
| 77 | 77 | } |
| 78 | − if (SM_I(sbi) && SM_I(sbi)->dcc_info) { | |
| 78 | + if (SM_I(sbi)->dcc_info) { | |
| 79 | 79 | si->nr_discarded = |
| 80 | 80 | atomic_read(&SM_I(sbi)->dcc_info->issued_discard); |
| 81 | 81 | si->nr_discarding = |
| @@ -8,6 +8,7 @@ · 7 unmodified lines | ||
| 8 | 8 | #include <linux/fs.h> |
| 9 | 9 | #include <linux/f2fs_fs.h> |
| 10 | 10 | #include <linux/sched/signal.h> |
| 11 | +#include <linux/unicode.h> | |
| 11 | 12 | #include "f2fs.h" |
| 12 | 13 | #include "node.h" |
| 13 | 14 | #include "acl.h" |
| @@ -81,7 +82,8 @@ static unsigned long dir_block_index(unsigned int level, · 67 unmodified lines | ||
| 81 | 82 | return bidx; |
| 82 | 83 | } |
| 83 | 84 | |
| 84 | −static struct f2fs_dir_entry *find_in_block(struct page *dentry_page, | |
| 85 | +static struct f2fs_dir_entry *find_in_block(struct inode *dir, | |
| 86 | + struct page *dentry_page, | |
| 85 | 87 | struct fscrypt_name *fname, |
| 86 | 88 | f2fs_hash_t namehash, |
| 87 | 89 | int *max_slots, |
| @@ -93,7 +95,7 @@ static struct f2fs_dir_entry *find_in_block(struct page *dentry_page, · 5 unmodified lines | ||
| 93 | 95 | |
| 94 | 96 | dentry_blk = (struct f2fs_dentry_block *)page_address(dentry_page); |
| 95 | 97 | |
| 96 | − make_dentry_ptr_block(NULL, &d, dentry_blk); | |
| 98 | + make_dentry_ptr_block(dir, &d, dentry_blk); | |
| 97 | 99 | de = f2fs_find_target_dentry(fname, namehash, max_slots, &d); |
| 98 | 100 | if (de) |
| 99 | 101 | *res_page = dentry_page; |
| @@ -101,14 +103,116 @@ static struct f2fs_dir_entry *find_in_block(struct page *dentry_page, · 1 unmodified line | ||
| 101 | 103 | return de; |
| 102 | 104 | } |
| 103 | 105 | |
| 106 | +#ifdef CONFIG_UNICODE | |
| 107 | +/* | |
| 108 | + * Test whether a case-insensitive directory entry matches the filename | |
| 109 | + * being searched for. | |
| 110 | + * | |
| 111 | + * Returns: 0 if the directory entry matches, more than 0 if it | |
| 112 | + * doesn't match or less than zero on error. | |
| 113 | + */ | |
| 114 | +int f2fs_ci_compare(const struct inode *parent, const struct qstr *name, | |
| 115 | + const struct qstr *entry, bool quick) | |
| 116 | +{ | |
| 117 | + const struct f2fs_sb_info *sbi = F2FS_SB(parent->i_sb); | |
| 118 | + const struct unicode_map *um = sbi->s_encoding; | |
| 119 | + int ret; | |
| 120 | + | |
| 121 | + if (quick) | |
| 122 | + ret = utf8_strncasecmp_folded(um, name, entry); | |
| 123 | + else | |
| 124 | + ret = utf8_strncasecmp(um, name, entry); | |
| 125 | + | |
| 126 | + if (ret < 0) { | |
| 127 | + /* Handle invalid character sequence as either an error | |
| 128 | + * or as an opaque byte sequence. | |
| 129 | + */ | |
| 130 | + if (f2fs_has_strict_mode(sbi)) | |
| 131 | + return -EINVAL; | |
| 132 | + | |
| 133 | + if (name->len != entry->len) | |
| 134 | + return 1; | |
| 135 | + | |
| 136 | + return !!memcmp(name->name, entry->name, name->len); | |
| 137 | + } | |
| 138 | + | |
| 139 | + return ret; | |
| 140 | +} | |
| 141 | + | |
| 142 | +static void f2fs_fname_setup_ci_filename(struct inode *dir, | |
| 143 | + const struct qstr *iname, | |
| 144 | + struct fscrypt_str *cf_name) | |
| 145 | +{ | |
| 146 | + struct f2fs_sb_info *sbi = F2FS_I_SB(dir); | |
| 147 | + | |
| 148 | + if (!IS_CASEFOLDED(dir)) { | |
| 149 | + cf_name->name = NULL; | |
| 150 | + return; | |
| 151 | + } | |
| 152 | + | |
| 153 | + cf_name->name = f2fs_kmalloc(sbi, F2FS_NAME_LEN, GFP_NOFS); | |
| 154 | + if (!cf_name->name) | |
| 155 | + return; | |
| 156 | + | |
| 157 | + cf_name->len = utf8_casefold(sbi->s_encoding, | |
| 158 | + iname, cf_name->name, | |
| 159 | + F2FS_NAME_LEN); | |
| 160 | + if ((int)cf_name->len <= 0) { | |
| 161 | + kvfree(cf_name->name); | |
| 162 | + cf_name->name = NULL; | |
| 163 | + } | |
| 164 | +} | |
| 165 | +#endif | |
| 166 | + | |
| 167 | +static inline bool f2fs_match_name(struct f2fs_dentry_ptr *d, | |
| 168 | + struct f2fs_dir_entry *de, | |
| 169 | + struct fscrypt_name *fname, | |
| 170 | + struct fscrypt_str *cf_str, | |
| 171 | + unsigned long bit_pos, | |
| 172 | + f2fs_hash_t namehash) | |
| 173 | +{ | |
| 174 | +#ifdef CONFIG_UNICODE | |
| 175 | + struct inode *parent = d->inode; | |
| 176 | + struct f2fs_sb_info *sbi = F2FS_I_SB(parent); | |
| 177 | + struct qstr entry; | |
| 178 | +#endif | |
| 179 | + | |
| 180 | + if (de->hash_code != namehash) | |
| 181 | + return false; | |
| 182 | + | |
| 183 | +#ifdef CONFIG_UNICODE | |
| 184 | + entry.name = d->filename[bit_pos]; | |
| 185 | + entry.len = de->name_len; | |
| 186 | + | |
| 187 | + if (sbi->s_encoding && IS_CASEFOLDED(parent)) { | |
| 188 | + if (cf_str->name) { | |
| 189 | + struct qstr cf = {.name = cf_str->name, | |
| 190 | + .len = cf_str->len}; | |
| 191 | + return !f2fs_ci_compare(parent, &cf, &entry, true); | |
| 192 | + } | |
| 193 | + return !f2fs_ci_compare(parent, fname->usr_fname, &entry, | |
| 194 | + false); | |
| 195 | + } | |
| 196 | +#endif | |
| 197 | + if (fscrypt_match_name(fname, d->filename[bit_pos], | |
| 198 | + le16_to_cpu(de->name_len))) | |
| 199 | + return true; | |
| 200 | + return false; | |
| 201 | +} | |
| 202 | + | |
| 104 | 203 | struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, |
| 105 | 204 | f2fs_hash_t namehash, int *max_slots, |
| 106 | 205 | struct f2fs_dentry_ptr *d) |
| 107 | 206 | { |
| 108 | 207 | struct f2fs_dir_entry *de; |
| 208 | + struct fscrypt_str cf_str = { .name = NULL, .len = 0 }; | |
| 109 | 209 | unsigned long bit_pos = 0; |
| 110 | 210 | int max_len = 0; |
| 111 | 211 | |
| 212 | +#ifdef CONFIG_UNICODE | |
| 213 | + f2fs_fname_setup_ci_filename(d->inode, fname->usr_fname, &cf_str); | |
| 214 | +#endif | |
| 215 | + | |
| 112 | 216 | if (max_slots) |
| 113 | 217 | *max_slots = 0; |
| 114 | 218 | while (bit_pos < d->max) { |
| @@ -125,9 +229,7 @@ struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, · 10 unmodified lines | ||
| 125 | 229 | continue; |
| 126 | 230 | } |
| 127 | 231 | |
| 128 | − if (de->hash_code == namehash && | |
| 129 | − fscrypt_match_name(fname, d->filename[bit_pos], | |
| 130 | − le16_to_cpu(de->name_len))) | |
| 232 | + if (f2fs_match_name(d, de, fname, &cf_str, bit_pos, namehash)) | |
| 131 | 233 | goto found; |
| 132 | 234 | |
| 133 | 235 | if (max_slots && max_len > *max_slots) |
| @@ -141,6 +243,10 @@ struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, · 7 unmodified lines | ||
| 141 | 243 | found: |
| 142 | 244 | if (max_slots && max_len > *max_slots) |
| 143 | 245 | *max_slots = max_len; |
| 246 | + | |
| 247 | +#ifdef CONFIG_UNICODE | |
| 248 | + kvfree(cf_str.name); | |
| 249 | +#endif | |
| 144 | 250 | return de; |
| 145 | 251 | } |
| 146 | 252 | |
| @@ -157,7 +263,7 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir, · 10 unmodified lines | ||
| 157 | 263 | struct f2fs_dir_entry *de = NULL; |
| 158 | 264 | bool room = false; |
| 159 | 265 | int max_slots; |
| 160 | − f2fs_hash_t namehash = f2fs_dentry_hash(&name, fname); | |
| 266 | + f2fs_hash_t namehash = f2fs_dentry_hash(dir, &name, fname); | |
| 161 | 267 | |
| 162 | 268 | nbucket = dir_buckets(level, F2FS_I(dir)->i_dir_level); |
| 163 | 269 | nblock = bucket_blocks(level); |
| @@ -179,8 +285,8 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir, · 15 unmodified lines | ||
| 179 | 285 | } |
| 180 | 286 | } |
| 181 | 287 | |
| 182 | − de = find_in_block(dentry_page, fname, namehash, &max_slots, | |
| 183 | − res_page); | |
| 288 | + de = find_in_block(dir, dentry_page, fname, namehash, | |
| 289 | + &max_slots, res_page); | |
| 184 | 290 | if (de) |
| 185 | 291 | break; |
| 186 | 292 | |
| @@ -250,6 +356,14 @@ struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, · 63 unmodified lines | ||
| 250 | 356 | struct fscrypt_name fname; |
| 251 | 357 | int err; |
| 252 | 358 | |
| 359 | +#ifdef CONFIG_UNICODE | |
| 360 | + if (f2fs_has_strict_mode(F2FS_I_SB(dir)) && IS_CASEFOLDED(dir) && | |
| 361 | + utf8_validate(F2FS_I_SB(dir)->s_encoding, child)) { | |
| 362 | + *res_page = ERR_PTR(-EINVAL); | |
| 363 | + return NULL; | |
| 364 | + } | |
| 365 | +#endif | |
| 366 | + | |
| 253 | 367 | err = fscrypt_setup_filename(dir, child, 1, &fname); |
| 254 | 368 | if (err) { |
| 255 | 369 | if (err == -ENOENT) |
| @@ -504,7 +618,7 @@ int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, · 248 unmodified lines | ||
| 504 | 618 | |
| 505 | 619 | level = 0; |
| 506 | 620 | slots = GET_DENTRY_SLOTS(new_name->len); |
| 507 | − dentry_hash = f2fs_dentry_hash(new_name, NULL); | |
| 621 | + dentry_hash = f2fs_dentry_hash(dir, new_name, NULL); | |
| 508 | 622 | |
| 509 | 623 | current_depth = F2FS_I(dir)->i_current_depth; |
| 510 | 624 | if (F2FS_I(dir)->chash == dentry_hash) { |
| @@ -568,6 +682,11 @@ add_dentry: · 57 unmodified lines | ||
| 568 | 682 | |
| 569 | 683 | if (inode) { |
| 570 | 684 | f2fs_i_pino_write(inode, dir->i_ino); |
| 685 | + | |
| 686 | + /* synchronize inode page's data from inode cache */ | |
| 687 | + if (is_inode_flag_set(inode, FI_NEW_INODE)) | |
| 688 | + f2fs_update_inode(inode, page); | |
| 689 | + | |
| 571 | 690 | f2fs_put_page(page, 1); |
| 572 | 691 | } |
| 573 | 692 | |
| @@ -943,3 +1062,50 @@ const struct file_operations f2fs_dir_operations = { · 369 unmodified lines | ||
| 943 | 1062 | .compat_ioctl = f2fs_compat_ioctl, |
| 944 | 1063 | #endif |
| 945 | 1064 | }; |
| 1065 | + | |
| 1066 | +#ifdef CONFIG_UNICODE | |
| 1067 | +static int f2fs_d_compare(const struct dentry *dentry, unsigned int len, | |
| 1068 | + const char *str, const struct qstr *name) | |
| 1069 | +{ | |
| 1070 | + struct qstr qstr = {.name = str, .len = len }; | |
| 1071 | + | |
| 1072 | + if (!IS_CASEFOLDED(dentry->d_parent->d_inode)) { | |
| 1073 | + if (len != name->len) | |
| 1074 | + return -1; | |
| 1075 | + return memcmp(str, name, len); | |
| 1076 | + } | |
| 1077 | + | |
| 1078 | + return f2fs_ci_compare(dentry->d_parent->d_inode, name, &qstr, false); | |
| 1079 | +} | |
| 1080 | + | |
| 1081 | +static int f2fs_d_hash(const struct dentry *dentry, struct qstr *str) | |
| 1082 | +{ | |
| 1083 | + struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb); | |
| 1084 | + const struct unicode_map *um = sbi->s_encoding; | |
| 1085 | + unsigned char *norm; | |
| 1086 | + int len, ret = 0; | |
| 1087 | + | |
| 1088 | + if (!IS_CASEFOLDED(dentry->d_inode)) | |
| 1089 | + return 0; | |
| 1090 | + | |
| 1091 | + norm = f2fs_kmalloc(sbi, PATH_MAX, GFP_ATOMIC); | |
| 1092 | + if (!norm) | |
| 1093 | + return -ENOMEM; | |
| 1094 | + | |
| 1095 | + len = utf8_casefold(um, str, norm, PATH_MAX); | |
| 1096 | + if (len < 0) { | |
| 1097 | + if (f2fs_has_strict_mode(sbi)) | |
| 1098 | + ret = -EINVAL; | |
| 1099 | + goto out; | |
| 1100 | + } | |
| 1101 | + str->hash = full_name_hash(dentry, norm, len); | |
| 1102 | +out: | |
| 1103 | + kvfree(norm); | |
| 1104 | + return ret; | |
| 1105 | +} | |
| 1106 | + | |
| 1107 | +const struct dentry_operations f2fs_dentry_ops = { | |
| 1108 | + .d_hash = f2fs_d_hash, | |
| 1109 | + .d_compare = f2fs_d_compare, | |
| 1110 | +}; | |
| 1111 | +#endif | |
| @@ -154,6 +154,7 @@ struct f2fs_mount_info { · 153 unmodified lines | ||
| 154 | 154 | #define F2FS_FEATURE_LOST_FOUND 0x0200 |
| 155 | 155 | #define F2FS_FEATURE_VERITY 0x0400 |
| 156 | 156 | #define F2FS_FEATURE_SB_CHKSUM 0x0800 |
| 157 | +#define F2FS_FEATURE_CASEFOLD 0x1000 | |
| 157 | 158 | |
| 158 | 159 | #define __F2FS_HAS_FEATURE(raw_super, mask) \ |
| 159 | 160 | ((raw_super->feature & cpu_to_le32(mask)) != 0) |
| @@ -418,6 +419,9 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal, · 258 unmodified lines | ||
| 418 | 419 | #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) |
| 419 | 420 | #define F2FS_IOC_RESIZE_FS _IOW(F2FS_IOCTL_MAGIC, 16, __u64) |
| 420 | 421 | |
| 422 | +#define F2FS_IOC_GET_VOLUME_NAME FS_IOC_GETFSLABEL | |
| 423 | +#define F2FS_IOC_SET_VOLUME_NAME FS_IOC_SETFSLABEL | |
| 424 | + | |
| 421 | 425 | #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY |
| 422 | 426 | #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY |
| 423 | 427 | #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT |
| @@ -1172,6 +1176,10 @@ struct f2fs_sb_info { · 748 unmodified lines | ||
| 1172 | 1176 | int valid_super_block; /* valid super block no */ |
| 1173 | 1177 | unsigned long s_flag; /* flags for sbi */ |
| 1174 | 1178 | struct mutex writepages; /* mutex for writepages() */ |
| 1179 | +#ifdef CONFIG_UNICODE | |
| 1180 | + struct unicode_map *s_encoding; | |
| 1181 | + __u16 s_encoding_flags; | |
| 1182 | +#endif | |
| 1175 | 1183 | |
| 1176 | 1184 | #ifdef CONFIG_BLK_DEV_ZONED |
| 1177 | 1185 | unsigned int blocks_per_blkz; /* F2FS blocks per zone */ |
| @@ -1643,6 +1651,7 @@ static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) · 465 unmodified lines | ||
| 1643 | 1651 | static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) |
| 1644 | 1652 | { |
| 1645 | 1653 | unsigned long flags; |
| 1654 | + unsigned char *nat_bits; | |
| 1646 | 1655 | |
| 1647 | 1656 | /* |
| 1648 | 1657 | * In order to re-enable nat_bits we need to call fsck.f2fs by |
| @@ -1653,10 +1662,12 @@ static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) · 4 unmodified lines | ||
| 1653 | 1662 | if (lock) |
| 1654 | 1663 | spin_lock_irqsave(&sbi->cp_lock, flags); |
| 1655 | 1664 | __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); |
| 1656 | − kvfree(NM_I(sbi)->nat_bits); | |
| 1665 | + nat_bits = NM_I(sbi)->nat_bits; | |
| 1657 | 1666 | NM_I(sbi)->nat_bits = NULL; |
| 1658 | 1667 | if (lock) |
| 1659 | 1668 | spin_unlock_irqrestore(&sbi->cp_lock, flags); |
| 1669 | + | |
| 1670 | + kvfree(nat_bits); | |
| 1660 | 1671 | } |
| 1661 | 1672 | |
| 1662 | 1673 | static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, |
| @@ -1763,7 +1774,7 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, · 100 unmodified lines | ||
| 1763 | 1774 | if (time_to_inject(sbi, FAULT_BLOCK)) { |
| 1764 | 1775 | f2fs_show_injection_info(FAULT_BLOCK); |
| 1765 | 1776 | release = *count; |
| 1766 | − goto enospc; | |
| 1777 | + goto release_quota; | |
| 1767 | 1778 | } |
| 1768 | 1779 | |
| 1769 | 1780 | /* |
| @@ -1808,6 +1819,7 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, · 38 unmodified lines | ||
| 1808 | 1819 | |
| 1809 | 1820 | enospc: |
| 1810 | 1821 | percpu_counter_sub(&sbi->alloc_valid_block_count, release); |
| 1822 | +release_quota: | |
| 1811 | 1823 | dquot_release_reservation_block(inode, release); |
| 1812 | 1824 | return -ENOSPC; |
| 1813 | 1825 | } |
| @@ -2362,13 +2374,16 @@ static inline void f2fs_change_bit(unsigned int nr, char *addr) · 548 unmodified lines | ||
| 2362 | 2374 | #define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */ |
| 2363 | 2375 | #define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ |
| 2364 | 2376 | #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ |
| 2377 | +#define F2FS_CASEFOLD_FL 0x40000000 /* Casefolded file */ | |
| 2365 | 2378 | |
| 2366 | 2379 | /* Flags that should be inherited by new inodes from their parent. */ |
| 2367 | 2380 | #define F2FS_FL_INHERITED (F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL | \ |
| 2368 | − F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL) | |
| 2381 | + F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ | |
| 2382 | + F2FS_CASEFOLD_FL) | |
| 2369 | 2383 | |
| 2370 | 2384 | /* Flags that are appropriate for regular files (all but dir-specific ones). */ |
| 2371 | −#define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL)) | |
| 2385 | +#define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ | |
| 2386 | + F2FS_CASEFOLD_FL)) | |
| 2372 | 2387 | |
| 2373 | 2388 | /* Flags that are appropriate for non-directories/regular files. */ |
| 2374 | 2389 | #define F2FS_OTHER_FLMASK (F2FS_NODUMP_FL | F2FS_NOATIME_FL) |
| @@ -2935,6 +2950,11 @@ int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, · 560 unmodified lines | ||
| 2935 | 2950 | bool hot, bool set); |
| 2936 | 2951 | struct dentry *f2fs_get_parent(struct dentry *child); |
| 2937 | 2952 | |
| 2953 | +extern int f2fs_ci_compare(const struct inode *parent, | |
| 2954 | + const struct qstr *name, | |
| 2955 | + const struct qstr *entry, | |
| 2956 | + bool quick); | |
| 2957 | + | |
| 2938 | 2958 | /* |
| 2939 | 2959 | * dir.c |
| 2940 | 2960 | */ |
| @@ -2998,8 +3018,8 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); · 57 unmodified lines | ||
| 2998 | 3018 | /* |
| 2999 | 3019 | * hash.c |
| 3000 | 3020 | */ |
| 3001 | −f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, | |
| 3002 | − struct fscrypt_name *fname); | |
| 3021 | +f2fs_hash_t f2fs_dentry_hash(const struct inode *dir, | |
| 3022 | + const struct qstr *name_info, struct fscrypt_name *fname); | |
| 3003 | 3023 | |
| 3004 | 3024 | /* |
| 3005 | 3025 | * node.c |
| @@ -3442,6 +3462,9 @@ static inline void f2fs_destroy_root_stats(void) { } · 436 unmodified lines | ||
| 3442 | 3462 | #endif |
| 3443 | 3463 | |
| 3444 | 3464 | extern const struct file_operations f2fs_dir_operations; |
| 3465 | +#ifdef CONFIG_UNICODE | |
| 3466 | +extern const struct dentry_operations f2fs_dentry_ops; | |
| 3467 | +#endif | |
| 3445 | 3468 | extern const struct file_operations f2fs_file_operations; |
| 3446 | 3469 | extern const struct inode_operations f2fs_file_inode_operations; |
| 3447 | 3470 | extern const struct address_space_operations f2fs_dblock_aops; |
| @@ -3576,6 +3599,7 @@ F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); · 128 unmodified lines | ||
| 3576 | 3599 | F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); |
| 3577 | 3600 | F2FS_FEATURE_FUNCS(verity, VERITY); |
| 3578 | 3601 | F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); |
| 3602 | +F2FS_FEATURE_FUNCS(casefold, CASEFOLD); | |
| 3579 | 3603 | |
| 3580 | 3604 | #ifdef CONFIG_BLK_DEV_ZONED |
| 3581 | 3605 | static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi, |
| @@ -3694,11 +3718,14 @@ static inline bool f2fs_force_buffered_io(struct inode *inode, · 112 unmodified lines | ||
| 3694 | 3718 | */ |
| 3695 | 3719 | if (f2fs_sb_has_blkzoned(sbi)) |
| 3696 | 3720 | return true; |
| 3697 | − if (test_opt(sbi, LFS) && (rw == WRITE) && | |
| 3698 | − block_unaligned_IO(inode, iocb, iter)) | |
| 3699 | − return true; | |
| 3721 | + if (test_opt(sbi, LFS) && (rw == WRITE)) { | |
| 3722 | + if (block_unaligned_IO(inode, iocb, iter)) | |
| 3723 | + return true; | |
| 3724 | + if (F2FS_IO_ALIGNED(sbi)) | |
| 3725 | + return true; | |
| 3726 | + } | |
| 3700 | 3727 | if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED) && |
| 3701 | − !(inode->i_flags & S_SWAPFILE)) | |
| 3728 | + !IS_SWAPFILE(inode)) | |
| 3702 | 3729 | return true; |
| 3703 | 3730 | |
| 3704 | 3731 | return false; |
| @@ -20,6 +20,7 @@ · 19 unmodified lines | ||
| 20 | 20 | #include <linux/uio.h> |
| 21 | 21 | #include <linux/uuid.h> |
| 22 | 22 | #include <linux/file.h> |
| 23 | +#include <linux/nls.h> | |
| 23 | 24 | |
| 24 | 25 | #include "f2fs.h" |
| 25 | 26 | #include "node.h" |
| @@ -57,6 +58,11 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) · 31 unmodified lines | ||
| 57 | 58 | goto err; |
| 58 | 59 | } |
| 59 | 60 | |
| 61 | + if (!f2fs_is_checkpoint_ready(sbi)) { | |
| 62 | + err = -ENOSPC; | |
| 63 | + goto err; | |
| 64 | + } | |
| 65 | + | |
| 60 | 66 | sb_start_pagefault(inode->i_sb); |
| 61 | 67 | |
| 62 | 68 | f2fs_bug_on(sbi, f2fs_has_inline_data(inode)); |
| @@ -819,14 +825,24 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) · 756 unmodified lines | ||
| 819 | 825 | } |
| 820 | 826 | |
| 821 | 827 | if (attr->ia_valid & ATTR_SIZE) { |
| 822 | − bool to_smaller = (attr->ia_size <= i_size_read(inode)); | |
| 828 | + loff_t old_size = i_size_read(inode); | |
| 829 | + | |
| 830 | + if (attr->ia_size > MAX_INLINE_DATA(inode)) { | |
| 831 | + /* | |
| 832 | + * should convert inline inode before i_size_write to | |
| 833 | + * keep smaller than inline_data size with inline flag. | |
| 834 | + */ | |
| 835 | + err = f2fs_convert_inline_inode(inode); | |
| 836 | + if (err) | |
| 837 | + return err; | |
| 838 | + } | |
| 823 | 839 | |
| 824 | 840 | down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
| 825 | 841 | down_write(&F2FS_I(inode)->i_mmap_sem); |
| 826 | 842 | |
| 827 | 843 | truncate_setsize(inode, attr->ia_size); |
| 828 | 844 | |
| 829 | − if (to_smaller) | |
| 845 | + if (attr->ia_size <= old_size) | |
| 830 | 846 | err = f2fs_truncate(inode); |
| 831 | 847 | /* |
| 832 | 848 | * do not trim all blocks after i_size if target size is |
| @@ -834,21 +850,11 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) · 1 unmodified line | ||
| 834 | 850 | */ |
| 835 | 851 | up_write(&F2FS_I(inode)->i_mmap_sem); |
| 836 | 852 | up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
| 837 | − | |
| 838 | 853 | if (err) |
| 839 | 854 | return err; |
| 840 | 855 | |
| 841 | − if (!to_smaller) { | |
| 842 | − /* should convert inline inode here */ | |
| 843 | − if (!f2fs_may_inline_data(inode)) { | |
| 844 | − err = f2fs_convert_inline_inode(inode); | |
| 845 | − if (err) | |
| 846 | − return err; | |
| 847 | − } | |
| 848 | − inode->i_mtime = inode->i_ctime = current_time(inode); | |
| 849 | − } | |
| 850 | − | |
| 851 | 856 | down_write(&F2FS_I(inode)->i_sem); |
| 857 | + inode->i_mtime = inode->i_ctime = current_time(inode); | |
| 852 | 858 | F2FS_I(inode)->last_disk_size = i_size_read(inode); |
| 853 | 859 | up_write(&F2FS_I(inode)->i_sem); |
| 854 | 860 | } |
| @@ -1041,7 +1047,7 @@ next_dnode: · 186 unmodified lines | ||
| 1041 | 1047 | |
| 1042 | 1048 | if (test_opt(sbi, LFS)) { |
| 1043 | 1049 | f2fs_put_dnode(&dn); |
| 1044 | − return -ENOTSUPP; | |
| 1050 | + return -EOPNOTSUPP; | |
| 1045 | 1051 | } |
| 1046 | 1052 | |
| 1047 | 1053 | /* do not invalidate this block address */ |
| @@ -1578,6 +1584,8 @@ static long f2fs_fallocate(struct file *file, int mode, · 530 unmodified lines | ||
| 1578 | 1584 | |
| 1579 | 1585 | if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) |
| 1580 | 1586 | return -EIO; |
| 1587 | + if (!f2fs_is_checkpoint_ready(F2FS_I_SB(inode))) | |
| 1588 | + return -ENOSPC; | |
| 1581 | 1589 | |
| 1582 | 1590 | /* f2fs only support ->fallocate for regular file */ |
| 1583 | 1591 | if (!S_ISREG(inode->i_mode)) |
| @@ -1669,6 +1677,13 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask) · 85 unmodified lines | ||
| 1669 | 1677 | if (IS_NOQUOTA(inode)) |
| 1670 | 1678 | return -EPERM; |
| 1671 | 1679 | |
| 1680 | + if ((iflags ^ fi->i_flags) & F2FS_CASEFOLD_FL) { | |
| 1681 | + if (!f2fs_sb_has_casefold(F2FS_I_SB(inode))) | |
| 1682 | + return -EOPNOTSUPP; | |
| 1683 | + if (!f2fs_empty_dir(inode)) | |
| 1684 | + return -ENOTEMPTY; | |
| 1685 | + } | |
| 1686 | + | |
| 1672 | 1687 | fi->i_flags = iflags | (fi->i_flags & ~mask); |
| 1673 | 1688 | |
| 1674 | 1689 | if (fi->i_flags & F2FS_PROJINHERIT_FL) |
| @@ -1703,6 +1718,7 @@ static const struct { · 28 unmodified lines | ||
| 1703 | 1718 | { F2FS_INDEX_FL, FS_INDEX_FL }, |
| 1704 | 1719 | { F2FS_DIRSYNC_FL, FS_DIRSYNC_FL }, |
| 1705 | 1720 | { F2FS_PROJINHERIT_FL, FS_PROJINHERIT_FL }, |
| 1721 | + { F2FS_CASEFOLD_FL, FS_CASEFOLD_FL }, | |
| 1706 | 1722 | }; |
| 1707 | 1723 | |
| 1708 | 1724 | #define F2FS_GETTABLE_FS_FL ( \ |
| @@ -1717,7 +1733,8 @@ static const struct { · 8 unmodified lines | ||
| 1717 | 1733 | FS_ENCRYPT_FL | \ |
| 1718 | 1734 | FS_INLINE_DATA_FL | \ |
| 1719 | 1735 | FS_NOCOW_FL | \ |
| 1720 | − FS_VERITY_FL) | |
| 1736 | + FS_VERITY_FL | \ | |
| 1737 | + FS_CASEFOLD_FL) | |
| 1721 | 1738 | |
| 1722 | 1739 | #define F2FS_SETTABLE_FS_FL ( \ |
| 1723 | 1740 | FS_SYNC_FL | \ |
| @@ -1726,7 +1743,8 @@ static const struct { · 2 unmodified lines | ||
| 1726 | 1743 | FS_NODUMP_FL | \ |
| 1727 | 1744 | FS_NOATIME_FL | \ |
| 1728 | 1745 | FS_DIRSYNC_FL | \ |
| 1729 | − FS_PROJINHERIT_FL) | |
| 1746 | + FS_PROJINHERIT_FL | \ | |
| 1747 | + FS_CASEFOLD_FL) | |
| 1730 | 1748 | |
| 1731 | 1749 | /* Convert f2fs on-disk i_flags to FS_IOC_{GET,SET}FLAGS flags */ |
| 1732 | 1750 | static inline u32 f2fs_iflags_to_fsflags(u32 iflags) |
| @@ -1825,6 +1843,8 @@ static int f2fs_ioc_getversion(struct file *filp, unsigned long arg) · 92 unmodified lines | ||
| 1825 | 1843 | static int f2fs_ioc_start_atomic_write(struct file *filp) |
| 1826 | 1844 | { |
| 1827 | 1845 | struct inode *inode = file_inode(filp); |
| 1846 | + struct f2fs_inode_info *fi = F2FS_I(inode); | |
| 1847 | + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | |
| 1828 | 1848 | int ret; |
| 1829 | 1849 | |
| 1830 | 1850 | if (!inode_owner_or_capable(inode)) |
| @@ -1833,6 +1853,9 @@ static int f2fs_ioc_start_atomic_write(struct file *filp) · 2 unmodified lines | ||
| 1833 | 1853 | if (!S_ISREG(inode->i_mode)) |
| 1834 | 1854 | return -EINVAL; |
| 1835 | 1855 | |
| 1856 | + if (filp->f_flags & O_DIRECT) | |
| 1857 | + return -EINVAL; | |
| 1858 | + | |
| 1836 | 1859 | ret = mnt_want_write_file(filp); |
| 1837 | 1860 | if (ret) |
| 1838 | 1861 | return ret; |
| @@ -1864,6 +1887,12 @@ static int f2fs_ioc_start_atomic_write(struct file *filp) · 25 unmodified lines | ||
| 1864 | 1887 | goto out; |
| 1865 | 1888 | } |
| 1866 | 1889 | |
| 1890 | + spin_lock(&sbi->inode_lock[ATOMIC_FILE]); | |
| 1891 | + if (list_empty(&fi->inmem_ilist)) | |
| 1892 | + list_add_tail(&fi->inmem_ilist, &sbi->inode_list[ATOMIC_FILE]); | |
| 1893 | + spin_unlock(&sbi->inode_lock[ATOMIC_FILE]); | |
| 1894 | + | |
| 1895 | + /* add inode in inmem_list first and set atomic_file */ | |
| 1867 | 1896 | set_inode_flag(inode, FI_ATOMIC_FILE); |
| 1868 | 1897 | clear_inode_flag(inode, FI_ATOMIC_REVOKE_REQUEST); |
| 1869 | 1898 | up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
| @@ -1905,11 +1934,8 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp) · 35 unmodified lines | ||
| 1905 | 1934 | goto err_out; |
| 1906 | 1935 | |
| 1907 | 1936 | ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 0, true); |
| 1908 | − if (!ret) { | |
| 1909 | − clear_inode_flag(inode, FI_ATOMIC_FILE); | |
| 1910 | − F2FS_I(inode)->i_gc_failures[GC_FAILURE_ATOMIC] = 0; | |
| 1911 | − stat_dec_atomic_write(inode); | |
| 1912 | − } | |
| 1937 | + if (!ret) | |
| 1938 | + f2fs_drop_inmem_pages(inode); | |
| 1913 | 1939 | } else { |
| 1914 | 1940 | ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 1, false); |
| 1915 | 1941 | } |
| @@ -2295,9 +2321,9 @@ static int f2fs_ioc_gc_range(struct file *filp, unsigned long arg) · 379 unmodified lines | ||
| 2295 | 2321 | return -EROFS; |
| 2296 | 2322 | |
| 2297 | 2323 | end = range.start + range.len; |
| 2298 | − if (range.start < MAIN_BLKADDR(sbi) || end >= MAX_BLKADDR(sbi)) { | |
| 2324 | + if (end < range.start || range.start < MAIN_BLKADDR(sbi) || | |
| 2325 | + end >= MAX_BLKADDR(sbi)) | |
| 2299 | 2326 | return -EINVAL; |
| 2300 | − } | |
| 2301 | 2327 | |
| 2302 | 2328 | ret = mnt_want_write_file(filp); |
| 2303 | 2329 | if (ret) |
| @@ -2421,8 +2447,10 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, · 117 unmodified lines | ||
| 2421 | 2447 | map.m_lblk += map.m_len; |
| 2422 | 2448 | } |
| 2423 | 2449 | |
| 2424 | − if (!fragmented) | |
| 2450 | + if (!fragmented) { | |
| 2451 | + total = 0; | |
| 2425 | 2452 | goto out; |
| 2453 | + } | |
| 2426 | 2454 | |
| 2427 | 2455 | sec_num = DIV_ROUND_UP(total, BLKS_PER_SEC(sbi)); |
| 2428 | 2456 | |
| @@ -2452,7 +2480,7 @@ do_map: · 23 unmodified lines | ||
| 2452 | 2480 | |
| 2453 | 2481 | if (!(map.m_flags & F2FS_MAP_FLAGS)) { |
| 2454 | 2482 | map.m_lblk = next_pgofs; |
| 2455 | − continue; | |
| 2483 | + goto check; | |
| 2456 | 2484 | } |
| 2457 | 2485 | |
| 2458 | 2486 | set_inode_flag(inode, FI_DO_DEFRAG); |
| @@ -2476,8 +2504,8 @@ do_map: · 17 unmodified lines | ||
| 2476 | 2504 | } |
| 2477 | 2505 | |
| 2478 | 2506 | map.m_lblk = idx; |
| 2479 | − | |
| 2480 | − if (idx < pg_end && cnt < blk_per_seg) | |
| 2507 | +check: | |
| 2508 | + if (map.m_lblk < pg_end && cnt < blk_per_seg) | |
| 2481 | 2509 | goto do_map; |
| 2482 | 2510 | |
| 2483 | 2511 | clear_inode_flag(inode, FI_DO_DEFRAG); |
| @@ -3141,10 +3169,74 @@ static int f2fs_ioc_measure_verity(struct file *filp, unsigned long arg) · 657 unmodified lines | ||
| 3141 | 3169 | return fsverity_ioctl_measure(filp, (void __user *)arg); |
| 3142 | 3170 | } |
| 3143 | 3171 | |
| 3172 | +static int f2fs_get_volume_name(struct file *filp, unsigned long arg) | |
| 3173 | +{ | |
| 3174 | + struct inode *inode = file_inode(filp); | |
| 3175 | + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | |
| 3176 | + char *vbuf; | |
| 3177 | + int count; | |
| 3178 | + int err = 0; | |
| 3179 | + | |
| 3180 | + vbuf = f2fs_kzalloc(sbi, MAX_VOLUME_NAME, GFP_KERNEL); | |
| 3181 | + if (!vbuf) | |
| 3182 | + return -ENOMEM; | |
| 3183 | + | |
| 3184 | + down_read(&sbi->sb_lock); | |
| 3185 | + count = utf16s_to_utf8s(sbi->raw_super->volume_name, | |
| 3186 | + ARRAY_SIZE(sbi->raw_super->volume_name), | |
| 3187 | + UTF16_LITTLE_ENDIAN, vbuf, MAX_VOLUME_NAME); | |
| 3188 | + up_read(&sbi->sb_lock); | |
| 3189 | + | |
| 3190 | + if (copy_to_user((char __user *)arg, vbuf, | |
| 3191 | + min(FSLABEL_MAX, count))) | |
| 3192 | + err = -EFAULT; | |
| 3193 | + | |
| 3194 | + kvfree(vbuf); | |
| 3195 | + return err; | |
| 3196 | +} | |
| 3197 | + | |
| 3198 | +static int f2fs_set_volume_name(struct file *filp, unsigned long arg) | |
| 3199 | +{ | |
| 3200 | + struct inode *inode = file_inode(filp); | |
| 3201 | + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | |
| 3202 | + char *vbuf; | |
| 3203 | + int err = 0; | |
| 3204 | + | |
| 3205 | + if (!capable(CAP_SYS_ADMIN)) | |
| 3206 | + return -EPERM; | |
| 3207 | + | |
| 3208 | + vbuf = strndup_user((const char __user *)arg, FSLABEL_MAX); | |
| 3209 | + if (IS_ERR(vbuf)) | |
| 3210 | + return PTR_ERR(vbuf); | |
| 3211 | + | |
| 3212 | + err = mnt_want_write_file(filp); | |
| 3213 | + if (err) | |
| 3214 | + goto out; | |
| 3215 | + | |
| 3216 | + down_write(&sbi->sb_lock); | |
| 3217 | + | |
| 3218 | + memset(sbi->raw_super->volume_name, 0, | |
| 3219 | + sizeof(sbi->raw_super->volume_name)); | |
| 3220 | + utf8s_to_utf16s(vbuf, strlen(vbuf), UTF16_LITTLE_ENDIAN, | |
| 3221 | + sbi->raw_super->volume_name, | |
| 3222 | + ARRAY_SIZE(sbi->raw_super->volume_name)); | |
| 3223 | + | |
| 3224 | + err = f2fs_commit_super(sbi, false); | |
| 3225 | + | |
| 3226 | + up_write(&sbi->sb_lock); | |
| 3227 | + | |
| 3228 | + mnt_drop_write_file(filp); | |
| 3229 | +out: | |
| 3230 | + kfree(vbuf); | |
| 3231 | + return err; | |
| 3232 | +} | |
| 3233 | + | |
| 3144 | 3234 | long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
| 3145 | 3235 | { |
| 3146 | 3236 | if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) |
| 3147 | 3237 | return -EIO; |
| 3238 | + if (!f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(filp)))) | |
| 3239 | + return -ENOSPC; | |
| 3148 | 3240 | |
| 3149 | 3241 | switch (cmd) { |
| 3150 | 3242 | case F2FS_IOC_GETFLAGS: |
| @@ -3213,6 +3305,10 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · 62 unmodified lines | ||
| 3213 | 3305 | return f2fs_ioc_enable_verity(filp, arg); |
| 3214 | 3306 | case FS_IOC_MEASURE_VERITY: |
| 3215 | 3307 | return f2fs_ioc_measure_verity(filp, arg); |
| 3308 | + case F2FS_IOC_GET_VOLUME_NAME: | |
| 3309 | + return f2fs_get_volume_name(filp, arg); | |
| 3310 | + case F2FS_IOC_SET_VOLUME_NAME: | |
| 3311 | + return f2fs_set_volume_name(filp, arg); | |
| 3216 | 3312 | default: |
| 3217 | 3313 | return -ENOTTY; |
| 3218 | 3314 | } |
| @@ -3229,16 +3325,12 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) · 10 unmodified lines | ||
| 3229 | 3325 | goto out; |
| 3230 | 3326 | } |
| 3231 | 3327 | |
| 3232 | − if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT)) { | |
| 3233 | − ret = -EINVAL; | |
| 3234 | − goto out; | |
| 3235 | − } | |
| 3236 | − | |
| 3237 | − if (!inode_trylock(inode)) { | |
| 3238 | − if (iocb->ki_flags & IOCB_NOWAIT) { | |
| 3328 | + if (iocb->ki_flags & IOCB_NOWAIT) { | |
| 3329 | + if (!inode_trylock(inode)) { | |
| 3239 | 3330 | ret = -EAGAIN; |
| 3240 | 3331 | goto out; |
| 3241 | 3332 | } |
| 3333 | + } else { | |
| 3242 | 3334 | inode_lock(inode); |
| 3243 | 3335 | } |
| 3244 | 3336 | |
| @@ -3334,6 +3426,8 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) · 89 unmodified lines | ||
| 3334 | 3426 | case F2FS_IOC_RESIZE_FS: |
| 3335 | 3427 | case FS_IOC_ENABLE_VERITY: |
| 3336 | 3428 | case FS_IOC_MEASURE_VERITY: |
| 3429 | + case F2FS_IOC_GET_VOLUME_NAME: | |
| 3430 | + case F2FS_IOC_SET_VOLUME_NAME: | |
| 3337 | 3431 | break; |
| 3338 | 3432 | default: |
| 3339 | 3433 | return -ENOIOCTLCMD; |
| @@ -382,6 +382,16 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi, · 381 unmodified lines | ||
| 382 | 382 | nsearched++; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | +#ifdef CONFIG_F2FS_CHECK_FS | |
| 386 | + /* | |
| 387 | + * skip selecting the invalid segno (that is failed due to block | |
| 388 | + * validity check failure during GC) to avoid endless GC loop in | |
| 389 | + * such cases. | |
| 390 | + */ | |
| 391 | + if (test_bit(segno, sm->invalid_segmap)) | |
| 392 | + goto next; | |
| 393 | +#endif | |
| 394 | + | |
| 385 | 395 | secno = GET_SEC_FROM_SEG(sbi, segno); |
| 386 | 396 | |
| 387 | 397 | if (sec_usage_check(sbi, secno)) |
| @@ -627,8 +637,21 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, · 239 unmodified lines | ||
| 627 | 637 | source_blkaddr = datablock_addr(NULL, node_page, ofs_in_node); |
| 628 | 638 | f2fs_put_page(node_page, 1); |
| 629 | 639 | |
| 630 | − if (source_blkaddr != blkaddr) | |
| 640 | + if (source_blkaddr != blkaddr) { | |
| 641 | +#ifdef CONFIG_F2FS_CHECK_FS | |
| 642 | + unsigned int segno = GET_SEGNO(sbi, blkaddr); | |
| 643 | + unsigned long offset = GET_BLKOFF_FROM_SEG0(sbi, blkaddr); | |
| 644 | + | |
| 645 | + if (unlikely(check_valid_map(sbi, segno, offset))) { | |
| 646 | + if (!test_and_set_bit(segno, SIT_I(sbi)->invalid_segmap)) { | |
| 647 | + f2fs_err(sbi, "mismatched blkaddr %u (source_blkaddr %u) in seg %u\n", | |
| 648 | + blkaddr, source_blkaddr, segno); | |
| 649 | + f2fs_bug_on(sbi, 1); | |
| 650 | + } | |
| 651 | + } | |
| 652 | +#endif | |
| 631 | 653 | return false; |
| 654 | + } | |
| 632 | 655 | return true; |
| 633 | 656 | } |
| 634 | 657 | |
| @@ -1303,7 +1326,7 @@ gc_more: · 668 unmodified lines | ||
| 1303 | 1326 | round++; |
| 1304 | 1327 | } |
| 1305 | 1328 | |
| 1306 | − if (gc_type == FG_GC) | |
| 1329 | + if (gc_type == FG_GC && seg_freed) | |
| 1307 | 1330 | sbi->cur_victim_sec = NULL_SEGNO; |
| 1308 | 1331 | |
| 1309 | 1332 | if (sync) |
| @@ -14,6 +14,7 @@ · 13 unmodified lines | ||
| 14 | 14 | #include <linux/f2fs_fs.h> |
| 15 | 15 | #include <linux/cryptohash.h> |
| 16 | 16 | #include <linux/pagemap.h> |
| 17 | +#include <linux/unicode.h> | |
| 17 | 18 | |
| 18 | 19 | #include "f2fs.h" |
| 19 | 20 | |
| @@ -67,7 +68,7 @@ static void str2hashbuf(const unsigned char *msg, size_t len, · 47 unmodified lines | ||
| 67 | 68 | *buf++ = pad; |
| 68 | 69 | } |
| 69 | 70 | |
| 70 | −f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, | |
| 71 | +static f2fs_hash_t __f2fs_dentry_hash(const struct qstr *name_info, | |
| 71 | 72 | struct fscrypt_name *fname) |
| 72 | 73 | { |
| 73 | 74 | __u32 hash; |
| @@ -103,3 +104,37 @@ f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, · 29 unmodified lines | ||
| 103 | 104 | f2fs_hash = cpu_to_le32(hash & ~F2FS_HASH_COL_BIT); |
| 104 | 105 | return f2fs_hash; |
| 105 | 106 | } |
| 107 | + | |
| 108 | +f2fs_hash_t f2fs_dentry_hash(const struct inode *dir, | |
| 109 | + const struct qstr *name_info, struct fscrypt_name *fname) | |
| 110 | +{ | |
| 111 | +#ifdef CONFIG_UNICODE | |
| 112 | + struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); | |
| 113 | + const struct unicode_map *um = sbi->s_encoding; | |
| 114 | + int r, dlen; | |
| 115 | + unsigned char *buff; | |
| 116 | + struct qstr folded; | |
| 117 | + | |
| 118 | + if (!name_info->len || !IS_CASEFOLDED(dir)) | |
| 119 | + goto opaque_seq; | |
| 120 | + | |
| 121 | + buff = f2fs_kzalloc(sbi, sizeof(char) * PATH_MAX, GFP_KERNEL); | |
| 122 | + if (!buff) | |
| 123 | + return -ENOMEM; | |
| 124 | + | |
| 125 | + dlen = utf8_casefold(um, name_info, buff, PATH_MAX); | |
| 126 | + if (dlen < 0) { | |
| 127 | + kvfree(buff); | |
| 128 | + goto opaque_seq; | |
| 129 | + } | |
| 130 | + folded.name = buff; | |
| 131 | + folded.len = dlen; | |
| 132 | + r = __f2fs_dentry_hash(&folded, fname); | |
| 133 | + | |
| 134 | + kvfree(buff); | |
| 135 | + return r; | |
| 136 | + | |
| 137 | +opaque_seq: | |
| 138 | +#endif | |
| 139 | + return __f2fs_dentry_hash(name_info, fname); | |
| 140 | +} | |
| @@ -131,6 +131,7 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) · 130 unmodified lines | ||
| 131 | 131 | |
| 132 | 132 | err = f2fs_get_node_info(fio.sbi, dn->nid, &ni); |
| 133 | 133 | if (err) { |
| 134 | + f2fs_truncate_data_blocks_range(dn, 1); | |
| 134 | 135 | f2fs_put_dnode(dn); |
| 135 | 136 | return err; |
| 136 | 137 | } |
| @@ -320,7 +321,7 @@ struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, · 183 unmodified lines | ||
| 320 | 321 | return NULL; |
| 321 | 322 | } |
| 322 | 323 | |
| 323 | − namehash = f2fs_dentry_hash(&name, fname); | |
| 324 | + namehash = f2fs_dentry_hash(dir, &name, fname); | |
| 324 | 325 | |
| 325 | 326 | inline_dentry = inline_data_addr(dir, ipage); |
| 326 | 327 | |
| @@ -580,7 +581,7 @@ int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, · 253 unmodified lines | ||
| 580 | 581 | |
| 581 | 582 | f2fs_wait_on_page_writeback(ipage, NODE, true, true); |
| 582 | 583 | |
| 583 | − name_hash = f2fs_dentry_hash(new_name, NULL); | |
| 584 | + name_hash = f2fs_dentry_hash(dir, new_name, NULL); | |
| 584 | 585 | f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos); |
| 585 | 586 | |
| 586 | 587 | set_page_dirty(ipage); |
| @@ -588,6 +589,11 @@ int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, · 1 unmodified line | ||
| 588 | 589 | /* we don't need to mark_inode_dirty now */ |
| 589 | 590 | if (inode) { |
| 590 | 591 | f2fs_i_pino_write(inode, dir->i_ino); |
| 592 | + | |
| 593 | + /* synchronize inode page's data from inode cache */ | |
| 594 | + if (is_inode_flag_set(inode, FI_NEW_INODE)) | |
| 595 | + f2fs_update_inode(inode, page); | |
| 596 | + | |
| 591 | 597 | f2fs_put_page(page, 1); |
| 592 | 598 | } |
| 593 | 599 | |
| @@ -704,7 +710,13 @@ int f2fs_inline_data_fiemap(struct inode *inode, · 110 unmodified lines | ||
| 704 | 710 | if (IS_ERR(ipage)) |
| 705 | 711 | return PTR_ERR(ipage); |
| 706 | 712 | |
| 707 | − if (!f2fs_has_inline_data(inode)) { | |
| 713 | + if ((S_ISREG(inode->i_mode) || S_ISLNK(inode->i_mode)) && | |
| 714 | + !f2fs_has_inline_data(inode)) { | |
| 715 | + err = -EAGAIN; | |
| 716 | + goto out; | |
| 717 | + } | |
| 718 | + | |
| 719 | + if (S_ISDIR(inode->i_mode) && !f2fs_has_inline_dentry(inode)) { | |
| 708 | 720 | err = -EAGAIN; |
| 709 | 721 | goto out; |
| 710 | 722 | } |
| @@ -48,9 +48,11 @@ void f2fs_set_inode_flags(struct inode *inode) · 47 unmodified lines | ||
| 48 | 48 | new_fl |= S_ENCRYPTED; |
| 49 | 49 | if (file_is_verity(inode)) |
| 50 | 50 | new_fl |= S_VERITY; |
| 51 | + if (flags & F2FS_CASEFOLD_FL) | |
| 52 | + new_fl |= S_CASEFOLD; | |
| 51 | 53 | inode_set_flags(inode, new_fl, |
| 52 | 54 | S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC| |
| 53 | − S_ENCRYPTED|S_VERITY); | |
| 55 | + S_ENCRYPTED|S_VERITY|S_CASEFOLD); | |
| 54 | 56 | } |
| 55 | 57 | |
| 56 | 58 | static void __get_inode_rdev(struct inode *inode, struct f2fs_inode *ri) |
| @@ -616,7 +618,7 @@ int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc) · 559 unmodified lines | ||
| 616 | 618 | if (!is_inode_flag_set(inode, FI_DIRTY_INODE)) |
| 617 | 619 | return 0; |
| 618 | 620 | |
| 619 | − if (f2fs_is_checkpoint_ready(sbi)) | |
| 621 | + if (!f2fs_is_checkpoint_ready(sbi)) | |
| 620 | 622 | return -ENOSPC; |
| 621 | 623 | |
| 622 | 624 | /* |
| @@ -695,7 +697,8 @@ retry: · 72 unmodified lines | ||
| 695 | 697 | |
| 696 | 698 | if (err) { |
| 697 | 699 | f2fs_update_inode_page(inode); |
| 698 | − set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); | |
| 700 | + if (dquot_initialize_needed(inode)) | |
| 701 | + set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); | |
| 699 | 702 | } |
| 700 | 703 | sb_end_intwrite(inode->i_sb); |
| 701 | 704 | no_delete: |
| @@ -705,7 +708,7 @@ no_delete: · 3 unmodified lines | ||
| 705 | 708 | stat_dec_inline_dir(inode); |
| 706 | 709 | stat_dec_inline_inode(inode); |
| 707 | 710 | |
| 708 | − if (likely(!is_set_ckpt_flags(sbi, CP_ERROR_FLAG) && | |
| 711 | + if (likely(!f2fs_cp_error(sbi) && | |
| 709 | 712 | !is_sbi_flag_set(sbi, SBI_CP_DISABLED))) |
| 710 | 713 | f2fs_bug_on(sbi, is_inode_flag_set(inode, FI_DIRTY_INODE)); |
| 711 | 714 | else |
| @@ -272,9 +272,8 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode, · 271 unmodified lines | ||
| 272 | 272 | |
| 273 | 273 | if (unlikely(f2fs_cp_error(sbi))) |
| 274 | 274 | return -EIO; |
| 275 | − err = f2fs_is_checkpoint_ready(sbi); | |
| 276 | − if (err) | |
| 277 | − return err; | |
| 275 | + if (!f2fs_is_checkpoint_ready(sbi)) | |
| 276 | + return -ENOSPC; | |
| 278 | 277 | |
| 279 | 278 | err = dquot_initialize(dir); |
| 280 | 279 | if (err) |
| @@ -321,9 +320,8 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir, · 40 unmodified lines | ||
| 321 | 320 | |
| 322 | 321 | if (unlikely(f2fs_cp_error(sbi))) |
| 323 | 322 | return -EIO; |
| 324 | − err = f2fs_is_checkpoint_ready(sbi); | |
| 325 | − if (err) | |
| 326 | − return err; | |
| 323 | + if (!f2fs_is_checkpoint_ready(sbi)) | |
| 324 | + return -ENOSPC; | |
| 327 | 325 | |
| 328 | 326 | err = fscrypt_prepare_link(old_dentry, dir, dentry); |
| 329 | 327 | if (err) |
| @@ -489,6 +487,17 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry, · 159 unmodified lines | ||
| 489 | 487 | goto out_iput; |
| 490 | 488 | } |
| 491 | 489 | out_splice: |
| 490 | +#ifdef CONFIG_UNICODE | |
| 491 | + if (!inode && IS_CASEFOLDED(dir)) { | |
| 492 | + /* Eventually we want to call d_add_ci(dentry, NULL) | |
| 493 | + * for negative dentries in the encoding case as | |
| 494 | + * well. For now, prevent the negative dentry | |
| 495 | + * from being cached. | |
| 496 | + */ | |
| 497 | + trace_f2fs_lookup_end(dir, dentry, ino, err); | |
| 498 | + return NULL; | |
| 499 | + } | |
| 500 | +#endif | |
| 492 | 501 | new = d_splice_alias(inode, dentry); |
| 493 | 502 | err = PTR_ERR_OR_ZERO(new); |
| 494 | 503 | trace_f2fs_lookup_end(dir, dentry, ino, err); |
| @@ -537,6 +546,16 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry) · 42 unmodified lines | ||
| 537 | 546 | goto fail; |
| 538 | 547 | } |
| 539 | 548 | f2fs_delete_entry(de, page, dir, inode); |
| 549 | +#ifdef CONFIG_UNICODE | |
| 550 | + /* VFS negative dentries are incompatible with Encoding and | |
| 551 | + * Case-insensitiveness. Eventually we'll want avoid | |
| 552 | + * invalidating the dentries here, alongside with returning the | |
| 553 | + * negative dentries at f2fs_lookup(), when it is better | |
| 554 | + * supported by the VFS for the CI case. | |
| 555 | + */ | |
| 556 | + if (IS_CASEFOLDED(dir)) | |
| 557 | + d_invalidate(dentry); | |
| 558 | +#endif | |
| 540 | 559 | f2fs_unlock_op(sbi); |
| 541 | 560 | |
| 542 | 561 | if (IS_DIRSYNC(dir)) |
| @@ -571,9 +590,8 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, · 28 unmodified lines | ||
| 571 | 590 | |
| 572 | 591 | if (unlikely(f2fs_cp_error(sbi))) |
| 573 | 592 | return -EIO; |
| 574 | − err = f2fs_is_checkpoint_ready(sbi); | |
| 575 | − if (err) | |
| 576 | − return err; | |
| 593 | + if (!f2fs_is_checkpoint_ready(sbi)) | |
| 594 | + return -ENOSPC; | |
| 577 | 595 | |
| 578 | 596 | err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize, |
| 579 | 597 | &disk_link); |
| @@ -703,9 +721,8 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry, · 123 unmodified lines | ||
| 703 | 721 | |
| 704 | 722 | if (unlikely(f2fs_cp_error(sbi))) |
| 705 | 723 | return -EIO; |
| 706 | − err = f2fs_is_checkpoint_ready(sbi); | |
| 707 | − if (err) | |
| 708 | − return err; | |
| 724 | + if (!f2fs_is_checkpoint_ready(sbi)) | |
| 725 | + return -ENOSPC; | |
| 709 | 726 | |
| 710 | 727 | err = dquot_initialize(dir); |
| 711 | 728 | if (err) |
| @@ -804,6 +821,8 @@ static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) · 92 unmodified lines | ||
| 804 | 821 | |
| 805 | 822 | if (unlikely(f2fs_cp_error(sbi))) |
| 806 | 823 | return -EIO; |
| 824 | + if (!f2fs_is_checkpoint_ready(sbi)) | |
| 825 | + return -ENOSPC; | |
| 807 | 826 | |
| 808 | 827 | if (IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) { |
| 809 | 828 | int err = fscrypt_get_encryption_info(dir); |
| @@ -840,9 +859,8 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, · 30 unmodified lines | ||
| 840 | 859 | |
| 841 | 860 | if (unlikely(f2fs_cp_error(sbi))) |
| 842 | 861 | return -EIO; |
| 843 | − err = f2fs_is_checkpoint_ready(sbi); | |
| 844 | − if (err) | |
| 845 | − return err; | |
| 862 | + if (!f2fs_is_checkpoint_ready(sbi)) | |
| 863 | + return -ENOSPC; | |
| 846 | 864 | |
| 847 | 865 | if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && |
| 848 | 866 | (!projid_eq(F2FS_I(new_dir)->i_projid, |
| @@ -1035,9 +1053,8 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry, · 186 unmodified lines | ||
| 1035 | 1053 | |
| 1036 | 1054 | if (unlikely(f2fs_cp_error(sbi))) |
| 1037 | 1055 | return -EIO; |
| 1038 | − err = f2fs_is_checkpoint_ready(sbi); | |
| 1039 | − if (err) | |
| 1040 | − return err; | |
| 1056 | + if (!f2fs_is_checkpoint_ready(sbi)) | |
| 1057 | + return -ENOSPC; | |
| 1041 | 1058 | |
| 1042 | 1059 | if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && |
| 1043 | 1060 | !projid_eq(F2FS_I(new_dir)->i_projid, |
| @@ -1250,6 +1267,7 @@ const struct inode_operations f2fs_dir_inode_operations = { · 206 unmodified lines | ||
| 1250 | 1267 | #ifdef CONFIG_F2FS_FS_XATTR |
| 1251 | 1268 | .listxattr = f2fs_listxattr, |
| 1252 | 1269 | #endif |
| 1270 | + .fiemap = f2fs_fiemap, | |
| 1253 | 1271 | }; |
| 1254 | 1272 | |
| 1255 | 1273 | const struct inode_operations f2fs_symlink_inode_operations = { |
| @@ -1524,7 +1524,8 @@ static int __write_node_page(struct page *page, bool atomic, bool *submitted, · 1523 unmodified lines | ||
| 1524 | 1524 | if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) |
| 1525 | 1525 | goto redirty_out; |
| 1526 | 1526 | |
| 1527 | − if (wbc->sync_mode == WB_SYNC_NONE && | |
| 1527 | + if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED) && | |
| 1528 | + wbc->sync_mode == WB_SYNC_NONE && | |
| 1528 | 1529 | IS_DNODE(page) && is_cold_node(page)) |
| 1529 | 1530 | goto redirty_out; |
| 1530 | 1531 | |
| @@ -1762,6 +1763,47 @@ out: · 231 unmodified lines | ||
| 1762 | 1763 | return ret ? -EIO: 0; |
| 1763 | 1764 | } |
| 1764 | 1765 | |
| 1766 | +static int f2fs_match_ino(struct inode *inode, unsigned long ino, void *data) | |
| 1767 | +{ | |
| 1768 | + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | |
| 1769 | + bool clean; | |
| 1770 | + | |
| 1771 | + if (inode->i_ino != ino) | |
| 1772 | + return 0; | |
| 1773 | + | |
| 1774 | + if (!is_inode_flag_set(inode, FI_DIRTY_INODE)) | |
| 1775 | + return 0; | |
| 1776 | + | |
| 1777 | + spin_lock(&sbi->inode_lock[DIRTY_META]); | |
| 1778 | + clean = list_empty(&F2FS_I(inode)->gdirty_list); | |
| 1779 | + spin_unlock(&sbi->inode_lock[DIRTY_META]); | |
| 1780 | + | |
| 1781 | + if (clean) | |
| 1782 | + return 0; | |
| 1783 | + | |
| 1784 | + inode = igrab(inode); | |
| 1785 | + if (!inode) | |
| 1786 | + return 0; | |
| 1787 | + return 1; | |
| 1788 | +} | |
| 1789 | + | |
| 1790 | +static bool flush_dirty_inode(struct page *page) | |
| 1791 | +{ | |
| 1792 | + struct f2fs_sb_info *sbi = F2FS_P_SB(page); | |
| 1793 | + struct inode *inode; | |
| 1794 | + nid_t ino = ino_of_node(page); | |
| 1795 | + | |
| 1796 | + inode = find_inode_nowait(sbi->sb, ino, f2fs_match_ino, NULL); | |
| 1797 | + if (!inode) | |
| 1798 | + return false; | |
| 1799 | + | |
| 1800 | + f2fs_update_inode(inode, page); | |
| 1801 | + unlock_page(page); | |
| 1802 | + | |
| 1803 | + iput(inode); | |
| 1804 | + return true; | |
| 1805 | +} | |
| 1806 | + | |
| 1765 | 1807 | int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, |
| 1766 | 1808 | struct writeback_control *wbc, |
| 1767 | 1809 | bool do_balance, enum iostat_type io_type) |
| @@ -1785,6 +1827,7 @@ next_step: · 17 unmodified lines | ||
| 1785 | 1827 | for (i = 0; i < nr_pages; i++) { |
| 1786 | 1828 | struct page *page = pvec.pages[i]; |
| 1787 | 1829 | bool submitted = false; |
| 1830 | + bool may_dirty = true; | |
| 1788 | 1831 | |
| 1789 | 1832 | /* give a priority to WB_SYNC threads */ |
| 1790 | 1833 | if (atomic_read(&sbi->wb_sync_req[NODE]) && |
| @@ -1832,6 +1875,13 @@ continue_unlock: · 41 unmodified lines | ||
| 1832 | 1875 | goto lock_node; |
| 1833 | 1876 | } |
| 1834 | 1877 | |
| 1878 | + /* flush dirty inode */ | |
| 1879 | + if (IS_INODE(page) && may_dirty) { | |
| 1880 | + may_dirty = false; | |
| 1881 | + if (flush_dirty_inode(page)) | |
| 1882 | + goto lock_node; | |
| 1883 | + } | |
| 1884 | + | |
| 1835 | 1885 | f2fs_wait_on_page_writeback(page, NODE, true, true); |
| 1836 | 1886 | |
| 1837 | 1887 | if (!clear_page_dirty_for_io(page)) |
| @@ -1860,7 +1910,8 @@ continue_unlock: · 22 unmodified lines | ||
| 1860 | 1910 | } |
| 1861 | 1911 | |
| 1862 | 1912 | if (step < 2) { |
| 1863 | − if (wbc->sync_mode == WB_SYNC_NONE && step == 1) | |
| 1913 | + if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED) && | |
| 1914 | + wbc->sync_mode == WB_SYNC_NONE && step == 1) | |
| 1864 | 1915 | goto out; |
| 1865 | 1916 | step++; |
| 1866 | 1917 | goto next_step; |
| @@ -2964,7 +3015,7 @@ static int init_node_manager(struct f2fs_sb_info *sbi) · 1097 unmodified lines | ||
| 2964 | 3015 | |
| 2965 | 3016 | /* not used nids: 0, node, meta, (and root counted as valid node) */ |
| 2966 | 3017 | nm_i->available_nids = nm_i->max_nid - sbi->total_valid_node_count - |
| 2967 | − sbi->nquota_files - F2FS_RESERVED_NODE_NUM; | |
| 3018 | + F2FS_RESERVED_NODE_NUM; | |
| 2968 | 3019 | nm_i->nid_cnt[FREE_NID] = 0; |
| 2969 | 3020 | nm_i->nid_cnt[PREALLOC_NID] = 0; |
| 2970 | 3021 | nm_i->nat_cnt = 0; |
| @@ -185,8 +185,6 @@ bool f2fs_need_SSR(struct f2fs_sb_info *sbi) · 184 unmodified lines | ||
| 185 | 185 | |
| 186 | 186 | void f2fs_register_inmem_page(struct inode *inode, struct page *page) |
| 187 | 187 | { |
| 188 | − struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | |
| 189 | − struct f2fs_inode_info *fi = F2FS_I(inode); | |
| 190 | 188 | struct inmem_pages *new; |
| 191 | 189 | |
| 192 | 190 | f2fs_trace_pid(page); |
| @@ -200,15 +198,11 @@ void f2fs_register_inmem_page(struct inode *inode, struct page *page) · 7 unmodified lines | ||
| 200 | 198 | INIT_LIST_HEAD(&new->list); |
| 201 | 199 | |
| 202 | 200 | /* increase reference count with clean state */ |
| 203 | − mutex_lock(&fi->inmem_lock); | |
| 204 | 201 | get_page(page); |
| 205 | − list_add_tail(&new->list, &fi->inmem_pages); | |
| 206 | − spin_lock(&sbi->inode_lock[ATOMIC_FILE]); | |
| 207 | − if (list_empty(&fi->inmem_ilist)) | |
| 208 | − list_add_tail(&fi->inmem_ilist, &sbi->inode_list[ATOMIC_FILE]); | |
| 209 | − spin_unlock(&sbi->inode_lock[ATOMIC_FILE]); | |
| 202 | + mutex_lock(&F2FS_I(inode)->inmem_lock); | |
| 203 | + list_add_tail(&new->list, &F2FS_I(inode)->inmem_pages); | |
| 210 | 204 | inc_page_count(F2FS_I_SB(inode), F2FS_INMEM_PAGES); |
| 211 | − mutex_unlock(&fi->inmem_lock); | |
| 205 | + mutex_unlock(&F2FS_I(inode)->inmem_lock); | |
| 212 | 206 | |
| 213 | 207 | trace_f2fs_register_inmem_page(page, INMEM); |
| 214 | 208 | } |
| @@ -330,19 +324,17 @@ void f2fs_drop_inmem_pages(struct inode *inode) · 115 unmodified lines | ||
| 330 | 324 | mutex_lock(&fi->inmem_lock); |
| 331 | 325 | __revoke_inmem_pages(inode, &fi->inmem_pages, |
| 332 | 326 | true, false, true); |
| 333 | − | |
| 334 | − if (list_empty(&fi->inmem_pages)) { | |
| 335 | − spin_lock(&sbi->inode_lock[ATOMIC_FILE]); | |
| 336 | − if (!list_empty(&fi->inmem_ilist)) | |
| 337 | − list_del_init(&fi->inmem_ilist); | |
| 338 | − spin_unlock(&sbi->inode_lock[ATOMIC_FILE]); | |
| 339 | − } | |
| 340 | 327 | mutex_unlock(&fi->inmem_lock); |
| 341 | 328 | } |
| 342 | 329 | |
| 343 | 330 | clear_inode_flag(inode, FI_ATOMIC_FILE); |
| 344 | 331 | fi->i_gc_failures[GC_FAILURE_ATOMIC] = 0; |
| 345 | 332 | stat_dec_atomic_write(inode); |
| 333 | + | |
| 334 | + spin_lock(&sbi->inode_lock[ATOMIC_FILE]); | |
| 335 | + if (!list_empty(&fi->inmem_ilist)) | |
| 336 | + list_del_init(&fi->inmem_ilist); | |
| 337 | + spin_unlock(&sbi->inode_lock[ATOMIC_FILE]); | |
| 346 | 338 | } |
| 347 | 339 | |
| 348 | 340 | void f2fs_drop_inmem_page(struct inode *inode, struct page *page) |
| @@ -471,11 +463,6 @@ int f2fs_commit_inmem_pages(struct inode *inode) · 122 unmodified lines | ||
| 471 | 463 | |
| 472 | 464 | mutex_lock(&fi->inmem_lock); |
| 473 | 465 | err = __f2fs_commit_inmem_pages(inode); |
| 474 | − | |
| 475 | − spin_lock(&sbi->inode_lock[ATOMIC_FILE]); | |
| 476 | − if (!list_empty(&fi->inmem_ilist)) | |
| 477 | − list_del_init(&fi->inmem_ilist); | |
| 478 | − spin_unlock(&sbi->inode_lock[ATOMIC_FILE]); | |
| 479 | 466 | mutex_unlock(&fi->inmem_lock); |
| 480 | 467 | |
| 481 | 468 | clear_inode_flag(inode, FI_ATOMIC_COMMIT); |
| @@ -501,7 +488,7 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need) · 19 unmodified lines | ||
| 501 | 488 | if (need && excess_cached_nats(sbi)) |
| 502 | 489 | f2fs_balance_fs_bg(sbi); |
| 503 | 490 | |
| 504 | − if (f2fs_is_checkpoint_ready(sbi)) | |
| 491 | + if (!f2fs_is_checkpoint_ready(sbi)) | |
| 505 | 492 | return; |
| 506 | 493 | |
| 507 | 494 | /* |
| @@ -817,9 +804,13 @@ static void __remove_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno, · 309 unmodified lines | ||
| 817 | 804 | if (test_and_clear_bit(segno, dirty_i->dirty_segmap[t])) |
| 818 | 805 | dirty_i->nr_dirty[t]--; |
| 819 | 806 | |
| 820 | − if (get_valid_blocks(sbi, segno, true) == 0) | |
| 807 | + if (get_valid_blocks(sbi, segno, true) == 0) { | |
| 821 | 808 | clear_bit(GET_SEC_FROM_SEG(sbi, segno), |
| 822 | 809 | dirty_i->victim_secmap); |
| 810 | +#ifdef CONFIG_F2FS_CHECK_FS | |
| 811 | + clear_bit(segno, SIT_I(sbi)->invalid_segmap); | |
| 812 | +#endif | |
| 813 | + } | |
| 823 | 814 | } |
| 824 | 815 | } |
| 825 | 816 | |
| @@ -2084,6 +2075,13 @@ static void destroy_discard_cmd_control(struct f2fs_sb_info *sbi) · 1258 unmodified lines | ||
| 2084 | 2075 | |
| 2085 | 2076 | f2fs_stop_discard_thread(sbi); |
| 2086 | 2077 | |
| 2078 | + /* | |
| 2079 | + * Recovery can cache discard commands, so in error path of | |
| 2080 | + * fill_super(), it needs to give a chance to handle them. | |
| 2081 | + */ | |
| 2082 | + if (unlikely(atomic_read(&dcc->discard_cmd_cnt))) | |
| 2083 | + f2fs_issue_discard_timeout(sbi); | |
| 2084 | + | |
| 2087 | 2085 | kvfree(dcc); |
| 2088 | 2086 | SM_I(sbi)->dcc_info = NULL; |
| 2089 | 2087 | } |
| @@ -2156,9 +2154,11 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) · 66 unmodified lines | ||
| 2156 | 2154 | if (!f2fs_test_and_set_bit(offset, se->discard_map)) |
| 2157 | 2155 | sbi->discard_blks--; |
| 2158 | 2156 | |
| 2159 | − /* don't overwrite by SSR to keep node chain */ | |
| 2160 | − if (IS_NODESEG(se->type) && | |
| 2161 | − !is_sbi_flag_set(sbi, SBI_CP_DISABLED)) { | |
| 2157 | + /* | |
| 2158 | + * SSR should never reuse block which is checkpointed | |
| 2159 | + * or newly invalidated. | |
| 2160 | + */ | |
| 2161 | + if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED)) { | |
| 2162 | 2162 | if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map)) |
| 2163 | 2163 | se->ckpt_valid_blocks++; |
| 2164 | 2164 | } |
| @@ -3116,12 +3116,14 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, · 951 unmodified lines | ||
| 3116 | 3116 | f2fs_inode_chksum_set(sbi, page); |
| 3117 | 3117 | } |
| 3118 | 3118 | |
| 3119 | + if (F2FS_IO_ALIGNED(sbi)) | |
| 3120 | + fio->retry = false; | |
| 3121 | + | |
| 3119 | 3122 | if (add_list) { |
| 3120 | 3123 | struct f2fs_bio_info *io; |
| 3121 | 3124 | |
| 3122 | 3125 | INIT_LIST_HEAD(&fio->list); |
| 3123 | 3126 | fio->in_list = true; |
| 3124 | − fio->retry = false; | |
| 3125 | 3127 | io = sbi->write_io[fio->type] + fio->temp; |
| 3126 | 3128 | spin_lock(&io->io_lock); |
| 3127 | 3129 | list_add_tail(&fio->list, &io->io_list); |
| @@ -3447,11 +3449,6 @@ static int read_compacted_summaries(struct f2fs_sb_info *sbi) · 319 unmodified lines | ||
| 3447 | 3449 | seg_i = CURSEG_I(sbi, i); |
| 3448 | 3450 | segno = le32_to_cpu(ckpt->cur_data_segno[i]); |
| 3449 | 3451 | blk_off = le16_to_cpu(ckpt->cur_data_blkoff[i]); |
| 3450 | − if (blk_off > ENTRIES_IN_SUM) { | |
| 3451 | − f2fs_bug_on(sbi, 1); | |
| 3452 | − f2fs_put_page(page, 1); | |
| 3453 | − return -EFAULT; | |
| 3454 | − } | |
| 3455 | 3452 | seg_i->next_segno = segno; |
| 3456 | 3453 | reset_curseg(sbi, i, 0); |
| 3457 | 3454 | seg_i->alloc_type = ckpt->alloc_type[i]; |
| @@ -3941,8 +3938,8 @@ static int build_sit_info(struct f2fs_sb_info *sbi) · 483 unmodified lines | ||
| 3941 | 3938 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); |
| 3942 | 3939 | struct sit_info *sit_i; |
| 3943 | 3940 | unsigned int sit_segs, start; |
| 3944 | − char *src_bitmap; | |
| 3945 | − unsigned int bitmap_size; | |
| 3941 | + char *src_bitmap, *bitmap; | |
| 3942 | + unsigned int bitmap_size, main_bitmap_size, sit_bitmap_size; | |
| 3946 | 3943 | |
| 3947 | 3944 | /* allocate memory for SIT information */ |
| 3948 | 3945 | sit_i = f2fs_kzalloc(sbi, sizeof(struct sit_info), GFP_KERNEL); |
| @@ -3958,33 +3955,37 @@ static int build_sit_info(struct f2fs_sb_info *sbi) · 9 unmodified lines | ||
| 3958 | 3955 | if (!sit_i->sentries) |
| 3959 | 3956 | return -ENOMEM; |
| 3960 | 3957 | |
| 3961 | − bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi)); | |
| 3962 | − sit_i->dirty_sentries_bitmap = f2fs_kvzalloc(sbi, bitmap_size, | |
| 3958 | + main_bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi)); | |
| 3959 | + sit_i->dirty_sentries_bitmap = f2fs_kvzalloc(sbi, main_bitmap_size, | |
| 3963 | 3960 | GFP_KERNEL); |
| 3964 | 3961 | if (!sit_i->dirty_sentries_bitmap) |
| 3965 | 3962 | return -ENOMEM; |
| 3966 | 3963 | |
| 3964 | +#ifdef CONFIG_F2FS_CHECK_FS | |
| 3965 | + bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 4; | |
| 3966 | +#else | |
| 3967 | + bitmap_size = MAIN_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE * 3; | |
| 3968 | +#endif | |
| 3969 | + sit_i->bitmap = f2fs_kvzalloc(sbi, bitmap_size, GFP_KERNEL); | |
| 3970 | + if (!sit_i->bitmap) | |
| 3971 | + return -ENOMEM; | |
| 3972 | + | |
| 3973 | + bitmap = sit_i->bitmap; | |
| 3974 | + | |
| 3967 | 3975 | for (start = 0; start < MAIN_SEGS(sbi); start++) { |
| 3968 | − sit_i->sentries[start].cur_valid_map | |
| 3969 | − = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | |
| 3970 | − sit_i->sentries[start].ckpt_valid_map | |
| 3971 | − = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | |
| 3972 | − if (!sit_i->sentries[start].cur_valid_map || | |
| 3973 | − !sit_i->sentries[start].ckpt_valid_map) | |
| 3974 | − return -ENOMEM; | |
| 3976 | + sit_i->sentries[start].cur_valid_map = bitmap; | |
| 3977 | + bitmap += SIT_VBLOCK_MAP_SIZE; | |
| 3978 | + | |
| 3979 | + sit_i->sentries[start].ckpt_valid_map = bitmap; | |
| 3980 | + bitmap += SIT_VBLOCK_MAP_SIZE; | |
| 3975 | 3981 | |
| 3976 | 3982 | #ifdef CONFIG_F2FS_CHECK_FS |
| 3977 | − sit_i->sentries[start].cur_valid_map_mir | |
| 3978 | − = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | |
| 3979 | − if (!sit_i->sentries[start].cur_valid_map_mir) | |
| 3980 | − return -ENOMEM; | |
| 3983 | + sit_i->sentries[start].cur_valid_map_mir = bitmap; | |
| 3984 | + bitmap += SIT_VBLOCK_MAP_SIZE; | |
| 3981 | 3985 | #endif |
| 3982 | 3986 | |
| 3983 | − sit_i->sentries[start].discard_map | |
| 3984 | − = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, | |
| 3985 | − GFP_KERNEL); | |
| 3986 | − if (!sit_i->sentries[start].discard_map) | |
| 3987 | − return -ENOMEM; | |
| 3987 | + sit_i->sentries[start].discard_map = bitmap; | |
| 3988 | + bitmap += SIT_VBLOCK_MAP_SIZE; | |
| 3988 | 3989 | } |
| 3989 | 3990 | |
| 3990 | 3991 | sit_i->tmp_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); |
| @@ -4004,17 +4005,23 @@ static int build_sit_info(struct f2fs_sb_info *sbi) · 13 unmodified lines | ||
| 4004 | 4005 | sit_segs = le32_to_cpu(raw_super->segment_count_sit) >> 1; |
| 4005 | 4006 | |
| 4006 | 4007 | /* setup SIT bitmap from ckeckpoint pack */ |
| 4007 | − bitmap_size = __bitmap_size(sbi, SIT_BITMAP); | |
| 4008 | + sit_bitmap_size = __bitmap_size(sbi, SIT_BITMAP); | |
| 4008 | 4009 | src_bitmap = __bitmap_ptr(sbi, SIT_BITMAP); |
| 4009 | 4010 | |
| 4010 | − sit_i->sit_bitmap = kmemdup(src_bitmap, bitmap_size, GFP_KERNEL); | |
| 4011 | + sit_i->sit_bitmap = kmemdup(src_bitmap, sit_bitmap_size, GFP_KERNEL); | |
| 4011 | 4012 | if (!sit_i->sit_bitmap) |
| 4012 | 4013 | return -ENOMEM; |
| 4013 | 4014 | |
| 4014 | 4015 | #ifdef CONFIG_F2FS_CHECK_FS |
| 4015 | − sit_i->sit_bitmap_mir = kmemdup(src_bitmap, bitmap_size, GFP_KERNEL); | |
| 4016 | + sit_i->sit_bitmap_mir = kmemdup(src_bitmap, | |
| 4017 | + sit_bitmap_size, GFP_KERNEL); | |
| 4016 | 4018 | if (!sit_i->sit_bitmap_mir) |
| 4017 | 4019 | return -ENOMEM; |
| 4020 | + | |
| 4021 | + sit_i->invalid_segmap = f2fs_kvzalloc(sbi, | |
| 4022 | + main_bitmap_size, GFP_KERNEL); | |
| 4023 | + if (!sit_i->invalid_segmap) | |
| 4024 | + return -ENOMEM; | |
| 4018 | 4025 | #endif |
| 4019 | 4026 | |
| 4020 | 4027 | /* init SIT information */ |
| @@ -4023,7 +4030,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi) · 2 unmodified lines | ||
| 4023 | 4030 | sit_i->sit_base_addr = le32_to_cpu(raw_super->sit_blkaddr); |
| 4024 | 4031 | sit_i->sit_blocks = sit_segs << sbi->log_blocks_per_seg; |
| 4025 | 4032 | sit_i->written_valid_blocks = 0; |
| 4026 | − sit_i->bitmap_size = bitmap_size; | |
| 4033 | + sit_i->bitmap_size = sit_bitmap_size; | |
| 4027 | 4034 | sit_i->dirty_sentries = 0; |
| 4028 | 4035 | sit_i->sents_per_block = SIT_ENTRY_PER_BLOCK; |
| 4029 | 4036 | sit_i->elapsed_time = le64_to_cpu(sbi->ckpt->elapsed_time); |
| @@ -4161,7 +4168,6 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) · 131 unmodified lines | ||
| 4161 | 4168 | if (start >= MAIN_SEGS(sbi)) { |
| 4162 | 4169 | f2fs_err(sbi, "Wrong journal entry on segno %u", |
| 4163 | 4170 | start); |
| 4164 | − set_sbi_flag(sbi, SBI_NEED_FSCK); | |
| 4165 | 4171 | err = -EFSCORRUPTED; |
| 4166 | 4172 | break; |
| 4167 | 4173 | } |
| @@ -4201,7 +4207,6 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) · 33 unmodified lines | ||
| 4201 | 4207 | if (!err && total_node_blocks != valid_node_count(sbi)) { |
| 4202 | 4208 | f2fs_err(sbi, "SIT is corrupted node# %u vs %u", |
| 4203 | 4209 | total_node_blocks, valid_node_count(sbi)); |
| 4204 | − set_sbi_flag(sbi, SBI_NEED_FSCK); | |
| 4205 | 4210 | err = -EFSCORRUPTED; |
| 4206 | 4211 | } |
| 4207 | 4212 | |
| @@ -4492,21 +4497,12 @@ static void destroy_free_segmap(struct f2fs_sb_info *sbi) · 284 unmodified lines | ||
| 4492 | 4497 | static void destroy_sit_info(struct f2fs_sb_info *sbi) |
| 4493 | 4498 | { |
| 4494 | 4499 | struct sit_info *sit_i = SIT_I(sbi); |
| 4495 | − unsigned int start; | |
| 4496 | 4500 | |
| 4497 | 4501 | if (!sit_i) |
| 4498 | 4502 | return; |
| 4499 | 4503 | |
| 4500 | − if (sit_i->sentries) { | |
| 4501 | − for (start = 0; start < MAIN_SEGS(sbi); start++) { | |
| 4502 | − kvfree(sit_i->sentries[start].cur_valid_map); | |
| 4503 | −#ifdef CONFIG_F2FS_CHECK_FS | |
| 4504 | − kvfree(sit_i->sentries[start].cur_valid_map_mir); | |
| 4505 | −#endif | |
| 4506 | − kvfree(sit_i->sentries[start].ckpt_valid_map); | |
| 4507 | − kvfree(sit_i->sentries[start].discard_map); | |
| 4508 | − } | |
| 4509 | − } | |
| 4504 | + if (sit_i->sentries) | |
| 4505 | + kvfree(sit_i->bitmap); | |
| 4510 | 4506 | kvfree(sit_i->tmp_map); |
| 4511 | 4507 | |
| 4512 | 4508 | kvfree(sit_i->sentries); |
| @@ -4517,6 +4513,7 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi) · 4 unmodified lines | ||
| 4517 | 4513 | kvfree(sit_i->sit_bitmap); |
| 4518 | 4514 | #ifdef CONFIG_F2FS_CHECK_FS |
| 4519 | 4515 | kvfree(sit_i->sit_bitmap_mir); |
| 4516 | + kvfree(sit_i->invalid_segmap); | |
| 4520 | 4517 | #endif |
| 4521 | 4518 | kvfree(sit_i); |
| 4522 | 4519 | } |
| @@ -226,9 +226,13 @@ struct sit_info { · 225 unmodified lines | ||
| 226 | 226 | block_t sit_base_addr; /* start block address of SIT area */ |
| 227 | 227 | block_t sit_blocks; /* # of blocks used by SIT area */ |
| 228 | 228 | block_t written_valid_blocks; /* # of valid blocks in main area */ |
| 229 | + char *bitmap; /* all bitmaps pointer */ | |
| 229 | 230 | char *sit_bitmap; /* SIT bitmap pointer */ |
| 230 | 231 | #ifdef CONFIG_F2FS_CHECK_FS |
| 231 | 232 | char *sit_bitmap_mir; /* SIT bitmap mirror */ |
| 233 | + | |
| 234 | + /* bitmap of segments to be ignored by GC in case of errors */ | |
| 235 | + unsigned long *invalid_segmap; | |
| 232 | 236 | #endif |
| 233 | 237 | unsigned int bitmap_size; /* SIT bitmap size */ |
| 234 | 238 | |
| @@ -582,13 +586,13 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, · 347 unmodified lines | ||
| 582 | 586 | reserved_sections(sbi) + needed); |
| 583 | 587 | } |
| 584 | 588 | |
| 585 | −static inline int f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi) | |
| 589 | +static inline bool f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi) | |
| 586 | 590 | { |
| 587 | 591 | if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED))) |
| 588 | − return 0; | |
| 592 | + return true; | |
| 589 | 593 | if (likely(!has_not_enough_free_secs(sbi, 0, 0))) |
| 590 | − return 0; | |
| 591 | − return -ENOSPC; | |
| 594 | + return true; | |
| 595 | + return false; | |
| 592 | 596 | } |
| 593 | 597 | |
| 594 | 598 | static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi) |
| @@ -23,6 +23,7 @@ · 22 unmodified lines | ||
| 23 | 23 | #include <linux/f2fs_fs.h> |
| 24 | 24 | #include <linux/sysfs.h> |
| 25 | 25 | #include <linux/quota.h> |
| 26 | +#include <linux/unicode.h> | |
| 26 | 27 | |
| 27 | 28 | #include "f2fs.h" |
| 28 | 29 | #include "node.h" |
| @@ -222,6 +223,36 @@ void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...) · 193 unmodified lines | ||
| 222 | 223 | va_end(args); |
| 223 | 224 | } |
| 224 | 225 | |
| 226 | +#ifdef CONFIG_UNICODE | |
| 227 | +static const struct f2fs_sb_encodings { | |
| 228 | + __u16 magic; | |
| 229 | + char *name; | |
| 230 | + char *version; | |
| 231 | +} f2fs_sb_encoding_map[] = { | |
| 232 | + {F2FS_ENC_UTF8_12_1, "utf8", "12.1.0"}, | |
| 233 | +}; | |
| 234 | + | |
| 235 | +static int f2fs_sb_read_encoding(const struct f2fs_super_block *sb, | |
| 236 | + const struct f2fs_sb_encodings **encoding, | |
| 237 | + __u16 *flags) | |
| 238 | +{ | |
| 239 | + __u16 magic = le16_to_cpu(sb->s_encoding); | |
| 240 | + int i; | |
| 241 | + | |
| 242 | + for (i = 0; i < ARRAY_SIZE(f2fs_sb_encoding_map); i++) | |
| 243 | + if (magic == f2fs_sb_encoding_map[i].magic) | |
| 244 | + break; | |
| 245 | + | |
| 246 | + if (i >= ARRAY_SIZE(f2fs_sb_encoding_map)) | |
| 247 | + return -EINVAL; | |
| 248 | + | |
| 249 | + *encoding = &f2fs_sb_encoding_map[i]; | |
| 250 | + *flags = le16_to_cpu(sb->s_encoding_flags); | |
| 251 | + | |
| 252 | + return 0; | |
| 253 | +} | |
| 254 | +#endif | |
| 255 | + | |
| 225 | 256 | static inline void limit_reserve_root(struct f2fs_sb_info *sbi) |
| 226 | 257 | { |
| 227 | 258 | block_t limit = min((sbi->user_block_count << 1) / 1000, |
| @@ -798,6 +829,13 @@ static int parse_options(struct super_block *sb, char *options) · 570 unmodified lines | ||
| 798 | 829 | return -EINVAL; |
| 799 | 830 | } |
| 800 | 831 | #endif |
| 832 | +#ifndef CONFIG_UNICODE | |
| 833 | + if (f2fs_sb_has_casefold(sbi)) { | |
| 834 | + f2fs_err(sbi, | |
| 835 | + "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE"); | |
| 836 | + return -EINVAL; | |
| 837 | + } | |
| 838 | +#endif | |
| 801 | 839 | |
| 802 | 840 | if (F2FS_IO_SIZE_BITS(sbi) && !test_opt(sbi, LFS)) { |
| 803 | 841 | f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO", |
| @@ -873,7 +911,21 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb) · 69 unmodified lines | ||
| 873 | 911 | |
| 874 | 912 | static int f2fs_drop_inode(struct inode *inode) |
| 875 | 913 | { |
| 914 | + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | |
| 876 | 915 | int ret; |
| 916 | + | |
| 917 | + /* | |
| 918 | + * during filesystem shutdown, if checkpoint is disabled, | |
| 919 | + * drop useless meta/node dirty pages. | |
| 920 | + */ | |
| 921 | + if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { | |
| 922 | + if (inode->i_ino == F2FS_NODE_INO(sbi) || | |
| 923 | + inode->i_ino == F2FS_META_INO(sbi)) { | |
| 924 | + trace_f2fs_drop_inode(inode, 1); | |
| 925 | + return 1; | |
| 926 | + } | |
| 927 | + } | |
| 928 | + | |
| 877 | 929 | /* |
| 878 | 930 | * This is to avoid a deadlock condition like below. |
| 879 | 931 | * writeback_single_inode(inode) |
| @@ -1091,6 +1143,9 @@ static void f2fs_put_super(struct super_block *sb) · 211 unmodified lines | ||
| 1091 | 1143 | destroy_percpu_info(sbi); |
| 1092 | 1144 | for (i = 0; i < NR_PAGE_TYPE; i++) |
| 1093 | 1145 | kvfree(sbi->write_io[i]); |
| 1146 | +#ifdef CONFIG_UNICODE | |
| 1147 | + utf8_unload(sbi->s_encoding); | |
| 1148 | +#endif | |
| 1094 | 1149 | kvfree(sbi); |
| 1095 | 1150 | } |
| 1096 | 1151 | |
| @@ -1216,8 +1271,7 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) · 119 unmodified lines | ||
| 1216 | 1271 | else |
| 1217 | 1272 | buf->f_bavail = 0; |
| 1218 | 1273 | |
| 1219 | − avail_node_count = sbi->total_node_count - sbi->nquota_files - | |
| 1220 | − F2FS_RESERVED_NODE_NUM; | |
| 1274 | + avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; | |
| 1221 | 1275 | |
| 1222 | 1276 | if (avail_node_count > user_block_count) { |
| 1223 | 1277 | buf->f_files = user_block_count; |
| @@ -1524,6 +1578,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) · 300 unmodified lines | ||
| 1524 | 1578 | bool need_stop_gc = false; |
| 1525 | 1579 | bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE); |
| 1526 | 1580 | bool disable_checkpoint = test_opt(sbi, DISABLE_CHECKPOINT); |
| 1581 | + bool no_io_align = !F2FS_IO_ALIGNED(sbi); | |
| 1527 | 1582 | bool checkpoint_changed; |
| 1528 | 1583 | #ifdef CONFIG_QUOTA |
| 1529 | 1584 | int i, j; |
| @@ -1603,6 +1658,12 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) · 73 unmodified lines | ||
| 1603 | 1658 | goto restore_opts; |
| 1604 | 1659 | } |
| 1605 | 1660 | |
| 1661 | + if (no_io_align == !!F2FS_IO_ALIGNED(sbi)) { | |
| 1662 | + err = -EINVAL; | |
| 1663 | + f2fs_warn(sbi, "switch io_bits option is not allowed"); | |
| 1664 | + goto restore_opts; | |
| 1665 | + } | |
| 1666 | + | |
| 1606 | 1667 | if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) { |
| 1607 | 1668 | err = -EINVAL; |
| 1608 | 1669 | f2fs_warn(sbi, "disabling checkpoint not compatible with read-only"); |
| @@ -1981,6 +2042,12 @@ static int f2fs_quota_on(struct super_block *sb, int type, int format_id, · 372 unmodified lines | ||
| 1981 | 2042 | struct inode *inode; |
| 1982 | 2043 | int err; |
| 1983 | 2044 | |
| 2045 | + /* if quota sysfile exists, deny enabling quota with specific file */ | |
| 2046 | + if (f2fs_sb_has_quota_ino(F2FS_SB(sb))) { | |
| 2047 | + f2fs_err(F2FS_SB(sb), "quota sysfile already exists"); | |
| 2048 | + return -EBUSY; | |
| 2049 | + } | |
| 2050 | + | |
| 1984 | 2051 | err = f2fs_quota_sync(sb, type); |
| 1985 | 2052 | if (err) |
| 1986 | 2053 | return err; |
| @@ -2000,7 +2067,7 @@ static int f2fs_quota_on(struct super_block *sb, int type, int format_id, · 13 unmodified lines | ||
| 2000 | 2067 | return 0; |
| 2001 | 2068 | } |
| 2002 | 2069 | |
| 2003 | −static int f2fs_quota_off(struct super_block *sb, int type) | |
| 2070 | +static int __f2fs_quota_off(struct super_block *sb, int type) | |
| 2004 | 2071 | { |
| 2005 | 2072 | struct inode *inode = sb_dqopt(sb)->files[type]; |
| 2006 | 2073 | int err; |
| @@ -2026,13 +2093,30 @@ out_put: · 19 unmodified lines | ||
| 2026 | 2093 | return err; |
| 2027 | 2094 | } |
| 2028 | 2095 | |
| 2096 | +static int f2fs_quota_off(struct super_block *sb, int type) | |
| 2097 | +{ | |
| 2098 | + struct f2fs_sb_info *sbi = F2FS_SB(sb); | |
| 2099 | + int err; | |
| 2100 | + | |
| 2101 | + err = __f2fs_quota_off(sb, type); | |
| 2102 | + | |
| 2103 | + /* | |
| 2104 | + * quotactl can shutdown journalled quota, result in inconsistence | |
| 2105 | + * between quota record and fs data by following updates, tag the | |
| 2106 | + * flag to let fsck be aware of it. | |
| 2107 | + */ | |
| 2108 | + if (is_journalled_quota(sbi)) | |
| 2109 | + set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); | |
| 2110 | + return err; | |
| 2111 | +} | |
| 2112 | + | |
| 2029 | 2113 | void f2fs_quota_off_umount(struct super_block *sb) |
| 2030 | 2114 | { |
| 2031 | 2115 | int type; |
| 2032 | 2116 | int err; |
| 2033 | 2117 | |
| 2034 | 2118 | for (type = 0; type < MAXQUOTAS; type++) { |
| 2035 | − err = f2fs_quota_off(sb, type); | |
| 2119 | + err = __f2fs_quota_off(sb, type); | |
| 2036 | 2120 | if (err) { |
| 2037 | 2121 | int ret = dquot_quota_off(sb, type); |
| 2038 | 2122 | |
| @@ -2617,8 +2701,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · 578 unmodified lines | ||
| 2617 | 2701 | } |
| 2618 | 2702 | |
| 2619 | 2703 | valid_node_count = le32_to_cpu(ckpt->valid_node_count); |
| 2620 | − avail_node_count = sbi->total_node_count - sbi->nquota_files - | |
| 2621 | − F2FS_RESERVED_NODE_NUM; | |
| 2704 | + avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; | |
| 2622 | 2705 | if (valid_node_count > avail_node_count) { |
| 2623 | 2706 | f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u", |
| 2624 | 2707 | valid_node_count, avail_node_count); |
| @@ -2657,10 +2740,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · 32 unmodified lines | ||
| 2657 | 2740 | } |
| 2658 | 2741 | } |
| 2659 | 2742 | for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) { |
| 2660 | − for (j = i; j < NR_CURSEG_DATA_TYPE; j++) { | |
| 2743 | + for (j = 0; j < NR_CURSEG_DATA_TYPE; j++) { | |
| 2661 | 2744 | if (le32_to_cpu(ckpt->cur_node_segno[i]) == |
| 2662 | 2745 | le32_to_cpu(ckpt->cur_data_segno[j])) { |
| 2663 | − f2fs_err(sbi, "Data segment (%u) and Data segment (%u) has the same segno: %u", | |
| 2746 | + f2fs_err(sbi, "Node segment (%u) and Data segment (%u) has the same segno: %u", | |
| 2664 | 2747 | i, j, |
| 2665 | 2748 | le32_to_cpu(ckpt->cur_node_segno[i])); |
| 2666 | 2749 | return 1; |
| @@ -3033,6 +3116,53 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) · 366 unmodified lines | ||
| 3033 | 3116 | return 0; |
| 3034 | 3117 | } |
| 3035 | 3118 | |
| 3119 | +static int f2fs_setup_casefold(struct f2fs_sb_info *sbi) | |
| 3120 | +{ | |
| 3121 | +#ifdef CONFIG_UNICODE | |
| 3122 | + if (f2fs_sb_has_casefold(sbi) && !sbi->s_encoding) { | |
| 3123 | + const struct f2fs_sb_encodings *encoding_info; | |
| 3124 | + struct unicode_map *encoding; | |
| 3125 | + __u16 encoding_flags; | |
| 3126 | + | |
| 3127 | + if (f2fs_sb_has_encrypt(sbi)) { | |
| 3128 | + f2fs_err(sbi, | |
| 3129 | + "Can't mount with encoding and encryption"); | |
| 3130 | + return -EINVAL; | |
| 3131 | + } | |
| 3132 | + | |
| 3133 | + if (f2fs_sb_read_encoding(sbi->raw_super, &encoding_info, | |
| 3134 | + &encoding_flags)) { | |
| 3135 | + f2fs_err(sbi, | |
| 3136 | + "Encoding requested by superblock is unknown"); | |
| 3137 | + return -EINVAL; | |
| 3138 | + } | |
| 3139 | + | |
| 3140 | + encoding = utf8_load(encoding_info->version); | |
| 3141 | + if (IS_ERR(encoding)) { | |
| 3142 | + f2fs_err(sbi, | |
| 3143 | + "can't mount with superblock charset: %s-%s " | |
| 3144 | + "not supported by the kernel. flags: 0x%x.", | |
| 3145 | + encoding_info->name, encoding_info->version, | |
| 3146 | + encoding_flags); | |
| 3147 | + return PTR_ERR(encoding); | |
| 3148 | + } | |
| 3149 | + f2fs_info(sbi, "Using encoding defined by superblock: " | |
| 3150 | + "%s-%s with flags 0x%hx", encoding_info->name, | |
| 3151 | + encoding_info->version?:"\b", encoding_flags); | |
| 3152 | + | |
| 3153 | + sbi->s_encoding = encoding; | |
| 3154 | + sbi->s_encoding_flags = encoding_flags; | |
| 3155 | + sbi->sb->s_d_op = &f2fs_dentry_ops; | |
| 3156 | + } | |
| 3157 | +#else | |
| 3158 | + if (f2fs_sb_has_casefold(sbi)) { | |
| 3159 | + f2fs_err(sbi, "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE"); | |
| 3160 | + return -EINVAL; | |
| 3161 | + } | |
| 3162 | +#endif | |
| 3163 | + return 0; | |
| 3164 | +} | |
| 3165 | + | |
| 3036 | 3166 | static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi) |
| 3037 | 3167 | { |
| 3038 | 3168 | struct f2fs_sm_info *sm_i = SM_I(sbi); |
| @@ -3129,6 +3259,10 @@ try_onemore: · 90 unmodified lines | ||
| 3129 | 3259 | le32_to_cpu(raw_super->log_blocksize); |
| 3130 | 3260 | sb->s_max_links = F2FS_LINK_MAX; |
| 3131 | 3261 | |
| 3262 | + err = f2fs_setup_casefold(sbi); | |
| 3263 | + if (err) | |
| 3264 | + goto free_options; | |
| 3265 | + | |
| 3132 | 3266 | #ifdef CONFIG_QUOTA |
| 3133 | 3267 | sb->dq_op = &f2fs_quota_operations; |
| 3134 | 3268 | sb->s_qcop = &f2fs_quotactl_ops; |
| @@ -3207,7 +3341,7 @@ try_onemore: · 72 unmodified lines | ||
| 3207 | 3341 | if (err) |
| 3208 | 3342 | goto free_bio_info; |
| 3209 | 3343 | |
| 3210 | − if (F2FS_IO_SIZE(sbi) > 1) { | |
| 3344 | + if (F2FS_IO_ALIGNED(sbi)) { | |
| 3211 | 3345 | sbi->write_io_dummy = |
| 3212 | 3346 | mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); |
| 3213 | 3347 | if (!sbi->write_io_dummy) { |
| @@ -3482,6 +3616,10 @@ free_percpu: · 268 unmodified lines | ||
| 3482 | 3616 | free_bio_info: |
| 3483 | 3617 | for (i = 0; i < NR_PAGE_TYPE; i++) |
| 3484 | 3618 | kvfree(sbi->write_io[i]); |
| 3619 | + | |
| 3620 | +#ifdef CONFIG_UNICODE | |
| 3621 | + utf8_unload(sbi->s_encoding); | |
| 3622 | +#endif | |
| 3485 | 3623 | free_options: |
| 3486 | 3624 | #ifdef CONFIG_QUOTA |
| 3487 | 3625 | for (i = 0; i < MAXQUOTAS; i++) |
| @@ -10,6 +10,7 @@ · 9 unmodified lines | ||
| 10 | 10 | #include <linux/proc_fs.h> |
| 11 | 11 | #include <linux/f2fs_fs.h> |
| 12 | 12 | #include <linux/seq_file.h> |
| 13 | +#include <linux/unicode.h> | |
| 13 | 14 | |
| 14 | 15 | #include "f2fs.h" |
| 15 | 16 | #include "segment.h" |
| @@ -81,6 +82,19 @@ static ssize_t unusable_show(struct f2fs_attr *a, · 65 unmodified lines | ||
| 81 | 82 | (unsigned long long)unusable); |
| 82 | 83 | } |
| 83 | 84 | |
| 85 | +static ssize_t encoding_show(struct f2fs_attr *a, | |
| 86 | + struct f2fs_sb_info *sbi, char *buf) | |
| 87 | +{ | |
| 88 | +#ifdef CONFIG_UNICODE | |
| 89 | + if (f2fs_sb_has_casefold(sbi)) | |
| 90 | + return snprintf(buf, PAGE_SIZE, "%s (%d.%d.%d)\n", | |
| 91 | + sbi->s_encoding->charset, | |
| 92 | + (sbi->s_encoding->version >> 16) & 0xff, | |
| 93 | + (sbi->s_encoding->version >> 8) & 0xff, | |
| 94 | + sbi->s_encoding->version & 0xff); | |
| 95 | +#endif | |
| 96 | + return snprintf(buf, PAGE_SIZE, "(none)"); | |
| 97 | +} | |
| 84 | 98 | |
| 85 | 99 | static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a, |
| 86 | 100 | struct f2fs_sb_info *sbi, char *buf) |
| @@ -137,6 +151,9 @@ static ssize_t features_show(struct f2fs_attr *a, · 50 unmodified lines | ||
| 137 | 151 | if (f2fs_sb_has_sb_chksum(sbi)) |
| 138 | 152 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
| 139 | 153 | len ? ", " : "", "sb_checksum"); |
| 154 | + if (f2fs_sb_has_casefold(sbi)) | |
| 155 | + len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", | |
| 156 | + len ? ", " : "", "casefold"); | |
| 140 | 157 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 141 | 158 | return len; |
| 142 | 159 | } |
| @@ -369,6 +386,7 @@ enum feat_id { · 226 unmodified lines | ||
| 369 | 386 | FEAT_LOST_FOUND, |
| 370 | 387 | FEAT_VERITY, |
| 371 | 388 | FEAT_SB_CHECKSUM, |
| 389 | + FEAT_CASEFOLD, | |
| 372 | 390 | }; |
| 373 | 391 | |
| 374 | 392 | static ssize_t f2fs_feature_show(struct f2fs_attr *a, |
| @@ -387,6 +405,7 @@ static ssize_t f2fs_feature_show(struct f2fs_attr *a, · 12 unmodified lines | ||
| 387 | 405 | case FEAT_LOST_FOUND: |
| 388 | 406 | case FEAT_VERITY: |
| 389 | 407 | case FEAT_SB_CHECKSUM: |
| 408 | + case FEAT_CASEFOLD: | |
| 390 | 409 | return snprintf(buf, PAGE_SIZE, "supported\n"); |
| 391 | 410 | } |
| 392 | 411 | return 0; |
| @@ -460,6 +479,7 @@ F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes); · 67 unmodified lines | ||
| 460 | 479 | F2FS_GENERAL_RO_ATTR(features); |
| 461 | 480 | F2FS_GENERAL_RO_ATTR(current_reserved_blocks); |
| 462 | 481 | F2FS_GENERAL_RO_ATTR(unusable); |
| 482 | +F2FS_GENERAL_RO_ATTR(encoding); | |
| 463 | 483 | |
| 464 | 484 | #ifdef CONFIG_FS_ENCRYPTION |
| 465 | 485 | F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO); |
| @@ -479,6 +499,7 @@ F2FS_FEATURE_RO_ATTR(lost_found, FEAT_LOST_FOUND); · 13 unmodified lines | ||
| 479 | 499 | F2FS_FEATURE_RO_ATTR(verity, FEAT_VERITY); |
| 480 | 500 | #endif |
| 481 | 501 | F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM); |
| 502 | +F2FS_FEATURE_RO_ATTR(casefold, FEAT_CASEFOLD); | |
| 482 | 503 | |
| 483 | 504 | #define ATTR_LIST(name) (&f2fs_attr_##name.attr) |
| 484 | 505 | static struct attribute *f2fs_attrs[] = { |
| @@ -523,6 +544,7 @@ static struct attribute *f2fs_attrs[] = { · 38 unmodified lines | ||
| 523 | 544 | ATTR_LIST(features), |
| 524 | 545 | ATTR_LIST(reserved_blocks), |
| 525 | 546 | ATTR_LIST(current_reserved_blocks), |
| 547 | + ATTR_LIST(encoding), | |
| 526 | 548 | NULL, |
| 527 | 549 | }; |
| 528 | 550 | ATTRIBUTE_GROUPS(f2fs); |
| @@ -546,6 +568,7 @@ static struct attribute *f2fs_feat_attrs[] = { · 17 unmodified lines | ||
| 546 | 568 | ATTR_LIST(verity), |
| 547 | 569 | #endif |
| 548 | 570 | ATTR_LIST(sb_checksum), |
| 571 | + ATTR_LIST(casefold), | |
| 549 | 572 | NULL, |
| 550 | 573 | }; |
| 551 | 574 | ATTRIBUTE_GROUPS(f2fs_feat); |
| @@ -21,6 +21,7 @@ · 20 unmodified lines | ||
| 21 | 21 | #include <linux/posix_acl_xattr.h> |
| 22 | 22 | #include "f2fs.h" |
| 23 | 23 | #include "xattr.h" |
| 24 | +#include "segment.h" | |
| 24 | 25 | |
| 25 | 26 | static int f2fs_xattr_generic_get(const struct xattr_handler *handler, |
| 26 | 27 | struct dentry *unused, struct inode *inode, |
| @@ -729,6 +730,11 @@ int f2fs_setxattr(struct inode *inode, int index, const char *name, · 702 unmodified lines | ||
| 729 | 730 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
| 730 | 731 | int err; |
| 731 | 732 | |
| 733 | + if (unlikely(f2fs_cp_error(sbi))) | |
| 734 | + return -EIO; | |
| 735 | + if (!f2fs_is_checkpoint_ready(sbi)) | |
| 736 | + return -ENOSPC; | |
| 737 | + | |
| 732 | 738 | err = dquot_initialize(inode); |
| 733 | 739 | if (err) |
| 734 | 740 | return err; |
| @@ -36,11 +36,17 @@ · 35 unmodified lines | ||
| 36 | 36 | |
| 37 | 37 | #define F2FS_MAX_QUOTAS 3 |
| 38 | 38 | |
| 39 | +#define F2FS_ENC_UTF8_12_1 1 | |
| 40 | +#define F2FS_ENC_STRICT_MODE_FL (1 << 0) | |
| 41 | +#define f2fs_has_strict_mode(sbi) \ | |
| 42 | + (sbi->s_encoding_flags & F2FS_ENC_STRICT_MODE_FL) | |
| 43 | + | |
| 39 | 44 | #define F2FS_IO_SIZE(sbi) (1 << F2FS_OPTION(sbi).write_io_size_bits) /* Blocks */ |
| 40 | 45 | #define F2FS_IO_SIZE_KB(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 2)) /* KB */ |
| 41 | 46 | #define F2FS_IO_SIZE_BYTES(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 12)) /* B */ |
| 42 | 47 | #define F2FS_IO_SIZE_BITS(sbi) (F2FS_OPTION(sbi).write_io_size_bits) /* power of 2 */ |
| 43 | 48 | #define F2FS_IO_SIZE_MASK(sbi) (F2FS_IO_SIZE(sbi) - 1) |
| 49 | +#define F2FS_IO_ALIGNED(sbi) (F2FS_IO_SIZE(sbi) > 1) | |
| 44 | 50 | |
| 45 | 51 | /* This flag is used by node and meta inodes, and by recovery */ |
| 46 | 52 | #define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO) |
| @@ -109,7 +115,9 @@ struct f2fs_super_block { · 62 unmodified lines | ||
| 109 | 115 | struct f2fs_device devs[MAX_DEVICES]; /* device list */ |
| 110 | 116 | __le32 qf_ino[F2FS_MAX_QUOTAS]; /* quota inode numbers */ |
| 111 | 117 | __u8 hot_ext_count; /* # of hot file extension */ |
| 112 | − __u8 reserved[310]; /* valid reserved region */ | |
| 118 | + __le16 s_encoding; /* Filename charset encoding */ | |
| 119 | + __le16 s_encoding_flags; /* Filename charset encoding flags */ | |
| 120 | + __u8 reserved[306]; /* valid reserved region */ | |
| 113 | 121 | __le32 crc; /* checksum of superblock */ |
| 114 | 122 | } __packed; |
| 115 | 123 | |
| @@ -264,6 +264,7 @@ struct fsxattr { · 263 unmodified lines | ||
| 264 | 264 | #define FS_NOCOW_FL 0x00800000 /* Do not cow file */ |
| 265 | 265 | #define FS_INLINE_DATA_FL 0x10000000 /* Reserved for ext4 */ |
| 266 | 266 | #define FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ |
| 267 | +#define FS_CASEFOLD_FL 0x40000000 /* Folder is case insensitive */ | |
| 267 | 268 | #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ |
| 268 | 269 | |
| 269 | 270 | #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ |
| @@ -311,6 +311,7 @@ struct fscrypt_key { · 310 unmodified lines | ||
| 311 | 311 | #define FS_NOCOW_FL 0x00800000 /* Do not cow file */ |
| 312 | 312 | #define FS_INLINE_DATA_FL 0x10000000 /* Reserved for ext4 */ |
| 313 | 313 | #define FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ |
| 314 | +#define FS_CASEFOLD_FL 0x40000000 /* Folder is case insensitive */ | |
| 314 | 315 | #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ |
| 315 | 316 | |
| 316 | 317 | #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ |