From 8f98479170b3ccd684baa7cd8f1abcd08605a123 Mon Sep 17 00:00:00 2001 From: Derrick Brashear Date: Sat, 8 Dec 2007 17:59:06 +0000 Subject: [PATCH] DEVEL15-writedcache-enforce-xdcache-writelock-20071208 LICENSE IPL10 FIXES 59136 in order that the writes to CacheItems not be addled, we need to *actually* hold a *write* lock when we write. not even just read as the comment says. and certainly not none as was happening in the dir package. (cherry picked from commit c0a04c21cf36e4c8e25be9703f715f30d1bf55a6) --- src/afs/VNOPS/afs_vnop_create.c | 2 ++ src/afs/VNOPS/afs_vnop_dirops.c | 2 ++ src/afs/VNOPS/afs_vnop_link.c | 2 ++ src/afs/VNOPS/afs_vnop_rename.c | 2 ++ src/afs/VNOPS/afs_vnop_symlink.c | 2 ++ src/afs/afs_dcache.c | 1 + 6 files changed, 11 insertions(+) diff --git a/src/afs/VNOPS/afs_vnop_create.c b/src/afs/VNOPS/afs_vnop_create.c index fbb33fc273..bdf35a9b43 100644 --- a/src/afs/VNOPS/afs_vnop_create.c +++ b/src/afs/VNOPS/afs_vnop_create.c @@ -353,7 +353,9 @@ afs_create(OSI_VC_DECL(adp), char *aname, struct vattr *attrs, UpgradeSToWLock(&tdc->lock, 631); if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) { /* we can do it locally */ + ObtainWriteLock(&afs_xdcache, 291); code = afs_dir_Create(tdc, aname, &newFid.Fid); + ReleaseWriteLock(&afs_xdcache); if (code) { ZapDCE(tdc); DZap(tdc); diff --git a/src/afs/VNOPS/afs_vnop_dirops.c b/src/afs/VNOPS/afs_vnop_dirops.c index 0079acfe74..5e73dd0d64 100644 --- a/src/afs/VNOPS/afs_vnop_dirops.c +++ b/src/afs/VNOPS/afs_vnop_dirops.c @@ -132,7 +132,9 @@ afs_mkdir(OSI_VC_DECL(adp), char *aname, struct vattr *attrs, ObtainWriteLock(&tdc->lock, 632); if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) { /* we can do it locally */ + ObtainWriteLock(&afs_xdcache, 294); code = afs_dir_Create(tdc, aname, &newFid.Fid); + ReleaseWriteLock(&afs_xdcache); if (code) { ZapDCE(tdc); /* surprise error -- use invalid value */ DZap(tdc); diff --git a/src/afs/VNOPS/afs_vnop_link.c b/src/afs/VNOPS/afs_vnop_link.c index cbd59aabf4..04c08a6dc4 100644 --- a/src/afs/VNOPS/afs_vnop_link.c +++ b/src/afs/VNOPS/afs_vnop_link.c @@ -127,7 +127,9 @@ afs_link(avc, OSI_VC_ARG(adp), aname, acred) ObtainWriteLock(&tdc->lock, 635); if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) { /* we can do it locally */ + ObtainWriteLock(&afs_xdcache, 290); code = afs_dir_Create(tdc, aname, &avc->fid.Fid); + ReleaseWriteLock(&afs_xdcache); if (code) { ZapDCE(tdc); /* surprise error -- invalid value */ DZap(tdc); diff --git a/src/afs/VNOPS/afs_vnop_rename.c b/src/afs/VNOPS/afs_vnop_rename.c index 1af38a21c4..02c67f99c0 100644 --- a/src/afs/VNOPS/afs_vnop_rename.c +++ b/src/afs/VNOPS/afs_vnop_rename.c @@ -227,7 +227,9 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp, code = afs_dir_Delete(tdc2, aname2); } if (code == 0) { + ObtainWriteLock(&afs_xdcache, 292); code = afs_dir_Create(tdc2, aname2, &fileFid.Fid); + ReleaseWriteLock(&afs_xdcache); } if (code != 0) { ZapDCE(tdc1); diff --git a/src/afs/VNOPS/afs_vnop_symlink.c b/src/afs/VNOPS/afs_vnop_symlink.c index fa5a8f4b98..22aa636abc 100644 --- a/src/afs/VNOPS/afs_vnop_symlink.c +++ b/src/afs/VNOPS/afs_vnop_symlink.c @@ -177,7 +177,9 @@ int afs_symlink /* otherwise, we should see if we can make the change to the dir locally */ if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) { /* we can do it locally */ + ObtainWriteLock(&afs_xdcache, 293); code = afs_dir_Create(tdc, aname, &newFid.Fid); + ReleaseWriteLock(&afs_xdcache); if (code) { ZapDCE(tdc); /* surprise error -- use invalid value */ DZap(tdc); diff --git a/src/afs/afs_dcache.c b/src/afs/afs_dcache.c index 1e645a1b43..3801328af6 100644 --- a/src/afs/afs_dcache.c +++ b/src/afs/afs_dcache.c @@ -3073,6 +3073,7 @@ afs_WriteDCache(register struct dcache *adc, int atime) if (cacheDiskType == AFS_FCACHE_TYPE_MEM) return 0; AFS_STATCNT(afs_WriteDCache); + osi_Assert(WriteLocked(&afs_xdcache)); if (atime) adc->f.modTime = osi_Time(); /*