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 /* Note that we don't set CDirty here, this is OK because the link
28 * RPC is called synchronously. */
31 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
32 afs_link(OSI_VC_DECL(adp), struct vcache *avc, char *aname,
35 afs_link(struct vcache *avc, OSI_VC_DECL(adp), char *aname,
39 struct vrequest *treq = NULL;
43 afs_size_t offset, len;
44 struct AFSFetchStatus *OutFidStatus, *OutDirStatus;
45 struct AFSVolSync tsync;
46 struct afs_fakestat_state vfakestate, dfakestate;
47 struct rx_connection *rxconn;
51 AFS_STATCNT(afs_link);
52 afs_Trace3(afs_iclSetp, CM_TRACE_LINK, ICL_TYPE_POINTER, adp,
53 ICL_TYPE_POINTER, avc, ICL_TYPE_STRING, aname);
55 OutFidStatus = osi_AllocSmallSpace(sizeof(struct AFSFetchStatus));
56 OutDirStatus = osi_AllocSmallSpace(sizeof(struct AFSFetchStatus));
58 /* create a hard link; new entry is aname in dir adp */
59 if ((code = afs_CreateReq(&treq, acred)))
62 afs_InitFakeStat(&vfakestate);
63 afs_InitFakeStat(&dfakestate);
67 code = afs_EvalFakeStat(&avc, &vfakestate, treq);
70 code = afs_EvalFakeStat(&adp, &dfakestate, treq);
74 if (avc->f.fid.Cell != adp->f.fid.Cell
75 || avc->f.fid.Fid.Volume != adp->f.fid.Fid.Volume) {
79 if (strlen(aname) > AFSNAMEMAX) {
83 code = afs_VerifyVCache(adp, treq);
87 /** If the volume is read-only, return error without making an RPC to the
90 if (adp->f.states & CRO) {
95 if (AFS_IS_DISCONNECTED) {
100 tdc = afs_GetDCache(adp, (afs_size_t) 0, treq, &offset, &len, 1); /* test for error below */
101 ObtainWriteLock(&adp->lock, 145);
103 tc = afs_Conn(&adp->f.fid, treq, SHARED_LOCK, &rxconn);
105 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_LINK);
108 RXAFS_Link(rxconn, (struct AFSFid *)&adp->f.fid.Fid, aname,
109 (struct AFSFid *)&avc->f.fid.Fid, OutFidStatus,
110 OutDirStatus, &tsync);
117 (tc, rxconn, code, &adp->f.fid, treq, AFS_STATS_FS_RPCIDX_LINK,
124 afs_StaleVCache(adp);
126 ReleaseWriteLock(&adp->lock);
130 ObtainWriteLock(&tdc->lock, 635);
131 if (afs_LocalHero(adp, tdc, OutDirStatus, 1)) {
132 /* we can do it locally */
133 ObtainWriteLock(&afs_xdcache, 290);
134 code = afs_dir_Create(tdc, aname, &avc->f.fid.Fid);
135 ReleaseWriteLock(&afs_xdcache);
137 ZapDCE(tdc); /* surprise error -- invalid value */
142 ReleaseWriteLock(&tdc->lock);
143 afs_PutDCache(tdc); /* drop ref count */
145 ReleaseWriteLock(&adp->lock);
146 ObtainWriteLock(&avc->lock, 146); /* correct link count */
148 /* we could lock both dir and file; since we get the new fid
149 * status back, you'd think we could put it in the cache status
150 * entry at that point. Note that if we don't lock the file over
151 * the rpc call, we have no guarantee that the status info
152 * returned in ustat is the most recent to store in the file's
155 afs_StaleVCache(avc); /* don't really know new link count */
156 ReleaseWriteLock(&avc->lock);
159 code = afs_CheckCode(code, treq, 24);
160 afs_DestroyReq(treq);
161 afs_PutFakeStat(&vfakestate);
162 afs_PutFakeStat(&dfakestate);
165 osi_FreeSmallSpace(OutFidStatus);
166 osi_FreeSmallSpace(OutDirStatus);