From 75a037f3604ceb781ae23167e0cdfbe5d71533d7 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Wed, 31 Jul 2019 13:27:05 -0700 Subject: f2fs: fix livelock in swapfile writes This patch fixes livelock in the below call path when writing swap pages. [46374.617256] c2 701 __switch_to+0xe4/0x100 [46374.617265] c2 701 __schedule+0x80c/0xbc4 [46374.617273] c2 701 schedule+0x74/0x98 [46374.617281] c2 701 rwsem_down_read_failed+0x190/0x234 [46374.617291] c2 701 down_read+0x58/0x5c [46374.617300] c2 701 f2fs_map_blocks+0x138/0x9a8 [46374.617310] c2 701 get_data_block_dio_write+0x74/0x104 [46374.617320] c2 701 __blockdev_direct_IO+0x1350/0x3930 [46374.617331] c2 701 f2fs_direct_IO+0x55c/0x8bc [46374.617341] c2 701 __swap_writepage+0x1d0/0x3e8 [46374.617351] c2 701 swap_writepage+0x44/0x54 [46374.617360] c2 701 shrink_page_list+0x140/0xe80 [46374.617371] c2 701 shrink_inactive_list+0x510/0x918 [46374.617381] c2 701 shrink_node_memcg+0x2d4/0x804 [46374.617391] c2 701 shrink_node+0x10c/0x2f8 [46374.617400] c2 701 do_try_to_free_pages+0x178/0x38c [46374.617410] c2 701 try_to_free_pages+0x348/0x4b8 [46374.617419] c2 701 __alloc_pages_nodemask+0x7f8/0x1014 [46374.617429] c2 701 pagecache_get_page+0x184/0x2cc [46374.617438] c2 701 f2fs_new_node_page+0x60/0x41c [46374.617449] c2 701 f2fs_new_inode_page+0x50/0x7c [46374.617460] c2 701 f2fs_init_inode_metadata+0x128/0x530 [46374.617472] c2 701 f2fs_add_inline_entry+0x138/0xd64 [46374.617480] c2 701 f2fs_do_add_link+0xf4/0x178 [46374.617488] c2 701 f2fs_create+0x1e4/0x3ac [46374.617497] c2 701 path_openat+0xdc0/0x1308 [46374.617507] c2 701 do_filp_open+0x78/0x124 [46374.617516] c2 701 do_sys_open+0x134/0x248 [46374.617525] c2 701 SyS_openat+0x14/0x20 Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim --- fs/f2fs/data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fs/f2fs/data.c') diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index abbf14e9bd72..f49f243fd54f 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1372,7 +1372,7 @@ static int get_data_block_dio_write(struct inode *inode, sector_t iblock, return __get_data_block(inode, iblock, bh_result, create, F2FS_GET_BLOCK_DIO, NULL, f2fs_rw_hint_to_seg_type(inode->i_write_hint), - true); + IS_SWAPFILE(inode) ? false : true); } static int get_data_block_dio(struct inode *inode, sector_t iblock, -- cgit v1.2.3 From 8896cbdfed0ca34452252b72d6ee97bcfca9abd2 Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Fri, 12 Jul 2019 16:55:41 +0800 Subject: f2fs: introduce {page,io}_is_mergeable() for readability Wrap merge condition into function for readability, no logic change. Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim --- fs/f2fs/data.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'fs/f2fs/data.c') diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index f49f243fd54f..0686306ed988 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -481,6 +481,33 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) return 0; } +static bool page_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio, + block_t last_blkaddr, block_t cur_blkaddr) +{ + if (last_blkaddr + 1 != cur_blkaddr) + return false; + return __same_bdev(sbi, cur_blkaddr, bio); +} + +static bool io_type_is_mergeable(struct f2fs_bio_info *io, + struct f2fs_io_info *fio) +{ + if (io->fio.op != fio->op) + return false; + return io->fio.op_flags == fio->op_flags; +} + +static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio, + struct f2fs_bio_info *io, + struct f2fs_io_info *fio, + block_t last_blkaddr, + block_t cur_blkaddr) +{ + if (!page_is_mergeable(sbi, bio, last_blkaddr, cur_blkaddr)) + return false; + return io_type_is_mergeable(io, fio); +} + int f2fs_merge_page_bio(struct f2fs_io_info *fio) { struct bio *bio = *fio->bio; @@ -494,8 +521,8 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) trace_f2fs_submit_page_bio(page, fio); f2fs_trace_ios(fio, 0); - if (bio && (*fio->last_block + 1 != fio->new_blkaddr || - !__same_bdev(fio->sbi, fio->new_blkaddr, bio))) { + if (bio && !page_is_mergeable(fio->sbi, bio, *fio->last_block, + fio->new_blkaddr)) { __submit_bio(fio->sbi, bio, fio->type); bio = NULL; } @@ -568,9 +595,8 @@ next: inc_page_count(sbi, WB_DATA_TYPE(bio_page)); - if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 || - (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags) || - !__same_bdev(sbi, fio->new_blkaddr, io->bio))) + if (io->bio && !io_is_mergeable(sbi, io->bio, io, fio, + io->last_block_in_bio, fio->new_blkaddr)) __submit_merged_bio(io); alloc_new: if (io->bio == NULL) { @@ -1642,8 +1668,8 @@ zero_out: * This page will go to BIO. Do we need to send this * BIO off first? */ - if (bio && (*last_block_in_bio != block_nr - 1 || - !__same_bdev(F2FS_I_SB(inode), block_nr, bio))) { + if (bio && !page_is_mergeable(F2FS_I_SB(inode), bio, + *last_block_in_bio, block_nr)) { submit_and_realloc: __submit_bio(F2FS_I_SB(inode), bio, DATA); bio = NULL; -- cgit v1.2.3 From c72db71ed61ff51c2b8189ac9889dd18f22eb612 Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Fri, 12 Jul 2019 16:55:42 +0800 Subject: f2fs: fix panic of IO alignment feature Since 07173c3ec276 ("block: enable multipage bvecs"), one bio vector can store multi pages, so that we can not calculate max IO size of bio as PAGE_SIZE * bio->bi_max_vecs. However IO alignment feature of f2fs always has that assumption, so finally, it may cause panic during IO submission as below stack. kernel BUG at fs/f2fs/data.c:317! RIP: 0010:__submit_merged_bio+0x8b0/0x8c0 Call Trace: f2fs_submit_page_write+0x3cd/0xdd0 do_write_page+0x15d/0x360 f2fs_outplace_write_data+0xd7/0x210 f2fs_do_write_data_page+0x43b/0xf30 __write_data_page+0xcf6/0x1140 f2fs_write_cache_pages+0x3ba/0xb40 f2fs_write_data_pages+0x3dd/0x8b0 do_writepages+0xbb/0x1e0 __writeback_single_inode+0xb6/0x800 writeback_sb_inodes+0x441/0x910 wb_writeback+0x261/0x650 wb_workfn+0x1f9/0x7a0 process_one_work+0x503/0x970 worker_thread+0x7d/0x820 kthread+0x1ad/0x210 ret_from_fork+0x35/0x40 This patch adds one extra condition to check left space in bio while trying merging page to bio, to avoid panic. This bug was reported in bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204043 Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim --- fs/f2fs/data.c | 10 ++++++++++ fs/f2fs/super.c | 2 +- include/linux/f2fs_fs.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) (limited to 'fs/f2fs/data.c') diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 0686306ed988..5bce20005add 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -503,6 +503,16 @@ static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio, block_t last_blkaddr, block_t cur_blkaddr) { + if (F2FS_IO_ALIGNED(sbi) && (fio->type == DATA || fio->type == NODE)) { + unsigned int filled_blocks = + F2FS_BYTES_TO_BLK(bio->bi_iter.bi_size); + unsigned int io_size = F2FS_IO_SIZE(sbi); + unsigned int left_vecs = bio->bi_max_vecs - bio->bi_vcnt; + + /* IOs in bio is aligned and left space of vectors is not enough */ + if (!(filled_blocks % io_size) && left_vecs < io_size) + return false; + } if (!page_is_mergeable(sbi, bio, last_blkaddr, cur_blkaddr)) return false; return io_type_is_mergeable(io, fio); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 78a1b873e48a..720f2e6d6f0a 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3202,7 +3202,7 @@ try_onemore: if (err) goto free_bio_info; - if (F2FS_IO_SIZE(sbi) > 1) { + if (F2FS_IO_ALIGNED(sbi)) { sbi->write_io_dummy = mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); if (!sbi->write_io_dummy) { diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 65559900d4d7..52af9ac164b4 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -41,6 +41,7 @@ #define F2FS_IO_SIZE_BYTES(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 12)) /* B */ #define F2FS_IO_SIZE_BITS(sbi) (F2FS_OPTION(sbi).write_io_size_bits) /* power of 2 */ #define F2FS_IO_SIZE_MASK(sbi) (F2FS_IO_SIZE(sbi) - 1) +#define F2FS_IO_ALIGNED(sbi) (F2FS_IO_SIZE(sbi) > 1) /* This flag is used by node and meta inodes, and by recovery */ #define GFP_F2FS_ZERO (GFP_NOFS | __GFP_ZERO) -- cgit v1.2.3 From 7975f3498dc0403d8177c0775b9514158ec66681 Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Mon, 22 Jul 2019 18:03:50 +0800 Subject: f2fs: support fiemap() for directory inode Adjust f2fs_fiemap() to support fiemap() on directory inode. Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim --- fs/f2fs/data.c | 2 +- fs/f2fs/inline.c | 8 +++++++- fs/f2fs/namei.c | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'fs/f2fs/data.c') diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 5bce20005add..73ed4ff9d01c 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1539,7 +1539,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, goto out; } - if (f2fs_has_inline_data(inode)) { + if (f2fs_has_inline_data(inode) || f2fs_has_inline_dentry(inode)) { ret = f2fs_inline_data_fiemap(inode, fieinfo, start, len); if (ret != -EAGAIN) goto out; diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 3613efca8c00..8c0712154fb1 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -704,7 +704,13 @@ int f2fs_inline_data_fiemap(struct inode *inode, if (IS_ERR(ipage)) return PTR_ERR(ipage); - if (!f2fs_has_inline_data(inode)) { + if ((S_ISREG(inode->i_mode) || S_ISLNK(inode->i_mode)) && + !f2fs_has_inline_data(inode)) { + err = -EAGAIN; + goto out; + } + + if (S_ISDIR(inode->i_mode) && !f2fs_has_inline_dentry(inode)) { err = -EAGAIN; goto out; } diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index c5b99042e6f2..612561c4f7bd 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -1250,6 +1250,7 @@ const struct inode_operations f2fs_dir_inode_operations = { #ifdef CONFIG_F2FS_FS_XATTR .listxattr = f2fs_listxattr, #endif + .fiemap = f2fs_fiemap, }; const struct inode_operations f2fs_symlink_inode_operations = { -- cgit v1.2.3 From b757f6edbeddd0c43135edfdee18103bd73f0991 Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Fri, 23 Aug 2019 17:58:35 +0800 Subject: f2fs: clean up __bio_alloc()'s parameter Just cleanup, no logic change. Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim --- fs/f2fs/data.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'fs/f2fs/data.c') diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 73ed4ff9d01c..0b3728f58d17 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -259,26 +259,25 @@ static bool __same_bdev(struct f2fs_sb_info *sbi, /* * Low-level block read/write IO operations. */ -static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr, - struct writeback_control *wbc, - int npages, bool is_read, - enum page_type type, enum temp_type temp) +static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages) { + struct f2fs_sb_info *sbi = fio->sbi; struct bio *bio; bio = f2fs_bio_alloc(sbi, npages, true); - f2fs_target_device(sbi, blk_addr, bio); - if (is_read) { + f2fs_target_device(sbi, fio->new_blkaddr, bio); + if (is_read_io(fio->op)) { bio->bi_end_io = f2fs_read_end_io; bio->bi_private = NULL; } else { bio->bi_end_io = f2fs_write_end_io; bio->bi_private = sbi; - bio->bi_write_hint = f2fs_io_type_to_rw_hint(sbi, type, temp); + bio->bi_write_hint = f2fs_io_type_to_rw_hint(sbi, + fio->type, fio->temp); } - if (wbc) - wbc_init_bio(wbc, bio); + if (fio->io_wbc) + wbc_init_bio(fio->io_wbc, bio); return bio; } @@ -461,8 +460,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) f2fs_trace_ios(fio, 0); /* Allocate a new bio */ - bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc, - 1, is_read_io(fio->op), fio->type, fio->temp); + bio = __bio_alloc(fio, 1); if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { bio_put(bio); @@ -538,8 +536,7 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) } alloc_new: if (!bio) { - bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc, - BIO_MAX_PAGES, false, fio->type, fio->temp); + bio = __bio_alloc(fio, BIO_MAX_PAGES); bio_set_op_attrs(bio, fio->op, fio->op_flags); } @@ -616,9 +613,7 @@ alloc_new: fio->retry = true; goto skip; } - io->bio = __bio_alloc(sbi, fio->new_blkaddr, fio->io_wbc, - BIO_MAX_PAGES, false, - fio->type, fio->temp); + io->bio = __bio_alloc(fio, BIO_MAX_PAGES); io->fio = *fio; } -- cgit v1.2.3 From 00e09c0bccc71825ca9a659eb145ed7c4dc95588 Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Fri, 23 Aug 2019 17:58:36 +0800 Subject: f2fs: enhance f2fs_is_checkpoint_ready()'s readability This patch changes sematics of f2fs_is_checkpoint_ready()'s return value as: return true when checkpoint is ready, other return false, it can improve readability of below conditions. f2fs_submit_page_write() ... if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) || !f2fs_is_checkpoint_ready(sbi)) __submit_merged_bio(io); f2fs_balance_fs() ... if (!f2fs_is_checkpoint_ready(sbi)) return; Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim --- fs/f2fs/data.c | 7 ++++--- fs/f2fs/file.c | 18 ++++++++---------- fs/f2fs/inode.c | 2 +- fs/f2fs/namei.c | 36 ++++++++++++++---------------------- fs/f2fs/segment.c | 2 +- fs/f2fs/segment.h | 8 ++++---- fs/f2fs/xattr.c | 5 ++--- 7 files changed, 34 insertions(+), 44 deletions(-) (limited to 'fs/f2fs/data.c') diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 0b3728f58d17..ab8c8f2fff70 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -634,7 +634,7 @@ skip: goto next; out: if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) || - f2fs_is_checkpoint_ready(sbi)) + !f2fs_is_checkpoint_ready(sbi)) __submit_merged_bio(io); up_write(&io->io_rwsem); } @@ -2570,9 +2570,10 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, trace_f2fs_write_begin(inode, pos, len, flags); - err = f2fs_is_checkpoint_ready(sbi); - if (err) + if (!f2fs_is_checkpoint_ready(sbi)) { + err = -ENOSPC; goto fail; + } if ((f2fs_is_atomic_file(inode) && !f2fs_available_free_memory(sbi, INMEM_PAGES)) || diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 344e0bd638e5..6528216ab832 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -57,9 +57,11 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) err = -EIO; goto err; } - err = f2fs_is_checkpoint_ready(sbi); - if (err) + + if (!f2fs_is_checkpoint_ready(sbi)) { + err = -ENOSPC; goto err; + } sb_start_pagefault(inode->i_sb); @@ -1571,9 +1573,8 @@ static long f2fs_fallocate(struct file *file, int mode, if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) return -EIO; - ret = f2fs_is_checkpoint_ready(F2FS_I_SB(inode)); - if (ret) - return ret; + if (!f2fs_is_checkpoint_ready(F2FS_I_SB(inode))) + return -ENOSPC; /* f2fs only support ->fallocate for regular file */ if (!S_ISREG(inode->i_mode)) @@ -3146,13 +3147,10 @@ out: long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { - int ret; - if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) return -EIO; - ret = f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(filp))); - if (ret) - return ret; + if (!f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(filp)))) + return -ENOSPC; switch (cmd) { case F2FS_IOC_GETFLAGS: diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 88af85e0db62..87214414936b 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -616,7 +616,7 @@ int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc) if (!is_inode_flag_set(inode, FI_DIRTY_INODE)) return 0; - if (f2fs_is_checkpoint_ready(sbi)) + if (!f2fs_is_checkpoint_ready(sbi)) return -ENOSPC; /* diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index 9a28c5d9b3e9..4faf06e8bf89 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -272,9 +272,8 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode, if (unlikely(f2fs_cp_error(sbi))) return -EIO; - err = f2fs_is_checkpoint_ready(sbi); - if (err) - return err; + if (!f2fs_is_checkpoint_ready(sbi)) + return -ENOSPC; err = dquot_initialize(dir); if (err) @@ -321,9 +320,8 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir, if (unlikely(f2fs_cp_error(sbi))) return -EIO; - err = f2fs_is_checkpoint_ready(sbi); - if (err) - return err; + if (!f2fs_is_checkpoint_ready(sbi)) + return -ENOSPC; err = fscrypt_prepare_link(old_dentry, dir, dentry); if (err) @@ -592,9 +590,8 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, if (unlikely(f2fs_cp_error(sbi))) return -EIO; - err = f2fs_is_checkpoint_ready(sbi); - if (err) - return err; + if (!f2fs_is_checkpoint_ready(sbi)) + return -ENOSPC; err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize, &disk_link); @@ -724,9 +721,8 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry, if (unlikely(f2fs_cp_error(sbi))) return -EIO; - err = f2fs_is_checkpoint_ready(sbi); - if (err) - return err; + if (!f2fs_is_checkpoint_ready(sbi)) + return -ENOSPC; err = dquot_initialize(dir); if (err) @@ -822,13 +818,11 @@ out: static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) { struct f2fs_sb_info *sbi = F2FS_I_SB(dir); - int ret; if (unlikely(f2fs_cp_error(sbi))) return -EIO; - ret = f2fs_is_checkpoint_ready(sbi); - if (ret) - return ret; + if (!f2fs_is_checkpoint_ready(sbi)) + return -ENOSPC; if (IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) { int err = fscrypt_get_encryption_info(dir); @@ -865,9 +859,8 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, if (unlikely(f2fs_cp_error(sbi))) return -EIO; - err = f2fs_is_checkpoint_ready(sbi); - if (err) - return err; + if (!f2fs_is_checkpoint_ready(sbi)) + return -ENOSPC; if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && (!projid_eq(F2FS_I(new_dir)->i_projid, @@ -1060,9 +1053,8 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry, if (unlikely(f2fs_cp_error(sbi))) return -EIO; - err = f2fs_is_checkpoint_ready(sbi); - if (err) - return err; + if (!f2fs_is_checkpoint_ready(sbi)) + return -ENOSPC; if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) && !projid_eq(F2FS_I(new_dir)->i_projid, diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index cc230fc829e1..18584d4c078a 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -501,7 +501,7 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need) if (need && excess_cached_nats(sbi)) f2fs_balance_fs_bg(sbi); - if (f2fs_is_checkpoint_ready(sbi)) + if (!f2fs_is_checkpoint_ready(sbi)) return; /* diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index b219009c3e20..325781a1ae4d 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -586,13 +586,13 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, reserved_sections(sbi) + needed); } -static inline int f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi) +static inline bool f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi) { if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED))) - return 0; + return true; if (likely(!has_not_enough_free_secs(sbi, 0, 0))) - return 0; - return -ENOSPC; + return true; + return false; } static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi) diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index f85c810e33ca..181900af2576 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -732,9 +732,8 @@ int f2fs_setxattr(struct inode *inode, int index, const char *name, if (unlikely(f2fs_cp_error(sbi))) return -EIO; - err = f2fs_is_checkpoint_ready(sbi); - if (err) - return err; + if (!f2fs_is_checkpoint_ready(sbi)) + return -ENOSPC; err = dquot_initialize(inode); if (err) -- cgit v1.2.3 From 86f35dc39ef9cdc5d33548e2d4ddac815a39e542 Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Wed, 28 Aug 2019 17:33:35 +0800 Subject: f2fs: fix extent corrupotion during directIO in LFS mode In LFS mode, por_fsstress testcase reports a bug as below: [ASSERT] (fsck_chk_inode_blk: 931) --> ino: 0x12fe has wrong ext: [pgofs:142, blk:215424, len:16] Since commit f847c699cff3 ("f2fs: allow out-place-update for direct IO in LFS mode"), we start to allow OPU mode for direct IO, however, we missed to update extent cache in __allocate_data_block(), finally, it cause extent field being inconsistent with physical block address, fix it. Fixes: f847c699cff3 ("f2fs: allow out-place-update for direct IO in LFS mode") Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim --- fs/f2fs/data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fs/f2fs/data.c') diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index ab8c8f2fff70..7e9fafd44cbc 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1018,7 +1018,7 @@ alloc: if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) invalidate_mapping_pages(META_MAPPING(sbi), old_blkaddr, old_blkaddr); - f2fs_set_data_blkaddr(dn); + f2fs_update_data_blkaddr(dn, dn->data_blkaddr); /* * i_size will be updated by direct_IO. Otherwise, we'll get stale -- cgit v1.2.3 From 05e360061cbdcbfa93f8fcace2e7b53b2baed191 Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Wed, 28 Aug 2019 17:33:36 +0800 Subject: f2fs: fix to handle error path correctly in f2fs_map_blocks In f2fs_map_blocks(), we should bail out once __allocate_data_block() failed. Fixes: f847c699cff3 ("f2fs: allow out-place-update for direct IO in LFS mode") Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim --- fs/f2fs/data.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'fs/f2fs/data.c') diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 7e9fafd44cbc..a3e2ce5a6b22 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1195,10 +1195,10 @@ next_block: if (test_opt(sbi, LFS) && flag == F2FS_GET_BLOCK_DIO && map->m_may_create) { err = __allocate_data_block(&dn, map->m_seg_type); - if (!err) { - blkaddr = dn.data_blkaddr; - set_inode_flag(inode, FI_APPEND_WRITE); - } + if (err) + goto sync_out; + blkaddr = dn.data_blkaddr; + set_inode_flag(inode, FI_APPEND_WRITE); } } else { if (create) { -- cgit v1.2.3 From 8223ecc456d079ef9b7a1fed237134cf62e9e870 Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Wed, 28 Aug 2019 17:33:38 +0800 Subject: f2fs: fix to add missing F2FS_IO_ALIGNED() condition In f2fs_allocate_data_block(), we will reset fio.retry for IO alignment feature instead of IO serialization feature. In addition, spread F2FS_IO_ALIGNED() to check IO alignment feature status explicitly. Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim --- fs/f2fs/data.c | 6 +++++- fs/f2fs/segment.c | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'fs/f2fs/data.c') diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index a3e2ce5a6b22..adc64d514b79 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -294,6 +294,9 @@ static inline void __submit_bio(struct f2fs_sb_info *sbi, if (test_opt(sbi, LFS) && current->plug) blk_finish_plug(current->plug); + if (F2FS_IO_ALIGNED(sbi)) + goto submit_io; + start = bio->bi_iter.bi_size >> F2FS_BLKSIZE_BITS; start %= F2FS_IO_SIZE(sbi); @@ -607,7 +610,8 @@ next: __submit_merged_bio(io); alloc_new: if (io->bio == NULL) { - if ((fio->type == DATA || fio->type == NODE) && + if (F2FS_IO_ALIGNED(sbi) && + (fio->type == DATA || fio->type == NODE) && fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { dec_page_count(sbi, WB_DATA_TYPE(bio_page)); fio->retry = true; diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 204524943bc6..808709581481 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3116,12 +3116,14 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, f2fs_inode_chksum_set(sbi, page); } + if (F2FS_IO_ALIGNED(sbi)) + fio->retry = false; + if (add_list) { struct f2fs_bio_info *io; INIT_LIST_HEAD(&fio->list); fio->in_list = true; - fio->retry = false; io = sbi->write_io[fio->type] + fio->temp; spin_lock(&io->io_lock); list_add_tail(&fio->list, &io->io_list); -- cgit v1.2.3