From: Chao Yu <yuchao0@huawei.com>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: jaegeuk@kernel.org
Subject: [PATCH] f2fs-tools: introduce get_checkpoint_version() for cleanup
Date: Thu, 13 Jun 2019 16:09:03 +0800 [thread overview]
Message-ID: <20190613080903.4828-1-yuchao0@huawei.com> (raw)
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
WARNING: multiple messages have this Message-ID (diff)
From: Chao Yu <yuchao0@huawei.com>
To: <linux-f2fs-devel@lists.sourceforge.net>
Cc: jaegeuk@kernel.org
Subject: [f2fs-dev] [PATCH] f2fs-tools: introduce get_checkpoint_version() for cleanup
Date: Thu, 13 Jun 2019 16:09:03 +0800 [thread overview]
Message-ID: <20190613080903.4828-1-yuchao0@huawei.com> (raw)
Message-ID: <20190613080903.b1xK5JyoZL4AocrRWRZSsM527rJRP5i-ffoOnu8n7vE@z> (raw)
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
next reply other threads:[~2019-06-13 8:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-13 8:09 Chao Yu [this message]
2019-06-13 8:09 ` [f2fs-dev] [PATCH] f2fs-tools: introduce get_checkpoint_version() for cleanup Chao Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190613080903.4828-1-yuchao0@huawei.com \
--to=yuchao0@huawei.com \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).