diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2019-09-21 17:26:33 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-09-21 17:26:33 -0400 |
commit | fbc246a12aac27f7b25a37f9398bb3bc552cec92 (patch) | |
tree | 4b28f91eeda2c6d7d4db86e7c97fca2d305b6706 | |
parent | 7ce1e15d9a85a2b589a68a04afb2b2ded109b680 (diff) | |
parent | fbbf779989d2ef9a51daaa4e53c0b2ecc8c55c4e (diff) |
Merge tag 'f2fs-for-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
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
...
-rw-r--r-- | Documentation/ABI/testing/sysfs-fs-f2fs | 7 | ||||
-rw-r--r-- | Documentation/filesystems/f2fs.txt | 8 | ||||
-rw-r--r-- | fs/f2fs/Kconfig | 5 | ||||
-rw-r--r-- | fs/f2fs/data.c | 104 | ||||
-rw-r--r-- | fs/f2fs/debug.c | 4 | ||||
-rw-r--r-- | fs/f2fs/dir.c | 184 | ||||
-rw-r--r-- | fs/f2fs/f2fs.h | 47 | ||||
-rw-r--r-- | fs/f2fs/file.c | 162 | ||||
-rw-r--r-- | fs/f2fs/gc.c | 27 | ||||
-rw-r--r-- | fs/f2fs/hash.c | 37 | ||||
-rw-r--r-- | fs/f2fs/inline.c | 18 | ||||
-rw-r--r-- | fs/f2fs/inode.c | 11 | ||||
-rw-r--r-- | fs/f2fs/namei.c | 54 | ||||
-rw-r--r-- | fs/f2fs/node.c | 57 | ||||
-rw-r--r-- | fs/f2fs/segment.c | 135 | ||||
-rw-r--r-- | fs/f2fs/segment.h | 12 | ||||
-rw-r--r-- | fs/f2fs/super.c | 156 | ||||
-rw-r--r-- | fs/f2fs/sysfs.c | 23 | ||||
-rw-r--r-- | fs/f2fs/xattr.c | 6 | ||||
-rw-r--r-- | include/linux/f2fs_fs.h | 10 | ||||
-rw-r--r-- | include/uapi/linux/fs.h | 1 | ||||
-rw-r--r-- | tools/include/uapi/linux/fs.h | 1 |
22 files changed, 865 insertions, 204 deletions
diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index dca326e0ee3e..7ab2b1b5e255 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs | |||
@@ -251,3 +251,10 @@ Description: | |||
251 | If checkpoint=disable, it displays the number of blocks that are unusable. | 251 | If checkpoint=disable, it displays the number of blocks that are unusable. |
252 | If checkpoint=enable it displays the enumber of blocks that would be unusable | 252 | If checkpoint=enable it displays the enumber of blocks that would be unusable |
253 | if checkpoint=disable were to be set. | 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) | ||
diff --git a/Documentation/filesystems/f2fs.txt b/Documentation/filesystems/f2fs.txt index 496fa28b2492..7e1991328473 100644 --- a/Documentation/filesystems/f2fs.txt +++ b/Documentation/filesystems/f2fs.txt | |||
@@ -157,6 +157,11 @@ noinline_data Disable the inline data feature, inline data feature is | |||
157 | enabled by default. | 157 | enabled by default. |
158 | data_flush Enable data flushing before checkpoint in order to | 158 | data_flush Enable data flushing before checkpoint in order to |
159 | persist data of regular and symlink. | 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 | fault_injection=%d Enable fault injection in all supported types with | 165 | fault_injection=%d Enable fault injection in all supported types with |
161 | specified injection rate. | 166 | specified injection rate. |
162 | fault_type=%d Support configuring fault injection type, should be | 167 | fault_type=%d Support configuring fault injection type, should be |
@@ -413,6 +418,9 @@ Files in /sys/fs/f2fs/<devname> | |||
413 | that would be unusable if checkpoint=disable were | 418 | that would be unusable if checkpoint=disable were |
414 | to be set. | 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 | USAGE | 425 | USAGE |
418 | ================================================================================ | 426 | ================================================================================ |
diff --git a/fs/f2fs/Kconfig b/fs/f2fs/Kconfig index 110a38ca5d53..652fd2e2b23d 100644 --- a/fs/f2fs/Kconfig +++ b/fs/f2fs/Kconfig | |||
@@ -2,6 +2,7 @@ | |||
2 | config F2FS_FS | 2 | config F2FS_FS |
3 | tristate "F2FS filesystem support" | 3 | tristate "F2FS filesystem support" |
4 | depends on BLOCK | 4 | depends on BLOCK |
5 | select NLS | ||
5 | select CRYPTO | 6 | select CRYPTO |
6 | select CRYPTO_CRC32 | 7 | select CRYPTO_CRC32 |
7 | select F2FS_FS_XATTR if FS_ENCRYPTION | 8 | select F2FS_FS_XATTR if FS_ENCRYPTION |
@@ -60,7 +61,9 @@ config F2FS_FS_SECURITY | |||
60 | Security Models (LSMs) accepted by AppArmor, SELinux, Smack and TOMOYO | 61 | Security Models (LSMs) accepted by AppArmor, SELinux, Smack and TOMOYO |
61 | Linux. This option enables an extended attribute handler for file | 62 | Linux. This option enables an extended attribute handler for file |
62 | security labels in the f2fs filesystem, so that it requires enabling | 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 | If you are not using a security module, say N. | 68 | If you are not using a security module, say N. |
66 | 69 | ||
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 54cad80acb7d..5755e897a5f0 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c | |||
@@ -283,26 +283,25 @@ static bool __same_bdev(struct f2fs_sb_info *sbi, | |||
283 | /* | 283 | /* |
284 | * Low-level block read/write IO operations. | 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, | 286 | static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages) |
287 | struct writeback_control *wbc, | ||
288 | int npages, bool is_read, | ||
289 | enum page_type type, enum temp_type temp) | ||
290 | { | 287 | { |
288 | struct f2fs_sb_info *sbi = fio->sbi; | ||
291 | struct bio *bio; | 289 | struct bio *bio; |
292 | 290 | ||
293 | bio = f2fs_bio_alloc(sbi, npages, true); | 291 | bio = f2fs_bio_alloc(sbi, npages, true); |
294 | 292 | ||
295 | f2fs_target_device(sbi, blk_addr, bio); | 293 | f2fs_target_device(sbi, fio->new_blkaddr, bio); |
296 | if (is_read) { | 294 | if (is_read_io(fio->op)) { |
297 | bio->bi_end_io = f2fs_read_end_io; | 295 | bio->bi_end_io = f2fs_read_end_io; |
298 | bio->bi_private = NULL; | 296 | bio->bi_private = NULL; |
299 | } else { | 297 | } else { |
300 | bio->bi_end_io = f2fs_write_end_io; | 298 | bio->bi_end_io = f2fs_write_end_io; |
301 | bio->bi_private = sbi; | 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) | 303 | if (fio->io_wbc) |
305 | wbc_init_bio(wbc, bio); | 304 | wbc_init_bio(fio->io_wbc, bio); |
306 | 305 | ||
307 | return bio; | 306 | return bio; |
308 | } | 307 | } |
@@ -319,6 +318,9 @@ static inline void __submit_bio(struct f2fs_sb_info *sbi, | |||
319 | if (test_opt(sbi, LFS) && current->plug) | 318 | if (test_opt(sbi, LFS) && current->plug) |
320 | blk_finish_plug(current->plug); | 319 | blk_finish_plug(current->plug); |
321 | 320 | ||
321 | if (F2FS_IO_ALIGNED(sbi)) | ||
322 | goto submit_io; | ||
323 | |||
322 | start = bio->bi_iter.bi_size >> F2FS_BLKSIZE_BITS; | 324 | start = bio->bi_iter.bi_size >> F2FS_BLKSIZE_BITS; |
323 | start %= F2FS_IO_SIZE(sbi); | 325 | start %= F2FS_IO_SIZE(sbi); |
324 | 326 | ||
@@ -485,8 +487,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) | |||
485 | f2fs_trace_ios(fio, 0); | 487 | f2fs_trace_ios(fio, 0); |
486 | 488 | ||
487 | /* Allocate a new bio */ | 489 | /* Allocate a new bio */ |
488 | bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc, | 490 | bio = __bio_alloc(fio, 1); |
489 | 1, is_read_io(fio->op), fio->type, fio->temp); | ||
490 | 491 | ||
491 | if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { | 492 | if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { |
492 | bio_put(bio); | 493 | bio_put(bio); |
@@ -505,6 +506,43 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) | |||
505 | return 0; | 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 | int f2fs_merge_page_bio(struct f2fs_io_info *fio) | 546 | int f2fs_merge_page_bio(struct f2fs_io_info *fio) |
509 | { | 547 | { |
510 | struct bio *bio = *fio->bio; | 548 | struct bio *bio = *fio->bio; |
@@ -518,15 +556,14 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) | |||
518 | trace_f2fs_submit_page_bio(page, fio); | 556 | trace_f2fs_submit_page_bio(page, fio); |
519 | f2fs_trace_ios(fio, 0); | 557 | f2fs_trace_ios(fio, 0); |
520 | 558 | ||
521 | if (bio && (*fio->last_block + 1 != fio->new_blkaddr || | 559 | if (bio && !page_is_mergeable(fio->sbi, bio, *fio->last_block, |
522 | !__same_bdev(fio->sbi, fio->new_blkaddr, bio))) { | 560 | fio->new_blkaddr)) { |
523 | __submit_bio(fio->sbi, bio, fio->type); | 561 | __submit_bio(fio->sbi, bio, fio->type); |
524 | bio = NULL; | 562 | bio = NULL; |
525 | } | 563 | } |
526 | alloc_new: | 564 | alloc_new: |
527 | if (!bio) { | 565 | if (!bio) { |
528 | bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc, | 566 | bio = __bio_alloc(fio, BIO_MAX_PAGES); |
529 | BIO_MAX_PAGES, false, fio->type, fio->temp); | ||
530 | bio_set_op_attrs(bio, fio->op, fio->op_flags); | 567 | bio_set_op_attrs(bio, fio->op, fio->op_flags); |
531 | } | 568 | } |
532 | 569 | ||
@@ -592,21 +629,19 @@ next: | |||
592 | 629 | ||
593 | inc_page_count(sbi, WB_DATA_TYPE(bio_page)); | 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 || | 632 | if (io->bio && !io_is_mergeable(sbi, io->bio, io, fio, |
596 | (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags) || | 633 | io->last_block_in_bio, fio->new_blkaddr)) |
597 | !__same_bdev(sbi, fio->new_blkaddr, io->bio))) | ||
598 | __submit_merged_bio(io); | 634 | __submit_merged_bio(io); |
599 | alloc_new: | 635 | alloc_new: |
600 | if (io->bio == NULL) { | 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 | fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { | 639 | fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { |
603 | dec_page_count(sbi, WB_DATA_TYPE(bio_page)); | 640 | dec_page_count(sbi, WB_DATA_TYPE(bio_page)); |
604 | fio->retry = true; | 641 | fio->retry = true; |
605 | goto skip; | 642 | goto skip; |
606 | } | 643 | } |
607 | io->bio = __bio_alloc(sbi, fio->new_blkaddr, fio->io_wbc, | 644 | io->bio = __bio_alloc(fio, BIO_MAX_PAGES); |
608 | BIO_MAX_PAGES, false, | ||
609 | fio->type, fio->temp); | ||
610 | io->fio = *fio; | 645 | io->fio = *fio; |
611 | } | 646 | } |
612 | 647 | ||
@@ -627,7 +662,7 @@ skip: | |||
627 | goto next; | 662 | goto next; |
628 | out: | 663 | out: |
629 | if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) || | 664 | if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) || |
630 | f2fs_is_checkpoint_ready(sbi)) | 665 | !f2fs_is_checkpoint_ready(sbi)) |
631 | __submit_merged_bio(io); | 666 | __submit_merged_bio(io); |
632 | up_write(&io->io_rwsem); | 667 | up_write(&io->io_rwsem); |
633 | } | 668 | } |
@@ -1022,7 +1057,7 @@ alloc: | |||
1022 | if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) | 1057 | if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) |
1023 | invalidate_mapping_pages(META_MAPPING(sbi), | 1058 | invalidate_mapping_pages(META_MAPPING(sbi), |
1024 | old_blkaddr, old_blkaddr); | 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 | * i_size will be updated by direct_IO. Otherwise, we'll get stale | 1063 | * i_size will be updated by direct_IO. Otherwise, we'll get stale |
@@ -1199,10 +1234,10 @@ next_block: | |||
1199 | if (test_opt(sbi, LFS) && flag == F2FS_GET_BLOCK_DIO && | 1234 | if (test_opt(sbi, LFS) && flag == F2FS_GET_BLOCK_DIO && |
1200 | map->m_may_create) { | 1235 | map->m_may_create) { |
1201 | err = __allocate_data_block(&dn, map->m_seg_type); | 1236 | err = __allocate_data_block(&dn, map->m_seg_type); |
1202 | if (!err) { | 1237 | if (err) |
1203 | blkaddr = dn.data_blkaddr; | 1238 | goto sync_out; |
1204 | set_inode_flag(inode, FI_APPEND_WRITE); | 1239 | blkaddr = dn.data_blkaddr; |
1205 | } | 1240 | set_inode_flag(inode, FI_APPEND_WRITE); |
1206 | } | 1241 | } |
1207 | } else { | 1242 | } else { |
1208 | if (create) { | 1243 | if (create) { |
@@ -1407,7 +1442,7 @@ static int get_data_block_dio_write(struct inode *inode, sector_t iblock, | |||
1407 | return __get_data_block(inode, iblock, bh_result, create, | 1442 | return __get_data_block(inode, iblock, bh_result, create, |
1408 | F2FS_GET_BLOCK_DIO, NULL, | 1443 | F2FS_GET_BLOCK_DIO, NULL, |
1409 | f2fs_rw_hint_to_seg_type(inode->i_write_hint), | 1444 | f2fs_rw_hint_to_seg_type(inode->i_write_hint), |
1410 | true); | 1445 | IS_SWAPFILE(inode) ? false : true); |
1411 | } | 1446 | } |
1412 | 1447 | ||
1413 | static int get_data_block_dio(struct inode *inode, sector_t iblock, | 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, | |||
1538 | goto out; | 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 | ret = f2fs_inline_data_fiemap(inode, fieinfo, start, len); | 1577 | ret = f2fs_inline_data_fiemap(inode, fieinfo, start, len); |
1543 | if (ret != -EAGAIN) | 1578 | if (ret != -EAGAIN) |
1544 | goto out; | 1579 | goto out; |
@@ -1691,8 +1726,8 @@ zero_out: | |||
1691 | * This page will go to BIO. Do we need to send this | 1726 | * This page will go to BIO. Do we need to send this |
1692 | * BIO off first? | 1727 | * BIO off first? |
1693 | */ | 1728 | */ |
1694 | if (bio && (*last_block_in_bio != block_nr - 1 || | 1729 | if (bio && !page_is_mergeable(F2FS_I_SB(inode), bio, |
1695 | !__same_bdev(F2FS_I_SB(inode), block_nr, bio))) { | 1730 | *last_block_in_bio, block_nr)) { |
1696 | submit_and_realloc: | 1731 | submit_and_realloc: |
1697 | __submit_bio(F2FS_I_SB(inode), bio, DATA); | 1732 | __submit_bio(F2FS_I_SB(inode), bio, DATA); |
1698 | bio = NULL; | 1733 | bio = NULL; |
@@ -2590,9 +2625,10 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, | |||
2590 | 2625 | ||
2591 | trace_f2fs_write_begin(inode, pos, len, flags); | 2626 | trace_f2fs_write_begin(inode, pos, len, flags); |
2592 | 2627 | ||
2593 | err = f2fs_is_checkpoint_ready(sbi); | 2628 | if (!f2fs_is_checkpoint_ready(sbi)) { |
2594 | if (err) | 2629 | err = -ENOSPC; |
2595 | goto fail; | 2630 | goto fail; |
2631 | } | ||
2596 | 2632 | ||
2597 | if ((f2fs_is_atomic_file(inode) && | 2633 | if ((f2fs_is_atomic_file(inode) && |
2598 | !f2fs_available_free_memory(sbi, INMEM_PAGES)) || | 2634 | !f2fs_available_free_memory(sbi, INMEM_PAGES)) || |
diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index 7706049d23bf..9b0bedd82581 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c | |||
@@ -67,7 +67,7 @@ static void update_general_status(struct f2fs_sb_info *sbi) | |||
67 | si->nr_rd_data = get_pages(sbi, F2FS_RD_DATA); | 67 | si->nr_rd_data = get_pages(sbi, F2FS_RD_DATA); |
68 | si->nr_rd_node = get_pages(sbi, F2FS_RD_NODE); | 68 | si->nr_rd_node = get_pages(sbi, F2FS_RD_NODE); |
69 | si->nr_rd_meta = get_pages(sbi, F2FS_RD_META); | 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 | si->nr_flushed = | 71 | si->nr_flushed = |
72 | atomic_read(&SM_I(sbi)->fcc_info->issued_flush); | 72 | atomic_read(&SM_I(sbi)->fcc_info->issued_flush); |
73 | si->nr_flushing = | 73 | si->nr_flushing = |
@@ -75,7 +75,7 @@ static void update_general_status(struct f2fs_sb_info *sbi) | |||
75 | si->flush_list_empty = | 75 | si->flush_list_empty = |
76 | llist_empty(&SM_I(sbi)->fcc_info->issue_list); | 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 | si->nr_discarded = | 79 | si->nr_discarded = |
80 | atomic_read(&SM_I(sbi)->dcc_info->issued_discard); | 80 | atomic_read(&SM_I(sbi)->dcc_info->issued_discard); |
81 | si->nr_discarding = | 81 | si->nr_discarding = |
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 85a1528f319f..4033778bcbbf 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <linux/fs.h> | 8 | #include <linux/fs.h> |
9 | #include <linux/f2fs_fs.h> | 9 | #include <linux/f2fs_fs.h> |
10 | #include <linux/sched/signal.h> | 10 | #include <linux/sched/signal.h> |
11 | #include <linux/unicode.h> | ||
11 | #include "f2fs.h" | 12 | #include "f2fs.h" |
12 | #include "node.h" | 13 | #include "node.h" |
13 | #include "acl.h" | 14 | #include "acl.h" |
@@ -81,7 +82,8 @@ static unsigned long dir_block_index(unsigned int level, | |||
81 | return bidx; | 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 | struct fscrypt_name *fname, | 87 | struct fscrypt_name *fname, |
86 | f2fs_hash_t namehash, | 88 | f2fs_hash_t namehash, |
87 | int *max_slots, | 89 | int *max_slots, |
@@ -93,7 +95,7 @@ static struct f2fs_dir_entry *find_in_block(struct page *dentry_page, | |||
93 | 95 | ||
94 | dentry_blk = (struct f2fs_dentry_block *)page_address(dentry_page); | 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 | de = f2fs_find_target_dentry(fname, namehash, max_slots, &d); | 99 | de = f2fs_find_target_dentry(fname, namehash, max_slots, &d); |
98 | if (de) | 100 | if (de) |
99 | *res_page = dentry_page; | 101 | *res_page = dentry_page; |
@@ -101,14 +103,116 @@ static struct f2fs_dir_entry *find_in_block(struct page *dentry_page, | |||
101 | return de; | 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 | struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, | 203 | struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, |
105 | f2fs_hash_t namehash, int *max_slots, | 204 | f2fs_hash_t namehash, int *max_slots, |
106 | struct f2fs_dentry_ptr *d) | 205 | struct f2fs_dentry_ptr *d) |
107 | { | 206 | { |
108 | struct f2fs_dir_entry *de; | 207 | struct f2fs_dir_entry *de; |
208 | struct fscrypt_str cf_str = { .name = NULL, .len = 0 }; | ||
109 | unsigned long bit_pos = 0; | 209 | unsigned long bit_pos = 0; |
110 | int max_len = 0; | 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 | if (max_slots) | 216 | if (max_slots) |
113 | *max_slots = 0; | 217 | *max_slots = 0; |
114 | while (bit_pos < d->max) { | 218 | while (bit_pos < d->max) { |
@@ -125,9 +229,7 @@ struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, | |||
125 | continue; | 229 | continue; |
126 | } | 230 | } |
127 | 231 | ||
128 | if (de->hash_code == namehash && | 232 | if (f2fs_match_name(d, de, fname, &cf_str, bit_pos, namehash)) |
129 | fscrypt_match_name(fname, d->filename[bit_pos], | ||
130 | le16_to_cpu(de->name_len))) | ||
131 | goto found; | 233 | goto found; |
132 | 234 | ||
133 | if (max_slots && max_len > *max_slots) | 235 | if (max_slots && max_len > *max_slots) |
@@ -141,6 +243,10 @@ struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, | |||
141 | found: | 243 | found: |
142 | if (max_slots && max_len > *max_slots) | 244 | if (max_slots && max_len > *max_slots) |
143 | *max_slots = max_len; | 245 | *max_slots = max_len; |
246 | |||
247 | #ifdef CONFIG_UNICODE | ||
248 | kvfree(cf_str.name); | ||
249 | #endif | ||
144 | return de; | 250 | return de; |
145 | } | 251 | } |
146 | 252 | ||
@@ -157,7 +263,7 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir, | |||
157 | struct f2fs_dir_entry *de = NULL; | 263 | struct f2fs_dir_entry *de = NULL; |
158 | bool room = false; | 264 | bool room = false; |
159 | int max_slots; | 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 | nbucket = dir_buckets(level, F2FS_I(dir)->i_dir_level); | 268 | nbucket = dir_buckets(level, F2FS_I(dir)->i_dir_level); |
163 | nblock = bucket_blocks(level); | 269 | nblock = bucket_blocks(level); |
@@ -179,8 +285,8 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir, | |||
179 | } | 285 | } |
180 | } | 286 | } |
181 | 287 | ||
182 | de = find_in_block(dentry_page, fname, namehash, &max_slots, | 288 | de = find_in_block(dir, dentry_page, fname, namehash, |
183 | res_page); | 289 | &max_slots, res_page); |
184 | if (de) | 290 | if (de) |
185 | break; | 291 | break; |
186 | 292 | ||
@@ -250,6 +356,14 @@ struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, | |||
250 | struct fscrypt_name fname; | 356 | struct fscrypt_name fname; |
251 | int err; | 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 | err = fscrypt_setup_filename(dir, child, 1, &fname); | 367 | err = fscrypt_setup_filename(dir, child, 1, &fname); |
254 | if (err) { | 368 | if (err) { |
255 | if (err == -ENOENT) | 369 | if (err == -ENOENT) |
@@ -504,7 +618,7 @@ int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, | |||
504 | 618 | ||
505 | level = 0; | 619 | level = 0; |
506 | slots = GET_DENTRY_SLOTS(new_name->len); | 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 | current_depth = F2FS_I(dir)->i_current_depth; | 623 | current_depth = F2FS_I(dir)->i_current_depth; |
510 | if (F2FS_I(dir)->chash == dentry_hash) { | 624 | if (F2FS_I(dir)->chash == dentry_hash) { |
@@ -568,6 +682,11 @@ add_dentry: | |||
568 | 682 | ||
569 | if (inode) { | 683 | if (inode) { |
570 | f2fs_i_pino_write(inode, dir->i_ino); | 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 | f2fs_put_page(page, 1); | 690 | f2fs_put_page(page, 1); |
572 | } | 691 | } |
573 | 692 | ||
@@ -943,3 +1062,50 @@ const struct file_operations f2fs_dir_operations = { | |||
943 | .compat_ioctl = f2fs_compat_ioctl, | 1062 | .compat_ioctl = f2fs_compat_ioctl, |
944 | #endif | 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 | ||
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 7c5f121edac5..4024790028aa 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h | |||
@@ -154,6 +154,7 @@ struct f2fs_mount_info { | |||
154 | #define F2FS_FEATURE_LOST_FOUND 0x0200 | 154 | #define F2FS_FEATURE_LOST_FOUND 0x0200 |
155 | #define F2FS_FEATURE_VERITY 0x0400 | 155 | #define F2FS_FEATURE_VERITY 0x0400 |
156 | #define F2FS_FEATURE_SB_CHKSUM 0x0800 | 156 | #define F2FS_FEATURE_SB_CHKSUM 0x0800 |
157 | #define F2FS_FEATURE_CASEFOLD 0x1000 | ||
157 | 158 | ||
158 | #define __F2FS_HAS_FEATURE(raw_super, mask) \ | 159 | #define __F2FS_HAS_FEATURE(raw_super, mask) \ |
159 | ((raw_super->feature & cpu_to_le32(mask)) != 0) | 160 | ((raw_super->feature & cpu_to_le32(mask)) != 0) |
@@ -418,6 +419,9 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal, | |||
418 | #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) | 419 | #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) |
419 | #define F2FS_IOC_RESIZE_FS _IOW(F2FS_IOCTL_MAGIC, 16, __u64) | 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 | #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY | 425 | #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY |
422 | #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY | 426 | #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY |
423 | #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT | 427 | #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT |
@@ -1172,6 +1176,10 @@ struct f2fs_sb_info { | |||
1172 | int valid_super_block; /* valid super block no */ | 1176 | int valid_super_block; /* valid super block no */ |
1173 | unsigned long s_flag; /* flags for sbi */ | 1177 | unsigned long s_flag; /* flags for sbi */ |
1174 | struct mutex writepages; /* mutex for writepages() */ | 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 | #ifdef CONFIG_BLK_DEV_ZONED | 1184 | #ifdef CONFIG_BLK_DEV_ZONED |
1177 | unsigned int blocks_per_blkz; /* F2FS blocks per zone */ | 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) | |||
1643 | static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) | 1651 | static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) |
1644 | { | 1652 | { |
1645 | unsigned long flags; | 1653 | unsigned long flags; |
1654 | unsigned char *nat_bits; | ||
1646 | 1655 | ||
1647 | /* | 1656 | /* |
1648 | * In order to re-enable nat_bits we need to call fsck.f2fs by | 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) | |||
1653 | if (lock) | 1662 | if (lock) |
1654 | spin_lock_irqsave(&sbi->cp_lock, flags); | 1663 | spin_lock_irqsave(&sbi->cp_lock, flags); |
1655 | __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); | 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 | NM_I(sbi)->nat_bits = NULL; | 1666 | NM_I(sbi)->nat_bits = NULL; |
1658 | if (lock) | 1667 | if (lock) |
1659 | spin_unlock_irqrestore(&sbi->cp_lock, flags); | 1668 | spin_unlock_irqrestore(&sbi->cp_lock, flags); |
1669 | |||
1670 | kvfree(nat_bits); | ||
1660 | } | 1671 | } |
1661 | 1672 | ||
1662 | static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, | 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, | |||
1763 | if (time_to_inject(sbi, FAULT_BLOCK)) { | 1774 | if (time_to_inject(sbi, FAULT_BLOCK)) { |
1764 | f2fs_show_injection_info(FAULT_BLOCK); | 1775 | f2fs_show_injection_info(FAULT_BLOCK); |
1765 | release = *count; | 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, | |||
1808 | 1819 | ||
1809 | enospc: | 1820 | enospc: |
1810 | percpu_counter_sub(&sbi->alloc_valid_block_count, release); | 1821 | percpu_counter_sub(&sbi->alloc_valid_block_count, release); |
1822 | release_quota: | ||
1811 | dquot_release_reservation_block(inode, release); | 1823 | dquot_release_reservation_block(inode, release); |
1812 | return -ENOSPC; | 1824 | return -ENOSPC; |
1813 | } | 1825 | } |
@@ -2362,13 +2374,16 @@ static inline void f2fs_change_bit(unsigned int nr, char *addr) | |||
2362 | #define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */ | 2374 | #define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */ |
2363 | #define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ | 2375 | #define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ |
2364 | #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ | 2376 | #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ |
2377 | #define F2FS_CASEFOLD_FL 0x40000000 /* Casefolded file */ | ||
2365 | 2378 | ||
2366 | /* Flags that should be inherited by new inodes from their parent. */ | 2379 | /* Flags that should be inherited by new inodes from their parent. */ |
2367 | #define F2FS_FL_INHERITED (F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL | \ | 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 | /* Flags that are appropriate for regular files (all but dir-specific ones). */ | 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 | /* Flags that are appropriate for non-directories/regular files. */ | 2388 | /* Flags that are appropriate for non-directories/regular files. */ |
2374 | #define F2FS_OTHER_FLMASK (F2FS_NODUMP_FL | F2FS_NOATIME_FL) | 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, | |||
2935 | bool hot, bool set); | 2950 | bool hot, bool set); |
2936 | struct dentry *f2fs_get_parent(struct dentry *child); | 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 | * dir.c | 2959 | * dir.c |
2940 | */ | 2960 | */ |
@@ -2998,8 +3018,8 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); | |||
2998 | /* | 3018 | /* |
2999 | * hash.c | 3019 | * hash.c |
3000 | */ | 3020 | */ |
3001 | f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, | 3021 | f2fs_hash_t f2fs_dentry_hash(const struct inode *dir, |
3002 | struct fscrypt_name *fname); | 3022 | const struct qstr *name_info, struct fscrypt_name *fname); |
3003 | 3023 | ||
3004 | /* | 3024 | /* |
3005 | * node.c | 3025 | * node.c |
@@ -3442,6 +3462,9 @@ static inline void f2fs_destroy_root_stats(void) { } | |||
3442 | #endif | 3462 | #endif |
3443 | 3463 | ||
3444 | extern const struct file_operations f2fs_dir_operations; | 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 | extern const struct file_operations f2fs_file_operations; | 3468 | extern const struct file_operations f2fs_file_operations; |
3446 | extern const struct inode_operations f2fs_file_inode_operations; | 3469 | extern const struct inode_operations f2fs_file_inode_operations; |
3447 | extern const struct address_space_operations f2fs_dblock_aops; | 3470 | extern const struct address_space_operations f2fs_dblock_aops; |
@@ -3576,6 +3599,7 @@ F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); | |||
3576 | F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); | 3599 | F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); |
3577 | F2FS_FEATURE_FUNCS(verity, VERITY); | 3600 | F2FS_FEATURE_FUNCS(verity, VERITY); |
3578 | F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); | 3601 | F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); |
3602 | F2FS_FEATURE_FUNCS(casefold, CASEFOLD); | ||
3579 | 3603 | ||
3580 | #ifdef CONFIG_BLK_DEV_ZONED | 3604 | #ifdef CONFIG_BLK_DEV_ZONED |
3581 | static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi, | 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, | |||
3694 | */ | 3718 | */ |
3695 | if (f2fs_sb_has_blkzoned(sbi)) | 3719 | if (f2fs_sb_has_blkzoned(sbi)) |
3696 | return true; | 3720 | return true; |
3697 | if (test_opt(sbi, LFS) && (rw == WRITE) && | 3721 | if (test_opt(sbi, LFS) && (rw == WRITE)) { |
3698 | block_unaligned_IO(inode, iocb, iter)) | 3722 | if (block_unaligned_IO(inode, iocb, iter)) |
3699 | return true; | 3723 | return true; |
3724 | if (F2FS_IO_ALIGNED(sbi)) | ||
3725 | return true; | ||
3726 | } | ||
3700 | if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED) && | 3727 | if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED) && |
3701 | !(inode->i_flags & S_SWAPFILE)) | 3728 | !IS_SWAPFILE(inode)) |
3702 | return true; | 3729 | return true; |
3703 | 3730 | ||
3704 | return false; | 3731 | return false; |
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 56efde9d3659..29bc0a542759 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/uio.h> | 20 | #include <linux/uio.h> |
21 | #include <linux/uuid.h> | 21 | #include <linux/uuid.h> |
22 | #include <linux/file.h> | 22 | #include <linux/file.h> |
23 | #include <linux/nls.h> | ||
23 | 24 | ||
24 | #include "f2fs.h" | 25 | #include "f2fs.h" |
25 | #include "node.h" | 26 | #include "node.h" |
@@ -57,6 +58,11 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) | |||
57 | goto err; | 58 | goto err; |
58 | } | 59 | } |
59 | 60 | ||
61 | if (!f2fs_is_checkpoint_ready(sbi)) { | ||
62 | err = -ENOSPC; | ||
63 | goto err; | ||
64 | } | ||
65 | |||
60 | sb_start_pagefault(inode->i_sb); | 66 | sb_start_pagefault(inode->i_sb); |
61 | 67 | ||
62 | f2fs_bug_on(sbi, f2fs_has_inline_data(inode)); | 68 | f2fs_bug_on(sbi, f2fs_has_inline_data(inode)); |
@@ -819,14 +825,24 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) | |||
819 | } | 825 | } |
820 | 826 | ||
821 | if (attr->ia_valid & ATTR_SIZE) { | 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 | down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); | 840 | down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
825 | down_write(&F2FS_I(inode)->i_mmap_sem); | 841 | down_write(&F2FS_I(inode)->i_mmap_sem); |
826 | 842 | ||
827 | truncate_setsize(inode, attr->ia_size); | 843 | truncate_setsize(inode, attr->ia_size); |
828 | 844 | ||
829 | if (to_smaller) | 845 | if (attr->ia_size <= old_size) |
830 | err = f2fs_truncate(inode); | 846 | err = f2fs_truncate(inode); |
831 | /* | 847 | /* |
832 | * do not trim all blocks after i_size if target size is | 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) | |||
834 | */ | 850 | */ |
835 | up_write(&F2FS_I(inode)->i_mmap_sem); | 851 | up_write(&F2FS_I(inode)->i_mmap_sem); |
836 | up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); | 852 | up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
837 | |||
838 | if (err) | 853 | if (err) |
839 | return err; | 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 | down_write(&F2FS_I(inode)->i_sem); | 856 | down_write(&F2FS_I(inode)->i_sem); |
857 | inode->i_mtime = inode->i_ctime = current_time(inode); | ||
852 | F2FS_I(inode)->last_disk_size = i_size_read(inode); | 858 | F2FS_I(inode)->last_disk_size = i_size_read(inode); |
853 | up_write(&F2FS_I(inode)->i_sem); | 859 | up_write(&F2FS_I(inode)->i_sem); |
854 | } | 860 | } |
@@ -1041,7 +1047,7 @@ next_dnode: | |||
1041 | 1047 | ||
1042 | if (test_opt(sbi, LFS)) { | 1048 | if (test_opt(sbi, LFS)) { |
1043 | f2fs_put_dnode(&dn); | 1049 | f2fs_put_dnode(&dn); |
1044 | return -ENOTSUPP; | 1050 | return -EOPNOTSUPP; |
1045 | } | 1051 | } |
1046 | 1052 | ||
1047 | /* do not invalidate this block address */ | 1053 | /* do not invalidate this block address */ |
@@ -1578,6 +1584,8 @@ static long f2fs_fallocate(struct file *file, int mode, | |||
1578 | 1584 | ||
1579 | if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) | 1585 | if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) |
1580 | return -EIO; | 1586 | return -EIO; |
1587 | if (!f2fs_is_checkpoint_ready(F2FS_I_SB(inode))) | ||
1588 | return -ENOSPC; | ||
1581 | 1589 | ||
1582 | /* f2fs only support ->fallocate for regular file */ | 1590 | /* f2fs only support ->fallocate for regular file */ |
1583 | if (!S_ISREG(inode->i_mode)) | 1591 | if (!S_ISREG(inode->i_mode)) |
@@ -1669,6 +1677,13 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask) | |||
1669 | if (IS_NOQUOTA(inode)) | 1677 | if (IS_NOQUOTA(inode)) |
1670 | return -EPERM; | 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 | fi->i_flags = iflags | (fi->i_flags & ~mask); | 1687 | fi->i_flags = iflags | (fi->i_flags & ~mask); |
1673 | 1688 | ||
1674 | if (fi->i_flags & F2FS_PROJINHERIT_FL) | 1689 | if (fi->i_flags & F2FS_PROJINHERIT_FL) |
@@ -1703,6 +1718,7 @@ static const struct { | |||
1703 | { F2FS_INDEX_FL, FS_INDEX_FL }, | 1718 | { F2FS_INDEX_FL, FS_INDEX_FL }, |
1704 | { F2FS_DIRSYNC_FL, FS_DIRSYNC_FL }, | 1719 | { F2FS_DIRSYNC_FL, FS_DIRSYNC_FL }, |
1705 | { F2FS_PROJINHERIT_FL, FS_PROJINHERIT_FL }, | 1720 | { F2FS_PROJINHERIT_FL, FS_PROJINHERIT_FL }, |
1721 | { F2FS_CASEFOLD_FL, FS_CASEFOLD_FL }, | ||
1706 | }; | 1722 | }; |
1707 | 1723 | ||
1708 | #define F2FS_GETTABLE_FS_FL ( \ | 1724 | #define F2FS_GETTABLE_FS_FL ( \ |
@@ -1717,7 +1733,8 @@ static const struct { | |||
1717 | FS_ENCRYPT_FL | \ | 1733 | FS_ENCRYPT_FL | \ |
1718 | FS_INLINE_DATA_FL | \ | 1734 | FS_INLINE_DATA_FL | \ |
1719 | FS_NOCOW_FL | \ | 1735 | FS_NOCOW_FL | \ |
1720 | FS_VERITY_FL) | 1736 | FS_VERITY_FL | \ |
1737 | FS_CASEFOLD_FL) | ||
1721 | 1738 | ||
1722 | #define F2FS_SETTABLE_FS_FL ( \ | 1739 | #define F2FS_SETTABLE_FS_FL ( \ |
1723 | FS_SYNC_FL | \ | 1740 | FS_SYNC_FL | \ |
@@ -1726,7 +1743,8 @@ static const struct { | |||
1726 | FS_NODUMP_FL | \ | 1743 | FS_NODUMP_FL | \ |
1727 | FS_NOATIME_FL | \ | 1744 | FS_NOATIME_FL | \ |
1728 | FS_DIRSYNC_FL | \ | 1745 | FS_DIRSYNC_FL | \ |
1729 | FS_PROJINHERIT_FL) | 1746 | FS_PROJINHERIT_FL | \ |
1747 | FS_CASEFOLD_FL) | ||
1730 | 1748 | ||
1731 | /* Convert f2fs on-disk i_flags to FS_IOC_{GET,SET}FLAGS flags */ | 1749 | /* Convert f2fs on-disk i_flags to FS_IOC_{GET,SET}FLAGS flags */ |
1732 | static inline u32 f2fs_iflags_to_fsflags(u32 iflags) | 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) | |||
1825 | static int f2fs_ioc_start_atomic_write(struct file *filp) | 1843 | static int f2fs_ioc_start_atomic_write(struct file *filp) |
1826 | { | 1844 | { |
1827 | struct inode *inode = file_inode(filp); | 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 | int ret; | 1848 | int ret; |
1829 | 1849 | ||
1830 | if (!inode_owner_or_capable(inode)) | 1850 | if (!inode_owner_or_capable(inode)) |
@@ -1833,6 +1853,9 @@ static int f2fs_ioc_start_atomic_write(struct file *filp) | |||
1833 | if (!S_ISREG(inode->i_mode)) | 1853 | if (!S_ISREG(inode->i_mode)) |
1834 | return -EINVAL; | 1854 | return -EINVAL; |
1835 | 1855 | ||
1856 | if (filp->f_flags & O_DIRECT) | ||
1857 | return -EINVAL; | ||
1858 | |||
1836 | ret = mnt_want_write_file(filp); | 1859 | ret = mnt_want_write_file(filp); |
1837 | if (ret) | 1860 | if (ret) |
1838 | return ret; | 1861 | return ret; |
@@ -1864,6 +1887,12 @@ static int f2fs_ioc_start_atomic_write(struct file *filp) | |||
1864 | goto out; | 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 | set_inode_flag(inode, FI_ATOMIC_FILE); | 1896 | set_inode_flag(inode, FI_ATOMIC_FILE); |
1868 | clear_inode_flag(inode, FI_ATOMIC_REVOKE_REQUEST); | 1897 | clear_inode_flag(inode, FI_ATOMIC_REVOKE_REQUEST); |
1869 | up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); | 1898 | up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
@@ -1905,11 +1934,8 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp) | |||
1905 | goto err_out; | 1934 | goto err_out; |
1906 | 1935 | ||
1907 | ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 0, true); | 1936 | ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 0, true); |
1908 | if (!ret) { | 1937 | if (!ret) |
1909 | clear_inode_flag(inode, FI_ATOMIC_FILE); | 1938 | f2fs_drop_inmem_pages(inode); |
1910 | F2FS_I(inode)->i_gc_failures[GC_FAILURE_ATOMIC] = 0; | ||
1911 | stat_dec_atomic_write(inode); | ||
1912 | } | ||
1913 | } else { | 1939 | } else { |
1914 | ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 1, false); | 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) | |||
2295 | return -EROFS; | 2321 | return -EROFS; |
2296 | 2322 | ||
2297 | end = range.start + range.len; | 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 | return -EINVAL; | 2326 | return -EINVAL; |
2300 | } | ||
2301 | 2327 | ||
2302 | ret = mnt_want_write_file(filp); | 2328 | ret = mnt_want_write_file(filp); |
2303 | if (ret) | 2329 | if (ret) |
@@ -2421,8 +2447,10 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, | |||
2421 | map.m_lblk += map.m_len; | 2447 | map.m_lblk += map.m_len; |
2422 | } | 2448 | } |
2423 | 2449 | ||
2424 | if (!fragmented) | 2450 | if (!fragmented) { |
2451 | total = 0; | ||
2425 | goto out; | 2452 | goto out; |
2453 | } | ||
2426 | 2454 | ||
2427 | sec_num = DIV_ROUND_UP(total, BLKS_PER_SEC(sbi)); | 2455 | sec_num = DIV_ROUND_UP(total, BLKS_PER_SEC(sbi)); |
2428 | 2456 | ||
@@ -2452,7 +2480,7 @@ do_map: | |||
2452 | 2480 | ||
2453 | if (!(map.m_flags & F2FS_MAP_FLAGS)) { | 2481 | if (!(map.m_flags & F2FS_MAP_FLAGS)) { |
2454 | map.m_lblk = next_pgofs; | 2482 | map.m_lblk = next_pgofs; |
2455 | continue; | 2483 | goto check; |
2456 | } | 2484 | } |
2457 | 2485 | ||
2458 | set_inode_flag(inode, FI_DO_DEFRAG); | 2486 | set_inode_flag(inode, FI_DO_DEFRAG); |
@@ -2476,8 +2504,8 @@ do_map: | |||
2476 | } | 2504 | } |
2477 | 2505 | ||
2478 | map.m_lblk = idx; | 2506 | map.m_lblk = idx; |
2479 | 2507 | check: | |
2480 | if (idx < pg_end && cnt < blk_per_seg) | 2508 | if (map.m_lblk < pg_end && cnt < blk_per_seg) |
2481 | goto do_map; | 2509 | goto do_map; |
2482 | 2510 | ||
2483 | clear_inode_flag(inode, FI_DO_DEFRAG); | 2511 | clear_inode_flag(inode, FI_DO_DEFRAG); |
@@ -3141,10 +3169,74 @@ static int f2fs_ioc_measure_verity(struct file *filp, unsigned long arg) | |||
3141 | return fsverity_ioctl_measure(filp, (void __user *)arg); | 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 | long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | 3234 | long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
3145 | { | 3235 | { |
3146 | if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) | 3236 | if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) |
3147 | return -EIO; | 3237 | return -EIO; |
3238 | if (!f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(filp)))) | ||
3239 | return -ENOSPC; | ||
3148 | 3240 | ||
3149 | switch (cmd) { | 3241 | switch (cmd) { |
3150 | case F2FS_IOC_GETFLAGS: | 3242 | case F2FS_IOC_GETFLAGS: |
@@ -3213,6 +3305,10 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | |||
3213 | return f2fs_ioc_enable_verity(filp, arg); | 3305 | return f2fs_ioc_enable_verity(filp, arg); |
3214 | case FS_IOC_MEASURE_VERITY: | 3306 | case FS_IOC_MEASURE_VERITY: |
3215 | return f2fs_ioc_measure_verity(filp, arg); | 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 | default: | 3312 | default: |
3217 | return -ENOTTY; | 3313 | return -ENOTTY; |
3218 | } | 3314 | } |
@@ -3229,16 +3325,12 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) | |||
3229 | goto out; | 3325 | goto out; |
3230 | } | 3326 | } |
3231 | 3327 | ||
3232 | if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT)) { | 3328 | if (iocb->ki_flags & IOCB_NOWAIT) { |
3233 | ret = -EINVAL; | 3329 | if (!inode_trylock(inode)) { |
3234 | goto out; | ||
3235 | } | ||
3236 | |||
3237 | if (!inode_trylock(inode)) { | ||
3238 | if (iocb->ki_flags & IOCB_NOWAIT) { | ||
3239 | ret = -EAGAIN; | 3330 | ret = -EAGAIN; |
3240 | goto out; | 3331 | goto out; |
3241 | } | 3332 | } |
3333 | } else { | ||
3242 | inode_lock(inode); | 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) | |||
3334 | case F2FS_IOC_RESIZE_FS: | 3426 | case F2FS_IOC_RESIZE_FS: |
3335 | case FS_IOC_ENABLE_VERITY: | 3427 | case FS_IOC_ENABLE_VERITY: |
3336 | case FS_IOC_MEASURE_VERITY: | 3428 | case FS_IOC_MEASURE_VERITY: |
3429 | case F2FS_IOC_GET_VOLUME_NAME: | ||
3430 | case F2FS_IOC_SET_VOLUME_NAME: | ||
3337 | break; | 3431 | break; |
3338 | default: | 3432 | default: |
3339 | return -ENOIOCTLCMD; | 3433 | return -ENOIOCTLCMD; |
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 8974672db78f..5877bd729689 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c | |||
@@ -382,6 +382,16 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi, | |||
382 | nsearched++; | 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 | secno = GET_SEC_FROM_SEG(sbi, segno); | 395 | secno = GET_SEC_FROM_SEG(sbi, segno); |
386 | 396 | ||
387 | if (sec_usage_check(sbi, secno)) | 397 | if (sec_usage_check(sbi, secno)) |
@@ -627,8 +637,21 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, | |||
627 | source_blkaddr = datablock_addr(NULL, node_page, ofs_in_node); | 637 | source_blkaddr = datablock_addr(NULL, node_page, ofs_in_node); |
628 | f2fs_put_page(node_page, 1); | 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 | return false; | 653 | return false; |
654 | } | ||
632 | return true; | 655 | return true; |
633 | } | 656 | } |
634 | 657 | ||
@@ -1303,7 +1326,7 @@ gc_more: | |||
1303 | round++; | 1326 | round++; |
1304 | } | 1327 | } |
1305 | 1328 | ||
1306 | if (gc_type == FG_GC) | 1329 | if (gc_type == FG_GC && seg_freed) |
1307 | sbi->cur_victim_sec = NULL_SEGNO; | 1330 | sbi->cur_victim_sec = NULL_SEGNO; |
1308 | 1331 | ||
1309 | if (sync) | 1332 | if (sync) |
diff --git a/fs/f2fs/hash.c b/fs/f2fs/hash.c index cc82f142f811..5bc4dcd8fc03 100644 --- a/fs/f2fs/hash.c +++ b/fs/f2fs/hash.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/f2fs_fs.h> | 14 | #include <linux/f2fs_fs.h> |
15 | #include <linux/cryptohash.h> | 15 | #include <linux/cryptohash.h> |
16 | #include <linux/pagemap.h> | 16 | #include <linux/pagemap.h> |
17 | #include <linux/unicode.h> | ||
17 | 18 | ||
18 | #include "f2fs.h" | 19 | #include "f2fs.h" |
19 | 20 | ||
@@ -67,7 +68,7 @@ static void str2hashbuf(const unsigned char *msg, size_t len, | |||
67 | *buf++ = pad; | 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 | struct fscrypt_name *fname) | 72 | struct fscrypt_name *fname) |
72 | { | 73 | { |
73 | __u32 hash; | 74 | __u32 hash; |
@@ -103,3 +104,37 @@ f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, | |||
103 | f2fs_hash = cpu_to_le32(hash & ~F2FS_HASH_COL_BIT); | 104 | f2fs_hash = cpu_to_le32(hash & ~F2FS_HASH_COL_BIT); |
104 | return f2fs_hash; | 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 | } | ||
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 3613efca8c00..896db0416f0e 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c | |||
@@ -131,6 +131,7 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) | |||
131 | 131 | ||
132 | err = f2fs_get_node_info(fio.sbi, dn->nid, &ni); | 132 | err = f2fs_get_node_info(fio.sbi, dn->nid, &ni); |
133 | if (err) { | 133 | if (err) { |
134 | f2fs_truncate_data_blocks_range(dn, 1); | ||
134 | f2fs_put_dnode(dn); | 135 | f2fs_put_dnode(dn); |
135 | return err; | 136 | return err; |
136 | } | 137 | } |
@@ -320,7 +321,7 @@ struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, | |||
320 | return NULL; | 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 | inline_dentry = inline_data_addr(dir, ipage); | 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, | |||
580 | 581 | ||
581 | f2fs_wait_on_page_writeback(ipage, NODE, true, true); | 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 | f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos); | 585 | f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos); |
585 | 586 | ||
586 | set_page_dirty(ipage); | 587 | set_page_dirty(ipage); |
@@ -588,6 +589,11 @@ int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, | |||
588 | /* we don't need to mark_inode_dirty now */ | 589 | /* we don't need to mark_inode_dirty now */ |
589 | if (inode) { | 590 | if (inode) { |
590 | f2fs_i_pino_write(inode, dir->i_ino); | 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 | f2fs_put_page(page, 1); | 597 | f2fs_put_page(page, 1); |
592 | } | 598 | } |
593 | 599 | ||
@@ -704,7 +710,13 @@ int f2fs_inline_data_fiemap(struct inode *inode, | |||
704 | if (IS_ERR(ipage)) | 710 | if (IS_ERR(ipage)) |
705 | return PTR_ERR(ipage); | 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 | err = -EAGAIN; | 720 | err = -EAGAIN; |
709 | goto out; | 721 | goto out; |
710 | } | 722 | } |
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 06da75d418e0..db4fec30c30d 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c | |||
@@ -48,9 +48,11 @@ void f2fs_set_inode_flags(struct inode *inode) | |||
48 | new_fl |= S_ENCRYPTED; | 48 | new_fl |= S_ENCRYPTED; |
49 | if (file_is_verity(inode)) | 49 | if (file_is_verity(inode)) |
50 | new_fl |= S_VERITY; | 50 | new_fl |= S_VERITY; |
51 | if (flags & F2FS_CASEFOLD_FL) | ||
52 | new_fl |= S_CASEFOLD; | ||
51 | inode_set_flags(inode, new_fl, | 53 | inode_set_flags(inode, new_fl, |
52 | S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC| | 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 | static void __get_inode_rdev(struct inode *inode, struct f2fs_inode *ri) | 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) | |||
616 | if (!is_inode_flag_set(inode, FI_DIRTY_INODE)) | 618 | if (!is_inode_flag_set(inode, FI_DIRTY_INODE)) |
617 | return 0; | 619 | return 0; |
618 | 620 | ||
619 | if (f2fs_is_checkpoint_ready(sbi)) | 621 | if (!f2fs_is_checkpoint_ready(sbi)) |
620 | return -ENOSPC; | 622 | return -ENOSPC; |
621 | 623 | ||
622 | /* | 624 | /* |
@@ -695,7 +697,8 @@ retry: | |||
695 | 697 | ||
696 | if (err) { | 698 | if (err) { |
697 | f2fs_update_inode_page(inode); | 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 | sb_end_intwrite(inode->i_sb); | 703 | sb_end_intwrite(inode->i_sb); |
701 | no_delete: | 704 | no_delete: |
@@ -705,7 +708,7 @@ no_delete: | |||
705 | stat_dec_inline_dir(inode); | 708 | stat_dec_inline_dir(inode); |
706 | stat_dec_inline_inode(inode); | 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 | !is_sbi_flag_set(sbi, SBI_CP_DISABLED))) | 712 | !is_sbi_flag_set(sbi, SBI_CP_DISABLED))) |
710 | f2fs_bug_on(sbi, is_inode_flag_set(inode, FI_DIRTY_INODE)); | 713 | f2fs_bug_on(sbi, is_inode_flag_set(inode, FI_DIRTY_INODE)); |
711 | else | 714 | else |
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index c5b99042e6f2..4faf06e8bf89 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c | |||
@@ -272,9 +272,8 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode, | |||
272 | 272 | ||
273 | if (unlikely(f2fs_cp_error(sbi))) | 273 | if (unlikely(f2fs_cp_error(sbi))) |
274 | return -EIO; | 274 | return -EIO; |
275 | err = f2fs_is_checkpoint_ready(sbi); | 275 | if (!f2fs_is_checkpoint_ready(sbi)) |
276 | if (err) | 276 | return -ENOSPC; |
277 | return err; | ||
278 | 277 | ||
279 | err = dquot_initialize(dir); | 278 | err = dquot_initialize(dir); |
280 | if (err) | 279 | if (err) |
@@ -321,9 +320,8 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir, | |||
321 | 320 | ||
322 | if (unlikely(f2fs_cp_error(sbi))) | 321 | if (unlikely(f2fs_cp_error(sbi))) |
323 | return -EIO; | 322 | return -EIO; |
324 | err = f2fs_is_checkpoint_ready(sbi); | 323 | if (!f2fs_is_checkpoint_ready(sbi)) |
325 | if (err) | 324 | return -ENOSPC; |
326 | return err; | ||
327 | 325 | ||
328 | err = fscrypt_prepare_link(old_dentry, dir, dentry); | 326 | err = fscrypt_prepare_link(old_dentry, dir, dentry); |
329 | if (err) | 327 | if (err) |
@@ -489,6 +487,17 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry, | |||
489 | goto out_iput; | 487 | goto out_iput; |
490 | } | 488 | } |
491 | out_splice: | 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 | new = d_splice_alias(inode, dentry); | 501 | new = d_splice_alias(inode, dentry); |
493 | err = PTR_ERR_OR_ZERO(new); | 502 | err = PTR_ERR_OR_ZERO(new); |
494 | trace_f2fs_lookup_end(dir, dentry, ino, err); | 503 | trace_f2fs_lookup_end(dir, dentry, ino, err); |
@@ -537,6 +546,16 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry) | |||
537 | goto fail; | 546 | goto fail; |
538 | } | 547 | } |
539 | f2fs_delete_entry(de, page, dir, inode); | 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 | f2fs_unlock_op(sbi); | 559 | f2fs_unlock_op(sbi); |
541 | 560 | ||
542 | if (IS_DIRSYNC(dir)) | 561 | if (IS_DIRSYNC(dir)) |
@@ -571,9 +590,8 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, | |||
571 | 590 | ||
572 | if (unlikely(f2fs_cp_error(sbi))) | 591 | if (unlikely(f2fs_cp_error(sbi))) |
573 | return -EIO; | 592 | return -EIO; |
574 | err = f2fs_is_checkpoint_ready(sbi); | 593 | if (!f2fs_is_checkpoint_ready(sbi)) |
575 | if (err) | 594 | return -ENOSPC; |
576 | return err; | ||
577 | 595 | ||
578 | err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize, | 596 | err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize, |
579 | &disk_link); | 597 | &disk_link); |
@@ -703,9 +721,8 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry, | |||
703 | 721 | ||
704 | if (unlikely(f2fs_cp_error(sbi))) | 722 | if (unlikely(f2fs_cp_error(sbi))) |
705 | return -EIO; | 723 | return -EIO; |
706 | err = f2fs_is_checkpoint_ready(sbi); | 724 | if (!f2fs_is_checkpoint_ready(sbi)) |
707 | if (err) | 725 | return -ENOSPC; |
708 | return err; | ||
709 | 726 | ||
710 | err = dquot_initialize(dir); | 727 | err = dquot_initialize(dir); |
711 | if (err) | 728 | if (err) |
@@ -804,6 +821,8 @@ static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) | |||
804 | 821 | ||
805 | if (unlikely(f2fs_cp_error(sbi))) | 822 | if (unlikely(f2fs_cp_error(sbi))) |
806 | return -EIO; | 823 | return -EIO; |
824 | if (!f2fs_is_checkpoint_ready(sbi)) | ||
825 | return -ENOSPC; | ||
807 | 826 | ||
808 | if (IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) { | 827 | if (IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) { |
809 | int err = fscrypt_get_encryption_info(dir); | 828 | int err = fscrypt_get_encryption_info(dir); |
@@ -840,9 +859,8 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
840 | 859 | ||
841 | if (unlikely(f2fs_cp_error(sbi))) | 860 | if (unlikely(f2fs_cp_error(sbi))) |
842 | return -EIO; | 861 | return -EIO; |
843 | err = f2fs_is_checkpoint_ready(sbi); | 862 | if (!f2fs_is_checkpoint_ready(sbi)) |
844 | if (err) | 863 | return -ENOSPC; |
845 | return err; | ||
846 | 864 | ||
847 | if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && | 865 | if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && |
848 | (!projid_eq(F2FS_I(new_dir)->i_projid, | 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, | |||
1035 | 1053 | ||
1036 | if (unlikely(f2fs_cp_error(sbi))) | 1054 | if (unlikely(f2fs_cp_error(sbi))) |
1037 | return -EIO; | 1055 | return -EIO; |
1038 | err = f2fs_is_checkpoint_ready(sbi); | 1056 | if (!f2fs_is_checkpoint_ready(sbi)) |
1039 | if (err) | 1057 | return -ENOSPC; |
1040 | return err; | ||
1041 | 1058 | ||
1042 | if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && | 1059 | if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && |
1043 | !projid_eq(F2FS_I(new_dir)->i_projid, | 1060 | !projid_eq(F2FS_I(new_dir)->i_projid, |
@@ -1250,6 +1267,7 @@ const struct inode_operations f2fs_dir_inode_operations = { | |||
1250 | #ifdef CONFIG_F2FS_FS_XATTR | 1267 | #ifdef CONFIG_F2FS_FS_XATTR |
1251 | .listxattr = f2fs_listxattr, | 1268 | .listxattr = f2fs_listxattr, |
1252 | #endif | 1269 | #endif |
1270 | .fiemap = f2fs_fiemap, | ||
1253 | }; | 1271 | }; |
1254 | 1272 | ||
1255 | const struct inode_operations f2fs_symlink_inode_operations = { | 1273 | const struct inode_operations f2fs_symlink_inode_operations = { |
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index a18b2a895771..8b66bc4c004b 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c | |||
@@ -1524,7 +1524,8 @@ static int __write_node_page(struct page *page, bool atomic, bool *submitted, | |||
1524 | if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) | 1524 | if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) |
1525 | goto redirty_out; | 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 | IS_DNODE(page) && is_cold_node(page)) | 1529 | IS_DNODE(page) && is_cold_node(page)) |
1529 | goto redirty_out; | 1530 | goto redirty_out; |
1530 | 1531 | ||
@@ -1762,6 +1763,47 @@ out: | |||
1762 | return ret ? -EIO: 0; | 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 | int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, | 1807 | int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, |
1766 | struct writeback_control *wbc, | 1808 | struct writeback_control *wbc, |
1767 | bool do_balance, enum iostat_type io_type) | 1809 | bool do_balance, enum iostat_type io_type) |
@@ -1785,6 +1827,7 @@ next_step: | |||
1785 | for (i = 0; i < nr_pages; i++) { | 1827 | for (i = 0; i < nr_pages; i++) { |
1786 | struct page *page = pvec.pages[i]; | 1828 | struct page *page = pvec.pages[i]; |
1787 | bool submitted = false; | 1829 | bool submitted = false; |
1830 | bool may_dirty = true; | ||
1788 | 1831 | ||
1789 | /* give a priority to WB_SYNC threads */ | 1832 | /* give a priority to WB_SYNC threads */ |
1790 | if (atomic_read(&sbi->wb_sync_req[NODE]) && | 1833 | if (atomic_read(&sbi->wb_sync_req[NODE]) && |
@@ -1832,6 +1875,13 @@ continue_unlock: | |||
1832 | goto lock_node; | 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 | f2fs_wait_on_page_writeback(page, NODE, true, true); | 1885 | f2fs_wait_on_page_writeback(page, NODE, true, true); |
1836 | 1886 | ||
1837 | if (!clear_page_dirty_for_io(page)) | 1887 | if (!clear_page_dirty_for_io(page)) |
@@ -1860,7 +1910,8 @@ continue_unlock: | |||
1860 | } | 1910 | } |
1861 | 1911 | ||
1862 | if (step < 2) { | 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 | goto out; | 1915 | goto out; |
1865 | step++; | 1916 | step++; |
1866 | goto next_step; | 1917 | goto next_step; |
@@ -2964,7 +3015,7 @@ static int init_node_manager(struct f2fs_sb_info *sbi) | |||
2964 | 3015 | ||
2965 | /* not used nids: 0, node, meta, (and root counted as valid node) */ | 3016 | /* not used nids: 0, node, meta, (and root counted as valid node) */ |
2966 | nm_i->available_nids = nm_i->max_nid - sbi->total_valid_node_count - | 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 | nm_i->nid_cnt[FREE_NID] = 0; | 3019 | nm_i->nid_cnt[FREE_NID] = 0; |
2969 | nm_i->nid_cnt[PREALLOC_NID] = 0; | 3020 | nm_i->nid_cnt[PREALLOC_NID] = 0; |
2970 | nm_i->nat_cnt = 0; | 3021 | nm_i->nat_cnt = 0; |
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index a661ac32e829..808709581481 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c | |||
@@ -185,8 +185,6 @@ bool f2fs_need_SSR(struct f2fs_sb_info *sbi) | |||
185 | 185 | ||
186 | void f2fs_register_inmem_page(struct inode *inode, struct page *page) | 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 | struct inmem_pages *new; | 188 | struct inmem_pages *new; |
191 | 189 | ||
192 | f2fs_trace_pid(page); | 190 | f2fs_trace_pid(page); |
@@ -200,15 +198,11 @@ void f2fs_register_inmem_page(struct inode *inode, struct page *page) | |||
200 | INIT_LIST_HEAD(&new->list); | 198 | INIT_LIST_HEAD(&new->list); |
201 | 199 | ||
202 | /* increase reference count with clean state */ | 200 | /* increase reference count with clean state */ |
203 | mutex_lock(&fi->inmem_lock); | ||
204 | get_page(page); | 201 | get_page(page); |
205 | list_add_tail(&new->list, &fi->inmem_pages); | 202 | mutex_lock(&F2FS_I(inode)->inmem_lock); |
206 | spin_lock(&sbi->inode_lock[ATOMIC_FILE]); | 203 | list_add_tail(&new->list, &F2FS_I(inode)->inmem_pages); |
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]); | ||
210 | inc_page_count(F2FS_I_SB(inode), F2FS_INMEM_PAGES); | 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 | trace_f2fs_register_inmem_page(page, INMEM); | 207 | trace_f2fs_register_inmem_page(page, INMEM); |
214 | } | 208 | } |
@@ -330,19 +324,17 @@ void f2fs_drop_inmem_pages(struct inode *inode) | |||
330 | mutex_lock(&fi->inmem_lock); | 324 | mutex_lock(&fi->inmem_lock); |
331 | __revoke_inmem_pages(inode, &fi->inmem_pages, | 325 | __revoke_inmem_pages(inode, &fi->inmem_pages, |
332 | true, false, true); | 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 | mutex_unlock(&fi->inmem_lock); | 327 | mutex_unlock(&fi->inmem_lock); |
341 | } | 328 | } |
342 | 329 | ||
343 | clear_inode_flag(inode, FI_ATOMIC_FILE); | 330 | clear_inode_flag(inode, FI_ATOMIC_FILE); |
344 | fi->i_gc_failures[GC_FAILURE_ATOMIC] = 0; | 331 | fi->i_gc_failures[GC_FAILURE_ATOMIC] = 0; |
345 | stat_dec_atomic_write(inode); | 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 | void f2fs_drop_inmem_page(struct inode *inode, struct page *page) | 340 | void f2fs_drop_inmem_page(struct inode *inode, struct page *page) |
@@ -471,11 +463,6 @@ int f2fs_commit_inmem_pages(struct inode *inode) | |||
471 | 463 | ||
472 | mutex_lock(&fi->inmem_lock); | 464 | mutex_lock(&fi->inmem_lock); |
473 | err = __f2fs_commit_inmem_pages(inode); | 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 | mutex_unlock(&fi->inmem_lock); | 466 | mutex_unlock(&fi->inmem_lock); |
480 | 467 | ||
481 | clear_inode_flag(inode, FI_ATOMIC_COMMIT); | 468 | clear_inode_flag(inode, FI_ATOMIC_COMMIT); |
@@ -501,7 +488,7 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need) | |||
501 | if (need && excess_cached_nats(sbi)) | 488 | if (need && excess_cached_nats(sbi)) |
502 | f2fs_balance_fs_bg(sbi); | 489 | f2fs_balance_fs_bg(sbi); |
503 | 490 | ||
504 | if (f2fs_is_checkpoint_ready(sbi)) | 491 | if (!f2fs_is_checkpoint_ready(sbi)) |
505 | return; | 492 | return; |
506 | 493 | ||
507 | /* | 494 | /* |
@@ -817,9 +804,13 @@ static void __remove_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno, | |||
817 | if (test_and_clear_bit(segno, dirty_i->dirty_segmap[t])) | 804 | if (test_and_clear_bit(segno, dirty_i->dirty_segmap[t])) |
818 | dirty_i->nr_dirty[t]--; | 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 | clear_bit(GET_SEC_FROM_SEG(sbi, segno), | 808 | clear_bit(GET_SEC_FROM_SEG(sbi, segno), |
822 | dirty_i->victim_secmap); | 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) | |||
2084 | 2075 | ||
2085 | f2fs_stop_discard_thread(sbi); | 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 | kvfree(dcc); | 2085 | kvfree(dcc); |
2088 | SM_I(sbi)->dcc_info = NULL; | 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) | |||
2156 | if (!f2fs_test_and_set_bit(offset, se->discard_map)) | 2154 | if (!f2fs_test_and_set_bit(offset, se->discard_map)) |
2157 | sbi->discard_blks--; | 2155 | sbi->discard_blks--; |
2158 | 2156 | ||
2159 | /* don't overwrite by SSR to keep node chain */ | 2157 | /* |
2160 | if (IS_NODESEG(se->type) && | 2158 | * SSR should never reuse block which is checkpointed |
2161 | !is_sbi_flag_set(sbi, SBI_CP_DISABLED)) { | 2159 | * or newly invalidated. |
2160 | */ | ||
2161 | if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED)) { | ||
2162 | if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map)) | 2162 | if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map)) |
2163 | se->ckpt_valid_blocks++; | 2163 | se->ckpt_valid_blocks++; |
2164 | } | 2164 | } |
@@ -3116,12 +3116,14 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, | |||
3116 | f2fs_inode_chksum_set(sbi, page); | 3116 | f2fs_inode_chksum_set(sbi, page); |
3117 | } | 3117 | } |
3118 | 3118 | ||
3119 | if (F2FS_IO_ALIGNED(sbi)) | ||
3120 | fio->retry = false; | ||
3121 | |||
3119 | if (add_list) { | 3122 | if (add_list) { |
3120 | struct f2fs_bio_info *io; | 3123 | struct f2fs_bio_info *io; |
3121 | 3124 | ||
3122 | INIT_LIST_HEAD(&fio->list); | 3125 | INIT_LIST_HEAD(&fio->list); |
3123 | fio->in_list = true; | 3126 | fio->in_list = true; |
3124 | fio->retry = false; | ||
3125 | io = sbi->write_io[fio->type] + fio->temp; | 3127 | io = sbi->write_io[fio->type] + fio->temp; |
3126 | spin_lock(&io->io_lock); | 3128 | spin_lock(&io->io_lock); |
3127 | list_add_tail(&fio->list, &io->io_list); | 3129 | list_add_tail(&fio->list, &io->io_list); |
@@ -3447,11 +3449,6 @@ static int read_compacted_summaries(struct f2fs_sb_info *sbi) | |||
3447 | seg_i = CURSEG_I(sbi, i); | 3449 | seg_i = CURSEG_I(sbi, i); |
3448 | segno = le32_to_cpu(ckpt->cur_data_segno[i]); | 3450 | segno = le32_to_cpu(ckpt->cur_data_segno[i]); |
3449 | blk_off = le16_to_cpu(ckpt->cur_data_blkoff[i]); | 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 | seg_i->next_segno = segno; | 3452 | seg_i->next_segno = segno; |
3456 | reset_curseg(sbi, i, 0); | 3453 | reset_curseg(sbi, i, 0); |
3457 | seg_i->alloc_type = ckpt->alloc_type[i]; | 3454 | seg_i->alloc_type = ckpt->alloc_type[i]; |
@@ -3941,8 +3938,8 @@ static int build_sit_info(struct f2fs_sb_info *sbi) | |||
3941 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); | 3938 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); |
3942 | struct sit_info *sit_i; | 3939 | struct sit_info *sit_i; |
3943 | unsigned int sit_segs, start; | 3940 | unsigned int sit_segs, start; |
3944 | char *src_bitmap; | 3941 | char *src_bitmap, *bitmap; |
3945 | unsigned int bitmap_size; | 3942 | unsigned int bitmap_size, main_bitmap_size, sit_bitmap_size; |
3946 | 3943 | ||
3947 | /* allocate memory for SIT information */ | 3944 | /* allocate memory for SIT information */ |
3948 | sit_i = f2fs_kzalloc(sbi, sizeof(struct sit_info), GFP_KERNEL); | 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) | |||
3958 | if (!sit_i->sentries) | 3955 | if (!sit_i->sentries) |
3959 | return -ENOMEM; | 3956 | return -ENOMEM; |
3960 | 3957 | ||
3961 | bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi)); | 3958 | main_bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi)); |
3962 | sit_i->dirty_sentries_bitmap = f2fs_kvzalloc(sbi, bitmap_size, | 3959 | sit_i->dirty_sentries_bitmap = f2fs_kvzalloc(sbi, main_bitmap_size, |
3963 | GFP_KERNEL); | 3960 | GFP_KERNEL); |
3964 | if (!sit_i->dirty_sentries_bitmap) | 3961 | if (!sit_i->dirty_sentries_bitmap) |
3965 | return -ENOMEM; | 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 | for (start = 0; start < MAIN_SEGS(sbi); start++) { | 3975 | for (start = 0; start < MAIN_SEGS(sbi); start++) { |
3968 | sit_i->sentries[start].cur_valid_map | 3976 | sit_i->sentries[start].cur_valid_map = bitmap; |
3969 | = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 3977 | bitmap += SIT_VBLOCK_MAP_SIZE; |
3970 | sit_i->sentries[start].ckpt_valid_map | 3978 | |
3971 | = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 3979 | sit_i->sentries[start].ckpt_valid_map = bitmap; |
3972 | if (!sit_i->sentries[start].cur_valid_map || | 3980 | bitmap += SIT_VBLOCK_MAP_SIZE; |
3973 | !sit_i->sentries[start].ckpt_valid_map) | ||
3974 | return -ENOMEM; | ||
3975 | 3981 | ||
3976 | #ifdef CONFIG_F2FS_CHECK_FS | 3982 | #ifdef CONFIG_F2FS_CHECK_FS |
3977 | sit_i->sentries[start].cur_valid_map_mir | 3983 | sit_i->sentries[start].cur_valid_map_mir = bitmap; |
3978 | = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 3984 | bitmap += SIT_VBLOCK_MAP_SIZE; |
3979 | if (!sit_i->sentries[start].cur_valid_map_mir) | ||
3980 | return -ENOMEM; | ||
3981 | #endif | 3985 | #endif |
3982 | 3986 | ||
3983 | sit_i->sentries[start].discard_map | 3987 | sit_i->sentries[start].discard_map = bitmap; |
3984 | = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, | 3988 | bitmap += SIT_VBLOCK_MAP_SIZE; |
3985 | GFP_KERNEL); | ||
3986 | if (!sit_i->sentries[start].discard_map) | ||
3987 | return -ENOMEM; | ||
3988 | } | 3989 | } |
3989 | 3990 | ||
3990 | sit_i->tmp_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 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) | |||
4004 | sit_segs = le32_to_cpu(raw_super->segment_count_sit) >> 1; | 4005 | sit_segs = le32_to_cpu(raw_super->segment_count_sit) >> 1; |
4005 | 4006 | ||
4006 | /* setup SIT bitmap from ckeckpoint pack */ | 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 | src_bitmap = __bitmap_ptr(sbi, SIT_BITMAP); | 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 | if (!sit_i->sit_bitmap) | 4012 | if (!sit_i->sit_bitmap) |
4012 | return -ENOMEM; | 4013 | return -ENOMEM; |
4013 | 4014 | ||
4014 | #ifdef CONFIG_F2FS_CHECK_FS | 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 | if (!sit_i->sit_bitmap_mir) | 4018 | if (!sit_i->sit_bitmap_mir) |
4017 | return -ENOMEM; | 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 | #endif | 4025 | #endif |
4019 | 4026 | ||
4020 | /* init SIT information */ | 4027 | /* init SIT information */ |
@@ -4023,7 +4030,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi) | |||
4023 | sit_i->sit_base_addr = le32_to_cpu(raw_super->sit_blkaddr); | 4030 | sit_i->sit_base_addr = le32_to_cpu(raw_super->sit_blkaddr); |
4024 | sit_i->sit_blocks = sit_segs << sbi->log_blocks_per_seg; | 4031 | sit_i->sit_blocks = sit_segs << sbi->log_blocks_per_seg; |
4025 | sit_i->written_valid_blocks = 0; | 4032 | sit_i->written_valid_blocks = 0; |
4026 | sit_i->bitmap_size = bitmap_size; | 4033 | sit_i->bitmap_size = sit_bitmap_size; |
4027 | sit_i->dirty_sentries = 0; | 4034 | sit_i->dirty_sentries = 0; |
4028 | sit_i->sents_per_block = SIT_ENTRY_PER_BLOCK; | 4035 | sit_i->sents_per_block = SIT_ENTRY_PER_BLOCK; |
4029 | sit_i->elapsed_time = le64_to_cpu(sbi->ckpt->elapsed_time); | 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) | |||
4161 | if (start >= MAIN_SEGS(sbi)) { | 4168 | if (start >= MAIN_SEGS(sbi)) { |
4162 | f2fs_err(sbi, "Wrong journal entry on segno %u", | 4169 | f2fs_err(sbi, "Wrong journal entry on segno %u", |
4163 | start); | 4170 | start); |
4164 | set_sbi_flag(sbi, SBI_NEED_FSCK); | ||
4165 | err = -EFSCORRUPTED; | 4171 | err = -EFSCORRUPTED; |
4166 | break; | 4172 | break; |
4167 | } | 4173 | } |
@@ -4201,7 +4207,6 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) | |||
4201 | if (!err && total_node_blocks != valid_node_count(sbi)) { | 4207 | if (!err && total_node_blocks != valid_node_count(sbi)) { |
4202 | f2fs_err(sbi, "SIT is corrupted node# %u vs %u", | 4208 | f2fs_err(sbi, "SIT is corrupted node# %u vs %u", |
4203 | total_node_blocks, valid_node_count(sbi)); | 4209 | total_node_blocks, valid_node_count(sbi)); |
4204 | set_sbi_flag(sbi, SBI_NEED_FSCK); | ||
4205 | err = -EFSCORRUPTED; | 4210 | err = -EFSCORRUPTED; |
4206 | } | 4211 | } |
4207 | 4212 | ||
@@ -4492,21 +4497,12 @@ static void destroy_free_segmap(struct f2fs_sb_info *sbi) | |||
4492 | static void destroy_sit_info(struct f2fs_sb_info *sbi) | 4497 | static void destroy_sit_info(struct f2fs_sb_info *sbi) |
4493 | { | 4498 | { |
4494 | struct sit_info *sit_i = SIT_I(sbi); | 4499 | struct sit_info *sit_i = SIT_I(sbi); |
4495 | unsigned int start; | ||
4496 | 4500 | ||
4497 | if (!sit_i) | 4501 | if (!sit_i) |
4498 | return; | 4502 | return; |
4499 | 4503 | ||
4500 | if (sit_i->sentries) { | 4504 | if (sit_i->sentries) |
4501 | for (start = 0; start < MAIN_SEGS(sbi); start++) { | 4505 | kvfree(sit_i->bitmap); |
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 | } | ||
4510 | kvfree(sit_i->tmp_map); | 4506 | kvfree(sit_i->tmp_map); |
4511 | 4507 | ||
4512 | kvfree(sit_i->sentries); | 4508 | kvfree(sit_i->sentries); |
@@ -4517,6 +4513,7 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi) | |||
4517 | kvfree(sit_i->sit_bitmap); | 4513 | kvfree(sit_i->sit_bitmap); |
4518 | #ifdef CONFIG_F2FS_CHECK_FS | 4514 | #ifdef CONFIG_F2FS_CHECK_FS |
4519 | kvfree(sit_i->sit_bitmap_mir); | 4515 | kvfree(sit_i->sit_bitmap_mir); |
4516 | kvfree(sit_i->invalid_segmap); | ||
4520 | #endif | 4517 | #endif |
4521 | kvfree(sit_i); | 4518 | kvfree(sit_i); |
4522 | } | 4519 | } |
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index b74602813a05..325781a1ae4d 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h | |||
@@ -226,9 +226,13 @@ struct sit_info { | |||
226 | block_t sit_base_addr; /* start block address of SIT area */ | 226 | block_t sit_base_addr; /* start block address of SIT area */ |
227 | block_t sit_blocks; /* # of blocks used by SIT area */ | 227 | block_t sit_blocks; /* # of blocks used by SIT area */ |
228 | block_t written_valid_blocks; /* # of valid blocks in main area */ | 228 | block_t written_valid_blocks; /* # of valid blocks in main area */ |
229 | char *bitmap; /* all bitmaps pointer */ | ||
229 | char *sit_bitmap; /* SIT bitmap pointer */ | 230 | char *sit_bitmap; /* SIT bitmap pointer */ |
230 | #ifdef CONFIG_F2FS_CHECK_FS | 231 | #ifdef CONFIG_F2FS_CHECK_FS |
231 | char *sit_bitmap_mir; /* SIT bitmap mirror */ | 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 | #endif | 236 | #endif |
233 | unsigned int bitmap_size; /* SIT bitmap size */ | 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, | |||
582 | reserved_sections(sbi) + needed); | 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 | if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED))) | 591 | if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED))) |
588 | return 0; | 592 | return true; |
589 | if (likely(!has_not_enough_free_secs(sbi, 0, 0))) | 593 | if (likely(!has_not_enough_free_secs(sbi, 0, 0))) |
590 | return 0; | 594 | return true; |
591 | return -ENOSPC; | 595 | return false; |
592 | } | 596 | } |
593 | 597 | ||
594 | static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi) | 598 | static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi) |
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index f43befda0e1a..1443cee15863 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/f2fs_fs.h> | 23 | #include <linux/f2fs_fs.h> |
24 | #include <linux/sysfs.h> | 24 | #include <linux/sysfs.h> |
25 | #include <linux/quota.h> | 25 | #include <linux/quota.h> |
26 | #include <linux/unicode.h> | ||
26 | 27 | ||
27 | #include "f2fs.h" | 28 | #include "f2fs.h" |
28 | #include "node.h" | 29 | #include "node.h" |
@@ -222,6 +223,36 @@ void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...) | |||
222 | va_end(args); | 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 | static inline void limit_reserve_root(struct f2fs_sb_info *sbi) | 256 | static inline void limit_reserve_root(struct f2fs_sb_info *sbi) |
226 | { | 257 | { |
227 | block_t limit = min((sbi->user_block_count << 1) / 1000, | 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) | |||
798 | return -EINVAL; | 829 | return -EINVAL; |
799 | } | 830 | } |
800 | #endif | 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 | if (F2FS_IO_SIZE_BITS(sbi) && !test_opt(sbi, LFS)) { | 840 | if (F2FS_IO_SIZE_BITS(sbi) && !test_opt(sbi, LFS)) { |
803 | f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO", | 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) | |||
873 | 911 | ||
874 | static int f2fs_drop_inode(struct inode *inode) | 912 | static int f2fs_drop_inode(struct inode *inode) |
875 | { | 913 | { |
914 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | ||
876 | int ret; | 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 | * This is to avoid a deadlock condition like below. | 930 | * This is to avoid a deadlock condition like below. |
879 | * writeback_single_inode(inode) | 931 | * writeback_single_inode(inode) |
@@ -1091,6 +1143,9 @@ static void f2fs_put_super(struct super_block *sb) | |||
1091 | destroy_percpu_info(sbi); | 1143 | destroy_percpu_info(sbi); |
1092 | for (i = 0; i < NR_PAGE_TYPE; i++) | 1144 | for (i = 0; i < NR_PAGE_TYPE; i++) |
1093 | kvfree(sbi->write_io[i]); | 1145 | kvfree(sbi->write_io[i]); |
1146 | #ifdef CONFIG_UNICODE | ||
1147 | utf8_unload(sbi->s_encoding); | ||
1148 | #endif | ||
1094 | kvfree(sbi); | 1149 | kvfree(sbi); |
1095 | } | 1150 | } |
1096 | 1151 | ||
@@ -1216,8 +1271,7 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
1216 | else | 1271 | else |
1217 | buf->f_bavail = 0; | 1272 | buf->f_bavail = 0; |
1218 | 1273 | ||
1219 | avail_node_count = sbi->total_node_count - sbi->nquota_files - | 1274 | avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; |
1220 | F2FS_RESERVED_NODE_NUM; | ||
1221 | 1275 | ||
1222 | if (avail_node_count > user_block_count) { | 1276 | if (avail_node_count > user_block_count) { |
1223 | buf->f_files = user_block_count; | 1277 | buf->f_files = user_block_count; |
@@ -1524,6 +1578,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) | |||
1524 | bool need_stop_gc = false; | 1578 | bool need_stop_gc = false; |
1525 | bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE); | 1579 | bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE); |
1526 | bool disable_checkpoint = test_opt(sbi, DISABLE_CHECKPOINT); | 1580 | bool disable_checkpoint = test_opt(sbi, DISABLE_CHECKPOINT); |
1581 | bool no_io_align = !F2FS_IO_ALIGNED(sbi); | ||
1527 | bool checkpoint_changed; | 1582 | bool checkpoint_changed; |
1528 | #ifdef CONFIG_QUOTA | 1583 | #ifdef CONFIG_QUOTA |
1529 | int i, j; | 1584 | int i, j; |
@@ -1603,6 +1658,12 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) | |||
1603 | goto restore_opts; | 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 | if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) { | 1667 | if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) { |
1607 | err = -EINVAL; | 1668 | err = -EINVAL; |
1608 | f2fs_warn(sbi, "disabling checkpoint not compatible with read-only"); | 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, | |||
1981 | struct inode *inode; | 2042 | struct inode *inode; |
1982 | int err; | 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 | err = f2fs_quota_sync(sb, type); | 2051 | err = f2fs_quota_sync(sb, type); |
1985 | if (err) | 2052 | if (err) |
1986 | return err; | 2053 | return err; |
@@ -2000,7 +2067,7 @@ static int f2fs_quota_on(struct super_block *sb, int type, int format_id, | |||
2000 | return 0; | 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 | struct inode *inode = sb_dqopt(sb)->files[type]; | 2072 | struct inode *inode = sb_dqopt(sb)->files[type]; |
2006 | int err; | 2073 | int err; |
@@ -2026,13 +2093,30 @@ out_put: | |||
2026 | return err; | 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 | void f2fs_quota_off_umount(struct super_block *sb) | 2113 | void f2fs_quota_off_umount(struct super_block *sb) |
2030 | { | 2114 | { |
2031 | int type; | 2115 | int type; |
2032 | int err; | 2116 | int err; |
2033 | 2117 | ||
2034 | for (type = 0; type < MAXQUOTAS; type++) { | 2118 | for (type = 0; type < MAXQUOTAS; type++) { |
2035 | err = f2fs_quota_off(sb, type); | 2119 | err = __f2fs_quota_off(sb, type); |
2036 | if (err) { | 2120 | if (err) { |
2037 | int ret = dquot_quota_off(sb, type); | 2121 | int ret = dquot_quota_off(sb, type); |
2038 | 2122 | ||
@@ -2617,8 +2701,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) | |||
2617 | } | 2701 | } |
2618 | 2702 | ||
2619 | valid_node_count = le32_to_cpu(ckpt->valid_node_count); | 2703 | valid_node_count = le32_to_cpu(ckpt->valid_node_count); |
2620 | avail_node_count = sbi->total_node_count - sbi->nquota_files - | 2704 | avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; |
2621 | F2FS_RESERVED_NODE_NUM; | ||
2622 | if (valid_node_count > avail_node_count) { | 2705 | if (valid_node_count > avail_node_count) { |
2623 | f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u", | 2706 | f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u", |
2624 | valid_node_count, avail_node_count); | 2707 | valid_node_count, avail_node_count); |
@@ -2657,10 +2740,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) | |||
2657 | } | 2740 | } |
2658 | } | 2741 | } |
2659 | for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) { | 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 | if (le32_to_cpu(ckpt->cur_node_segno[i]) == | 2744 | if (le32_to_cpu(ckpt->cur_node_segno[i]) == |
2662 | le32_to_cpu(ckpt->cur_data_segno[j])) { | 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 | i, j, | 2747 | i, j, |
2665 | le32_to_cpu(ckpt->cur_node_segno[i])); | 2748 | le32_to_cpu(ckpt->cur_node_segno[i])); |
2666 | return 1; | 2749 | return 1; |
@@ -3033,6 +3116,53 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) | |||
3033 | return 0; | 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 | static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi) | 3166 | static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi) |
3037 | { | 3167 | { |
3038 | struct f2fs_sm_info *sm_i = SM_I(sbi); | 3168 | struct f2fs_sm_info *sm_i = SM_I(sbi); |
@@ -3129,6 +3259,10 @@ try_onemore: | |||
3129 | le32_to_cpu(raw_super->log_blocksize); | 3259 | le32_to_cpu(raw_super->log_blocksize); |
3130 | sb->s_max_links = F2FS_LINK_MAX; | 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 | #ifdef CONFIG_QUOTA | 3266 | #ifdef CONFIG_QUOTA |
3133 | sb->dq_op = &f2fs_quota_operations; | 3267 | sb->dq_op = &f2fs_quota_operations; |
3134 | sb->s_qcop = &f2fs_quotactl_ops; | 3268 | sb->s_qcop = &f2fs_quotactl_ops; |
@@ -3207,7 +3341,7 @@ try_onemore: | |||
3207 | if (err) | 3341 | if (err) |
3208 | goto free_bio_info; | 3342 | goto free_bio_info; |
3209 | 3343 | ||
3210 | if (F2FS_IO_SIZE(sbi) > 1) { | 3344 | if (F2FS_IO_ALIGNED(sbi)) { |
3211 | sbi->write_io_dummy = | 3345 | sbi->write_io_dummy = |
3212 | mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); | 3346 | mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); |
3213 | if (!sbi->write_io_dummy) { | 3347 | if (!sbi->write_io_dummy) { |
@@ -3482,6 +3616,10 @@ free_percpu: | |||
3482 | free_bio_info: | 3616 | free_bio_info: |
3483 | for (i = 0; i < NR_PAGE_TYPE; i++) | 3617 | for (i = 0; i < NR_PAGE_TYPE; i++) |
3484 | kvfree(sbi->write_io[i]); | 3618 | kvfree(sbi->write_io[i]); |
3619 | |||
3620 | #ifdef CONFIG_UNICODE | ||
3621 | utf8_unload(sbi->s_encoding); | ||
3622 | #endif | ||
3485 | free_options: | 3623 | free_options: |
3486 | #ifdef CONFIG_QUOTA | 3624 | #ifdef CONFIG_QUOTA |
3487 | for (i = 0; i < MAXQUOTAS; i++) | 3625 | for (i = 0; i < MAXQUOTAS; i++) |
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 0cd64f994068..b558b64a4c9c 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/proc_fs.h> | 10 | #include <linux/proc_fs.h> |
11 | #include <linux/f2fs_fs.h> | 11 | #include <linux/f2fs_fs.h> |
12 | #include <linux/seq_file.h> | 12 | #include <linux/seq_file.h> |
13 | #include <linux/unicode.h> | ||
13 | 14 | ||
14 | #include "f2fs.h" | 15 | #include "f2fs.h" |
15 | #include "segment.h" | 16 | #include "segment.h" |
@@ -81,6 +82,19 @@ static ssize_t unusable_show(struct f2fs_attr *a, | |||
81 | (unsigned long long)unusable); | 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 | static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a, | 99 | static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a, |
86 | struct f2fs_sb_info *sbi, char *buf) | 100 | struct f2fs_sb_info *sbi, char *buf) |
@@ -137,6 +151,9 @@ static ssize_t features_show(struct f2fs_attr *a, | |||
137 | if (f2fs_sb_has_sb_chksum(sbi)) | 151 | if (f2fs_sb_has_sb_chksum(sbi)) |
138 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", | 152 | len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", |
139 | len ? ", " : "", "sb_checksum"); | 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 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | 157 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
141 | return len; | 158 | return len; |
142 | } | 159 | } |
@@ -369,6 +386,7 @@ enum feat_id { | |||
369 | FEAT_LOST_FOUND, | 386 | FEAT_LOST_FOUND, |
370 | FEAT_VERITY, | 387 | FEAT_VERITY, |
371 | FEAT_SB_CHECKSUM, | 388 | FEAT_SB_CHECKSUM, |
389 | FEAT_CASEFOLD, | ||
372 | }; | 390 | }; |
373 | 391 | ||
374 | static ssize_t f2fs_feature_show(struct f2fs_attr *a, | 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, | |||
387 | case FEAT_LOST_FOUND: | 405 | case FEAT_LOST_FOUND: |
388 | case FEAT_VERITY: | 406 | case FEAT_VERITY: |
389 | case FEAT_SB_CHECKSUM: | 407 | case FEAT_SB_CHECKSUM: |
408 | case FEAT_CASEFOLD: | ||
390 | return snprintf(buf, PAGE_SIZE, "supported\n"); | 409 | return snprintf(buf, PAGE_SIZE, "supported\n"); |
391 | } | 410 | } |
392 | return 0; | 411 | return 0; |
@@ -460,6 +479,7 @@ F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes); | |||
460 | F2FS_GENERAL_RO_ATTR(features); | 479 | F2FS_GENERAL_RO_ATTR(features); |
461 | F2FS_GENERAL_RO_ATTR(current_reserved_blocks); | 480 | F2FS_GENERAL_RO_ATTR(current_reserved_blocks); |
462 | F2FS_GENERAL_RO_ATTR(unusable); | 481 | F2FS_GENERAL_RO_ATTR(unusable); |
482 | F2FS_GENERAL_RO_ATTR(encoding); | ||
463 | 483 | ||
464 | #ifdef CONFIG_FS_ENCRYPTION | 484 | #ifdef CONFIG_FS_ENCRYPTION |
465 | F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO); | 485 | F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO); |
@@ -479,6 +499,7 @@ F2FS_FEATURE_RO_ATTR(lost_found, FEAT_LOST_FOUND); | |||
479 | F2FS_FEATURE_RO_ATTR(verity, FEAT_VERITY); | 499 | F2FS_FEATURE_RO_ATTR(verity, FEAT_VERITY); |
480 | #endif | 500 | #endif |
481 | F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM); | 501 | F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM); |
502 | F2FS_FEATURE_RO_ATTR(casefold, FEAT_CASEFOLD); | ||
482 | 503 | ||
483 | #define ATTR_LIST(name) (&f2fs_attr_##name.attr) | 504 | #define ATTR_LIST(name) (&f2fs_attr_##name.attr) |
484 | static struct attribute *f2fs_attrs[] = { | 505 | static struct attribute *f2fs_attrs[] = { |
@@ -523,6 +544,7 @@ static struct attribute *f2fs_attrs[] = { | |||
523 | ATTR_LIST(features), | 544 | ATTR_LIST(features), |
524 | ATTR_LIST(reserved_blocks), | 545 | ATTR_LIST(reserved_blocks), |
525 | ATTR_LIST(current_reserved_blocks), | 546 | ATTR_LIST(current_reserved_blocks), |
547 | ATTR_LIST(encoding), | ||
526 | NULL, | 548 | NULL, |
527 | }; | 549 | }; |
528 | ATTRIBUTE_GROUPS(f2fs); | 550 | ATTRIBUTE_GROUPS(f2fs); |
@@ -546,6 +568,7 @@ static struct attribute *f2fs_feat_attrs[] = { | |||
546 | ATTR_LIST(verity), | 568 | ATTR_LIST(verity), |
547 | #endif | 569 | #endif |
548 | ATTR_LIST(sb_checksum), | 570 | ATTR_LIST(sb_checksum), |
571 | ATTR_LIST(casefold), | ||
549 | NULL, | 572 | NULL, |
550 | }; | 573 | }; |
551 | ATTRIBUTE_GROUPS(f2fs_feat); | 574 | ATTRIBUTE_GROUPS(f2fs_feat); |
diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index b32c45621679..181900af2576 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/posix_acl_xattr.h> | 21 | #include <linux/posix_acl_xattr.h> |
22 | #include "f2fs.h" | 22 | #include "f2fs.h" |
23 | #include "xattr.h" | 23 | #include "xattr.h" |
24 | #include "segment.h" | ||
24 | 25 | ||
25 | static int f2fs_xattr_generic_get(const struct xattr_handler *handler, | 26 | static int f2fs_xattr_generic_get(const struct xattr_handler *handler, |
26 | struct dentry *unused, struct inode *inode, | 27 | struct dentry *unused, struct inode *inode, |
@@ -729,6 +730,11 @@ int f2fs_setxattr(struct inode *inode, int index, const char *name, | |||
729 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | 730 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
730 | int err; | 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 | err = dquot_initialize(inode); | 738 | err = dquot_initialize(inode); |
733 | if (err) | 739 | if (err) |
734 | return err; | 740 | return err; |
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 65559900d4d7..284738996028 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h | |||
@@ -36,11 +36,17 @@ | |||
36 | 36 | ||
37 | #define F2FS_MAX_QUOTAS 3 | 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 | #define F2FS_IO_SIZE(sbi) (1 << F2FS_OPTION(sbi).write_io_size_bits) /* Blocks */ | 44 | #define F2FS_IO_SIZE(sbi) (1 << F2FS_OPTION(sbi).write_io_size_bits) /* Blocks */ |
40 | #define F2FS_IO_SIZE_KB(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 2)) /* KB */ | 45 | #define F2FS_IO_SIZE_KB(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 2)) /* KB */ |
41 | #define F2FS_IO_SIZE_BYTES(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 12)) /* B */ | 46 | #define F2FS_IO_SIZE_BYTES(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 12)) /* B */ |
42 | #define F2FS_IO_SIZE_BITS(sbi) (F2FS_OPTION(sbi).write_io_size_bits) /* power of 2 */ | 47 | #define F2FS_IO_SIZE_BITS(sbi) (F2FS_OPTION(sbi).write_io_size_bits) /* power of 2 */ |
43 | #define F2FS_IO_SIZE_MASK(sbi) (F2FS_IO_SIZE(sbi) - 1) | 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 | /* This flag is used by node and meta inodes, and by recovery */ | 51 | /* This flag is used by node and meta inodes, and by recovery */ |
46 | #define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO) | 52 | #define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO) |
@@ -109,7 +115,9 @@ struct f2fs_super_block { | |||
109 | struct f2fs_device devs[MAX_DEVICES]; /* device list */ | 115 | struct f2fs_device devs[MAX_DEVICES]; /* device list */ |
110 | __le32 qf_ino[F2FS_MAX_QUOTAS]; /* quota inode numbers */ | 116 | __le32 qf_ino[F2FS_MAX_QUOTAS]; /* quota inode numbers */ |
111 | __u8 hot_ext_count; /* # of hot file extension */ | 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 | __le32 crc; /* checksum of superblock */ | 121 | __le32 crc; /* checksum of superblock */ |
114 | } __packed; | 122 | } __packed; |
115 | 123 | ||
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index aad225b05be7..379a612f8f1d 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h | |||
@@ -264,6 +264,7 @@ struct fsxattr { | |||
264 | #define FS_NOCOW_FL 0x00800000 /* Do not cow file */ | 264 | #define FS_NOCOW_FL 0x00800000 /* Do not cow file */ |
265 | #define FS_INLINE_DATA_FL 0x10000000 /* Reserved for ext4 */ | 265 | #define FS_INLINE_DATA_FL 0x10000000 /* Reserved for ext4 */ |
266 | #define FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ | 266 | #define FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ |
267 | #define FS_CASEFOLD_FL 0x40000000 /* Folder is case insensitive */ | ||
267 | #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ | 268 | #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ |
268 | 269 | ||
269 | #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ | 270 | #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ |
diff --git a/tools/include/uapi/linux/fs.h b/tools/include/uapi/linux/fs.h index 59c71fa8c553..2a616aa3f686 100644 --- a/tools/include/uapi/linux/fs.h +++ b/tools/include/uapi/linux/fs.h | |||
@@ -311,6 +311,7 @@ struct fscrypt_key { | |||
311 | #define FS_NOCOW_FL 0x00800000 /* Do not cow file */ | 311 | #define FS_NOCOW_FL 0x00800000 /* Do not cow file */ |
312 | #define FS_INLINE_DATA_FL 0x10000000 /* Reserved for ext4 */ | 312 | #define FS_INLINE_DATA_FL 0x10000000 /* Reserved for ext4 */ |
313 | #define FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ | 313 | #define FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ |
314 | #define FS_CASEFOLD_FL 0x40000000 /* Folder is case insensitive */ | ||
314 | #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ | 315 | #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ |
315 | 316 | ||
316 | #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ | 317 | #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ |