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_symlink.c - symlink and readlink vnodeops.
21 #include "../afs/param.h" /* Should be always first */
22 #include "../afs/sysincludes.h" /* Standard vendor system headers */
23 #include "../afs/afsincludes.h" /* Afs-based standard headers */
24 #include "../afs/afs_stats.h" /* statistics */
25 #include "../afs/afs_cbqueue.h"
26 #include "../afs/nfsclient.h"
27 #include "../afs/afs_osidnlc.h"
29 extern afs_rwlock_t afs_xvcache;
30 extern afs_rwlock_t afs_xcbhash;
32 /* Note: There is the bare bones beginning of symlink hints in the now
33 * defunct afs/afs_lookup.c file. Since they are not in use, making the call
34 * is just a performance hit.
38 /* don't set CDirty in here because RPC is called synchronously */
41 (ndp, attrs, atargetName)
42 struct nameidata *ndp;
44 register char *atargetName; {
45 register struct vcache *adp = (struct vcache *)ndp->ni_dvp;
46 char *aname = ndp->ni_dent.d_name;
47 struct ucred *acred = ndp->ni_cred;
48 #else /* AFS_OSF_ENV */
49 (OSI_VC_ARG(adp), aname, attrs, atargetName, acred)
54 struct AFS_UCRED *acred; {
60 struct VenusFid newFid;
62 afs_int32 offset, len, alen;
63 struct server *hostp=0;
65 struct AFSStoreStatus InStatus;
66 struct AFSFetchStatus OutFidStatus, OutDirStatus;
67 struct AFSCallBack CallBack;
68 struct AFSVolSync tsync;
69 struct volume* volp=0;
73 AFS_STATCNT(afs_symlink);
74 afs_Trace2(afs_iclSetp, CM_TRACE_SYMLINK, ICL_TYPE_POINTER, adp,
75 ICL_TYPE_STRING, aname);
76 if (code = afs_InitReq(&treq, acred))
79 code = afs_VerifyVCache(adp, &treq);
81 code = afs_CheckCode(code, &treq, 30);
85 /** If the volume is read-only, return error without making an RPC to the
88 if ( adp->states & CRO ) {
93 InStatus.Mask = AFS_SETMODTIME | AFS_SETMODE;
94 InStatus.ClientModTime = osi_Time();
95 alen = strlen(atargetName); /* we want it to include the null */
96 if (*atargetName == '#' || *atargetName == '%') {
97 InStatus.UnixModeBits = 0644; /* mt pt: null from "." at end */
98 if (alen == 1) alen++; /* Empty string */
100 InStatus.UnixModeBits = 0755;
101 alen++; /* add in the null */
103 tdc = afs_GetDCache(adp, 0, &treq, &offset, &len, 1);
104 volp = afs_FindVolume(&adp->fid, READ_LOCK); /*parent is also in same vol*/
105 ObtainWriteLock(&adp->lock,156);
106 ObtainSharedLock(&afs_xvcache,17); /* prevent others from creating this entry */
107 /* XXX Pay attention to afs_xvcache around the whole thing!! XXX */
109 tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK);
111 hostp = tc->srvr->server;
112 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SYMLINK);
113 if (adp->states & CForeign) {
115 #ifdef RX_ENABLE_LOCKS
117 #endif /* RX_ENABLE_LOCKS */
118 code = RXAFS_DFSSymlink(tc->id, (struct AFSFid *) &adp->fid.Fid, aname,
119 atargetName, &InStatus, (struct AFSFid *) &newFid.Fid,
120 &OutFidStatus, &OutDirStatus, &CallBack, &tsync);
121 #ifdef RX_ENABLE_LOCKS
123 #endif /* RX_ENABLE_LOCKS */
125 #ifdef RX_ENABLE_LOCKS
127 #endif /* RX_ENABLE_LOCKS */
128 code = RXAFS_Symlink(tc->id, (struct AFSFid *) &adp->fid.Fid, aname,
129 atargetName, &InStatus, (struct AFSFid *) &newFid.Fid,
130 &OutFidStatus, &OutDirStatus, &tsync);
131 #ifdef RX_ENABLE_LOCKS
133 #endif /* RX_ENABLE_LOCKS */
139 (afs_Analyze(tc, code, &adp->fid, &treq,
140 AFS_STATS_FS_RPCIDX_SYMLINK, SHARED_LOCK, (struct cell *)0));
142 UpgradeSToWLock(&afs_xvcache,40);
145 ObtainWriteLock(&afs_xcbhash, 499);
146 afs_DequeueCallback(adp);
147 adp->states &= ~CStatd;
148 ReleaseWriteLock(&afs_xcbhash);
149 osi_dnlc_purgedp(adp);
151 ReleaseWriteLock(&adp->lock);
152 ReleaseWriteLock(&afs_xvcache);
153 if (tdc) afs_PutDCache(tdc);
156 /* otherwise, we should see if we can make the change to the dir locally */
157 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
158 /* we can do it locally */
159 code = afs_dir_Create(&tdc->f.inode, aname, &newFid.Fid);
161 ZapDCE(tdc); /* surprise error -- use invalid value */
168 newFid.Cell = adp->fid.Cell;
169 newFid.Fid.Volume = adp->fid.Fid.Volume;
170 ReleaseWriteLock(&adp->lock);
172 /* now we're done with parent dir, create the link's entry. Note that
173 * no one can get a pointer to the new cache entry until we release
174 * the xvcache lock. */
175 tvc = afs_NewVCache(&newFid, hostp, 1, WRITE_LOCK);
176 ObtainWriteLock(&tvc->lock,157);
177 ObtainWriteLock(&afs_xcbhash, 500);
178 tvc->states |= CStatd; /* have valid info */
179 tvc->states &= ~CBulkFetching;
181 if (adp->states & CForeign) {
182 tvc->states |= CForeign;
183 /* We don't have to worry about losing the callback since we're doing it
184 * under the afs_xvcache lock actually, afs_NewVCache may drop the
185 * afs_xvcache lock, if it calls afs_FlushVCache */
186 tvc->cbExpires = CallBack.ExpirationTime + now;
187 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), volp);
189 tvc->cbExpires = 0x7fffffff; /* never expires, they can't change */
190 /* since it never expires, we don't have to queue the callback */
192 ReleaseWriteLock(&afs_xcbhash);
193 afs_ProcessFS(tvc, &OutFidStatus, &treq);
195 if (!tvc->linkData) {
196 tvc->linkData = (char *) afs_osi_Alloc(alen);
197 strncpy(tvc->linkData, atargetName, alen-1);
198 tvc->linkData[alen-1] = 0;
200 ReleaseWriteLock(&tvc->lock);
201 ReleaseWriteLock(&afs_xvcache);
202 afs_PutVCache(tvc, WRITE_LOCK);
206 AFS_RELE(ndp->ni_dvp);
207 #endif /* AFS_OSF_ENV */
209 afs_PutVolume(volp, READ_LOCK);
210 code = afs_CheckCode(code, &treq, 31);
214 afs_MemHandleLink(avc, areq)
215 register struct vcache *avc;
216 struct vrequest *areq;
218 register struct dcache *tdc;
220 afs_int32 offset, len, alen;
221 register afs_int32 code;
223 AFS_STATCNT(afs_MemHandleLink);
224 /* two different formats, one for links protected 644, have a "." at
225 the end of the file name, which we turn into a null. Others,
226 protected 755, we add a null to the end of */
227 if (!avc->linkData) {
229 tdc = afs_GetDCache(avc, 0, areq, &offset, &len, 0);
233 /* otherwise we have the data loaded, go for it */
238 if (avc->m.Mode & 0111) alen = len+1; /* regular link */
239 else alen = len; /* mt point */
240 tp = afs_osi_Alloc(alen); /* make room for terminating null */
241 addr = afs_MemCacheOpen(tdc->f.inode);
242 code = afs_MemReadBlk(addr, 0, tp, len);
246 afs_osi_Free(tp, alen);
254 afs_UFSHandleLink(avc, areq)
255 register struct vcache *avc;
256 struct vrequest *areq; {
257 register struct dcache *tdc;
260 afs_int32 offset, len, alen;
261 register afs_int32 code;
263 /* two different formats, one for links protected 644, have a "." at the end
264 of the file name, which we turn into a null. Others, protected 755,
265 we add a null to the end of */
266 AFS_STATCNT(afs_UFSHandleLink);
267 if (!avc->linkData) {
268 tdc = afs_GetDCache(avc, 0, areq, &offset, &len, 0);
272 /* otherwise we have the data loaded, go for it */
277 tfile = osi_UFSOpen (tdc->f.inode);
278 if (avc->m.Mode & 0111) alen = len+1; /* regular link */
279 else alen = len; /* mt point */
280 tp = afs_osi_Alloc(alen); /* make room for terminating null */
281 code = afs_osi_Read(tfile, -1, tp, len);
286 afs_osi_Free(tp, alen);
294 afs_readlink(OSI_VC_ARG(avc), auio, acred)
297 struct AFS_UCRED *acred; {
298 register afs_int32 code;
299 struct vrequest treq;
303 AFS_STATCNT(afs_readlink);
304 afs_Trace1(afs_iclSetp, CM_TRACE_READLINK, ICL_TYPE_POINTER, avc);
305 if (code = afs_InitReq(&treq, acred)) return code;
306 code = afs_VerifyVCache(avc, &treq);
308 if (vType(avc) != VLNK) {
312 ObtainWriteLock(&avc->lock,158);
313 code = afs_HandleLink(avc, &treq);
314 /* finally uiomove it to user-land */
317 if (tp) AFS_UIOMOVE(tp, strlen(tp), UIO_READ, auio, code);
322 ReleaseWriteLock(&avc->lock);
324 code = afs_CheckCode(code, &treq, 32);