2023-10-09 20:29:42

by Daeho Jeong

[permalink] [raw]
Subject: [PATCH v2] f2fs-tools: use proper address entry count for direct nodes

From: Daeho Jeong <[email protected]>

For direct nodes, we have to use DEF_ADDRS_PER_BLOCK.

Signed-off-by: Daeho Jeong <[email protected]>
---
v2: pass inode struct as a parameter and check COMPRESS_ADDR
---
fsck/fsck.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/fsck/fsck.c b/fsck/fsck.c
index 78ffdb6..3ade728 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -2875,7 +2875,7 @@ static int fsck_do_reconnect_file(struct f2fs_sb_info *sbi,
}

static void fsck_failed_reconnect_file_dnode(struct f2fs_sb_info *sbi,
- nid_t nid)
+ struct f2fs_inode *inode, nid_t nid)
{
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
struct f2fs_node *node;
@@ -2894,12 +2894,12 @@ static void fsck_failed_reconnect_file_dnode(struct f2fs_sb_info *sbi,
fsck->chk.valid_blk_cnt--;
f2fs_clear_main_bitmap(sbi, ni.blk_addr);

- for (i = 0; i < ADDRS_PER_BLOCK(&node->i); i++) {
+ for (i = 0; i < ADDRS_PER_BLOCK(inode); i++) {
addr = le32_to_cpu(node->dn.addr[i]);
if (!addr)
continue;
fsck->chk.valid_blk_cnt--;
- if (addr == NEW_ADDR)
+ if (addr == NEW_ADDR || addr == COMPRESS_ADDR)
continue;
f2fs_clear_main_bitmap(sbi, addr);
}
@@ -2908,7 +2908,7 @@ static void fsck_failed_reconnect_file_dnode(struct f2fs_sb_info *sbi,
}

static void fsck_failed_reconnect_file_idnode(struct f2fs_sb_info *sbi,
- nid_t nid)
+ struct f2fs_inode *inode, nid_t nid)
{
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
struct f2fs_node *node;
@@ -2931,14 +2931,14 @@ static void fsck_failed_reconnect_file_idnode(struct f2fs_sb_info *sbi,
tmp = le32_to_cpu(node->in.nid[i]);
if (!tmp)
continue;
- fsck_failed_reconnect_file_dnode(sbi, tmp);
+ fsck_failed_reconnect_file_dnode(sbi, inode, tmp);
}

free(node);
}

static void fsck_failed_reconnect_file_didnode(struct f2fs_sb_info *sbi,
- nid_t nid)
+ struct f2fs_inode *inode, nid_t nid)
{
struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
struct f2fs_node *node;
@@ -2961,7 +2961,7 @@ static void fsck_failed_reconnect_file_didnode(struct f2fs_sb_info *sbi,
tmp = le32_to_cpu(node->in.nid[i]);
if (!tmp)
continue;
- fsck_failed_reconnect_file_idnode(sbi, tmp);
+ fsck_failed_reconnect_file_idnode(sbi, inode, tmp);
}

free(node);
@@ -3010,7 +3010,7 @@ static void fsck_failed_reconnect_file(struct f2fs_sb_info *sbi, nid_t ino)
if (!addr)
continue;
fsck->chk.valid_blk_cnt--;
- if (addr == NEW_ADDR)
+ if (addr == NEW_ADDR || addr == COMPRESS_ADDR)
continue;
f2fs_clear_main_bitmap(sbi, addr);
}
@@ -3024,14 +3024,14 @@ static void fsck_failed_reconnect_file(struct f2fs_sb_info *sbi, nid_t ino)
switch (i) {
case 0: /* direct node */
case 1:
- fsck_failed_reconnect_file_dnode(sbi, nid);
+ fsck_failed_reconnect_file_dnode(sbi, &node->i, nid);
break;
case 2: /* indirect node */
case 3:
- fsck_failed_reconnect_file_idnode(sbi, nid);
+ fsck_failed_reconnect_file_idnode(sbi, &node->i, nid);
break;
case 4: /* double indirect node */
- fsck_failed_reconnect_file_didnode(sbi, nid);
+ fsck_failed_reconnect_file_didnode(sbi, &node->i, nid);
break;
}
}
--
2.42.0.609.gbb76f46606-goog


2023-10-10 01:33:37

by Chao Yu

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH v2] f2fs-tools: use proper address entry count for direct nodes

On 2023/10/10 4:29, Daeho Jeong wrote:
> From: Daeho Jeong <[email protected]>
>
> For direct nodes, we have to use DEF_ADDRS_PER_BLOCK.
>
> Signed-off-by: Daeho Jeong <[email protected]>

Reviewed-by: Chao Yu <[email protected]>

Thanks,