[f2fs-dev] 回复: [PATCH] f2fs: fix a race condition between f2fs_write_end_io and f2fs_del_fsync_node_entry

2020-06-17 Thread Zac via Linux-f2fs-devel


> On 2020/6/17 17:04, [email protected] wrote:
> > From: Wuyun Zhao 
> >
> > Under some condition, the __write_node_page will submit a page which is
> not
> > f2fs_in_warm_node_list and will not call f2fs_add_fsync_node_entry.
> > f2fs_gc continue to run to invoke f2fs_iget -> do_read_inode to read the
> same node page
> > and set code node, which make f2fs_in_warm_node_list become true,
> > that will cause f2fs_bug_on in f2fs_del_fsync_node_entry when
> f2fs_write_end_io called.
> Could you please add below race condition description into commit
> message?
> 
> - f2fs_write_end_io
>   - f2fs_iget
>- do_read_inode
> - set_cold_node
> recover cold node flag
>  - f2fs_in_warm_node_list
>   - is_cold_node
>   if node is cold, assume we have added
>   node to fsync_node_list during writepages()
>  - f2fs_del_fsync_node_entry
>   - f2fs_bug_on() due to node page
>   is not in fsync_node_list

Ok, will add the commit message.

> BTW, I'm curious about why we can lose cold flag for non-dir inode?
> any clue to reproduce this bug (I mean losing cold flag)?

it's a f2fs image with 25600MB
flash this image to device
the device will resize it according to the userdata partition size which is
about 94GB
the device mount the f2fs partition
then hit this f2fs_bug_on

seems that the cold flag is not been set when mkfs

I think the issue is that

1. the node page in the storage is without cold bit
2. f2fs_disable_checkpoint -> f2fs_gc -> f2fs_get_node_page, this page won't
be set cold flag
3. f2fs_move_node_page -> __write_node_page to write this page
4. f2fs_gc -> f2fs_iget -> do_read_inode to read this page and set cold flag

> >
> > [   34.966133] Call trace:
> > [   34.969902]  f2fs_del_fsync_node_entry+0x100/0x108
> > [   34.976071]  f2fs_write_end_io+0x1e0/0x288
> > [   34.981539]  bio_endio+0x248/0x270
> > [   34.986289]  blk_update_request+0x2b0/0x4d8
> > [   34.991841]  scsi_end_request+0x40/0x440
> > [   34.997126]  scsi_io_completion+0xa4/0x748
> > [   35.002593]  scsi_finish_command+0xdc/0x110
> > [   35.008143]  scsi_softirq_done+0x118/0x150
> > [   35.013610]  blk_done_softirq+0x8c/0xe8
> > [   35.018811]  __do_softirq+0x2e8/0x578
> > [   35.023828]  irq_exit+0xfc/0x120
> > [   35.028398]  handle_IPI+0x1d8/0x330
> > [   35.033233]  gic_handle_irq+0x110/0x1d4
> > [   35.038433]  el1_irq+0xb4/0x130
> > [   35.042917]  kmem_cache_alloc+0x3f0/0x418
> > [   35.048288]  radix_tree_node_alloc+0x50/0xf8
> > [   35.053933]  __radix_tree_create+0xf8/0x188
> > [   35.059484]  __radix_tree_insert+0x3c/0x128
> > [   35.065035]  add_gc_inode+0x90/0x118
> > [   35.069967]  f2fs_gc+0x1b80/0x2d70
> > [   35.074718]  f2fs_disable_checkpoint+0x94/0x1d0
> > [   35.080621]  f2fs_fill_super+0x10c4/0x1b88
> > [   35.086088]  mount_bdev+0x194/0x1e0
> > [   35.090923]  f2fs_mount+0x40/0x50
> > [   35.095589]  mount_fs+0xb4/0x190
> > [   35.100159]  vfs_kern_mount+0x80/0x1d8
> > [   35.105260]  do_mount+0x478/0xf18
> > [   35.109926]  ksys_mount+0x90/0xd0
> > [   35.114592]  __arm64_sys_mount+0x24/0x38
> >
> > Signed-off-by: Wuyun Zhao 
> 
> Reviewed-by: Chao Yu 
> 
> Thanks,
> 
> > ---
> >  fs/f2fs/inode.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
> > index be6ac33..0df5c8c 100644
> > --- a/fs/f2fs/inode.c
> > +++ b/fs/f2fs/inode.c
> > @@ -402,6 +402,7 @@ static int do_read_inode(struct inode *inode)
> >
> > /* try to recover cold bit for non-dir inode */
> > if (!S_ISDIR(inode->i_mode) && !is_cold_node(node_page)) {
> > +   f2fs_wait_on_page_writeback(node_page, NODE, true, true);
> > set_cold_node(node_page, false);
> > set_page_dirty(node_page);
> > }
> >



___
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] 回复: 回复: [PATCH] f2fs: fix a race condition between f2fs_write_end_io and f2fs_del_fsync_node_entry

2020-06-17 Thread Zac via Linux-f2fs-devel
> On 2020/6/18 10:39, Zac wrote:
> >
> >> On 2020/6/17 17:04, [email protected] wrote:
> >>> From: Wuyun Zhao 
> >>>
> >>> Under some condition, the __write_node_page will submit a page which
> is
> >> not
> >>> f2fs_in_warm_node_list and will not call f2fs_add_fsync_node_entry.
> >>> f2fs_gc continue to run to invoke f2fs_iget -> do_read_inode to read
the
> >> same node page
> >>> and set code node, which make f2fs_in_warm_node_list become true,
> >>> that will cause f2fs_bug_on in f2fs_del_fsync_node_entry when
> >> f2fs_write_end_io called.
> >> Could you please add below race condition description into commit
> >> message?
> >>
> >> - f2fs_write_end_io
> >>- f2fs_iget
> >> - do_read_inode
> >>  - set_cold_node
> >>  recover cold node flag
> >>  - f2fs_in_warm_node_list
> >>   - is_cold_node
> >>   if node is cold, assume we have added
> >>   node to fsync_node_list during writepages()
> >>  - f2fs_del_fsync_node_entry
> >>   - f2fs_bug_on() due to node page
> >>   is not in fsync_node_list
> >
> > Ok, will add the commit message.
> >
> >> BTW, I'm curious about why we can lose cold flag for non-dir inode?
> >> any clue to reproduce this bug (I mean losing cold flag)?
> >
> > it's a f2fs image with 25600MB
> > flash this image to device
> > the device will resize it according to the userdata partition size which
is
> > about 94GB
> > the device mount the f2fs partition
> > then hit this f2fs_bug_on
> >
> > seems that the cold flag is not been set when mkfs
> 
> Ah, I guess both mkfs/sload ignores setting cold node flag for non-dir
inode,
> could you please send another patch to fix this issue?

Patch v2 has been sent.

> >
> > I think the issue is that
> >
> > 1. the node page in the storage is without cold bit
> > 2. f2fs_disable_checkpoint -> f2fs_gc -> f2fs_get_node_page, this page
> won't
> > be set cold flag
> > 3. f2fs_move_node_page -> __write_node_page to write this page
> > 4. f2fs_gc -> f2fs_iget -> do_read_inode to read this page and set cold
flag
> 
> Clear enough, thanks for your explanation. :)
> 
> Thanks,
> 
> >
> >>>
> >>> [   34.966133] Call trace:
> >>> [   34.969902]  f2fs_del_fsync_node_entry+0x100/0x108
> >>> [   34.976071]  f2fs_write_end_io+0x1e0/0x288
> >>> [   34.981539]  bio_endio+0x248/0x270
> >>> [   34.986289]  blk_update_request+0x2b0/0x4d8
> >>> [   34.991841]  scsi_end_request+0x40/0x440
> >>> [   34.997126]  scsi_io_completion+0xa4/0x748
> >>> [   35.002593]  scsi_finish_command+0xdc/0x110
> >>> [   35.008143]  scsi_softirq_done+0x118/0x150
> >>> [   35.013610]  blk_done_softirq+0x8c/0xe8
> >>> [   35.018811]  __do_softirq+0x2e8/0x578
> >>> [   35.023828]  irq_exit+0xfc/0x120
> >>> [   35.028398]  handle_IPI+0x1d8/0x330
> >>> [   35.033233]  gic_handle_irq+0x110/0x1d4
> >>> [   35.038433]  el1_irq+0xb4/0x130
> >>> [   35.042917]  kmem_cache_alloc+0x3f0/0x418
> >>> [   35.048288]  radix_tree_node_alloc+0x50/0xf8
> >>> [   35.053933]  __radix_tree_create+0xf8/0x188
> >>> [   35.059484]  __radix_tree_insert+0x3c/0x128
> >>> [   35.065035]  add_gc_inode+0x90/0x118
> >>> [   35.069967]  f2fs_gc+0x1b80/0x2d70
> >>> [   35.074718]  f2fs_disable_checkpoint+0x94/0x1d0
> >>> [   35.080621]  f2fs_fill_super+0x10c4/0x1b88
> >>> [   35.086088]  mount_bdev+0x194/0x1e0
> >>> [   35.090923]  f2fs_mount+0x40/0x50
> >>> [   35.095589]  mount_fs+0xb4/0x190
> >>> [   35.100159]  vfs_kern_mount+0x80/0x1d8
> >>> [   35.105260]  do_mount+0x478/0xf18
> >>> [   35.109926]  ksys_mount+0x90/0xd0
> >>> [   35.114592]  __arm64_sys_mount+0x24/0x38
> >>>
> >>> Signed-off-by: Wuyun Zhao 
> >>
> >> Reviewed-by: Chao Yu 
> >>
> >> Thanks,
> >>
> >>> ---
> >>>  fs/f2fs/inode.c | 1 +
> >>>  1 file changed, 1 insertion(+)
> >>>
> >>> diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
> >>> index be6ac33..0df5c8c 100644
> >>> --- a/fs/f2fs/inode.c
> >>> +++ b/fs/f2fs/inode.c
> >>> @@ -402,6 +402,7 @@ static int do_read_inode(struct inode *inode)
> >>>
> >>>   /* try to recover cold bit for non-dir inode */
> >>>   if (!S_ISDIR(inode->i_mode) && !is_cold_node(node_page)) {
> >>> + f2fs_wait_on_page_writeback(node_page, NODE, true, true);
> >>>   set_cold_node(node_page, false);
> >>>   set_page_dirty(node_page);
> >>>   }
> >>>
> >
> > .
> >



___
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] 回复: 回复: 回复: [PATCH] f2fs: fix a race condition between f2fs_write_end_io and f2fs_del_fsync_node_entry

2020-06-18 Thread Zac via Linux-f2fs-devel
> On 2020/6/18 11:28, Zac wrote:
> >> On 2020/6/18 10:39, Zac wrote:
> >>>
>  On 2020/6/17 17:04, [email protected] wrote:
> > From: Wuyun Zhao 
> >
> > Under some condition, the __write_node_page will submit a page
> which
> >> is
>  not
> > f2fs_in_warm_node_list and will not call f2fs_add_fsync_node_entry.
> > f2fs_gc continue to run to invoke f2fs_iget -> do_read_inode to read
> > the
>  same node page
> > and set code node, which make f2fs_in_warm_node_list become
> true,
> > that will cause f2fs_bug_on in f2fs_del_fsync_node_entry when
>  f2fs_write_end_io called.
>  Could you please add below race condition description into commit
>  message?
> 
>  - f2fs_write_end_io
>   - f2fs_iget
>    - do_read_inode
> - set_cold_node
> recover cold node flag
>   - f2fs_in_warm_node_list
>    - is_cold_node
>    if node is cold, assume we have added
>    node to fsync_node_list during writepages()
>   - f2fs_del_fsync_node_entry
>    - f2fs_bug_on() due to node page
>    is not in fsync_node_list
> >>>
> >>> Ok, will add the commit message.
> >>>
>  BTW, I'm curious about why we can lose cold flag for non-dir inode?
>  any clue to reproduce this bug (I mean losing cold flag)?
> >>>
> >>> it's a f2fs image with 25600MB
> >>> flash this image to device
> >>> the device will resize it according to the userdata partition size
which
> > is
> >>> about 94GB
> >>> the device mount the f2fs partition
> >>> then hit this f2fs_bug_on
> >>>
> >>> seems that the cold flag is not been set when mkfs
> >>
> >> Ah, I guess both mkfs/sload ignores setting cold node flag for non-dir
> > inode,
> >> could you please send another patch to fix this issue?
> >
> > Patch v2 has been sent.
> 
> I see, it looks good to me.
> 
> Actually, I meant we need to fix mkfs/sload bugs as well, do you have time
> to
> work on it? :)
> 
> Thanks,

Ok, I will try to work on it.

> >
> >>>
> >>> I think the issue is that
> >>>
> >>> 1. the node page in the storage is without cold bit
> >>> 2. f2fs_disable_checkpoint -> f2fs_gc -> f2fs_get_node_page, this page
> >> won't
> >>> be set cold flag
> >>> 3. f2fs_move_node_page -> __write_node_page to write this page
> >>> 4. f2fs_gc -> f2fs_iget -> do_read_inode to read this page and set
cold
> > flag
> >>
> >> Clear enough, thanks for your explanation. :)
> >>
> >> Thanks,
> >>
> >>>
> >
> > [   34.966133] Call trace:
> > [   34.969902]  f2fs_del_fsync_node_entry+0x100/0x108
> > [   34.976071]  f2fs_write_end_io+0x1e0/0x288
> > [   34.981539]  bio_endio+0x248/0x270
> > [   34.986289]  blk_update_request+0x2b0/0x4d8
> > [   34.991841]  scsi_end_request+0x40/0x440
> > [   34.997126]  scsi_io_completion+0xa4/0x748
> > [   35.002593]  scsi_finish_command+0xdc/0x110
> > [   35.008143]  scsi_softirq_done+0x118/0x150
> > [   35.013610]  blk_done_softirq+0x8c/0xe8
> > [   35.018811]  __do_softirq+0x2e8/0x578
> > [   35.023828]  irq_exit+0xfc/0x120
> > [   35.028398]  handle_IPI+0x1d8/0x330
> > [   35.033233]  gic_handle_irq+0x110/0x1d4
> > [   35.038433]  el1_irq+0xb4/0x130
> > [   35.042917]  kmem_cache_alloc+0x3f0/0x418
> > [   35.048288]  radix_tree_node_alloc+0x50/0xf8
> > [   35.053933]  __radix_tree_create+0xf8/0x188
> > [   35.059484]  __radix_tree_insert+0x3c/0x128
> > [   35.065035]  add_gc_inode+0x90/0x118
> > [   35.069967]  f2fs_gc+0x1b80/0x2d70
> > [   35.074718]  f2fs_disable_checkpoint+0x94/0x1d0
> > [   35.080621]  f2fs_fill_super+0x10c4/0x1b88
> > [   35.086088]  mount_bdev+0x194/0x1e0
> > [   35.090923]  f2fs_mount+0x40/0x50
> > [   35.095589]  mount_fs+0xb4/0x190
> > [   35.100159]  vfs_kern_mount+0x80/0x1d8
> > [   35.105260]  do_mount+0x478/0xf18
> > [   35.109926]  ksys_mount+0x90/0xd0
> > [   35.114592]  __arm64_sys_mount+0x24/0x38
> >
> > Signed-off-by: Wuyun Zhao 
> 
>  Reviewed-by: Chao Yu 
> 
>  Thanks,
> 
> > ---
> >  fs/f2fs/inode.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
> > index be6ac33..0df5c8c 100644
> > --- a/fs/f2fs/inode.c
> > +++ b/fs/f2fs/inode.c
> > @@ -402,6 +402,7 @@ static int do_read_inode(struct inode *inode)
> >
> > /* try to recover cold bit for non-dir inode */
> > if (!S_ISDIR(inode->i_mode) && !is_cold_node(node_page)) {
> > +   f2fs_wait_on_page_writeback(node_page, NODE, true,
true);
> > set_cold_node(node_page, false);
> > set_page_dirty(node_page);
> > }
> >
> >>>
> >>> .
> >>>
> >
> > .
> >



___
Linux-f2fs-devel mailing list
L

[f2fs-dev] 回复: [PATCH] f2fs-tools: set cold flag for non-dir node

2020-06-18 Thread Zac via Linux-f2fs-devel
> On 2020/6/18 20:48, [email protected] wrote:
> > From: Wuyun Zhao 
> 
> Thanks for the patch. :)
> 
> Please add commit message here.

OK

> >
> > Signed-off-by: Wuyun Zhao 
> > ---
> >  fsck/dir.c  |  1 +
> >  fsck/node.c |  1 +
> >  fsck/node.h | 11 +++
> >  3 files changed, 13 insertions(+)
> >
> > diff --git a/fsck/dir.c b/fsck/dir.c
> > index 5f4f75e..dc03c98 100644
> > --- a/fsck/dir.c
> > +++ b/fsck/dir.c
> > @@ -522,6 +522,7 @@ static void init_inode_block(struct f2fs_sb_info
> *sbi,
> > node_blk->footer.nid = cpu_to_le32(de->ino);
> > node_blk->footer.flag = 0;
> > node_blk->footer.cp_ver = ckpt->checkpoint_ver;
> > +   set_cold_node(node_blk, S_ISDIR(mode));
> >
> > if (S_ISDIR(mode)) {
> > make_empty_dir(sbi, node_blk);
> > diff --git a/fsck/node.c b/fsck/node.c
> > index 229a99c..1d291ca 100644
> > --- a/fsck/node.c
> > +++ b/fsck/node.c
> > @@ -79,6 +79,7 @@ block_t new_node_block(struct f2fs_sb_info *sbi,
> > node_blk->footer.ino = f2fs_inode->footer.ino;
> > node_blk->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT);
> > node_blk->footer.cp_ver = ckpt->checkpoint_ver;
> > +   set_cold_node(node_blk, S_ISDIR(le16_to_cpu(f2fs_inode->i.i_mode)));
> 
> How about wrapping these node footer fields assignment into a function?
> then
> we can reuse this in other places.
> 
> void set_node_footer(nid, ino, ofs, ver, is_dir)
> {
>   node_blk->footer.nid = cpu_to_le32(nid);
>   node_blk->footer.ino = f2fs_inode->footer.ino;
>   node_blk->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT);
>   node_blk->footer.cp_ver = ckpt->checkpoint_ver;
>   set_cold_node(node_blk, S_ISDIR(le16_to_cpu(f2fs_inode->i.i_mode)));
> }

Ok, That's good.

> >
> > type = CURSEG_COLD_NODE;
> > if (IS_DNODE(node_blk)) {
> > diff --git a/fsck/node.h b/fsck/node.h
> > index 6bce1fb..99139b1 100644
> > --- a/fsck/node.h
> > +++ b/fsck/node.h
> > @@ -161,6 +161,17 @@ static inline int is_node(struct f2fs_node
> *node_blk, int type)
> > return le32_to_cpu(node_blk->footer.flag) & (1 << type);
> >  }
> 
> Beside this, I think we need to use set_node_footer() in:
> - f2fs_write_root_inode
> - f2fs_write_qf_inode
> - f2fs_write_lpf_inode
> 
> as well to fix mkfs bugs.

the root inode and the lpf inode is dir, need to set cold flag? 

> Thanks,
> 
> >
> > +static inline void set_cold_node(struct f2fs_node *rn, bool is_dir)
> > +{
> > +   unsigned int flag = le32_to_cpu(rn->footer.flag);
> > +
> > +   if (is_dir)
> > +   flag &= ~(0x1 << COLD_BIT_SHIFT);
> > +   else
> > +   flag |= (0x1 << COLD_BIT_SHIFT);
> > +   rn->footer.flag = cpu_to_le32(flag);
> > +}
> > +
> >  #define is_fsync_dnode(node_blk)   is_node(node_blk, FSYNC_BIT_SHIFT)
> >  #define is_dent_dnode(node_blk)is_node(node_blk,
> DENT_BIT_SHIFT)
> >
> >



___
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] 回复: [PATCH v2] f2fs-tools: introduce set_node_footer to initialize node footer

2020-06-19 Thread Zac via Linux-f2fs-devel
> On 2020/6/19 14:37, [email protected] wrote:
> > From: Wuyun Zhao 
> >
> > the filesystem will use the cold flag, so deal with it to avoid
> > potential issue of inconsistency
> >
> > Signed-off-by: Wuyun Zhao 
> > ---
> >  fsck/dir.c |  6 +-
> >  fsck/node.c|  9 +
> >  include/f2fs_fs.h  | 20 
> >  mkfs/f2fs_format.c | 14 +-
> >  4 files changed, 31 insertions(+), 18 deletions(-)
> >
> > diff --git a/fsck/dir.c b/fsck/dir.c
> > index 5f4f75e..64aa539 100644
> > --- a/fsck/dir.c
> > +++ b/fsck/dir.c
> > @@ -517,11 +517,7 @@ static void init_inode_block(struct f2fs_sb_info
> *sbi,
> > }
> >
> > set_file_temperature(sbi, node_blk, de->name);
> > -
> > -   node_blk->footer.ino = cpu_to_le32(de->ino);
> > -   node_blk->footer.nid = cpu_to_le32(de->ino);
> > -   node_blk->footer.flag = 0;
> > -   node_blk->footer.cp_ver = ckpt->checkpoint_ver;
> > +   set_node_footer(node_blk, de->ino, de->ino, 0,
> le64_to_cpu(ckpt->checkpoint_ver), S_ISDIR(mode));
> >
> > if (S_ISDIR(mode)) {
> > make_empty_dir(sbi, node_blk);
> > diff --git a/fsck/node.c b/fsck/node.c
> > index 229a99c..66e8a81 100644
> > --- a/fsck/node.c
> > +++ b/fsck/node.c
> > @@ -69,16 +69,17 @@ block_t new_node_block(struct f2fs_sb_info *sbi,
> > block_t blkaddr = NULL_ADDR;
> > int type;
> > int ret;
> > +   u32 ino;
> 
> nid_t ino;
> 
> > +   u64 cp_ver;
> >
> > f2fs_inode = dn->inode_blk;
> >
> > node_blk = calloc(BLOCK_SZ, 1);
> > ASSERT(node_blk);
> >
> > -   node_blk->footer.nid = cpu_to_le32(dn->nid);
> > -   node_blk->footer.ino = f2fs_inode->footer.ino;
> > -   node_blk->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT);
> > -   node_blk->footer.cp_ver = ckpt->checkpoint_ver;
> > +   ino = le32_to_cpu(f2fs_inode->footer.ino);
> > +   cp_ver = le64_to_cpu(ckpt->checkpoint_ver);
> > +   set_node_footer(node_blk, dn->nid, ino, ofs, cp_ver,
> S_ISDIR(le16_to_cpu(f2fs_inode->i.i_mode)));
> >
> > type = CURSEG_COLD_NODE;
> > if (IS_DNODE(node_blk)) {
> > diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
> > index 709bfd8..3583df4 100644
> > --- a/include/f2fs_fs.h
> > +++ b/include/f2fs_fs.h
> > @@ -923,6 +923,26 @@ struct f2fs_node {
> > struct node_footer footer;
> >  } __attribute__((packed));
> >
> > +static inline void set_cold_node(struct f2fs_node *rn, bool is_dir)
> > +{
> > +   unsigned int flag = le32_to_cpu(rn->footer.flag);
> > +
> > +   if (is_dir)
> > +   flag &= ~(0x1 << COLD_BIT_SHIFT);
> > +   else
> > +   flag |= (0x1 << COLD_BIT_SHIFT);
> > +   rn->footer.flag = cpu_to_le32(flag);
> > +}
> > +
> > +static inline void set_node_footer(struct f2fs_node *rn, u32 nid, u32
ino,
> u32 ofs, u64 ver, bool is_dir)
> 
> Sorry, I forgot to add parameter for next_blkaddr...
> 
> Could you check this?

Sent v3 patch, please help to review, thanks.

> From: Wuyun Zhao 
> Subject: [PATCH] f2fs-tools: introduce set_node_footer to initialize node
>  footer
> 
> the filesystem will use the cold flag, so deal with it to avoid
> potential issue of inconsistency
> 
> Signed-off-by: Wuyun Zhao 
> ---
>  fsck/dir.c |  7 ++-
>  fsck/node.c|  8 
>  include/f2fs_fs.h  | 23 +++
>  mkfs/f2fs_format.c | 34 +-
>  4 files changed, 42 insertions(+), 30 deletions(-)
> 
> diff --git a/fsck/dir.c b/fsck/dir.c
> index 5f4f75ebed77..b067aec9cffd 100644
> --- a/fsck/dir.c
> +++ b/fsck/dir.c
> @@ -517,11 +517,8 @@ static void init_inode_block(struct f2fs_sb_info
> *sbi,
>   }
> 
>   set_file_temperature(sbi, node_blk, de->name);
> -
> - node_blk->footer.ino = cpu_to_le32(de->ino);
> - node_blk->footer.nid = cpu_to_le32(de->ino);
> - node_blk->footer.flag = 0;
> - node_blk->footer.cp_ver = ckpt->checkpoint_ver;
> + set_node_footer(node_blk, de->ino, de->ino, 0,
> + le64_to_cpu(ckpt->checkpoint_ver), 0,
S_ISDIR(mode));
> 
>   if (S_ISDIR(mode)) {
>   make_empty_dir(sbi, node_blk);
> diff --git a/fsck/node.c b/fsck/node.c
> index 229a99cab481..da010ff669cc 100644
> --- a/fsck/node.c
> +++ b/fsck/node.c
> @@ -69,16 +69,16 @@ block_t new_node_block(struct f2fs_sb_info *sbi,
>   block_t blkaddr = NULL_ADDR;
>   int type;
>   int ret;
> + nid_t ino = le32_to_cpu(f2fs_inode->footer.ino);
> + u64 cp_ver = le64_to_cpu(ckpt->checkpoint_ver);
> 
>   f2fs_inode = dn->inode_blk;
> 
>   node_blk = calloc(BLOCK_SZ, 1);
>   ASSERT(node_blk);
> 
> - node_blk->footer.nid = cpu_to_le32(dn->nid);
> - node_blk->footer.ino = f2fs_inode->footer.ino;
> - node_blk->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT);
> - node_blk->footer.cp_ver = ckpt->checkpoint_ver;
> + set_node_footer(node_blk, dn->nid, ino, ofs, cp_ver, 0,
> + S_ISDIR(le16_to_cpu(f2fs_inode->i.i_mode)));
> 
>   type = CURSEG_COLD_NODE;
>   if (IS_DNODE(node_blk))