From 25e708f0f5ebe01060b3f40123b3aeeec8d76bb1 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Mon, 16 Nov 2009 22:52:01 +0000 Subject: [PATCH] Linux: Fix lock ordering 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 Tested-by: Derrick Brashear Reviewed-by: Derrick Brashear (cherry picked from commit a2744cab12c87a8c42ba40a9f186a1f05c6886f8) Reviewed-on: http://gerrit.openafs.org/977 --- src/afs/LINUX/osi_file.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/afs/LINUX/osi_file.c b/src/afs/LINUX/osi_file.c index f1dcfc0ea..e7c3661cc 100644 --- a/src/afs/LINUX/osi_file.c +++ b/src/afs/LINUX/osi_file.c @@ -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); -- 2.39.5