2023-10-03 23:02:26

by Daeho Jeong

[permalink] [raw]
Subject: [PATCH] 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]>
---
fsck/fsck.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fsck/fsck.c b/fsck/fsck.c
index 78ffdb6..56a7d31 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -2894,7 +2894,7 @@ 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 < DEF_ADDRS_PER_BLOCK; i++) {
addr = le32_to_cpu(node->dn.addr[i]);
if (!addr)
continue;
--
2.42.0.582.g8ccd20d70d-goog


2023-10-04 23:27:26

by Jaegeuk Kim

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

On 10/03, 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]>
> ---
> fsck/fsck.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fsck/fsck.c b/fsck/fsck.c
> index 78ffdb6..56a7d31 100644
> --- a/fsck/fsck.c
> +++ b/fsck/fsck.c
> @@ -2894,7 +2894,7 @@ 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 < DEF_ADDRS_PER_BLOCK; i++) {

It seems we need to use the inode block passing by fsck_failed_reconnect_file().

> addr = le32_to_cpu(node->dn.addr[i]);
> if (!addr)
> continue;

3012 fsck->chk.valid_blk_cnt--;
3013 if (addr == NEW_ADDR)

And, we also need to skip if addr == COMPRESS_ADDR here?

3014 continue;
3015 f2fs_clear_main_bitmap(sbi, addr);
3016 }

> --
> 2.42.0.582.g8ccd20d70d-goog

2023-10-04 23:38:08

by Daeho Jeong

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

On Wed, Oct 4, 2023 at 4:26 PM Jaegeuk Kim <[email protected]> wrote:
>
> On 10/03, 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]>
> > ---
> > fsck/fsck.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/fsck/fsck.c b/fsck/fsck.c
> > index 78ffdb6..56a7d31 100644
> > --- a/fsck/fsck.c
> > +++ b/fsck/fsck.c
> > @@ -2894,7 +2894,7 @@ 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 < DEF_ADDRS_PER_BLOCK; i++) {
>
> It seems we need to use the inode block passing by fsck_failed_reconnect_file().

This function is for direct nodes. Is it correct to use inode block here?

>
> > addr = le32_to_cpu(node->dn.addr[i]);
> > if (!addr)
> > continue;
>
> 3012 fsck->chk.valid_blk_cnt--;
> 3013 if (addr == NEW_ADDR)
>
> And, we also need to skip if addr == COMPRESS_ADDR here?
>
> 3014 continue;
> 3015 f2fs_clear_main_bitmap(sbi, addr);
> 3016 }
>
> > --
> > 2.42.0.582.g8ccd20d70d-goog

2023-10-04 23:56:05

by Jaegeuk Kim

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

On 10/04, Daeho Jeong wrote:
> On Wed, Oct 4, 2023 at 4:26 PM Jaegeuk Kim <[email protected]> wrote:
> >
> > On 10/03, 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]>
> > > ---
> > > fsck/fsck.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/fsck/fsck.c b/fsck/fsck.c
> > > index 78ffdb6..56a7d31 100644
> > > --- a/fsck/fsck.c
> > > +++ b/fsck/fsck.c
> > > @@ -2894,7 +2894,7 @@ 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 < DEF_ADDRS_PER_BLOCK; i++) {
> >
> > It seems we need to use the inode block passing by fsck_failed_reconnect_file().
>
> This function is for direct nodes. Is it correct to use inode block here?

523 unsigned int addrs_per_block(struct f2fs_inode *i)
524 {
525 if (!LINUX_S_ISREG(le16_to_cpu(i->i_mode)) ||
526 !(le32_to_cpu(i->i_flags) & F2FS_COMPR_FL))
527 return DEF_ADDRS_PER_BLOCK;
528 return ALIGN_DOWN(DEF_ADDRS_PER_BLOCK, 1 << i->i_log_cluster_size);
529 }

If the inode is compressed, it seems it has to be aligned to cluster size.

>
> >
> > > addr = le32_to_cpu(node->dn.addr[i]);
> > > if (!addr)
> > > continue;
> >
> > 3012 fsck->chk.valid_blk_cnt--;
> > 3013 if (addr == NEW_ADDR)
> >
> > And, we also need to skip if addr == COMPRESS_ADDR here?
> >
> > 3014 continue;
> > 3015 f2fs_clear_main_bitmap(sbi, addr);
> > 3016 }
> >
> > > --
> > > 2.42.0.582.g8ccd20d70d-goog

2023-10-05 00:04:58

by Daeho Jeong

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

On Wed, Oct 4, 2023 at 4:55 PM Jaegeuk Kim <[email protected]> wrote:
>
> On 10/04, Daeho Jeong wrote:
> > On Wed, Oct 4, 2023 at 4:26 PM Jaegeuk Kim <[email protected]> wrote:
> > >
> > > On 10/03, 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]>
> > > > ---
> > > > fsck/fsck.c | 2 +-
> > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/fsck/fsck.c b/fsck/fsck.c
> > > > index 78ffdb6..56a7d31 100644
> > > > --- a/fsck/fsck.c
> > > > +++ b/fsck/fsck.c
> > > > @@ -2894,7 +2894,7 @@ 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 < DEF_ADDRS_PER_BLOCK; i++) {
> > >
> > > It seems we need to use the inode block passing by fsck_failed_reconnect_file().
> >
> > This function is for direct nodes. Is it correct to use inode block here?
>
> 523 unsigned int addrs_per_block(struct f2fs_inode *i)
> 524 {
> 525 if (!LINUX_S_ISREG(le16_to_cpu(i->i_mode)) ||
> 526 !(le32_to_cpu(i->i_flags) & F2FS_COMPR_FL))
> 527 return DEF_ADDRS_PER_BLOCK;
> 528 return ALIGN_DOWN(DEF_ADDRS_PER_BLOCK, 1 << i->i_log_cluster_size);
> 529 }
>
> If the inode is compressed, it seems it has to be aligned to cluster size.

makes sense. Thanks~!

>
> >
> > >
> > > > addr = le32_to_cpu(node->dn.addr[i]);
> > > > if (!addr)
> > > > continue;
> > >
> > > 3012 fsck->chk.valid_blk_cnt--;
> > > 3013 if (addr == NEW_ADDR)
> > >
> > > And, we also need to skip if addr == COMPRESS_ADDR here?
> > >
> > > 3014 continue;
> > > 3015 f2fs_clear_main_bitmap(sbi, addr);
> > > 3016 }
> > >
> > > > --
> > > > 2.42.0.582.g8ccd20d70d-goog