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
10 /* afs_fileprocs.c - Complete File Server request routines */
12 /* Information Technology Center */
13 /* Carnegie Mellon University */
17 /* Function - A set of routines to handle the various file Server */
18 /* requests; these routines are invoked by rxgen. */
20 /* ********************************************************************** */
23 * GetVolumePackage disables Rx keepalives; PutVolumePackage re-enables.
24 * If callbacks are to be broken, keepalives should be enabled in the
25 * stub while that occurs; disabled while disk I/O is in process.
29 * in Check_PermissionRights, certain privileges are afforded to the owner
30 * of the volume, or the owner of a file. Are these considered "use of
34 #include <afsconfig.h>
35 #include <afs/param.h>
41 #undef SHARED /* XXX */
48 #ifdef HAVE_NETINET_IF_ETHER_H
49 #include <netinet/if_ether.h>
52 #if !defined(AFS_SGI_ENV) && defined(HAVE_SYS_MAP_H)
56 #ifdef HAVE_SYS_STATFS_H
57 #include <sys/statfs.h>
60 #ifdef HAVE_SYS_LOCKF_H
61 #include <sys/lockf.h>
69 /* included early because of name conflict on IOPEN */
70 #include <sys/inode.h>
74 #endif /* AFS_HPUX_ENV */
77 #include <rx/rx_queue.h>
81 #include <afs/afsint.h>
82 #include <afs/vldbint.h>
83 #include <afs/errors.h>
84 #include <afs/ihandle.h>
85 #include <afs/vnode.h>
86 #include <afs/volume.h>
87 #include <afs/ptclient.h>
88 #include <afs/ptuser.h>
89 #include <afs/prs_fs.h>
92 #include <rx/rx_globals.h>
94 #include <afs/cellconfig.h>
97 #include <afs/partition.h>
98 #include "viced_prototypes.h"
101 #include "callback.h"
102 #include <afs/unified_afs.h>
103 #include <afs/audit.h>
104 #include <afs/afsutil.h>
107 extern void SetDirHandle(DirHandle * dir, Vnode * vnode);
108 extern void FidZap(DirHandle * file);
109 extern void FidZero(DirHandle * file);
111 pthread_mutex_t fileproc_glock_mutex;
113 /* Useful local defines used by this module */
116 #define MustNOTBeDIR 1
120 #define TVS_SSTATUS 2
123 #define TVS_MKDIR 0x10
125 #define CHK_FETCH 0x10
126 #define CHK_FETCHDATA 0x10
127 #define CHK_FETCHACL 0x11
128 #define CHK_FETCHSTATUS 0x12
129 #define CHK_STOREDATA 0x00
130 #define CHK_STOREACL 0x01
131 #define CHK_STORESTATUS 0x02
133 #define OWNERREAD 0400
134 #define OWNERWRITE 0200
135 #define OWNEREXEC 0100
136 #ifdef USE_GROUP_PERMS
137 #define GROUPREAD 0040
138 #define GROUPWRITE 0020
139 #define GROUPREXEC 0010
142 /* The following errors were not defined in NT. They are given unique
143 * names here to avoid any potential collision.
145 #define FSERR_ELOOP 90
146 #define FSERR_EOPNOTSUPP 122
147 #define FSERR_ECONNREFUSED 130
149 #define NOTACTIVECALL 0
152 #define CREATE_SGUID_ADMIN_ONLY 1
156 * Abort the fileserver on fatal errors returned from vnode operations.
158 #define assert_vnode_success_or_salvaging(code) \
159 opr_Assert((code) == 0 || (code) == VSALVAGE || (code) == VSALVAGING)
161 extern struct afsconf_dir *confDir;
162 extern afs_int32 dataVersionHigh;
165 static struct AFSCallStatistics AFSCallStats;
166 struct fs_stats_FullPerfStats afs_FullPerfStats;
167 extern int AnonymousID;
168 static const char nullString[] = "";
171 afs_int32 NothingYet;
174 struct afs_FSStats afs_fsstats;
178 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
180 extern afs_int32 implicitAdminRights;
181 extern afs_int32 readonlyServer;
182 extern afs_int32 adminwriteServer;
183 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
184 extern afs_fsize_t CopyOnWrite_maxsize;
187 * Externals used by the xstat code.
189 extern VolPkgStats VStats;
190 extern int CEs, CEBlocks;
192 extern int HTs, HTBlocks;
194 static afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
195 struct rx_call *Call, afs_sfsize_t Pos,
196 afs_sfsize_t Len, afs_int32 Int64Mode,
197 afs_sfsize_t * a_bytesToFetchP,
198 afs_sfsize_t * a_bytesFetchedP);
200 static afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
201 struct AFSFid *Fid, struct client *client,
202 struct rx_call *Call, afs_fsize_t Pos,
203 afs_fsize_t Length, afs_fsize_t FileLength,
205 afs_sfsize_t * a_bytesToStoreP,
206 afs_sfsize_t * a_bytesStoredP);
208 #ifdef AFS_SGI_XFS_IOPS_ENV
209 #include <afs/xfsattrs.h>
211 GetLinkCount(Volume * avp, struct stat *astat)
213 if (!strcmp("xfs", astat->st_fstype)) {
214 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
216 return astat->st_nlink;
219 #define GetLinkCount(V, S) (S)->st_nlink
223 SpareComp(Volume * avolp)
229 temp = V_maxquota(avolp);
231 /* no matter; doesn't check in this case */
235 temp = (temp * PctSpare) / 100;
246 * Set the volume synchronization parameter for this volume. If it changes,
247 * the Cache Manager knows that the volume must be purged from the stat cache.
250 SetVolumeSync(struct AFSVolSync *async, Volume * avol)
253 /* date volume instance was created */
256 async->spare1 = V_creationDate(avol);
269 * Verify that the on-disk size for a vnode matches the length in the vnode
272 * @param[in] vp Volume pointer
273 * @param[in] vnp Vnode pointer
274 * @param[in] alen Size of the vnode on disk, if known. If unknown, give -1,
275 * and CheckLength itself will determine the on-disk size.
277 * @return operation status
278 * @retval 0 lengths match
279 * @retval nonzero Error; either the lengths do not match or there was an
280 * error determining the on-disk size. The volume should be
281 * taken offline and salvaged.
284 CheckLength(struct Volume *vp, struct Vnode *vnp, afs_sfsize_t alen)
287 VN_GET_LEN(vlen, vnp);
292 fdP = IH_OPEN(vnp->handle);
294 ViceLog(0, ("CheckLength: cannot open inode for fid %" AFS_VOLID_FMT ".%lu.%lu\n",
295 afs_printable_VolumeId_lu(vp->hashid),
296 afs_printable_uint32_lu(Vn_id(vnp)),
297 afs_printable_uint32_lu(vnp->disk.uniquifier)));
300 alen = FDH_SIZE(fdP);
303 afs_int64 alen64 = alen;
304 ViceLog(0, ("CheckLength: cannot get size for inode for fid %"
305 AFS_VOLID_FMT ".%lu.%lu; FDH_SIZE returned %" AFS_INT64_FMT "\n",
306 afs_printable_VolumeId_lu(vp->hashid),
307 afs_printable_uint32_lu(Vn_id(vnp)),
308 afs_printable_uint32_lu(vnp->disk.uniquifier),
315 afs_int64 alen64 = alen, vlen64 = vlen;
316 ViceLog(0, ("Fid %" AFS_VOLID_FMT ".%lu.%lu has inconsistent length (index "
317 "%lld inode %lld ); volume must be salvaged\n",
318 afs_printable_VolumeId_lu(vp->hashid),
319 afs_printable_uint32_lu(Vn_id(vnp)),
320 afs_printable_uint32_lu(vnp->disk.uniquifier),
328 LogClientError(const char *message, struct rx_connection *tcon, afs_int32 viceid, struct AFSFid *Fid)
332 ViceLog(0, ("%s while handling request from host %s:%d viceid %d "
333 "fid %" AFS_VOLID_FMT ".%lu.%lu, failing request\n",
335 afs_inet_ntoa_r(rx_HostOf(rx_PeerOf(tcon)), hoststr),
336 (int)ntohs(rx_PortOf(rx_PeerOf(tcon))),
338 afs_printable_VolumeId_lu(Fid->Volume),
339 afs_printable_uint32_lu(Fid->Vnode),
340 afs_printable_uint32_lu(Fid->Unique)));
342 ViceLog(0, ("%s while handling request from host %s:%d viceid %d "
343 "fid (none), failing request\n",
345 afs_inet_ntoa_r(rx_HostOf(rx_PeerOf(tcon)), hoststr),
346 (int)ntohs(rx_PortOf(rx_PeerOf(tcon))),
352 * Note that this function always returns a held host, so
353 * that CallPostamble can block without the host's disappearing.
354 * Call returns rx connection in passed in *tconn
356 * 'Fid' is optional, and is just used for printing log messages.
359 CallPreamble(struct rx_call *acall, int activecall, struct AFSFid *Fid,
360 struct rx_connection **tconn, struct host **ahostp)
363 struct client *tclient;
364 afs_int32 viceid = -1;
367 char hoststr[16], hoststr2[16];
368 struct ubik_client *uclient;
372 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
375 *tconn = rx_ConnectionOf(acall);
379 tclient = h_FindClient_r(*tconn, &viceid);
382 LogClientError("CallPreamble: Couldn't get client", *tconn, viceid, Fid);
385 thost = tclient->z.host;
386 if (tclient->z.prfail == 1) { /* couldn't get the CPS */
388 h_ReleaseClient_r(tclient);
391 LogClientError("CallPreamble: Couldn't get CPS", *tconn, viceid, Fid);
394 retry_flag = 0; /* Retry once */
396 /* Take down the old connection and re-read the key file */
398 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
399 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
401 /* Is it still necessary to drop this? We hit the net, we should... */
407 code = hpr_Initialize(&uclient);
410 opr_Verify(pthread_setspecific(viced_uclient_key,
411 (void *)uclient) == 0);
415 h_ReleaseClient_r(tclient);
418 LogClientError("CallPreamble: couldn't reconnect to ptserver", *tconn, viceid, Fid);
422 tclient->z.prfail = 2; /* Means re-eval client's cps */
423 h_ReleaseClient_r(tclient);
428 tclient->z.LastCall = thost->z.LastCall = time(NULL);
429 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
430 thost->z.ActiveCall = thost->z.LastCall;
433 if (thost->z.hostFlags & HOSTDELETED) {
435 ("Discarded a packet for deleted host %s:%d\n",
436 afs_inet_ntoa_r(thost->z.host, hoststr), ntohs(thost->z.port)));
437 code = VBUSY; /* raced, so retry */
438 } else if ((thost->z.hostFlags & VENUSDOWN)
439 || (thost->z.hostFlags & HFE_LATER)) {
440 if (BreakDelayedCallBacks_r(thost)) {
442 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
443 afs_inet_ntoa_r(thost->z.host, hoststr), ntohs(thost->z.port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
444 ntohs(rxr_PortOf(*tconn))));
445 if (MultiProbeAlternateAddress_r(thost)) {
447 ("MultiProbe failed to find new address for host %s:%d\n",
448 afs_inet_ntoa_r(thost->z.host, hoststr),
449 ntohs(thost->z.port)));
453 ("MultiProbe found new address for host %s:%d\n",
454 afs_inet_ntoa_r(thost->z.host, hoststr),
455 ntohs(thost->z.port)));
456 if (BreakDelayedCallBacks_r(thost)) {
458 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
459 afs_inet_ntoa_r(thost->z.host, hoststr), ntohs(thost->z.port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
460 ntohs(rxr_PortOf(*tconn))));
469 h_ReleaseClient_r(tclient);
479 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
483 struct client *tclient;
487 tclient = h_FindClient_r(aconn, NULL);
490 thost = tclient->z.host;
491 if (thost->z.hostFlags & HERRORTRANS)
493 h_ReleaseClient_r(tclient);
496 if (ahost != thost) {
497 /* host/client recycle */
498 char hoststr[16], hoststr2[16];
499 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
501 afs_inet_ntoa_r(ahost->z.host, hoststr),
502 ntohs(ahost->z.port),
504 afs_inet_ntoa_r(thost->z.host, hoststr2),
505 ntohs(thost->z.port),
508 /* return the reference taken in CallPreamble */
512 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
513 afs_inet_ntoa_r(thost->z.host, hoststr),
514 ntohs(thost->z.port),
518 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
519 * does not decrement refcount on client->z.host */
524 return (translate ? sys_error_to_et(ret) : ret);
528 * Returns the volume and vnode pointers associated with file Fid; the lock
529 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
530 * are incremented and they must be eventualy released.
533 CheckVnodeWithCall(AFSFid * fid, Volume ** volptr, struct VCallByVol *cbv,
534 Vnode ** vptr, int lock)
537 Error local_errorCode, errorCode = -1;
538 static struct timeval restartedat = { 0, 0 };
540 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
542 if ((*volptr) == 0) {
547 #ifdef AFS_DEMAND_ATTACH_FS
553 static const struct timespec timeout_ts = { 0, 0 };
554 static const struct timespec * const ts = &timeout_ts;
557 *volptr = VGetVolumeWithCall(&local_errorCode, &errorCode,
558 fid->Volume, ts, cbv);
563 if ((errorCode == VOFFLINE) && (VInit < 2)) {
564 /* The volume we want may not be attached yet because
565 * the volume initialization is not yet complete.
566 * We can do several things:
567 * 1. return -1, which will cause users to see
568 * "connection timed out". This is more or
569 * less the same as always, except that the servers
570 * may appear to bounce up and down while they
571 * are actually restarting.
572 * 2. return VBUSY which will cause clients to
573 * sleep and retry for 6.5 - 15 minutes, depending
574 * on what version of the CM they are running. If
575 * the file server takes longer than that interval
576 * to attach the desired volume, then the application
577 * will see an ENODEV or EIO. This approach has
578 * the advantage that volumes which have been attached
579 * are immediately available, it keeps the server's
580 * immediate backlog low, and the call is interruptible
581 * by the user. Users see "waiting for busy volume."
582 * 3. sleep here and retry. Some people like this approach
583 * because there is no danger of seeing errors. However,
584 * this approach only works with a bounded number of
585 * clients, since the pending queues will grow without
586 * stopping. It might be better to find a way to take
587 * this call and stick it back on a queue in order to
588 * recycle this thread for a different request.
589 * 4. Return a new error code, which new cache managers will
590 * know enough to interpret as "sleep and retry", without
591 * the upper bound of 6-15 minutes that is imposed by the
592 * VBUSY handling. Users will see "waiting for
593 * busy volume," so they know that something is
594 * happening. Old cache managers must be able to do
595 * something reasonable with this, for instance, mark the
596 * server down. Fortunately, any error code < 0
597 * will elicit that behavior. See #1.
598 * 5. Some combination of the above. I like doing #2 for 10
599 * minutes, followed by #4. 3.1b and 3.2 cache managers
600 * will be fine as long as the restart period is
601 * not longer than 6.5 minutes, otherwise they may
602 * return ENODEV to users. 3.3 cache managers will be
603 * fine for 10 minutes, then will return
604 * ETIMEDOUT. 3.4 cache managers will just wait
605 * until the call works or fails definitively.
606 * NB. The problem with 2,3,4,5 is that old clients won't
607 * fail over to an alternate read-only replica while this
608 * server is restarting. 3.4 clients will fail over right away.
610 if (restartedat.tv_sec == 0) {
611 /* I'm not really worried about when we restarted, I'm */
612 /* just worried about when the first VBUSY was returned. */
613 gettimeofday(&restartedat, 0);
616 afs_perfstats.fs_nBusies++;
619 return (busyonrst ? VBUSY : restarting);
622 gettimeofday(&now, 0);
623 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
626 afs_perfstats.fs_nBusies++;
629 return (busyonrst ? VBUSY : restarting);
635 /* allow read operations on busy volume.
636 * must check local_errorCode because demand attach fs
637 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
638 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
639 #ifdef AFS_DEMAND_ATTACH_FS
640 /* DAFS case is complicated by the fact that local_errorCode can
641 * be VBUSY in cases where the volume is truly offline */
643 /* volume is in VOL_STATE_UNATTACHED */
646 #endif /* AFS_DEMAND_ATTACH_FS */
649 } else if (errorCode)
656 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
659 if ((*vptr)->disk.uniquifier != fid->Unique) {
660 VPutVnode(&fileCode, *vptr);
661 assert_vnode_success_or_salvaging(fileCode);
663 return (VNOVNODE); /* return the right error code, at least */
668 static_inline afs_int32
669 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
671 return CheckVnodeWithCall(fid, volptr, NULL, vptr, lock);
675 * This routine returns the ACL associated with the targetptr. If the
676 * targetptr isn't a directory, we access its parent dir and get the ACL
677 * thru the parent; in such case the parent's vnode is returned in
681 SetAccessList(Vnode ** targetptr, Volume ** volume,
682 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
683 AFSFid * Fid, int Lock)
685 if ((*targetptr)->disk.type == vDirectory) {
687 *ACL = VVnodeACL(*targetptr);
688 *ACLSize = VAclSize(*targetptr);
691 opr_Assert(Fid != 0);
696 parentvnode = (*targetptr)->disk.parent;
697 VPutVnode(&errorCode, *targetptr);
701 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
704 *ACL = VVnodeACL(*parent);
705 *ACLSize = VAclSize(*parent);
706 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
708 if ((*targetptr)->disk.parent != parentvnode) {
709 VPutVnode(&errorCode, *parent);
720 /* Must not be called with H_LOCK held */
722 client_CheckRights(struct client *client, struct acl_accessList *ACL,
726 ObtainReadLock(&client->lock);
727 if (client->z.CPS.prlist_len > 0 && !client->z.deleted &&
728 client->z.host && !(client->z.host->z.hostFlags & HOSTDELETED))
729 acl_CheckRights(ACL, &client->z.CPS, rights);
730 ReleaseReadLock(&client->lock);
733 /* Must not be called with H_LOCK held */
735 client_HasAsMember(struct client *client, afs_int32 id)
739 ObtainReadLock(&client->lock);
740 if (client->z.CPS.prlist_len > 0 && !client->z.deleted &&
741 client->z.host && !(client->z.host->z.hostFlags & HOSTDELETED))
742 code = acl_IsAMember(id, &client->z.CPS);
743 ReleaseReadLock(&client->lock);
748 * Compare the directory's ACL with the user's access rights in the client
749 * connection and return the user's and everybody else's access permissions
750 * in rights and anyrights, respectively
753 GetRights(struct client *client, struct acl_accessList *ACL,
754 afs_int32 * rights, afs_int32 * anyrights)
756 extern prlist SystemAnyUserCPS;
757 afs_int32 hrights = 0;
759 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
760 ViceLog(0, ("CheckRights failed\n"));
765 client_CheckRights(client, ACL, rights);
767 /* wait if somebody else is already doing the getCPS call */
769 while (client->z.host->z.hostFlags & HCPS_INPROGRESS) {
770 client->z.host->z.hostFlags |= HCPS_WAITING; /* I am waiting */
771 opr_cv_wait(&client->z.host->cond, &host_glock_mutex);
774 if (!client->z.host->z.hcps.prlist_len || !client->z.host->z.hcps.prlist_val) {
777 ("CheckRights: len=%u, for host=%s:%d\n",
778 client->z.host->z.hcps.prlist_len,
779 afs_inet_ntoa_r(client->z.host->z.host, hoststr),
780 ntohs(client->z.host->z.port)));
782 acl_CheckRights(ACL, &client->z.host->z.hcps, &hrights);
784 /* Allow system:admin the rights given with the -implicit option */
785 if (client_HasAsMember(client, SystemId))
786 *rights |= implicitAdminRights;
789 *anyrights |= hrights;
796 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
797 * a System:Administrator)
800 VanillaUser(struct client *client)
802 if (client_HasAsMember(client, SystemId))
803 return (0); /* not a system administrator, then you're "vanilla" */
809 /*------------------------------------------------------------------------
810 * GetVolumePackageWithCall
813 * This unusual afs_int32-parameter routine encapsulates all volume
814 * package related operations together in a single function; it's
815 * called by almost all AFS interface calls.
818 * acall : Ptr to Rx call on which this request came in.
819 * cbv : struct containing the RX call for offline cancels
820 * Fid : the AFS fid the caller is acting on
821 * volptr : returns a pointer to the volume struct
822 * targetptr : returns a pointer to the vnode struct
823 * chkforDir : whether to check for if vnode is a dir
824 * parent : returns a pointer to the parent of this vnode
825 * client : returns a pointer to the calling client
826 * locktype : indicates what kind of lock to take on vnodes
827 * rights : returns a pointer to caller's rights
828 * anyrights : returns a pointer to anonymous' rights
829 * remote : indicates that the volume is a remote RW replica
833 * appropriate error based on permission or invalid operation.
836 * Nothing interesting.
839 * On success, disables keepalives on the call. Caller should re-enable
840 * after completing disk I/O.
841 *------------------------------------------------------------------------*/
843 GetVolumePackageWithCall(struct rx_call *acall, struct VCallByVol *cbv,
844 AFSFid * Fid, Volume ** volptr, Vnode ** targetptr,
845 int chkforDir, Vnode ** parent,
846 struct client **client, int locktype,
847 afs_int32 * rights, afs_int32 * anyrights, int remote)
849 struct acl_accessList *aCL = NULL; /* Internal access List */
850 int aCLSize; /* size of the access list */
851 Error errorCode = 0; /* return code to caller */
852 struct rx_connection *tcon = rx_ConnectionOf(acall);
854 if ((errorCode = CheckVnodeWithCall(Fid, volptr, cbv, targetptr, locktype)))
858 if (chkforDir == MustNOTBeDIR
859 && ((*targetptr)->disk.type == vDirectory)) {
863 else if (chkforDir == MustBeDIR
864 && ((*targetptr)->disk.type != vDirectory)) {
870 * If the remote flag is set, the current call is dealing with a remote RW
871 * replica, and it can be assumed that the appropriate access checks were
872 * done by the calling server hosting the master volume.
875 if ((errorCode = SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
876 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
877 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
879 if (chkforDir == MustBeDIR)
880 opr_Assert((*parent) == 0);
882 if ((errorCode = GetClient(tcon, client)) != 0)
889 GetRights(*client, aCL, rights, anyrights);
890 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
891 if ((*targetptr)->disk.type != vDirectory) {
892 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
893 if ((*targetptr)->disk.owner == (*client)->z.ViceId)
894 (*rights) |= PRSFS_ADMINISTER;
896 (*rights) &= ~PRSFS_ADMINISTER;
898 #ifdef ADMIN_IMPLICIT_LOOKUP
899 /* admins get automatic lookup on everything */
900 if (!VanillaUser(*client))
901 (*rights) |= PRSFS_LOOKUP;
902 #endif /* ADMIN_IMPLICIT_LOOKUP */
907 } /*GetVolumePackage */
909 static_inline afs_int32
910 GetVolumePackage(struct rx_call *acall, AFSFid * Fid, Volume ** volptr,
911 Vnode ** targetptr, int chkforDir, Vnode ** parent,
912 struct client **client, int locktype, afs_int32 * rights,
913 afs_int32 * anyrights)
915 return GetVolumePackageWithCall(acall, NULL, Fid, volptr, targetptr,
916 chkforDir, parent, client, locktype,
917 rights, anyrights, 0);
921 /*------------------------------------------------------------------------
922 * PutVolumePackageWithCall
925 * This is the opposite of GetVolumePackage(), and is always used at
926 * the end of AFS calls to put back all used vnodes and the volume
927 * in the proper order!
930 * acall : Ptr to Rx call on which this request came in.
931 * parentwhentargetnotdir : a pointer to the parent when the target isn't
933 * targetptr : a pointer to the vnode struct
934 * parentptr : a pointer to the parent of this vnode
935 * volptr : a pointer to the volume structure
936 * client : a pointer to the calling client
937 * cbv : struct containing the RX call for offline cancels
943 * Nothing interesting.
946 * Enables keepalives on the call.
947 *------------------------------------------------------------------------*/
949 PutVolumePackageWithCall(struct rx_call *acall, Vnode *
950 parentwhentargetnotdir, Vnode * targetptr,
951 Vnode * parentptr, Volume * volptr,
952 struct client **client, struct VCallByVol *cbv)
954 Error fileCode = 0; /* Error code returned by the volume package */
956 if (parentwhentargetnotdir) {
957 VPutVnode(&fileCode, parentwhentargetnotdir);
958 assert_vnode_success_or_salvaging(fileCode);
961 VPutVnode(&fileCode, targetptr);
962 assert_vnode_success_or_salvaging(fileCode);
965 VPutVnode(&fileCode, parentptr);
966 assert_vnode_success_or_salvaging(fileCode);
969 VPutVolumeWithCall(volptr, cbv);
975 } /*PutVolumePackage */
978 PutVolumePackage(struct rx_call *acall, Vnode * parentwhentargetnotdir,
979 Vnode * targetptr, Vnode * parentptr, Volume * volptr,
980 struct client **client)
982 PutVolumePackageWithCall(acall, parentwhentargetnotdir, targetptr,
983 parentptr, volptr, client, NULL);
987 VolumeOwner(struct client *client, Vnode * targetptr)
989 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
992 return (client->z.ViceId == owner);
995 * We don't have to check for host's cps since only regular
996 * viceid are volume owners.
998 return (client_HasAsMember(client, owner));
1004 VolumeRootVnode(Vnode * targetptr)
1006 return ((targetptr->vnodeNumber == ROOTVNODE)
1007 && (targetptr->disk.uniquifier == 1));
1009 } /*VolumeRootVnode */
1012 * Check if server can perform writes.
1014 * This functions checks if the fileserver is read-only for the client received
1015 * as an argument. Read-only fileservers allow write requests for members of
1016 * system:administrators when started with both -readonly and -admin-write.
1018 * @param[in] client calling user
1020 * @return 1 if not read-only for this user; 0 otherwise
1023 IsWriteAllowed(struct client *client)
1025 if (readonlyServer) {
1026 if (adminwriteServer && !VanillaUser(client)) {
1027 /* admins can write */
1036 * Check if target file has the proper access permissions for the Fetch
1037 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
1038 * StoreStatus) related calls
1040 /* this code should probably just set a "priv" flag where all the audit events
1041 * are now, and only generate the audit event once at the end of the routine,
1042 * thus only generating the event if all the checks succeed, but only because
1043 * of the privilege XXX
1046 Check_PermissionRights(Vnode * targetptr, struct client *client,
1047 afs_int32 rights, int CallingRoutine,
1048 AFSStoreStatus * InStatus)
1050 Error errorCode = 0;
1051 #define OWNSp(client, target) ((client)->z.ViceId == (target)->disk.owner)
1052 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
1053 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
1055 if (CallingRoutine & CHK_FETCH) {
1056 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
1057 if (targetptr->disk.type == vDirectory
1058 || targetptr->disk.type == vSymlink) {
1059 if (!(rights & PRSFS_LOOKUP)
1060 #ifdef ADMIN_IMPLICIT_LOOKUP
1061 /* grant admins fetch on all directories */
1062 && VanillaUser(client)
1063 #endif /* ADMIN_IMPLICIT_LOOKUP */
1064 && !VolumeOwner(client, targetptr))
1067 /* must have read access, or be owner and have insert access */
1068 if (!(rights & PRSFS_READ)
1069 && !((OWNSp(client, targetptr) && (rights & PRSFS_INSERT)
1070 && (client->z.ViceId != AnonymousID))))
1073 if (CallingRoutine == CHK_FETCHDATA
1074 && targetptr->disk.type == vFile)
1075 #ifdef USE_GROUP_PERMS
1076 if (!OWNSp(client, targetptr)
1077 && !client_HasAsMember(client, targetptr->disk.owner)) {
1079 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
1083 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
1088 * The check with the ownership below is a kludge to allow
1089 * reading of files created with no read permission. The owner
1090 * of the file is always allowed to read it.
1092 if ((client->z.ViceId != targetptr->disk.owner)
1093 && VanillaUser(client))
1095 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
1096 modeBits) ? 0 : EACCES);
1098 } else { /* !VanillaUser(client) && !FetchData */
1100 osi_audit(PrivilegeEvent, 0, AUD_ID,
1101 (client ? client->z.ViceId : 0), AUD_INT, CallingRoutine,
1104 } else { /* a store operation */
1105 if (!IsWriteAllowed(client)) {
1108 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
1109 && (CallingRoutine != CHK_STOREACL)
1110 && (targetptr->disk.type == vFile)) {
1111 /* bypass protection checks on first store after a create
1112 * for the creator; also prevent chowns during this time
1113 * unless you are a system administrator */
1114 /****** InStatus->Owner && UnixModeBits better be SET!! */
1115 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
1116 if (VanillaUser(client))
1117 return (EPERM); /* Was EACCES */
1119 osi_audit(PrivilegeEvent, 0, AUD_ID,
1120 (client ? client->z.ViceId : 0), AUD_INT,
1121 CallingRoutine, AUD_END);
1124 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
1125 osi_audit(PrivilegeEvent, 0, AUD_ID,
1126 (client ? client->z.ViceId : 0), AUD_INT,
1127 CallingRoutine, AUD_END);
1129 if (CallingRoutine == CHK_STOREACL) {
1130 if (!(rights & PRSFS_ADMINISTER)
1131 && !VolumeOwner(client, targetptr))
1133 } else { /* store data or status */
1134 /* watch for chowns and chgrps */
1135 if (CHOWN(InStatus, targetptr)
1136 || CHGRP(InStatus, targetptr)) {
1137 if (VanillaUser(client))
1138 return (EPERM); /* Was EACCES */
1140 osi_audit(PrivilegeEvent, 0, AUD_ID,
1141 (client ? client->z.ViceId : 0), AUD_INT,
1142 CallingRoutine, AUD_END);
1144 /* must be sysadmin to set suid/sgid bits */
1145 if ((InStatus->Mask & AFS_SETMODE) &&
1147 (InStatus->UnixModeBits & 0xc00) != 0) {
1149 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
1151 if (VanillaUser(client))
1154 osi_audit(PrivSetID, 0, AUD_ID,
1155 (client ? client->z.ViceId : 0), AUD_INT,
1156 CallingRoutine, AUD_END);
1158 if (CallingRoutine == CHK_STOREDATA) {
1159 if (!(rights & PRSFS_WRITE))
1161 /* Next thing is tricky. We want to prevent people
1162 * from writing files sans 0200 bit, but we want
1163 * creating new files with 0444 mode to work. We
1164 * don't check the 0200 bit in the "you are the owner"
1165 * path above, but here we check the bit. However, if
1166 * you're a system administrator, we ignore the 0200
1167 * bit anyway, since you may have fchowned the file,
1169 #ifdef USE_GROUP_PERMS
1170 if ((targetptr->disk.type == vFile)
1171 && VanillaUser(client)) {
1172 if (!OWNSp(client, targetptr)
1173 && !client_HasAsMember(client, targetptr->disk.owner)) {
1175 ((GROUPWRITE & targetptr->disk.modeBits)
1179 ((OWNERWRITE & targetptr->disk.modeBits)
1184 if ((targetptr->disk.type != vDirectory)
1185 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1186 if (VanillaUser(client))
1189 osi_audit(PrivilegeEvent, 0, AUD_ID,
1190 (client ? client->z.ViceId : 0),
1191 AUD_INT, CallingRoutine, AUD_END);
1193 } else { /* a status store */
1194 if (targetptr->disk.type == vDirectory) {
1195 if (!(rights & PRSFS_DELETE)
1196 && !(rights & PRSFS_INSERT))
1198 } else { /* a file or symlink */
1199 if (!(rights & PRSFS_WRITE))
1209 } /*Check_PermissionRights */
1213 * The Access List information is converted from its internal form in the
1214 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1215 * external form and returned back to the caller, via the AccessList
1219 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1220 struct AFSOpaque *AccessList)
1222 char *eACL; /* External access list placeholder */
1224 if (acl_Externalize_pr
1225 (hpr_IdToName, (targetptr->disk.type ==
1226 vDirectory ? VVnodeACL(targetptr) :
1227 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1230 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1231 acl_FreeExternalACL(&eACL);
1234 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1235 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1237 acl_FreeExternalACL(&eACL);
1240 } /*RXFetch_AccessList */
1244 * The Access List information is converted from its external form in the
1245 * input AccessList structure to the internal representation and copied into
1246 * the target dir's vnode storage.
1249 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1251 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1253 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1256 if ((newACL->size + 4) > VAclSize(targetptr))
1258 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1259 acl_FreeACL(&newACL);
1262 } /*RXStore_AccessList */
1265 CheckLink(Volume *volptr, FdHandle_t *fdP, const char *descr)
1270 code = FDH_ISUNLINKED(fdP);
1272 ViceLog(0, ("CopyOnWrite: error fstating volume %u inode %s (%s), errno %d\n",
1273 V_id(volptr), PrintInode(ino, fdP->fd_ih->ih_ino), descr, errno));
1277 ViceLog(0, ("CopyOnWrite corruption prevention: detected zero nlink for "
1278 "volume %u inode %s (%s), forcing volume offline\n",
1279 V_id(volptr), PrintInode(ino, fdP->fd_ih->ih_ino), descr));
1285 /* In our current implementation, each successive data store (new file
1286 * data version) creates a new inode. This function creates the new
1287 * inode, copies the old inode's contents to the new one, remove the old
1288 * inode (i.e. decrement inode count -- if it's currently used the delete
1289 * will be delayed), and modify some fields (i.e. vnode's
1290 * disk.inodeNumber and cloned)
1292 #define COPYBUFFSIZE 8192
1293 #define MAXFSIZE (~(afs_fsize_t) 0)
1295 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1298 Inode nearInode AFS_UNUSED;
1305 int rc; /* return code */
1306 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1307 FdHandle_t *targFdP; /* Source Inode file handle */
1308 FdHandle_t *newFdP; /* Dest Inode file handle */
1310 if (targetptr->disk.type == vDirectory)
1311 DFlush(); /* just in case? */
1313 VN_GET_LEN(size, targetptr);
1321 buff = malloc(COPYBUFFSIZE);
1326 ino = VN_GET_INO(targetptr);
1327 if (!VALID_INO(ino)) {
1329 VTakeOffline(volptr);
1330 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
1331 afs_printable_VolumeId_lu(volptr->hashid)));
1334 targFdP = IH_OPEN(targetptr->handle);
1335 if (targFdP == NULL) {
1338 ("CopyOnWrite failed: Failed to open target vnode %u in volume %" AFS_VOLID_FMT " (errno = %d)\n",
1339 targetptr->vnodeNumber, afs_printable_VolumeId_lu(V_id(volptr)), rc));
1341 VTakeOffline(volptr);
1345 nearInode = VN_GET_INO(targetptr);
1347 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1348 VPartitionPath(V_partition(volptr)), nearInode,
1349 V_id(volptr), targetptr->vnodeNumber,
1350 targetptr->disk.uniquifier,
1351 (int)targetptr->disk.dataVersion);
1352 if (!VALID_INO(ino)) {
1354 ("CopyOnWrite failed: Partition %s that contains volume %" AFS_VOLID_FMT " may be out of free inodes(errno = %d)\n",
1355 volptr->partition->name, afs_printable_VolumeId_lu(V_id(volptr)), errno));
1360 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1361 newFdP = IH_OPEN(newH);
1362 opr_Assert(newFdP != NULL);
1364 rc = CheckLink(volptr, targFdP, "source");
1366 rc = CheckLink(volptr, newFdP, "dest");
1369 FDH_REALLYCLOSE(newFdP);
1371 FDH_REALLYCLOSE(targFdP);
1372 IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1374 VTakeOffline(volptr);
1380 if (size > COPYBUFFSIZE) { /* more than a buffer */
1381 length = COPYBUFFSIZE;
1382 size -= COPYBUFFSIZE;
1387 rdlen = FDH_PREAD(targFdP, buff, length, done);
1388 if (rdlen == length) {
1389 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1393 /* Callers of this function are not prepared to recover
1394 * from error that put the filesystem in an inconsistent
1395 * state. Make sure that we force the volume off-line if
1396 * we some error other than ENOSPC - 4.29.99)
1398 * In case we are unable to write the required bytes, and the
1399 * error code indicates that the disk is full, we roll-back to
1400 * the initial state.
1402 if ((rdlen != length) || (wrlen != length)) {
1403 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1405 ("CopyOnWrite failed: Partition %s containing volume %" AFS_VOLID_FMT " is full\n",
1406 volptr->partition->name, afs_printable_VolumeId_lu(V_id(volptr))));
1407 /* remove destination inode which was partially copied till now */
1408 FDH_REALLYCLOSE(newFdP);
1410 FDH_REALLYCLOSE(targFdP);
1411 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1414 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %" AFS_VOLID_FMT " in partition %s needs salvage\n",
1415 rc, afs_printable_VolumeId_lu(V_id(volptr)), volptr->partition->name));
1416 VTakeOffline(volptr);
1421 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1422 * since we never do any I/O anywhere near 2^32 bytes at a
1423 * time, just case to an unsigned int for printing */
1426 ("CopyOnWrite failed: volume %" AFS_VOLID_FMT " in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1427 afs_printable_VolumeId_lu(V_id(volptr)), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1428 (unsigned)wrlen, errno));
1429 #if defined(AFS_DEMAND_ATTACH_FS)
1430 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1432 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1434 /* Decrement this inode so salvager doesn't find it. */
1435 FDH_REALLYCLOSE(newFdP);
1437 FDH_REALLYCLOSE(targFdP);
1438 IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1440 VTakeOffline(volptr);
1445 FDH_REALLYCLOSE(targFdP);
1446 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1447 V_parentId(volptr));
1449 IH_RELEASE(targetptr->handle);
1451 rc = FDH_SYNC(newFdP);
1452 opr_Assert(rc == 0);
1454 targetptr->handle = newH;
1455 VN_SET_INO(targetptr, ino);
1456 targetptr->disk.cloned = 0;
1457 /* Internal change to vnode, no user level change to volume - def 5445 */
1458 targetptr->changed_oldTime = 1;
1460 return 0; /* success */
1464 * Common code to handle with removing the Name (file when it's called from
1465 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1466 * given directory, parentptr.
1468 int DT1 = 0, DT0 = 0;
1470 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1471 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1473 DirHandle childdir; /* Handle for dir package I/O */
1474 Error errorCode = 0;
1478 /* watch for invalid names */
1479 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1482 if (CheckLength(volptr, parentptr, -1)) {
1483 VTakeOffline(volptr);
1487 if (parentptr->disk.cloned) {
1488 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1489 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1491 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1497 /* check that the file is in the directory */
1498 SetDirHandle(dir, parentptr);
1499 errorCode = afs_dir_Lookup(dir, Name, fileFid);
1500 if (errorCode && errorCode != ENOENT) {
1506 fileFid->Volume = V_id(volptr);
1508 /* just-in-case check for something causing deadlock */
1509 if (fileFid->Vnode == parentptr->vnodeNumber)
1512 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1516 if (ChkForDir == MustBeDIR) {
1517 if ((*targetptr)->disk.type != vDirectory)
1519 } else if ((*targetptr)->disk.type == vDirectory)
1522 /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1524 * If the uniquifiers dont match then instead of asserting
1525 * take the volume offline and return VSALVAGE
1527 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1528 VTakeOffline(volptr);
1530 ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
1531 afs_printable_VolumeId_lu(volptr->hashid)));
1532 errorCode = VSALVAGE;
1536 if (ChkForDir == MustBeDIR) {
1537 SetDirHandle(&childdir, *targetptr);
1538 if (afs_dir_IsEmpty(&childdir) != 0)
1542 (*targetptr)->delete = 1;
1543 } else if ((--(*targetptr)->disk.linkCount) == 0)
1544 (*targetptr)->delete = 1;
1545 if ((*targetptr)->delete) {
1546 if (VN_GET_INO(*targetptr)) {
1548 IH_REALLYCLOSE((*targetptr)->handle);
1550 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1551 V_parentId(volptr));
1552 IH_RELEASE((*targetptr)->handle);
1553 if (errorCode == -1) {
1555 ("DT: inode=%s, name=%s, errno=%d\n",
1556 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1558 if (errno != ENOENT)
1560 VTakeOffline(volptr);
1562 ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
1563 afs_printable_VolumeId_lu(volptr->hashid)));
1570 VN_SET_INO(*targetptr, (Inode) 0);
1572 afs_fsize_t adjLength;
1573 VN_GET_LEN(adjLength, *targetptr);
1574 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1578 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1580 code = afs_dir_Delete(dir, Name);
1583 ("Error %d deleting %s\n", code,
1584 (((*targetptr)->disk.type ==
1585 Directory) ? "directory" : "file")));
1586 VTakeOffline(volptr);
1588 ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
1589 afs_printable_VolumeId_lu(volptr->hashid)));
1601 * This routine updates the parent directory's status block after the
1602 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1603 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1607 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1608 int author, int linkcount, char a_inSameNetwork)
1610 afs_fsize_t newlength; /* Holds new directory length */
1611 afs_fsize_t parentLength;
1613 Date currDate; /*Current date */
1614 int writeIdx; /*Write index to bump */
1615 int timeIdx; /*Authorship time index to bump */
1618 parentptr->disk.dataVersion++;
1619 newlength = (afs_fsize_t) afs_dir_Length(dir);
1621 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1622 * (create, symlink, link, makedir) so we need to check if we have enough space
1623 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1624 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1626 VN_GET_LEN(parentLength, parentptr);
1627 if (nBlocks(newlength) != nBlocks(parentLength)) {
1628 VAdjustDiskUsage(&errorCode, volptr,
1629 (nBlocks(newlength) - nBlocks(parentLength)),
1630 (nBlocks(newlength) - nBlocks(parentLength)));
1632 VN_SET_LEN(parentptr, newlength);
1635 * Update directory write stats for this volume. Note that the auth
1636 * counter is located immediately after its associated ``distance''
1639 if (a_inSameNetwork)
1640 writeIdx = VOL_STATS_SAME_NET;
1642 writeIdx = VOL_STATS_DIFF_NET;
1643 V_stat_writes(volptr, writeIdx)++;
1644 if (author != AnonymousID) {
1645 V_stat_writes(volptr, writeIdx + 1)++;
1649 * Update the volume's authorship information in response to this
1650 * directory operation. Get the current time, decide to which time
1651 * slot this operation belongs, and bump the appropriate slot.
1654 currDate = (now - parentptr->disk.unixModifyTime);
1656 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1657 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1658 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1659 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1660 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1661 if (parentptr->disk.author == author) {
1662 V_stat_dirSameAuthor(volptr, timeIdx)++;
1664 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1667 parentptr->disk.author = author;
1668 parentptr->disk.linkCount = linkcount;
1669 parentptr->disk.unixModifyTime = now; /* This should be set from CLIENT!! */
1670 parentptr->disk.serverModifyTime = now;
1671 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1676 * Update the target file's (or dir's) status block after the specified
1677 * operation is complete. Note that some other fields maybe updated by
1678 * the individual module.
1679 * If remote is set, the volume is a RW replica and access checks can
1683 /* XXX INCOMPLETE - More attention is needed here! */
1685 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1686 struct client *client, AFSStoreStatus * InStatus,
1687 Vnode * parentptr, Volume * volptr,
1688 afs_fsize_t length, int remote)
1690 Date currDate; /*Current date */
1691 int writeIdx; /*Write index to bump */
1692 int timeIdx; /*Authorship time index to bump */
1694 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1695 targetptr->disk.parent = parentptr->vnodeNumber;
1696 VN_SET_LEN(targetptr, length);
1697 /* targetptr->disk.group = 0; save some cycles */
1698 targetptr->disk.modeBits = 0777;
1699 targetptr->disk.owner = client->z.ViceId;
1700 targetptr->disk.dataVersion = 0; /* consistent with the client */
1701 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1702 /* the inode was created in Alloc_NewVnode() */
1705 * Update file write stats for this volume. Note that the auth
1706 * counter is located immediately after its associated ``distance''
1709 if (client->z.InSameNetwork)
1710 writeIdx = VOL_STATS_SAME_NET;
1712 writeIdx = VOL_STATS_DIFF_NET;
1713 V_stat_writes(volptr, writeIdx)++;
1714 if (client->z.ViceId != AnonymousID) {
1715 V_stat_writes(volptr, writeIdx + 1)++;
1719 * We only count operations that DON'T involve creating new objects
1720 * (files, symlinks, directories) or simply setting status as
1721 * authorship-change operations.
1723 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1725 * Update the volume's authorship information in response to this
1726 * file operation. Get the current time, decide to which time
1727 * slot this operation belongs, and bump the appropriate slot.
1729 currDate = (time(NULL) - targetptr->disk.unixModifyTime);
1732 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1733 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1734 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1735 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1736 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1737 VOL_STATS_TIME_IDX_5);
1738 if (targetptr->disk.author == client->z.ViceId) {
1739 V_stat_fileSameAuthor(volptr, timeIdx)++;
1741 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1745 if (!(Caller & TVS_SSTATUS))
1746 targetptr->disk.author = client->z.ViceId;
1747 if (Caller & TVS_SDATA) {
1748 targetptr->disk.dataVersion++;
1749 if (!remote && VanillaUser(client)) {
1751 targetptr->disk.modeBits = targetptr->disk.modeBits & ~04000;
1752 #ifdef CREATE_SGUID_ADMIN_ONLY
1754 targetptr->disk.modeBits = targetptr->disk.modeBits & ~02000;
1758 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1759 /* store status, must explicitly request to change the date */
1760 if (InStatus->Mask & AFS_SETMODTIME)
1761 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1762 } else { /* other: date always changes, but perhaps to what is specified by caller */
1763 targetptr->disk.unixModifyTime =
1764 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1765 ClientModTime : time(NULL));
1767 if (InStatus->Mask & AFS_SETOWNER) {
1768 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1769 if (!remote && VanillaUser(client)) {
1771 targetptr->disk.modeBits = targetptr->disk.modeBits & ~04000;
1772 #ifdef CREATE_SGUID_ADMIN_ONLY
1774 targetptr->disk.modeBits = targetptr->disk.modeBits & ~02000;
1777 targetptr->disk.owner = InStatus->Owner;
1778 if (VolumeRootVnode(targetptr)) {
1779 Error errorCode = 0; /* what should be done with this? */
1781 V_owner(targetptr->volumePtr) = InStatus->Owner;
1782 VUpdateVolume(&errorCode, targetptr->volumePtr);
1785 if (InStatus->Mask & AFS_SETMODE) {
1786 int modebits = InStatus->UnixModeBits;
1787 #ifdef CREATE_SGUID_ADMIN_ONLY
1788 if (!remote && VanillaUser(client))
1789 modebits = modebits & 0777;
1791 if (!remote && VanillaUser(client)) {
1792 targetptr->disk.modeBits = modebits;
1794 targetptr->disk.modeBits = modebits;
1797 osi_audit(PrivSetID, 0, AUD_ID, client->z.ViceId, AUD_INT,
1798 CHK_STOREDATA, AUD_END);
1802 osi_audit(PrivSetID, 0, AUD_ID, client->z.ViceId, AUD_INT,
1803 CHK_STORESTATUS, AUD_END);
1810 targetptr->disk.serverModifyTime = time(NULL);
1811 if (InStatus->Mask & AFS_SETGROUP)
1812 targetptr->disk.group = InStatus->Group;
1813 /* vnode changed : to be written back by VPutVnode */
1814 targetptr->changed_newTime = 1;
1816 } /*Update_TargetVnodeStatus */
1820 * Fills the CallBack structure with the expiration time and type of callback
1821 * structure. Warning: this function is currently incomplete.
1824 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1826 /* CallBackTime could not be 0 */
1827 if (CallBackTime == 0) {
1828 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1829 CallBack->ExpirationTime = 0;
1831 CallBack->ExpirationTime = CallBackTime - time(NULL);
1832 CallBack->CallBackVersion = CALLBACK_VERSION;
1833 CallBack->CallBackType = CB_SHARED; /* The default for now */
1835 } /*SetCallBackStruct */
1839 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1840 * allocation; if some error occured (exceeded volume quota or partition
1841 * was full, or whatever), it frees the space back and returns the code.
1842 * We usually pre-adjust the volume space to make sure that there's
1843 * enough space before consuming some.
1846 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1847 afs_sfsize_t checkLength)
1852 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1854 VAdjustDiskUsage(&nc, volptr, -length, 0);
1855 if (rc == VOVERQUOTA) {
1857 ("Volume %" AFS_VOLID_FMT " (%s) is full\n",
1858 afs_printable_VolumeId_lu(V_id(volptr)),
1862 if (rc == VDISKFULL) {
1864 ("Partition %s that contains volume %" AFS_VOLID_FMT " is full\n",
1865 volptr->partition->name,
1866 afs_printable_VolumeId_lu(V_id(volptr))));
1869 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1874 } /*AdjustDiskUsage */
1877 * Common code that handles the creation of a new file (SAFS_CreateFile and
1878 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1881 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1882 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1883 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1885 Error errorCode = 0; /* Error code returned back */
1888 Inode nearInode AFS_UNUSED; /* hint for inode allocation in solaris */
1892 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1893 BlocksPreallocatedForVnode))) {
1895 ("Insufficient space to allocate %lld blocks\n",
1896 (afs_intmax_t) BlocksPreallocatedForVnode));
1900 if (CheckLength(volptr, parentptr, -1)) {
1901 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1902 VTakeOffline(volptr);
1906 *targetptr = VAllocVnode(&errorCode, volptr, FileType, 0, 0);
1907 if (errorCode != 0) {
1908 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1911 OutFid->Volume = V_id(volptr);
1912 OutFid->Vnode = (*targetptr)->vnodeNumber;
1913 OutFid->Unique = (*targetptr)->disk.uniquifier;
1915 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1917 /* create the inode now itself */
1919 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1920 VPartitionPath(V_partition(volptr)), nearInode,
1921 V_id(volptr), (*targetptr)->vnodeNumber,
1922 (*targetptr)->disk.uniquifier, 1);
1924 /* error in creating inode */
1925 if (!VALID_INO(inode)) {
1927 ("Volume : %" AFS_VOLID_FMT " vnode = %u Failed to create inode: errno = %d\n",
1928 afs_printable_VolumeId_lu(V_id((*targetptr)->volumePtr)),
1929 (*targetptr)->vnodeNumber, errno));
1930 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1931 (*targetptr)->delete = 1; /* delete vnode */
1934 VN_SET_INO(*targetptr, inode);
1935 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1937 /* copy group from parent dir */
1938 (*targetptr)->disk.group = parentptr->disk.group;
1940 if (parentptr->disk.cloned) {
1941 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1942 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1943 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1944 /* delete the vnode previously allocated */
1945 (*targetptr)->delete = 1;
1946 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1947 IH_REALLYCLOSE((*targetptr)->handle);
1948 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1950 ("Alloc_NewVnode: partition %s idec %s failed\n",
1951 volptr->partition->name, PrintInode(stmp, inode)));
1952 IH_RELEASE((*targetptr)->handle);
1958 /* add the name to the directory */
1959 SetDirHandle(dir, parentptr);
1960 if ((errorCode = afs_dir_Create(dir, Name, OutFid))) {
1961 (*targetptr)->delete = 1;
1962 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1963 IH_REALLYCLOSE((*targetptr)->handle);
1964 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1966 ("Alloc_NewVnode: partition %s idec %s failed\n",
1967 volptr->partition->name, PrintInode(stmp, inode)));
1968 IH_RELEASE((*targetptr)->handle);
1974 } /*Alloc_NewVnode */
1978 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1982 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1984 int Time; /* Used for time */
1985 int writeVnode = targetptr->changed_oldTime; /* save original status */
1987 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1989 switch (LockingType) {
1992 if (Time > targetptr->disk.lock.lockTime)
1993 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1995 Time += AFS_LOCKWAIT;
1996 if (LockingType == LockRead) {
1997 if ( !(rights & PRSFS_LOCK) &&
1998 !(rights & PRSFS_WRITE) &&
1999 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
2002 if (targetptr->disk.lock.lockCount >= 0) {
2003 ++(targetptr->disk.lock.lockCount);
2004 targetptr->disk.lock.lockTime = Time;
2007 } else if (LockingType == LockWrite) {
2008 if ( !(rights & PRSFS_WRITE) &&
2009 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
2012 if (targetptr->disk.lock.lockCount == 0) {
2013 targetptr->disk.lock.lockCount = -1;
2014 targetptr->disk.lock.lockTime = Time;
2020 Time += AFS_LOCKWAIT;
2021 if (targetptr->disk.lock.lockCount != 0)
2022 targetptr->disk.lock.lockTime = Time;
2027 if ((--targetptr->disk.lock.lockCount) <= 0)
2028 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
2032 targetptr->changed_oldTime = writeVnode; /* restore old status */
2033 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
2036 } /*HandleLocking */
2038 /* Checks if caller has the proper AFS and Unix (WRITE) access permission to the target directory; Prfs_Mode refers to the AFS Mode operation while rights contains the caller's access permissions to the directory. */
2041 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode,
2042 struct client *client)
2044 if (!IsWriteAllowed(client))
2046 if (!(rights & Prfs_Mode))
2048 if ((targetptr->disk.type != vDirectory)
2049 && (!(targetptr->disk.modeBits & OWNERWRITE)))
2055 * If some flags (i.e. min or max quota) are set, the volume's in disk
2056 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
2057 * update, if applicable.
2060 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
2061 char *Name, char *OfflineMsg, char *Motd)
2063 Error errorCode = 0;
2065 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
2066 V_minquota(volptr) = StoreVolStatus->MinQuota;
2067 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
2068 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
2069 if (strlen(OfflineMsg) > 0) {
2070 strcpy(V_offlineMessage(volptr), OfflineMsg);
2072 if (strlen(Name) > 0) {
2073 strcpy(V_name(volptr), Name);
2076 * We don't overwrite the motd field, since it's now being used
2079 VUpdateVolume(&errorCode, volptr);
2082 } /*RXUpdate_VolumeStatus */
2086 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
2087 char **motd, Volume * volptr)
2090 status->Vid = V_id(volptr);
2091 status->ParentId = V_parentId(volptr);
2092 status->Online = V_inUse(volptr);
2093 status->InService = V_inService(volptr);
2094 status->Blessed = V_blessed(volptr);
2095 status->NeedsSalvage = V_needsSalvaged(volptr);
2096 if (VolumeWriteable(volptr))
2097 status->Type = ReadWrite;
2099 status->Type = ReadOnly;
2100 status->MinQuota = V_minquota(volptr);
2101 status->MaxQuota = V_maxquota(volptr);
2102 status->BlocksInUse = V_diskused(volptr);
2103 status->PartBlocksAvail = RoundInt64ToInt31(volptr->partition->free);
2104 status->PartMaxBlocks = RoundInt64ToInt31(volptr->partition->totalUsable);
2106 /* now allocate and copy these things; they're freed by the RXGEN stub */
2107 *name = strdup(V_name(volptr));
2109 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2111 *offMsg = strdup(V_offlineMessage(volptr));
2113 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2117 ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
2119 strcpy(*motd, nullString);
2121 } /*RXGetVolumeStatus */
2125 FileNameOK(char *aname)
2130 /* watch for @sys on the right */
2131 if (strcmp(aname + i - 4, "@sys") == 0)
2134 while ((tc = *aname++)) {
2136 return 0; /* very bad character to encounter */
2138 return 1; /* file name is ok */
2144 * This variant of symlink is expressly to support the AFS/DFS translator
2145 * and is not supported by the AFS fileserver. We just return EINVAL.
2146 * The cache manager should not generate this call to an AFS cache manager.
2149 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2150 char *LinkContents, struct AFSStoreStatus *InStatus,
2151 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2152 struct AFSFetchStatus *OutDirStatus,
2153 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2159 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2160 struct FsCmdInputs * Inputs,
2161 struct FsCmdOutputs * Outputs)
2165 switch (Inputs->command) {
2169 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2170 Inputs->command, Outputs->code));
2175 static struct afs_buffer {
2176 struct afs_buffer *next;
2177 } *freeBufferList = 0;
2178 static int afs_buffersAlloced = 0;
2181 FreeSendBuffer(struct afs_buffer *adata)
2184 afs_buffersAlloced--;
2185 adata->next = freeBufferList;
2186 freeBufferList = adata;
2190 } /*FreeSendBuffer */
2192 /* allocate space for sender */
2194 AllocSendBuffer(void)
2196 struct afs_buffer *tp;
2199 afs_buffersAlloced++;
2200 if (!freeBufferList) {
2203 tmp = malloc(sendBufSize);
2205 ViceLogThenPanic(0, ("Failed malloc in AllocSendBuffer\n"));
2209 tp = freeBufferList;
2210 freeBufferList = tp->next;
2214 } /*AllocSendBuffer */
2215 #endif /* HAVE_PIOV */
2218 * This routine returns the status info associated with the targetptr vnode
2219 * in the AFSFetchStatus structure. Some of the newer fields, such as
2220 * SegSize and Group are not yet implemented
2224 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2225 afs_int32 anyrights, Vnode * parentptr)
2227 int Time = time(NULL);
2229 /* initialize return status from a vnode */
2230 status->InterfaceVersion = 1;
2231 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2232 status->errorCode = 0;
2233 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2234 if (targetptr->disk.type == vFile)
2235 status->FileType = File;
2236 else if (targetptr->disk.type == vDirectory)
2237 status->FileType = Directory;
2238 else if (targetptr->disk.type == vSymlink)
2239 status->FileType = SymbolicLink;
2241 status->FileType = Invalid; /*invalid type field */
2242 status->LinkCount = targetptr->disk.linkCount;
2244 afs_fsize_t targetLen;
2245 VN_GET_LEN(targetLen, targetptr);
2246 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2248 status->DataVersion = targetptr->disk.dataVersion;
2249 status->Author = targetptr->disk.author;
2250 status->Owner = targetptr->disk.owner;
2251 status->CallerAccess = rights;
2252 status->AnonymousAccess = anyrights;
2253 status->UnixModeBits = targetptr->disk.modeBits;
2254 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2255 status->ParentVnode =
2256 (status->FileType ==
2257 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2258 status->ParentUnique =
2259 (status->FileType ==
2260 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2261 status->ServerModTime = targetptr->disk.serverModifyTime;
2262 status->Group = targetptr->disk.group;
2263 status->lockCount = Time > targetptr->disk.lock.lockTime ? 0 : targetptr->disk.lock.lockCount;
2264 status->errorCode = 0;
2269 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2270 afs_sfsize_t Pos, afs_sfsize_t Len,
2271 struct AFSFetchStatus *OutStatus,
2272 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2275 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2276 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2277 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2278 Error errorCode = 0; /* return code to caller */
2279 Error fileCode = 0; /* return code from vol package */
2280 Volume *volptr = 0; /* pointer to the volume */
2281 struct client *client = 0; /* pointer to the client data */
2282 struct rx_connection *tcon; /* the connection we're part of */
2284 afs_int32 rights, anyrights; /* rights for this and any user */
2285 struct client *t_client = NULL; /* tmp ptr to client data */
2286 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2287 struct VCallByVol tcbv, *cbv = NULL;
2288 static int remainder = 0; /* shared access protected by FS_LOCK */
2289 struct fsstats fsstats;
2290 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2291 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2292 int readIdx; /* Index of read stats array to bump */
2294 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHDATA);
2297 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2300 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2302 if ((errorCode = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
2305 /* Get ptr to client data for user Id for logging */
2306 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2307 logHostAddr.s_addr = rxr_HostOf(tcon);
2309 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2310 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2311 ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
2313 queue_NodeInit(&tcbv);
2318 * Get volume/vnode for the fetched file; caller's access rights to
2319 * it are also returned
2322 GetVolumePackageWithCall(acall, cbv, Fid, &volptr, &targetptr, DONTCHECK,
2323 &parentwhentargetnotdir, &client, READ_LOCK,
2324 &rights, &anyrights, 0)))
2327 SetVolumeSync(Sync, volptr);
2330 * Remember that another read operation was performed.
2333 if (client->z.InSameNetwork)
2334 readIdx = VOL_STATS_SAME_NET;
2336 readIdx = VOL_STATS_DIFF_NET;
2337 V_stat_reads(volptr, readIdx)++;
2338 if (client->z.ViceId != AnonymousID) {
2339 V_stat_reads(volptr, readIdx + 1)++;
2342 /* Check whether the caller has permission access to fetch the data */
2344 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2348 * Drop the read lock on the parent directory after saving the parent
2349 * vnode information we need to pass to GetStatus
2351 if (parentwhentargetnotdir != NULL) {
2352 tparentwhentargetnotdir = *parentwhentargetnotdir;
2353 VPutVnode(&fileCode, parentwhentargetnotdir);
2354 assert_vnode_success_or_salvaging(fileCode);
2355 parentwhentargetnotdir = NULL;
2358 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_FETCHDATA);
2360 /* actually do the data transfer */
2362 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2363 &bytesToXfer, &bytesXferred);
2365 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2371 /* write back the OutStatus from the target vnode */
2372 GetStatus(targetptr, OutStatus, rights, anyrights,
2373 &tparentwhentargetnotdir);
2375 /* if a r/w volume, promise a callback to the caller */
2376 if (VolumeWriteable(volptr))
2377 SetCallBackStruct(AddCallBack(client->z.host, Fid), CallBack);
2379 struct AFSFid myFid;
2380 memset(&myFid, 0, sizeof(struct AFSFid));
2381 myFid.Volume = Fid->Volume;
2382 SetCallBackStruct(AddVolCallBack(client->z.host, &myFid), CallBack);
2386 /* Update and store volume/vnode and parent vnodes back */
2387 (void)PutVolumePackageWithCall(acall, parentwhentargetnotdir, targetptr,
2388 (Vnode *) 0, volptr, &client, cbv);
2389 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2390 errorCode = CallPostamble(tcon, errorCode, thost);
2392 fsstats_FinishOp(&fsstats, errorCode);
2394 osi_auditU(acall, FetchDataEvent, errorCode,
2395 AUD_ID, t_client ? t_client->z.ViceId : 0,
2396 AUD_FID, Fid, AUD_END);
2399 } /*SRXAFS_FetchData */
2402 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2403 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2404 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2406 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2411 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2412 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2413 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2416 afs_sfsize_t tPos, tLen;
2418 tPos = (afs_sfsize_t) Pos;
2419 tLen = (afs_sfsize_t) Len;
2422 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2428 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2429 struct AFSOpaque * AccessList,
2430 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2432 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2433 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2434 Error errorCode = 0; /* return error code to caller */
2435 Volume *volptr = 0; /* pointer to the volume */
2436 struct client *client = 0; /* pointer to the client data */
2437 afs_int32 rights, anyrights; /* rights for this and any user */
2438 struct rx_connection *tcon = rx_ConnectionOf(acall);
2440 struct client *t_client = NULL; /* tmp ptr to client data */
2441 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2442 struct fsstats fsstats;
2444 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHACL);
2447 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2450 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2452 if ((errorCode = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
2455 /* Get ptr to client data for user Id for logging */
2456 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2457 logHostAddr.s_addr = rxr_HostOf(tcon);
2459 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2460 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2461 ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
2463 AccessList->AFSOpaque_len = 0;
2464 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2465 if (!AccessList->AFSOpaque_val) {
2466 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2470 * Get volume/vnode for the fetched file; caller's access rights to it
2474 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
2475 &parentwhentargetnotdir, &client, READ_LOCK,
2476 &rights, &anyrights)))
2479 SetVolumeSync(Sync, volptr);
2481 /* Check whether we have permission to fetch the ACL */
2483 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2486 /* Get the Access List from the dir's vnode */
2488 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2491 /* Get OutStatus back From the target Vnode */
2492 GetStatus(targetptr, OutStatus, rights, anyrights,
2493 parentwhentargetnotdir);
2496 /* Update and store volume/vnode and parent vnodes back */
2497 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2498 (Vnode *) 0, volptr, &client);
2500 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2501 AccessList->AFSOpaque_val));
2502 errorCode = CallPostamble(tcon, errorCode, thost);
2504 fsstats_FinishOp(&fsstats, errorCode);
2506 osi_auditU(acall, FetchACLEvent, errorCode,
2507 AUD_ID, t_client ? t_client->z.ViceId : 0,
2509 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2511 } /*SRXAFS_FetchACL */
2515 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2516 * merged into it when possible.
2519 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2520 struct AFSFetchStatus *OutStatus,
2521 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2523 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2524 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2525 Error errorCode = 0; /* return code to caller */
2526 Volume *volptr = 0; /* pointer to the volume */
2527 struct client *client = 0; /* pointer to the client data */
2528 afs_int32 rights, anyrights; /* rights for this and any user */
2529 struct client *t_client = NULL; /* tmp ptr to client data */
2530 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2531 struct rx_connection *tcon = rx_ConnectionOf(acall);
2533 /* Get ptr to client data for user Id for logging */
2534 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2535 logHostAddr.s_addr = rxr_HostOf(tcon);
2537 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2538 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2539 ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
2541 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2544 * Get volume/vnode for the fetched file; caller's rights to it are
2548 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
2549 &parentwhentargetnotdir, &client, READ_LOCK,
2550 &rights, &anyrights)))
2551 goto Bad_FetchStatus;
2553 /* set volume synchronization information */
2554 SetVolumeSync(Sync, volptr);
2556 /* Are we allowed to fetch Fid's status? */
2557 if (targetptr->disk.type != vDirectory) {
2559 Check_PermissionRights(targetptr, client, rights,
2560 CHK_FETCHSTATUS, 0))) {
2561 if (rx_GetCallAbortCode(acall) == errorCode)
2562 rx_SetCallAbortCode(acall, 0);
2563 goto Bad_FetchStatus;
2567 /* set OutStatus From the Fid */
2568 GetStatus(targetptr, OutStatus, rights, anyrights,
2569 parentwhentargetnotdir);
2571 /* If a r/w volume, also set the CallBack state */
2572 if (VolumeWriteable(volptr))
2573 SetCallBackStruct(AddCallBack(client->z.host, Fid), CallBack);
2575 struct AFSFid myFid;
2576 memset(&myFid, 0, sizeof(struct AFSFid));
2577 myFid.Volume = Fid->Volume;
2578 SetCallBackStruct(AddVolCallBack(client->z.host, &myFid), CallBack);
2582 /* Update and store volume/vnode and parent vnodes back */
2583 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2584 (Vnode *) 0, volptr, &client);
2585 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2588 } /*SAFSS_FetchStatus */
2592 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2593 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2594 struct AFSVolSync * Sync)
2598 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2599 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2600 Error errorCode = 0; /* return code to caller */
2601 Volume *volptr = 0; /* pointer to the volume */
2602 struct client *client = 0; /* pointer to the client data */
2603 afs_int32 rights, anyrights; /* rights for this and any user */
2604 struct AFSFid *tfid; /* file id we're dealing with now */
2605 struct rx_connection *tcon = rx_ConnectionOf(acall);
2607 struct client *t_client = NULL; /* tmp pointer to the client data */
2608 struct fsstats fsstats;
2610 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2612 ViceLog(1, ("SAFS_BulkStatus\n"));
2614 AFSCallStats.TotalCalls++;
2616 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2617 if (nfiles <= 0) { /* Sanity check */
2619 goto Audit_and_Return;
2622 /* allocate space for return output parameters */
2623 OutStats->AFSBulkStats_val = malloc(nfiles * sizeof(struct AFSFetchStatus));
2624 if (!OutStats->AFSBulkStats_val) {
2625 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2627 OutStats->AFSBulkStats_len = nfiles;
2628 CallBacks->AFSCBs_val = malloc(nfiles * sizeof(struct AFSCallBack));
2629 if (!CallBacks->AFSCBs_val) {
2630 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2632 CallBacks->AFSCBs_len = nfiles;
2634 tfid = Fids->AFSCBFids_val;
2636 if ((errorCode = CallPreamble(acall, ACTIVECALL, tfid, &tcon, &thost)))
2637 goto Bad_BulkStatus;
2639 for (i = 0; i < nfiles; i++, tfid++) {
2641 * Get volume/vnode for the fetched file; caller's rights to it
2645 GetVolumePackage(acall, tfid, &volptr, &targetptr, DONTCHECK,
2646 &parentwhentargetnotdir, &client, READ_LOCK,
2647 &rights, &anyrights)))
2648 goto Bad_BulkStatus;
2650 /* set volume synchronization information, but only once per call */
2652 SetVolumeSync(Sync, volptr);
2654 /* Are we allowed to fetch Fid's status? */
2655 if (targetptr->disk.type != vDirectory) {
2657 Check_PermissionRights(targetptr, client, rights,
2658 CHK_FETCHSTATUS, 0))) {
2659 if (rx_GetCallAbortCode(acall) == errorCode)
2660 rx_SetCallAbortCode(acall, 0);
2661 goto Bad_BulkStatus;
2665 /* set OutStatus From the Fid */
2666 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2667 anyrights, parentwhentargetnotdir);
2669 /* If a r/w volume, also set the CallBack state */
2670 if (VolumeWriteable(volptr))
2671 SetCallBackStruct(AddBulkCallBack(client->z.host, tfid),
2672 &CallBacks->AFSCBs_val[i]);
2674 struct AFSFid myFid;
2675 memset(&myFid, 0, sizeof(struct AFSFid));
2676 myFid.Volume = tfid->Volume;
2677 SetCallBackStruct(AddVolCallBack(client->z.host, &myFid),
2678 &CallBacks->AFSCBs_val[i]);
2681 /* put back the file ID and volume */
2682 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2683 (Vnode *) 0, volptr, &client);
2684 parentwhentargetnotdir = (Vnode *) 0;
2685 targetptr = (Vnode *) 0;
2686 volptr = (Volume *) 0;
2687 client = (struct client *)0;
2691 /* Update and store volume/vnode and parent vnodes back */
2692 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2693 (Vnode *) 0, volptr, &client);
2694 errorCode = CallPostamble(tcon, errorCode, thost);
2696 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2698 fsstats_FinishOp(&fsstats, errorCode);
2701 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2702 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2703 AUD_ID, t_client ? t_client->z.ViceId : 0,
2704 AUD_FIDS, Fids, AUD_END);
2707 } /*SRXAFS_BulkStatus */
2711 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2712 struct AFSBulkStats * OutStats,
2713 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2717 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2718 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2719 Error errorCode = 0; /* return code to caller */
2720 Volume *volptr = 0; /* pointer to the volume */
2721 struct client *client = 0; /* pointer to the client data */
2722 afs_int32 rights, anyrights; /* rights for this and any user */
2723 struct AFSFid *tfid; /* file id we're dealing with now */
2724 struct rx_connection *tcon;
2726 struct client *t_client = NULL; /* tmp ptr to client data */
2727 AFSFetchStatus *tstatus;
2728 int VolSync_set = 0;
2729 struct fsstats fsstats;
2731 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_BULKSTATUS);
2733 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2735 AFSCallStats.TotalCalls++;
2737 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2738 if (nfiles <= 0) { /* Sanity check */
2740 goto Audit_and_Return;
2743 /* allocate space for return output parameters */
2744 OutStats->AFSBulkStats_val = calloc(nfiles, sizeof(struct AFSFetchStatus));
2745 if (!OutStats->AFSBulkStats_val) {
2746 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2748 OutStats->AFSBulkStats_len = nfiles;
2749 CallBacks->AFSCBs_val = calloc(nfiles, sizeof(struct AFSCallBack));
2750 if (!CallBacks->AFSCBs_val) {
2751 ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2753 CallBacks->AFSCBs_len = nfiles;
2755 /* Zero out return values to avoid leaking information on partial succes */
2756 memset(Sync, 0, sizeof(*Sync));
2758 tfid = Fids->AFSCBFids_val;
2760 if ((errorCode = CallPreamble(acall, ACTIVECALL, tfid, &tcon, &thost))) {
2761 goto Bad_InlineBulkStatus;
2764 for (i = 0; i < nfiles; i++, tfid++) {
2766 * Get volume/vnode for the fetched file; caller's rights to it
2770 GetVolumePackage(acall, tfid, &volptr, &targetptr, DONTCHECK,
2771 &parentwhentargetnotdir, &client, READ_LOCK,
2772 &rights, &anyrights))) {
2773 tstatus = &OutStats->AFSBulkStats_val[i];
2775 tstatus->InterfaceVersion = 1;
2776 if (thost->z.hostFlags & HERRORTRANS) {
2777 tstatus->errorCode = sys_error_to_et(errorCode);
2779 tstatus->errorCode = errorCode;
2782 PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2783 (Vnode *) 0, volptr, &client);
2784 parentwhentargetnotdir = (Vnode *) 0;
2785 targetptr = (Vnode *) 0;
2786 volptr = (Volume *) 0;
2787 client = (struct client *)0;
2791 /* set volume synchronization information, but only once per call */
2793 SetVolumeSync(Sync, volptr);
2797 /* Are we allowed to fetch Fid's status? */
2798 if (targetptr->disk.type != vDirectory) {
2800 Check_PermissionRights(targetptr, client, rights,
2801 CHK_FETCHSTATUS, 0))) {
2802 tstatus = &OutStats->AFSBulkStats_val[i];
2804 tstatus->InterfaceVersion = 1;
2805 if (thost->z.hostFlags & HERRORTRANS) {
2806 tstatus->errorCode = sys_error_to_et(errorCode);
2808 tstatus->errorCode = errorCode;
2811 (void)PutVolumePackage(acall, parentwhentargetnotdir,
2812 targetptr, (Vnode *) 0, volptr,
2814 parentwhentargetnotdir = (Vnode *) 0;
2815 targetptr = (Vnode *) 0;
2816 volptr = (Volume *) 0;
2817 client = (struct client *)0;
2822 /* set OutStatus From the Fid */
2823 GetStatus(targetptr,
2824 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2825 rights, anyrights, parentwhentargetnotdir);
2827 /* If a r/w volume, also set the CallBack state */
2828 if (VolumeWriteable(volptr))
2829 SetCallBackStruct(AddBulkCallBack(client->z.host, tfid),
2830 &CallBacks->AFSCBs_val[i]);
2832 struct AFSFid myFid;
2833 memset(&myFid, 0, sizeof(struct AFSFid));
2834 myFid.Volume = tfid->Volume;
2835 SetCallBackStruct(AddVolCallBack(client->z.host, &myFid),
2836 &CallBacks->AFSCBs_val[i]);
2839 /* put back the file ID and volume */
2840 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2841 (Vnode *) 0, volptr, &client);
2842 parentwhentargetnotdir = (Vnode *) 0;
2843 targetptr = (Vnode *) 0;
2844 volptr = (Volume *) 0;
2845 client = (struct client *)0;
2849 Bad_InlineBulkStatus:
2850 /* Update and store volume/vnode and parent vnodes back */
2851 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
2852 (Vnode *) 0, volptr, &client);
2853 errorCode = CallPostamble(tcon, errorCode, thost);
2855 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2857 fsstats_FinishOp(&fsstats, errorCode);
2860 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2861 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2862 AUD_ID, t_client ? t_client->z.ViceId : 0,
2863 AUD_FIDS, Fids, AUD_END);
2866 } /*SRXAFS_InlineBulkStatus */
2870 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2871 struct AFSFetchStatus * OutStatus,
2872 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2875 struct rx_connection *tcon;
2877 struct client *t_client = NULL; /* tmp ptr to client data */
2878 struct fsstats fsstats;
2880 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_FETCHSTATUS);
2882 if ((code = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
2883 goto Bad_FetchStatus;
2885 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2888 code = CallPostamble(tcon, code, thost);
2890 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2892 fsstats_FinishOp(&fsstats, code);
2894 osi_auditU(acall, FetchStatusEvent, code,
2895 AUD_ID, t_client ? t_client->z.ViceId : 0,
2896 AUD_FID, Fid, AUD_END);
2899 } /*SRXAFS_FetchStatus */
2903 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2904 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2905 afs_fsize_t Length, afs_fsize_t FileLength,
2906 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2908 Vnode *targetptr = 0; /* pointer to input fid */
2909 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2910 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2911 Error errorCode = 0; /* return code for caller */
2912 Error fileCode = 0; /* return code from vol package */
2913 Volume *volptr = 0; /* pointer to the volume header */
2914 struct client *client = 0; /* pointer to client structure */
2915 afs_int32 rights, anyrights; /* rights for this and any user */
2916 struct client *t_client = NULL; /* tmp ptr to client data */
2917 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2918 struct rx_connection *tcon;
2920 struct fsstats fsstats;
2921 afs_sfsize_t bytesToXfer;
2922 afs_sfsize_t bytesXferred;
2923 static int remainder = 0;
2926 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2929 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREDATA);
2932 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2934 if ((errorCode = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
2937 /* Get ptr to client data for user Id for logging */
2938 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2939 logHostAddr.s_addr = rxr_HostOf(tcon);
2941 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2942 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2943 ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
2946 * Get associated volume/vnode for the stored file; caller's rights
2950 GetVolumePackage(acall, Fid, &volptr, &targetptr, MustNOTBeDIR,
2951 &parentwhentargetnotdir, &client, WRITE_LOCK,
2952 &rights, &anyrights))) {
2956 /* set volume synchronization information */
2957 SetVolumeSync(Sync, volptr);
2959 if (targetptr->disk.type == vSymlink) {
2960 /* Should we return a better error code here??? */
2965 /* Check if we're allowed to store the data */
2967 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2973 * Drop the read lock on the parent directory after saving the parent
2974 * vnode information we need to pass to GetStatus
2976 if (parentwhentargetnotdir != NULL) {
2977 tparentwhentargetnotdir = *parentwhentargetnotdir;
2978 VPutVnode(&fileCode, parentwhentargetnotdir);
2979 assert_vnode_success_or_salvaging(fileCode);
2980 parentwhentargetnotdir = NULL;
2983 fsstats_StartXfer(&fsstats, FS_STATS_XFERIDX_STOREDATA);
2986 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2987 FileLength, (InStatus->Mask & AFS_FSYNC),
2988 &bytesToXfer, &bytesXferred);
2990 fsstats_FinishXfer(&fsstats, errorCode, bytesToXfer, bytesXferred,
2993 if (errorCode && (!targetptr->changed_newTime))
2996 /* Update the status of the target's vnode */
2997 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
2998 targetptr, volptr, 0, 0);
3000 /* Get the updated File's status back to the caller */
3001 GetStatus(targetptr, OutStatus, rights, anyrights,
3002 &tparentwhentargetnotdir);
3005 /* Update and store volume/vnode and parent vnodes back */
3006 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
3007 (Vnode *) 0, volptr, &client);
3008 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3010 errorCode = CallPostamble(tcon, errorCode, thost);
3012 fsstats_FinishOp(&fsstats, errorCode);
3014 osi_auditU(acall, StoreDataEvent, errorCode,
3015 AUD_ID, t_client ? t_client->z.ViceId : 0,
3016 AUD_FID, Fid, AUD_END);
3018 } /*common_StoreData64 */
3021 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3022 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3023 afs_uint32 Length, afs_uint32 FileLength,
3024 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3026 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3027 (0x7fffffff - Pos) < Length)
3030 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3032 } /*SRXAFS_StoreData */
3035 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3036 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3037 afs_uint64 Length, afs_uint64 FileLength,
3038 struct AFSFetchStatus * OutStatus,
3039 struct AFSVolSync * Sync)
3043 afs_fsize_t tLength;
3044 afs_fsize_t tFileLength;
3046 tPos = (afs_fsize_t) Pos;
3047 tLength = (afs_fsize_t) Length;
3048 tFileLength = (afs_fsize_t) FileLength;
3051 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3057 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3058 struct AFSOpaque * AccessList,
3059 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3061 Vnode *targetptr = 0; /* pointer to input fid */
3062 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3063 Error errorCode = 0; /* return code for caller */
3064 struct AFSStoreStatus InStatus; /* Input status for fid */
3065 Volume *volptr = 0; /* pointer to the volume header */
3066 struct client *client = 0; /* pointer to client structure */
3067 afs_int32 rights, anyrights; /* rights for this and any user */
3068 struct rx_connection *tcon;
3070 struct client *t_client = NULL; /* tmp ptr to client data */
3071 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3072 struct fsstats fsstats;
3074 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STOREACL);
3076 if ((errorCode = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
3079 /* Get ptr to client data for user Id for logging */
3080 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3081 logHostAddr.s_addr = rxr_HostOf(tcon);
3083 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3084 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3085 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
3087 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3089 InStatus.Mask = 0; /* not storing any status */
3092 * Get associated volume/vnode for the target dir; caller's rights
3093 * are also returned.
3096 GetVolumePackage(acall, Fid, &volptr, &targetptr, MustBeDIR,
3097 &parentwhentargetnotdir, &client, WRITE_LOCK,
3098 &rights, &anyrights))) {
3102 /* set volume synchronization information */
3103 SetVolumeSync(Sync, volptr);
3105 /* Check if we have permission to change the dir's ACL */
3107 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3112 /* Build and store the new Access List for the dir */
3113 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3117 targetptr->changed_newTime = 1; /* status change of directory */
3119 /* convert the write lock to a read lock before breaking callbacks */
3120 VVnodeWriteToRead(&errorCode, targetptr);
3121 assert_vnode_success_or_salvaging(errorCode);
3123 /* break call backs on the directory */
3124 BreakCallBack(client->z.host, Fid, 0);
3126 /* Get the updated dir's status back to the caller */
3127 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3130 /* Update and store volume/vnode and parent vnodes back */
3131 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
3133 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3134 errorCode = CallPostamble(tcon, errorCode, thost);
3136 fsstats_FinishOp(&fsstats, errorCode);
3138 osi_auditU(acall, StoreACLEvent, errorCode,
3139 AUD_ID, t_client ? t_client->z.ViceId : 0,
3140 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3143 } /*SRXAFS_StoreACL */
3147 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3148 * should be merged when possible.
3151 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3152 struct AFSStoreStatus *InStatus,
3153 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3155 Vnode *targetptr = 0; /* pointer to input fid */
3156 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3157 Error errorCode = 0; /* return code for caller */
3158 Volume *volptr = 0; /* pointer to the volume header */
3159 struct client *client = 0; /* pointer to client structure */
3160 afs_int32 rights, anyrights; /* rights for this and any user */
3161 struct client *t_client = NULL; /* tmp ptr to client data */
3162 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3163 struct rx_connection *tcon = rx_ConnectionOf(acall);
3165 /* Get ptr to client data for user Id for logging */
3166 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3167 logHostAddr.s_addr = rxr_HostOf(tcon);
3169 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3170 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3171 ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
3173 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3176 * Get volume/vnode for the target file; caller's rights to it are
3180 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
3181 &parentwhentargetnotdir, &client, WRITE_LOCK,
3182 &rights, &anyrights))) {
3183 goto Bad_StoreStatus;
3186 /* set volume synchronization information */
3187 SetVolumeSync(Sync, volptr);
3189 /* Check if the caller has proper permissions to store status to Fid */
3191 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3193 goto Bad_StoreStatus;
3196 * Check for a symbolic link; we can't chmod these (otherwise could
3197 * change a symlink to a mt pt or vice versa)
3199 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3201 goto Bad_StoreStatus;
3204 /* Update the status of the target's vnode */
3205 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3206 (parentwhentargetnotdir ? parentwhentargetnotdir
3207 : targetptr), volptr, 0, 0);
3209 /* convert the write lock to a read lock before breaking callbacks */
3210 VVnodeWriteToRead(&errorCode, targetptr);
3211 assert_vnode_success_or_salvaging(errorCode);
3213 /* Break call backs on Fid */
3214 BreakCallBack(client->z.host, Fid, 0);
3216 /* Return the updated status back to caller */
3217 GetStatus(targetptr, OutStatus, rights, anyrights,
3218 parentwhentargetnotdir);
3221 /* Update and store volume/vnode and parent vnodes back */
3222 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
3224 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3227 } /*SAFSS_StoreStatus */
3231 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3232 struct AFSStoreStatus * InStatus,
3233 struct AFSFetchStatus * OutStatus,
3234 struct AFSVolSync * Sync)
3237 struct rx_connection *tcon;
3239 struct client *t_client = NULL; /* tmp ptr to client data */
3240 struct fsstats fsstats;
3242 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_STORESTATUS);
3244 if ((code = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
3245 goto Bad_StoreStatus;
3247 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3250 code = CallPostamble(tcon, code, thost);
3252 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3254 fsstats_FinishOp(&fsstats, code);
3256 osi_auditU(acall, StoreStatusEvent, code,
3257 AUD_ID, t_client ? t_client->z.ViceId : 0,
3258 AUD_FID, Fid, AUD_END);
3261 } /*SRXAFS_StoreStatus */
3265 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3266 * merged in when possible.
3269 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3270 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3272 Vnode *parentptr = 0; /* vnode of input Directory */
3273 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3274 Vnode *targetptr = 0; /* file to be deleted */
3275 Volume *volptr = 0; /* pointer to the volume header */
3276 AFSFid fileFid; /* area for Fid from the directory */
3277 Error errorCode = 0; /* error code */
3278 DirHandle dir; /* Handle for dir package I/O */
3279 struct client *client = 0; /* pointer to client structure */
3280 afs_int32 rights, anyrights; /* rights for this and any user */
3281 struct client *t_client; /* tmp ptr to client data */
3282 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3283 struct rx_connection *tcon = rx_ConnectionOf(acall);
3286 /* Get ptr to client data for user Id for logging */
3287 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3288 logHostAddr.s_addr = rxr_HostOf(tcon);
3290 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3291 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3292 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
3294 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3297 * Get volume/vnode for the parent dir; caller's access rights are
3301 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
3302 &parentwhentargetnotdir, &client, WRITE_LOCK,
3303 &rights, &anyrights))) {
3304 goto Bad_RemoveFile;
3306 /* set volume synchronization information */
3307 SetVolumeSync(Sync, volptr);
3309 /* Does the caller has delete (& write) access to the parent directory? */
3310 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE, client))) {
3311 goto Bad_RemoveFile;
3314 /* Actually delete the desired file */
3316 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3318 goto Bad_RemoveFile;
3321 /* Update the vnode status of the parent dir */
3322 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->z.ViceId,
3323 parentptr->disk.linkCount,
3324 client->z.InSameNetwork);
3326 /* Return the updated parent dir's status back to caller */
3327 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3329 /* Handle internal callback state for the parent and the deleted file */
3330 if (targetptr->disk.linkCount == 0) {
3331 /* no references left, discard entry */
3332 DeleteFileCallBacks(&fileFid);
3333 /* convert the parent lock to a read lock before breaking callbacks */
3334 VVnodeWriteToRead(&errorCode, parentptr);
3335 assert_vnode_success_or_salvaging(errorCode);
3337 /* convert the parent lock to a read lock before breaking callbacks */
3338 VVnodeWriteToRead(&errorCode, parentptr);
3339 assert_vnode_success_or_salvaging(errorCode);
3340 /* convert the target lock to a read lock before breaking callbacks */
3341 VVnodeWriteToRead(&errorCode, targetptr);
3342 assert_vnode_success_or_salvaging(errorCode);
3343 /* tell all the file has changed */
3344 BreakCallBack(client->z.host, &fileFid, 1);
3347 /* break call back on the directory */
3348 BreakCallBack(client->z.host, DirFid, 0);
3351 /* Update and store volume/vnode and parent vnodes back */
3352 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
3355 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3358 } /*SAFSS_RemoveFile */
3362 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3363 struct AFSFetchStatus * OutDirStatus,
3364 struct AFSVolSync * Sync)
3367 struct rx_connection *tcon;
3369 struct client *t_client = NULL; /* tmp ptr to client data */
3370 struct fsstats fsstats;
3372 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_REMOVEFILE);
3374 if ((code = CallPreamble(acall, ACTIVECALL, DirFid, &tcon, &thost)))
3375 goto Bad_RemoveFile;
3377 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3380 code = CallPostamble(tcon, code, thost);
3382 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3384 fsstats_FinishOp(&fsstats, code);
3386 osi_auditU(acall, RemoveFileEvent, code,
3387 AUD_ID, t_client ? t_client->z.ViceId : 0,
3388 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3391 } /*SRXAFS_RemoveFile */
3395 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3396 * be merged in when possible.
3399 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3400 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3401 struct AFSFetchStatus *OutFidStatus,
3402 struct AFSFetchStatus *OutDirStatus,
3403 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3405 Vnode *parentptr = 0; /* vnode of input Directory */
3406 Vnode *targetptr = 0; /* vnode of the new file */
3407 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3408 Volume *volptr = 0; /* pointer to the volume header */
3409 Error errorCode = 0; /* error code */
3410 DirHandle dir; /* Handle for dir package I/O */
3411 struct client *client = 0; /* pointer to client structure */
3412 afs_int32 rights, anyrights; /* rights for this and any user */
3413 struct client *t_client; /* tmp ptr to client data */
3414 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3415 struct rx_connection *tcon = rx_ConnectionOf(acall);
3419 /* Get ptr to client data for user Id for logging */
3420 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3421 logHostAddr.s_addr = rxr_HostOf(tcon);
3423 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3424 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3425 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
3427 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3429 if (!FileNameOK(Name)) {
3431 goto Bad_CreateFile;
3435 * Get associated volume/vnode for the parent dir; caller long are
3439 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
3440 &parentwhentargetnotdir, &client, WRITE_LOCK,
3441 &rights, &anyrights))) {
3442 goto Bad_CreateFile;
3445 /* set volume synchronization information */
3446 SetVolumeSync(Sync, volptr);
3448 /* Can we write (and insert) onto the parent directory? */
3449 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT, client))) {
3450 goto Bad_CreateFile;
3453 /* get a new vnode for the file to be created and set it up */
3455 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3456 vFile, nBlocks(0))))
3457 goto Bad_CreateFile;
3459 /* update the status of the parent vnode */
3460 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->z.ViceId,
3461 parentptr->disk.linkCount,
3462 client->z.InSameNetwork);
3464 /* update the status of the new file's vnode */
3465 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3466 parentptr, volptr, 0, 0);
3468 /* set up the return status for the parent dir and the newly created file, and since the newly created file is owned by the creator, give it PRSFS_ADMINISTER to tell the client its the owner of the file */
3469 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3470 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3472 /* convert the write lock to a read lock before breaking callbacks */
3473 VVnodeWriteToRead(&errorCode, parentptr);
3474 assert_vnode_success_or_salvaging(errorCode);
3476 /* break call back on parent dir */
3477 BreakCallBack(client->z.host, DirFid, 0);
3479 /* Return a callback promise for the newly created file to the caller */
3480 SetCallBackStruct(AddCallBack(client->z.host, OutFid), CallBack);
3483 /* Update and store volume/vnode and parent vnodes back */
3484 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
3487 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3490 } /*SAFSS_CreateFile */
3494 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3495 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3496 struct AFSFetchStatus * OutFidStatus,
3497 struct AFSFetchStatus * OutDirStatus,
3498 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3501 struct rx_connection *tcon;
3503 struct client *t_client = NULL; /* tmp ptr to client data */
3504 struct fsstats fsstats;
3506 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_CREATEFILE);
3508 memset(OutFid, 0, sizeof(struct AFSFid));
3510 if ((code = CallPreamble(acall, ACTIVECALL, DirFid, &tcon, &thost)))
3511 goto Bad_CreateFile;
3514 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3515 OutDirStatus, CallBack, Sync);
3518 code = CallPostamble(tcon, code, thost);
3520 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3522 fsstats_FinishOp(&fsstats, code);
3524 osi_auditU(acall, CreateFileEvent, code,
3525 AUD_ID, t_client ? t_client->z.ViceId : 0,
3526 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3529 } /*SRXAFS_CreateFile */
3533 * This routine is called exclusively from SRXAFS_Rename(), and should be
3534 * merged in when possible.
3537 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3538 struct AFSFid *NewDirFid, char *NewName,
3539 struct AFSFetchStatus *OutOldDirStatus,
3540 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3542 Vnode *oldvptr = 0; /* vnode of the old Directory */
3543 Vnode *newvptr = 0; /* vnode of the new Directory */
3544 Vnode *fileptr = 0; /* vnode of the file to move */
3545 Vnode *newfileptr = 0; /* vnode of the file to delete */
3546 Vnode *testvptr = 0; /* used in directory tree walk */
3547 Vnode *parent = 0; /* parent for use in SetAccessList */
3548 Error errorCode = 0; /* error code */
3549 Error fileCode = 0; /* used when writing Vnodes */
3550 VnodeId testnode; /* used in directory tree walk */
3551 AFSFid fileFid; /* Fid of file to move */
3552 AFSFid newFileFid; /* Fid of new file */
3553 DirHandle olddir; /* Handle for dir package I/O */
3554 DirHandle newdir; /* Handle for dir package I/O */
3555 DirHandle filedir; /* Handle for dir package I/O */
3556 DirHandle newfiledir; /* Handle for dir package I/O */
3557 Volume *volptr = 0; /* pointer to the volume header */
3558 struct client *client = 0; /* pointer to client structure */
3559 afs_int32 rights, anyrights; /* rights for this and any user */
3560 afs_int32 newrights; /* rights for this user */
3561 afs_int32 newanyrights; /* rights for any user */
3562 int doDelete; /* deleted the rename target (ref count now 0) */
3564 int updatefile = 0; /* are we changing the renamed file? (we do this
3565 * if we need to update .. on a renamed dir) */
3566 struct client *t_client; /* tmp ptr to client data */
3567 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3568 struct rx_connection *tcon = rx_ConnectionOf(acall);
3574 FidZero(&newfiledir);
3576 /* Get ptr to client data for user Id for logging */
3577 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3578 logHostAddr.s_addr = rxr_HostOf(tcon);
3580 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3581 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3582 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3583 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
3585 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3587 if (!FileNameOK(NewName)) {
3591 if (OldDirFid->Volume != NewDirFid->Volume) {
3596 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3597 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3598 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3604 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3606 GetVolumePackage(acall, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3607 &parent, &client, WRITE_LOCK, &rights,
3612 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3614 newrights = rights, newanyrights = anyrights;
3617 GetVolumePackage(acall, NewDirFid, &volptr, &newvptr,
3618 MustBeDIR, &parent, &client, WRITE_LOCK,
3619 &newrights, &newanyrights))) {
3625 GetVolumePackage(acall, NewDirFid, &volptr, &newvptr, MustBeDIR,
3626 &parent, &client, WRITE_LOCK, &newrights,
3632 GetVolumePackage(acall, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3633 &parent, &client, WRITE_LOCK, &rights,
3640 /* set volume synchronization information */
3641 SetVolumeSync(Sync, volptr);
3643 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE, client))) {
3646 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT,
3651 if (CheckLength(volptr, oldvptr, -1) ||
3652 CheckLength(volptr, newvptr, -1)) {
3653 VTakeOffline(volptr);
3654 errorCode = VSALVAGE;
3658 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3659 * call to CopyOnWrite returns error, it is not necessary to revert back
3660 * the effects of the first call because the contents of the volume is
3661 * not modified, it is only replicated.
3663 if (oldvptr->disk.cloned) {
3664 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3665 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
3668 SetDirHandle(&olddir, oldvptr);
3669 if (newvptr->disk.cloned) {
3670 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3671 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
3675 SetDirHandle(&newdir, newvptr);
3677 /* Lookup the file to delete its vnode */
3678 errorCode = afs_dir_Lookup(&olddir, OldName, &fileFid);
3679 if (errorCode && errorCode != ENOENT) {
3685 if (fileFid.Vnode == oldvptr->vnodeNumber
3686 || fileFid.Vnode == newvptr->vnodeNumber) {
3687 errorCode = FSERR_ELOOP;
3690 fileFid.Volume = V_id(volptr);
3691 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3692 if (errorCode != 0) {
3694 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3695 OldName, errorCode));
3696 VTakeOffline(volptr);
3699 if (fileptr->disk.uniquifier != fileFid.Unique) {
3701 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3703 VTakeOffline(volptr);
3708 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3709 && fileptr->disk.linkCount != 1) {
3711 * Hard links exist to this file - cannot move one of the links to
3712 * a new directory because of AFS restrictions (this is the same
3713 * reason that links cannot be made across directories, i.e.
3720 /* Lookup the new file */
3721 code = afs_dir_Lookup(&newdir, NewName, &newFileFid);
3722 if (code && code != ENOENT) {
3727 if (!IsWriteAllowed(client)) {
3728 errorCode = VREADONLY;
3731 if (!(newrights & PRSFS_DELETE)) {
3735 if (newFileFid.Vnode == oldvptr->vnodeNumber
3736 || newFileFid.Vnode == newvptr->vnodeNumber
3737 || newFileFid.Vnode == fileFid.Vnode) {
3741 newFileFid.Volume = V_id(volptr);
3743 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3744 if (errorCode != 0) {
3746 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
3747 NewName, errorCode));
3748 VTakeOffline(volptr);
3751 if (fileptr->disk.uniquifier != fileFid.Unique) {
3753 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
3755 VTakeOffline(volptr);
3759 SetDirHandle(&newfiledir, newfileptr);
3760 /* Now check that we're moving directories over directories properly, etc.
3761 * return proper POSIX error codes:
3762 * if fileptr is a file and new is a dir: EISDIR.
3763 * if fileptr is a dir and new is a file: ENOTDIR.
3764 * Also, dir to be removed must be empty, of course.
3766 if (newfileptr->disk.type == vDirectory) {
3767 if (fileptr->disk.type != vDirectory) {
3771 if ((afs_dir_IsEmpty(&newfiledir))) {
3776 if (fileptr->disk.type == vDirectory) {
3777 errorCode = ENOTDIR;
3784 * ok - now we check that the old name is not above new name in the
3785 * directory structure. This is to prevent removing a subtree alltogether
3787 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
3788 afs_int32 forpass = 0, vnum = 0, top = 0;
3789 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
3790 if (testnode > vnum) vnum = testnode;
3791 if (forpass > vnum) {
3792 errorCode = FSERR_ELOOP;
3795 if (testnode == oldvptr->vnodeNumber) {
3796 testnode = oldvptr->disk.parent;
3799 if ((testnode == fileptr->vnodeNumber)
3800 || (testnode == newvptr->vnodeNumber)) {
3801 errorCode = FSERR_ELOOP;
3804 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
3805 errorCode = FSERR_ELOOP;
3808 if (testnode == 1) top = 1;
3809 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
3810 assert_vnode_success_or_salvaging(errorCode);
3811 testnode = testvptr->disk.parent;
3812 VPutVnode(&errorCode, testvptr);
3813 if ((top == 1) && (testnode != 0)) {
3814 VTakeOffline(volptr);
3816 ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
3817 afs_printable_VolumeId_lu(volptr->hashid)));
3821 assert_vnode_success_or_salvaging(errorCode);
3825 if (fileptr->disk.type == vDirectory) {
3826 SetDirHandle(&filedir, fileptr);
3827 if (oldvptr != newvptr) {
3828 /* we always need to update .. if we've moving fileptr to a
3829 * different directory */
3832 struct AFSFid unused;
3834 code = afs_dir_Lookup(&filedir, "..", &unused);
3835 if (code && code != ENOENT) {
3839 if (code == ENOENT) {
3840 /* only update .. if it doesn't already exist */
3846 /* Do the CopyonWrite first before modifying anything else. Copying is
3847 * required when we have to change entries for ..
3849 if (updatefile && (fileptr->disk.cloned)) {
3850 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
3851 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
3853 /* since copyonwrite would mean fileptr has a new handle, do it here */
3855 SetDirHandle(&filedir, fileptr);
3858 /* If the new name exists already, delete it and the file it points to */
3861 /* Delete NewName from its directory */
3862 code = afs_dir_Delete(&newdir, NewName);
3863 opr_Assert(code == 0);
3865 /* Drop the link count */
3866 newfileptr->disk.linkCount--;
3867 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
3868 afs_fsize_t newSize;
3869 VN_GET_LEN(newSize, newfileptr);
3870 VAdjustDiskUsage((Error *) & errorCode, volptr,
3871 (afs_sfsize_t) - nBlocks(newSize), 0);
3872 if (VN_GET_INO(newfileptr)) {
3873 IH_REALLYCLOSE(newfileptr->handle);
3875 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
3876 V_parentId(volptr));
3877 IH_RELEASE(newfileptr->handle);
3878 if (errorCode == -1) {
3880 ("Del: inode=%s, name=%s, errno=%d\n",
3881 PrintInode(stmp, VN_GET_INO(newfileptr)),
3883 if ((errno != ENOENT) && (errno != EIO)
3884 && (errno != ENXIO))
3885 ViceLog(0, ("Do we need to fsck?\n"));
3888 VN_SET_INO(newfileptr, (Inode) 0);
3889 newfileptr->delete = 1; /* Mark NewName vnode to delete */
3892 /* Link count did not drop to zero.
3893 * Mark NewName vnode as changed - updates stime.
3895 newfileptr->changed_newTime = 1;
3900 * If the create below fails, and the delete above worked, we have
3901 * removed the new name and not replaced it. This is not very likely,
3902 * but possible. We could try to put the old file back, but it is
3903 * highly unlikely that it would work since it would involve issuing
3906 if ((errorCode = afs_dir_Create(&newdir, NewName, &fileFid)))
3909 /* Delete the old name */
3910 opr_Assert(afs_dir_Delete(&olddir, OldName) == 0);
3912 /* if the directory length changes, reflect it in the statistics */
3913 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->z.ViceId,
3914 oldvptr->disk.linkCount, client->z.InSameNetwork);
3915 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->z.ViceId,
3916 newvptr->disk.linkCount, client->z.InSameNetwork);
3918 if (oldvptr == newvptr)
3919 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
3921 if (fileptr->disk.parent != newvptr->vnodeNumber) {
3922 fileptr->disk.parent = newvptr->vnodeNumber;
3923 fileptr->changed_newTime = 1;
3926 /* if we are dealing with a rename of a directory, and we need to
3927 * update the .. entry of that directory */
3929 opr_Assert(!fileptr->disk.cloned);
3931 fileptr->changed_newTime = 1; /* status change of moved file */
3933 /* fix .. to point to the correct place */
3934 afs_dir_Delete(&filedir, ".."); /* No assert--some directories may be bad */
3935 opr_Assert(afs_dir_Create(&filedir, "..", NewDirFid) == 0);
3936 fileptr->disk.dataVersion++;
3938 /* if the parent directories are different the link counts have to be */
3939 /* changed due to .. in the renamed directory */
3940 if (oldvptr != newvptr) {
3941 oldvptr->disk.linkCount--;
3942 newvptr->disk.linkCount++;
3946 /* set up return status */
3947 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
3948 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
3949 if (newfileptr && doDelete) {
3950 DeleteFileCallBacks(&newFileFid); /* no other references */
3955 /* convert the write locks to a read locks before breaking callbacks */
3956 VVnodeWriteToRead(&errorCode, newvptr);
3957 assert_vnode_success_or_salvaging(errorCode);
3958 if (oldvptr != newvptr) {
3959 VVnodeWriteToRead(&errorCode, oldvptr);
3960 assert_vnode_success_or_salvaging(errorCode);
3962 if (newfileptr && !doDelete) {
3963 /* convert the write lock to a read lock before breaking callbacks */
3964 VVnodeWriteToRead(&errorCode, newfileptr);
3965 assert_vnode_success_or_salvaging(errorCode);
3968 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
3969 BreakCallBack(client->z.host, NewDirFid, 0);
3970 if (oldvptr != newvptr) {
3971 BreakCallBack(client->z.host, OldDirFid, 0);
3974 /* if a dir moved, .. changed */
3975 /* we do not give an AFSFetchStatus structure back to the
3976 * originating client, and the file's status has changed, so be
3977 * sure to send a callback break. In theory the client knows
3978 * enough to know that the callback could be broken implicitly,
3979 * but that may not be clear, and some client implementations
3980 * may not know to. */
3981 BreakCallBack(client->z.host, &fileFid, 1);
3984 /* Note: it is not necessary to break the callback */
3986 DeleteFileCallBacks(&newFileFid); /* no other references */
3988 /* other's still exist (with wrong link count) */
3989 BreakCallBack(client->z.host, &newFileFid, 1);
3994 VPutVnode(&fileCode, newfileptr);
3995 assert_vnode_success_or_salvaging(fileCode);
3997 (void)PutVolumePackage(acall, fileptr, (newvptr && newvptr != oldvptr ?
3998 newvptr : 0), oldvptr, volptr, &client);
4002 FidZap(&newfiledir);
4003 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4010 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4011 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4012 struct AFSFetchStatus * OutOldDirStatus,
4013 struct AFSFetchStatus * OutNewDirStatus,
4014 struct AFSVolSync * Sync)
4017 struct rx_connection *tcon;
4019 struct client *t_client = NULL; /* tmp ptr to client data */
4020 struct fsstats fsstats;
4022 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_RENAME);
4024 if ((code = CallPreamble(acall, ACTIVECALL, OldDirFid, &tcon, &thost)))
4028 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4029 OutOldDirStatus, OutNewDirStatus, Sync);
4032 code = CallPostamble(tcon, code, thost);
4034 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4036 fsstats_FinishOp(&fsstats, code);
4038 osi_auditU(acall, RenameFileEvent, code,
4039 AUD_ID, t_client ? t_client->z.ViceId : 0,
4040 AUD_FID, OldDirFid, AUD_STR, OldName,
4041 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4044 } /*SRXAFS_Rename */
4048 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4049 * merged into it when possible.
4052 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4053 char *LinkContents, struct AFSStoreStatus *InStatus,
4054 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4055 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4057 Vnode *parentptr = 0; /* vnode of input Directory */
4058 Vnode *targetptr = 0; /* vnode of the new link */
4059 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4060 Error errorCode = 0; /* error code */
4063 DirHandle dir; /* Handle for dir package I/O */
4064 Volume *volptr = 0; /* pointer to the volume header */
4065 struct client *client = 0; /* pointer to client structure */
4066 afs_int32 rights, anyrights; /* rights for this and any user */
4067 struct client *t_client; /* tmp ptr to client data */
4068 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4070 struct rx_connection *tcon = rx_ConnectionOf(acall);
4074 /* Get ptr to client data for user Id for logging */
4075 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4076 logHostAddr.s_addr = rxr_HostOf(tcon);
4078 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4079 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4080 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
4082 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4084 if (!FileNameOK(Name)) {
4090 * Get the vnode and volume for the parent dir along with the caller's
4094 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4095 &parentwhentargetnotdir, &client, WRITE_LOCK,
4096 &rights, &anyrights)))
4099 /* set volume synchronization information */
4100 SetVolumeSync(Sync, volptr);
4102 /* Does the caller has insert (and write) access to the parent directory? */
4103 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT, client)))
4107 * If we're creating a mount point (any x bits clear), we must have
4108 * administer access to the directory, too. Always allow sysadmins
4111 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4112 if (!IsWriteAllowed(client)) {
4113 errorCode = VREADONLY;
4117 * We have a mountpoint, 'cause we're trying to set the Unix mode
4118 * bits to something with some x bits missing (default mode bits
4119 * if AFS_SETMODE is false is 0777)
4121 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4127 /* get a new vnode for the symlink and set it up */
4129 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4130 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4134 /* update the status of the parent vnode */
4135 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->z.ViceId,
4136 parentptr->disk.linkCount,
4137 client->z.InSameNetwork);
4139 /* update the status of the new symbolic link file vnode */
4140 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4141 parentptr, volptr, strlen((char *)LinkContents), 0);
4143 /* Write the contents of the symbolic link name into the target inode */
4144 fdP = IH_OPEN(targetptr->handle);
4146 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4147 parentptr, volptr, &client);
4148 VTakeOffline(volptr);
4149 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
4150 afs_printable_VolumeId_lu(volptr->hashid)));
4153 len = strlen((char *) LinkContents);
4154 code = (len == FDH_PWRITE(fdP, (char *) LinkContents, len, 0)) ? 0 : VDISKFULL;
4156 ViceLog(0, ("SAFSS_Symlink FDH_PWRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4159 * Set up and return modified status for the parent dir and new symlink
4162 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4163 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4165 /* convert the write lock to a read lock before breaking callbacks */
4166 VVnodeWriteToRead(&errorCode, parentptr);
4167 assert_vnode_success_or_salvaging(errorCode);
4169 /* break call back on the parent dir */
4170 BreakCallBack(client->z.host, DirFid, 0);
4173 /* Write the all modified vnodes (parent, new files) and volume back */
4174 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4177 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4178 return ( errorCode ? errorCode : code );
4180 } /*SAFSS_Symlink */
4184 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4185 struct AFSFid *DirFid, /* Parent dir's fid */
4186 char *Name, /* File name to create */
4187 char *LinkContents, /* Contents of the new created file */
4188 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4189 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4190 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4191 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4192 struct AFSVolSync *Sync)
4195 struct rx_connection *tcon;
4197 struct client *t_client = NULL; /* tmp ptr to client data */
4198 struct fsstats fsstats;
4200 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SYMLINK);
4202 if ((code = CallPreamble(acall, ACTIVECALL, DirFid, &tcon, &thost)))
4206 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4207 OutFidStatus, OutDirStatus, Sync);
4210 code = CallPostamble(tcon, code, thost);
4212 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4214 fsstats_FinishOp(&fsstats, code);
4216 osi_auditU(acall, SymlinkEvent, code,
4217 AUD_ID, t_client ? t_client->z.ViceId : 0,
4218 AUD_FID, DirFid, AUD_STR, Name,
4219 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4222 } /*SRXAFS_Symlink */
4226 * This routine is called exclusively by SRXAFS_Link(), and should be
4227 * merged into it when possible.
4230 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4231 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4232 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4234 Vnode *parentptr = 0; /* vnode of input Directory */
4235 Vnode *targetptr = 0; /* vnode of the new file */
4236 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4237 Volume *volptr = 0; /* pointer to the volume header */
4238 Error errorCode = 0; /* error code */
4239 DirHandle dir; /* Handle for dir package I/O */
4240 struct client *client = 0; /* pointer to client structure */
4241 afs_int32 rights, anyrights; /* rights for this and any user */
4242 struct client *t_client; /* tmp ptr to client data */
4243 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4244 struct rx_connection *tcon = rx_ConnectionOf(acall);
4248 /* Get ptr to client data for user Id for logging */
4249 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4250 logHostAddr.s_addr = rxr_HostOf(tcon);
4252 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4253 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4254 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4255 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
4257 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4259 if (DirFid->Volume != ExistingFid->Volume) {
4263 if (!FileNameOK(Name)) {
4269 * Get the vnode and volume for the parent dir along with the caller's
4273 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4274 &parentwhentargetnotdir, &client, WRITE_LOCK,
4275 &rights, &anyrights))) {
4279 /* set volume synchronization information */
4280 SetVolumeSync(Sync, volptr);
4282 /* Can the caller insert into the parent directory? */
4283 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT, client))) {
4287 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4288 /* AFS fileservers always have directory vnodes that are odd. */
4293 if (CheckLength(volptr, parentptr, -1)) {
4294 VTakeOffline(volptr);
4295 errorCode = VSALVAGE;
4299 /* get the file vnode */
4301 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4305 if (targetptr->disk.type != vFile) {
4309 if (targetptr->disk.parent != DirFid->Vnode) {
4313 if (parentptr->disk.cloned) {
4314 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4315 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4316 goto Bad_Link; /* disk full error */
4319 /* add the name to the directory */
4320 SetDirHandle(&dir, parentptr);
4321 if ((errorCode = afs_dir_Create(&dir, Name, ExistingFid)))
4325 /* update the status in the parent vnode */
4326 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4327 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->z.ViceId,
4328 parentptr->disk.linkCount,
4329 client->z.InSameNetwork);
4331 targetptr->disk.linkCount++;
4332 targetptr->disk.author = client->z.ViceId;
4333 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4335 /* set up return status */
4336 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4337 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4339 /* convert the write locks to read locks before breaking callbacks */
4340 VVnodeWriteToRead(&errorCode, targetptr);
4341 assert_vnode_success_or_salvaging(errorCode);
4342 VVnodeWriteToRead(&errorCode, parentptr);
4343 assert_vnode_success_or_salvaging(errorCode);
4345 /* break call back on DirFid */
4346 BreakCallBack(client->z.host, DirFid, 0);
4348 * We also need to break the callback for the file that is hard-linked since part
4349 * of its status (like linkcount) is changed
4351 BreakCallBack(client->z.host, ExistingFid, 0);
4354 /* Write the all modified vnodes (parent, new files) and volume back */
4355 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4358 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4365 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4366 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4367 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4370 struct rx_connection *tcon;
4372 struct client *t_client = NULL; /* tmp ptr to client data */
4373 struct fsstats fsstats;
4375 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_LINK);
4377 if ((code = CallPreamble(acall, ACTIVECALL, DirFid, &tcon, &thost)))
4381 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4382 OutDirStatus, Sync);
4385 code = CallPostamble(tcon, code, thost);
4387 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4389 fsstats_FinishOp(&fsstats, code);
4391 osi_auditU(acall, LinkEvent, code,
4392 AUD_ID, t_client ? t_client->z.ViceId : 0,
4393 AUD_FID, DirFid, AUD_STR, Name,
4394 AUD_FID, ExistingFid, AUD_END);
4401 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4402 * merged into it when possible.
4405 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4406 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4407 struct AFSFetchStatus *OutFidStatus,
4408 struct AFSFetchStatus *OutDirStatus,
4409 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4411 Vnode *parentptr = 0; /* vnode of input Directory */
4412 Vnode *targetptr = 0; /* vnode of the new file */
4413 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4414 Volume *volptr = 0; /* pointer to the volume header */
4415 Error errorCode = 0; /* error code */
4416 struct acl_accessList *newACL; /* Access list */
4417 int newACLSize; /* Size of access list */
4418 DirHandle dir; /* Handle for dir package I/O */
4419 DirHandle parentdir; /* Handle for dir package I/O */
4420 struct client *client = 0; /* pointer to client structure */
4421 afs_int32 rights, anyrights; /* rights for this and any user */
4422 struct client *t_client; /* tmp ptr to client data */
4423 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4424 struct rx_connection *tcon = rx_ConnectionOf(acall);
4427 FidZero(&parentdir);
4429 /* Get ptr to client data for user Id for logging */
4430 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4431 logHostAddr.s_addr = rxr_HostOf(tcon);
4433 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4434 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4435 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
4437 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4439 if (!FileNameOK(Name)) {
4445 * Get the vnode and volume for the parent dir along with the caller's
4449 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4450 &parentwhentargetnotdir, &client, WRITE_LOCK,
4451 &rights, &anyrights))) {
4455 /* set volume synchronization information */
4456 SetVolumeSync(Sync, volptr);
4458 /* Write access to the parent directory? */
4459 #ifdef DIRCREATE_NEED_WRITE
4461 * requires w access for the user to create a directory. this
4462 * closes a loophole in the current security arrangement, since a
4463 * user with i access only can create a directory and get the
4464 * implcit a access that goes with dir ownership, and proceed to
4465 * subvert quota in the volume.
4467 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT, client))
4468 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE,
4471 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT, client))) {
4472 #endif /* DIRCREATE_NEED_WRITE */
4475 #define EMPTYDIRBLOCKS 2
4476 /* get a new vnode and set it up */
4478 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4479 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4483 /* Update the status for the parent dir */
4484 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->z.ViceId,
4485 parentptr->disk.linkCount + 1,
4486 client->z.InSameNetwork);
4488 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4489 opr_Verify((SetAccessList(&targetptr, &volptr, &newACL, &newACLSize,
4490 &parentwhentargetnotdir, NULL, 0)) == 0);
4491 opr_Assert(parentwhentargetnotdir == 0);
4492 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4494 /* update the status for the target vnode */
4495 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4496 parentptr, volptr, 0, 0);
4498 /* Actually create the New directory in the directory package */
4499 SetDirHandle(&dir, targetptr);
4500 opr_Verify(!(afs_dir_MakeDir(&dir, (afs_int32 *)OutFid,
4501 (afs_int32 *)DirFid)));
4503 VN_SET_LEN(targetptr, (afs_fsize_t) afs_dir_Length(&dir));
4505 /* set up return status */
4506 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4507 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4509 /* convert the write lock to a read lock before breaking callbacks */
4510 VVnodeWriteToRead(&errorCode, parentptr);
4511 assert_vnode_success_or_salvaging(errorCode);
4513 /* break call back on DirFid */
4514 BreakCallBack(client->z.host, DirFid, 0);
4516 /* Return a callback promise to caller */
4517 SetCallBackStruct(AddCallBack(client->z.host, OutFid), CallBack);
4520 /* Write the all modified vnodes (parent, new files) and volume back */
4521 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4525 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4528 } /*SAFSS_MakeDir */
4532 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4533 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4534 struct AFSFetchStatus * OutFidStatus,
4535 struct AFSFetchStatus * OutDirStatus,
4536 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4539 struct rx_connection *tcon;
4541 struct client *t_client = NULL; /* tmp ptr to client data */
4542 struct fsstats fsstats;
4544 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_MAKEDIR);
4546 if ((code = CallPreamble(acall, ACTIVECALL, DirFid, &tcon, &thost)))
4550 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4551 OutDirStatus, CallBack, Sync);
4554 code = CallPostamble(tcon, code, thost);
4556 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4558 fsstats_FinishOp(&fsstats, code);
4560 osi_auditU(acall, MakeDirEvent, code,
4561 AUD_ID, t_client ? t_client->z.ViceId : 0,
4562 AUD_FID, DirFid, AUD_STR, Name,
4563 AUD_FID, OutFid, AUD_END);
4566 } /*SRXAFS_MakeDir */
4570 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4571 * merged into it when possible.
4574 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4575 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4577 Vnode *parentptr = 0; /* vnode of input Directory */
4578 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4579 Vnode *targetptr = 0; /* file to be deleted */
4580 AFSFid fileFid; /* area for Fid from the directory */
4581 Error errorCode = 0; /* error code */
4582 DirHandle dir; /* Handle for dir package I/O */
4583 Volume *volptr = 0; /* pointer to the volume header */
4584 struct client *client = 0; /* pointer to client structure */
4585 afs_int32 rights, anyrights; /* rights for this and any user */
4586 struct client *t_client; /* tmp ptr to client data */
4587 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4588 struct rx_connection *tcon = rx_ConnectionOf(acall);
4592 /* Get ptr to client data for user Id for logging */
4593 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4594 logHostAddr.s_addr = rxr_HostOf(tcon);
4596 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4597 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4598 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
4600 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4603 * Get the vnode and volume for the parent dir along with the caller's
4607 GetVolumePackage(acall, DirFid, &volptr, &parentptr, MustBeDIR,
4608 &parentwhentargetnotdir, &client, WRITE_LOCK,
4609 &rights, &anyrights))) {
4613 /* set volume synchronization information */
4614 SetVolumeSync(Sync, volptr);
4616 /* Does the caller has delete (&write) access to the parent dir? */
4617 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE, client))) {
4621 /* Do the actual delete of the desired (empty) directory, Name */
4623 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
4628 /* Update the status for the parent dir; link count is also adjusted */
4629 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->z.ViceId,
4630 parentptr->disk.linkCount - 1,
4631 client->z.InSameNetwork);
4633 /* Return to the caller the updated parent dir status */
4634 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4637 * Note: it is not necessary to break the callback on fileFid, since
4638 * refcount is now 0, so no one should be able to refer to the dir
4641 DeleteFileCallBacks(&fileFid);
4643 /* convert the write lock to a read lock before breaking callbacks */
4644 VVnodeWriteToRead(&errorCode, parentptr);
4645 assert_vnode_success_or_salvaging(errorCode);
4647 /* break call back on DirFid and fileFid */
4648 BreakCallBack(client->z.host, DirFid, 0);
4651 /* Write the all modified vnodes (parent, new files) and volume back */
4652 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr, parentptr,
4655 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
4658 } /*SAFSS_RemoveDir */
4662 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4663 struct AFSFetchStatus * OutDirStatus,
4664 struct AFSVolSync * Sync)
4667 struct rx_connection *tcon;
4669 struct client *t_client = NULL; /* tmp ptr to client data */
4670 struct fsstats fsstats;
4672 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_REMOVEDIR);
4674 if ((code = CallPreamble(acall, ACTIVECALL, DirFid, &tcon, &thost)))
4677 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
4680 code = CallPostamble(tcon, code, thost);
4682 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4684 fsstats_FinishOp(&fsstats, code);
4686 osi_auditU(acall, RemoveDirEvent, code,
4687 AUD_ID, t_client ? t_client->z.ViceId : 0,
4688 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
4691 } /*SRXAFS_RemoveDir */
4695 * This routine is called exclusively by SRXAFS_SetLock(), and should be
4696 * merged into it when possible.
4699 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
4700 struct AFSVolSync *Sync)
4702 Vnode *targetptr = 0; /* vnode of input file */
4703 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4704 Error errorCode = 0; /* error code */
4705 Volume *volptr = 0; /* pointer to the volume header */
4706 struct client *client = 0; /* pointer to client structure */
4707 afs_int32 rights, anyrights; /* rights for this and any user */
4708 struct client *t_client; /* tmp ptr to client data */
4709 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4710 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
4711 struct rx_connection *tcon = rx_ConnectionOf(acall);
4713 if (type != LockRead && type != LockWrite) {
4717 /* Get ptr to client data for user Id for logging */
4718 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4719 logHostAddr.s_addr = rxr_HostOf(tcon);
4721 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4722 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
4723 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
4725 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
4728 * Get the vnode and volume for the desired file along with the caller's
4732 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
4733 &parentwhentargetnotdir, &client, WRITE_LOCK,
4734 &rights, &anyrights))) {
4738 /* set volume synchronization information */
4739 SetVolumeSync(Sync, volptr);
4741 /* Handle the particular type of set locking, type */
4742 errorCode = HandleLocking(targetptr, client, rights, type);
4745 /* Write the all modified vnodes (parent, new files) and volume back */
4746 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4747 (Vnode *) 0, volptr, &client);
4749 if ((errorCode == VREADONLY) && (type == LockRead))
4750 errorCode = 0; /* allow read locks on RO volumes without saving state */
4752 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
4755 } /*SAFSS_SetLock */
4759 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
4760 ViceLockType type, struct AFSVolSync * Sync)
4762 return SRXAFS_SetLock(acall, Fid, type, Sync);
4763 } /*SRXAFS_OldSetLock */
4767 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
4768 struct AFSVolSync * Sync)
4771 struct rx_connection *tcon;
4773 struct client *t_client = NULL; /* tmp ptr to client data */
4774 struct fsstats fsstats;
4776 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SETLOCK);
4778 if ((code = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
4781 code = SAFSS_SetLock(acall, Fid, type, Sync);
4784 code = CallPostamble(tcon, code, thost);
4786 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4788 fsstats_FinishOp(&fsstats, code);
4790 osi_auditU(acall, SetLockEvent, code,
4791 AUD_ID, t_client ? t_client->z.ViceId : 0,
4792 AUD_FID, Fid, AUD_LONG, type, AUD_END);
4794 } /*SRXAFS_SetLock */
4798 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
4799 * merged into it when possible.
4802 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
4803 struct AFSVolSync *Sync)
4805 Vnode *targetptr = 0; /* vnode of input file */
4806 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4807 Error errorCode = 0; /* error code */
4808 Volume *volptr = 0; /* pointer to the volume header */
4809 struct client *client = 0; /* pointer to client structure */
4810 afs_int32 rights, anyrights; /* rights for this and any user */
4811 struct client *t_client; /* tmp ptr to client data */
4812 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4813 struct rx_connection *tcon = rx_ConnectionOf(acall);
4815 /* Get ptr to client data for user Id for logging */
4816 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4817 logHostAddr.s_addr = rxr_HostOf(tcon);
4819 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
4820 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
4821 ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
4823 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
4826 * Get the vnode and volume for the desired file along with the caller's
4830 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
4831 &parentwhentargetnotdir, &client, WRITE_LOCK,
4832 &rights, &anyrights))) {
4833 goto Bad_ExtendLock;
4836 /* set volume synchronization information */
4837 SetVolumeSync(Sync, volptr);
4839 /* Handle the actual lock extension */
4840 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
4843 /* Put back file's vnode and volume */
4844 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4845 (Vnode *) 0, volptr, &client);
4847 if (errorCode == VREADONLY) /* presumably, we already granted this lock */
4848 errorCode = 0; /* under our generous policy re RO vols */
4850 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
4853 } /*SAFSS_ExtendLock */
4857 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
4858 struct AFSVolSync * Sync)
4860 return SRXAFS_ExtendLock(acall, Fid, Sync);
4861 } /*SRXAFS_OldExtendLock */
4865 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
4866 struct AFSVolSync * Sync)
4869 struct rx_connection *tcon;
4871 struct client *t_client = NULL; /* tmp ptr to client data */
4872 struct fsstats fsstats;
4874 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_EXTENDLOCK);
4876 if ((code = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
4877 goto Bad_ExtendLock;
4879 code = SAFSS_ExtendLock(acall, Fid, Sync);
4882 code = CallPostamble(tcon, code, thost);
4884 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4886 fsstats_FinishOp(&fsstats, code);
4888 osi_auditU(acall, ExtendLockEvent, code,
4889 AUD_ID, t_client ? t_client->z.ViceId : 0,
4890 AUD_FID, Fid, AUD_END);
4893 } /*SRXAFS_ExtendLock */
4897 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
4898 * merged into it when possible.
4901 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
4902 struct AFSVolSync *Sync)
4904 Vnode *targetptr = 0; /* vnode of input file */
4905 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4906 Error errorCode = 0; /* error code */
4907 Volume *volptr = 0; /* pointer to the volume header */
4908 struct client *client = 0; /* pointer to client structure */
4909 afs_int32 rights, anyrights; /* rights for this and any user */
4910 struct client *t_client; /* tmp ptr to client data */
4911 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4912 struct rx_connection *tcon = rx_ConnectionOf(acall);
4914 /* Get ptr to client data for user Id for logging */
4915 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4916 logHostAddr.s_addr = rxr_HostOf(tcon);
4918 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
4919 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
4920 ntohs(rxr_PortOf(tcon)), t_client->z.ViceId));
4922 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
4925 * Get the vnode and volume for the desired file along with the caller's
4929 GetVolumePackage(acall, Fid, &volptr, &targetptr, DONTCHECK,
4930 &parentwhentargetnotdir, &client, WRITE_LOCK,
4931 &rights, &anyrights))) {
4932 goto Bad_ReleaseLock;
4935 /* set volume synchronization information */
4936 SetVolumeSync(Sync, volptr);
4938 /* Handle the actual lock release */
4939 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
4940 goto Bad_ReleaseLock;
4942 /* if no more locks left, a callback would be triggered here */
4943 if (targetptr->disk.lock.lockCount <= 0) {
4944 /* convert the write lock to a read lock before breaking callbacks */
4945 VVnodeWriteToRead(&errorCode, targetptr);
4946 assert_vnode_success_or_salvaging(errorCode);
4947 BreakCallBack(client->z.host, Fid, 0);
4951 /* Put back file's vnode and volume */
4952 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
4953 (Vnode *) 0, volptr, &client);
4955 if (errorCode == VREADONLY) /* presumably, we already granted this lock */
4956 errorCode = 0; /* under our generous policy re RO vols */
4958 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
4961 } /*SAFSS_ReleaseLock */
4965 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
4966 struct AFSVolSync * Sync)
4968 return SRXAFS_ReleaseLock(acall, Fid, Sync);
4969 } /*SRXAFS_OldReleaseLock */
4973 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
4974 struct AFSVolSync * Sync)
4977 struct rx_connection *tcon;
4979 struct client *t_client = NULL; /* tmp ptr to client data */
4980 struct fsstats fsstats;
4982 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_RELEASELOCK);
4984 if ((code = CallPreamble(acall, ACTIVECALL, Fid, &tcon, &thost)))
4985 goto Bad_ReleaseLock;
4987 code = SAFSS_ReleaseLock(acall, Fid, Sync);
4990 code = CallPostamble(tcon, code, thost);
4992 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4994 fsstats_FinishOp(&fsstats, code);
4996 osi_auditU(acall, ReleaseLockEvent, code,
4997 AUD_ID, t_client ? t_client->z.ViceId : 0,
4998 AUD_FID, Fid, AUD_END);
5001 } /*SRXAFS_ReleaseLock */
5005 SetSystemStats(struct AFSStatistics *stats)
5007 /* Fix this sometime soon.. */
5008 /* Because hey, it's not like we have a network monitoring protocol... */
5010 stats->CurrentTime = time(NULL);
5011 } /*SetSystemStats */
5014 SetAFSStats(struct AFSStatistics *stats)
5016 extern afs_int32 StartTime, CurrentConnections;
5020 stats->CurrentMsgNumber = 0;
5021 stats->OldestMsgNumber = 0;
5022 stats->StartTime = StartTime;
5023 stats->CurrentConnections = CurrentConnections;
5024 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5025 stats->TotalFetchs =
5026 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5027 AFSCallStats.FetchStatus;
5028 stats->FetchDatas = AFSCallStats.FetchData;
5029 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5030 seconds = AFSCallStats.AccumFetchTime / 1000;
5033 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5034 stats->TotalStores =
5035 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5036 AFSCallStats.StoreStatus;
5037 stats->StoreDatas = AFSCallStats.StoreData;
5038 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5039 seconds = AFSCallStats.AccumStoreTime / 1000;
5042 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5043 stats->ProcessSize = opr_procsize();
5045 h_GetWorkStats((int *)&(stats->WorkStations),
5046 (int *)&(stats->ActiveWorkStations), (int *)0,
5047 (afs_int32) (time(NULL)) - (15 * 60));
5051 /* Get disk related information from all AFS partitions. */
5054 SetVolumeStats(struct AFSStatistics *stats)
5056 struct DiskPartition64 *part;
5059 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5060 part = part->next) {
5061 stats->Disks[i].TotalBlocks = RoundInt64ToInt31(part->totalUsable);
5062 stats->Disks[i].BlocksAvailable = RoundInt64ToInt31(part->free);
5063 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5064 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5067 while (i < AFS_MSTATDISKS) {
5068 stats->Disks[i].TotalBlocks = -1;
5071 } /*SetVolumeStats */
5074 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5077 struct rx_connection *tcon = rx_ConnectionOf(acall);
5079 struct client *t_client = NULL; /* tmp ptr to client data */
5080 struct fsstats fsstats;
5082 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETSTATISTICS);
5084 if ((code = CallPreamble(acall, NOTACTIVECALL, NULL, &tcon, &thost)))
5085 goto Bad_GetStatistics;
5087 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5089 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5091 memset(Statistics, 0, sizeof(*Statistics));
5092 SetAFSStats((struct AFSStatistics *)Statistics);
5093 SetVolumeStats((struct AFSStatistics *)Statistics);
5094 SetSystemStats((struct AFSStatistics *)Statistics);
5097 code = CallPostamble(tcon, code, thost);
5099 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5101 fsstats_FinishOp(&fsstats, code);
5103 osi_auditU(acall, GetStatisticsEvent, code,
5104 AUD_ID, t_client ? t_client->z.ViceId : 0, AUD_END);
5106 } /*SRXAFS_GetStatistics */
5110 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5112 extern afs_int32 StartTime, CurrentConnections;
5115 struct rx_connection *tcon = rx_ConnectionOf(acall);
5117 struct client *t_client = NULL; /* tmp ptr to client data */
5118 struct fsstats fsstats;
5120 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETSTATISTICS);
5122 if ((code = CallPreamble(acall, NOTACTIVECALL, NULL, &tcon, &thost)))
5123 goto Bad_GetStatistics64;
5125 if (statsVersion != STATS64_VERSION) {
5127 goto Bad_GetStatistics64;
5130 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5131 Statistics->ViceStatistics64_val =
5132 malloc(statsVersion*sizeof(afs_uint64));
5133 Statistics->ViceStatistics64_len = statsVersion;
5135 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5136 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5137 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5139 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5140 AFSCallStats.TotalCalls;
5141 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5142 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5143 AFSCallStats.FetchStatus;
5144 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5145 AFSCallStats.FetchData;
5146 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5147 AFSCallStats.TotalFetchedBytes;
5148 seconds = AFSCallStats.AccumFetchTime / 1000;
5151 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5152 AFSCallStats.TotalFetchedBytes / seconds;
5153 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5154 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5155 AFSCallStats.StoreStatus;
5156 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5157 AFSCallStats.StoreData;
5158 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5159 AFSCallStats.TotalStoredBytes;
5160 seconds = AFSCallStats.AccumStoreTime / 1000;
5163 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5164 AFSCallStats.TotalStoredBytes / seconds;
5165 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = opr_procsize();
5167 h_GetWorkStats64(&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5168 &(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5170 (afs_int32) (time(NULL)) - (15 * 60));
5172 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time(NULL);
5174 Bad_GetStatistics64:
5175 code = CallPostamble(tcon, code, thost);
5177 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5179 fsstats_FinishOp(&fsstats, code);
5181 osi_auditU(acall, GetStatisticsEvent, code,
5182 AUD_ID, t_client ? t_client->z.ViceId : 0, AUD_END);
5184 } /*SRXAFS_GetStatistics */
5187 /*------------------------------------------------------------------------
5188 * EXPORTED SRXAFS_XStatsVersion
5191 * Routine called by the server-side RPC interface to implement
5192 * pulling out the xstat version number for the File Server.
5195 * a_versionP : Ptr to the version number variable to set.
5201 * Nothing interesting.
5205 *------------------------------------------------------------------------*/
5208 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5209 { /*SRXAFS_XStatsVersion */
5211 struct client *t_client = NULL; /* tmp ptr to client data */
5212 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5213 struct fsstats fsstats;
5215 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_XSTATSVERSION);
5217 *a_versionP = AFS_XSTAT_VERSION;
5219 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5221 fsstats_FinishOp(&fsstats, 0);
5223 osi_auditU(a_call, XStatsVersionEvent, 0,
5224 AUD_ID, t_client ? t_client->z.ViceId : 0, AUD_END);
5226 } /*SRXAFS_XStatsVersion */
5229 /*------------------------------------------------------------------------
5230 * PRIVATE FillPerfValues
5233 * Routine called to fill a regular performance data structure.
5236 * a_perfP : Ptr to perf structure to fill
5242 * Various collections need this info, so the guts were put in
5243 * this separate routine.
5247 *------------------------------------------------------------------------*/
5250 FillPerfValues(struct afs_PerfStats *a_perfP)
5251 { /*FillPerfValues */
5252 int dir_Buffers; /*# buffers in use by dir package */
5253 int dir_Calls; /*# read calls in dir package */
5254 int dir_IOs; /*# I/O ops in dir package */
5255 struct rx_statistics *stats;
5258 * Vnode cache section.
5260 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5261 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5262 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5263 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5264 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5265 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5266 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5267 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5268 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5269 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5270 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5271 a_perfP->vcache_H_Gets = (int)VStats.hdr_gets;
5272 a_perfP->vcache_H_Replacements = (int)VStats.hdr_loads;
5275 * Directory section.
5277 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5278 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5279 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5280 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5285 stats = rx_GetStatistics();
5287 a_perfP->rx_packetRequests = (afs_int32) stats->packetRequests;
5288 a_perfP->rx_noPackets_RcvClass =
5289 (afs_int32) stats->receivePktAllocFailures;
5290 a_perfP->rx_noPackets_SendClass =
5291 (afs_int32) stats->sendPktAllocFailures;
5292 a_perfP->rx_noPackets_SpecialClass =
5293 (afs_int32) stats->specialPktAllocFailures;
5294 a_perfP->rx_socketGreedy = (afs_int32) stats->socketGreedy;
5295 a_perfP->rx_bogusPacketOnRead = (afs_int32) stats->bogusPacketOnRead;
5296 a_perfP->rx_bogusHost = (afs_int32) stats->bogusHost;
5297 a_perfP->rx_noPacketOnRead = (afs_int32) stats->noPacketOnRead;
5298 a_perfP->rx_noPacketBuffersOnRead =
5299 (afs_int32) stats->noPacketBuffersOnRead;
5300 a_perfP->rx_selects = (afs_int32) stats->selects;
5301 a_perfP->rx_sendSelects = (afs_int32) stats->sendSelects;
5302 a_perfP->rx_packetsRead_RcvClass =
5303 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_RECEIVE];
5304 a_perfP->rx_packetsRead_SendClass =
5305 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SEND];
5306 a_perfP->rx_packetsRead_SpecialClass =
5307 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SPECIAL];
5308 a_perfP->rx_dataPacketsRead = (afs_int32) stats->dataPacketsRead;
5309 a_perfP->rx_ackPacketsRead = (afs_int32) stats->ackPacketsRead;
5310 a_perfP->rx_dupPacketsRead = (afs_int32) stats->dupPacketsRead;
5311 a_perfP->rx_spuriousPacketsRead =
5312 (afs_int32) stats->spuriousPacketsRead;
5313 a_perfP->rx_packetsSent_RcvClass =
5314 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_RECEIVE];
5315 a_perfP->rx_packetsSent_SendClass =
5316 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SEND];
5317 a_perfP->rx_packetsSent_SpecialClass =
5318 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SPECIAL];
5319 a_perfP->rx_ackPacketsSent = (afs_int32) stats->ackPacketsSent;
5320 a_perfP->rx_pingPacketsSent = (afs_int32) stats->pingPacketsSent;
5321 a_perfP->rx_abortPacketsSent = (afs_int32) stats->abortPacketsSent;
5322 a_perfP->rx_busyPacketsSent = (afs_int32) stats->busyPacketsSent;
5323 a_perfP->rx_dataPacketsSent = (afs_int32) stats->dataPacketsSent;
5324 a_perfP->rx_dataPacketsReSent = (afs_int32) stats->dataPacketsReSent;
5325 a_perfP->rx_dataPacketsPushed = (afs_int32) stats->dataPacketsPushed;
5326 a_perfP->rx_ignoreAckedPacket = (afs_int32) stats->ignoreAckedPacket;
5327 a_perfP->rx_totalRtt_Sec = (afs_int32) stats->totalRtt.sec;
5328 a_perfP->rx_totalRtt_Usec = (afs_int32) stats->totalRtt.usec;
5329 a_perfP->rx_minRtt_Sec = (afs_int32) stats->minRtt.sec;
5330 a_perfP->rx_minRtt_Usec = (afs_int32) stats->minRtt.usec;
5331 a_perfP->rx_maxRtt_Sec = (afs_int32) stats->maxRtt.sec;
5332 a_perfP->rx_maxRtt_Usec = (afs_int32) stats->maxRtt.usec;
5333 a_perfP->rx_nRttSamples = (afs_int32) stats->nRttSamples;
5334 a_perfP->rx_nServerConns = (afs_int32) stats->nServerConns;
5335 a_perfP->rx_nClientConns = (afs_int32) stats->nClientConns;
5336 a_perfP->rx_nPeerStructs = (afs_int32) stats->nPeerStructs;
5337 a_perfP->rx_nCallStructs = (afs_int32) stats->nCallStructs;
5338 a_perfP->rx_nFreeCallStructs = (afs_int32) stats->nFreeCallStructs;
5340 a_perfP->host_NumHostEntries = HTs;
5341 a_perfP->host_HostBlocks = HTBlocks;
5342 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5343 &(a_perfP->host_HostsInSameNetOrSubnet),
5344 &(a_perfP->host_HostsInDiffSubnet),
5345 &(a_perfP->host_HostsInDiffNetwork));
5346 a_perfP->host_NumClients = CEs;
5347 a_perfP->host_ClientBlocks = CEBlocks;
5349 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5350 a_perfP->rx_nBusies = (afs_int32) stats->nBusies;
5351 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5352 rx_FreeStatistics(&stats);
5353 } /*FillPerfValues */
5356 /*------------------------------------------------------------------------
5357 * EXPORTED SRXAFS_GetXStats
5360 * Routine called by the server-side callback RPC interface to
5361 * implement getting the given data collection from the extended
5362 * File Server statistics.
5365 * a_call : Ptr to Rx call on which this request came in.
5366 * a_clientVersionNum : Client version number.
5367 * a_opCode : Desired operation.
5368 * a_serverVersionNumP : Ptr to version number to set.
5369 * a_timeP : Ptr to time value (seconds) to set.
5370 * a_dataP : Ptr to variable array structure to return
5377 * Nothing interesting.
5381 *------------------------------------------------------------------------*/
5384 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5385 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5386 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5387 { /*SRXAFS_GetXStats */
5389 struct client *t_client = NULL; /* tmp ptr to client data */
5390 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5391 int code; /*Return value */
5392 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5393 afs_int32 dataBytes; /*Bytes in data buffer */
5394 struct fsstats fsstats;
5397 * Note: This function intentionally omits CallPreamble()
5398 * to avoid issuing TellMeAboutYourself() calls to
5399 * simple clients which are only gathering stats.
5402 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETXSTATS);
5404 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5406 /* Return the server's time of day and xstat version number. */
5407 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5408 *a_timeP = (afs_int32) time(NULL);
5411 osi_auditU(a_call, GetXStatsEvent,
5412 AUD_ID, t_client ? t_client->z.ViceId : 0,
5413 AUD_INT, a_clientVersionNum,
5414 AUD_INT, a_collectionNumber, AUD_END);
5416 switch (a_collectionNumber) {
5417 case AFS_XSTATSCOLL_CALL_INFO:
5418 /* The call info collection type is not implemented. */
5419 a_dataP->AFS_CollData_len = 0;
5420 a_dataP->AFS_CollData_val = NULL;
5423 case AFS_XSTATSCOLL_PERF_INFO:
5425 * Pass back all the regular performance-related data.
5427 * Allocate a separate area in which to put this stuff in
5428 * by the RPC stub generator, since it will be freed at the
5429 * tail end of the server stub code.
5431 afs_perfstats.numPerfCalls++;
5432 FillPerfValues(&afs_perfstats);
5433 dataBytes = sizeof(struct afs_PerfStats);
5434 dataBuffP = calloc(1, dataBytes);
5435 memcpy(dataBuffP, &afs_perfstats, dataBytes);
5436 a_dataP->AFS_CollData_len = dataBytes / sizeof(afs_int32);
5437 a_dataP->AFS_CollData_val = dataBuffP;
5440 case AFS_XSTATSCOLL_FULL_PERF_INFO:
5442 * Pass back the full collection of performance-related data.
5443 * We have to stuff the basic, overall numbers in, but the
5444 * detailed numbers are kept in the structure already.
5446 * Allocate a separate area in which to put this stuff in
5447 * by the RPC stub generator, since it will be freed at the
5448 * tail end of the server stub code.
5450 afs_perfstats.numPerfCalls++;
5451 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
5452 FillPerfValues(&afs_FullPerfStats.overall);
5453 dataBytes = sizeof(struct fs_stats_FullPerfStats);
5454 dataBuffP = calloc(1, dataBytes);
5455 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
5456 a_dataP->AFS_CollData_len = dataBytes / sizeof(afs_int32);
5457 a_dataP->AFS_CollData_val = dataBuffP;
5460 case AFS_XSTATSCOLL_CBSTATS:
5461 afs_perfstats.numPerfCalls++;
5463 dataBytes = sizeof(struct cbcounters);
5464 dataBuffP = calloc(1, dataBytes);
5466 extern struct cbcounters cbstuff;
5467 dataBuffP[0]=cbstuff.DeleteFiles;
5468 dataBuffP[1]=cbstuff.DeleteCallBacks;
5469 dataBuffP[2]=cbstuff.BreakCallBacks;
5470 dataBuffP[3]=cbstuff.AddCallBacks;
5471 dataBuffP[4]=cbstuff.GotSomeSpaces;
5472 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
5473 dataBuffP[6]=cbstuff.nFEs;
5474 dataBuffP[7]=cbstuff.nCBs;
5475 dataBuffP[8]=cbstuff.nblks;
5476 dataBuffP[9]=cbstuff.CBsTimedOut;
5477 dataBuffP[10]=cbstuff.nbreakers;
5478 dataBuffP[11]=cbstuff.GSS1;
5479 dataBuffP[12]=cbstuff.GSS2;
5480 dataBuffP[13]=cbstuff.GSS3;
5481 dataBuffP[14]=cbstuff.GSS4;
5482 dataBuffP[15]=cbstuff.GSS5;
5485 a_dataP->AFS_CollData_len = dataBytes / sizeof(afs_int32);
5486 a_dataP->AFS_CollData_val = dataBuffP;
5490 /* Illegal collection number. */
5491 a_dataP->AFS_CollData_len = 0;
5492 a_dataP->AFS_CollData_val = NULL;
5494 } /*Switch on collection number */
5496 fsstats_FinishOp(&fsstats, code);
5500 } /*SRXAFS_GetXStats */
5504 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
5505 struct AFSCBs *CallBackArray)
5507 afs_int32 errorCode = 0;
5509 struct client *client = 0;
5510 struct rx_connection *tcon;
5512 struct fsstats fsstats;
5514 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GIVEUPCALLBACKS);
5518 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
5519 FidArray->AFSCBFids_len));
5522 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
5524 if ((errorCode = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &thost)))
5525 goto Bad_GiveUpCallBacks;
5527 if (!FidArray && !CallBackArray) {
5529 ("SAFS_GiveUpAllCallBacks: host=%x\n",
5530 (rx_PeerOf(tcon) ? rx_HostOf(rx_PeerOf(tcon)) : 0)));
5531 errorCode = GetClient(tcon, &client);
5534 DeleteAllCallBacks_r(client->z.host, 1);
5539 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
5541 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
5542 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
5543 (rx_PeerOf(tcon) ? rx_HostOf(rx_PeerOf(tcon)) : 0)));
5545 goto Bad_GiveUpCallBacks;
5548 errorCode = GetClient(tcon, &client);
5550 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
5551 struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
5552 DeleteCallBack(client->z.host, fid);
5558 Bad_GiveUpCallBacks:
5559 errorCode = CallPostamble(tcon, errorCode, thost);
5561 fsstats_FinishOp(&fsstats, errorCode);
5565 } /*common_GiveUpCallBacks */
5569 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
5570 struct AFSCBs * CallBackArray)
5572 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
5573 } /*SRXAFS_GiveUpCallBacks */
5576 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
5578 return common_GiveUpCallBacks(acall, 0, 0);
5579 } /*SRXAFS_GiveUpAllCallBacks */
5583 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
5584 struct AFSVolumeInfo * avolinfo)
5586 return (VNOVOL); /* XXX Obsolete routine XXX */
5588 } /*SRXAFS_NGetVolumeInfo */
5592 * Dummy routine. Should never be called (the cache manager should only
5593 * invoke this interface when communicating with a AFS/DFS Protocol
5597 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
5598 char *afs_name_p, struct AFSFid * afs_fid_p,
5599 struct AFSFetchStatus * afs_status_p,
5600 struct AFSFetchStatus * afs_dir_status_p,
5601 struct AFSCallBack * afs_callback_p,
5602 struct AFSVolSync * afs_sync_p)
5609 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
5612 struct rx_connection *tcon;
5614 afs_uint32 *dataBuffP;
5615 afs_int32 dataBytes;
5618 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
5619 afs_FullPerfStats.overall.fs_nGetCaps++;
5621 ViceLog(2, ("SAFS_GetCapabilties\n"));
5623 if ((code = CallPreamble(acall, NOTACTIVECALL, NULL, &tcon, &thost)))
5626 dataBytes = 1 * sizeof(afs_int32);
5627 dataBuffP = malloc(dataBytes);
5628 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
5629 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
5631 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
5633 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
5634 capabilities->Capabilities_val = dataBuffP;
5637 code = CallPostamble(tcon, code, thost);
5643 /* client is held, but not locked */
5645 FlushClientCPS(struct client *client, void *arock)
5647 ObtainWriteLock(&client->lock);
5649 client->z.prfail = 2; /* Means re-eval client's cps */
5651 if ((client->z.ViceId != ANONYMOUSID) && client->z.CPS.prlist_val) {
5652 free(client->z.CPS.prlist_val);
5653 client->z.CPS.prlist_val = NULL;
5654 client->z.CPS.prlist_len = 0;
5657 ReleaseWriteLock(&client->lock);
5663 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
5664 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
5668 afs_int32 nids, naddrs;
5669 afs_int32 *vd, *addr;
5670 Error errorCode = 0; /* return code to caller */
5672 ViceLog(1, ("SRXAFS_FlushCPS\n"));
5674 AFSCallStats.TotalCalls++;
5677 if (!viced_SuperUser(acall)) {
5682 nids = vids->ViceIds_len; /* # of users in here */
5683 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
5684 if (nids < 0 || naddrs < 0) {
5689 vd = vids->ViceIds_val;
5690 for (i = 0; i < nids; i++, vd++) {
5693 h_EnumerateClients(*vd, FlushClientCPS, NULL);
5696 addr = addrs->IPAddrs_val;
5697 for (i = 0; i < naddrs; i++, addr++) {
5699 h_flushhostcps(*addr, htons(7001));
5703 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
5705 } /*SRXAFS_FlushCPS */
5707 /* worthless hack to let CS keep running ancient software */
5709 afs_vtoi(char *aname)
5715 while ((tc = *aname++)) {
5716 if (tc > '9' || tc < '0')
5717 return 0; /* invalid name */
5725 * may get name or #, but must handle all weird cases (recognize readonly
5726 * or backup volumes by name or #
5729 CopyVolumeEntry(char *aname, struct vldbentry *ave,
5730 struct VolumeInfo *av)
5733 afs_int32 mask, whichType;
5734 afs_uint32 *serverHost, *typePtr;
5736 /* figure out what type we want if by name */
5738 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
5739 whichType = BACKVOL;
5740 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
5745 vol = afs_vtoi(aname);
5747 vol = ave->volumeId[whichType];
5750 * Now vol has volume # we're interested in. Next, figure out the type
5751 * of the volume by looking finding it in the vldb entry
5753 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
5756 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
5759 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
5760 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
5761 whichType = BACKVOL;
5763 return EINVAL; /* error: can't find volume in vldb entry */
5765 typePtr = &av->Type0;
5766 serverHost = &av->Server0;
5768 av->Type = whichType;
5769 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
5770 if (ave->flags & VLF_RWEXISTS)
5771 typePtr[RWVOL] = ave->volumeId[RWVOL];
5772 if (ave->flags & VLF_ROEXISTS)
5773 typePtr[ROVOL] = ave->volumeId[ROVOL];
5774 if (ave->flags & VLF_BACKEXISTS)
5775 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
5777 for (i = 0, j = 0; i < ave->nServers; i++) {
5778 if ((ave->serverFlags[i] & mask) == 0)
5779 continue; /* wrong volume */
5780 serverHost[j] = ave->serverNumber[i];
5783 av->ServerCount = j;
5785 serverHost[j++] = 0; /* bogus 8, but compat only now */
5790 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
5792 static struct rx_connection *vlConn = 0;
5793 static int down = 0;
5794 static afs_int32 lastDownTime = 0;
5795 struct vldbentry tve;
5796 struct rx_securityClass *vlSec;
5800 vlSec = rxnull_NewClientSecurityObject();
5802 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
5803 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
5805 if (down && (time(NULL) < lastDownTime + 180)) {
5806 return 1; /* failure */
5809 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
5811 down = 0; /* call worked */
5814 lastDownTime = time(NULL); /* last time we tried an RPC */
5820 /* otherwise convert to old format vldb entry */
5821 code = CopyVolumeEntry(avolid, &tve, avolinfo);
5831 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
5832 struct VolumeInfo * avolinfo)
5835 struct rx_connection *tcon;
5837 struct fsstats fsstats;
5839 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETVOLUMEINFO);
5841 if ((code = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &thost)))
5842 goto Bad_GetVolumeInfo;
5845 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
5847 code = TryLocalVLServer(avolid, avolinfo);
5849 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
5850 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
5851 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
5852 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
5855 code = CallPostamble(tcon, code, thost);
5857 fsstats_FinishOp(&fsstats, code);
5861 } /*SRXAFS_GetVolumeInfo */
5865 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
5866 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
5867 char **OfflineMsg, char **Motd)
5869 Vnode *targetptr = 0; /* vnode of the new file */
5870 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
5871 Error errorCode = 0; /* error code */
5872 Volume *volptr = 0; /* pointer to the volume header */
5873 struct client *client = 0; /* pointer to client entry */
5874 afs_int32 rights, anyrights; /* rights for this and any user */
5876 struct rx_connection *tcon;
5878 struct client *t_client = NULL; /* tmp ptr to client data */
5879 struct fsstats fsstats;
5881 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETVOLUMESTATUS);
5883 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
5884 if ((errorCode = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &thost)))
5885 goto Bad_GetVolumeStatus;
5888 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
5892 goto Bad_GetVolumeStatus;
5894 dummyFid.Volume = avolid, dummyFid.Vnode =
5895 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
5898 GetVolumePackage(acall, &dummyFid, &volptr, &targetptr, MustBeDIR,
5899 &parentwhentargetnotdir, &client, READ_LOCK,
5900 &rights, &anyrights)))
5901 goto Bad_GetVolumeStatus;
5903 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
5905 Bad_GetVolumeStatus:
5906 (void)PutVolumePackage(acall, parentwhentargetnotdir, targetptr,
5907 (Vnode *) 0, volptr, &client);
5908 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
5909 /* next is to guarantee out strings exist for stub */
5918 if (*OfflineMsg == 0) {
5919 *OfflineMsg = malloc(1);
5922 errorCode = CallPostamble(tcon, errorCode, thost);
5924 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5926 fsstats_FinishOp(&fsstats, errorCode);
5928 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
5929 AUD_ID, t_client ? t_client->z.ViceId : 0,
5930 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
5933 } /*SRXAFS_GetVolumeStatus */
5937 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
5938 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
5939 char *OfflineMsg, char *Motd)
5941 Vnode *targetptr = 0; /* vnode of the new file */
5942 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
5943 Error errorCode = 0; /* error code */
5944 Volume *volptr = 0; /* pointer to the volume header */
5945 struct client *client = 0; /* pointer to client entry */
5946 afs_int32 rights, anyrights; /* rights for this and any user */
5948 struct rx_connection *tcon = rx_ConnectionOf(acall);
5950 struct client *t_client = NULL; /* tmp ptr to client data */
5951 struct fsstats fsstats;
5953 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_SETVOLUMESTATUS);
5955 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
5956 if ((errorCode = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &thost)))
5957 goto Bad_SetVolumeStatus;
5960 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
5964 goto Bad_SetVolumeStatus;
5966 dummyFid.Volume = avolid, dummyFid.Vnode =
5967 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
5970 GetVolumePackage(acall, &dummyFid, &volptr, &targetptr, MustBeDIR,
5971 &parentwhentargetnotdir, &client, READ_LOCK,
5972 &rights, &anyrights)))
5973 goto Bad_SetVolumeStatus;
5975 if (!IsWriteAllowed(client)) {
5976 errorCode = VREADONLY;
5977 goto Bad_SetVolumeStatus;
5979 if (VanillaUser(client)) {
5981 goto Bad_SetVolumeStatus;
5985 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
5987 Bad_SetVolumeStatus:
5988 PutVolumePackage(acall, parentwhentargetnotdir, targetptr, (Vnode *) 0,
5990 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
5991 errorCode = CallPostamble(tcon, errorCode, thost);
5993 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5995 fsstats_FinishOp(&fsstats, errorCode);
5997 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
5998 AUD_ID, t_client ? t_client->z.ViceId : 0,
5999 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6001 } /*SRXAFS_SetVolumeStatus */
6003 #define DEFAULTVOLUME "root.afs"
6006 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6008 struct fsstats fsstats;
6010 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETROOTVOLUME);
6012 return FSERR_EOPNOTSUPP;
6015 if (errorCode = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &thost))
6016 goto Bad_GetRootVolume;
6018 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6021 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6023 strcpy(temp, DEFAULTVOLUME);
6025 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6026 lockf(fd, F_LOCK, 0);
6030 len = read(fd, temp, 256);
6031 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6032 lockf(fd, F_ULOCK, 0);
6037 if (temp[len - 1] == '\n')
6041 *VolumeName = temp; /* freed by rx server-side stub */
6044 errorCode = CallPostamble(tcon, errorCode, thost);
6046 fsstats_FinishOp(&fsstats, errorCode);
6051 } /*SRXAFS_GetRootVolume */
6055 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6056 struct AFSOpaque * Token)
6059 struct rx_connection *tcon;
6061 struct fsstats fsstats;
6063 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_CHECKTOKEN);
6065 if ((code = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &thost)))
6066 goto Bad_CheckToken;
6068 code = FSERR_ECONNREFUSED;
6071 code = CallPostamble(tcon, code, thost);
6073 fsstats_FinishOp(&fsstats, code);
6077 } /*SRXAFS_CheckToken */
6080 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6081 afs_uint32 * USeconds)
6084 struct rx_connection *tcon;
6087 struct fsstats fsstats;
6089 fsstats_StartOp(&fsstats, FS_STATS_RPCIDX_GETTIME);
6091 if ((code = CallPreamble(acall, NOTACTIVECALL, NULL, &tcon, &thost)))
6095 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6097 gettimeofday(&tpl, 0);
6098 *Seconds = tpl.tv_sec;
6099 *USeconds = tpl.tv_usec;
6101 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6104 code = CallPostamble(tcon, code, thost);
6106 fsstats_FinishOp(&fsstats, code);
6110 } /*SRXAFS_GetTime */
6117 * Implement a client's data fetch using Rx.
6120 * volptr : Ptr to the given volume's info.
6121 * targetptr : Pointer to the vnode involved.
6122 * Call : Ptr to the Rx call involved.
6123 * Pos : Offset within the file.
6124 * Len : Length in bytes to read; this value is bogus!
6125 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6127 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6132 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
6133 struct rx_call * Call, afs_sfsize_t Pos,
6134 afs_sfsize_t Len, afs_int32 Int64Mode,
6135 afs_sfsize_t * a_bytesToFetchP,
6136 afs_sfsize_t * a_bytesFetchedP)
6138 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6143 #else /* HAVE_PIOV */
6144 struct iovec tiov[RX_MAXIOVECS];
6146 #endif /* HAVE_PIOV */
6151 * Initialize the byte count arguments.
6153 (*a_bytesToFetchP) = 0;
6154 (*a_bytesFetchedP) = 0;
6157 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
6158 (afs_uintmax_t) Len));
6160 if (!VN_GET_INO(targetptr)) {
6161 afs_int32 zero = htonl(0);
6163 * This is used for newly created files; we simply send 0 bytes
6164 * back to make the cache manager happy...
6167 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6168 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6171 gettimeofday(&StartTime, 0);
6172 ihP = targetptr->handle;
6175 VTakeOffline(volptr);
6176 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
6177 afs_printable_VolumeId_lu(volptr->hashid)));
6180 optSize = sendBufSize;
6181 tlen = FDH_SIZE(fdP);
6183 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
6186 VTakeOffline(volptr);
6187 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
6188 afs_printable_VolumeId_lu(volptr->hashid)));
6191 if (CheckLength(volptr, targetptr, tlen)) {
6193 VTakeOffline(volptr);
6200 if (Pos + Len > tlen) /* get length we should send */
6201 Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
6204 afs_int32 high, low;
6205 SplitOffsetOrSize(Len, high, low);
6206 opr_Assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
6209 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
6212 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
6214 (*a_bytesToFetchP) = Len;
6216 tbuffer = AllocSendBuffer();
6217 #endif /* HAVE_PIOV */
6226 nBytes = FDH_PREAD(fdP, tbuffer, wlen, Pos);
6227 if (nBytes != wlen) {
6229 FreeSendBuffer((struct afs_buffer *)tbuffer);
6230 VTakeOffline(volptr);
6231 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
6232 afs_printable_VolumeId_lu(volptr->hashid)));
6235 nBytes = rx_Write(Call, tbuffer, wlen);
6236 #else /* HAVE_PIOV */
6237 nBytes = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
6243 nBytes = FDH_PREADV(fdP, tiov, tnio, Pos);
6244 if (nBytes != wlen) {
6246 VTakeOffline(volptr);
6247 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
6248 afs_printable_VolumeId_lu(volptr->hashid)));
6251 nBytes = rx_Writev(Call, tiov, tnio, wlen);
6252 #endif /* HAVE_PIOV */
6255 * Bump the number of bytes actually sent by the number from this
6258 (*a_bytesFetchedP) += nBytes;
6259 if (nBytes != wlen) {
6263 FreeSendBuffer((struct afs_buffer *)tbuffer);
6264 #endif /* HAVE_PIOV */
6265 err = VIsGoingOffline(volptr);
6274 FreeSendBuffer((struct afs_buffer *)tbuffer);
6275 #endif /* HAVE_PIOV */
6277 gettimeofday(&StopTime, 0);
6279 /* Adjust all Fetch Data related stats */
6281 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
6282 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
6283 AFSCallStats.AccumFetchTime +=
6284 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
6285 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
6287 afs_fsize_t targLen;
6288 VN_GET_LEN(targLen, targetptr);
6289 AFSCallStats.TotalFetchedBytes += targLen;
6290 AFSCallStats.FetchSize1++;
6291 if (targLen < SIZE2)
6292 AFSCallStats.FetchSize2++;
6293 else if (targLen < SIZE3)
6294 AFSCallStats.FetchSize3++;
6295 else if (targLen < SIZE4)
6296 AFSCallStats.FetchSize4++;
6298 AFSCallStats.FetchSize5++;
6303 } /*FetchData_RXStyle */
6306 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
6307 afs_sfsize_t * size)
6309 #ifdef AFS_NAMEI_ENV
6311 lhp = IH_OPEN(V_linkHandle(vp));
6314 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0, 0, 1);
6318 *size = OS_SIZE(fdP->fd_fd);
6319 return (*size == -1) ? -1 : 0;
6321 struct afs_stat status;
6323 if (afs_fstat(fdP->fd_fd, &status) < 0) {
6327 *lc = GetLinkCount(vp, &status);
6328 *size = status.st_size;
6337 * Implement a client's data store using Rx.
6340 * volptr : Ptr to the given volume's info.
6341 * targetptr : Pointer to the vnode involved.
6342 * Call : Ptr to the Rx call involved.
6343 * Pos : Offset within the file.
6344 * Len : Length in bytes to store; this value is bogus!
6345 * a_bytesToStoreP : Set to the number of bytes to be stored to
6347 * a_bytesStoredP : Set to the actual number of bytes stored to
6351 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
6352 struct client * client, struct rx_call * Call,
6353 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
6355 afs_sfsize_t * a_bytesToStoreP,
6356 afs_sfsize_t * a_bytesStoredP)
6358 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
6359 Error errorCode = 0; /* Returned error code to caller */
6361 char *tbuffer; /* data copying buffer */
6362 #else /* HAVE_PIOV */
6363 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
6364 int tnio; /* temp for iovec size */
6365 #endif /* HAVE_PIOV */
6366 afs_sfsize_t tlen; /* temp for xfr length */
6367 Inode tinode; /* inode for I/O */
6368 afs_int32 optSize; /* optimal transfer size */
6369 afs_sfsize_t DataLength = 0; /* size of inode */
6370 afs_sfsize_t TruncatedLength; /* size after ftruncate */
6371 afs_fsize_t NewLength; /* size after this store completes */
6372 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
6373 int linkCount = 0; /* link count on inode */
6376 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
6380 * Initialize the byte count arguments.
6382 (*a_bytesToStoreP) = 0;
6383 (*a_bytesStoredP) = 0;
6386 * We break the callbacks here so that the following signal will not
6389 BreakCallBack(client->z.host, Fid, 0);
6391 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
6392 /* the inode should have been created in Alloc_NewVnode */
6393 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
6395 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
6396 Fid->Volume, Fid->Vnode, Fid->Unique,
6397 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
6398 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
6399 return ENOENT; /* is this proper error code? */
6402 * See if the file has several links (from other volumes). If it
6403 * does, then we have to make a copy before changing it to avoid
6404 *changing read-only clones of this dude
6407 ("StoreData_RXStyle : Opening inode %s\n",
6408 PrintInode(stmp, VN_GET_INO(targetptr))));
6409 fdP = IH_OPEN(targetptr->handle);
6412 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
6414 VTakeOffline(volptr);
6415 ViceLog(0, ("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
6416 afs_printable_VolumeId_lu(volptr->hashid)));
6419 if (CheckLength(volptr, targetptr, DataLength)) {
6421 VTakeOffline(volptr);
6425 if (linkCount != 1) {
6428 ("StoreData_RXStyle : inode %s has more than onelink\n",
6429 PrintInode(stmp, VN_GET_INO(targetptr))));
6430 /* other volumes share this data, better copy it first */
6432 /* Adjust the disk block count by the creation of the new inode.
6433 * We call the special VDiskUsage so we don't adjust the volume's
6434 * quota since we don't want to penalyze the user for afs's internal
6435 * mechanisms (i.e. copy on write overhead.) Also the right size
6436 * of the disk will be recorded...
6439 VN_GET_LEN(size, targetptr);
6440 volptr->partition->flags &= ~PART_DONTUPDATE;
6441 VSetPartitionDiskUsage(volptr->partition);
6442 volptr->partition->flags |= PART_DONTUPDATE;
6443 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
6444 volptr->partition->flags &= ~PART_DONTUPDATE;
6448 ViceLog(25, ("StoreData : calling CopyOnWrite on target dir\n"));
6449 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, MAXFSIZE))) {
6450 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
6451 volptr->partition->flags &= ~PART_DONTUPDATE;
6454 volptr->partition->flags &= ~PART_DONTUPDATE;
6455 VSetPartitionDiskUsage(volptr->partition);
6456 fdP = IH_OPEN(targetptr->handle);
6459 ("StoreData : Reopen after CopyOnWrite failed\n"));
6463 tinode = VN_GET_INO(targetptr);
6465 if (!VALID_INO(tinode)) {
6466 VTakeOffline(volptr);
6467 ViceLog(0,("Volume %" AFS_VOLID_FMT " now offline, must be salvaged.\n",
6468 afs_printable_VolumeId_lu(volptr->hashid)));
6472 /* compute new file length */
6473 NewLength = DataLength;
6474 if (FileLength < NewLength)
6475 /* simulate truncate */
6476 NewLength = FileLength;
6477 TruncatedLength = NewLength; /* remember length after possible ftruncate */
6478 if (Pos + Length > NewLength)
6479 NewLength = Pos + Length; /* and write */
6481 /* adjust the disk block count by the difference in the files */
6483 afs_fsize_t targSize;
6484 VN_GET_LEN(targSize, targetptr);
6485 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
6488 AdjustDiskUsage(volptr, adjustSize,
6489 adjustSize - SpareComp(volptr)))) {
6494 /* can signal cache manager to proceed from close now */
6495 /* this bit means that the locks are set and protections are OK */
6496 rx_SetLocalStatus(Call, 1);
6498 optSize = sendBufSize;
6500 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
6501 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
6502 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
6504 bytesTransfered = 0;
6506 tbuffer = AllocSendBuffer();
6507 #endif /* HAVE_PIOV */
6508 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
6509 if (FileLength < DataLength) {
6510 errorCode = FDH_TRUNC(fdP, FileLength);
6515 /* if length == 0, the loop below isn't going to do anything, including
6516 * extend the length of the inode, which it must do, since the file system
6517 * assumes that the inode length == vnode's file length. So, we extend
6518 * the file length manually if need be. Note that if file is bigger than
6519 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
6520 * do what we're going to do below.
6522 if (Length == 0 && Pos > TruncatedLength) {
6523 /* Set the file's length; we've already done an lseek to the right
6526 tlen = 0; /* Just a source of data for the write */
6527 nBytes = FDH_PWRITE(fdP, &tlen, 1, Pos);
6532 errorCode = FDH_TRUNC(fdP, Pos);
6534 /* have some data to copy */
6535 (*a_bytesToStoreP) = Length;
6538 if (bytesTransfered >= Length) {
6542 tlen = Length - bytesTransfered; /* how much more to do */
6544 rlen = optSize; /* bound by buffer size */
6548 errorCode = rx_Read(Call, tbuffer, rlen);
6549 #else /* HAVE_PIOV */
6550 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
6551 #endif /* HAVE_PIOV */
6552 if (errorCode <= 0) {
6556 (*a_bytesStoredP) += errorCode;
6559 nBytes = FDH_PWRITE(fdP, tbuffer, rlen, Pos);
6560 #else /* HAVE_PIOV */
6561 nBytes = FDH_PWRITEV(fdP, tiov, tnio, Pos);
6562 #endif /* HAVE_PIOV */
6563 if (nBytes != rlen) {
6564 errorCode = VDISKFULL;
6567 bytesTransfered += rlen;
6573 FreeSendBuffer((struct afs_buffer *)tbuffer);
6574 #endif /* HAVE_PIOV */
6576 (void) FDH_SYNC(fdP);
6579 Error tmp_errorCode = 0;
6580 afs_sfsize_t nfSize = FDH_SIZE(fdP);
6581 opr_Assert(nfSize >= 0);
6582 /* something went wrong: adjust size and return */
6583 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
6584 /* changed_newTime is tested in StoreData to detemine if we
6585 * need to update the target vnode.
6587 targetptr->changed_newTime = 1;
6589 /* set disk usage to be correct */
6590 VAdjustDiskUsage(&tmp_errorCode, volptr,
6591 (afs_sfsize_t) (nBlocks(nfSize) -
6592 nBlocks(NewLength)), 0);
6593 if (tmp_errorCode) {
6594 errorCode = tmp_errorCode;
6600 VN_SET_LEN(targetptr, NewLength);
6602 /* Update all StoreData related stats */
6604 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
6605 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
6606 AFSCallStats.StoreSize1++; /* Piggybacked data */
6608 afs_fsize_t targLen;
6609 VN_GET_LEN(targLen, targetptr);
6610 if (targLen < SIZE2)
6611 AFSCallStats.StoreSize2++;
6612 else if (targLen < SIZE3)
6613 AFSCallStats.StoreSize3++;
6614 else if (targLen < SIZE4)
6615 AFSCallStats.StoreSize4++;
6617 AFSCallStats.StoreSize5++;
6622 } /*StoreData_RXStyle */
6624 static int sys2et[512];
6627 init_sys_error_to_et(void)
6629 memset(&sys2et, 0, sizeof(sys2et));
6630 sys2et[EPERM] = UAEPERM;
6631 sys2et[ENOENT] = UAENOENT;
6632 sys2et[ESRCH] = UAESRCH;
6633 sys2et[EINTR] = UAEINTR;
6634 sys2et[EIO] = UAEIO;
6635 sys2et[ENXIO] = UAENXIO;
6636 sys2et[E2BIG] = UAE2BIG;
6637 sys2et[ENOEXEC] = UAENOEXEC;
6638 sys2et[EBADF] = UAEBADF;
6639 sys2et[ECHILD] = UAECHILD;
6640 sys2et[EAGAIN] = UAEAGAIN;
6641 sys2et[ENOMEM] = UAENOMEM;
6642 sys2et[EACCES] = UAEACCES;
6643 sys2et[EFAULT] = UAEFAULT;
6644 sys2et[ENOTBLK] = UAENOTBLK;
6645 sys2et[EBUSY] = UAEBUSY;
6646 sys2et[EEXIST] = UAEEXIST;
6647 sys2et[EXDEV] = UAEXDEV;
6648 sys2et[ENODEV] = UAENODEV;
6649 sys2et[ENOTDIR] = UAENOTDIR;
6650 sys2et[EISDIR] = UAEISDIR;
6651 sys2et[EINVAL] = UAEINVAL;
6652 sys2et[ENFILE] = UAENFILE;
6653 sys2et[EMFILE] = UAEMFILE;
6654 sys2et[ENOTTY] = UAENOTTY;
6655 sys2et[ETXTBSY] = UAETXTBSY;
6656 sys2et[EFBIG] = UAEFBIG;
6657 sys2et[ENOSPC] = UAENOSPC;
6658 sys2et[ESPIPE] = UAESPIPE;
6659 sys2et[EROFS] = UAEROFS;
6660 sys2et[EMLINK] = UAEMLINK;
6661 sys2et[EPIPE] = UAEPIPE;
6662 sys2et[EDOM] = UAEDOM;
6663 sys2et[ERANGE] = UAERANGE;
6664 sys2et[EDEADLK] = UAEDEADLK;
6665 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
6666 sys2et[ENOLCK] = UAENOLCK;
6667 sys2et[ENOSYS] = UAENOSYS;
6668 #if (ENOTEMPTY != EEXIST)
6669 sys2et[ENOTEMPTY] = UAENOTEMPTY;
6671 sys2et[ELOOP] = UAELOOP;
6672 #if (EWOULDBLOCK != EAGAIN)
6673 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
6675 sys2et[ENOMSG] = UAENOMSG;
6676 sys2et[EIDRM] = UAEIDRM;
6677 sys2et[ECHRNG] = UAECHRNG;
6678 sys2et[EL2NSYNC] = UAEL2NSYNC;
6679 sys2et[EL3HLT] = UAEL3HLT;
6680 sys2et[EL3RST] = UAEL3RST;
6681 sys2et[ELNRNG] = UAELNRNG;
6682 sys2et[EUNATCH] = UAEUNATCH;
6683 sys2et[ENOCSI] = UAENOCSI;
6684 sys2et[EL2HLT] = UAEL2HLT;
6685 sys2et[EBADE] = UAEBADE;
6686 sys2et[EBADR] = UAEBADR;
6687 sys2et[EXFULL] = UAEXFULL;
6688 sys2et[ENOANO] = UAENOANO;
6689 sys2et[EBADRQC] = UAEBADRQC;
6690 sys2et[EBADSLT] = UAEBADSLT;
6691 sys2et[EDEADLK] = UAEDEADLK;
6692 sys2et[EBFONT] = UAEBFONT;
6693 sys2et[ENOSTR] = UAENOSTR;
6694 sys2et[ENODATA] = UAENODATA;
6695 sys2et[ETIME] = UAETIME;
6696 sys2et[ENOSR] = UAENOSR;
6697 sys2et[ENONET] = UAENONET;
6698 sys2et[ENOPKG] = UAENOPKG;
6699 sys2et[EREMOTE] = UAEREMOTE;
6700 sys2et[ENOLINK] = UAENOLINK;
6701 sys2et[EADV] = UAEADV;
6702 sys2et[ESRMNT] = UAESRMNT;
6703 sys2et[ECOMM] = UAECOMM;
6704 sys2et[EPROTO] = UAEPROTO;
6705 sys2et[EMULTIHOP] = UAEMULTIHOP;
6706 sys2et[EDOTDOT] = UAEDOTDOT;
6707 sys2et[EBADMSG] = UAEBADMSG;
6708 sys2et[EOVERFLOW] = UAEOVERFLOW;
6709 sys2et[ENOTUNIQ] = UAENOTUNIQ;
6710 sys2et[EBADFD] = UAEBADFD;
6711 sys2et[EREMCHG] = UAEREMCHG;
6712 sys2et[ELIBACC] = UAELIBACC;
6713 sys2et[ELIBBAD] = UAELIBBAD;
6714 sys2et[ELIBSCN] = UAELIBSCN;
6715 sys2et[ELIBMAX] = UAELIBMAX;
6716 sys2et[ELIBEXEC] = UAELIBEXEC;
6717 sys2et[EILSEQ] = UAEILSEQ;
6718 sys2et[ERESTART] = UAERESTART;
6719 sys2et[ESTRPIPE] = UAESTRPIPE;
6720 sys2et[EUSERS] = UAEUSERS;
6721 sys2et[ENOTSOCK] = UAENOTSOCK;
6722 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
6723 sys2et[EMSGSIZE] = UAEMSGSIZE;
6724 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
6725 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
6726 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
6727 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
6728 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
6729 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
6730 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
6731 sys2et[EADDRINUSE] = UAEADDRINUSE;
6732 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
6733 sys2et[ENETDOWN] = UAENETDOWN;
6734 sys2et[ENETUNREACH] = UAENETUNREACH;
6735 sys2et[ENETRESET] = UAENETRESET;
6736 sys2et[ECONNABORTED] = UAECONNABORTED;
6737 sys2et[ECONNRESET] = UAECONNRESET;
6738 sys2et[ENOBUFS] = UAENOBUFS;
6739 sys2et[EISCONN] = UAEISCONN;
6740 sys2et[ENOTCONN] = UAENOTCONN;
6741 sys2et[ESHUTDOWN] = UAESHUTDOWN;
6742 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
6743 sys2et[ETIMEDOUT] = UAETIMEDOUT;
6744 sys2et[ECONNREFUSED] = UAECONNREFUSED;
6745 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
6746 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
6747 sys2et[EALREADY] = UAEALREADY;
6748 sys2et[EINPROGRESS] = UAEINPROGRESS;
6749 sys2et[ESTALE] = UAESTALE;
6750 sys2et[EUCLEAN] = UAEUCLEAN;
6751 sys2et[ENOTNAM] = UAENOTNAM;
6752 sys2et[ENAVAIL] = UAENAVAIL;
6753 sys2et[EISNAM] = UAEISNAM;
6754 sys2et[EREMOTEIO] = UAEREMOTEIO;
6755 sys2et[EDQUOT] = UAEDQUOT;
6756 sys2et[ENOMEDIUM] = UAENOMEDIUM;
6757 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
6759 sys2et[EIO] = UAEIO;
6763 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
6764 * - pass back the connection, client, and host from CallPreamble
6765 * - keep a ref on the client, which we don't now
6766 * - keep a hold on the host, which we already do
6767 * - pass the connection, client, and host down into SAFSS_*, and use
6768 * them instead of independently discovering them via rx_ConnectionOf
6769 * (safe) and rx_GetSpecific (not so safe)
6770 * The idea being that we decide what client and host we're going to use
6771 * when CallPreamble is called, and stay consistent throughout the call.
6772 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
6776 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
6778 Error errorCode = 0;
6779 struct rx_connection *tcon;
6780 struct host *tcallhost;
6781 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
6783 struct client *tclient;
6784 static struct rx_securityClass *sc = 0;
6786 struct rx_connection *conn;
6787 afs_int32 viceid = -1;
6790 if ((errorCode = CallPreamble(acall, ACTIVECALL, NULL, &tcon, &tcallhost)))
6791 goto Bad_CallBackRxConnAddr1;
6793 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
6797 tclient = h_FindClient_r(tcon, &viceid);
6800 LogClientError("Client host too busy (CallBackRxConnAddr)", tcon, viceid, NULL);
6801 goto Bad_CallBackRxConnAddr;
6803 thost = tclient->z.host;
6805 /* nothing more can be done */
6806 if ( !thost->z.interface )
6807 goto Bad_CallBackRxConnAddr;
6809 /* the only address is the primary interface */
6810 /* can't change when there's only 1 address, anyway */
6811 if ( thost->z.interface->numberOfInterfaces <= 1 )
6812 goto Bad_CallBackRxConnAddr;
6814 /* initialise a security object only once */
6816 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
6818 for ( i=0; i < thost->z.interface->numberOfInterfaces; i++)
6820 if ( *addr == thost->z.interface->addr[i] ) {
6825 if ( *addr != thost->z.interface->addr[i] )
6826 goto Bad_CallBackRxConnAddr;
6828 conn = rx_NewConnection (thost->z.interface->addr[i],
6829 thost->z.port, 1, sc, 0);
6830 rx_SetConnDeadTime(conn, 2);
6831 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
6833 errorCode = RXAFSCB_Probe(conn);
6836 if ( thost->z.callback_rxcon )
6837 rx_DestroyConnection(thost->z.callback_rxcon);
6838 thost->z.callback_rxcon = conn;
6839 thost->z.host = addr;
6840 rx_SetConnDeadTime(thost->z.callback_rxcon, 50);
6841 rx_SetConnHardDeadTime(thost->z.callback_rxcon, AFS_HARDDEADTIME);
6842 h_ReleaseClient_r(tclient);
6843 /* The hold on thost will be released by CallPostamble */
6845 errorCode = CallPostamble(tcon, errorCode, tcallhost);
6848 rx_DestroyConnection(conn);
6850 Bad_CallBackRxConnAddr:
6851 h_ReleaseClient_r(tclient);
6852 /* The hold on thost will be released by CallPostamble */
6856 errorCode = CallPostamble(tcon, errorCode, tcallhost);
6857 Bad_CallBackRxConnAddr1:
6858 return errorCode; /* failure */
6862 sys_error_to_et(afs_int32 in)
6866 if (in < 0 || in > 511)
6868 if ((in >= VICE_SPECIAL_ERRORS && in <= VIO) || in == VRESTRICTED)
6870 if (sys2et[in] != 0)