2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * afs_vnop_dirops.c - make and remove directories
20 #include <afsconfig.h>
21 #include "afs/param.h"
26 #include "afs/sysincludes.h" /* Standard vendor system headers */
27 #include "afsincludes.h" /* Afs-based standard headers */
28 #include "afs/afs_stats.h" /* statistics */
29 #include "afs/afs_cbqueue.h"
30 #include "afs/nfsclient.h"
31 #include "afs/afs_osidnlc.h"
33 extern afs_rwlock_t afs_xvcache;
34 extern afs_rwlock_t afs_xcbhash;
36 /* don't set CDirty in here because RPC is called synchronously */
39 afs_mkdir(OSI_VC_DECL(adp), char *aname, struct vattr *attrs,
40 register struct vcache **avcp, struct AFS_UCRED *acred)
43 register afs_int32 code;
44 register struct conn *tc;
45 struct VenusFid newFid;
46 register struct dcache *tdc;
47 afs_size_t offset, len;
48 register struct vcache *tvc;
49 struct AFSStoreStatus InStatus;
50 struct AFSFetchStatus OutFidStatus, OutDirStatus;
51 struct AFSCallBack CallBack;
52 struct AFSVolSync tsync;
54 struct afs_fakestat_state fakestate;
58 AFS_STATCNT(afs_mkdir);
59 afs_Trace2(afs_iclSetp, CM_TRACE_MKDIR, ICL_TYPE_POINTER, adp,
60 ICL_TYPE_STRING, aname);
62 if ((code = afs_InitReq(&treq, acred)))
64 afs_InitFakeStat(&fakestate);
66 if (strlen(aname) > AFSNAMEMAX) {
71 if (!afs_ENameOK(aname)) {
75 code = afs_EvalFakeStat(&adp, &fakestate, &treq);
78 code = afs_VerifyVCache(adp, &treq);
82 /** If the volume is read-only, return error without making an RPC to the
85 if (adp->states & CRO) {
90 InStatus.Mask = AFS_SETMODTIME | AFS_SETMODE | AFS_SETGROUP;
91 InStatus.ClientModTime = osi_Time();
92 InStatus.UnixModeBits = attrs->va_mode & 0xffff; /* only care about protection bits */
93 InStatus.Group = (afs_int32) acred->cr_gid;
94 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1);
95 ObtainWriteLock(&adp->lock, 153);
97 tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK);
99 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_MAKEDIR);
103 RXAFS_MakeDir(tc->id, (struct AFSFid *)&adp->fid.Fid, aname,
104 &InStatus, (struct AFSFid *)&newFid.Fid,
105 &OutFidStatus, &OutDirStatus, &CallBack,
109 CallBack.ExpirationTime += now;
110 /* DON'T forget to Set the callback value... */
114 (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_MAKEDIR,
119 ObtainWriteLock(&afs_xcbhash, 490);
120 afs_DequeueCallback(adp);
121 adp->states &= ~CStatd;
122 ReleaseWriteLock(&afs_xcbhash);
123 osi_dnlc_purgedp(adp);
125 ReleaseWriteLock(&adp->lock);
130 /* otherwise, we should see if we can make the change to the dir locally */
132 ObtainWriteLock(&tdc->lock, 632);
133 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
134 /* we can do it locally */
135 code = afs_dir_Create(tdc, aname, &newFid.Fid);
137 ZapDCE(tdc); /* surprise error -- use invalid value */
142 ReleaseWriteLock(&tdc->lock);
145 adp->m.LinkCount = OutDirStatus.LinkCount;
146 newFid.Cell = adp->fid.Cell;
147 newFid.Fid.Volume = adp->fid.Fid.Volume;
148 ReleaseWriteLock(&adp->lock);
149 /* now we're done with parent dir, create the real dir's cache entry */
150 tvc = afs_GetVCache(&newFid, &treq, NULL, NULL);
157 afs_PutFakeStat(&fakestate);
158 code = afs_CheckCode(code, &treq, 26);
165 /* don't set CDirty in here because RPC is called synchronously */
166 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
167 afs_rmdir(OSI_VC_DECL(adp), char *aname, struct vnode *cdirp,
168 struct AFS_UCRED *acred)
170 afs_rmdir(OSI_VC_DECL(adp), char *aname, struct AFS_UCRED *acred)
173 struct vrequest treq;
174 register struct dcache *tdc;
175 register struct vcache *tvc = NULL;
176 register afs_int32 code;
177 register struct conn *tc;
178 afs_size_t offset, len;
179 struct AFSFetchStatus OutDirStatus;
180 struct AFSVolSync tsync;
181 struct afs_fakestat_state fakestate;
185 AFS_STATCNT(afs_rmdir);
187 afs_Trace2(afs_iclSetp, CM_TRACE_RMDIR, ICL_TYPE_POINTER, adp,
188 ICL_TYPE_STRING, aname);
190 if ((code = afs_InitReq(&treq, acred)))
192 afs_InitFakeStat(&fakestate);
194 if (strlen(aname) > AFSNAMEMAX) {
199 code = afs_EvalFakeStat(&adp, &fakestate, &treq);
203 code = afs_VerifyVCache(adp, &treq);
207 /** If the volume is read-only, return error without making an RPC to the
210 if (adp->states & CRO) {
215 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); /* test for error below */
216 ObtainWriteLock(&adp->lock, 154);
218 ObtainSharedLock(&tdc->lock, 633);
219 if (tdc && (adp->states & CForeign)) {
220 struct VenusFid unlinkFid;
222 unlinkFid.Fid.Vnode = 0;
223 code = afs_dir_Lookup(tdc, aname, &unlinkFid.Fid);
225 afs_int32 cached = 0;
227 unlinkFid.Cell = adp->fid.Cell;
228 unlinkFid.Fid.Volume = adp->fid.Fid.Volume;
229 if (unlinkFid.Fid.Unique == 0) {
231 afs_LookupVCache(&unlinkFid, &treq, &cached, adp, aname);
233 ObtainReadLock(&afs_xvcache);
234 tvc = afs_FindVCache(&unlinkFid, 0, 1 /* do xstats */ );
235 ReleaseReadLock(&afs_xvcache);
241 tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK);
243 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEDIR);
246 RXAFS_RemoveDir(tc->id, (struct AFSFid *)&adp->fid.Fid, aname,
247 &OutDirStatus, &tsync);
253 (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_REMOVEDIR,
258 ReleaseSharedLock(&tdc->lock);
262 ObtainWriteLock(&afs_xcbhash, 491);
263 afs_DequeueCallback(adp);
264 adp->states &= ~CStatd;
265 ReleaseWriteLock(&afs_xcbhash);
266 osi_dnlc_purgedp(adp);
268 ReleaseWriteLock(&adp->lock);
271 /* here if rpc worked; update the in-core link count */
272 adp->m.LinkCount = OutDirStatus.LinkCount;
274 UpgradeSToWLock(&tdc->lock, 634);
275 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
276 /* we can do it locally */
277 code = afs_dir_Delete(tdc, aname);
279 ZapDCE(tdc); /* surprise error -- invalid value */
284 ReleaseWriteLock(&tdc->lock);
285 afs_PutDCache(tdc); /* drop ref count */
290 osi_dnlc_purgedp(tvc); /* get rid of any entries for this directory */
291 afs_symhint_inval(tvc);
293 osi_dnlc_remove(adp, aname, 0);
296 ObtainWriteLock(&tvc->lock, 155);
297 tvc->states &= ~CUnique; /* For the dfs xlator */
298 ReleaseWriteLock(&tvc->lock);
301 ReleaseWriteLock(&adp->lock);
302 /* don't worry about link count since dirs can not be hardlinked */
306 afs_PutFakeStat(&fakestate);
307 code = afs_CheckCode(code, &treq, 27);