Skip to content

Commit fbc246a

Browse files
committed
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 ...
2 parents 7ce1e15 + fbbf779 commit fbc246a

22 files changed

Lines changed: 865 additions & 204 deletions

File tree

‎Documentation/ABI/testing/sysfs-fs-f2fs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,10 @@ Description:
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‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ noinline_data Disable the inline data feature, inline data feature is
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>
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‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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
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‎

Lines changed: 70 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -283,26 +283,25 @@ static bool __same_bdev(struct f2fs_sb_info *sbi,
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,
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)
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)
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)
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 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
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 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
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 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
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 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
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,
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,
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 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,
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,
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‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ static void update_general_status(struct f2fs_sb_info *sbi)
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 =
7474
atomic_read(&SM_I(sbi)->fcc_info->queued_flush);
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 =

0 commit comments

Comments
 (0)