Skip to content

Commit 70c8038

Browse files
committed
Merge tag 'for-f2fs-3.17-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
Pull f2fs bug fixes from Jaegeuk Kim: "This series includes patches to: - fix recovery routines - fix bugs related to inline_data/xattr - fix when casting the dentry names - handle EIO or ENOMEM correctly - fix memory leak - fix lock coverage" * tag 'for-f2fs-3.17-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (28 commits) f2fs: reposition unlock_new_inode to prevent accessing invalid inode f2fs: fix wrong casting for dentry name f2fs: simplify by using a literal f2fs: truncate stale block for inline_data f2fs: use macro for code readability f2fs: introduce need_do_checkpoint for readability f2fs: fix incorrect calculation with total/free inode num f2fs: remove rename and use rename2 f2fs: skip if inline_data was converted already f2fs: remove rewrite_node_page f2fs: avoid double lock in truncate_blocks f2fs: prevent checkpoint during roll-forward f2fs: add WARN_ON in f2fs_bug_on f2fs: handle EIO not to break fs consistency f2fs: check s_dirty under cp_mutex f2fs: unlock_page when node page is redirtied out f2fs: introduce f2fs_cp_error for readability f2fs: give a chance to mount again when encountering errors f2fs: trigger release_dirty_inode in f2fs_put_super f2fs: don't skip checkpoint if there is no dirty node pages ...
2 parents 5a147c9 + b73e528 commit 70c8038

19 files changed

Lines changed: 261 additions & 231 deletions

File tree

‎fs/f2fs/Kconfig‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ config F2FS_STAT_FS
2323
mounted as f2fs. Each file shows the whole f2fs information.
2424

2525
/sys/kernel/debug/f2fs/status includes:
26-
- major file system information managed by f2fs currently
26+
- major filesystem information managed by f2fs currently
2727
- average SIT information about whole segments
2828
- current memory footprint consumed by f2fs.
2929

@@ -68,6 +68,6 @@ config F2FS_CHECK_FS
6868
bool "F2FS consistency checking feature"
6969
depends on F2FS_FS
7070
help
71-
Enables BUG_ONs which check the file system consistency in runtime.
71+
Enables BUG_ONs which check the filesystem consistency in runtime.
7272

7373
If you want to improve the performance, say N.

‎fs/f2fs/checkpoint.c‎

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,11 @@ static int f2fs_write_meta_page(struct page *page,
160160
goto redirty_out;
161161
if (wbc->for_reclaim)
162162
goto redirty_out;
163-
164-
/* Should not write any meta pages, if any IO error was occurred */
165-
if (unlikely(is_set_ckpt_flags(F2FS_CKPT(sbi), CP_ERROR_FLAG)))
166-
goto no_write;
163+
if (unlikely(f2fs_cp_error(sbi)))
164+
goto redirty_out;
167165

168166
f2fs_wait_on_page_writeback(page, META);
169167
write_meta_page(sbi, page);
170-
no_write:
171168
dec_page_count(sbi, F2FS_DIRTY_META);
172169
unlock_page(page);
173170
return 0;
@@ -348,7 +345,7 @@ bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode)
348345
return e ? true : false;
349346
}
350347

351-
static void release_dirty_inode(struct f2fs_sb_info *sbi)
348+
void release_dirty_inode(struct f2fs_sb_info *sbi)
352349
{
353350
struct ino_entry *e, *tmp;
354351
int i;
@@ -446,8 +443,8 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
446443
struct f2fs_orphan_block *orphan_blk = NULL;
447444
unsigned int nentries = 0;
448445
unsigned short index;
449-
unsigned short orphan_blocks = (unsigned short)((sbi->n_orphans +
450-
(F2FS_ORPHANS_PER_BLOCK - 1)) / F2FS_ORPHANS_PER_BLOCK);
446+
unsigned short orphan_blocks =
447+
(unsigned short)GET_ORPHAN_BLOCKS(sbi->n_orphans);
451448
struct page *page = NULL;
452449
struct ino_entry *orphan = NULL;
453450

@@ -737,14 +734,15 @@ void sync_dirty_dir_inodes(struct f2fs_sb_info *sbi)
737734
/*
738735
* Freeze all the FS-operations for checkpoint.
739736
*/
740-
static void block_operations(struct f2fs_sb_info *sbi)
737+
static int block_operations(struct f2fs_sb_info *sbi)
741738
{
742739
struct writeback_control wbc = {
743740
.sync_mode = WB_SYNC_ALL,
744741
.nr_to_write = LONG_MAX,
745742
.for_reclaim = 0,
746743
};
747744
struct blk_plug plug;
745+
int err = 0;
748746

749747
blk_start_plug(&plug);
750748

@@ -754,11 +752,15 @@ static void block_operations(struct f2fs_sb_info *sbi)
754752
if (get_pages(sbi, F2FS_DIRTY_DENTS)) {
755753
f2fs_unlock_all(sbi);
756754
sync_dirty_dir_inodes(sbi);
755+
if (unlikely(f2fs_cp_error(sbi))) {
756+
err = -EIO;
757+
goto out;
758+
}
757759
goto retry_flush_dents;
758760
}
759761

760762
/*
761-
* POR: we should ensure that there is no dirty node pages
763+
* POR: we should ensure that there are no dirty node pages
762764
* until finishing nat/sit flush.
763765
*/
764766
retry_flush_nodes:
@@ -767,9 +769,16 @@ static void block_operations(struct f2fs_sb_info *sbi)
767769
if (get_pages(sbi, F2FS_DIRTY_NODES)) {
768770
up_write(&sbi->node_write);
769771
sync_node_pages(sbi, 0, &wbc);
772+
if (unlikely(f2fs_cp_error(sbi))) {
773+
f2fs_unlock_all(sbi);
774+
err = -EIO;
775+
goto out;
776+
}
770777
goto retry_flush_nodes;
771778
}
779+
out:
772780
blk_finish_plug(&plug);
781+
return err;
773782
}
774783

775784
static void unblock_operations(struct f2fs_sb_info *sbi)
@@ -813,8 +822,11 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
813822
discard_next_dnode(sbi, NEXT_FREE_BLKADDR(sbi, curseg));
814823

815824
/* Flush all the NAT/SIT pages */
816-
while (get_pages(sbi, F2FS_DIRTY_META))
825+
while (get_pages(sbi, F2FS_DIRTY_META)) {
817826
sync_meta_pages(sbi, META, LONG_MAX);
827+
if (unlikely(f2fs_cp_error(sbi)))
828+
return;
829+
}
818830

819831
next_free_nid(sbi, &last_nid);
820832

@@ -825,15 +837,15 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
825837
ckpt->elapsed_time = cpu_to_le64(get_mtime(sbi));
826838
ckpt->valid_block_count = cpu_to_le64(valid_user_blocks(sbi));
827839
ckpt->free_segment_count = cpu_to_le32(free_segments(sbi));
828-
for (i = 0; i < 3; i++) {
840+
for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) {
829841
ckpt->cur_node_segno[i] =
830842
cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_NODE));
831843
ckpt->cur_node_blkoff[i] =
832844
cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_NODE));
833845
ckpt->alloc_type[i + CURSEG_HOT_NODE] =
834846
curseg_alloc_type(sbi, i + CURSEG_HOT_NODE);
835847
}
836-
for (i = 0; i < 3; i++) {
848+
for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
837849
ckpt->cur_data_segno[i] =
838850
cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_DATA));
839851
ckpt->cur_data_blkoff[i] =
@@ -848,24 +860,23 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
848860

849861
/* 2 cp + n data seg summary + orphan inode blocks */
850862
data_sum_blocks = npages_for_summary_flush(sbi);
851-
if (data_sum_blocks < 3)
863+
if (data_sum_blocks < NR_CURSEG_DATA_TYPE)
852864
set_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG);
853865
else
854866
clear_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG);
855867

856-
orphan_blocks = (sbi->n_orphans + F2FS_ORPHANS_PER_BLOCK - 1)
857-
/ F2FS_ORPHANS_PER_BLOCK;
868+
orphan_blocks = GET_ORPHAN_BLOCKS(sbi->n_orphans);
858869
ckpt->cp_pack_start_sum = cpu_to_le32(1 + cp_payload_blks +
859870
orphan_blocks);
860871

861872
if (is_umount) {
862873
set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
863-
ckpt->cp_pack_total_block_count = cpu_to_le32(2 +
874+
ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS+
864875
cp_payload_blks + data_sum_blocks +
865876
orphan_blocks + NR_CURSEG_NODE_TYPE);
866877
} else {
867878
clear_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
868-
ckpt->cp_pack_total_block_count = cpu_to_le32(2 +
879+
ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS +
869880
cp_payload_blks + data_sum_blocks +
870881
orphan_blocks);
871882
}
@@ -924,6 +935,9 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
924935
/* wait for previous submitted node/meta pages writeback */
925936
wait_on_all_pages_writeback(sbi);
926937

938+
if (unlikely(f2fs_cp_error(sbi)))
939+
return;
940+
927941
filemap_fdatawait_range(NODE_MAPPING(sbi), 0, LONG_MAX);
928942
filemap_fdatawait_range(META_MAPPING(sbi), 0, LONG_MAX);
929943

@@ -934,15 +948,17 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
934948
/* Here, we only have one bio having CP pack */
935949
sync_meta_pages(sbi, META_FLUSH, LONG_MAX);
936950

937-
if (!is_set_ckpt_flags(ckpt, CP_ERROR_FLAG)) {
938-
clear_prefree_segments(sbi);
939-
release_dirty_inode(sbi);
940-
F2FS_RESET_SB_DIRT(sbi);
941-
}
951+
release_dirty_inode(sbi);
952+
953+
if (unlikely(f2fs_cp_error(sbi)))
954+
return;
955+
956+
clear_prefree_segments(sbi);
957+
F2FS_RESET_SB_DIRT(sbi);
942958
}
943959

944960
/*
945-
* We guarantee that this checkpoint procedure should not fail.
961+
* We guarantee that this checkpoint procedure will not fail.
946962
*/
947963
void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
948964
{
@@ -952,7 +968,13 @@ void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
952968
trace_f2fs_write_checkpoint(sbi->sb, is_umount, "start block_ops");
953969

954970
mutex_lock(&sbi->cp_mutex);
955-
block_operations(sbi);
971+
972+
if (!sbi->s_dirty)
973+
goto out;
974+
if (unlikely(f2fs_cp_error(sbi)))
975+
goto out;
976+
if (block_operations(sbi))
977+
goto out;
956978

957979
trace_f2fs_write_checkpoint(sbi->sb, is_umount, "finish block_ops");
958980

@@ -976,9 +998,9 @@ void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
976998
do_checkpoint(sbi, is_umount);
977999

9781000
unblock_operations(sbi);
979-
mutex_unlock(&sbi->cp_mutex);
980-
9811001
stat_inc_cp_count(sbi->stat_info);
1002+
out:
1003+
mutex_unlock(&sbi->cp_mutex);
9821004
trace_f2fs_write_checkpoint(sbi->sb, is_umount, "finish checkpoint");
9831005
}
9841006

@@ -999,8 +1021,8 @@ void init_ino_entry_info(struct f2fs_sb_info *sbi)
9991021
* for cp pack we can have max 1020*504 orphan entries
10001022
*/
10011023
sbi->n_orphans = 0;
1002-
sbi->max_orphans = (sbi->blocks_per_seg - 2 - NR_CURSEG_TYPE)
1003-
* F2FS_ORPHANS_PER_BLOCK;
1024+
sbi->max_orphans = (sbi->blocks_per_seg - F2FS_CP_PACKS -
1025+
NR_CURSEG_TYPE) * F2FS_ORPHANS_PER_BLOCK;
10041026
}
10051027

10061028
int __init create_checkpoint_caches(void)

‎fs/f2fs/data.c‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void f2fs_write_end_io(struct bio *bio, int err)
5353
struct page *page = bvec->bv_page;
5454

5555
if (unlikely(err)) {
56-
SetPageError(page);
56+
set_page_dirty(page);
5757
set_bit(AS_EIO, &page->mapping->flags);
5858
f2fs_stop_checkpoint(sbi);
5959
}
@@ -691,7 +691,7 @@ static int __get_data_block(struct inode *inode, sector_t iblock,
691691
allocated = true;
692692
blkaddr = dn.data_blkaddr;
693693
}
694-
/* Give more consecutive addresses for the read ahead */
694+
/* Give more consecutive addresses for the readahead */
695695
if (blkaddr == (bh_result->b_blocknr + ofs)) {
696696
ofs++;
697697
dn.ofs_in_node++;
@@ -739,7 +739,7 @@ static int f2fs_read_data_page(struct file *file, struct page *page)
739739

740740
trace_f2fs_readpage(page, DATA);
741741

742-
/* If the file has inline data, try to read it directlly */
742+
/* If the file has inline data, try to read it directly */
743743
if (f2fs_has_inline_data(inode))
744744
ret = f2fs_read_inline_data(inode, page);
745745
else
@@ -836,10 +836,19 @@ static int f2fs_write_data_page(struct page *page,
836836

837837
/* Dentry blocks are controlled by checkpoint */
838838
if (S_ISDIR(inode->i_mode)) {
839+
if (unlikely(f2fs_cp_error(sbi)))
840+
goto redirty_out;
839841
err = do_write_data_page(page, &fio);
840842
goto done;
841843
}
842844

845+
/* we should bypass data pages to proceed the kworkder jobs */
846+
if (unlikely(f2fs_cp_error(sbi))) {
847+
SetPageError(page);
848+
unlock_page(page);
849+
return 0;
850+
}
851+
843852
if (!wbc->for_reclaim)
844853
need_balance_fs = true;
845854
else if (has_not_enough_free_secs(sbi, 0))
@@ -927,7 +936,7 @@ static void f2fs_write_failed(struct address_space *mapping, loff_t to)
927936

928937
if (to > inode->i_size) {
929938
truncate_pagecache(inode, inode->i_size);
930-
truncate_blocks(inode, inode->i_size);
939+
truncate_blocks(inode, inode->i_size, true);
931940
}
932941
}
933942

@@ -946,7 +955,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
946955

947956
f2fs_balance_fs(sbi);
948957
repeat:
949-
err = f2fs_convert_inline_data(inode, pos + len);
958+
err = f2fs_convert_inline_data(inode, pos + len, NULL);
950959
if (err)
951960
goto fail;
952961

‎fs/f2fs/debug.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void update_general_status(struct f2fs_sb_info *sbi)
3232
struct f2fs_stat_info *si = F2FS_STAT(sbi);
3333
int i;
3434

35-
/* valid check of the segment numbers */
35+
/* validation check of the segment numbers */
3636
si->hit_ext = sbi->read_hit_ext;
3737
si->total_ext = sbi->total_hit_ext;
3838
si->ndirty_node = get_pages(sbi, F2FS_DIRTY_NODES);
@@ -152,7 +152,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
152152
si->base_mem += NR_DIRTY_TYPE * f2fs_bitmap_size(TOTAL_SEGS(sbi));
153153
si->base_mem += f2fs_bitmap_size(TOTAL_SECS(sbi));
154154

155-
/* buld nm */
155+
/* build nm */
156156
si->base_mem += sizeof(struct f2fs_nm_info);
157157
si->base_mem += __bitmap_size(sbi, NAT_BITMAP);
158158

‎fs/f2fs/dir.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static struct f2fs_dir_entry *find_in_block(struct page *dentry_page,
124124

125125
/*
126126
* For the most part, it should be a bug when name_len is zero.
127-
* We stop here for figuring out where the bugs are occurred.
127+
* We stop here for figuring out where the bugs has occurred.
128128
*/
129129
f2fs_bug_on(!de->name_len);
130130

@@ -391,7 +391,7 @@ static struct page *init_inode_metadata(struct inode *inode,
391391
error:
392392
/* once the failed inode becomes a bad inode, i_mode is S_IFREG */
393393
truncate_inode_pages(&inode->i_data, 0);
394-
truncate_blocks(inode, 0);
394+
truncate_blocks(inode, 0, false);
395395
remove_dirty_dir_inode(inode);
396396
remove_inode_page(inode);
397397
return ERR_PTR(err);
@@ -563,7 +563,7 @@ int f2fs_do_tmpfile(struct inode *inode, struct inode *dir)
563563
}
564564

565565
/*
566-
* It only removes the dentry from the dentry page,corresponding name
566+
* It only removes the dentry from the dentry page, corresponding name
567567
* entry in name page does not need to be touched during deletion.
568568
*/
569569
void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,

0 commit comments

Comments
 (0)