From 686e1d6fc137595d249d1d6794d8932f86345646 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Wed, 10 Mar 2010 14:47:04 -0800 Subject: [PATCH] Refine lock acquisition order for renames. --- nfs3/nfs3.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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); } -- 2.20.1