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"
20 #include "afs/sysincludes.h" /* Standard vendor system headers */
21 #include "afsincludes.h" /* Afs-based standard headers */
22 #include "afs/afs_stats.h" /* statistics */
23 #include "afs/afs_cbqueue.h"
24 #include "afs/nfsclient.h"
25 #include "afs/afs_osidnlc.h"
27 extern afs_rwlock_t afs_xcbhash;
29 /* Note that we don't set CDirty here, this is OK because the link
30 * RPC is called synchronously. */
33 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
34 afs_link(OSI_VC_DECL(adp), struct vcache *avc, char *aname,
37 afs_link(struct vcache *avc, OSI_VC_DECL(adp), char *aname,
45 afs_size_t offset, len;
46 struct AFSFetchStatus OutFidStatus, OutDirStatus;
47 struct AFSVolSync tsync;
48 struct afs_fakestat_state vfakestate, dfakestate;
49 struct rx_connection *rxconn;
53 AFS_STATCNT(afs_link);
54 afs_Trace3(afs_iclSetp, CM_TRACE_LINK, ICL_TYPE_POINTER, adp,
55 ICL_TYPE_POINTER, avc, ICL_TYPE_STRING, aname);
56 /* create a hard link; new entry is aname in dir adp */
57 if ((code = afs_InitReq(&treq, acred)))
60 afs_InitFakeStat(&vfakestate);
61 afs_InitFakeStat(&dfakestate);
65 code = afs_EvalFakeStat(&avc, &vfakestate, &treq);
68 code = afs_EvalFakeStat(&adp, &dfakestate, &treq);
72 if (avc->f.fid.Cell != adp->f.fid.Cell
73 || avc->f.fid.Fid.Volume != adp->f.fid.Fid.Volume) {
77 if (strlen(aname) > AFSNAMEMAX) {
81 code = afs_VerifyVCache(adp, &treq);
85 /** If the volume is read-only, return error without making an RPC to the
88 if (adp->f.states & CRO) {
93 if (AFS_IS_DISCONNECTED) {
98 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq, &offset, &len, 1); /* test for error below */
99 ObtainWriteLock(&adp->lock, 145);
101 tc = afs_Conn(&adp->f.fid, &treq, SHARED_LOCK, &rxconn);
103 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_LINK);
106 RXAFS_Link(rxconn, (struct AFSFid *)&adp->f.fid.Fid, aname,
107 (struct AFSFid *)&avc->f.fid.Fid, &OutFidStatus,
108 &OutDirStatus, &tsync);
115 (tc, rxconn, code, &adp->f.fid, &treq, AFS_STATS_FS_RPCIDX_LINK,
122 ObtainWriteLock(&afs_xcbhash, 492);
123 afs_DequeueCallback(adp);
124 adp->f.states &= ~CStatd;
125 ReleaseWriteLock(&afs_xcbhash);
126 osi_dnlc_purgedp(adp);
128 ReleaseWriteLock(&adp->lock);
132 ObtainWriteLock(&tdc->lock, 635);
133 if (afs_LocalHero(adp, tdc, &OutDirStatus, 1)) {
134 /* we can do it locally */
135 ObtainWriteLock(&afs_xdcache, 290);
136 code = afs_dir_Create(tdc, aname, &avc->f.fid.Fid);
137 ReleaseWriteLock(&afs_xdcache);
139 ZapDCE(tdc); /* surprise error -- invalid value */
144 ReleaseWriteLock(&tdc->lock);
145 afs_PutDCache(tdc); /* drop ref count */
147 ReleaseWriteLock(&adp->lock);
148 ObtainWriteLock(&avc->lock, 146); /* correct link count */
150 /* we could lock both dir and file; since we get the new fid
151 * status back, you'd think we could put it in the cache status
152 * entry at that point. Note that if we don't lock the file over
153 * the rpc call, we have no guarantee that the status info
154 * returned in ustat is the most recent to store in the file's
157 ObtainWriteLock(&afs_xcbhash, 493);
158 afs_DequeueCallback(avc);
159 avc->f.states &= ~CStatd; /* don't really know new link count */
160 ReleaseWriteLock(&afs_xcbhash);
161 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
162 osi_dnlc_purgedp(avc);
163 ReleaseWriteLock(&avc->lock);
166 code = afs_CheckCode(code, &treq, 24);
167 afs_PutFakeStat(&vfakestate);
168 afs_PutFakeStat(&dfakestate);