* [PATCH 3/5] f2fs: check in-memory block bitmap
@ 2017-01-07 10:51 Chao Yu
2017-01-08 5:02 ` [f2fs-dev] " Jaegeuk Kim
0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2017-01-07 10:51 UTC (permalink / raw)
To: Jaegeuk Kim; +Cc: linux-f2fs-devel, linux-kernel, Chao Yu
This patch adds a mirror for valid block bitmap, and use it to detect
in-memory bitmap corruption which may be caused by bit-transition of
cache or memory overflow.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
fs/f2fs/segment.c | 30 ++++++++++++++++++++++++++++--
fs/f2fs/segment.h | 6 ++++++
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index fa8c0ae87d47..ec21ee1c61cd 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1026,14 +1026,32 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
/* Update valid block bitmap */
if (del > 0) {
- if (f2fs_test_and_set_bit(offset, se->cur_valid_map))
+ if (f2fs_test_and_set_bit(offset, se->cur_valid_map)) {
+#ifdef CONFIG_F2FS_CHECK_FS
+ if (f2fs_test_and_set_bit(offset,
+ se->cur_valid_map_mir))
+ f2fs_bug_on(sbi, 1);
+ else
+ WARN_ON(1);
+#else
f2fs_bug_on(sbi, 1);
+#endif
+ }
if (f2fs_discard_en(sbi) &&
!f2fs_test_and_set_bit(offset, se->discard_map))
sbi->discard_blks--;
} else {
- if (!f2fs_test_and_clear_bit(offset, se->cur_valid_map))
+ if (!f2fs_test_and_clear_bit(offset, se->cur_valid_map)) {
+#ifdef CONFIG_F2FS_CHECK_FS
+ if (!f2fs_test_and_clear_bit(offset,
+ se->cur_valid_map_mir))
+ f2fs_bug_on(sbi, 1);
+ else
+ WARN_ON(1);
+#else
f2fs_bug_on(sbi, 1);
+#endif
+ }
if (f2fs_discard_en(sbi) &&
f2fs_test_and_clear_bit(offset, se->discard_map))
sbi->discard_blks++;
@@ -2357,6 +2375,13 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
!sit_i->sentries[start].ckpt_valid_map)
return -ENOMEM;
+#ifdef CONFIG_F2FS_CHECK_FS
+ sit_i->sentries[start].cur_valid_map_mir
+ = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
+ if (!sit_i->sentries[start].cur_valid_map_mir)
+ return -ENOMEM;
+#endif
+
if (f2fs_discard_en(sbi)) {
sit_i->sentries[start].discard_map
= kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
@@ -2786,6 +2811,7 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi)
if (sit_i->sentries) {
for (start = 0; start < MAIN_SEGS(sbi); start++) {
kfree(sit_i->sentries[start].cur_valid_map);
+ kfree(sit_i->sentries[start].cur_valid_map_mir);
kfree(sit_i->sentries[start].ckpt_valid_map);
kfree(sit_i->sentries[start].discard_map);
}
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 08f1455c812c..9af95194db06 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -164,6 +164,9 @@ struct seg_entry {
unsigned int ckpt_valid_blocks:10; /* # of valid blocks last cp */
unsigned int padding:6; /* padding */
unsigned char *cur_valid_map; /* validity bitmap of blocks */
+#ifdef CONFIG_F2FS_CHECK_FS
+ unsigned char *cur_valid_map_mir; /* mirror of current valid bitmap */
+#endif
/*
* # of valid blocks and the validity bitmap stored in the the last
* checkpoint pack. This information is used by the SSR mode.
@@ -320,6 +323,9 @@ static inline void seg_info_from_raw_sit(struct seg_entry *se,
se->ckpt_valid_blocks = GET_SIT_VBLOCKS(rs);
memcpy(se->cur_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE);
memcpy(se->ckpt_valid_map, rs->valid_map, SIT_VBLOCK_MAP_SIZE);
+#ifdef CONFIG_F2FS_CHECK_FS
+ memcpy(se->cur_valid_map_mir, rs->valid_map, SIT_VBLOCK_MAP_SIZE);
+#endif
se->type = GET_SIT_TYPE(rs);
se->mtime = le64_to_cpu(rs->mtime);
}
--
2.8.2.295.g3f1c1d0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [f2fs-dev] [PATCH 3/5] f2fs: check in-memory block bitmap
2017-01-07 10:51 [PATCH 3/5] f2fs: check in-memory block bitmap Chao Yu
@ 2017-01-08 5:02 ` Jaegeuk Kim
2017-01-09 8:42 ` Chao Yu
0 siblings, 1 reply; 3+ messages in thread
From: Jaegeuk Kim @ 2017-01-08 5:02 UTC (permalink / raw)
To: Chao Yu; +Cc: Chao Yu, linux-kernel, linux-f2fs-devel
Hi Chao,
On 01/07, Chao Yu wrote:
> This patch adds a mirror for valid block bitmap, and use it to detect
> in-memory bitmap corruption which may be caused by bit-transition of
> cache or memory overflow.
>
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
> fs/f2fs/segment.c | 30 ++++++++++++++++++++++++++++--
> fs/f2fs/segment.h | 6 ++++++
> 2 files changed, 34 insertions(+), 2 deletions(-)
>
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index fa8c0ae87d47..ec21ee1c61cd 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -1026,14 +1026,32 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
>
> /* Update valid block bitmap */
> if (del > 0) {
> - if (f2fs_test_and_set_bit(offset, se->cur_valid_map))
> + if (f2fs_test_and_set_bit(offset, se->cur_valid_map)) {
> +#ifdef CONFIG_F2FS_CHECK_FS
> + if (f2fs_test_and_set_bit(offset,
> + se->cur_valid_map_mir))
> + f2fs_bug_on(sbi, 1);
> + else
> + WARN_ON(1);
> +#else
> f2fs_bug_on(sbi, 1);
> +#endif
> + }
> if (f2fs_discard_en(sbi) &&
> !f2fs_test_and_set_bit(offset, se->discard_map))
> sbi->discard_blks--;
> } else {
> - if (!f2fs_test_and_clear_bit(offset, se->cur_valid_map))
> + if (!f2fs_test_and_clear_bit(offset, se->cur_valid_map)) {
> +#ifdef CONFIG_F2FS_CHECK_FS
> + if (!f2fs_test_and_clear_bit(offset,
> + se->cur_valid_map_mir))
> + f2fs_bug_on(sbi, 1);
> + else
> + WARN_ON(1);
> +#else
> f2fs_bug_on(sbi, 1);
> +#endif
> + }
> if (f2fs_discard_en(sbi) &&
> f2fs_test_and_clear_bit(offset, se->discard_map))
> sbi->discard_blks++;
> @@ -2357,6 +2375,13 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
> !sit_i->sentries[start].ckpt_valid_map)
> return -ENOMEM;
>
> +#ifdef CONFIG_F2FS_CHECK_FS
> + sit_i->sentries[start].cur_valid_map_mir
> + = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
> + if (!sit_i->sentries[start].cur_valid_map_mir)
> + return -ENOMEM;
> +#endif
> +
> if (f2fs_discard_en(sbi)) {
> sit_i->sentries[start].discard_map
> = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
> @@ -2786,6 +2811,7 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi)
> if (sit_i->sentries) {
> for (start = 0; start < MAIN_SEGS(sbi); start++) {
> kfree(sit_i->sentries[start].cur_valid_map);
I added:
#ifdef CONFIG_F2FS_CHECK_FS
> + kfree(sit_i->sentries[start].cur_valid_map_mir);
#endif
Thanks,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [f2fs-dev] [PATCH 3/5] f2fs: check in-memory block bitmap
2017-01-08 5:02 ` [f2fs-dev] " Jaegeuk Kim
@ 2017-01-09 8:42 ` Chao Yu
0 siblings, 0 replies; 3+ messages in thread
From: Chao Yu @ 2017-01-09 8:42 UTC (permalink / raw)
To: Jaegeuk Kim; +Cc: Chao Yu, linux-kernel, linux-f2fs-devel
Hi Jaegeuk,
On 2017/1/8 13:02, Jaegeuk Kim wrote:
>> @@ -2786,6 +2811,7 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi)
>> if (sit_i->sentries) {
>> for (start = 0; start < MAIN_SEGS(sbi); start++) {
>> kfree(sit_i->sentries[start].cur_valid_map);
>
> I added:
>
> #ifdef CONFIG_F2FS_CHECK_FS
Oops, thanks for fixing it. :)
Thanks,
>
>> + kfree(sit_i->sentries[start].cur_valid_map_mir);
>
> #endif
>
> Thanks,
>
> .
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-01-09 8:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-07 10:51 [PATCH 3/5] f2fs: check in-memory block bitmap Chao Yu
2017-01-08 5:02 ` [f2fs-dev] " Jaegeuk Kim
2017-01-09 8:42 ` Chao Yu
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).