History

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 ...

Linus Torvalds committed 7 years ago

Commit fbc246a2 parents 7ce1e15 fbbf77922 files · +865 −204Browse files

Unified · Split

22 files
  1. Documentation/ABI/testing/sysfs-fs-f2fs +7 −0
  2. Documentation/filesystems/f2fs.txt +8 −0
  3. fs/f2fs/Kconfig +4 −1
  4. fs/f2fs/data.c +70 −34
  5. fs/f2fs/debug.c +2 −2
  6. fs/f2fs/dir.c +175 −9
  7. fs/f2fs/f2fs.h +37 −10
  8. fs/f2fs/file.c +128 −34
  9. fs/f2fs/gc.c +25 −2
  10. fs/f2fs/hash.c +36 −1
  11. fs/f2fs/inline.c +15 −3
  12. fs/f2fs/inode.c +7 −4
  13. fs/f2fs/namei.c +36 −18
  14. fs/f2fs/node.c +54 −3
  15. fs/f2fs/segment.c +66 −69
  16. fs/f2fs/segment.h +8 −4
  17. fs/f2fs/super.c +147 −9
  18. fs/f2fs/sysfs.c +23 −0
  19. fs/f2fs/xattr.c +6 −0
  20. include/linux/f2fs_fs.h +9 −1
  21. include/uapi/linux/fs.h +1 −0
  22. tools/include/uapi/linux/fs.h +1 −0
Documentation/ABI/testing/sysfs-fs-f2fs+7−0
@@ -251,3 +251,10 @@ Description: · 250 unmodified lines
251251 If checkpoint=disable, it displays the number of blocks that are unusable.
252252 If checkpoint=enable it displays the enumber of blocks that would be unusable
253253 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)
Documentation/filesystems/f2fs.txt+8−0
@@ -157,6 +157,11 @@ noinline_data Disable the inline data feature, inline data feature is · 156 unmodified lines
157157 enabled by default.
158158 data_flush Enable data flushing before checkpoint in order to
159159 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.
160165 fault_injection=%d Enable fault injection in all supported types with
161166 specified injection rate.
162167 fault_type=%d Support configuring fault injection type, should be
@@ -413,6 +418,9 @@ Files in /sys/fs/f2fs/<devname> · 250 unmodified lines
413418 that would be unusable if checkpoint=disable were
414419 to be set.
415420
421+encoding This shows the encoding used for casefolding.
422+ If casefolding is not enabled, returns (none)
423+
416424 ================================================================================
417425 USAGE
418426 ================================================================================
fs/f2fs/Kconfig+4−1
@@ -2,6 +2,7 @@ · 1 unmodified line
22 config F2FS_FS
33 tristate "F2FS filesystem support"
44 depends on BLOCK
5+ select NLS
56 select CRYPTO
67 select CRYPTO_CRC32
78 select F2FS_FS_XATTR if FS_ENCRYPTION
@@ -60,7 +61,9 @@ config F2FS_FS_SECURITY · 52 unmodified lines
6061 Security Models (LSMs) accepted by AppArmor, SELinux, Smack and TOMOYO
6162 Linux. This option enables an extended attribute handler for file
6263 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).
6467
6568 If you are not using a security module, say N.
6669
fs/f2fs/data.c+70−34
@@ -283,26 +283,25 @@ static bool __same_bdev(struct f2fs_sb_info *sbi, · 282 unmodified lines
283283 /*
284284 * Low-level block read/write IO operations.
285285 */
286−static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr,
287− struct writeback_control *wbc,
288− int npages, bool is_read,
289− enum page_type type, enum temp_type temp)
286+static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages)
290287 {
288+ struct f2fs_sb_info *sbi = fio->sbi;
291289 struct bio *bio;
292290
293291 bio = f2fs_bio_alloc(sbi, npages, true);
294292
295− f2fs_target_device(sbi, blk_addr, bio);
296− if (is_read) {
293+ f2fs_target_device(sbi, fio->new_blkaddr, bio);
294+ if (is_read_io(fio->op)) {
297295 bio->bi_end_io = f2fs_read_end_io;
298296 bio->bi_private = NULL;
299297 } else {
300298 bio->bi_end_io = f2fs_write_end_io;
301299 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);
303302 }
304− if (wbc)
305− wbc_init_bio(wbc, bio);
303+ if (fio->io_wbc)
304+ wbc_init_bio(fio->io_wbc, bio);
306305
307306 return bio;
308307 }
@@ -319,6 +318,9 @@ static inline void __submit_bio(struct f2fs_sb_info *sbi, · 10 unmodified lines
319318 if (test_opt(sbi, LFS) && current->plug)
320319 blk_finish_plug(current->plug);
321320
321+ if (F2FS_IO_ALIGNED(sbi))
322+ goto submit_io;
323+
322324 start = bio->bi_iter.bi_size >> F2FS_BLKSIZE_BITS;
323325 start %= F2FS_IO_SIZE(sbi);
324326
@@ -485,8 +487,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) · 160 unmodified lines
485487 f2fs_trace_ios(fio, 0);
486488
487489 /* Allocate a new bio */
488− bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc,
489− 1, is_read_io(fio->op), fio->type, fio->temp);
490+ bio = __bio_alloc(fio, 1);
490491
491492 if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
492493 bio_put(bio);
@@ -505,6 +506,43 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) · 12 unmodified lines
505506 return 0;
506507 }
507508
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+
508546 int f2fs_merge_page_bio(struct f2fs_io_info *fio)
509547 {
510548 struct bio *bio = *fio->bio;
@@ -518,15 +556,14 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) · 7 unmodified lines
518556 trace_f2fs_submit_page_bio(page, fio);
519557 f2fs_trace_ios(fio, 0);
520558
521− if (bio && (*fio->last_block + 1 != fio->new_blkaddr ||
522− !__same_bdev(fio->sbi, fio->new_blkaddr, bio))) {
559+ if (bio && !page_is_mergeable(fio->sbi, bio, *fio->last_block,
560+ fio->new_blkaddr)) {
523561 __submit_bio(fio->sbi, bio, fio->type);
524562 bio = NULL;
525563 }
526564 alloc_new:
527565 if (!bio) {
528− bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc,
529− BIO_MAX_PAGES, false, fio->type, fio->temp);
566+ bio = __bio_alloc(fio, BIO_MAX_PAGES);
530567 bio_set_op_attrs(bio, fio->op, fio->op_flags);
531568 }
532569
@@ -592,21 +629,19 @@ next: · 59 unmodified lines
592629
593630 inc_page_count(sbi, WB_DATA_TYPE(bio_page));
594631
595− if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 ||
596− (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags) ||
597− !__same_bdev(sbi, fio->new_blkaddr, io->bio)))
632+ if (io->bio && !io_is_mergeable(sbi, io->bio, io, fio,
633+ io->last_block_in_bio, fio->new_blkaddr))
598634 __submit_merged_bio(io);
599635 alloc_new:
600636 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) &&
602639 fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) {
603640 dec_page_count(sbi, WB_DATA_TYPE(bio_page));
604641 fio->retry = true;
605642 goto skip;
606643 }
607− io->bio = __bio_alloc(sbi, fio->new_blkaddr, fio->io_wbc,
608− BIO_MAX_PAGES, false,
609− fio->type, fio->temp);
644+ io->bio = __bio_alloc(fio, BIO_MAX_PAGES);
610645 io->fio = *fio;
611646 }
612647
@@ -627,7 +662,7 @@ skip: · 14 unmodified lines
627662 goto next;
628663 out:
629664 if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) ||
630− f2fs_is_checkpoint_ready(sbi))
665+ !f2fs_is_checkpoint_ready(sbi))
631666 __submit_merged_bio(io);
632667 up_write(&io->io_rwsem);
633668 }
@@ -1022,7 +1057,7 @@ alloc: · 388 unmodified lines
10221057 if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO)
10231058 invalidate_mapping_pages(META_MAPPING(sbi),
10241059 old_blkaddr, old_blkaddr);
1025− f2fs_set_data_blkaddr(dn);
1060+ f2fs_update_data_blkaddr(dn, dn->data_blkaddr);
10261061
10271062 /*
10281063 * i_size will be updated by direct_IO. Otherwise, we'll get stale
@@ -1199,10 +1234,10 @@ next_block: · 170 unmodified lines
11991234 if (test_opt(sbi, LFS) && flag == F2FS_GET_BLOCK_DIO &&
12001235 map->m_may_create) {
12011236 err = __allocate_data_block(&dn, map->m_seg_type);
1202− if (!err) {
1203− blkaddr = dn.data_blkaddr;
1204− set_inode_flag(inode, FI_APPEND_WRITE);
1205− }
1237+ if (err)
1238+ goto sync_out;
1239+ blkaddr = dn.data_blkaddr;
1240+ set_inode_flag(inode, FI_APPEND_WRITE);
12061241 }
12071242 } else {
12081243 if (create) {
@@ -1407,7 +1442,7 @@ static int get_data_block_dio_write(struct inode *inode, sector_t iblock, · 198 unmodified lines
14071442 return __get_data_block(inode, iblock, bh_result, create,
14081443 F2FS_GET_BLOCK_DIO, NULL,
14091444 f2fs_rw_hint_to_seg_type(inode->i_write_hint),
1410− true);
1445+ IS_SWAPFILE(inode) ? false : true);
14111446 }
14121447
14131448 static int get_data_block_dio(struct inode *inode, sector_t iblock,
@@ -1538,7 +1573,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · 124 unmodified lines
15381573 goto out;
15391574 }
15401575
1541− if (f2fs_has_inline_data(inode)) {
1576+ if (f2fs_has_inline_data(inode) || f2fs_has_inline_dentry(inode)) {
15421577 ret = f2fs_inline_data_fiemap(inode, fieinfo, start, len);
15431578 if (ret != -EAGAIN)
15441579 goto out;
@@ -1691,8 +1726,8 @@ zero_out: · 146 unmodified lines
16911726 * This page will go to BIO. Do we need to send this
16921727 * BIO off first?
16931728 */
1694− if (bio && (*last_block_in_bio != block_nr - 1 ||
1695− !__same_bdev(F2FS_I_SB(inode), block_nr, bio))) {
1729+ if (bio && !page_is_mergeable(F2FS_I_SB(inode), bio,
1730+ *last_block_in_bio, block_nr)) {
16961731 submit_and_realloc:
16971732 __submit_bio(F2FS_I_SB(inode), bio, DATA);
16981733 bio = NULL;
@@ -2590,9 +2625,10 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, · 891 unmodified lines
25902625
25912626 trace_f2fs_write_begin(inode, pos, len, flags);
25922627
2593− err = f2fs_is_checkpoint_ready(sbi);
2594− if (err)
2628+ if (!f2fs_is_checkpoint_ready(sbi)) {
2629+ err = -ENOSPC;
25952630 goto fail;
2631+ }
25962632
25972633 if ((f2fs_is_atomic_file(inode) &&
25982634 !f2fs_available_free_memory(sbi, INMEM_PAGES)) ||
fs/f2fs/debug.c+2−2
@@ -67,7 +67,7 @@ static void update_general_status(struct f2fs_sb_info *sbi) · 66 unmodified lines
6767 si->nr_rd_data = get_pages(sbi, F2FS_RD_DATA);
6868 si->nr_rd_node = get_pages(sbi, F2FS_RD_NODE);
6969 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) {
7171 si->nr_flushed =
7272 atomic_read(&SM_I(sbi)->fcc_info->issued_flush);
7373 si->nr_flushing =
@@ -75,7 +75,7 @@ static void update_general_status(struct f2fs_sb_info *sbi) · 1 unmodified line
7575 si->flush_list_empty =
7676 llist_empty(&SM_I(sbi)->fcc_info->issue_list);
7777 }
78− if (SM_I(sbi) && SM_I(sbi)->dcc_info) {
78+ if (SM_I(sbi)->dcc_info) {
7979 si->nr_discarded =
8080 atomic_read(&SM_I(sbi)->dcc_info->issued_discard);
8181 si->nr_discarding =
fs/f2fs/dir.c+175−9
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 #include <linux/fs.h>
99 #include <linux/f2fs_fs.h>
1010 #include <linux/sched/signal.h>
11+#include <linux/unicode.h>
1112 #include "f2fs.h"
1213 #include "node.h"
1314 #include "acl.h"
@@ -81,7 +82,8 @@ static unsigned long dir_block_index(unsigned int level, · 67 unmodified lines
8182 return bidx;
8283 }
8384
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,
8587 struct fscrypt_name *fname,
8688 f2fs_hash_t namehash,
8789 int *max_slots,
@@ -93,7 +95,7 @@ static struct f2fs_dir_entry *find_in_block(struct page *dentry_page, · 5 unmodified lines
9395
9496 dentry_blk = (struct f2fs_dentry_block *)page_address(dentry_page);
9597
96− make_dentry_ptr_block(NULL, &d, dentry_blk);
98+ make_dentry_ptr_block(dir, &d, dentry_blk);
9799 de = f2fs_find_target_dentry(fname, namehash, max_slots, &d);
98100 if (de)
99101 *res_page = dentry_page;
@@ -101,14 +103,116 @@ static struct f2fs_dir_entry *find_in_block(struct page *dentry_page, · 1 unmodified line
101103 return de;
102104 }
103105
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+
104203 struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname,
105204 f2fs_hash_t namehash, int *max_slots,
106205 struct f2fs_dentry_ptr *d)
107206 {
108207 struct f2fs_dir_entry *de;
208+ struct fscrypt_str cf_str = { .name = NULL, .len = 0 };
109209 unsigned long bit_pos = 0;
110210 int max_len = 0;
111211
212+#ifdef CONFIG_UNICODE
213+ f2fs_fname_setup_ci_filename(d->inode, fname->usr_fname, &cf_str);
214+#endif
215+
112216 if (max_slots)
113217 *max_slots = 0;
114218 while (bit_pos < d->max) {
@@ -125,9 +229,7 @@ struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, · 10 unmodified lines
125229 continue;
126230 }
127231
128− if (de->hash_code == namehash &&
129− fscrypt_match_name(fname, d->filename[bit_pos],
130− le16_to_cpu(de->name_len)))
232+ if (f2fs_match_name(d, de, fname, &cf_str, bit_pos, namehash))
131233 goto found;
132234
133235 if (max_slots && max_len > *max_slots)
@@ -141,6 +243,10 @@ struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, · 7 unmodified lines
141243 found:
142244 if (max_slots && max_len > *max_slots)
143245 *max_slots = max_len;
246+
247+#ifdef CONFIG_UNICODE
248+ kvfree(cf_str.name);
249+#endif
144250 return de;
145251 }
146252
@@ -157,7 +263,7 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir, · 10 unmodified lines
157263 struct f2fs_dir_entry *de = NULL;
158264 bool room = false;
159265 int max_slots;
160− f2fs_hash_t namehash = f2fs_dentry_hash(&name, fname);
266+ f2fs_hash_t namehash = f2fs_dentry_hash(dir, &name, fname);
161267
162268 nbucket = dir_buckets(level, F2FS_I(dir)->i_dir_level);
163269 nblock = bucket_blocks(level);
@@ -179,8 +285,8 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir, · 15 unmodified lines
179285 }
180286 }
181287
182− de = find_in_block(dentry_page, fname, namehash, &max_slots,
183− res_page);
288+ de = find_in_block(dir, dentry_page, fname, namehash,
289+ &max_slots, res_page);
184290 if (de)
185291 break;
186292
@@ -250,6 +356,14 @@ struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, · 63 unmodified lines
250356 struct fscrypt_name fname;
251357 int err;
252358
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+
253367 err = fscrypt_setup_filename(dir, child, 1, &fname);
254368 if (err) {
255369 if (err == -ENOENT)
@@ -504,7 +618,7 @@ int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, · 248 unmodified lines
504618
505619 level = 0;
506620 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);
508622
509623 current_depth = F2FS_I(dir)->i_current_depth;
510624 if (F2FS_I(dir)->chash == dentry_hash) {
@@ -568,6 +682,11 @@ add_dentry: · 57 unmodified lines
568682
569683 if (inode) {
570684 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+
571690 f2fs_put_page(page, 1);
572691 }
573692
@@ -943,3 +1062,50 @@ const struct file_operations f2fs_dir_operations = { · 369 unmodified lines
9431062 .compat_ioctl = f2fs_compat_ioctl,
9441063 #endif
9451064 };
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
fs/f2fs/f2fs.h+37−10
@@ -154,6 +154,7 @@ struct f2fs_mount_info { · 153 unmodified lines
154154 #define F2FS_FEATURE_LOST_FOUND 0x0200
155155 #define F2FS_FEATURE_VERITY 0x0400
156156 #define F2FS_FEATURE_SB_CHKSUM 0x0800
157+#define F2FS_FEATURE_CASEFOLD 0x1000
157158
158159 #define __F2FS_HAS_FEATURE(raw_super, mask) \
159160 ((raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -418,6 +419,9 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal, · 258 unmodified lines
418419 #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15)
419420 #define F2FS_IOC_RESIZE_FS _IOW(F2FS_IOCTL_MAGIC, 16, __u64)
420421
422+#define F2FS_IOC_GET_VOLUME_NAME FS_IOC_GETFSLABEL
423+#define F2FS_IOC_SET_VOLUME_NAME FS_IOC_SETFSLABEL
424+
421425 #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY
422426 #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
423427 #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT
@@ -1172,6 +1176,10 @@ struct f2fs_sb_info { · 748 unmodified lines
11721176 int valid_super_block; /* valid super block no */
11731177 unsigned long s_flag; /* flags for sbi */
11741178 struct mutex writepages; /* mutex for writepages() */
1179+#ifdef CONFIG_UNICODE
1180+ struct unicode_map *s_encoding;
1181+ __u16 s_encoding_flags;
1182+#endif
11751183
11761184 #ifdef CONFIG_BLK_DEV_ZONED
11771185 unsigned int blocks_per_blkz; /* F2FS blocks per zone */
@@ -1643,6 +1651,7 @@ static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) · 465 unmodified lines
16431651 static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock)
16441652 {
16451653 unsigned long flags;
1654+ unsigned char *nat_bits;
16461655
16471656 /*
16481657 * In order to re-enable nat_bits we need to call fsck.f2fs by
@@ -1653,10 +1662,12 @@ static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) · 4 unmodified lines
16531662 if (lock)
16541663 spin_lock_irqsave(&sbi->cp_lock, flags);
16551664 __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;
16571666 NM_I(sbi)->nat_bits = NULL;
16581667 if (lock)
16591668 spin_unlock_irqrestore(&sbi->cp_lock, flags);
1669+
1670+ kvfree(nat_bits);
16601671 }
16611672
16621673 static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi,
@@ -1763,7 +1774,7 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, · 100 unmodified lines
17631774 if (time_to_inject(sbi, FAULT_BLOCK)) {
17641775 f2fs_show_injection_info(FAULT_BLOCK);
17651776 release = *count;
1766− goto enospc;
1777+ goto release_quota;
17671778 }
17681779
17691780 /*
@@ -1808,6 +1819,7 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, · 38 unmodified lines
18081819
18091820 enospc:
18101821 percpu_counter_sub(&sbi->alloc_valid_block_count, release);
1822+release_quota:
18111823 dquot_release_reservation_block(inode, release);
18121824 return -ENOSPC;
18131825 }
@@ -2362,13 +2374,16 @@ static inline void f2fs_change_bit(unsigned int nr, char *addr) · 548 unmodified lines
23622374 #define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */
23632375 #define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
23642376 #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */
2377+#define F2FS_CASEFOLD_FL 0x40000000 /* Casefolded file */
23652378
23662379 /* Flags that should be inherited by new inodes from their parent. */
23672380 #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)
23692383
23702384 /* 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))
23722387
23732388 /* Flags that are appropriate for non-directories/regular files. */
23742389 #define F2FS_OTHER_FLMASK (F2FS_NODUMP_FL | F2FS_NOATIME_FL)
@@ -2935,6 +2950,11 @@ int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, · 560 unmodified lines
29352950 bool hot, bool set);
29362951 struct dentry *f2fs_get_parent(struct dentry *child);
29372952
2953+extern int f2fs_ci_compare(const struct inode *parent,
2954+ const struct qstr *name,
2955+ const struct qstr *entry,
2956+ bool quick);
2957+
29382958 /*
29392959 * dir.c
29402960 */
@@ -2998,8 +3018,8 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); · 57 unmodified lines
29983018 /*
29993019 * hash.c
30003020 */
3001−f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info,
3002− struct fscrypt_name *fname);
3021+f2fs_hash_t f2fs_dentry_hash(const struct inode *dir,
3022+ const struct qstr *name_info, struct fscrypt_name *fname);
30033023
30043024 /*
30053025 * node.c
@@ -3442,6 +3462,9 @@ static inline void f2fs_destroy_root_stats(void) { } · 436 unmodified lines
34423462 #endif
34433463
34443464 extern const struct file_operations f2fs_dir_operations;
3465+#ifdef CONFIG_UNICODE
3466+extern const struct dentry_operations f2fs_dentry_ops;
3467+#endif
34453468 extern const struct file_operations f2fs_file_operations;
34463469 extern const struct inode_operations f2fs_file_inode_operations;
34473470 extern const struct address_space_operations f2fs_dblock_aops;
@@ -3576,6 +3599,7 @@ F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); · 128 unmodified lines
35763599 F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND);
35773600 F2FS_FEATURE_FUNCS(verity, VERITY);
35783601 F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM);
3602+F2FS_FEATURE_FUNCS(casefold, CASEFOLD);
35793603
35803604 #ifdef CONFIG_BLK_DEV_ZONED
35813605 static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi,
@@ -3694,11 +3718,14 @@ static inline bool f2fs_force_buffered_io(struct inode *inode, · 112 unmodified lines
36943718 */
36953719 if (f2fs_sb_has_blkzoned(sbi))
36963720 return true;
3697− if (test_opt(sbi, LFS) && (rw == WRITE) &&
3698− block_unaligned_IO(inode, iocb, iter))
3699− return true;
3721+ if (test_opt(sbi, LFS) && (rw == WRITE)) {
3722+ if (block_unaligned_IO(inode, iocb, iter))
3723+ return true;
3724+ if (F2FS_IO_ALIGNED(sbi))
3725+ return true;
3726+ }
37003727 if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED) &&
3701− !(inode->i_flags & S_SWAPFILE))
3728+ !IS_SWAPFILE(inode))
37023729 return true;
37033730
37043731 return false;
fs/f2fs/file.c+128−34
@@ -20,6 +20,7 @@ · 19 unmodified lines
2020 #include <linux/uio.h>
2121 #include <linux/uuid.h>
2222 #include <linux/file.h>
23+#include <linux/nls.h>
2324
2425 #include "f2fs.h"
2526 #include "node.h"
@@ -57,6 +58,11 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) · 31 unmodified lines
5758 goto err;
5859 }
5960
61+ if (!f2fs_is_checkpoint_ready(sbi)) {
62+ err = -ENOSPC;
63+ goto err;
64+ }
65+
6066 sb_start_pagefault(inode->i_sb);
6167
6268 f2fs_bug_on(sbi, f2fs_has_inline_data(inode));
@@ -819,14 +825,24 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) · 756 unmodified lines
819825 }
820826
821827 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+ }
823839
824840 down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
825841 down_write(&F2FS_I(inode)->i_mmap_sem);
826842
827843 truncate_setsize(inode, attr->ia_size);
828844
829− if (to_smaller)
845+ if (attr->ia_size <= old_size)
830846 err = f2fs_truncate(inode);
831847 /*
832848 * do not trim all blocks after i_size if target size is
@@ -834,21 +850,11 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) · 1 unmodified line
834850 */
835851 up_write(&F2FS_I(inode)->i_mmap_sem);
836852 up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
837−
838853 if (err)
839854 return err;
840855
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−
851856 down_write(&F2FS_I(inode)->i_sem);
857+ inode->i_mtime = inode->i_ctime = current_time(inode);
852858 F2FS_I(inode)->last_disk_size = i_size_read(inode);
853859 up_write(&F2FS_I(inode)->i_sem);
854860 }
@@ -1041,7 +1047,7 @@ next_dnode: · 186 unmodified lines
10411047
10421048 if (test_opt(sbi, LFS)) {
10431049 f2fs_put_dnode(&dn);
1044− return -ENOTSUPP;
1050+ return -EOPNOTSUPP;
10451051 }
10461052
10471053 /* do not invalidate this block address */
@@ -1578,6 +1584,8 @@ static long f2fs_fallocate(struct file *file, int mode, · 530 unmodified lines
15781584
15791585 if (unlikely(f2fs_cp_error(F2FS_I_SB(inode))))
15801586 return -EIO;
1587+ if (!f2fs_is_checkpoint_ready(F2FS_I_SB(inode)))
1588+ return -ENOSPC;
15811589
15821590 /* f2fs only support ->fallocate for regular file */
15831591 if (!S_ISREG(inode->i_mode))
@@ -1669,6 +1677,13 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask) · 85 unmodified lines
16691677 if (IS_NOQUOTA(inode))
16701678 return -EPERM;
16711679
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+
16721687 fi->i_flags = iflags | (fi->i_flags & ~mask);
16731688
16741689 if (fi->i_flags & F2FS_PROJINHERIT_FL)
@@ -1703,6 +1718,7 @@ static const struct { · 28 unmodified lines
17031718 { F2FS_INDEX_FL, FS_INDEX_FL },
17041719 { F2FS_DIRSYNC_FL, FS_DIRSYNC_FL },
17051720 { F2FS_PROJINHERIT_FL, FS_PROJINHERIT_FL },
1721+ { F2FS_CASEFOLD_FL, FS_CASEFOLD_FL },
17061722 };
17071723
17081724 #define F2FS_GETTABLE_FS_FL ( \
@@ -1717,7 +1733,8 @@ static const struct { · 8 unmodified lines
17171733 FS_ENCRYPT_FL | \
17181734 FS_INLINE_DATA_FL | \
17191735 FS_NOCOW_FL | \
1720− FS_VERITY_FL)
1736+ FS_VERITY_FL | \
1737+ FS_CASEFOLD_FL)
17211738
17221739 #define F2FS_SETTABLE_FS_FL ( \
17231740 FS_SYNC_FL | \
@@ -1726,7 +1743,8 @@ static const struct { · 2 unmodified lines
17261743 FS_NODUMP_FL | \
17271744 FS_NOATIME_FL | \
17281745 FS_DIRSYNC_FL | \
1729− FS_PROJINHERIT_FL)
1746+ FS_PROJINHERIT_FL | \
1747+ FS_CASEFOLD_FL)
17301748
17311749 /* Convert f2fs on-disk i_flags to FS_IOC_{GET,SET}FLAGS flags */
17321750 static inline u32 f2fs_iflags_to_fsflags(u32 iflags)
@@ -1825,6 +1843,8 @@ static int f2fs_ioc_getversion(struct file *filp, unsigned long arg) · 92 unmodified lines
18251843 static int f2fs_ioc_start_atomic_write(struct file *filp)
18261844 {
18271845 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);
18281848 int ret;
18291849
18301850 if (!inode_owner_or_capable(inode))
@@ -1833,6 +1853,9 @@ static int f2fs_ioc_start_atomic_write(struct file *filp) · 2 unmodified lines
18331853 if (!S_ISREG(inode->i_mode))
18341854 return -EINVAL;
18351855
1856+ if (filp->f_flags & O_DIRECT)
1857+ return -EINVAL;
1858+
18361859 ret = mnt_want_write_file(filp);
18371860 if (ret)
18381861 return ret;
@@ -1864,6 +1887,12 @@ static int f2fs_ioc_start_atomic_write(struct file *filp) · 25 unmodified lines
18641887 goto out;
18651888 }
18661889
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 */
18671896 set_inode_flag(inode, FI_ATOMIC_FILE);
18681897 clear_inode_flag(inode, FI_ATOMIC_REVOKE_REQUEST);
18691898 up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
@@ -1905,11 +1934,8 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp) · 35 unmodified lines
19051934 goto err_out;
19061935
19071936 ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 0, true);
1908− if (!ret) {
1909− clear_inode_flag(inode, FI_ATOMIC_FILE);
1910− F2FS_I(inode)->i_gc_failures[GC_FAILURE_ATOMIC] = 0;
1911− stat_dec_atomic_write(inode);
1912− }
1937+ if (!ret)
1938+ f2fs_drop_inmem_pages(inode);
19131939 } else {
19141940 ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 1, false);
19151941 }
@@ -2295,9 +2321,9 @@ static int f2fs_ioc_gc_range(struct file *filp, unsigned long arg) · 379 unmodified lines
22952321 return -EROFS;
22962322
22972323 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))
22992326 return -EINVAL;
2300− }
23012327
23022328 ret = mnt_want_write_file(filp);
23032329 if (ret)
@@ -2421,8 +2447,10 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, · 117 unmodified lines
24212447 map.m_lblk += map.m_len;
24222448 }
24232449
2424− if (!fragmented)
2450+ if (!fragmented) {
2451+ total = 0;
24252452 goto out;
2453+ }
24262454
24272455 sec_num = DIV_ROUND_UP(total, BLKS_PER_SEC(sbi));
24282456
@@ -2452,7 +2480,7 @@ do_map: · 23 unmodified lines
24522480
24532481 if (!(map.m_flags & F2FS_MAP_FLAGS)) {
24542482 map.m_lblk = next_pgofs;
2455− continue;
2483+ goto check;
24562484 }
24572485
24582486 set_inode_flag(inode, FI_DO_DEFRAG);
@@ -2476,8 +2504,8 @@ do_map: · 17 unmodified lines
24762504 }
24772505
24782506 map.m_lblk = idx;
2479−
2480− if (idx < pg_end && cnt < blk_per_seg)
2507+check:
2508+ if (map.m_lblk < pg_end && cnt < blk_per_seg)
24812509 goto do_map;
24822510
24832511 clear_inode_flag(inode, FI_DO_DEFRAG);
@@ -3141,10 +3169,74 @@ static int f2fs_ioc_measure_verity(struct file *filp, unsigned long arg) · 657 unmodified lines
31413169 return fsverity_ioctl_measure(filp, (void __user *)arg);
31423170 }
31433171
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+
31443234 long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
31453235 {
31463236 if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp)))))
31473237 return -EIO;
3238+ if (!f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(filp))))
3239+ return -ENOSPC;
31483240
31493241 switch (cmd) {
31503242 case F2FS_IOC_GETFLAGS:
@@ -3213,6 +3305,10 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · 62 unmodified lines
32133305 return f2fs_ioc_enable_verity(filp, arg);
32143306 case FS_IOC_MEASURE_VERITY:
32153307 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);
32163312 default:
32173313 return -ENOTTY;
32183314 }
@@ -3229,16 +3325,12 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) · 10 unmodified lines
32293325 goto out;
32303326 }
32313327
3232− if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT)) {
3233− ret = -EINVAL;
3234− goto out;
3235− }
3236−
3237− if (!inode_trylock(inode)) {
3238− if (iocb->ki_flags & IOCB_NOWAIT) {
3328+ if (iocb->ki_flags & IOCB_NOWAIT) {
3329+ if (!inode_trylock(inode)) {
32393330 ret = -EAGAIN;
32403331 goto out;
32413332 }
3333+ } else {
32423334 inode_lock(inode);
32433335 }
32443336
@@ -3334,6 +3426,8 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) · 89 unmodified lines
33343426 case F2FS_IOC_RESIZE_FS:
33353427 case FS_IOC_ENABLE_VERITY:
33363428 case FS_IOC_MEASURE_VERITY:
3429+ case F2FS_IOC_GET_VOLUME_NAME:
3430+ case F2FS_IOC_SET_VOLUME_NAME:
33373431 break;
33383432 default:
33393433 return -ENOIOCTLCMD;
fs/f2fs/gc.c+25−2
@@ -382,6 +382,16 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi, · 381 unmodified lines
382382 nsearched++;
383383 }
384384
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+
385395 secno = GET_SEC_FROM_SEG(sbi, segno);
386396
387397 if (sec_usage_check(sbi, secno))
@@ -627,8 +637,21 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, · 239 unmodified lines
627637 source_blkaddr = datablock_addr(NULL, node_page, ofs_in_node);
628638 f2fs_put_page(node_page, 1);
629639
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
631653 return false;
654+ }
632655 return true;
633656 }
634657
@@ -1303,7 +1326,7 @@ gc_more: · 668 unmodified lines
13031326 round++;
13041327 }
13051328
1306− if (gc_type == FG_GC)
1329+ if (gc_type == FG_GC && seg_freed)
13071330 sbi->cur_victim_sec = NULL_SEGNO;
13081331
13091332 if (sync)
fs/f2fs/hash.c+36−1
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #include <linux/f2fs_fs.h>
1515 #include <linux/cryptohash.h>
1616 #include <linux/pagemap.h>
17+#include <linux/unicode.h>
1718
1819 #include "f2fs.h"
1920
@@ -67,7 +68,7 @@ static void str2hashbuf(const unsigned char *msg, size_t len, · 47 unmodified lines
6768 *buf++ = pad;
6869 }
6970
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,
7172 struct fscrypt_name *fname)
7273 {
7374 __u32 hash;
@@ -103,3 +104,37 @@ f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, · 29 unmodified lines
103104 f2fs_hash = cpu_to_le32(hash & ~F2FS_HASH_COL_BIT);
104105 return f2fs_hash;
105106 }
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+}
fs/f2fs/inline.c+15−3
@@ -131,6 +131,7 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) · 130 unmodified lines
131131
132132 err = f2fs_get_node_info(fio.sbi, dn->nid, &ni);
133133 if (err) {
134+ f2fs_truncate_data_blocks_range(dn, 1);
134135 f2fs_put_dnode(dn);
135136 return err;
136137 }
@@ -320,7 +321,7 @@ struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, · 183 unmodified lines
320321 return NULL;
321322 }
322323
323− namehash = f2fs_dentry_hash(&name, fname);
324+ namehash = f2fs_dentry_hash(dir, &name, fname);
324325
325326 inline_dentry = inline_data_addr(dir, ipage);
326327
@@ -580,7 +581,7 @@ int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, · 253 unmodified lines
580581
581582 f2fs_wait_on_page_writeback(ipage, NODE, true, true);
582583
583− name_hash = f2fs_dentry_hash(new_name, NULL);
584+ name_hash = f2fs_dentry_hash(dir, new_name, NULL);
584585 f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos);
585586
586587 set_page_dirty(ipage);
@@ -588,6 +589,11 @@ int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, · 1 unmodified line
588589 /* we don't need to mark_inode_dirty now */
589590 if (inode) {
590591 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+
591597 f2fs_put_page(page, 1);
592598 }
593599
@@ -704,7 +710,13 @@ int f2fs_inline_data_fiemap(struct inode *inode, · 110 unmodified lines
704710 if (IS_ERR(ipage))
705711 return PTR_ERR(ipage);
706712
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)) {
708720 err = -EAGAIN;
709721 goto out;
710722 }
fs/f2fs/inode.c+7−4
@@ -48,9 +48,11 @@ void f2fs_set_inode_flags(struct inode *inode) · 47 unmodified lines
4848 new_fl |= S_ENCRYPTED;
4949 if (file_is_verity(inode))
5050 new_fl |= S_VERITY;
51+ if (flags & F2FS_CASEFOLD_FL)
52+ new_fl |= S_CASEFOLD;
5153 inode_set_flags(inode, new_fl,
5254 S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|
53− S_ENCRYPTED|S_VERITY);
55+ S_ENCRYPTED|S_VERITY|S_CASEFOLD);
5456 }
5557
5658 static void __get_inode_rdev(struct inode *inode, struct f2fs_inode *ri)
@@ -616,7 +618,7 @@ int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc) · 559 unmodified lines
616618 if (!is_inode_flag_set(inode, FI_DIRTY_INODE))
617619 return 0;
618620
619− if (f2fs_is_checkpoint_ready(sbi))
621+ if (!f2fs_is_checkpoint_ready(sbi))
620622 return -ENOSPC;
621623
622624 /*
@@ -695,7 +697,8 @@ retry: · 72 unmodified lines
695697
696698 if (err) {
697699 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);
699702 }
700703 sb_end_intwrite(inode->i_sb);
701704 no_delete:
@@ -705,7 +708,7 @@ no_delete: · 3 unmodified lines
705708 stat_dec_inline_dir(inode);
706709 stat_dec_inline_inode(inode);
707710
708− if (likely(!is_set_ckpt_flags(sbi, CP_ERROR_FLAG) &&
711+ if (likely(!f2fs_cp_error(sbi) &&
709712 !is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
710713 f2fs_bug_on(sbi, is_inode_flag_set(inode, FI_DIRTY_INODE));
711714 else
fs/f2fs/namei.c+36−18
@@ -272,9 +272,8 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode, · 271 unmodified lines
272272
273273 if (unlikely(f2fs_cp_error(sbi)))
274274 return -EIO;
275− err = f2fs_is_checkpoint_ready(sbi);
276− if (err)
277− return err;
275+ if (!f2fs_is_checkpoint_ready(sbi))
276+ return -ENOSPC;
278277
279278 err = dquot_initialize(dir);
280279 if (err)
@@ -321,9 +320,8 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir, · 40 unmodified lines
321320
322321 if (unlikely(f2fs_cp_error(sbi)))
323322 return -EIO;
324− err = f2fs_is_checkpoint_ready(sbi);
325− if (err)
326− return err;
323+ if (!f2fs_is_checkpoint_ready(sbi))
324+ return -ENOSPC;
327325
328326 err = fscrypt_prepare_link(old_dentry, dir, dentry);
329327 if (err)
@@ -489,6 +487,17 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry, · 159 unmodified lines
489487 goto out_iput;
490488 }
491489 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
492501 new = d_splice_alias(inode, dentry);
493502 err = PTR_ERR_OR_ZERO(new);
494503 trace_f2fs_lookup_end(dir, dentry, ino, err);
@@ -537,6 +546,16 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry) · 42 unmodified lines
537546 goto fail;
538547 }
539548 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
540559 f2fs_unlock_op(sbi);
541560
542561 if (IS_DIRSYNC(dir))
@@ -571,9 +590,8 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, · 28 unmodified lines
571590
572591 if (unlikely(f2fs_cp_error(sbi)))
573592 return -EIO;
574− err = f2fs_is_checkpoint_ready(sbi);
575− if (err)
576− return err;
593+ if (!f2fs_is_checkpoint_ready(sbi))
594+ return -ENOSPC;
577595
578596 err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize,
579597 &disk_link);
@@ -703,9 +721,8 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry, · 123 unmodified lines
703721
704722 if (unlikely(f2fs_cp_error(sbi)))
705723 return -EIO;
706− err = f2fs_is_checkpoint_ready(sbi);
707− if (err)
708− return err;
724+ if (!f2fs_is_checkpoint_ready(sbi))
725+ return -ENOSPC;
709726
710727 err = dquot_initialize(dir);
711728 if (err)
@@ -804,6 +821,8 @@ static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) · 92 unmodified lines
804821
805822 if (unlikely(f2fs_cp_error(sbi)))
806823 return -EIO;
824+ if (!f2fs_is_checkpoint_ready(sbi))
825+ return -ENOSPC;
807826
808827 if (IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) {
809828 int err = fscrypt_get_encryption_info(dir);
@@ -840,9 +859,8 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, · 30 unmodified lines
840859
841860 if (unlikely(f2fs_cp_error(sbi)))
842861 return -EIO;
843− err = f2fs_is_checkpoint_ready(sbi);
844− if (err)
845− return err;
862+ if (!f2fs_is_checkpoint_ready(sbi))
863+ return -ENOSPC;
846864
847865 if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
848866 (!projid_eq(F2FS_I(new_dir)->i_projid,
@@ -1035,9 +1053,8 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry, · 186 unmodified lines
10351053
10361054 if (unlikely(f2fs_cp_error(sbi)))
10371055 return -EIO;
1038− err = f2fs_is_checkpoint_ready(sbi);
1039− if (err)
1040− return err;
1056+ if (!f2fs_is_checkpoint_ready(sbi))
1057+ return -ENOSPC;
10411058
10421059 if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
10431060 !projid_eq(F2FS_I(new_dir)->i_projid,
@@ -1250,6 +1267,7 @@ const struct inode_operations f2fs_dir_inode_operations = { · 206 unmodified lines
12501267 #ifdef CONFIG_F2FS_FS_XATTR
12511268 .listxattr = f2fs_listxattr,
12521269 #endif
1270+ .fiemap = f2fs_fiemap,
12531271 };
12541272
12551273 const struct inode_operations f2fs_symlink_inode_operations = {
fs/f2fs/node.c+54−3
@@ -1524,7 +1524,8 @@ static int __write_node_page(struct page *page, bool atomic, bool *submitted, · 1523 unmodified lines
15241524 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
15251525 goto redirty_out;
15261526
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 &&
15281529 IS_DNODE(page) && is_cold_node(page))
15291530 goto redirty_out;
15301531
@@ -1762,6 +1763,47 @@ out: · 231 unmodified lines
17621763 return ret ? -EIO: 0;
17631764 }
17641765
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+
17651807 int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
17661808 struct writeback_control *wbc,
17671809 bool do_balance, enum iostat_type io_type)
@@ -1785,6 +1827,7 @@ next_step: · 17 unmodified lines
17851827 for (i = 0; i < nr_pages; i++) {
17861828 struct page *page = pvec.pages[i];
17871829 bool submitted = false;
1830+ bool may_dirty = true;
17881831
17891832 /* give a priority to WB_SYNC threads */
17901833 if (atomic_read(&sbi->wb_sync_req[NODE]) &&
@@ -1832,6 +1875,13 @@ continue_unlock: · 41 unmodified lines
18321875 goto lock_node;
18331876 }
18341877
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+
18351885 f2fs_wait_on_page_writeback(page, NODE, true, true);
18361886
18371887 if (!clear_page_dirty_for_io(page))
@@ -1860,7 +1910,8 @@ continue_unlock: · 22 unmodified lines
18601910 }
18611911
18621912 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)
18641915 goto out;
18651916 step++;
18661917 goto next_step;
@@ -2964,7 +3015,7 @@ static int init_node_manager(struct f2fs_sb_info *sbi) · 1097 unmodified lines
29643015
29653016 /* not used nids: 0, node, meta, (and root counted as valid node) */
29663017 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;
29683019 nm_i->nid_cnt[FREE_NID] = 0;
29693020 nm_i->nid_cnt[PREALLOC_NID] = 0;
29703021 nm_i->nat_cnt = 0;
fs/f2fs/segment.c+66−69
@@ -185,8 +185,6 @@ bool f2fs_need_SSR(struct f2fs_sb_info *sbi) · 184 unmodified lines
185185
186186 void f2fs_register_inmem_page(struct inode *inode, struct page *page)
187187 {
188− struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
189− struct f2fs_inode_info *fi = F2FS_I(inode);
190188 struct inmem_pages *new;
191189
192190 f2fs_trace_pid(page);
@@ -200,15 +198,11 @@ void f2fs_register_inmem_page(struct inode *inode, struct page *page) · 7 unmodified lines
200198 INIT_LIST_HEAD(&new->list);
201199
202200 /* increase reference count with clean state */
203− mutex_lock(&fi->inmem_lock);
204201 get_page(page);
205− list_add_tail(&new->list, &fi->inmem_pages);
206− spin_lock(&sbi->inode_lock[ATOMIC_FILE]);
207− if (list_empty(&fi->inmem_ilist))
208− list_add_tail(&fi->inmem_ilist, &sbi->inode_list[ATOMIC_FILE]);
209− spin_unlock(&sbi->inode_lock[ATOMIC_FILE]);
202+ mutex_lock(&F2FS_I(inode)->inmem_lock);
203+ list_add_tail(&new->list, &F2FS_I(inode)->inmem_pages);
210204 inc_page_count(F2FS_I_SB(inode), F2FS_INMEM_PAGES);
211− mutex_unlock(&fi->inmem_lock);
205+ mutex_unlock(&F2FS_I(inode)->inmem_lock);
212206
213207 trace_f2fs_register_inmem_page(page, INMEM);
214208 }
@@ -330,19 +324,17 @@ void f2fs_drop_inmem_pages(struct inode *inode) · 115 unmodified lines
330324 mutex_lock(&fi->inmem_lock);
331325 __revoke_inmem_pages(inode, &fi->inmem_pages,
332326 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− }
340327 mutex_unlock(&fi->inmem_lock);
341328 }
342329
343330 clear_inode_flag(inode, FI_ATOMIC_FILE);
344331 fi->i_gc_failures[GC_FAILURE_ATOMIC] = 0;
345332 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]);
346338 }
347339
348340 void f2fs_drop_inmem_page(struct inode *inode, struct page *page)
@@ -471,11 +463,6 @@ int f2fs_commit_inmem_pages(struct inode *inode) · 122 unmodified lines
471463
472464 mutex_lock(&fi->inmem_lock);
473465 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]);
479466 mutex_unlock(&fi->inmem_lock);
480467
481468 clear_inode_flag(inode, FI_ATOMIC_COMMIT);
@@ -501,7 +488,7 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need) · 19 unmodified lines
501488 if (need && excess_cached_nats(sbi))
502489 f2fs_balance_fs_bg(sbi);
503490
504− if (f2fs_is_checkpoint_ready(sbi))
491+ if (!f2fs_is_checkpoint_ready(sbi))
505492 return;
506493
507494 /*
@@ -817,9 +804,13 @@ static void __remove_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno, · 309 unmodified lines
817804 if (test_and_clear_bit(segno, dirty_i->dirty_segmap[t]))
818805 dirty_i->nr_dirty[t]--;
819806
820− if (get_valid_blocks(sbi, segno, true) == 0)
807+ if (get_valid_blocks(sbi, segno, true) == 0) {
821808 clear_bit(GET_SEC_FROM_SEG(sbi, segno),
822809 dirty_i->victim_secmap);
810+#ifdef CONFIG_F2FS_CHECK_FS
811+ clear_bit(segno, SIT_I(sbi)->invalid_segmap);
812+#endif
813+ }
823814 }
824815 }
825816
@@ -2084,6 +2075,13 @@ static void destroy_discard_cmd_control(struct f2fs_sb_info *sbi) · 1258 unmodified lines
20842075
20852076 f2fs_stop_discard_thread(sbi);
20862077
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+
20872085 kvfree(dcc);
20882086 SM_I(sbi)->dcc_info = NULL;
20892087 }
@@ -2156,9 +2154,11 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) · 66 unmodified lines
21562154 if (!f2fs_test_and_set_bit(offset, se->discard_map))
21572155 sbi->discard_blks--;
21582156
2159− /* don't overwrite by SSR to keep node chain */
2160− if (IS_NODESEG(se->type) &&
2161− !is_sbi_flag_set(sbi, SBI_CP_DISABLED)) {
2157+ /*
2158+ * SSR should never reuse block which is checkpointed
2159+ * or newly invalidated.
2160+ */
2161+ if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED)) {
21622162 if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map))
21632163 se->ckpt_valid_blocks++;
21642164 }
@@ -3116,12 +3116,14 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, · 951 unmodified lines
31163116 f2fs_inode_chksum_set(sbi, page);
31173117 }
31183118
3119+ if (F2FS_IO_ALIGNED(sbi))
3120+ fio->retry = false;
3121+
31193122 if (add_list) {
31203123 struct f2fs_bio_info *io;
31213124
31223125 INIT_LIST_HEAD(&fio->list);
31233126 fio->in_list = true;
3124− fio->retry = false;
31253127 io = sbi->write_io[fio->type] + fio->temp;
31263128 spin_lock(&io->io_lock);
31273129 list_add_tail(&fio->list, &io->io_list);
@@ -3447,11 +3449,6 @@ static int read_compacted_summaries(struct f2fs_sb_info *sbi) · 319 unmodified lines
34473449 seg_i = CURSEG_I(sbi, i);
34483450 segno = le32_to_cpu(ckpt->cur_data_segno[i]);
34493451 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− }
34553452 seg_i->next_segno = segno;
34563453 reset_curseg(sbi, i, 0);
34573454 seg_i->alloc_type = ckpt->alloc_type[i];
@@ -3941,8 +3938,8 @@ static int build_sit_info(struct f2fs_sb_info *sbi) · 483 unmodified lines
39413938 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
39423939 struct sit_info *sit_i;
39433940 unsigned int sit_segs, start;
3944− char *src_bitmap;
3945− unsigned int bitmap_size;
3941+ char *src_bitmap, *bitmap;
3942+ unsigned int bitmap_size, main_bitmap_size, sit_bitmap_size;
39463943
39473944 /* allocate memory for SIT information */
39483945 sit_i = f2fs_kzalloc(sbi, sizeof(struct sit_info), GFP_KERNEL);
@@ -3958,33 +3955,37 @@ static int build_sit_info(struct f2fs_sb_info *sbi) · 9 unmodified lines
39583955 if (!sit_i->sentries)
39593956 return -ENOMEM;
39603957
3961− bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi));
3962− sit_i->dirty_sentries_bitmap = f2fs_kvzalloc(sbi, bitmap_size,
3958+ main_bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi));
3959+ sit_i->dirty_sentries_bitmap = f2fs_kvzalloc(sbi, main_bitmap_size,
39633960 GFP_KERNEL);
39643961 if (!sit_i->dirty_sentries_bitmap)
39653962 return -ENOMEM;
39663963
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+
39673975 for (start = 0; start < MAIN_SEGS(sbi); start++) {
3968− sit_i->sentries[start].cur_valid_map
3969− = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
3970− sit_i->sentries[start].ckpt_valid_map
3971− = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
3972− if (!sit_i->sentries[start].cur_valid_map ||
3973− !sit_i->sentries[start].ckpt_valid_map)
3974− return -ENOMEM;
3976+ sit_i->sentries[start].cur_valid_map = bitmap;
3977+ bitmap += SIT_VBLOCK_MAP_SIZE;
3978+
3979+ sit_i->sentries[start].ckpt_valid_map = bitmap;
3980+ bitmap += SIT_VBLOCK_MAP_SIZE;
39753981
39763982 #ifdef CONFIG_F2FS_CHECK_FS
3977− sit_i->sentries[start].cur_valid_map_mir
3978− = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
3979− if (!sit_i->sentries[start].cur_valid_map_mir)
3980− return -ENOMEM;
3983+ sit_i->sentries[start].cur_valid_map_mir = bitmap;
3984+ bitmap += SIT_VBLOCK_MAP_SIZE;
39813985 #endif
39823986
3983− sit_i->sentries[start].discard_map
3984− = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
3985− GFP_KERNEL);
3986− if (!sit_i->sentries[start].discard_map)
3987− return -ENOMEM;
3987+ sit_i->sentries[start].discard_map = bitmap;
3988+ bitmap += SIT_VBLOCK_MAP_SIZE;
39883989 }
39893990
39903991 sit_i->tmp_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
@@ -4004,17 +4005,23 @@ static int build_sit_info(struct f2fs_sb_info *sbi) · 13 unmodified lines
40044005 sit_segs = le32_to_cpu(raw_super->segment_count_sit) >> 1;
40054006
40064007 /* setup SIT bitmap from ckeckpoint pack */
4007− bitmap_size = __bitmap_size(sbi, SIT_BITMAP);
4008+ sit_bitmap_size = __bitmap_size(sbi, SIT_BITMAP);
40084009 src_bitmap = __bitmap_ptr(sbi, SIT_BITMAP);
40094010
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);
40114012 if (!sit_i->sit_bitmap)
40124013 return -ENOMEM;
40134014
40144015 #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);
40164018 if (!sit_i->sit_bitmap_mir)
40174019 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;
40184025 #endif
40194026
40204027 /* init SIT information */
@@ -4023,7 +4030,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi) · 2 unmodified lines
40234030 sit_i->sit_base_addr = le32_to_cpu(raw_super->sit_blkaddr);
40244031 sit_i->sit_blocks = sit_segs << sbi->log_blocks_per_seg;
40254032 sit_i->written_valid_blocks = 0;
4026− sit_i->bitmap_size = bitmap_size;
4033+ sit_i->bitmap_size = sit_bitmap_size;
40274034 sit_i->dirty_sentries = 0;
40284035 sit_i->sents_per_block = SIT_ENTRY_PER_BLOCK;
40294036 sit_i->elapsed_time = le64_to_cpu(sbi->ckpt->elapsed_time);
@@ -4161,7 +4168,6 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) · 131 unmodified lines
41614168 if (start >= MAIN_SEGS(sbi)) {
41624169 f2fs_err(sbi, "Wrong journal entry on segno %u",
41634170 start);
4164− set_sbi_flag(sbi, SBI_NEED_FSCK);
41654171 err = -EFSCORRUPTED;
41664172 break;
41674173 }
@@ -4201,7 +4207,6 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) · 33 unmodified lines
42014207 if (!err && total_node_blocks != valid_node_count(sbi)) {
42024208 f2fs_err(sbi, "SIT is corrupted node# %u vs %u",
42034209 total_node_blocks, valid_node_count(sbi));
4204− set_sbi_flag(sbi, SBI_NEED_FSCK);
42054210 err = -EFSCORRUPTED;
42064211 }
42074212
@@ -4492,21 +4497,12 @@ static void destroy_free_segmap(struct f2fs_sb_info *sbi) · 284 unmodified lines
44924497 static void destroy_sit_info(struct f2fs_sb_info *sbi)
44934498 {
44944499 struct sit_info *sit_i = SIT_I(sbi);
4495− unsigned int start;
44964500
44974501 if (!sit_i)
44984502 return;
44994503
4500− if (sit_i->sentries) {
4501− for (start = 0; start < MAIN_SEGS(sbi); start++) {
4502− kvfree(sit_i->sentries[start].cur_valid_map);
4503−#ifdef CONFIG_F2FS_CHECK_FS
4504− kvfree(sit_i->sentries[start].cur_valid_map_mir);
4505−#endif
4506− kvfree(sit_i->sentries[start].ckpt_valid_map);
4507− kvfree(sit_i->sentries[start].discard_map);
4508− }
4509− }
4504+ if (sit_i->sentries)
4505+ kvfree(sit_i->bitmap);
45104506 kvfree(sit_i->tmp_map);
45114507
45124508 kvfree(sit_i->sentries);
@@ -4517,6 +4513,7 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi) · 4 unmodified lines
45174513 kvfree(sit_i->sit_bitmap);
45184514 #ifdef CONFIG_F2FS_CHECK_FS
45194515 kvfree(sit_i->sit_bitmap_mir);
4516+ kvfree(sit_i->invalid_segmap);
45204517 #endif
45214518 kvfree(sit_i);
45224519 }
fs/f2fs/segment.h+8−4
@@ -226,9 +226,13 @@ struct sit_info { · 225 unmodified lines
226226 block_t sit_base_addr; /* start block address of SIT area */
227227 block_t sit_blocks; /* # of blocks used by SIT area */
228228 block_t written_valid_blocks; /* # of valid blocks in main area */
229+ char *bitmap; /* all bitmaps pointer */
229230 char *sit_bitmap; /* SIT bitmap pointer */
230231 #ifdef CONFIG_F2FS_CHECK_FS
231232 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;
232236 #endif
233237 unsigned int bitmap_size; /* SIT bitmap size */
234238
@@ -582,13 +586,13 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, · 347 unmodified lines
582586 reserved_sections(sbi) + needed);
583587 }
584588
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)
586590 {
587591 if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
588− return 0;
592+ return true;
589593 if (likely(!has_not_enough_free_secs(sbi, 0, 0)))
590− return 0;
591− return -ENOSPC;
594+ return true;
595+ return false;
592596 }
593597
594598 static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi)
fs/f2fs/super.c+147−9
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323 #include <linux/f2fs_fs.h>
2424 #include <linux/sysfs.h>
2525 #include <linux/quota.h>
26+#include <linux/unicode.h>
2627
2728 #include "f2fs.h"
2829 #include "node.h"
@@ -222,6 +223,36 @@ void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...) · 193 unmodified lines
222223 va_end(args);
223224 }
224225
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+
225256 static inline void limit_reserve_root(struct f2fs_sb_info *sbi)
226257 {
227258 block_t limit = min((sbi->user_block_count << 1) / 1000,
@@ -798,6 +829,13 @@ static int parse_options(struct super_block *sb, char *options) · 570 unmodified lines
798829 return -EINVAL;
799830 }
800831 #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
801839
802840 if (F2FS_IO_SIZE_BITS(sbi) && !test_opt(sbi, LFS)) {
803841 f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
@@ -873,7 +911,21 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb) · 69 unmodified lines
873911
874912 static int f2fs_drop_inode(struct inode *inode)
875913 {
914+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
876915 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+
877929 /*
878930 * This is to avoid a deadlock condition like below.
879931 * writeback_single_inode(inode)
@@ -1091,6 +1143,9 @@ static void f2fs_put_super(struct super_block *sb) · 211 unmodified lines
10911143 destroy_percpu_info(sbi);
10921144 for (i = 0; i < NR_PAGE_TYPE; i++)
10931145 kvfree(sbi->write_io[i]);
1146+#ifdef CONFIG_UNICODE
1147+ utf8_unload(sbi->s_encoding);
1148+#endif
10941149 kvfree(sbi);
10951150 }
10961151
@@ -1216,8 +1271,7 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) · 119 unmodified lines
12161271 else
12171272 buf->f_bavail = 0;
12181273
1219− avail_node_count = sbi->total_node_count - sbi->nquota_files -
1220− F2FS_RESERVED_NODE_NUM;
1274+ avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
12211275
12221276 if (avail_node_count > user_block_count) {
12231277 buf->f_files = user_block_count;
@@ -1524,6 +1578,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) · 300 unmodified lines
15241578 bool need_stop_gc = false;
15251579 bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE);
15261580 bool disable_checkpoint = test_opt(sbi, DISABLE_CHECKPOINT);
1581+ bool no_io_align = !F2FS_IO_ALIGNED(sbi);
15271582 bool checkpoint_changed;
15281583 #ifdef CONFIG_QUOTA
15291584 int i, j;
@@ -1603,6 +1658,12 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) · 73 unmodified lines
16031658 goto restore_opts;
16041659 }
16051660
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+
16061667 if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) {
16071668 err = -EINVAL;
16081669 f2fs_warn(sbi, "disabling checkpoint not compatible with read-only");
@@ -1981,6 +2042,12 @@ static int f2fs_quota_on(struct super_block *sb, int type, int format_id, · 372 unmodified lines
19812042 struct inode *inode;
19822043 int err;
19832044
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+
19842051 err = f2fs_quota_sync(sb, type);
19852052 if (err)
19862053 return err;
@@ -2000,7 +2067,7 @@ static int f2fs_quota_on(struct super_block *sb, int type, int format_id, · 13 unmodified lines
20002067 return 0;
20012068 }
20022069
2003−static int f2fs_quota_off(struct super_block *sb, int type)
2070+static int __f2fs_quota_off(struct super_block *sb, int type)
20042071 {
20052072 struct inode *inode = sb_dqopt(sb)->files[type];
20062073 int err;
@@ -2026,13 +2093,30 @@ out_put: · 19 unmodified lines
20262093 return err;
20272094 }
20282095
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+
20292113 void f2fs_quota_off_umount(struct super_block *sb)
20302114 {
20312115 int type;
20322116 int err;
20332117
20342118 for (type = 0; type < MAXQUOTAS; type++) {
2035− err = f2fs_quota_off(sb, type);
2119+ err = __f2fs_quota_off(sb, type);
20362120 if (err) {
20372121 int ret = dquot_quota_off(sb, type);
20382122
@@ -2617,8 +2701,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · 578 unmodified lines
26172701 }
26182702
26192703 valid_node_count = le32_to_cpu(ckpt->valid_node_count);
2620− avail_node_count = sbi->total_node_count - sbi->nquota_files -
2621− F2FS_RESERVED_NODE_NUM;
2704+ avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
26222705 if (valid_node_count > avail_node_count) {
26232706 f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u",
26242707 valid_node_count, avail_node_count);
@@ -2657,10 +2740,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · 32 unmodified lines
26572740 }
26582741 }
26592742 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++) {
26612744 if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
26622745 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",
26642747 i, j,
26652748 le32_to_cpu(ckpt->cur_node_segno[i]));
26662749 return 1;
@@ -3033,6 +3116,53 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) · 366 unmodified lines
30333116 return 0;
30343117 }
30353118
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+
30363166 static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi)
30373167 {
30383168 struct f2fs_sm_info *sm_i = SM_I(sbi);
@@ -3129,6 +3259,10 @@ try_onemore: · 90 unmodified lines
31293259 le32_to_cpu(raw_super->log_blocksize);
31303260 sb->s_max_links = F2FS_LINK_MAX;
31313261
3262+ err = f2fs_setup_casefold(sbi);
3263+ if (err)
3264+ goto free_options;
3265+
31323266 #ifdef CONFIG_QUOTA
31333267 sb->dq_op = &f2fs_quota_operations;
31343268 sb->s_qcop = &f2fs_quotactl_ops;
@@ -3207,7 +3341,7 @@ try_onemore: · 72 unmodified lines
32073341 if (err)
32083342 goto free_bio_info;
32093343
3210− if (F2FS_IO_SIZE(sbi) > 1) {
3344+ if (F2FS_IO_ALIGNED(sbi)) {
32113345 sbi->write_io_dummy =
32123346 mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0);
32133347 if (!sbi->write_io_dummy) {
@@ -3482,6 +3616,10 @@ free_percpu: · 268 unmodified lines
34823616 free_bio_info:
34833617 for (i = 0; i < NR_PAGE_TYPE; i++)
34843618 kvfree(sbi->write_io[i]);
3619+
3620+#ifdef CONFIG_UNICODE
3621+ utf8_unload(sbi->s_encoding);
3622+#endif
34853623 free_options:
34863624 #ifdef CONFIG_QUOTA
34873625 for (i = 0; i < MAXQUOTAS; i++)
fs/f2fs/sysfs.c+23−0
@@ -10,6 +10,7 @@ · 9 unmodified lines
1010 #include <linux/proc_fs.h>
1111 #include <linux/f2fs_fs.h>
1212 #include <linux/seq_file.h>
13+#include <linux/unicode.h>
1314
1415 #include "f2fs.h"
1516 #include "segment.h"
@@ -81,6 +82,19 @@ static ssize_t unusable_show(struct f2fs_attr *a, · 65 unmodified lines
8182 (unsigned long long)unusable);
8283 }
8384
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+}
8498
8599 static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,
86100 struct f2fs_sb_info *sbi, char *buf)
@@ -137,6 +151,9 @@ static ssize_t features_show(struct f2fs_attr *a, · 50 unmodified lines
137151 if (f2fs_sb_has_sb_chksum(sbi))
138152 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
139153 len ? ", " : "", "sb_checksum");
154+ if (f2fs_sb_has_casefold(sbi))
155+ len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
156+ len ? ", " : "", "casefold");
140157 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
141158 return len;
142159 }
@@ -369,6 +386,7 @@ enum feat_id { · 226 unmodified lines
369386 FEAT_LOST_FOUND,
370387 FEAT_VERITY,
371388 FEAT_SB_CHECKSUM,
389+ FEAT_CASEFOLD,
372390 };
373391
374392 static ssize_t f2fs_feature_show(struct f2fs_attr *a,
@@ -387,6 +405,7 @@ static ssize_t f2fs_feature_show(struct f2fs_attr *a, · 12 unmodified lines
387405 case FEAT_LOST_FOUND:
388406 case FEAT_VERITY:
389407 case FEAT_SB_CHECKSUM:
408+ case FEAT_CASEFOLD:
390409 return snprintf(buf, PAGE_SIZE, "supported\n");
391410 }
392411 return 0;
@@ -460,6 +479,7 @@ F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes); · 67 unmodified lines
460479 F2FS_GENERAL_RO_ATTR(features);
461480 F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
462481 F2FS_GENERAL_RO_ATTR(unusable);
482+F2FS_GENERAL_RO_ATTR(encoding);
463483
464484 #ifdef CONFIG_FS_ENCRYPTION
465485 F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO);
@@ -479,6 +499,7 @@ F2FS_FEATURE_RO_ATTR(lost_found, FEAT_LOST_FOUND); · 13 unmodified lines
479499 F2FS_FEATURE_RO_ATTR(verity, FEAT_VERITY);
480500 #endif
481501 F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM);
502+F2FS_FEATURE_RO_ATTR(casefold, FEAT_CASEFOLD);
482503
483504 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
484505 static struct attribute *f2fs_attrs[] = {
@@ -523,6 +544,7 @@ static struct attribute *f2fs_attrs[] = { · 38 unmodified lines
523544 ATTR_LIST(features),
524545 ATTR_LIST(reserved_blocks),
525546 ATTR_LIST(current_reserved_blocks),
547+ ATTR_LIST(encoding),
526548 NULL,
527549 };
528550 ATTRIBUTE_GROUPS(f2fs);
@@ -546,6 +568,7 @@ static struct attribute *f2fs_feat_attrs[] = { · 17 unmodified lines
546568 ATTR_LIST(verity),
547569 #endif
548570 ATTR_LIST(sb_checksum),
571+ ATTR_LIST(casefold),
549572 NULL,
550573 };
551574 ATTRIBUTE_GROUPS(f2fs_feat);
fs/f2fs/xattr.c+6−0
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #include <linux/posix_acl_xattr.h>
2222 #include "f2fs.h"
2323 #include "xattr.h"
24+#include "segment.h"
2425
2526 static int f2fs_xattr_generic_get(const struct xattr_handler *handler,
2627 struct dentry *unused, struct inode *inode,
@@ -729,6 +730,11 @@ int f2fs_setxattr(struct inode *inode, int index, const char *name, · 702 unmodified lines
729730 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
730731 int err;
731732
733+ if (unlikely(f2fs_cp_error(sbi)))
734+ return -EIO;
735+ if (!f2fs_is_checkpoint_ready(sbi))
736+ return -ENOSPC;
737+
732738 err = dquot_initialize(inode);
733739 if (err)
734740 return err;
include/linux/f2fs_fs.h+9−1
@@ -36,11 +36,17 @@ · 35 unmodified lines
3636
3737 #define F2FS_MAX_QUOTAS 3
3838
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+
3944 #define F2FS_IO_SIZE(sbi) (1 << F2FS_OPTION(sbi).write_io_size_bits) /* Blocks */
4045 #define F2FS_IO_SIZE_KB(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 2)) /* KB */
4146 #define F2FS_IO_SIZE_BYTES(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 12)) /* B */
4247 #define F2FS_IO_SIZE_BITS(sbi) (F2FS_OPTION(sbi).write_io_size_bits) /* power of 2 */
4348 #define F2FS_IO_SIZE_MASK(sbi) (F2FS_IO_SIZE(sbi) - 1)
49+#define F2FS_IO_ALIGNED(sbi) (F2FS_IO_SIZE(sbi) > 1)
4450
4551 /* This flag is used by node and meta inodes, and by recovery */
4652 #define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO)
@@ -109,7 +115,9 @@ struct f2fs_super_block { · 62 unmodified lines
109115 struct f2fs_device devs[MAX_DEVICES]; /* device list */
110116 __le32 qf_ino[F2FS_MAX_QUOTAS]; /* quota inode numbers */
111117 __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 */
113121 __le32 crc; /* checksum of superblock */
114122 } __packed;
115123
include/uapi/linux/fs.h+1−0
@@ -264,6 +264,7 @@ struct fsxattr { · 263 unmodified lines
264264 #define FS_NOCOW_FL 0x00800000 /* Do not cow file */
265265 #define FS_INLINE_DATA_FL 0x10000000 /* Reserved for ext4 */
266266 #define FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */
267+#define FS_CASEFOLD_FL 0x40000000 /* Folder is case insensitive */
267268 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
268269
269270 #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
tools/include/uapi/linux/fs.h+1−0
@@ -311,6 +311,7 @@ struct fscrypt_key { · 310 unmodified lines
311311 #define FS_NOCOW_FL 0x00800000 /* Do not cow file */
312312 #define FS_INLINE_DATA_FL 0x10000000 /* Reserved for ext4 */
313313 #define FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */
314+#define FS_CASEFOLD_FL 0x40000000 /* Folder is case insensitive */
314315 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
315316
316317 #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t