Skip to content

Commit 5160bcc

Browse files
committed
Merge tag 'f2fs-for-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
Pull f2fs updates from Jaegeuk Kim: "We've continued mainly to fix bugs in this round, as f2fs has been shipped in more devices. Especially, we've focused on stabilizing checkpoint=disable feature, and provided some interfaces for QA. Enhancements: - expose FS_NOCOW_FL for pin_file - run discard jobs at unmount time with timeout - tune discarding thread to avoid idling which consumes power - some checking codes to address vulnerabilities - give random value to i_generation - shutdown with more flags for QA Bug fixes: - clean up stale objects when mount is failed along with checkpoint=disable - fix system being stuck due to wrong count by atomic writes - handle some corrupted disk cases - fix a deadlock in f2fs_read_inline_dir We've also added some minor build error fixes and clean-up patches" * tag 'f2fs-for-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (53 commits) f2fs: set pin_file under CAP_SYS_ADMIN f2fs: fix to avoid deadlock in f2fs_read_inline_dir() f2fs: fix to adapt small inline xattr space in __find_inline_xattr() f2fs: fix to do sanity check with inode.i_inline_xattr_size f2fs: give some messages for inline_xattr_size f2fs: don't trigger read IO for beyond EOF page f2fs: fix to add refcount once page is tagged PG_private f2fs: remove wrong comment in f2fs_invalidate_page() f2fs: fix to use kvfree instead of kzfree f2fs: print more parameters in trace_f2fs_map_blocks f2fs: trace f2fs_ioc_shutdown f2fs: fix to avoid deadlock of atomic file operations f2fs: fix to dirty inode for i_mode recovery f2fs: give random value to i_generation f2fs: no need to take page lock in readdir f2fs: fix to update iostat correctly in IPU path f2fs: fix encrypted page memory leak f2fs: make fault injection covering __submit_flush_wait() f2fs: fix to retry fill_super only if recovery failed f2fs: silence VM_WARN_ON_ONCE in mempool_alloc ...
2 parents f91f2ee + aff7b62 commit 5160bcc

File tree

22 files changed

+424
-185
lines changed

22 files changed

+424
-185
lines changed

Documentation/ABI/testing/sysfs-fs-f2fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ Description:
8686
The unit size is one block, now only support configuring in range
8787
of [1, 512].
8888

89+
What: /sys/fs/f2fs/<disk>/umount_discard_timeout
90+
Date: January 2019
91+
Contact: "Jaegeuk Kim" <jaegeuk@kernel.org>
92+
Description:
93+
Set timeout to issue discard commands during umount.
94+
Default: 5 secs
95+
8996
What: /sys/fs/f2fs/<disk>/max_victim_search
9097
Date: January 2014
9198
Contact: "Jaegeuk Kim" <jaegeuk.kim@samsung.com>

Documentation/filesystems/f2fs.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ disable_ext_identify Disable the extension list configured by mkfs, so f2fs
126126
does not aware of cold files such as media files.
127127
inline_xattr Enable the inline xattrs feature.
128128
noinline_xattr Disable the inline xattrs feature.
129+
inline_xattr_size=%u Support configuring inline xattr size, it depends on
130+
flexible inline xattr feature.
129131
inline_data Enable the inline data feature: New created small(<~3.4k)
130132
files can be written into inode block.
131133
inline_dentry Enable the inline dir feature: data in new created

fs/f2fs/checkpoint.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,9 @@ static int f2fs_write_meta_pages(struct address_space *mapping,
306306
goto skip_write;
307307

308308
/* collect a number of dirty meta pages and write together */
309-
if (wbc->for_kupdate ||
310-
get_pages(sbi, F2FS_DIRTY_META) < nr_pages_to_skip(sbi, META))
309+
if (wbc->sync_mode != WB_SYNC_ALL &&
310+
get_pages(sbi, F2FS_DIRTY_META) <
311+
nr_pages_to_skip(sbi, META))
311312
goto skip_write;
312313

313314
/* if locked failed, cp will flush dirty pages instead */
@@ -405,7 +406,7 @@ static int f2fs_set_meta_page_dirty(struct page *page)
405406
if (!PageDirty(page)) {
406407
__set_page_dirty_nobuffers(page);
407408
inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_META);
408-
SetPagePrivate(page);
409+
f2fs_set_page_private(page, 0);
409410
f2fs_trace_pid(page);
410411
return 1;
411412
}
@@ -956,7 +957,7 @@ void f2fs_update_dirty_page(struct inode *inode, struct page *page)
956957
inode_inc_dirty_pages(inode);
957958
spin_unlock(&sbi->inode_lock[type]);
958959

959-
SetPagePrivate(page);
960+
f2fs_set_page_private(page, 0);
960961
f2fs_trace_pid(page);
961962
}
962963

@@ -1259,10 +1260,17 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
12591260
else
12601261
__clear_ckpt_flags(ckpt, CP_DISABLED_FLAG);
12611262

1263+
if (is_sbi_flag_set(sbi, SBI_CP_DISABLED_QUICK))
1264+
__set_ckpt_flags(ckpt, CP_DISABLED_QUICK_FLAG);
1265+
else
1266+
__clear_ckpt_flags(ckpt, CP_DISABLED_QUICK_FLAG);
1267+
12621268
if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH))
12631269
__set_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG);
1264-
else
1265-
__clear_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG);
1270+
/*
1271+
* TODO: we count on fsck.f2fs to clear this flag until we figure out
1272+
* missing cases which clear it incorrectly.
1273+
*/
12661274

12671275
if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_REPAIR))
12681276
__set_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG);

fs/f2fs/data.c

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,10 @@ static inline void __submit_bio(struct f2fs_sb_info *sbi,
301301
for (; start < F2FS_IO_SIZE(sbi); start++) {
302302
struct page *page =
303303
mempool_alloc(sbi->write_io_dummy,
304-
GFP_NOIO | __GFP_ZERO | __GFP_NOFAIL);
304+
GFP_NOIO | __GFP_NOFAIL);
305305
f2fs_bug_on(sbi, !page);
306306

307+
zero_user_segment(page, 0, PAGE_SIZE);
307308
SetPagePrivate(page);
308309
set_page_private(page, (unsigned long)DUMMY_WRITTEN_PAGE);
309310
lock_page(page);
@@ -1553,6 +1554,9 @@ static int f2fs_mpage_readpages(struct address_space *mapping,
15531554
if (last_block > last_block_in_file)
15541555
last_block = last_block_in_file;
15551556

1557+
/* just zeroing out page which is beyond EOF */
1558+
if (block_in_file >= last_block)
1559+
goto zero_out;
15561560
/*
15571561
* Map blocks using the previous result first.
15581562
*/
@@ -1565,16 +1569,11 @@ static int f2fs_mpage_readpages(struct address_space *mapping,
15651569
* Then do more f2fs_map_blocks() calls until we are
15661570
* done with this page.
15671571
*/
1568-
map.m_flags = 0;
1569-
1570-
if (block_in_file < last_block) {
1571-
map.m_lblk = block_in_file;
1572-
map.m_len = last_block - block_in_file;
1572+
map.m_lblk = block_in_file;
1573+
map.m_len = last_block - block_in_file;
15731574

1574-
if (f2fs_map_blocks(inode, &map, 0,
1575-
F2FS_GET_BLOCK_DEFAULT))
1576-
goto set_error_page;
1577-
}
1575+
if (f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_DEFAULT))
1576+
goto set_error_page;
15781577
got_it:
15791578
if ((map.m_flags & F2FS_MAP_MAPPED)) {
15801579
block_nr = map.m_pblk + block_in_file - map.m_lblk;
@@ -1589,6 +1588,7 @@ static int f2fs_mpage_readpages(struct address_space *mapping,
15891588
DATA_GENERIC))
15901589
goto set_error_page;
15911590
} else {
1591+
zero_out:
15921592
zero_user_segment(page, 0, PAGE_SIZE);
15931593
if (!PageUptodate(page))
15941594
SetPageUptodate(page);
@@ -1863,8 +1863,13 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
18631863
if (fio->need_lock == LOCK_REQ)
18641864
f2fs_unlock_op(fio->sbi);
18651865
err = f2fs_inplace_write_data(fio);
1866-
if (err && PageWriteback(page))
1867-
end_page_writeback(page);
1866+
if (err) {
1867+
if (f2fs_encrypted_file(inode))
1868+
fscrypt_pullback_bio_page(&fio->encrypted_page,
1869+
true);
1870+
if (PageWriteback(page))
1871+
end_page_writeback(page);
1872+
}
18681873
trace_f2fs_do_write_data_page(fio->page, IPU);
18691874
set_inode_flag(inode, FI_UPDATE_WRITE);
18701875
return err;
@@ -2315,7 +2320,8 @@ static void f2fs_write_failed(struct address_space *mapping, loff_t to)
23152320
down_write(&F2FS_I(inode)->i_mmap_sem);
23162321

23172322
truncate_pagecache(inode, i_size);
2318-
f2fs_truncate_blocks(inode, i_size, true, true);
2323+
if (!IS_NOQUOTA(inode))
2324+
f2fs_truncate_blocks(inode, i_size, true);
23192325

23202326
up_write(&F2FS_I(inode)->i_mmap_sem);
23212327
up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
@@ -2585,14 +2591,11 @@ static void f2fs_dio_submit_bio(struct bio *bio, struct inode *inode,
25852591
{
25862592
struct f2fs_private_dio *dio;
25872593
bool write = (bio_op(bio) == REQ_OP_WRITE);
2588-
int err;
25892594

25902595
dio = f2fs_kzalloc(F2FS_I_SB(inode),
25912596
sizeof(struct f2fs_private_dio), GFP_NOFS);
2592-
if (!dio) {
2593-
err = -ENOMEM;
2597+
if (!dio)
25942598
goto out;
2595-
}
25962599

25972600
dio->inode = inode;
25982601
dio->orig_end_io = bio->bi_end_io;
@@ -2710,12 +2713,10 @@ void f2fs_invalidate_page(struct page *page, unsigned int offset,
27102713

27112714
clear_cold_data(page);
27122715

2713-
/* This is atomic written page, keep Private */
27142716
if (IS_ATOMIC_WRITTEN_PAGE(page))
27152717
return f2fs_drop_inmem_page(inode, page);
27162718

2717-
set_page_private(page, 0);
2718-
ClearPagePrivate(page);
2719+
f2fs_clear_page_private(page);
27192720
}
27202721

27212722
int f2fs_release_page(struct page *page, gfp_t wait)
@@ -2729,8 +2730,7 @@ int f2fs_release_page(struct page *page, gfp_t wait)
27292730
return 0;
27302731

27312732
clear_cold_data(page);
2732-
set_page_private(page, 0);
2733-
ClearPagePrivate(page);
2733+
f2fs_clear_page_private(page);
27342734
return 1;
27352735
}
27362736

@@ -2798,12 +2798,8 @@ int f2fs_migrate_page(struct address_space *mapping,
27982798
return -EAGAIN;
27992799
}
28002800

2801-
/*
2802-
* A reference is expected if PagePrivate set when move mapping,
2803-
* however F2FS breaks this for maintaining dirty page counts when
2804-
* truncating pages. So here adjusting the 'extra_count' make it work.
2805-
*/
2806-
extra_count = (atomic_written ? 1 : 0) - page_has_private(page);
2801+
/* one extra reference was held for atomic_write page */
2802+
extra_count = atomic_written ? 1 : 0;
28072803
rc = migrate_page_move_mapping(mapping, newpage,
28082804
page, mode, extra_count);
28092805
if (rc != MIGRATEPAGE_SUCCESS) {
@@ -2824,9 +2820,10 @@ int f2fs_migrate_page(struct address_space *mapping,
28242820
get_page(newpage);
28252821
}
28262822

2827-
if (PagePrivate(page))
2828-
SetPagePrivate(newpage);
2829-
set_page_private(newpage, page_private(page));
2823+
if (PagePrivate(page)) {
2824+
f2fs_set_page_private(newpage, page_private(page));
2825+
f2fs_clear_page_private(page);
2826+
}
28302827

28312828
if (mode != MIGRATE_SYNC_NO_COPY)
28322829
migrate_page_copy(newpage, page);

fs/f2fs/debug.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ static void update_general_status(struct f2fs_sb_info *sbi)
9696
si->free_secs = free_sections(sbi);
9797
si->prefree_count = prefree_segments(sbi);
9898
si->dirty_count = dirty_segments(sbi);
99-
si->node_pages = NODE_MAPPING(sbi)->nrpages;
100-
si->meta_pages = META_MAPPING(sbi)->nrpages;
99+
if (sbi->node_inode)
100+
si->node_pages = NODE_MAPPING(sbi)->nrpages;
101+
if (sbi->meta_inode)
102+
si->meta_pages = META_MAPPING(sbi)->nrpages;
101103
si->nats = NM_I(sbi)->nat_cnt;
102104
si->dirty_nats = NM_I(sbi)->dirty_nat_cnt;
103105
si->sits = MAIN_SEGS(sbi);
@@ -175,7 +177,6 @@ static void update_sit_info(struct f2fs_sb_info *sbi)
175177
static void update_mem_info(struct f2fs_sb_info *sbi)
176178
{
177179
struct f2fs_stat_info *si = F2FS_STAT(sbi);
178-
unsigned npages;
179180
int i;
180181

181182
if (si->base_mem)
@@ -258,10 +259,14 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
258259
sizeof(struct extent_node);
259260

260261
si->page_mem = 0;
261-
npages = NODE_MAPPING(sbi)->nrpages;
262-
si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
263-
npages = META_MAPPING(sbi)->nrpages;
264-
si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
262+
if (sbi->node_inode) {
263+
unsigned npages = NODE_MAPPING(sbi)->nrpages;
264+
si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
265+
}
266+
if (sbi->meta_inode) {
267+
unsigned npages = META_MAPPING(sbi)->nrpages;
268+
si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
269+
}
265270
}
266271

267272
static int stat_show(struct seq_file *s, void *v)

fs/f2fs/dir.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
728728
!f2fs_truncate_hole(dir, page->index, page->index + 1)) {
729729
f2fs_clear_page_cache_dirty_tag(page);
730730
clear_page_dirty_for_io(page);
731-
ClearPagePrivate(page);
731+
f2fs_clear_page_private(page);
732732
ClearPageUptodate(page);
733733
clear_cold_data(page);
734734
inode_dec_dirty_pages(dir);
@@ -800,6 +800,10 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
800800
if (de->name_len == 0) {
801801
bit_pos++;
802802
ctx->pos = start_pos + bit_pos;
803+
printk_ratelimited(
804+
"%s, invalid namelen(0), ino:%u, run fsck to fix.",
805+
KERN_WARNING, le32_to_cpu(de->ino));
806+
set_sbi_flag(sbi, SBI_NEED_FSCK);
803807
continue;
804808
}
805809

@@ -810,7 +814,8 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
810814

811815
/* check memory boundary before moving forward */
812816
bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
813-
if (unlikely(bit_pos > d->max)) {
817+
if (unlikely(bit_pos > d->max ||
818+
le16_to_cpu(de->name_len) > F2FS_NAME_LEN)) {
814819
f2fs_msg(sbi->sb, KERN_WARNING,
815820
"%s: corrupted namelen=%d, run fsck to fix.",
816821
__func__, le16_to_cpu(de->name_len));
@@ -891,7 +896,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
891896
page_cache_sync_readahead(inode->i_mapping, ra, file, n,
892897
min(npages - n, (pgoff_t)MAX_DIR_RA_PAGES));
893898

894-
dentry_page = f2fs_get_lock_data_page(inode, n, false);
899+
dentry_page = f2fs_find_data_page(inode, n);
895900
if (IS_ERR(dentry_page)) {
896901
err = PTR_ERR(dentry_page);
897902
if (err == -ENOENT) {
@@ -909,11 +914,11 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
909914
err = f2fs_fill_dentries(ctx, &d,
910915
n * NR_DENTRY_IN_BLOCK, &fstr);
911916
if (err) {
912-
f2fs_put_page(dentry_page, 1);
917+
f2fs_put_page(dentry_page, 0);
913918
break;
914919
}
915920

916-
f2fs_put_page(dentry_page, 1);
921+
f2fs_put_page(dentry_page, 0);
917922
}
918923
out_free:
919924
fscrypt_fname_free_buffer(&fstr);

fs/f2fs/extent_cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ static void f2fs_update_extent_tree_range(struct inode *inode,
506506
unsigned int end = fofs + len;
507507
unsigned int pos = (unsigned int)fofs;
508508
bool updated = false;
509-
bool leftmost;
509+
bool leftmost = false;
510510

511511
if (!et)
512512
return;

0 commit comments

Comments
 (0)