f2fs: fix extent corrupotion during directIO in LFS mode
PATCH 1/4 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.
--- fs/f2fs/data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/data.c +1 -1
@@ -1018,7 +1018,7 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)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
Signature · 1 line
2.18.0.rc1
PATCH 2/4 f2fs: fix to handle error path correctly in f2fs_map_blocks
In f2fs_map_blocks(), we should bail out once __allocate_data_block() failed.
--- fs/f2fs/data.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/f2fs/data.c +4 -4
@@ -1195,10 +1195,10 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,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) {
Signature · 8 lines
2.18.0.rc1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 3/4 f2fs: fix to fallback to buffered IO in IO aligned mode
In reply to Chao YuIn LFS mode, we allow OPU for direct IO, however, we didn't consider IO alignment feature, so direct IO can trigger unaligned IO, let's just fallback to buffered IO to keep correct IO alignment semantics in all places.
--- fs/f2fs/f2fs.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/f2fs/f2fs.h +6 -3
@@ -3733,9 +3733,12 @@ static inline bool f2fs_force_buffered_io(struct inode *inode,*/ if (f2fs_sb_has_blkzoned (sbi))return true; -if (test_opt (sbi,LFS ) && (rw ==WRITE ) && -block_unaligned_IO (inode, iocb, iter)) -return true; +if (test_opt (sbi,LFS ) && (rw ==WRITE )) { +if (block_unaligned_IO (inode, iocb, iter)) +return true; +if (F2FS_IO_ALIGNED (sbi)) +return true; + }if (is_sbi_flag_set (F2FS_I_SB (inode),SBI_CP_DISABLED ) && !IS_SWAPFILE (inode))return true;
Signature · 1 line
2.18.0.rc1
PATCH 4/4 f2fs: fix to add missing F2FS_IO_ALIGNED() condition
In reply to Chao YuIn 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.
--- fs/f2fs/data.c | 6 +++++- fs/f2fs/segment.c | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-)
fs/f2fs/data.c +5 -1
@@ -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 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)__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;
fs/f2fs/segment.c +3 -1
@@ -3129,12 +3129,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);
Signature · 1 line
2.18.0.rc1