From: Michael Vrable Date: Wed, 10 Mar 2010 22:47:04 +0000 (-0800) Subject: Refine lock acquisition order for renames. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=686e1d6fc137595d249d1d6794d8932f86345646;p=bluesky.git Refine lock acquisition order for renames. --- diff --git a/nfs3/nfs3.c b/nfs3/nfs3.c index 818cd4b..33ca180 100644 --- a/nfs3/nfs3.c +++ b/nfs3/nfs3.c @@ -754,17 +754,22 @@ void nfsproc3_rename_3_svc(rename3args *argp, RPCRequest *req) async_rpc_send_reply(req, &result); return; } - g_mutex_lock(dir1->lock); - encode_pre_wcc(wcc1, dir1); BlueSkyInode *dir2 = lookup_fh(req, &argp->to.dir); if (dir2 == NULL) { result.status = NFS3ERR_STALE; - g_mutex_unlock(dir1->lock); async_rpc_send_reply(req, &result); return; } - g_mutex_lock(dir2->lock); + + if (dir1->inum < dir2->inum) { + g_mutex_lock(dir1->lock); + g_mutex_lock(dir2->lock); + } else if (dir1->inum > dir2->inum) { + g_mutex_lock(dir2->lock); + g_mutex_lock(dir1->lock); + } + encode_pre_wcc(wcc1, dir1); encode_pre_wcc(wcc2, dir1); gboolean status = bluesky_rename(dir1, argp->from.name, @@ -780,8 +785,9 @@ void nfsproc3_rename_3_svc(rename3args *argp, RPCRequest *req) else result.status = NFS3ERR_PERM; - g_mutex_unlock(dir2->lock); g_mutex_unlock(dir1->lock); + if (dir1->inum != dir2->inum) + g_mutex_unlock(dir2->lock); async_rpc_send_reply(req, &result); }