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. */
35 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
36 afs_link(OSI_VC_DECL(adp), struct vcache *avc, char *aname,
37 struct AFS_UCRED *acred)
39 afs_link(struct vcache *avc, OSI_VC_DECL(adp), char *aname,
40 struct AFS_UCRED *acred)
44 register struct dcache *tdc;
45 register afs_int32 code;
46 register struct afs_conn *tc;
47 afs_size_t offset, len;
48 struct AFSFetchStatus OutFidStatus, OutDirStatus;
49 struct AFSVolSync tsync;
50 struct afs_fakestat_state vfakestate, dfakestate;
54 AFS_STATCNT(afs_link);
55 afs_Trace3(afs_iclSetp, CM_TRACE_LINK, ICL_TYPE_POINTER, adp,
56 ICL_TYPE_POINTER, avc, ICL_TYPE_STRING, aname);
57 /* create a hard link; new entry is aname in dir adp */
58 if ((code = afs_InitReq(&treq, acred)))
61 afs_InitFakeStat(&vfakestate);
62 afs_InitFakeStat(&dfakestate);
66 code = afs_EvalFakeStat(&avc, &vfakestate, &treq);
69 code = afs_EvalFakeStat(&adp, &dfakestate, &treq);
73 if (avc->f.fid.Cell != adp->f.fid.Cell
74 || avc->f.fid.Fid.Volume != adp->f.fid.Fid.Volume) {
78 if (strlen(aname) > AFSNAMEMAX) {
82 code = afs_VerifyVCache(adp, &treq);
86 /** If the volume is read-only, return error without making an RPC to the
89 if (adp->f.states & CRO) {
94 if (AFS_IS_DISCONNECTED) {
99 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); /* test for error below */
100 ObtainWriteLock(&adp->lock, 145);
102 tc = afs_Conn(&adp->f.fid, &treq, SHARED_LOCK);
104 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_LINK);
107 RXAFS_Link(tc->id, (struct AFSFid *)&adp->f.fid.Fid, aname,
108 (struct AFSFid *)&avc->f.fid.Fid, &OutFidStatus,
109 &OutDirStatus, &tsync);
116 (tc, code, &adp->f.fid, &treq, AFS_STATS_FS_RPCIDX_LINK,
123 ObtainWriteLock(&afs_xcbhash, 492);
124 afs_DequeueCallback(adp);
125 adp->f.states &= ~CStatd;
126 ReleaseWriteLock(&afs_xcbhash);
127 osi_dnlc_purgedp(adp);
129 ReleaseWriteLock(&adp->lock);
133 ObtainWriteLock(&tdc->lock, 635);
134 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
135 /* we can do it locally */
136 ObtainWriteLock(&afs_xdcache, 290);
137 code = afs_dir_Create(tdc, aname, &avc->f.fid.Fid);
138 ReleaseWriteLock(&afs_xdcache);
140 ZapDCE(tdc); /* surprise error -- invalid value */
145 ReleaseWriteLock(&tdc->lock);
146 afs_PutDCache(tdc); /* drop ref count */
148 ReleaseWriteLock(&adp->lock);
149 ObtainWriteLock(&avc->lock, 146); /* correct link count */
151 /* we could lock both dir and file; since we get the new fid
152 * status back, you'd think we could put it in the cache status
153 * entry at that point. Note that if we don't lock the file over
154 * the rpc call, we have no guarantee that the status info
155 * returned in ustat is the most recent to store in the file's
158 ObtainWriteLock(&afs_xcbhash, 493);
159 afs_DequeueCallback(avc);
160 avc->f.states &= ~CStatd; /* don't really know new link count */
161 ReleaseWriteLock(&afs_xcbhash);
162 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
163 osi_dnlc_purgedp(avc);
164 ReleaseWriteLock(&avc->lock);
167 code = afs_CheckCode(code, &treq, 24);
168 afs_PutFakeStat(&vfakestate);
169 afs_PutFakeStat(&dfakestate);