* [PATCH] f2fs-tools: introduce get_checkpoint_version() for cleanup
@ 2019-06-13 8:09 ` Chao Yu
0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2019-06-13 8:09 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: jaegeuk
Just cleanup, no logic change.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
fsck/mount.c | 42 ++++++++++++++++++++++++------------------
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/fsck/mount.c b/fsck/mount.c
index aecd0cd..8d5d5cf 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -780,6 +780,24 @@ static int verify_checksum_chksum(struct f2fs_checkpoint *cp)
return 0;
}
+static void *get_checkpoint_version(block_t cp_addr)
+{
+ void *cp_page;
+
+ cp_page = malloc(PAGE_SIZE);
+ ASSERT(cp_page);
+
+ if (dev_read_block(cp_page, cp_addr) < 0)
+ ASSERT(0);
+
+ if (verify_checksum_chksum((struct f2fs_checkpoint *)cp_page))
+ goto out;
+ return cp_page;
+out:
+ free(cp_page);
+ return NULL;
+}
+
void *validate_checkpoint(struct f2fs_sb_info *sbi, block_t cp_addr,
unsigned long long *version)
{
@@ -788,34 +806,23 @@ void *validate_checkpoint(struct f2fs_sb_info *sbi, block_t cp_addr,
unsigned long long cur_version = 0, pre_version = 0;
/* Read the 1st cp block in this CP pack */
- cp_page_1 = malloc(PAGE_SIZE);
- ASSERT(cp_page_1);
-
- if (dev_read_block(cp_page_1, cp_addr) < 0)
- goto invalid_cp1;
+ cp_page_1 = get_checkpoint_version(cp_addr);
+ if (!cp_page_1)
+ return NULL;
cp = (struct f2fs_checkpoint *)cp_page_1;
- if (verify_checksum_chksum(cp))
- goto invalid_cp1;
-
if (get_cp(cp_pack_total_block_count) > sbi->blocks_per_seg)
goto invalid_cp1;
pre_version = get_cp(checkpoint_ver);
/* Read the 2nd cp block in this CP pack */
- cp_page_2 = malloc(PAGE_SIZE);
- ASSERT(cp_page_2);
-
cp_addr += get_cp(cp_pack_total_block_count) - 1;
-
- if (dev_read_block(cp_page_2, cp_addr) < 0)
- goto invalid_cp2;
+ cp_page_2 = get_checkpoint_version(cp_addr);
+ if (!cp_page_2)
+ goto invalid_cp1;
cp = (struct f2fs_checkpoint *)cp_page_2;
- if (verify_checksum_chksum(cp))
- goto invalid_cp2;
-
cur_version = get_cp(checkpoint_ver);
if (cur_version == pre_version) {
@@ -824,7 +831,6 @@ void *validate_checkpoint(struct f2fs_sb_info *sbi, block_t cp_addr,
return cp_page_1;
}
-invalid_cp2:
free(cp_page_2);
invalid_cp1:
free(cp_page_1);
--
2.18.0.rc1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [f2fs-dev] [PATCH] f2fs-tools: introduce get_checkpoint_version() for cleanup
@ 2019-06-13 8:09 ` Chao Yu
0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2019-06-13 8:09 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: jaegeuk
Just cleanup, no logic change.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
fsck/mount.c | 42 ++++++++++++++++++++++++------------------
1 file changed, 24 insertions(+), 18 deletions(-)
diff --git a/fsck/mount.c b/fsck/mount.c
index aecd0cd..8d5d5cf 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -780,6 +780,24 @@ static int verify_checksum_chksum(struct f2fs_checkpoint *cp)
return 0;
}
+static void *get_checkpoint_version(block_t cp_addr)
+{
+ void *cp_page;
+
+ cp_page = malloc(PAGE_SIZE);
+ ASSERT(cp_page);
+
+ if (dev_read_block(cp_page, cp_addr) < 0)
+ ASSERT(0);
+
+ if (verify_checksum_chksum((struct f2fs_checkpoint *)cp_page))
+ goto out;
+ return cp_page;
+out:
+ free(cp_page);
+ return NULL;
+}
+
void *validate_checkpoint(struct f2fs_sb_info *sbi, block_t cp_addr,
unsigned long long *version)
{
@@ -788,34 +806,23 @@ void *validate_checkpoint(struct f2fs_sb_info *sbi, block_t cp_addr,
unsigned long long cur_version = 0, pre_version = 0;
/* Read the 1st cp block in this CP pack */
- cp_page_1 = malloc(PAGE_SIZE);
- ASSERT(cp_page_1);
-
- if (dev_read_block(cp_page_1, cp_addr) < 0)
- goto invalid_cp1;
+ cp_page_1 = get_checkpoint_version(cp_addr);
+ if (!cp_page_1)
+ return NULL;
cp = (struct f2fs_checkpoint *)cp_page_1;
- if (verify_checksum_chksum(cp))
- goto invalid_cp1;
-
if (get_cp(cp_pack_total_block_count) > sbi->blocks_per_seg)
goto invalid_cp1;
pre_version = get_cp(checkpoint_ver);
/* Read the 2nd cp block in this CP pack */
- cp_page_2 = malloc(PAGE_SIZE);
- ASSERT(cp_page_2);
-
cp_addr += get_cp(cp_pack_total_block_count) - 1;
-
- if (dev_read_block(cp_page_2, cp_addr) < 0)
- goto invalid_cp2;
+ cp_page_2 = get_checkpoint_version(cp_addr);
+ if (!cp_page_2)
+ goto invalid_cp1;
cp = (struct f2fs_checkpoint *)cp_page_2;
- if (verify_checksum_chksum(cp))
- goto invalid_cp2;
-
cur_version = get_cp(checkpoint_ver);
if (cur_version == pre_version) {
@@ -824,7 +831,6 @@ void *validate_checkpoint(struct f2fs_sb_info *sbi, block_t cp_addr,
return cp_page_1;
}
-invalid_cp2:
free(cp_page_2);
invalid_cp1:
free(cp_page_1);
--
2.18.0.rc1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-06-13 8:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-13 8:09 [PATCH] f2fs-tools: introduce get_checkpoint_version() for cleanup Chao Yu
2019-06-13 8:09 ` [f2fs-dev] " Chao Yu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.