fsck.f2fs: No need to write a new cp if nothing to flush
PATCH 2/2 fsck.f2fs: Add a judgment after calloc
In reply to Yunlei HeThis patch add a judgment after calloc avoid memory alloc failure
--- fsck/mount.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
fsck/mount.c +15 -5
@@ -777,6 +777,8 @@ int build_sit_info(struct f2fs_sb_info *sbi)SM_I (sbi)->sit_info = sit_i; sit_i->sentries =calloc (TOTAL_SEGS (sbi) *sizeof (struct seg_entry ),1 ); +if (!sit_i->sentries) +return -ENOMEM ;for (start =0 ; start <TOTAL_SEGS (sbi); start++) { sit_i->sentries[start].cur_valid_map
@@ -1022,9 +1024,11 @@ static struct f2fs_sit_block *get_current_sit_page(struct f2fs_sb_info *sbi,struct sit_info *sit_i =SIT_I (sbi);unsigned int offset =SIT_BLOCK_OFFSET (sit_i, segno);block_t blk_addr = sit_i->sit_base_addr + offset; -struct f2fs_sit_block *sit_blk =calloc (BLOCK_SZ ,1 ); +struct f2fs_sit_block *sit_blk;int ret; + sit_blk =calloc (BLOCK_SZ ,1 ); +ASSERT (sit_blk);check_seg_range (sbi, segno);/* calculate sit block address */
@@ -1189,6 +1193,7 @@ static void get_nat_entry(struct f2fs_sb_info *sbi, nid_t nid,return ; nat_block = (struct f2fs_nat_block *)calloc (BLOCK_SZ ,1 ); +ASSERT (nat_block); entry_off = nid %NAT_ENTRY_PER_BLOCK ; block_addr =current_nat_addr (sbi, nid);
@@ -1210,7 +1215,7 @@ void update_data_blkaddr(struct f2fs_sb_info *sbi, nid_t nid,int ret; node_blk = (struct f2fs_node *)calloc (BLOCK_SZ ,1 ); -ASSERT (node_blk !=NULL ); +ASSERT (node_blk);get_node_info (sbi, nid, &ni);
@@ -1260,6 +1265,7 @@ void update_nat_blkaddr(struct f2fs_sb_info *sbi, nid_t ino,int ret; nat_block = (struct f2fs_nat_block *)calloc (BLOCK_SZ ,1 ); +ASSERT (nat_block); entry_off = nid %NAT_ENTRY_PER_BLOCK ; block_addr =current_nat_addr (sbi, nid);
@@ -1357,6 +1363,7 @@ void build_sit_area_bitmap(struct f2fs_sb_info *sbi) fsck->sit_area_bitmap_sz = sm_i->main_segments *SIT_VBLOCK_MAP_SIZE ; fsck->sit_area_bitmap =calloc (1 , fsck->sit_area_bitmap_sz); +ASSERT (fsck->sit_area_bitmap); ptr = fsck->sit_area_bitmap;ASSERT (fsck->sit_area_bitmap_sz == fsck->main_area_bitmap_sz);
@@ -1490,18 +1497,21 @@ static int flush_nat_journal_entries(struct f2fs_sb_info *sbi)int ret;int i =0 ; + nat_block = (struct f2fs_nat_block *)calloc (BLOCK_SZ ,1 ); +ASSERT (nat_block); next:if (i >=nats_in_cursum (journal)) { +free (nat_block); journal->n_nats =0 ;return i; } nid =le32_to_cpu (nid_in_journal (journal, i)); - nat_block = (struct f2fs_nat_block *)calloc (BLOCK_SZ ,1 ); entry_off = nid %NAT_ENTRY_PER_BLOCK ; block_addr =current_nat_addr (sbi, nid); +memset ((void *)&nat_block,0 ,sizeof (struct f2fs_nat_block )); ret =dev_read_block (nat_block, block_addr);ASSERT (ret >=0 );
@@ -1510,7 +1520,6 @@ next: ret =dev_write_block (nat_block, block_addr);ASSERT (ret >=0 ); -free (nat_block); i++; goto next; }
@@ -1709,6 +1718,7 @@ void nullify_nat_entry(struct f2fs_sb_info *sbi, u32 nid) } } nat_block = (struct f2fs_nat_block *)calloc (BLOCK_SZ ,1 ); +ASSERT (nat_block); entry_off = nid %NAT_ENTRY_PER_BLOCK ; block_addr =current_nat_addr (sbi, nid);
@@ -1803,7 +1813,7 @@ void build_nat_area_bitmap(struct f2fs_sb_info *sbi) fsck->nr_nat_entries = nr_nat_blks *NAT_ENTRY_PER_BLOCK ; fsck->nat_area_bitmap_sz = (fsck->nr_nat_entries +7 ) /8 ; fsck->nat_area_bitmap =calloc (fsck->nat_area_bitmap_sz,1 ); -ASSERT (fsck->nat_area_bitmap !=NULL ); +ASSERT (fsck->nat_area_bitmap); fsck->entries =calloc (sizeof (struct f2fs_nat_entry ), fsck->nr_nat_entries);
Signature · 9 lines
2.10.1 ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi
PATCH 1/2 fsck.f2fs: No need to write a new cp if nothing to flush
This patch avoid to write a new cp if no journal info
--- fsck/mount.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
fsck/mount.c +10 -6
@@ -1447,7 +1447,7 @@ void rewrite_sit_area_bitmap(struct f2fs_sb_info *sbi) } } -static void flush_sit_journal_entries (struct f2fs_sb_info *sbi) +static int flush_sit_journal_entries (struct f2fs_sb_info *sbi) {struct curseg_info *curseg =CURSEG_I (sbi,CURSEG_COLD_DATA );struct f2fs_journal *journal = &curseg->sum_blk->journal;
@@ -1474,10 +1474,12 @@ static void flush_sit_journal_entries(struct f2fs_sb_info *sbi)rewrite_current_sit_page (sbi, segno, sit_blk);free (sit_blk); } + journal->n_sits =0 ; +return i; } -static void flush_nat_journal_entries (struct f2fs_sb_info *sbi) +static int flush_nat_journal_entries (struct f2fs_sb_info *sbi) {struct curseg_info *curseg =CURSEG_I (sbi,CURSEG_HOT_DATA );struct f2fs_journal *journal = &curseg->sum_blk->journal;
@@ -1491,7 +1493,7 @@ static void flush_nat_journal_entries(struct f2fs_sb_info *sbi) next:if (i >=nats_in_cursum (journal)) { journal->n_nats =0 ; -return ; +return i; } nid =le32_to_cpu (nid_in_journal (journal, i));
@@ -1515,9 +1517,11 @@ next:void flush_journal_entries (struct f2fs_sb_info *sbi) { -flush_nat_journal_entries (sbi); -flush_sit_journal_entries (sbi); -write_checkpoint (sbi); +int n_nats =flush_nat_journal_entries (sbi); +int n_sits =flush_sit_journal_entries (sbi); + +if (n_nats || n_sits) +write_checkpoint (sbi); }void flush_sit_entries (struct f2fs_sb_info *sbi)
Signature · 9 lines
2.10.1 ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi
Re: [PATCH 2/2] fsck.f2fs: Add a judgment after calloc
In reply to Yunlei HeHi Yunlei,
Quoted 77 lines · Yunlei He
This patch add a judgment after calloc avoid memory alloc failure
Signed-off-by Yunlei He <[email protected]>--- fsck/mount.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)fsck/mount.c +12
-2@@ -777,6 +777,8 @@ int build_sit_info(struct f2fs_sb_info *sbi)SM_I (sbi)->sit_info = sit_i; sit_i->sentries =calloc (TOTAL_SEGS (sbi) *sizeof (struct seg_entry ),1 ); +if (!sit_i->sentries) +return -ENOMEM ;for (start =0 ; start <TOTAL_SEGS (sbi); start++) { sit_i->sentries[start].cur_valid_map@@ -1022,9 +1024,11 @@ static struct f2fs_sit_block *get_current_sit_page(struct f2fs_sb_info *sbi,struct sit_info *sit_i =SIT_I (sbi);unsigned int offset =SIT_BLOCK_OFFSET (sit_i, segno);block_t blk_addr = sit_i->sit_base_addr + offset; -struct f2fs_sit_block *sit_blk =calloc (BLOCK_SZ ,1 ); +struct f2fs_sit_block *sit_blk;int ret; + sit_blk =calloc (BLOCK_SZ ,1 ); +ASSERT (sit_blk);check_seg_range (sbi, segno);/* calculate sit block address */ @@ -1189,6 +1193,7 @@ static void get_nat_entry(struct f2fs_sb_info *sbi, nid_t nid,return ; nat_block = (struct f2fs_nat_block *)calloc (BLOCK_SZ ,1 ); +ASSERT (nat_block); entry_off = nid %NAT_ENTRY_PER_BLOCK ; block_addr =current_nat_addr (sbi, nid);@@ -1210,7 +1215,7 @@ void update_data_blkaddr(struct f2fs_sb_info *sbi, nid_t nid,int ret; node_blk = (struct f2fs_node *)calloc (BLOCK_SZ ,1 ); -ASSERT (node_blk !=NULL ); +ASSERT (node_blk);get_node_info (sbi, nid, &ni);@@ -1260,6 +1265,7 @@ void update_nat_blkaddr(struct f2fs_sb_info *sbi, nid_t ino,int ret; nat_block = (struct f2fs_nat_block *)calloc (BLOCK_SZ ,1 ); +ASSERT (nat_block); entry_off = nid %NAT_ENTRY_PER_BLOCK ; block_addr =current_nat_addr (sbi, nid);@@ -1357,6 +1363,7 @@ void build_sit_area_bitmap(struct f2fs_sb_info *sbi) fsck->sit_area_bitmap_sz = sm_i->main_segments *SIT_VBLOCK_MAP_SIZE ; fsck->sit_area_bitmap =calloc (1 , fsck->sit_area_bitmap_sz); +ASSERT (fsck->sit_area_bitmap); ptr = fsck->sit_area_bitmap;ASSERT (fsck->sit_area_bitmap_sz == fsck->main_area_bitmap_sz);@@ -1490,18 +1497,21 @@ static int flush_nat_journal_entries(struct f2fs_sb_info *sbi)int ret;int i =0 ; + nat_block = (struct f2fs_nat_block *)calloc (BLOCK_SZ ,1 ); +ASSERT (nat_block); next:if (i >=nats_in_cursum (journal)) { +free (nat_block); journal->n_nats =0 ;
fsck/mount.c static int flush_nat_journal_entries(struct f2fs_sb_info *sbi) · line 1514
Quoted 10 lines
fsck/mount.c +1
-1return i; } nid =le32_to_cpu (nid_in_journal (journal, i)); - nat_block = (struct f2fs_nat_block *)calloc (BLOCK_SZ ,1 ); entry_off = nid %NAT_ENTRY_PER_BLOCK ; block_addr =current_nat_addr (sbi, nid); +memset ((void *)&nat_block,0 ,sizeof (struct f2fs_nat_block ));
I removed the above line and merged the modified patch due to:
/usr/include/x86_64-linux-gnu/bits/string3.h:84:3: warning: call to __builtin___memset_chk will always overflow destination buffer [enabled by default]
return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
^Thanks,
Quoted 42 lines
fsck/mount.c +2
-2ret =dev_read_block (nat_block, block_addr);ASSERT (ret >=0 );@@ -1510,7 +1520,6 @@ next: ret =dev_write_block (nat_block, block_addr);ASSERT (ret >=0 ); -free (nat_block); i++; goto next; }@@ -1709,6 +1718,7 @@ void nullify_nat_entry(struct f2fs_sb_info *sbi, u32 nid) } } nat_block = (struct f2fs_nat_block *)calloc (BLOCK_SZ ,1 ); +ASSERT (nat_block); entry_off = nid %NAT_ENTRY_PER_BLOCK ; block_addr =current_nat_addr (sbi, nid);@@ -1803,7 +1813,7 @@ void build_nat_area_bitmap(struct f2fs_sb_info *sbi) fsck->nr_nat_entries = nr_nat_blks *NAT_ENTRY_PER_BLOCK ; fsck->nat_area_bitmap_sz = (fsck->nr_nat_entries +7 ) /8 ; fsck->nat_area_bitmap =calloc (fsck->nat_area_bitmap_sz,1 ); -ASSERT (fsck->nat_area_bitmap !=NULL ); +ASSERT (fsck->nat_area_bitmap); fsck->entries =calloc (sizeof (struct f2fs_nat_entry ), fsck->nr_nat_entries);Signature · 13 lines
2.10.1 ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi