diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index 98d36548153dc3696619b2923e2eecce35bd6bbc..bbb4b3e5b4ffc5bbf52fc5d4206f52995a988ea1 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -1842,6 +1842,16 @@ int ocfs2_write_begin_nolock(struct address_space *mapping, ocfs2_commit_trans(osb, handle); out: + /* + * The mmapped page won't be unlocked in ocfs2_free_write_ctxt(), + * even in case of error here like ENOSPC and ENOMEM. So, we need + * to unlock the target page manually to prevent deadlocks when + * retrying again on ENOSPC, or when returning non-VM_FAULT_LOCKED + * to VM code. + */ + if (wc->w_target_locked) + unlock_page(mmap_page); + ocfs2_free_write_ctxt(inode, wc); if (data_ac) {