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"
25 #include "../afs/sysincludes.h" /* Standard vendor system headers */
26 #include "../afs/afsincludes.h" /* Afs-based standard headers */
27 #include "../afs/afs_stats.h" /* statistics */
28 #include "../afs/afs_cbqueue.h"
29 #include "../afs/nfsclient.h"
30 #include "../afs/afs_osidnlc.h"
32 extern afs_rwlock_t afs_xvcache;
33 extern afs_rwlock_t afs_xcbhash;
35 /* don't set CDirty in here because RPC is called synchronously */
39 struct nameidata *ndp;
40 struct vattr *attrs; {
41 register struct vcache *adp = VTOAFS(ndp->ni_dvp);
42 char *aname = ndp->ni_dent.d_name;
43 register struct vcache **avcp = (struct vcache **)&(ndp->ni_vp);
44 struct ucred *acred = ndp->ni_cred;
45 #else /* AFS_OSF_ENV */
46 afs_mkdir(OSI_VC_ARG(adp), aname, attrs, avcp, acred)
48 register struct vcache **avcp;
51 struct AFS_UCRED *acred; {
54 register afs_int32 code;
55 register struct conn *tc;
56 struct VenusFid newFid;
57 register struct dcache *tdc;
58 afs_size_t offset, len;
59 register struct vcache *tvc;
60 struct AFSStoreStatus InStatus;
61 struct AFSFetchStatus OutFidStatus, OutDirStatus;
62 struct AFSCallBack CallBack;
63 struct AFSVolSync tsync;
68 AFS_STATCNT(afs_mkdir);
69 afs_Trace2(afs_iclSetp, CM_TRACE_MKDIR, ICL_TYPE_POINTER, adp,
70 ICL_TYPE_STRING, aname);
72 if (code = afs_InitReq(&treq, acred))
75 if (strlen(aname) > AFSNAMEMAX) {
80 if (!afs_ENameOK(aname)) {
84 code = afs_VerifyVCache(adp, &treq);
87 /** If the volume is read-only, return error without making an RPC to the
90 if ( adp->states & CRO ) {
95 InStatus.Mask = AFS_SETMODTIME | AFS_SETMODE | AFS_SETGROUP;
96 InStatus.ClientModTime = osi_Time();
97 InStatus.UnixModeBits = attrs->va_mode & 0xffff; /* only care about protection bits */
98 InStatus.Group = (afs_int32)acred->cr_gid;
99 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1);
100 ObtainWriteLock(&adp->lock,153);
102 tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK);
104 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_MAKEDIR);
106 #ifdef RX_ENABLE_LOCKS
108 #endif /* RX_ENABLE_LOCKS */
109 code = RXAFS_MakeDir(tc->id, (struct AFSFid *) &adp->fid.Fid, aname,
110 &InStatus, (struct AFSFid *) &newFid.Fid,
111 &OutFidStatus, &OutDirStatus, &CallBack, &tsync);
112 #ifdef RX_ENABLE_LOCKS
114 #endif /* RX_ENABLE_LOCKS */
116 CallBack.ExpirationTime += now;
117 /* DON'T forget to Set the callback value... */
121 (afs_Analyze(tc, code, &adp->fid, &treq,
122 AFS_STATS_FS_RPCIDX_MAKEDIR, SHARED_LOCK, (struct cell *)0));
126 ObtainWriteLock(&afs_xcbhash, 490);
127 afs_DequeueCallback(adp);
128 adp->states &= ~CStatd;
129 ReleaseWriteLock(&afs_xcbhash);
130 osi_dnlc_purgedp(adp);
132 ReleaseWriteLock(&adp->lock);
133 if (tdc) afs_PutDCache(tdc);
136 /* otherwise, we should see if we can make the change to the dir locally */
137 if (tdc) ObtainWriteLock(&tdc->lock, 632);
138 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
139 /* we can do it locally */
140 code = afs_dir_Create(&tdc->f.inode, aname, &newFid.Fid);
142 ZapDCE(tdc); /* surprise error -- use invalid value */
147 ReleaseWriteLock(&tdc->lock);
150 adp->m.LinkCount = OutDirStatus.LinkCount;
151 newFid.Cell = adp->fid.Cell;
152 newFid.Fid.Volume = adp->fid.Fid.Volume;
153 ReleaseWriteLock(&adp->lock);
154 /* now we're done with parent dir, create the real dir's cache entry */
155 tvc = afs_GetVCache(&newFid, &treq, (afs_int32 *)0, (struct vcache*)0, 0);
162 code = afs_CheckCode(code, &treq, 26);
165 AFS_RELE(ndp->ni_dvp);
166 #endif /* AFS_OSF_ENV */
173 struct nameidata *ndp; {
174 register struct vcache *adp = VTOAFS(ndp->ni_dvp);
175 char *aname = ndp->ni_dent.d_name;
176 struct ucred *acred = ndp->ni_cred;
177 #else /* AFS_OSF_ENV */
178 /* don't set CDirty in here because RPC is called synchronously */
179 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
180 afs_rmdir(OSI_VC_ARG(adp), aname, cdirp, acred)
183 afs_rmdir(adp, aname, acred)
187 struct AFS_UCRED *acred; {
189 struct vrequest treq;
190 register struct dcache *tdc;
191 register struct vcache *tvc = (struct vcache *)0;
192 register afs_int32 code;
193 register struct conn *tc;
194 afs_size_t offset, len;
195 struct AFSFetchStatus OutDirStatus;
196 struct AFSVolSync tsync;
200 AFS_STATCNT(afs_rmdir);
202 afs_Trace2(afs_iclSetp, CM_TRACE_RMDIR, ICL_TYPE_POINTER, adp,
203 ICL_TYPE_STRING, aname);
205 if (code = afs_InitReq(&treq, acred))
208 if (strlen(aname) > AFSNAMEMAX) {
213 code = afs_VerifyVCache(adp, &treq);
216 /** If the volume is read-only, return error without making an RPC to the
219 if ( adp->states & CRO ) {
224 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); /* test for error below */
225 ObtainWriteLock(&adp->lock,154);
226 if (tdc) ObtainSharedLock(&tdc->lock, 633);
227 if (tdc && (adp->states & CForeign)) {
228 struct VenusFid unlinkFid;
230 unlinkFid.Fid.Vnode = 0;
231 code = afs_dir_Lookup(&tdc->f.inode, aname, &unlinkFid.Fid);
235 unlinkFid.Cell = adp->fid.Cell;
236 unlinkFid.Fid.Volume = adp->fid.Fid.Volume;
237 if (unlinkFid.Fid.Unique == 0) {
238 tvc = afs_LookupVCache(&unlinkFid, &treq, &cached,
239 WRITE_LOCK, adp, aname);
241 ObtainReadLock(&afs_xvcache);
242 tvc = afs_FindVCache(&unlinkFid, 1, WRITE_LOCK,
243 0, 1/* do xstats */);
244 ReleaseReadLock(&afs_xvcache);
250 tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK);
252 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEDIR);
253 #ifdef RX_ENABLE_LOCKS
255 #endif /* RX_ENABLE_LOCKS */
256 code = RXAFS_RemoveDir(tc->id, (struct AFSFid *) &adp->fid.Fid,
257 aname, &OutDirStatus, &tsync);
258 #ifdef RX_ENABLE_LOCKS
260 #endif /* RX_ENABLE_LOCKS */
265 (afs_Analyze(tc, code, &adp->fid, &treq,
266 AFS_STATS_FS_RPCIDX_REMOVEDIR, SHARED_LOCK, (struct cell *)0));
270 ReleaseSharedLock(&tdc->lock);
274 ObtainWriteLock(&afs_xcbhash, 491);
275 afs_DequeueCallback(adp);
276 adp->states &= ~CStatd;
277 ReleaseWriteLock(&afs_xcbhash);
278 osi_dnlc_purgedp(adp);
280 ReleaseWriteLock(&adp->lock);
283 /* here if rpc worked; update the in-core link count */
284 adp->m.LinkCount = OutDirStatus.LinkCount;
285 if (tdc) UpgradeSToWLock(&tdc->lock, 634);
286 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
287 /* we can do it locally */
288 code = afs_dir_Delete(&tdc->f.inode, aname);
290 ZapDCE(tdc); /* surprise error -- invalid value */
295 ReleaseWriteLock(&tdc->lock);
296 afs_PutDCache(tdc); /* drop ref count */
301 osi_dnlc_purgedp (tvc); /* get rid of any entries for this directory */
302 afs_symhint_inval(tvc);
304 osi_dnlc_remove (adp, aname, 0);
307 ObtainWriteLock(&tvc->lock,155);
308 tvc->states &= ~CUnique; /* For the dfs xlator */
309 ReleaseWriteLock(&tvc->lock);
310 afs_PutVCache(tvc, WRITE_LOCK);
312 ReleaseWriteLock(&adp->lock);
313 /* don't worry about link count since dirs can not be hardlinked */
317 code = afs_CheckCode(code, &treq, 27);
320 afs_PutVCache(adp, 0);
321 afs_PutVCache(ndp->ni_vp, 0);
322 #endif /* AFS_OSF_ENV */