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 */
40 struct nameidata *ndp;
43 register struct vcache *adp = VTOAFS(ndp->ni_dvp);
44 char *aname = ndp->ni_dent.d_name;
45 register struct vcache **avcp = (struct vcache **)&(ndp->ni_vp);
46 struct ucred *acred = ndp->ni_cred;
47 #else /* AFS_OSF_ENV */
48 afs_mkdir(OSI_VC_ARG(adp), aname, attrs, avcp, acred)
50 register struct vcache **avcp;
53 struct AFS_UCRED *acred;
57 register afs_int32 code;
58 register struct conn *tc;
59 struct VenusFid newFid;
60 register struct dcache *tdc;
61 afs_size_t offset, len;
62 register struct vcache *tvc;
63 struct AFSStoreStatus InStatus;
64 struct AFSFetchStatus OutFidStatus, OutDirStatus;
65 struct AFSCallBack CallBack;
66 struct AFSVolSync tsync;
68 struct afs_fakestat_state fakestate;
69 XSTATS_DECLS OSI_VC_CONVERT(adp)
71 AFS_STATCNT(afs_mkdir);
72 afs_Trace2(afs_iclSetp, CM_TRACE_MKDIR, ICL_TYPE_POINTER, adp,
73 ICL_TYPE_STRING, aname);
75 if ((code = afs_InitReq(&treq, acred)))
77 afs_InitFakeStat(&fakestate);
79 if (strlen(aname) > AFSNAMEMAX) {
84 if (!afs_ENameOK(aname)) {
88 code = afs_EvalFakeStat(&adp, &fakestate, &treq);
91 code = afs_VerifyVCache(adp, &treq);
95 /** If the volume is read-only, return error without making an RPC to the
98 if (adp->states & CRO) {
103 InStatus.Mask = AFS_SETMODTIME | AFS_SETMODE | AFS_SETGROUP;
104 InStatus.ClientModTime = osi_Time();
105 InStatus.UnixModeBits = attrs->va_mode & 0xffff; /* only care about protection bits */
106 InStatus.Group = (afs_int32) acred->cr_gid;
107 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1);
108 ObtainWriteLock(&adp->lock, 153);
110 tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK);
112 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_MAKEDIR);
116 RXAFS_MakeDir(tc->id, (struct AFSFid *)&adp->fid.Fid, aname,
117 &InStatus, (struct AFSFid *)&newFid.Fid,
118 &OutFidStatus, &OutDirStatus, &CallBack,
122 CallBack.ExpirationTime += now;
123 /* DON'T forget to Set the callback value... */
127 (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_MAKEDIR,
132 ObtainWriteLock(&afs_xcbhash, 490);
133 afs_DequeueCallback(adp);
134 adp->states &= ~CStatd;
135 ReleaseWriteLock(&afs_xcbhash);
136 osi_dnlc_purgedp(adp);
138 ReleaseWriteLock(&adp->lock);
143 /* otherwise, we should see if we can make the change to the dir locally */
145 ObtainWriteLock(&tdc->lock, 632);
146 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
147 /* we can do it locally */
148 code = afs_dir_Create(&tdc->f.inode, aname, &newFid.Fid);
150 ZapDCE(tdc); /* surprise error -- use invalid value */
155 ReleaseWriteLock(&tdc->lock);
158 adp->m.LinkCount = OutDirStatus.LinkCount;
159 newFid.Cell = adp->fid.Cell;
160 newFid.Fid.Volume = adp->fid.Fid.Volume;
161 ReleaseWriteLock(&adp->lock);
162 /* now we're done with parent dir, create the real dir's cache entry */
163 tvc = afs_GetVCache(&newFid, &treq, NULL, NULL);
170 afs_PutFakeStat(&fakestate);
171 code = afs_CheckCode(code, &treq, 26);
174 AFS_RELE(ndp->ni_dvp);
175 #endif /* AFS_OSF_ENV */
182 struct nameidata *ndp;
184 register struct vcache *adp = VTOAFS(ndp->ni_dvp);
185 char *aname = ndp->ni_dent.d_name;
186 struct ucred *acred = ndp->ni_cred;
187 #else /* AFS_OSF_ENV */
188 /* don't set CDirty in here because RPC is called synchronously */
189 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
190 afs_rmdir(OSI_VC_ARG(adp), aname, cdirp, acred)
193 afs_rmdir(adp, aname, acred)
197 struct AFS_UCRED *acred;
200 struct vrequest treq;
201 register struct dcache *tdc;
202 register struct vcache *tvc = NULL;
203 register afs_int32 code;
204 register struct conn *tc;
205 afs_size_t offset, len;
206 struct AFSFetchStatus OutDirStatus;
207 struct AFSVolSync tsync;
208 struct afs_fakestat_state fakestate;
209 XSTATS_DECLS OSI_VC_CONVERT(adp)
211 AFS_STATCNT(afs_rmdir);
213 afs_Trace2(afs_iclSetp, CM_TRACE_RMDIR, ICL_TYPE_POINTER, adp,
214 ICL_TYPE_STRING, aname);
216 if ((code = afs_InitReq(&treq, acred)))
218 afs_InitFakeStat(&fakestate);
220 if (strlen(aname) > AFSNAMEMAX) {
225 code = afs_EvalFakeStat(&adp, &fakestate, &treq);
229 code = afs_VerifyVCache(adp, &treq);
233 /** If the volume is read-only, return error without making an RPC to the
236 if (adp->states & CRO) {
241 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); /* test for error below */
242 ObtainWriteLock(&adp->lock, 154);
244 ObtainSharedLock(&tdc->lock, 633);
245 if (tdc && (adp->states & CForeign)) {
246 struct VenusFid unlinkFid;
248 unlinkFid.Fid.Vnode = 0;
249 code = afs_dir_Lookup(&tdc->f.inode, aname, &unlinkFid.Fid);
251 afs_int32 cached = 0;
253 unlinkFid.Cell = adp->fid.Cell;
254 unlinkFid.Fid.Volume = adp->fid.Fid.Volume;
255 if (unlinkFid.Fid.Unique == 0) {
257 afs_LookupVCache(&unlinkFid, &treq, &cached, adp, aname);
259 ObtainReadLock(&afs_xvcache);
260 tvc = afs_FindVCache(&unlinkFid, 0, 1 /* do xstats */ );
261 ReleaseReadLock(&afs_xvcache);
267 tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK);
269 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEDIR);
272 RXAFS_RemoveDir(tc->id, (struct AFSFid *)&adp->fid.Fid, aname,
273 &OutDirStatus, &tsync);
279 (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_REMOVEDIR,
284 ReleaseSharedLock(&tdc->lock);
288 ObtainWriteLock(&afs_xcbhash, 491);
289 afs_DequeueCallback(adp);
290 adp->states &= ~CStatd;
291 ReleaseWriteLock(&afs_xcbhash);
292 osi_dnlc_purgedp(adp);
294 ReleaseWriteLock(&adp->lock);
297 /* here if rpc worked; update the in-core link count */
298 adp->m.LinkCount = OutDirStatus.LinkCount;
300 UpgradeSToWLock(&tdc->lock, 634);
301 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
302 /* we can do it locally */
303 code = afs_dir_Delete(&tdc->f.inode, aname);
305 ZapDCE(tdc); /* surprise error -- invalid value */
310 ReleaseWriteLock(&tdc->lock);
311 afs_PutDCache(tdc); /* drop ref count */
316 osi_dnlc_purgedp(tvc); /* get rid of any entries for this directory */
317 afs_symhint_inval(tvc);
319 osi_dnlc_remove(adp, aname, 0);
322 ObtainWriteLock(&tvc->lock, 155);
323 tvc->states &= ~CUnique; /* For the dfs xlator */
324 ReleaseWriteLock(&tvc->lock);
327 ReleaseWriteLock(&adp->lock);
328 /* don't worry about link count since dirs can not be hardlinked */
332 afs_PutFakeStat(&fakestate);
333 code = afs_CheckCode(code, &treq, 27);
337 afs_PutVCache(ndp->ni_vp);
338 #endif /* AFS_OSF_ENV */