* [PATCH 1/2] fsck.f2fs: No need to write a new cp if nothing to flush
@ 2016-11-04 9:34 Yunlei He
2016-11-04 9:34 ` [PATCH 2/2] fsck.f2fs: Add a judgment after calloc Yunlei He
0 siblings, 1 reply; 3+ messages in thread
From: Yunlei He @ 2016-11-04 9:34 UTC (permalink / raw)
To: linux-f2fs-devel, jaegeuk, yuchao0; +Cc: heyunlei
This patch avoid to write a new cp if no journal info
Signed-off-by: Yunlei He <heyunlei@huawei.com>
---
fsck/mount.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/fsck/mount.c b/fsck/mount.c
index dd7a081..f2055e4 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -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)
--
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] fsck.f2fs: Add a judgment after calloc
2016-11-04 9:34 [PATCH 1/2] fsck.f2fs: No need to write a new cp if nothing to flush Yunlei He
@ 2016-11-04 9:34 ` Yunlei He
2016-11-04 23:07 ` Jaegeuk Kim
0 siblings, 1 reply; 3+ messages in thread
From: Yunlei He @ 2016-11-04 9:34 UTC (permalink / raw)
To: linux-f2fs-devel, jaegeuk, yuchao0; +Cc: heyunlei
This patch add a judgment after calloc avoid memory alloc
failure
Signed-off-by: Yunlei He <heyunlei@huawei.com>
---
fsck/mount.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/fsck/mount.c b/fsck/mount.c
index f2055e4..e4adb0e 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -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);
--
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] fsck.f2fs: Add a judgment after calloc
2016-11-04 9:34 ` [PATCH 2/2] fsck.f2fs: Add a judgment after calloc Yunlei He
@ 2016-11-04 23:07 ` Jaegeuk Kim
0 siblings, 0 replies; 3+ messages in thread
From: Jaegeuk Kim @ 2016-11-04 23:07 UTC (permalink / raw)
To: Yunlei He; +Cc: heyunlei, linux-f2fs-devel
Hi Yunlei,
On Fri, Nov 04, 2016 at 05:34:11PM +0800, Yunlei He wrote:
> This patch add a judgment after calloc avoid memory alloc
> failure
>
> Signed-off-by: Yunlei He <heyunlei@huawei.com>
> ---
> fsck/mount.c | 20 +++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/fsck/mount.c b/fsck/mount.c
> index f2055e4..e4adb0e 100644
> --- a/fsck/mount.c
> +++ b/fsck/mount.c
> @@ -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));
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,
> 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);
> --
> 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
> Linux-f2fs-devel@lists.sourceforge.net
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-11-04 23:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-04 9:34 [PATCH 1/2] fsck.f2fs: No need to write a new cp if nothing to flush Yunlei He
2016-11-04 9:34 ` [PATCH 2/2] fsck.f2fs: Add a judgment after calloc Yunlei He
2016-11-04 23:07 ` Jaegeuk Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).