Commit 55f57d2c authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: fix double lock in handle_failed_inode

In handle_failed_inode, there is a potential deadlock which can happen
in below call path:

- f2fs_create
 - f2fs_lock_op   down_read(cp_rwsem)
 - f2fs_add_link
  - __f2fs_add_link
   - init_inode_metadata
    - f2fs_init_security    failed
    - truncate_blocks    failed
 - handle_failed_inode
  - f2fs_truncate
   - truncate_blocks(..,true)
					- write_checkpoint
					 - block_operations
					  - f2fs_lock_all  down_write(cp_rwsem)
    - f2fs_lock_op   down_read(cp_rwsem)

So in this path, we pass parameter to f2fs_truncate to make sure
cp_rwsem in truncate_blocks will not be locked again.
Signed-off-by: default avatarChao Yu <chao2.yu@samsung.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent ecbaa406
...@@ -1579,7 +1579,7 @@ static inline bool f2fs_may_extent_tree(struct inode *inode) ...@@ -1579,7 +1579,7 @@ static inline bool f2fs_may_extent_tree(struct inode *inode)
int f2fs_sync_file(struct file *, loff_t, loff_t, int); int f2fs_sync_file(struct file *, loff_t, loff_t, int);
void truncate_data_blocks(struct dnode_of_data *); void truncate_data_blocks(struct dnode_of_data *);
int truncate_blocks(struct inode *, u64, bool); int truncate_blocks(struct inode *, u64, bool);
void f2fs_truncate(struct inode *); void f2fs_truncate(struct inode *, bool);
int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
int f2fs_setattr(struct dentry *, struct iattr *); int f2fs_setattr(struct dentry *, struct iattr *);
int truncate_hole(struct inode *, pgoff_t, pgoff_t); int truncate_hole(struct inode *, pgoff_t, pgoff_t);
......
...@@ -579,7 +579,7 @@ int truncate_blocks(struct inode *inode, u64 from, bool lock) ...@@ -579,7 +579,7 @@ int truncate_blocks(struct inode *inode, u64 from, bool lock)
return err; return err;
} }
void f2fs_truncate(struct inode *inode) void f2fs_truncate(struct inode *inode, bool lock)
{ {
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
S_ISLNK(inode->i_mode))) S_ISLNK(inode->i_mode)))
...@@ -593,7 +593,7 @@ void f2fs_truncate(struct inode *inode) ...@@ -593,7 +593,7 @@ void f2fs_truncate(struct inode *inode)
return; return;
} }
if (!truncate_blocks(inode, i_size_read(inode), true)) { if (!truncate_blocks(inode, i_size_read(inode), lock)) {
inode->i_mtime = inode->i_ctime = CURRENT_TIME; inode->i_mtime = inode->i_ctime = CURRENT_TIME;
mark_inode_dirty(inode); mark_inode_dirty(inode);
} }
...@@ -656,7 +656,7 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -656,7 +656,7 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
if (attr->ia_size <= i_size_read(inode)) { if (attr->ia_size <= i_size_read(inode)) {
truncate_setsize(inode, attr->ia_size); truncate_setsize(inode, attr->ia_size);
f2fs_truncate(inode); f2fs_truncate(inode, true);
f2fs_balance_fs(F2FS_I_SB(inode)); f2fs_balance_fs(F2FS_I_SB(inode));
} else { } else {
/* /*
......
...@@ -343,7 +343,7 @@ void f2fs_evict_inode(struct inode *inode) ...@@ -343,7 +343,7 @@ void f2fs_evict_inode(struct inode *inode)
i_size_write(inode, 0); i_size_write(inode, 0);
if (F2FS_HAS_BLOCKS(inode)) if (F2FS_HAS_BLOCKS(inode))
f2fs_truncate(inode); f2fs_truncate(inode, true);
f2fs_lock_op(sbi); f2fs_lock_op(sbi);
remove_inode_page(inode); remove_inode_page(inode);
...@@ -385,7 +385,7 @@ void handle_failed_inode(struct inode *inode) ...@@ -385,7 +385,7 @@ void handle_failed_inode(struct inode *inode)
i_size_write(inode, 0); i_size_write(inode, 0);
if (F2FS_HAS_BLOCKS(inode)) if (F2FS_HAS_BLOCKS(inode))
f2fs_truncate(inode); f2fs_truncate(inode, false);
remove_inode_page(inode); remove_inode_page(inode);
......
...@@ -467,7 +467,7 @@ static int f2fs_drop_inode(struct inode *inode) ...@@ -467,7 +467,7 @@ static int f2fs_drop_inode(struct inode *inode)
i_size_write(inode, 0); i_size_write(inode, 0);
if (F2FS_HAS_BLOCKS(inode)) if (F2FS_HAS_BLOCKS(inode))
f2fs_truncate(inode); f2fs_truncate(inode, true);
sb_end_intwrite(inode->i_sb); sb_end_intwrite(inode->i_sb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment