jbd2: Fix oops in jbd2_journal_file_inode()
Commit 0713ed0cde
added
jbd2_journal_file_inode() call into ext4_block_zero_page_range().
However that function gets called from truncate path and thus inode
needn't have jinode attached - that happens in ext4_file_open() but
the file needn't be ever open since mount. Calling
jbd2_journal_file_inode() without jinode attached results in the oops.
We fix the problem by attaching jinode to inode also in ext4_truncate()
and ext4_punch_hole() when we are going to zero out partial blocks.
Reported-by: majianpeng <majianpeng@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
@@ -219,7 +219,6 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
|
||||
{
|
||||
struct super_block *sb = inode->i_sb;
|
||||
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
|
||||
struct ext4_inode_info *ei = EXT4_I(inode);
|
||||
struct vfsmount *mnt = filp->f_path.mnt;
|
||||
struct path path;
|
||||
char buf[64], *cp;
|
||||
@@ -259,22 +258,10 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
|
||||
* Set up the jbd2_inode if we are opening the inode for
|
||||
* writing and the journal is present
|
||||
*/
|
||||
if (sbi->s_journal && !ei->jinode && (filp->f_mode & FMODE_WRITE)) {
|
||||
struct jbd2_inode *jinode = jbd2_alloc_inode(GFP_KERNEL);
|
||||
|
||||
spin_lock(&inode->i_lock);
|
||||
if (!ei->jinode) {
|
||||
if (!jinode) {
|
||||
spin_unlock(&inode->i_lock);
|
||||
return -ENOMEM;
|
||||
}
|
||||
ei->jinode = jinode;
|
||||
jbd2_journal_init_jbd_inode(ei->jinode, inode);
|
||||
jinode = NULL;
|
||||
}
|
||||
spin_unlock(&inode->i_lock);
|
||||
if (unlikely(jinode != NULL))
|
||||
jbd2_free_inode(jinode);
|
||||
if (filp->f_mode & FMODE_WRITE) {
|
||||
int ret = ext4_inode_attach_jinode(inode);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
return dquot_file_open(inode, filp);
|
||||
}
|
||||
|
Reference in New Issue
Block a user