Skip to content

Commit c4baa4a

Browse files
alex chengregkh
authored andcommitted
ocfs2: should wait dio before inode lock in ocfs2_setattr()
commit 28f5a8a7c033cbf3e32277f4cc9c6afd74f05300 upstream. we should wait dio requests to finish before inode lock in ocfs2_setattr(), otherwise the following deadlock will happen: process 1 process 2 process 3 truncate file 'A' end_io of writing file 'A' receiving the bast messages ocfs2_setattr ocfs2_inode_lock_tracker ocfs2_inode_lock_full inode_dio_wait __inode_dio_wait -->waiting for all dio requests finish dlm_proxy_ast_handler dlm_do_local_bast ocfs2_blocking_ast ocfs2_generic_handle_bast set OCFS2_LOCK_BLOCKED flag dio_end_io dio_bio_end_aio dio_complete ocfs2_dio_end_io ocfs2_dio_end_io_write ocfs2_inode_lock __ocfs2_cluster_lock ocfs2_wait_for_mask -->waiting for OCFS2_LOCK_BLOCKED flag to be cleared, that is waiting for 'process 1' unlocking the inode lock inode_dio_end -->here dec the i_dio_count, but will never be called, so a deadlock happened. Link: http://lkml.kernel.org/r/59F81636.70508@huawei.com Signed-off-by: Alex Chen <alex.chen@huawei.com> Reviewed-by: Jun Piao <piaojun@huawei.com> Reviewed-by: Joseph Qi <jiangqi903@gmail.com> Acked-by: Changwei Ge <ge.changwei@h3c.com> Cc: Mark Fasheh <mfasheh@versity.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8c32577 commit c4baa4a

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

fs/ocfs2/file.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,13 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
11661166
}
11671167
size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE;
11681168
if (size_change) {
1169+
/*
1170+
* Here we should wait dio to finish before inode lock
1171+
* to avoid a deadlock between ocfs2_setattr() and
1172+
* ocfs2_dio_end_io_write()
1173+
*/
1174+
inode_dio_wait(inode);
1175+
11691176
status = ocfs2_rw_lock(inode, 1);
11701177
if (status < 0) {
11711178
mlog_errno(status);
@@ -1186,8 +1193,6 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
11861193
if (status)
11871194
goto bail_unlock;
11881195

1189-
inode_dio_wait(inode);
1190-
11911196
if (i_size_read(inode) >= attr->ia_size) {
11921197
if (ocfs2_should_order_data(inode)) {
11931198
status = ocfs2_begin_ordered_truncate(inode,

0 commit comments

Comments
 (0)