LINUX: Avoid re-taking global lock in afs_dentry_iput 25/13725/3
authorYadavendra Yadav <yadayada@in.ibm.com>
Fri, 26 Jul 2019 14:29:25 +0000 (19:29 +0530)
committerBenjamin Kaduk <kaduk@mit.edu>
Thu, 1 Aug 2019 02:21:03 +0000 (22:21 -0400)
“dput” function internally can call dentry_iput which  results in
calling afs_dentry_iput. So in case before calling “dput” if global lock
was held then when afs_dentry_iput is called it will again try to lock
global lock and will result in deadlock scenario.  So to avoid this
deadlock make sure if global lock is already taken before calling
afs_dentry_iput, don’t try to lock it again.  This issue was partially
fixed in commit 0dac4de8 (Linux: drop GLOCK before calling dput)

Change-Id: I71f18c58d5254f0cf0c68ef04c22268ed70dd50f
Reviewed-on: https://gerrit.openafs.org/13725
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/afs/LINUX/osi_vnodeops.c

index fad928b..0ca2646 100644 (file)
@@ -1453,12 +1453,20 @@ static void
 afs_dentry_iput(struct dentry *dp, struct inode *ip)
 {
     struct vcache *vcp = VTOAFS(ip);
+    int haveGlock = ISAFS_GLOCK();
+
+    if (!haveGlock) {
+        AFS_GLOCK();
+    }
 
-    AFS_GLOCK();
     if (!AFS_IS_DISCONNECTED || (vcp->f.states & CUnlinked)) {
        (void) afs_InactiveVCache(vcp, NULL);
     }
-    AFS_GUNLOCK();
+
+    if (!haveGlock) {
+        AFS_GUNLOCK();
+    }
+
     afs_linux_clear_nfsfs_renamed(dp);
 
     iput(ip);