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
16 #include <afsconfig.h>
17 #include "afs/param.h"
22 #include "afs/sysincludes.h" /* Standard vendor system headers */
23 #include "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_xcbhash;
31 /* Note that we don't set CDirty here, this is OK because the link
32 * RPC is called synchronously. */
38 struct nameidata *ndp;
40 struct vcache *adp = VTOAFS(ndp->ni_dvp);
41 char *aname = ndp->ni_dent.d_name;
42 struct ucred *acred = ndp->ni_cred;
43 #else /* AFS_OSF_ENV */
44 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
45 afs_link(OSI_VC_ARG(adp), avc, aname, acred)
47 afs_link(avc, OSI_VC_ARG(adp), aname, acred)
52 struct AFS_UCRED *acred;
56 register struct dcache *tdc;
57 register afs_int32 code;
58 register struct conn *tc;
59 afs_size_t offset, len;
60 struct AFSFetchStatus OutFidStatus, OutDirStatus;
61 struct AFSVolSync tsync;
62 struct afs_fakestat_state vfakestate, dfakestate;
66 AFS_STATCNT(afs_link);
67 afs_Trace3(afs_iclSetp, CM_TRACE_LINK, ICL_TYPE_POINTER, adp,
68 ICL_TYPE_POINTER, avc, ICL_TYPE_STRING, aname);
69 /* create a hard link; new entry is aname in dir adp */
70 if ((code = afs_InitReq(&treq, acred)))
73 afs_InitFakeStat(&vfakestate);
74 afs_InitFakeStat(&dfakestate);
75 code = afs_EvalFakeStat(&avc, &vfakestate, &treq);
78 code = afs_EvalFakeStat(&adp, &dfakestate, &treq);
82 if (avc->fid.Cell != adp->fid.Cell
83 || avc->fid.Fid.Volume != adp->fid.Fid.Volume) {
87 if (strlen(aname) > AFSNAMEMAX) {
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 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); /* test for error below */
104 ObtainWriteLock(&adp->lock, 145);
106 tc = afs_Conn(&adp->fid, &treq, SHARED_LOCK);
108 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_LINK);
111 RXAFS_Link(tc->id, (struct AFSFid *)&adp->fid.Fid, aname,
112 (struct AFSFid *)&avc->fid.Fid, &OutFidStatus,
113 &OutDirStatus, &tsync);
120 (tc, code, &adp->fid, &treq, AFS_STATS_FS_RPCIDX_LINK,
127 ObtainWriteLock(&afs_xcbhash, 492);
128 afs_DequeueCallback(adp);
129 adp->states &= ~CStatd;
130 ReleaseWriteLock(&afs_xcbhash);
131 osi_dnlc_purgedp(adp);
133 ReleaseWriteLock(&adp->lock);
137 ObtainWriteLock(&tdc->lock, 635);
138 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
139 /* we can do it locally */
140 code = afs_dir_Create(tdc, aname, &avc->fid.Fid);
142 ZapDCE(tdc); /* surprise error -- invalid value */
147 ReleaseWriteLock(&tdc->lock);
148 afs_PutDCache(tdc); /* drop ref count */
150 ReleaseWriteLock(&adp->lock);
151 ObtainWriteLock(&avc->lock, 146); /* correct link count */
153 /* we could lock both dir and file; since we get the new fid
154 * status back, you'd think we could put it in the cache status
155 * entry at that point. Note that if we don't lock the file over
156 * the rpc call, we have no guarantee that the status info
157 * returned in ustat is the most recent to store in the file's
160 ObtainWriteLock(&afs_xcbhash, 493);
161 afs_DequeueCallback(avc);
162 avc->states &= ~CStatd; /* don't really know new link count */
163 ReleaseWriteLock(&afs_xcbhash);
164 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
165 osi_dnlc_purgedp(avc);
166 ReleaseWriteLock(&avc->lock);
169 code = afs_CheckCode(code, &treq, 24);
170 afs_PutFakeStat(&vfakestate);
171 afs_PutFakeStat(&dfakestate);
175 #endif /* AFS_OSF_ENV */