Skip to content

Commit 28f5a8a

Browse files
alex chentorvalds
alex chen
authored andcommitted
ocfs2: should wait dio before inode lock in ocfs2_setattr()
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/[email protected] Signed-off-by: Alex Chen <[email protected]> Reviewed-by: Jun Piao <[email protected]> Reviewed-by: Joseph Qi <[email protected]> Acked-by: Changwei Ge <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 67b1b8d commit 28f5a8a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

fs/ocfs2/file.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,13 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
11611161
}
11621162
size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE;
11631163
if (size_change) {
1164+
/*
1165+
* Here we should wait dio to finish before inode lock
1166+
* to avoid a deadlock between ocfs2_setattr() and
1167+
* ocfs2_dio_end_io_write()
1168+
*/
1169+
inode_dio_wait(inode);
1170+
11641171
status = ocfs2_rw_lock(inode, 1);
11651172
if (status < 0) {
11661173
mlog_errno(status);
@@ -1200,8 +1207,6 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
12001207
if (status)
12011208
goto bail_unlock;
12021209

1203-
inode_dio_wait(inode);
1204-
12051210
if (i_size_read(inode) >= attr->ia_size) {
12061211
if (ocfs2_should_order_data(inode)) {
12071212
status = ocfs2_begin_ordered_truncate(inode,

0 commit comments

Comments
 (0)