f2fs: check block reserve strictly a little bit
PATCH 1/1 f2fs: check block reserve strictly a little bit
This patch check new block reserve strictly, in case of garbage data of node page.
--- fs/f2fs/data.c | 9 +++++++-- fs/f2fs/file.c | 13 +++++-------- fs/f2fs/segment.c | 1 + 3 files changed, 13 insertions(+), 10 deletions(-)
fs/f2fs/data.c +7 -2
@@ -558,13 +558,18 @@ int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count)f2fs_wait_on_page_writeback (dn->node_page,NODE , true); -for (; count >0 ; dn->ofs_in_node++) { +for (; count >0 ; dn->ofs_in_node++, count--) {block_t blkaddr =datablock_addr (dn->inode, dn->node_page, dn->ofs_in_node);if (blkaddr ==NULL_ADDR ) { dn->data_blkaddr =NEW_ADDR ;__set_data_blkaddr (dn); - count--; + }else { +f2fs_msg (sbi->sb,KERN_ERR ,"reserve non NULL block, " +"blkaddr:%u, ino:%lu, nid:%u, ofs_in_node:%u" , + blkaddr, dn->inode->i_ino, dn->nid, + dn->ofs_in_node); +f2fs_bug_on (sbi,1 ); } }
fs/f2fs/file.c +5 -8
@@ -1218,19 +1218,16 @@ static int f2fs_do_zero_range(struct dnode_of_data *dn, pgoff_t start,struct f2fs_sb_info *sbi =F2FS_I_SB (dn->inode);pgoff_t index = start;unsigned int ofs_in_node = dn->ofs_in_node; -blkcnt_t count =0 ; -int ret; +int ret =0 ;for (; index < end; index++, dn->ofs_in_node++) {if (datablock_addr (dn->inode, dn->node_page, dn->ofs_in_node) ==NULL_ADDR ) - count++; - } + ret =reserve_new_blocks (dn,1 ); - dn->ofs_in_node = ofs_in_node; - ret =reserve_new_blocks (dn, count); -if (ret) -return ret; +if (ret) +return ret; + } dn->ofs_in_node = ofs_in_node;for (index = start; index < end; index++, dn->ofs_in_node++) {
fs/f2fs/segment.c +1 -0
@@ -1815,6 +1815,7 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)bool mir_exist;#endif +verify_block_addr (sbi, blkaddr); segno =GET_SEGNO (sbi, blkaddr); se =get_seg_entry (sbi, segno);
Signature · 6 lines
1.9.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Jaegeuk Kim
maintainerQuoted 22 lines · Yunlei He
This patch check new block reserve strictly, in case of garbage data of node page.
Signed-off-by Yunlei He <[email protected]>--- fs/f2fs/data.c | 9 +++++++-- fs/f2fs/file.c | 13 +++++-------- fs/f2fs/segment.c | 1 + 3 files changed, 13 insertions(+), 10 deletions(-)fs/f2fs/data.c +1
-1@@ -558,13 +558,18 @@ int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count)f2fs_wait_on_page_writeback (dn->node_page,NODE , true); -for (; count >0 ; dn->ofs_in_node++) { +for (; count >0 ; dn->ofs_in_node++, count--) {block_t blkaddr =datablock_addr (dn->inode, dn->node_page, dn->ofs_in_node);
fs/f2fs/data.c int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count) · line 572
Quoted 10 lines
fs/f2fs/data.c +6
-1if (blkaddr ==NULL_ADDR ) { dn->data_blkaddr =NEW_ADDR ;__set_data_blkaddr (dn); - count--; + }else { +f2fs_msg (sbi->sb,KERN_ERR ,"reserve non NULL block, " +"blkaddr:%u, ino:%lu, nid:%u, ofs_in_node:%u" , + blkaddr, dn->inode->i_ino, dn->nid, + dn->ofs_in_node); +f2fs_bug_on (sbi,1 );
What if there is a hole?
Quoted 46 lines
fs/f2fs/data.c +0
-0} }fs/f2fs/file.c +5
-8@@ -1218,19 +1218,16 @@ static int f2fs_do_zero_range(struct dnode_of_data *dn, pgoff_t start,struct f2fs_sb_info *sbi =F2FS_I_SB (dn->inode);pgoff_t index = start;unsigned int ofs_in_node = dn->ofs_in_node; -blkcnt_t count =0 ; -int ret; +int ret =0 ;for (; index < end; index++, dn->ofs_in_node++) {if (datablock_addr (dn->inode, dn->node_page, dn->ofs_in_node) ==NULL_ADDR ) - count++; - } + ret =reserve_new_blocks (dn,1 ); - dn->ofs_in_node = ofs_in_node; - ret =reserve_new_blocks (dn, count); -if (ret) -return ret; +if (ret) +return ret; + } dn->ofs_in_node = ofs_in_node;for (index = start; index < end; index++, dn->ofs_in_node++) {fs/f2fs/segment.c +1
-0@@ -1815,6 +1815,7 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)bool mir_exist;#endif +verify_block_addr (sbi, blkaddr); segno =GET_SEGNO (sbi, blkaddr); se =get_seg_entry (sbi, segno);Signature · 1 line
1.9.1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Quoted 28 lines
-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, November 10, 2017 1:55 AM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Jianing (Euler)
Subject: Re: [f2fs-dev][PATCH] f2fs: check block reserve strictly a little bitQuoted 18 lines · Yunlei He
This patch check new block reserve strictly, in case of garbage data of node page.
Signed-off-by Yunlei He <[email protected]>--- fs/f2fs/data.c | 9 +++++++-- fs/f2fs/file.c | 13 +++++-------- fs/f2fs/segment.c | 1 + 3 files changed, 13 insertions(+), 10 deletions(-)fs/f2fs/data.c +0
-0@@ -558,13 +558,18 @@ int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count)f2fs_wait_on_page_writeback (dn->node_page,NODE , true);
Quoted 16 lines
Quoted 4 lines
fs/f2fs/data.c +1
-1-for (; count >0 ; dn->ofs_in_node++) { +for (; count >0 ; dn->ofs_in_node++, count--) {block_t blkaddr =datablock_addr (dn->inode, dn->node_page, dn->ofs_in_node);fs/f2fs/data.c int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count) · line 572
Quoted 10 lines
fs/f2fs/data.c +6
-1if (blkaddr ==NULL_ADDR ) { dn->data_blkaddr =NEW_ADDR ;__set_data_blkaddr (dn); - count--; + }else { +f2fs_msg (sbi->sb,KERN_ERR ,"reserve non NULL block, " +"blkaddr:%u, ino:%lu, nid:%u, ofs_in_node:%u" , + blkaddr, dn->inode->i_ino, dn->nid, + dn->ofs_in_node); +f2fs_bug_on (sbi,1 );What if there is a hole?
Hole can hold a non NULL block index?NEW_ADDR may be possible, for the case date block is reserved but without wb after new cp.
How about this?
} else if (blkaddr != NEW_ADDR ){
f2fs_msg();
}Thanks.
Quoted 41 lines
Quoted 41 lines
fs/f2fs/data.c +0
-0} }fs/f2fs/file.c +5
-8@@ -1218,19 +1218,16 @@ static int f2fs_do_zero_range(struct dnode_of_data *dn, pgoff_t start,struct f2fs_sb_info *sbi =F2FS_I_SB (dn->inode);pgoff_t index = start;unsigned int ofs_in_node = dn->ofs_in_node; -blkcnt_t count =0 ; -int ret; +int ret =0 ;for (; index < end; index++, dn->ofs_in_node++) {if (datablock_addr (dn->inode, dn->node_page, dn->ofs_in_node) ==NULL_ADDR ) - count++; - } + ret =reserve_new_blocks (dn,1 ); - dn->ofs_in_node = ofs_in_node; - ret =reserve_new_blocks (dn, count); -if (ret) -return ret; +if (ret) +return ret; + } dn->ofs_in_node = ofs_in_node;for (index = start; index < end; index++, dn->ofs_in_node++) {fs/f2fs/segment.c +0
-0@@ -1815,6 +1815,7 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)bool mir_exist;#endif
Quoted 6 lines
Quoted 6 lines
fs/f2fs/segment.c +1
-1+verify_block_addr (sbi, blkaddr); segno =GET_SEGNO (sbi, blkaddr); se =get_seg_entry (sbi, segno); --1.9.1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Jaegeuk Kim
maintainerQuoted 45 lines · heyunlei
Quoted 28 lines
-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, November 10, 2017 1:55 AM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Jianing (Euler)
Subject: Re: [f2fs-dev][PATCH] f2fs: check block reserve strictly a little bitQuoted 18 lines · Yunlei He
This patch check new block reserve strictly, in case of garbage data of node page.
Signed-off-by Yunlei He <[email protected]>--- fs/f2fs/data.c | 9 +++++++-- fs/f2fs/file.c | 13 +++++-------- fs/f2fs/segment.c | 1 + 3 files changed, 13 insertions(+), 10 deletions(-)fs/f2fs/data.c +0
-0@@ -558,13 +558,18 @@ int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count)f2fs_wait_on_page_writeback (dn->node_page,NODE , true);Quoted 16 lines
Quoted 4 lines
fs/f2fs/data.c +1
-1-for (; count >0 ; dn->ofs_in_node++) { +for (; count >0 ; dn->ofs_in_node++, count--) {block_t blkaddr =datablock_addr (dn->inode, dn->node_page, dn->ofs_in_node);fs/f2fs/data.c int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count) · line 572
Quoted 10 lines
fs/f2fs/data.c +6
-1if (blkaddr ==NULL_ADDR ) { dn->data_blkaddr =NEW_ADDR ;__set_data_blkaddr (dn); - count--; + }else { +f2fs_msg (sbi->sb,KERN_ERR ,"reserve non NULL block, " +"blkaddr:%u, ino:%lu, nid:%u, ofs_in_node:%u" , + blkaddr, dn->inode->i_ino, dn->nid, + dn->ofs_in_node); +f2fs_bug_on (sbi,1 );What if there is a hole?
Quoted 7 lines
Hole can hold a non NULL block index?
NEW_ADDRmay be possible, for the case date block is reserved but without wb after new cp.
How about this?} else if (blkaddr != NEW_ADDR ){ f2fs_msg(); }
No, it is allowed to allocate new blocks in holes. We can give the # of allocated blocks to caller which can check its intention.
Quoted 42 lines
Thanks.
Quoted 41 lines
Quoted 41 lines
fs/f2fs/data.c +0
-0} }fs/f2fs/file.c +5
-8@@ -1218,19 +1218,16 @@ static int f2fs_do_zero_range(struct dnode_of_data *dn, pgoff_t start,struct f2fs_sb_info *sbi =F2FS_I_SB (dn->inode);pgoff_t index = start;unsigned int ofs_in_node = dn->ofs_in_node; -blkcnt_t count =0 ; -int ret; +int ret =0 ;for (; index < end; index++, dn->ofs_in_node++) {if (datablock_addr (dn->inode, dn->node_page, dn->ofs_in_node) ==NULL_ADDR ) - count++; - } + ret =reserve_new_blocks (dn,1 ); - dn->ofs_in_node = ofs_in_node; - ret =reserve_new_blocks (dn, count); -if (ret) -return ret; +if (ret) +return ret; + } dn->ofs_in_node = ofs_in_node;for (index = start; index < end; index++, dn->ofs_in_node++) {fs/f2fs/segment.c +0
-0@@ -1815,6 +1815,7 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)bool mir_exist;#endif
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
fs/f2fs/segment.c +1
-1+verify_block_addr (sbi, blkaddr); segno =GET_SEGNO (sbi, blkaddr); se =get_seg_entry (sbi, segno); --1.9.1
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot