]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Linux: Fix lock ordering
authorSimon Wilkinson <sxw@inf.ed.ac.uk>
Mon, 16 Nov 2009 22:52:01 +0000 (22:52 +0000)
committerDerrick Brashear <shadow|account-1000005@unknown>
Thu, 17 Dec 2009 06:17:58 +0000 (22:17 -0800)
The inode mutex (or semaphore) should be held before acquiring the
alloc semaphore. Fix the lock ordering to avoid theoretical deadlocks.

Change-Id: Ifc572083dc92fff51be6785b0bcc92152fab1d73
Reviewed-on: http://gerrit.openafs.org/835
Reviewed-by: Marc Dionne <marc.c.dionne@gmail.com>
Tested-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
(cherry picked from commit a2744cab12c87a8c42ba40a9f186a1f05c6886f8)
Reviewed-on: http://gerrit.openafs.org/977

src/afs/LINUX/osi_file.c

index f1dcfc0eafec1ead1117ba286f94f1d807673ca8..e7c3661ccb9a6fe3e7663c59714b8d55d27241b8 100644 (file)
@@ -218,13 +218,13 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
        return code;
     MObtainWriteLock(&afs_xosi, 321);
     AFS_GUNLOCK();
-#ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
-    down_write(&inode->i_alloc_sem);
-#endif
 #ifdef STRUCT_INODE_HAS_I_MUTEX
     mutex_lock(&inode->i_mutex);
 #else
     down(&inode->i_sem);
+#endif
+#ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
+    down_write(&inode->i_alloc_sem);
 #endif
     newattrs.ia_size = asize;
     newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
@@ -260,13 +260,13 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
     }
 #endif
     code = -code;
+#ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
+    up_write(&inode->i_alloc_sem);
+#endif
 #ifdef STRUCT_INODE_HAS_I_MUTEX
     mutex_unlock(&inode->i_mutex);
 #else
     up(&inode->i_sem);
-#endif
-#ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
-    up_write(&inode->i_alloc_sem);
 #endif
     AFS_GLOCK();
     MReleaseWriteLock(&afs_xosi);