ext4: release buffer when checksum failed
PATCH 1/4 ext4: release buffer when checksum failed
Commit b0336e8d (ext4: calculate and verify checksums of directory leaf blocks) and commit dbe89444 (ext4: Calculate and verify checksums for htree nodes) forget to release buffer when checksum failed, at some places.
--- fs/ext4/dir.c | 1 + fs/ext4/namei.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
fs/ext4/dir.c +1 -0
@@ -185,6 +185,7 @@ static int ext4_readdir(struct file *filp,"at offset %llu" , (unsigned long long)filp->f_pos); filp->f_pos += sb->s_blocksize - offset; +brelse (bh);continue ; }set_buffer_verified (bh);
fs/ext4/namei.c +10 -2
@@ -837,6 +837,7 @@ static int ext4_htree_next_block(struct inode *dir, __u32 hash, !ext4_dx_csum_verify(dir, (struct ext4_dir_entry *)bh->b_data)) {ext4_warning (dir->i_sb,"Node failed checksum" ); +brelse (bh);return -EIO ; }set_buffer_verified (bh);
@@ -877,8 +878,11 @@ static int htree_dirblock_to_tree(struct file *dir_file, }if (!buffer_verified (bh) && - !ext4_dirent_csum_verify (dir, (struct ext4_dir_entry *)bh->b_data)) + !ext4_dirent_csum_verify (dir, + (struct ext4_dir_entry *)bh->b_data)) { +brelse (bh);return -EIO ; + }set_buffer_verified (bh); de = (struct ext4_dir_entry_2 *) bh->b_data;
@@ -1929,8 +1933,10 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, }if (!buffer_verified (bh) && !ext4_dirent_csum_verify (dir, - (struct ext4_dir_entry *)bh->b_data)) + (struct ext4_dir_entry *)bh->b_data)) { +brelse (bh);return -EIO ; + }set_buffer_verified (bh); retval =add_dirent_to_buf (handle, dentry, inode,NULL , bh);if (retval != -ENOSPC ) {
@@ -2493,6 +2499,7 @@ static int empty_dir(struct inode *inode) (struct ext4_dir_entry *)bh->b_data)) {EXT4_ERROR_INODE (inode,"checksum error reading directory " "lblock 0" ); +brelse (bh);return -EIO ; }set_buffer_verified (bh);
@@ -2537,6 +2544,7 @@ static int empty_dir(struct inode *inode) (struct ext4_dir_entry *)bh->b_data)) {EXT4_ERROR_INODE (inode,"checksum error " "reading directory lblock 0" ); +brelse (bh);return -EIO ; }set_buffer_verified (bh);
Signature · 1 line
1.7.9.5
PATCH 2/4 ext4: remove unused variable in add_dirent_to_buf()
After commit 978fef9 (create __ext4_insert_dentry for dir entry insertion), 'reclen' is not used anymore.
--- fs/ext4/namei.c | 2 -- 1 file changed, 2 deletions(-)
fs/ext4/namei.c +0 -2
@@ -1703,7 +1703,6 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,const char *name = dentry->d_name.name;int namelen = dentry->d_name.len;unsigned int blocksize = dir->i_sb->s_blocksize; -unsigned short reclen;int csum_size =0 ;int err;
@@ -1711,7 +1710,6 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry, EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) csum_size =sizeof (struct ext4_dir_entry_tail ); - reclen =EXT4_DIR_REC_LEN (namelen);if (!de) { err = ext4_find_dest_de(dir, inode, bh, bh->b_data, blocksize - csum_size,
Signature · 1 line
1.7.9.5
Re: [PATCH 2/4] ext4: remove unused variable in add_dirent_to_buf()
Quoted 4 lines · Guo Chao
After commit 978fef9 (create
__ext4_insert_dentryfor dir entry insertion), 'reclen' is not used anymore.Signed-off-by Guo Chao <[email protected]>
This one looks ok too.
Quoted 31 lines
--- fs/ext4/namei.c | 2 -- 1 file changed, 2 deletions(-)fs/ext4/namei.c +0
-2@@ -1703,7 +1703,6 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,const char *name = dentry->d_name.name;int namelen = dentry->d_name.len;unsigned int blocksize = dir->i_sb->s_blocksize; -unsigned short reclen;int csum_size =0 ;int err;@@ -1711,7 +1710,6 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry, EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) csum_size =sizeof (struct ext4_dir_entry_tail ); - reclen =EXT4_DIR_REC_LEN (namelen);if (!de) { err = ext4_find_dest_de(dir, inode, bh, bh->b_data, blocksize - csum_size,Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/4] ext4: remove unused variable in add_dirent_to_buf()
Quoted 7 lines · Darrick J. Wong
Quoted 4 lines · Guo Chao
After commit 978fef9 (create
__ext4_insert_dentryfor dir entry insertion), 'reclen' is not used anymore.Signed-off-by Guo Chao <[email protected]>This one looks ok too.
Reviewed-by Darrick J. Wong <[email protected]>
Thanks, applied.
- Ted
PATCH 3/4 ext4: remove useless assignment in dx_probe()
In reply to Guo ChaoNo body care about the effect of this assignment.
--- fs/ext4/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/namei.c +1 -1
@@ -714,7 +714,7 @@ dx_probe(const struct qstr *d_name, struct inode *dir, *err =ERR_BAD_DX_DIR ; goto fail2; } - at = entries = ((struct dx_node *) bh->b_data)->entries; + entries = ((struct dx_node *) bh->b_data)->entries;if (!buffer_verified (bh) && !ext4_dx_csum_verify(dir,
Signature · 1 line
1.7.9.5
Re: [PATCH 3/4] ext4: remove useless assignment in dx_probe()
Quoted 12 lines · Guo Chao
No body care about the effect of this assignment.
Signed-off-by Guo Chao <[email protected]>--- fs/ext4/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ext4/namei.c +0
-0
fs/ext4/namei.c dx_probe(const struct qstr *d_name, struct inode *dir, · line 717
Quoted 5 lines
fs/ext4/namei.c +1
-1@@ -714,7 +714,7 @@ dx_probe(const struct qstr *d_name, struct inode *dir, *err =ERR_BAD_DX_DIR ; goto fail2; } - at = entries = ((struct dx_node *) bh->b_data)->entries; + entries = ((struct dx_node *) bh->b_data)->entries;
The 'at' variable seems to be used (in a if(0)'d code block) to check the results of the binary search against a slow linear search. Perhaps we should get rid of the if(0) hunk about 30 lines up? The 'at' variable itself could go too, since it seems to be an alias of "p - 1" and frame->at.
--D
Quoted 10 lines
fs/ext4/namei.c +0
-0if (!buffer_verified (bh) && !ext4_dx_csum_verify(dir,Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Theodore Ts'o
maintainerRe: [PATCH 3/4] ext4: remove useless assignment in dx_probe()
Quoted 6 lines · Darrick J. Wong
The 'at' variable seems to be used (in a if(0)'d code block) to check the results of the binary search against a slow linear search. Perhaps we should get rid of the if(0) hunk about 30 lines up? The 'at' variable itself could go too, since it seems to be an alias of "p - 1" and
frame->at.
What I'd suggest doing (if someone is interested in doing the cleanup) is moving the code into an inline function which is normally #ifdef'ed to be an empty function, but which could be enabled if we want enable the debugging cross check. This is what we've done in other parts of the ext4 code base, and by moving the debugging code so it's not inline with the rest of the function, it should make it more readable.
- Ted
Re: [PATCH 3/4] ext4: remove useless assignment in dx_probe()
In reply to Guo ChaoQuoted 3 lines · Guo Chao
No body care about the effect of this assignment.
Signed-off-by Guo Chao <[email protected]>
Thanks, applied.
- Ted
PATCH 4/4 ext4: remove unnecessary NULL pointer check
In reply to Guo Chaobrelse() and ext4_journal_force_commit() are both inlined and able to handle NULL.
--- fs/ext4/namei.c | 3 +-- fs/ext4/super.c | 6 +----- 2 files changed, 2 insertions(+), 7 deletions(-)
fs/ext4/namei.c +1 -2
@@ -2110,8 +2110,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry, journal_error:ext4_std_error (dir->i_sb, err); cleanup: -if (bh) -brelse (bh); +brelse (bh);dx_release (frames);return err; }
fs/ext4/super.c +0 -3
@@ -4476,16 +4476,12 @@ static void ext4_clear_journal_err(struct super_block *sb,int ext4_force_commit (struct super_block *sb) {journal_t *journal; -int ret =0 ;if (sb->s_flags &MS_RDONLY )return 0 ; journal =EXT4_SB (sb)->s_journal; -if (journal) - ret =ext4_journal_force_commit (journal);
Re: [PATCH 4/4] ext4: remove unnecessary NULL pointer check
Quoted 4 lines · Guo Chao
brelse()andext4_journal_force_commit()are both inlined and able to handle NULL.Signed-off-by Guo Chao <[email protected]>
This one looks ok too, so:
PS: Does the order of the patches matter? Or are these just four patches that are mostly independent of each other?
--D
Quoted 48 lines
--- fs/ext4/namei.c | 3 +-- fs/ext4/super.c | 6 +----- 2 files changed, 2 insertions(+), 7 deletions(-)fs/ext4/namei.c +1
-2@@ -2110,8 +2110,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry, journal_error:ext4_std_error (dir->i_sb, err); cleanup: -if (bh) -brelse (bh); +brelse (bh);dx_release (frames);return err; }fs/ext4/super.c +1
-5@@ -4476,16 +4476,12 @@ static void ext4_clear_journal_err(struct super_block *sb,int ext4_force_commit (struct super_block *sb) {journal_t *journal; -int ret =0 ;if (sb->s_flags &MS_RDONLY )return 0 ; journal =EXT4_SB (sb)->s_journal; -if (journal) - ret =ext4_journal_force_commit (journal); - -return ret; +return ext4_journal_force_commit (journal); }static int ext4_sync_fs (struct super_block *sb,int wait)Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 4/4] ext4: remove unnecessary NULL pointer check
Quoted 6 lines · Darrick J. Wong
Quoted 4 lines · Guo Chao
brelse()andext4_journal_force_commit()are both inlined and able to handle NULL.Signed-off-by Guo Chao <[email protected]>
Quoted 7 lines
This one looks ok too, so:
Reviewed-by Darrick J. Wong <[email protected]>PS: Does the order of the patches matter? Or are these just four patches that are mostly independent of each other?
--D
They are random independent fixes.
Thanks
Re: [PATCH 4/4] ext4: remove unnecessary NULL pointer check
In reply to Darrick J. WongQuoted 8 lines · Darrick J. Wong
Quoted 4 lines · Guo Chao
brelse()andext4_journal_force_commit()are both inlined and able to handle NULL.Signed-off-by Guo Chao <[email protected]>This one looks ok too, so:
Reviewed-by Darrick J. Wong <[email protected]>
Thanks, applied.
- Ted
Quoted 6 lines · Guo Chao
Commit
b0336e8d(ext4: calculate and verify checksums of directory leaf blocks) and commitdbe89444(ext4: Calculate and verify checksums for htree nodes) forget to release buffer when checksum failed, at some places.Cc D. J. Wong <[email protected]>Signed-off-by Guo Chao <[email protected]>
I think this looks ok...
Quoted 73 lines
--- fs/ext4/dir.c | 1 + fs/ext4/namei.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)fs/ext4/dir.c +1
-0@@ -185,6 +185,7 @@ static int ext4_readdir(struct file *filp,"at offset %llu" , (unsigned long long)filp->f_pos); filp->f_pos += sb->s_blocksize - offset; +brelse (bh);continue ; }set_buffer_verified (bh);fs/ext4/namei.c +10
-2@@ -837,6 +837,7 @@ static int ext4_htree_next_block(struct inode *dir, __u32 hash, !ext4_dx_csum_verify(dir, (struct ext4_dir_entry *)bh->b_data)) {ext4_warning (dir->i_sb,"Node failed checksum" ); +brelse (bh);return -EIO ; }set_buffer_verified (bh);@@ -877,8 +878,11 @@ static int htree_dirblock_to_tree(struct file *dir_file, }if (!buffer_verified (bh) && - !ext4_dirent_csum_verify (dir, (struct ext4_dir_entry *)bh->b_data)) + !ext4_dirent_csum_verify (dir, + (struct ext4_dir_entry *)bh->b_data)) { +brelse (bh);return -EIO ; + }set_buffer_verified (bh); de = (struct ext4_dir_entry_2 *) bh->b_data;@@ -1929,8 +1933,10 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, }if (!buffer_verified (bh) && !ext4_dirent_csum_verify (dir, - (struct ext4_dir_entry *)bh->b_data)) + (struct ext4_dir_entry *)bh->b_data)) { +brelse (bh);return -EIO ; + }set_buffer_verified (bh); retval =add_dirent_to_buf (handle, dentry, inode,NULL , bh);if (retval != -ENOSPC ) {@@ -2493,6 +2499,7 @@ static int empty_dir(struct inode *inode) (struct ext4_dir_entry *)bh->b_data)) {EXT4_ERROR_INODE (inode,"checksum error reading directory " "lblock 0" ); +brelse (bh);return -EIO ; }set_buffer_verified (bh);@@ -2537,6 +2544,7 @@ static int empty_dir(struct inode *inode) (struct ext4_dir_entry *)bh->b_data)) {EXT4_ERROR_INODE (inode,"checksum error " "reading directory lblock 0" ); +brelse (bh);return -EIO ; }set_buffer_verified (bh);Signature · 1 line
1.7.9.5
Quoted 10 lines · Darrick J. Wong
Quoted 6 lines · Guo Chao
Commit
b0336e8d(ext4: calculate and verify checksums of directory leaf blocks) and commitdbe89444(ext4: Calculate and verify checksums for htree nodes) forget to release buffer when checksum failed, at some places.Cc D. J. Wong <[email protected]>Signed-off-by Guo Chao <[email protected]>I think this looks ok...
Reviewed-by Darrick J. Wong <[email protected]>
Thanks, applied.
- Ted