Skip to content

Commit

Permalink
ocfs2: Fix possible deadlock in quota recovery
Browse files Browse the repository at this point in the history
In ocfs2_finish_quota_recovery() we acquired global quota file lock and started
recovering local quota file. During this process we need to get quota
structures, which calls ocfs2_dquot_acquire() which gets global quota file lock
again. This second lock can block in case some other node has requested the
quota file lock in the mean time. Fix the problem by moving quota file locking
down into the function where it is really needed.  Then dqget() or dqput()
won't be called with the lock held.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Joel Becker <joel.becker@oracle.com>
  • Loading branch information
Jan Kara authored and Joel Becker committed Jun 4, 2009
1 parent 65bac57 commit 80d73f1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions fs/ocfs2/quota_local.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,6 @@ static int ocfs2_recover_local_quota_file(struct inode *lqinode,

mlog_entry("ino=%lu type=%u", (unsigned long)lqinode->i_ino, type);

status = ocfs2_lock_global_qf(oinfo, 1);
if (status < 0)
goto out;

list_for_each_entry_safe(rchunk, next, &(rec->r_list[type]), rc_list) {
chunk = rchunk->rc_chunk;
hbh = NULL;
Expand Down Expand Up @@ -480,12 +476,18 @@ static int ocfs2_recover_local_quota_file(struct inode *lqinode,
type);
goto out_put_bh;
}
status = ocfs2_lock_global_qf(oinfo, 1);
if (status < 0) {
mlog_errno(status);
goto out_put_dquot;
}

handle = ocfs2_start_trans(OCFS2_SB(sb),
OCFS2_QSYNC_CREDITS);
if (IS_ERR(handle)) {
status = PTR_ERR(handle);
mlog_errno(status);
goto out_put_dquot;
goto out_drop_lock;
}
mutex_lock(&sb_dqopt(sb)->dqio_mutex);
spin_lock(&dq_data_lock);
Expand Down Expand Up @@ -523,6 +525,8 @@ static int ocfs2_recover_local_quota_file(struct inode *lqinode,
out_commit:
mutex_unlock(&sb_dqopt(sb)->dqio_mutex);
ocfs2_commit_trans(OCFS2_SB(sb), handle);
out_drop_lock:
ocfs2_unlock_global_qf(oinfo, 1);
out_put_dquot:
dqput(dquot);
out_put_bh:
Expand All @@ -537,8 +541,6 @@ static int ocfs2_recover_local_quota_file(struct inode *lqinode,
if (status < 0)
break;
}
ocfs2_unlock_global_qf(oinfo, 1);
out:
if (status < 0)
free_recovery_list(&(rec->r_list[type]));
mlog_exit(status);
Expand Down

0 comments on commit 80d73f1

Please sign in to comment.