From fa97579a08cdf23fcff3c50a5845d72a785feeaf Mon Sep 17 00:00:00 2001 From: Matt Benjamin Date: Wed, 24 Aug 2011 16:23:37 -0400 Subject: [PATCH 1/1] LINUX vcache lock ordering in afs_linux_readdir Normalize shared and exclusive lock operations. Take the lock exclusive immediately, since the code assumes a write lock if the vcache state is in flux or the entry is being fetched, releasing -write- rather than shared, since we do not hold a shared lock. Change-Id: Icbffdf21c6fc7929483589e87ffe9131834c79b4 Reviewed-on: http://gerrit.openafs.org/5309 Tested-by: BuildBot Reviewed-by: Simon Wilkinson Reviewed-by: Derrick Brashear --- src/afs/LINUX/osi_vnodeops.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/afs/LINUX/osi_vnodeops.c b/src/afs/LINUX/osi_vnodeops.c index f7d5277..57dc081 100644 --- a/src/afs/LINUX/osi_vnodeops.c +++ b/src/afs/LINUX/osi_vnodeops.c @@ -296,8 +296,7 @@ afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir) code = -ENOENT; goto out; } - ObtainSharedLock(&avc->lock, 810); - UpgradeSToWLock(&avc->lock, 811); + ObtainWriteLock(&avc->lock, 811); ObtainReadLock(&tdc->lock); /* * Make sure that the data in the cache is current. There are two @@ -309,15 +308,15 @@ afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir) && (tdc->dflags & DFFetching) && hsame(avc->f.m.DataVersion, tdc->f.versionNo)) { ReleaseReadLock(&tdc->lock); - ReleaseSharedLock(&avc->lock); + ReleaseWriteLock(&avc->lock); afs_osi_Sleep(&tdc->validPos); - ObtainSharedLock(&avc->lock, 812); + ObtainWriteLock(&avc->lock, 812); ObtainReadLock(&tdc->lock); } if (!(avc->f.states & CStatd) || !hsame(avc->f.m.DataVersion, tdc->f.versionNo)) { ReleaseReadLock(&tdc->lock); - ReleaseSharedLock(&avc->lock); + ReleaseWriteLock(&avc->lock); afs_PutDCache(tdc); goto tagain; } -- 1.9.4