From: Simon Wilkinson Date: Mon, 16 Nov 2009 22:52:01 +0000 (+0000) Subject: Linux: Fix lock ordering X-Git-Tag: openafs-devel-1_5_67~43 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=a2744cab12c87a8c42ba40a9f186a1f05c6886f8 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 --- diff --git a/src/afs/LINUX/osi_file.c b/src/afs/LINUX/osi_file.c index 378cda8..a1eebe3 100644 --- a/src/afs/LINUX/osi_file.c +++ b/src/afs/LINUX/osi_file.c @@ -191,14 +191,14 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize) return code; ObtainWriteLock(&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; newattrs.ia_ctime = CURRENT_TIME; @@ -220,14 +220,14 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize) if (!code) truncate_inode_pages(&inode->i_data, asize); 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(); ReleaseWriteLock(&afs_xosi); return code;