From: Matt Benjamin Date: Wed, 24 Aug 2011 20:23:37 +0000 (-0400) Subject: LINUX vcache lock ordering in afs_linux_readdir X-Git-Tag: openafs-devel-1_7_1~112 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=fa97579a08cdf23fcff3c50a5845d72a785feeaf 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 --- 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; }