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 * in Check_PermissionRights, certain privileges are afforded to the owner
24 * of the volume, or the owner of a file. Are these considered "use of
28 #include <afsconfig.h>
29 #include <afs/param.h>
38 #undef SHARED /* XXX */
43 #include <sys/param.h>
45 #include <sys/ioctl.h>
46 #include <sys/socket.h>
47 #include <netinet/in.h>
48 #include <arpa/inet.h>
52 #ifndef AFS_LINUX20_ENV
54 #include <netinet/if_ether.h>
58 /* included early because of name conflict on IOPEN */
59 #include <sys/inode.h>
63 #endif /* AFS_HPUX_ENV */
67 #include <afs/assert.h>
70 #include <afs/afsint.h>
71 #include <afs/vldbint.h>
72 #include <afs/errors.h>
73 #include <afs/ihandle.h>
74 #include <afs/vnode.h>
75 #include <afs/volume.h>
76 #include <afs/ptclient.h>
77 #include <afs/ptuser.h>
78 #include <afs/prs_fs.h>
81 #include <rx/rx_globals.h>
83 #if ! defined(AFS_SGI_ENV) && ! defined(AFS_AIX32_ENV) && ! defined(AFS_NT40_ENV) && ! defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
86 #if !defined(AFS_NT40_ENV)
89 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
91 #include <sys/statfs.h>
92 #include <sys/lockf.h>
94 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
99 #include <afs/cellconfig.h>
100 #include <afs/keys.h>
103 #include <afs/partition.h>
104 #include "viced_prototypes.h"
107 #include "callback.h"
108 #include <afs/unified_afs.h>
109 #include <afs/audit.h>
110 #include <afs/afsutil.h>
113 extern void SetDirHandle(register DirHandle * dir, register Vnode * vnode);
114 extern void FidZap(DirHandle * file);
115 extern void FidZero(DirHandle * file);
117 #ifdef AFS_PTHREAD_ENV
118 pthread_mutex_t fileproc_glock_mutex;
119 #endif /* AFS_PTHREAD_ENV */
122 #define afs_stat stat64
123 #define afs_fstat fstat64
124 #define afs_open open64
125 #else /* !O_LARGEFILE */
126 #define afs_stat stat
127 #define afs_fstat fstat
128 #define afs_open open
129 #endif /* !O_LARGEFILE */
132 /* Useful local defines used by this module */
135 #define MustNOTBeDIR 1
139 #define TVS_SSTATUS 2
142 #define TVS_MKDIR 0x10
144 #define CHK_FETCH 0x10
145 #define CHK_FETCHDATA 0x10
146 #define CHK_FETCHACL 0x11
147 #define CHK_FETCHSTATUS 0x12
148 #define CHK_STOREDATA 0x00
149 #define CHK_STOREACL 0x01
150 #define CHK_STORESTATUS 0x02
152 #define OWNERREAD 0400
153 #define OWNERWRITE 0200
154 #define OWNEREXEC 0100
155 #ifdef USE_GROUP_PERMS
156 #define GROUPREAD 0040
157 #define GROUPWRITE 0020
158 #define GROUPREXEC 0010
161 /* The following errors were not defined in NT. They are given unique
162 * names here to avoid any potential collision.
164 #define FSERR_ELOOP 90
165 #define FSERR_EOPNOTSUPP 122
166 #define FSERR_ECONNREFUSED 130
168 #define NOTACTIVECALL 0
171 #define CREATE_SGUID_ADMIN_ONLY 1
173 extern struct afsconf_dir *confDir;
174 extern afs_int32 dataVersionHigh;
177 static struct AFSCallStatistics AFSCallStats;
178 #if FS_STATS_DETAILED
179 struct fs_stats_FullPerfStats afs_FullPerfStats;
180 extern int AnonymousID;
181 #endif /* FS_STATS_DETAILED */
182 #if OPENAFS_VOL_STATS
183 static const char nullString[] = "";
184 #endif /* OPENAFS_VOL_STATS */
187 afs_int32 NothingYet;
190 struct afs_FSStats afs_fsstats;
192 void ResetDebug(), SetDebug(), Terminate();
197 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
199 extern afs_int32 implicitAdminRights;
200 extern afs_int32 readonlyServer;
203 * Externals used by the xstat code.
205 extern VolPkgStats VStats;
206 extern int CEs, CEBlocks;
208 extern int HTs, HTBlocks;
210 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
211 register struct rx_call *Call, afs_sfsize_t Pos,
212 afs_sfsize_t Len, afs_int32 Int64Mode,
213 #if FS_STATS_DETAILED
214 afs_sfsize_t * a_bytesToFetchP,
215 afs_sfsize_t * a_bytesFetchedP
216 #endif /* FS_STATS_DETAILED */
219 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
220 struct AFSFid *Fid, struct client *client,
221 register struct rx_call *Call, afs_fsize_t Pos,
222 afs_fsize_t Length, afs_fsize_t FileLength,
224 #if FS_STATS_DETAILED
225 afs_sfsize_t * a_bytesToStoreP,
226 afs_sfsize_t * a_bytesStoredP
227 #endif /* FS_STATS_DETAILED */
230 #ifdef AFS_SGI_XFS_IOPS_ENV
231 #include <afs/xfsattrs.h>
233 GetLinkCount(Volume * avp, struct stat *astat)
235 if (!strcmp("xfs", astat->st_fstype)) {
236 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
238 return astat->st_nlink;
241 #define GetLinkCount(V, S) (S)->st_nlink
245 SpareComp(Volume * avolp)
247 register afs_int32 temp;
251 temp = V_maxquota(avolp);
253 /* no matter; doesn't check in this case */
257 temp = (temp * PctSpare) / 100;
268 * Set the volume synchronization parameter for this volume. If it changes,
269 * the Cache Manager knows that the volume must be purged from the stat cache.
272 SetVolumeSync(register struct AFSVolSync *async, register Volume * avol)
275 /* date volume instance was created */
278 async->spare1 = avol->header->diskstuff.creationDate;
291 * Note that this function always returns a held host, so
292 * that CallPostamble can block without the host's disappearing.
293 * Call returns rx connection in passed in *tconn
296 CallPreamble(register struct rx_call *acall, int activecall,
297 struct rx_connection **tconn, struct host **ahostp)
300 struct client *tclient;
303 char hoststr[16], hoststr2[16];
304 struct ubik_client *uclient;
309 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
312 *tconn = rx_ConnectionOf(acall);
316 tclient = h_FindClient_r(*tconn);
318 ViceLog(0, ("CallPreamble: Couldn't get CPS. Too many lockers\n"));
322 thost = tclient->host;
323 if (tclient->prfail == 1) { /* couldn't get the CPS */
325 h_ReleaseClient_r(tclient);
327 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
331 retry_flag = 0; /* Retry once */
333 /* Take down the old connection and re-read the key file */
335 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
336 #ifdef AFS_PTHREAD_ENV
337 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
339 /* Is it still necessary to drop this? We hit the net, we should... */
343 code = hpr_Initialize(&uclient);
346 assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
349 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
352 h_ReleaseClient_r(tclient);
355 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
359 tclient->prfail = 2; /* Means re-eval client's cps */
360 h_ReleaseClient_r(tclient);
365 tclient->LastCall = thost->LastCall = FT_ApproxTime();
366 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
367 thost->ActiveCall = thost->LastCall;
370 if (thost->hostFlags & HOSTDELETED) {
372 ("Discarded a packet for deleted host %s:%d\n",
373 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
374 code = VBUSY; /* raced, so retry */
375 } else if ((thost->hostFlags & VENUSDOWN)
376 || (thost->hostFlags & HFE_LATER)) {
377 if (BreakDelayedCallBacks_r(thost)) {
379 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
380 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
381 ntohs(rxr_PortOf(*tconn))));
382 if (MultiProbeAlternateAddress_r(thost)) {
384 ("MultiProbe failed to find new address for host %s:%d\n",
385 afs_inet_ntoa_r(thost->host, hoststr),
386 ntohs(thost->port)));
390 ("MultiProbe found new address for host %s:%d\n",
391 afs_inet_ntoa_r(thost->host, hoststr),
392 ntohs(thost->port)));
393 if (BreakDelayedCallBacks_r(thost)) {
395 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
396 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
397 ntohs(rxr_PortOf(*tconn))));
406 h_ReleaseClient_r(tclient);
416 CallPostamble(register struct rx_connection *aconn, afs_int32 ret,
420 struct client *tclient;
425 tclient = h_FindClient_r(aconn);
428 thost = tclient->host;
429 if (thost->hostFlags & HERRORTRANS)
431 h_ReleaseClient_r(tclient);
432 held = h_Held_r(thost);
435 if (ahost && ahost != thost) {
436 char hoststr[16], hoststr2[16];
437 ViceLog(0, ("CallPostamble: ahost %s:%d (%x) != thost %s:%d (%x)\n",
438 afs_inet_ntoa_r(ahost->host, hoststr), ntohs(ahost->port),
440 afs_inet_ntoa_r(thost->host, hoststr2), ntohs(thost->port),
445 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%x)\n",
446 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port),
451 return (translate ? sys_error_to_et(ret) : ret);
455 * Returns the volume and vnode pointers associated with file Fid; the lock
456 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
457 * are incremented and they must be eventualy released.
460 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
463 afs_int32 local_errorCode, errorCode = -1;
464 static struct timeval restartedat = { 0, 0 };
466 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
468 if ((*volptr) == 0) {
473 #ifdef AFS_DEMAND_ATTACH_FS
481 *volptr = VGetVolume(&local_errorCode, &errorCode, (afs_int32) fid->Volume);
486 if ((errorCode == VOFFLINE) && (VInit < 2)) {
487 /* The volume we want may not be attached yet because
488 * the volume initialization is not yet complete.
489 * We can do several things:
490 * 1. return -1, which will cause users to see
491 * "connection timed out". This is more or
492 * less the same as always, except that the servers
493 * may appear to bounce up and down while they
494 * are actually restarting.
495 * 2. return VBUSY which will cause clients to
496 * sleep and retry for 6.5 - 15 minutes, depending
497 * on what version of the CM they are running. If
498 * the file server takes longer than that interval
499 * to attach the desired volume, then the application
500 * will see an ENODEV or EIO. This approach has
501 * the advantage that volumes which have been attached
502 * are immediately available, it keeps the server's
503 * immediate backlog low, and the call is interruptible
504 * by the user. Users see "waiting for busy volume."
505 * 3. sleep here and retry. Some people like this approach
506 * because there is no danger of seeing errors. However,
507 * this approach only works with a bounded number of
508 * clients, since the pending queues will grow without
509 * stopping. It might be better to find a way to take
510 * this call and stick it back on a queue in order to
511 * recycle this thread for a different request.
512 * 4. Return a new error code, which new cache managers will
513 * know enough to interpret as "sleep and retry", without
514 * the upper bound of 6-15 minutes that is imposed by the
515 * VBUSY handling. Users will see "waiting for
516 * busy volume," so they know that something is
517 * happening. Old cache managers must be able to do
518 * something reasonable with this, for instance, mark the
519 * server down. Fortunately, any error code < 0
520 * will elicit that behavior. See #1.
521 * 5. Some combination of the above. I like doing #2 for 10
522 * minutes, followed by #4. 3.1b and 3.2 cache managers
523 * will be fine as long as the restart period is
524 * not longer than 6.5 minutes, otherwise they may
525 * return ENODEV to users. 3.3 cache managers will be
526 * fine for 10 minutes, then will return
527 * ETIMEDOUT. 3.4 cache managers will just wait
528 * until the call works or fails definitively.
529 * NB. The problem with 2,3,4,5 is that old clients won't
530 * fail over to an alternate read-only replica while this
531 * server is restarting. 3.4 clients will fail over right away.
533 if (restartedat.tv_sec == 0) {
534 /* I'm not really worried about when we restarted, I'm */
535 /* just worried about when the first VBUSY was returned. */
536 TM_GetTimeOfDay(&restartedat, 0);
539 afs_perfstats.fs_nBusies++;
542 return (busyonrst ? VBUSY : restarting);
545 TM_GetTimeOfDay(&now, 0);
546 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
549 afs_perfstats.fs_nBusies++;
552 return (busyonrst ? VBUSY : restarting);
558 /* allow read operations on busy volume.
559 * must check local_errorCode because demand attach fs
560 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
561 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
562 #ifdef AFS_DEMAND_ATTACH_FS
563 /* DAFS case is complicated by the fact that local_errorCode can
564 * be VBUSY in cases where the volume is truly offline */
566 /* volume is in VOL_STATE_UNATTACHED */
569 #endif /* AFS_DEMAND_ATTACH_FS */
572 } else if (errorCode)
579 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
582 if ((*vptr)->disk.uniquifier != fid->Unique) {
583 VPutVnode(&fileCode, *vptr);
584 assert(fileCode == 0);
586 return (VNOVNODE); /* return the right error code, at least */
592 * This routine returns the ACL associated with the targetptr. If the
593 * targetptr isn't a directory, we access its parent dir and get the ACL
594 * thru the parent; in such case the parent's vnode is returned in
598 SetAccessList(Vnode ** targetptr, Volume ** volume,
599 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
600 AFSFid * Fid, int Lock)
602 if ((*targetptr)->disk.type == vDirectory) {
604 *ACL = VVnodeACL(*targetptr);
605 *ACLSize = VAclSize(*targetptr);
613 parentvnode = (*targetptr)->disk.parent;
614 VPutVnode(&errorCode, *targetptr);
618 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
621 *ACL = VVnodeACL(*parent);
622 *ACLSize = VAclSize(*parent);
623 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
625 if ((*targetptr)->disk.parent != parentvnode) {
626 VPutVnode(&errorCode, *parent);
637 /* Must not be called with H_LOCK held */
639 client_CheckRights(struct client *client, struct acl_accessList *ACL,
643 ObtainReadLock(&client->lock);
644 if (client->CPS.prlist_len > 0 && !client->deleted &&
645 client->host && !(client->host->hostFlags & HOSTDELETED))
646 acl_CheckRights(ACL, &client->CPS, rights);
647 ReleaseReadLock(&client->lock);
650 /* Must not be called with H_LOCK held */
652 client_HasAsMember(struct client *client, afs_int32 id)
656 ObtainReadLock(&client->lock);
657 if (client->CPS.prlist_len > 0 && !client->deleted &&
658 client->host && !(client->host->hostFlags & HOSTDELETED))
659 code = acl_IsAMember(id, &client->CPS);
660 ReleaseReadLock(&client->lock);
665 * Compare the directory's ACL with the user's access rights in the client
666 * connection and return the user's and everybody else's access permissions
667 * in rights and anyrights, respectively
670 GetRights(struct client *client, struct acl_accessList *ACL,
671 afs_int32 * rights, afs_int32 * anyrights)
673 extern prlist SystemAnyUserCPS;
674 afs_int32 hrights = 0;
675 #ifndef AFS_PTHREAD_ENV
679 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
680 ViceLog(0, ("CheckRights failed\n"));
685 client_CheckRights(client, ACL, rights);
687 /* wait if somebody else is already doing the getCPS call */
689 while (client->host->hostFlags & HCPS_INPROGRESS) {
690 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
691 #ifdef AFS_PTHREAD_ENV
692 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
693 #else /* AFS_PTHREAD_ENV */
695 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
696 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
697 #endif /* AFS_PTHREAD_ENV */
700 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
703 ("CheckRights: len=%u, for host=%s:%d\n",
704 client->host->hcps.prlist_len,
705 afs_inet_ntoa_r(client->host->host, hoststr),
706 ntohs(client->host->port)));
708 acl_CheckRights(ACL, &client->host->hcps, &hrights);
710 /* Allow system:admin the rights given with the -implicit option */
711 if (client_HasAsMember(client, SystemId))
712 *rights |= implicitAdminRights;
715 *anyrights |= hrights;
722 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
723 * a System:Administrator)
726 VanillaUser(struct client *client)
728 if (client_HasAsMember(client, SystemId))
729 return (0); /* not a system administrator, then you're "vanilla" */
736 * This unusual afs_int32-parameter routine encapsulates all volume package related
737 * operations together in a single function; it's called by almost all AFS
741 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
742 Vnode ** targetptr, int chkforDir, Vnode ** parent,
743 struct client **client, int locktype, afs_int32 * rights,
744 afs_int32 * anyrights)
746 struct acl_accessList *aCL; /* Internal access List */
747 int aCLSize; /* size of the access list */
748 int errorCode = 0; /* return code to caller */
750 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
753 if (chkforDir == MustNOTBeDIR
754 && ((*targetptr)->disk.type == vDirectory))
756 else if (chkforDir == MustBeDIR
757 && ((*targetptr)->disk.type != vDirectory))
761 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
762 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
763 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
765 if (chkforDir == MustBeDIR)
766 assert((*parent) == 0);
768 if ((errorCode = GetClient(tcon, client)) != 0)
773 GetRights(*client, aCL, rights, anyrights);
774 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
775 if ((*targetptr)->disk.type != vDirectory) {
776 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
777 if ((*targetptr)->disk.owner == (*client)->ViceId)
778 (*rights) |= PRSFS_ADMINISTER;
780 (*rights) &= ~PRSFS_ADMINISTER;
782 #ifdef ADMIN_IMPLICIT_LOOKUP
783 /* admins get automatic lookup on everything */
784 if (!VanillaUser(*client))
785 (*rights) |= PRSFS_LOOKUP;
786 #endif /* ADMIN_IMPLICIT_LOOKUP */
789 } /*GetVolumePackage */
793 * This is the opposite of GetVolumePackage(), and is always used at the end of
794 * AFS calls to put back all used vnodes and the volume in the proper order!
797 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
798 Vnode * parentptr, Volume * volptr, struct client **client)
800 int fileCode = 0; /* Error code returned by the volume package */
802 if (parentwhentargetnotdir) {
803 VPutVnode(&fileCode, parentwhentargetnotdir);
804 assert(!fileCode || (fileCode == VSALVAGE));
807 VPutVnode(&fileCode, targetptr);
808 assert(!fileCode || (fileCode == VSALVAGE));
811 VPutVnode(&fileCode, parentptr);
812 assert(!fileCode || (fileCode == VSALVAGE));
820 } /*PutVolumePackage */
823 VolumeOwner(register struct client *client, register Vnode * targetptr)
825 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
828 return (client->ViceId == owner);
831 * We don't have to check for host's cps since only regular
832 * viceid are volume owners.
834 return (client_HasAsMember(client, owner));
840 VolumeRootVnode(Vnode * targetptr)
842 return ((targetptr->vnodeNumber == ROOTVNODE)
843 && (targetptr->disk.uniquifier == 1));
845 } /*VolumeRootVnode */
848 * Check if target file has the proper access permissions for the Fetch
849 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
850 * StoreStatus) related calls
852 /* this code should probably just set a "priv" flag where all the audit events
853 * are now, and only generate the audit event once at the end of the routine,
854 * thus only generating the event if all the checks succeed, but only because
855 * of the privilege XXX
858 Check_PermissionRights(Vnode * targetptr, struct client *client,
859 afs_int32 rights, int CallingRoutine,
860 AFSStoreStatus * InStatus)
863 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
864 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
865 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
867 if (CallingRoutine & CHK_FETCH) {
868 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
869 if (targetptr->disk.type == vDirectory
870 || targetptr->disk.type == vSymlink) {
871 if (!(rights & PRSFS_LOOKUP)
872 #ifdef ADMIN_IMPLICIT_LOOKUP
873 /* grant admins fetch on all directories */
874 && VanillaUser(client)
875 #endif /* ADMIN_IMPLICIT_LOOKUP */
876 && !VolumeOwner(client, targetptr))
879 /* must have read access, or be owner and have insert access */
880 if (!(rights & PRSFS_READ)
881 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
884 if (CallingRoutine == CHK_FETCHDATA
885 && targetptr->disk.type == vFile)
886 #ifdef USE_GROUP_PERMS
887 if (!OWNSp(client, targetptr)
888 && !client_HasAsMember(client, targetptr->disk.owner)) {
890 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
894 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
899 * The check with the ownership below is a kludge to allow
900 * reading of files created with no read permission. The owner
901 * of the file is always allowed to read it.
903 if ((client->ViceId != targetptr->disk.owner)
904 && VanillaUser(client))
906 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
907 modeBits) ? 0 : EACCES);
909 } else { /* !VanillaUser(client) && !FetchData */
911 osi_audit(PrivilegeEvent, 0, AUD_ID,
912 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
915 } else { /* a store operation */
916 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
917 && (CallingRoutine != CHK_STOREACL)
918 && (targetptr->disk.type == vFile)) {
919 /* bypass protection checks on first store after a create
920 * for the creator; also prevent chowns during this time
921 * unless you are a system administrator */
922 /****** InStatus->Owner && UnixModeBits better be SET!! */
923 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
926 else if (VanillaUser(client))
927 return (EPERM); /* Was EACCES */
929 osi_audit(PrivilegeEvent, 0, AUD_ID,
930 (client ? client->ViceId : 0), AUD_INT,
931 CallingRoutine, AUD_END);
934 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
935 osi_audit(PrivilegeEvent, 0, AUD_ID,
936 (client ? client->ViceId : 0), AUD_INT,
937 CallingRoutine, AUD_END);
939 if (readonlyServer) {
942 if (CallingRoutine == CHK_STOREACL) {
943 if (!(rights & PRSFS_ADMINISTER)
944 && !VolumeOwner(client, targetptr))
946 } else { /* store data or status */
947 /* watch for chowns and chgrps */
948 if (CHOWN(InStatus, targetptr)
949 || CHGRP(InStatus, targetptr)) {
952 else if (VanillaUser(client))
953 return (EPERM); /* Was EACCES */
955 osi_audit(PrivilegeEvent, 0, AUD_ID,
956 (client ? client->ViceId : 0), AUD_INT,
957 CallingRoutine, AUD_END);
959 /* must be sysadmin to set suid/sgid bits */
960 if ((InStatus->Mask & AFS_SETMODE) &&
962 (InStatus->UnixModeBits & 0xc00) != 0) {
964 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
968 if (VanillaUser(client))
971 osi_audit(PrivSetID, 0, AUD_ID,
972 (client ? client->ViceId : 0), AUD_INT,
973 CallingRoutine, AUD_END);
975 if (CallingRoutine == CHK_STOREDATA) {
978 if (!(rights & PRSFS_WRITE))
980 /* Next thing is tricky. We want to prevent people
981 * from writing files sans 0200 bit, but we want
982 * creating new files with 0444 mode to work. We
983 * don't check the 0200 bit in the "you are the owner"
984 * path above, but here we check the bit. However, if
985 * you're a system administrator, we ignore the 0200
986 * bit anyway, since you may have fchowned the file,
988 #ifdef USE_GROUP_PERMS
989 if ((targetptr->disk.type == vFile)
990 && VanillaUser(client)) {
991 if (!OWNSp(client, targetptr)
992 && !client_HasAsMember(client, targetptr->disk.owner)) {
994 ((GROUPWRITE & targetptr->disk.modeBits)
998 ((OWNERWRITE & targetptr->disk.modeBits)
1003 if ((targetptr->disk.type != vDirectory)
1004 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1007 if (VanillaUser(client))
1010 osi_audit(PrivilegeEvent, 0, AUD_ID,
1011 (client ? client->ViceId : 0),
1012 AUD_INT, CallingRoutine, AUD_END);
1014 } else { /* a status store */
1017 if (targetptr->disk.type == vDirectory) {
1018 if (!(rights & PRSFS_DELETE)
1019 && !(rights & PRSFS_INSERT))
1021 } else { /* a file or symlink */
1022 if (!(rights & PRSFS_WRITE))
1032 } /*Check_PermissionRights */
1036 * The Access List information is converted from its internal form in the
1037 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1038 * external form and returned back to the caller, via the AccessList
1042 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1043 struct AFSOpaque *AccessList)
1045 char *eACL; /* External access list placeholder */
1048 ((targetptr->disk.type ==
1049 vDirectory ? VVnodeACL(targetptr) :
1050 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1053 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1054 acl_FreeExternalACL(&eACL);
1057 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1058 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1060 acl_FreeExternalACL(&eACL);
1063 } /*RXFetch_AccessList */
1067 * The Access List information is converted from its external form in the
1068 * input AccessList structure to the internal representation and copied into
1069 * the target dir's vnode storage.
1072 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1074 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1076 if (acl_Internalize(AccessList->AFSOpaque_val, &newACL) != 0)
1078 if ((newACL->size + 4) > VAclSize(targetptr))
1080 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1081 acl_FreeACL(&newACL);
1084 } /*RXStore_AccessList */
1087 /* In our current implementation, each successive data store (new file
1088 * data version) creates a new inode. This function creates the new
1089 * inode, copies the old inode's contents to the new one, remove the old
1090 * inode (i.e. decrement inode count -- if it's currently used the delete
1091 * will be delayed), and modify some fields (i.e. vnode's
1092 * disk.inodeNumber and cloned)
1094 #define COPYBUFFSIZE 8192
1096 CopyOnWrite(Vnode * targetptr, Volume * volptr)
1098 Inode ino, nearInode;
1101 register afs_fsize_t size;
1102 register int length;
1104 int rc; /* return code */
1105 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1106 FdHandle_t *targFdP; /* Source Inode file handle */
1107 FdHandle_t *newFdP; /* Dest Inode file handle */
1109 if (targetptr->disk.type == vDirectory)
1110 DFlush(); /* just in case? */
1112 VN_GET_LEN(size, targetptr);
1113 buff = (char *)malloc(COPYBUFFSIZE);
1118 ino = VN_GET_INO(targetptr);
1119 if (!VALID_INO(ino)) {
1121 VTakeOffline(volptr);
1122 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1126 targFdP = IH_OPEN(targetptr->handle);
1127 if (targFdP == NULL) {
1130 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1131 targetptr->vnodeNumber, V_id(volptr), rc));
1133 VTakeOffline(volptr);
1137 nearInode = VN_GET_INO(targetptr);
1139 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1140 VPartitionPath(V_partition(volptr)), nearInode,
1141 V_id(volptr), targetptr->vnodeNumber,
1142 targetptr->disk.uniquifier,
1143 (int)targetptr->disk.dataVersion);
1144 if (!VALID_INO(ino)) {
1146 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1147 volptr->partition->name, V_id(volptr), errno));
1152 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1153 newFdP = IH_OPEN(newH);
1154 assert(newFdP != NULL);
1157 if (size > COPYBUFFSIZE) { /* more than a buffer */
1158 length = COPYBUFFSIZE;
1159 size -= COPYBUFFSIZE;
1164 rdlen = FDH_READ(targFdP, buff, length);
1165 if (rdlen == length)
1166 wrlen = FDH_WRITE(newFdP, buff, length);
1169 /* Callers of this function are not prepared to recover
1170 * from error that put the filesystem in an inconsistent
1171 * state. Make sure that we force the volume off-line if
1172 * we some error other than ENOSPC - 4.29.99)
1174 * In case we are unable to write the required bytes, and the
1175 * error code indicates that the disk is full, we roll-back to
1176 * the initial state.
1178 if ((rdlen != length) || (wrlen != length))
1179 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1181 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1182 volptr->partition->name, V_id(volptr)));
1183 /* remove destination inode which was partially copied till now */
1184 FDH_REALLYCLOSE(newFdP);
1186 FDH_REALLYCLOSE(targFdP);
1187 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1190 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1191 rc, V_id(volptr), volptr->partition->name));
1192 VTakeOffline(volptr);
1198 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1199 V_id(volptr), volptr->partition->name, length, rdlen,
1201 #if defined(AFS_DEMAND_ATTACH_FS)
1202 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1204 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1206 /* Decrement this inode so salvager doesn't find it. */
1207 FDH_REALLYCLOSE(newFdP);
1209 FDH_REALLYCLOSE(targFdP);
1210 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1212 VTakeOffline(volptr);
1215 #ifndef AFS_PTHREAD_ENV
1217 #endif /* !AFS_PTHREAD_ENV */
1219 FDH_REALLYCLOSE(targFdP);
1220 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1221 V_parentId(volptr));
1223 IH_RELEASE(targetptr->handle);
1225 rc = FDH_SYNC(newFdP);
1228 targetptr->handle = newH;
1229 VN_SET_INO(targetptr, ino);
1230 targetptr->disk.cloned = 0;
1231 /* Internal change to vnode, no user level change to volume - def 5445 */
1232 targetptr->changed_oldTime = 1;
1234 return 0; /* success */
1239 * Common code to handle with removing the Name (file when it's called from
1240 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1241 * given directory, parentptr.
1243 int DT1 = 0, DT0 = 0;
1245 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1246 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1248 DirHandle childdir; /* Handle for dir package I/O */
1252 /* watch for invalid names */
1253 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1255 if (parentptr->disk.cloned) {
1256 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1257 if ((errorCode = CopyOnWrite(parentptr, volptr))) {
1259 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1265 /* check that the file is in the directory */
1266 SetDirHandle(dir, parentptr);
1267 if (Lookup(dir, Name, fileFid))
1269 fileFid->Volume = V_id(volptr);
1271 /* just-in-case check for something causing deadlock */
1272 if (fileFid->Vnode == parentptr->vnodeNumber)
1275 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1279 if (ChkForDir == MustBeDIR) {
1280 if ((*targetptr)->disk.type != vDirectory)
1282 } else if ((*targetptr)->disk.type == vDirectory)
1285 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1287 * If the uniquifiers dont match then instead of asserting
1288 * take the volume offline and return VSALVAGE
1290 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1291 VTakeOffline(volptr);
1293 ("Volume %u now offline, must be salvaged.\n",
1295 errorCode = VSALVAGE;
1299 if (ChkForDir == MustBeDIR) {
1300 SetDirHandle(&childdir, *targetptr);
1301 if (IsEmpty(&childdir) != 0)
1305 (*targetptr)->delete = 1;
1306 } else if ((--(*targetptr)->disk.linkCount) == 0)
1307 (*targetptr)->delete = 1;
1308 if ((*targetptr)->delete) {
1309 if (VN_GET_INO(*targetptr)) {
1311 IH_REALLYCLOSE((*targetptr)->handle);
1313 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1314 V_parentId(volptr));
1315 IH_RELEASE((*targetptr)->handle);
1316 if (errorCode == -1) {
1318 ("DT: inode=%s, name=%s, errno=%d\n",
1319 PrintInode(NULL, VN_GET_INO(*targetptr)), Name,
1321 if (errno != ENOENT)
1323 VTakeOffline(volptr);
1325 ("Volume %u now offline, must be salvaged.\n",
1333 VN_SET_INO(*targetptr, (Inode) 0);
1335 afs_fsize_t adjLength;
1336 VN_GET_LEN(adjLength, *targetptr);
1337 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1341 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1343 code = Delete(dir, (char *)Name);
1346 ("Error %d deleting %s\n", code,
1347 (((*targetptr)->disk.type ==
1348 Directory) ? "directory" : "file")));
1349 VTakeOffline(volptr);
1351 ("Volume %u now offline, must be salvaged.\n",
1364 * This routine updates the parent directory's status block after the
1365 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1366 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1370 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1371 int author, int linkcount,
1372 #if FS_STATS_DETAILED
1373 char a_inSameNetwork
1374 #endif /* FS_STATS_DETAILED */
1377 afs_fsize_t newlength; /* Holds new directory length */
1378 afs_fsize_t parentLength;
1380 #if FS_STATS_DETAILED
1381 Date currDate; /*Current date */
1382 int writeIdx; /*Write index to bump */
1383 int timeIdx; /*Authorship time index to bump */
1384 #endif /* FS_STATS_DETAILED */
1386 parentptr->disk.dataVersion++;
1387 newlength = (afs_fsize_t) Length(dir);
1389 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1390 * (create, symlink, link, makedir) so we need to check if we have enough space
1391 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1392 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1394 VN_GET_LEN(parentLength, parentptr);
1395 if (nBlocks(newlength) != nBlocks(parentLength)) {
1396 VAdjustDiskUsage(&errorCode, volptr,
1397 (nBlocks(newlength) - nBlocks(parentLength)),
1398 (nBlocks(newlength) - nBlocks(parentLength)));
1400 VN_SET_LEN(parentptr, newlength);
1402 #if FS_STATS_DETAILED
1404 * Update directory write stats for this volume. Note that the auth
1405 * counter is located immediately after its associated ``distance''
1408 if (a_inSameNetwork)
1409 writeIdx = VOL_STATS_SAME_NET;
1411 writeIdx = VOL_STATS_DIFF_NET;
1412 V_stat_writes(volptr, writeIdx)++;
1413 if (author != AnonymousID) {
1414 V_stat_writes(volptr, writeIdx + 1)++;
1418 * Update the volume's authorship information in response to this
1419 * directory operation. Get the current time, decide to which time
1420 * slot this operation belongs, and bump the appropriate slot.
1422 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1424 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1425 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1426 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1427 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1428 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1429 if (parentptr->disk.author == author) {
1430 V_stat_dirSameAuthor(volptr, timeIdx)++;
1432 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1434 #endif /* FS_STATS_DETAILED */
1436 parentptr->disk.author = author;
1437 parentptr->disk.linkCount = linkcount;
1438 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1439 parentptr->disk.serverModifyTime = FT_ApproxTime();
1440 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1445 * Update the target file's (or dir's) status block after the specified
1446 * operation is complete. Note that some other fields maybe updated by
1447 * the individual module.
1450 /* XXX INCOMPLETE - More attention is needed here! */
1452 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1453 struct client *client, AFSStoreStatus * InStatus,
1454 Vnode * parentptr, Volume * volptr,
1457 #if FS_STATS_DETAILED
1458 Date currDate; /*Current date */
1459 int writeIdx; /*Write index to bump */
1460 int timeIdx; /*Authorship time index to bump */
1461 #endif /* FS_STATS_DETAILED */
1463 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1464 targetptr->disk.parent = parentptr->vnodeNumber;
1465 VN_SET_LEN(targetptr, length);
1466 /* targetptr->disk.group = 0; save some cycles */
1467 targetptr->disk.modeBits = 0777;
1468 targetptr->disk.owner = client->ViceId;
1469 targetptr->disk.dataVersion = 0; /* consistent with the client */
1470 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1471 /* the inode was created in Alloc_NewVnode() */
1473 #if FS_STATS_DETAILED
1475 * Update file write stats for this volume. Note that the auth
1476 * counter is located immediately after its associated ``distance''
1479 if (client->InSameNetwork)
1480 writeIdx = VOL_STATS_SAME_NET;
1482 writeIdx = VOL_STATS_DIFF_NET;
1483 V_stat_writes(volptr, writeIdx)++;
1484 if (client->ViceId != AnonymousID) {
1485 V_stat_writes(volptr, writeIdx + 1)++;
1489 * We only count operations that DON'T involve creating new objects
1490 * (files, symlinks, directories) or simply setting status as
1491 * authorship-change operations.
1493 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1495 * Update the volume's authorship information in response to this
1496 * file operation. Get the current time, decide to which time
1497 * slot this operation belongs, and bump the appropriate slot.
1499 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1502 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1503 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1504 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1505 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1506 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1507 VOL_STATS_TIME_IDX_5);
1508 if (targetptr->disk.author == client->ViceId) {
1509 V_stat_fileSameAuthor(volptr, timeIdx)++;
1511 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1514 #endif /* FS_STATS_DETAILED */
1516 if (!(Caller & TVS_SSTATUS))
1517 targetptr->disk.author = client->ViceId;
1518 if (Caller & TVS_SDATA) {
1519 targetptr->disk.dataVersion++;
1520 if (VanillaUser(client)) {
1521 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1522 #ifdef CREATE_SGUID_ADMIN_ONLY
1523 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1527 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1528 /* store status, must explicitly request to change the date */
1529 if (InStatus->Mask & AFS_SETMODTIME)
1530 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1531 } else { /* other: date always changes, but perhaps to what is specified by caller */
1532 targetptr->disk.unixModifyTime =
1533 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1534 ClientModTime : FT_ApproxTime());
1536 if (InStatus->Mask & AFS_SETOWNER) {
1537 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1538 if (VanillaUser(client)) {
1539 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1540 #ifdef CREATE_SGUID_ADMIN_ONLY
1541 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1544 targetptr->disk.owner = InStatus->Owner;
1545 if (VolumeRootVnode(targetptr)) {
1546 Error errorCode = 0; /* what should be done with this? */
1548 V_owner(targetptr->volumePtr) = InStatus->Owner;
1549 VUpdateVolume(&errorCode, targetptr->volumePtr);
1552 if (InStatus->Mask & AFS_SETMODE) {
1553 int modebits = InStatus->UnixModeBits;
1554 #define CREATE_SGUID_ADMIN_ONLY 1
1555 #ifdef CREATE_SGUID_ADMIN_ONLY
1556 if (VanillaUser(client))
1557 modebits = modebits & 0777;
1559 if (VanillaUser(client)) {
1560 targetptr->disk.modeBits = modebits;
1562 targetptr->disk.modeBits = modebits;
1565 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1566 CHK_STOREDATA, AUD_END);
1570 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1571 CHK_STORESTATUS, AUD_END);
1578 targetptr->disk.serverModifyTime = FT_ApproxTime();
1579 if (InStatus->Mask & AFS_SETGROUP)
1580 targetptr->disk.group = InStatus->Group;
1581 /* vnode changed : to be written back by VPutVnode */
1582 targetptr->changed_newTime = 1;
1584 } /*Update_TargetVnodeStatus */
1588 * Fills the CallBack structure with the expiration time and type of callback
1589 * structure. Warning: this function is currently incomplete.
1592 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1594 /* CallBackTime could not be 0 */
1595 if (CallBackTime == 0) {
1596 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1597 CallBack->ExpirationTime = 0;
1599 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1600 CallBack->CallBackVersion = CALLBACK_VERSION;
1601 CallBack->CallBackType = CB_SHARED; /* The default for now */
1603 } /*SetCallBackStruct */
1607 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1608 * allocation; if some error occured (exceeded volume quota or partition
1609 * was full, or whatever), it frees the space back and returns the code.
1610 * We usually pre-adjust the volume space to make sure that there's
1611 * enough space before consuming some.
1614 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1615 afs_sfsize_t checkLength)
1620 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1622 VAdjustDiskUsage(&nc, volptr, -length, 0);
1623 if (rc == VOVERQUOTA) {
1625 ("Volume %u (%s) is full\n", V_id(volptr),
1629 if (rc == VDISKFULL) {
1631 ("Partition %s that contains volume %u is full\n",
1632 volptr->partition->name, V_id(volptr)));
1635 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1640 } /*AdjustDiskUsage */
1643 * Common code that handles the creation of a new file (SAFS_CreateFile and
1644 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1647 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1648 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1649 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1651 int errorCode = 0; /* Error code returned back */
1654 Inode nearInode; /* hint for inode allocation in solaris */
1657 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1658 BlocksPreallocatedForVnode))) {
1660 ("Insufficient space to allocate %lld blocks\n",
1661 (afs_intmax_t) BlocksPreallocatedForVnode));
1665 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1666 if (errorCode != 0) {
1667 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1670 OutFid->Volume = V_id(volptr);
1671 OutFid->Vnode = (*targetptr)->vnodeNumber;
1672 OutFid->Unique = (*targetptr)->disk.uniquifier;
1674 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1676 /* create the inode now itself */
1678 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1679 VPartitionPath(V_partition(volptr)), nearInode,
1680 V_id(volptr), (*targetptr)->vnodeNumber,
1681 (*targetptr)->disk.uniquifier, 1);
1683 /* error in creating inode */
1684 if (!VALID_INO(inode)) {
1686 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1687 (*targetptr)->volumePtr->header->diskstuff.id,
1688 (*targetptr)->vnodeNumber, errno));
1689 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1690 (*targetptr)->delete = 1; /* delete vnode */
1693 VN_SET_INO(*targetptr, inode);
1694 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1696 /* copy group from parent dir */
1697 (*targetptr)->disk.group = parentptr->disk.group;
1699 if (parentptr->disk.cloned) {
1700 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1701 if ((errorCode = CopyOnWrite(parentptr, volptr))) { /* disk full */
1702 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1703 /* delete the vnode previously allocated */
1704 (*targetptr)->delete = 1;
1705 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1706 IH_REALLYCLOSE((*targetptr)->handle);
1707 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1709 ("Alloc_NewVnode: partition %s idec %s failed\n",
1710 volptr->partition->name, PrintInode(NULL, inode)));
1711 IH_RELEASE((*targetptr)->handle);
1717 /* add the name to the directory */
1718 SetDirHandle(dir, parentptr);
1719 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1720 (*targetptr)->delete = 1;
1721 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1722 IH_REALLYCLOSE((*targetptr)->handle);
1723 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1725 ("Alloc_NewVnode: partition %s idec %s failed\n",
1726 volptr->partition->name, PrintInode(NULL, inode)));
1727 IH_RELEASE((*targetptr)->handle);
1733 } /*Alloc_NewVnode */
1737 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1741 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1743 int Time; /* Used for time */
1744 int writeVnode = targetptr->changed_oldTime; /* save original status */
1746 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1747 Time = FT_ApproxTime();
1748 switch (LockingType) {
1751 if (Time > targetptr->disk.lock.lockTime)
1752 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1754 Time += AFS_LOCKWAIT;
1755 if (LockingType == LockRead) {
1756 if ( !(rights & PRSFS_LOCK) &&
1757 !(rights & PRSFS_WRITE) &&
1758 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1762 if (targetptr->disk.lock.lockCount >= 0) {
1763 ++(targetptr->disk.lock.lockCount);
1764 targetptr->disk.lock.lockTime = Time;
1767 } else if (LockingType == LockWrite) {
1768 if ( !(rights & PRSFS_WRITE) &&
1769 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1772 if (targetptr->disk.lock.lockCount == 0) {
1773 targetptr->disk.lock.lockCount = -1;
1774 targetptr->disk.lock.lockTime = Time;
1780 Time += AFS_LOCKWAIT;
1781 if (targetptr->disk.lock.lockCount != 0)
1782 targetptr->disk.lock.lockTime = Time;
1787 if ((--targetptr->disk.lock.lockCount) <= 0)
1788 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1792 targetptr->changed_oldTime = writeVnode; /* restore old status */
1793 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1796 } /*HandleLocking */
1798 /* 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. */
1801 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1805 if (!(rights & Prfs_Mode))
1807 if ((targetptr->disk.type != vDirectory)
1808 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1814 * If some flags (i.e. min or max quota) are set, the volume's in disk
1815 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1816 * update, if applicable.
1819 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1820 char *Name, char *OfflineMsg, char *Motd)
1822 Error errorCode = 0;
1824 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1825 V_minquota(volptr) = StoreVolStatus->MinQuota;
1826 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1827 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1828 if (strlen(OfflineMsg) > 0) {
1829 strcpy(V_offlineMessage(volptr), OfflineMsg);
1831 if (strlen(Name) > 0) {
1832 strcpy(V_name(volptr), Name);
1834 #if OPENAFS_VOL_STATS
1836 * We don't overwrite the motd field, since it's now being used
1840 if (strlen(Motd) > 0) {
1841 strcpy(V_motd(volptr), Motd);
1843 #endif /* FS_STATS_DETAILED */
1844 VUpdateVolume(&errorCode, volptr);
1847 } /*RXUpdate_VolumeStatus */
1851 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1852 char **motd, Volume * volptr)
1856 status->Vid = V_id(volptr);
1857 status->ParentId = V_parentId(volptr);
1858 status->Online = V_inUse(volptr);
1859 status->InService = V_inService(volptr);
1860 status->Blessed = V_blessed(volptr);
1861 status->NeedsSalvage = V_needsSalvaged(volptr);
1862 if (VolumeWriteable(volptr))
1863 status->Type = ReadWrite;
1865 status->Type = ReadOnly;
1866 status->MinQuota = V_minquota(volptr);
1867 status->MaxQuota = V_maxquota(volptr);
1868 status->BlocksInUse = V_diskused(volptr);
1869 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
1870 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
1872 /* now allocate and copy these things; they're freed by the RXGEN stub */
1873 temp = strlen(V_name(volptr)) + 1;
1874 *name = malloc(temp);
1876 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1879 strcpy(*name, V_name(volptr));
1880 temp = strlen(V_offlineMessage(volptr)) + 1;
1881 *offMsg = malloc(temp);
1883 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1886 strcpy(*offMsg, V_offlineMessage(volptr));
1887 #if OPENAFS_VOL_STATS
1890 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1893 strcpy(*motd, nullString);
1895 temp = strlen(V_motd(volptr)) + 1;
1896 *motd = malloc(temp);
1898 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1901 strcpy(*motd, V_motd(volptr));
1902 #endif /* FS_STATS_DETAILED */
1904 } /*RXGetVolumeStatus */
1908 FileNameOK(register char *aname)
1910 register afs_int32 i, tc;
1913 /* watch for @sys on the right */
1914 if (strcmp(aname + i - 4, "@sys") == 0)
1917 while ((tc = *aname++)) {
1919 return 0; /* very bad character to encounter */
1921 return 1; /* file name is ok */
1927 * This variant of symlink is expressly to support the AFS/DFS translator
1928 * and is not supported by the AFS fileserver. We just return EINVAL.
1929 * The cache manager should not generate this call to an AFS cache manager.
1932 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
1933 char *LinkContents, struct AFSStoreStatus *InStatus,
1934 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
1935 struct AFSFetchStatus *OutDirStatus,
1936 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
1942 SRXAFS_ResidencyCmd(struct rx_call * acall, struct AFSFid * Fid,
1943 struct ResidencyCmdInputs * Inputs,
1944 struct ResidencyCmdOutputs * Outputs)
1950 static struct afs_buffer {
1951 struct afs_buffer *next;
1952 } *freeBufferList = 0;
1953 static int afs_buffersAlloced = 0;
1956 FreeSendBuffer(register struct afs_buffer *adata)
1959 afs_buffersAlloced--;
1960 adata->next = freeBufferList;
1961 freeBufferList = adata;
1965 } /*FreeSendBuffer */
1967 /* allocate space for sender */
1971 register struct afs_buffer *tp;
1974 afs_buffersAlloced++;
1975 if (!freeBufferList) {
1978 tmp = malloc(sendBufSize);
1980 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
1985 tp = freeBufferList;
1986 freeBufferList = tp->next;
1990 } /*AllocSendBuffer */
1991 #endif /* AFS_NT40_ENV */
1994 * This routine returns the status info associated with the targetptr vnode
1995 * in the AFSFetchStatus structure. Some of the newer fields, such as
1996 * SegSize and Group are not yet implemented
2000 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2001 afs_int32 anyrights, Vnode * parentptr)
2003 /* initialize return status from a vnode */
2004 status->InterfaceVersion = 1;
2005 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2006 status->errorCode = 0;
2007 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2008 if (targetptr->disk.type == vFile)
2009 status->FileType = File;
2010 else if (targetptr->disk.type == vDirectory)
2011 status->FileType = Directory;
2012 else if (targetptr->disk.type == vSymlink)
2013 status->FileType = SymbolicLink;
2015 status->FileType = Invalid; /*invalid type field */
2016 status->LinkCount = targetptr->disk.linkCount;
2018 afs_fsize_t targetLen;
2019 VN_GET_LEN(targetLen, targetptr);
2020 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2022 status->DataVersion = targetptr->disk.dataVersion;
2023 status->Author = targetptr->disk.author;
2024 status->Owner = targetptr->disk.owner;
2025 status->CallerAccess = rights;
2026 status->AnonymousAccess = anyrights;
2027 status->UnixModeBits = targetptr->disk.modeBits;
2028 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2029 status->ParentVnode =
2030 (status->FileType ==
2031 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2032 status->ParentUnique =
2033 (status->FileType ==
2034 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2035 status->ServerModTime = targetptr->disk.serverModifyTime;
2036 status->Group = targetptr->disk.group;
2037 status->lockCount = targetptr->disk.lock.lockCount;
2038 status->errorCode = 0;
2044 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2045 afs_sfsize_t Pos, afs_sfsize_t Len,
2046 struct AFSFetchStatus *OutStatus,
2047 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2050 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2051 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2052 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2053 int errorCode = 0; /* return code to caller */
2054 int fileCode = 0; /* return code from vol package */
2055 Volume *volptr = 0; /* pointer to the volume */
2056 struct client *client = 0; /* pointer to the client data */
2057 struct rx_connection *tcon; /* the connection we're part of */
2059 afs_int32 rights, anyrights; /* rights for this and any user */
2060 struct client *t_client = NULL; /* tmp ptr to client data */
2061 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2062 #if FS_STATS_DETAILED
2063 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2064 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2065 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2066 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2067 struct timeval elapsedTime; /* Transfer time */
2068 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2069 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2070 int readIdx; /* Index of read stats array to bump */
2071 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2074 * Set our stats pointers, remember when the RPC operation started, and
2075 * tally the operation.
2077 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2078 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2082 TM_GetTimeOfDay(&opStartTime, 0);
2083 #endif /* FS_STATS_DETAILED */
2086 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2089 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2091 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2094 /* Get ptr to client data for user Id for logging */
2095 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2096 logHostAddr.s_addr = rxr_HostOf(tcon);
2098 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2099 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2100 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2102 * Get volume/vnode for the fetched file; caller's access rights to
2103 * it are also returned
2106 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2107 &parentwhentargetnotdir, &client, READ_LOCK,
2108 &rights, &anyrights)))
2111 SetVolumeSync(Sync, volptr);
2113 #if FS_STATS_DETAILED
2115 * Remember that another read operation was performed.
2118 if (client->InSameNetwork)
2119 readIdx = VOL_STATS_SAME_NET;
2121 readIdx = VOL_STATS_DIFF_NET;
2122 V_stat_reads(volptr, readIdx)++;
2123 if (client->ViceId != AnonymousID) {
2124 V_stat_reads(volptr, readIdx + 1)++;
2127 #endif /* FS_STATS_DETAILED */
2128 /* Check whether the caller has permission access to fetch the data */
2130 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2134 * Drop the read lock on the parent directory after saving the parent
2135 * vnode information we need to pass to GetStatus
2137 if (parentwhentargetnotdir != NULL) {
2138 tparentwhentargetnotdir = *parentwhentargetnotdir;
2139 VPutVnode(&fileCode, parentwhentargetnotdir);
2140 assert(!fileCode || (fileCode == VSALVAGE));
2141 parentwhentargetnotdir = NULL;
2143 #if FS_STATS_DETAILED
2145 * Remember when the data transfer started.
2147 TM_GetTimeOfDay(&xferStartTime, 0);
2148 #endif /* FS_STATS_DETAILED */
2150 /* actually do the data transfer */
2151 #if FS_STATS_DETAILED
2153 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2154 &bytesToXfer, &bytesXferred);
2157 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2159 #endif /* FS_STATS_DETAILED */
2161 #if FS_STATS_DETAILED
2163 * At this point, the data transfer is done, for good or ill. Remember
2164 * when the transfer ended, bump the number of successes/failures, and
2165 * integrate the transfer size and elapsed time into the stats. If the
2166 * operation failed, we jump to the appropriate point.
2168 TM_GetTimeOfDay(&xferStopTime, 0);
2170 (xferP->numXfers)++;
2172 (xferP->numSuccesses)++;
2175 * Bump the xfer sum by the number of bytes actually sent, NOT the
2178 tot_bytesXferred += bytesXferred;
2179 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2180 tot_bytesXferred &= 0x3FF;
2181 if (bytesXferred < xferP->minBytes)
2182 xferP->minBytes = bytesXferred;
2183 if (bytesXferred > xferP->maxBytes)
2184 xferP->maxBytes = bytesXferred;
2187 * Tally the size of the object. Note: we tally the actual size,
2188 * NOT the number of bytes that made it out over the wire.
2190 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2191 (xferP->count[0])++;
2192 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2193 (xferP->count[1])++;
2194 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2195 (xferP->count[2])++;
2196 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2197 (xferP->count[3])++;
2198 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2199 (xferP->count[4])++;
2200 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2201 (xferP->count[5])++;
2202 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2203 (xferP->count[6])++;
2204 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2205 (xferP->count[7])++;
2207 (xferP->count[8])++;
2209 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2210 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2211 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2212 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2213 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2215 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2216 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2221 * Finally, go off to tell our caller the bad news in case the
2226 #endif /* FS_STATS_DETAILED */
2228 /* write back the OutStatus from the target vnode */
2229 GetStatus(targetptr, OutStatus, rights, anyrights,
2230 &tparentwhentargetnotdir);
2232 /* if a r/w volume, promise a callback to the caller */
2233 if (VolumeWriteable(volptr))
2234 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2236 struct AFSFid myFid;
2237 memset(&myFid, 0, sizeof(struct AFSFid));
2238 myFid.Volume = Fid->Volume;
2239 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2243 /* Update and store volume/vnode and parent vnodes back */
2244 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2246 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2247 errorCode = CallPostamble(tcon, errorCode, thost);
2249 #if FS_STATS_DETAILED
2250 TM_GetTimeOfDay(&opStopTime, 0);
2251 if (errorCode == 0) {
2253 (opP->numSuccesses)++;
2254 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2255 fs_stats_AddTo((opP->sumTime), elapsedTime);
2256 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2257 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2258 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2260 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2261 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2265 #endif /* FS_STATS_DETAILED */
2267 osi_auditU(acall, FetchDataEvent, errorCode,
2268 AUD_ID, t_client ? t_client->ViceId : 0,
2269 AUD_FID, Fid, AUD_END);
2272 } /*SRXAFS_FetchData */
2275 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2276 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2277 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2279 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2284 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2285 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2286 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2289 afs_sfsize_t tPos, tLen;
2291 #ifdef AFS_64BIT_ENV
2292 #ifndef AFS_LARGEFILE_ENV
2293 if (Pos + Len > 0x7fffffff)
2295 #endif /* !AFS_LARGEFILE_ENV */
2296 tPos = (afs_sfsize_t) Pos;
2297 tLen = (afs_sfsize_t) Len;
2298 #else /* AFS_64BIT_ENV */
2299 if (Pos.high || Len.high)
2303 #endif /* AFS_64BIT_ENV */
2306 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2312 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2313 struct AFSOpaque * AccessList,
2314 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2316 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2317 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2318 int errorCode = 0; /* return error code to caller */
2319 Volume *volptr = 0; /* pointer to the volume */
2320 struct client *client = 0; /* pointer to the client data */
2321 afs_int32 rights, anyrights; /* rights for this and any user */
2322 struct rx_connection *tcon = rx_ConnectionOf(acall);
2324 struct client *t_client = NULL; /* tmp ptr to client data */
2325 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2326 #if FS_STATS_DETAILED
2327 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2328 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2329 struct timeval elapsedTime; /* Transfer time */
2332 * Set our stats pointer, remember when the RPC operation started, and
2333 * tally the operation.
2335 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2339 TM_GetTimeOfDay(&opStartTime, 0);
2340 #endif /* FS_STATS_DETAILED */
2343 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2346 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2348 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2351 /* Get ptr to client data for user Id for logging */
2352 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2353 logHostAddr.s_addr = rxr_HostOf(tcon);
2355 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2356 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2357 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2359 AccessList->AFSOpaque_len = 0;
2360 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2361 if (!AccessList->AFSOpaque_val) {
2362 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2367 * Get volume/vnode for the fetched file; caller's access rights to it
2371 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2372 &parentwhentargetnotdir, &client, READ_LOCK,
2373 &rights, &anyrights)))
2376 SetVolumeSync(Sync, volptr);
2378 /* Check whether we have permission to fetch the ACL */
2380 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2383 /* Get the Access List from the dir's vnode */
2385 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2388 /* Get OutStatus back From the target Vnode */
2389 GetStatus(targetptr, OutStatus, rights, anyrights,
2390 parentwhentargetnotdir);
2393 /* Update and store volume/vnode and parent vnodes back */
2394 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2397 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2398 AccessList->AFSOpaque_val));
2399 errorCode = CallPostamble(tcon, errorCode, thost);
2401 #if FS_STATS_DETAILED
2402 TM_GetTimeOfDay(&opStopTime, 0);
2403 if (errorCode == 0) {
2405 (opP->numSuccesses)++;
2406 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2407 fs_stats_AddTo((opP->sumTime), elapsedTime);
2408 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2409 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2410 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2412 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2413 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2417 #endif /* FS_STATS_DETAILED */
2419 osi_auditU(acall, FetchACLEvent, errorCode,
2420 AUD_ID, t_client ? t_client->ViceId : 0,
2422 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2424 } /*SRXAFS_FetchACL */
2428 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2429 * merged into it when possible.
2433 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2434 struct AFSFetchStatus *OutStatus,
2435 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2437 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2438 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2439 int errorCode = 0; /* return code to caller */
2440 Volume *volptr = 0; /* pointer to the volume */
2441 struct client *client = 0; /* pointer to the client data */
2442 afs_int32 rights, anyrights; /* rights for this and any user */
2443 struct client *t_client = NULL; /* tmp ptr to client data */
2444 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2445 struct rx_connection *tcon = rx_ConnectionOf(acall);
2447 /* Get ptr to client data for user Id for logging */
2448 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2449 logHostAddr.s_addr = rxr_HostOf(tcon);
2451 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2452 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2453 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2455 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2458 * Get volume/vnode for the fetched file; caller's rights to it are
2462 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2463 &parentwhentargetnotdir, &client, READ_LOCK,
2464 &rights, &anyrights)))
2465 goto Bad_FetchStatus;
2467 /* set volume synchronization information */
2468 SetVolumeSync(Sync, volptr);
2470 /* Are we allowed to fetch Fid's status? */
2471 if (targetptr->disk.type != vDirectory) {
2473 Check_PermissionRights(targetptr, client, rights,
2474 CHK_FETCHSTATUS, 0))) {
2475 if (rx_GetCallAbortCode(acall) == errorCode)
2476 rx_SetCallAbortCode(acall, 0);
2477 goto Bad_FetchStatus;
2481 /* set OutStatus From the Fid */
2482 GetStatus(targetptr, OutStatus, rights, anyrights,
2483 parentwhentargetnotdir);
2485 /* If a r/w volume, also set the CallBack state */
2486 if (VolumeWriteable(volptr))
2487 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2489 struct AFSFid myFid;
2490 memset(&myFid, 0, sizeof(struct AFSFid));
2491 myFid.Volume = Fid->Volume;
2492 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2496 /* Update and store volume/vnode and parent vnodes back */
2497 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2499 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2502 } /*SAFSS_FetchStatus */
2506 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2507 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2508 struct AFSVolSync * Sync)
2512 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2513 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2514 int errorCode = 0; /* return code to caller */
2515 Volume *volptr = 0; /* pointer to the volume */
2516 struct client *client = 0; /* pointer to the client data */
2517 afs_int32 rights, anyrights; /* rights for this and any user */
2518 register struct AFSFid *tfid; /* file id we're dealing with now */
2519 struct rx_connection *tcon = rx_ConnectionOf(acall);
2521 struct client *t_client = NULL; /* tmp pointer to the client data */
2522 #if FS_STATS_DETAILED
2523 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2524 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2525 struct timeval elapsedTime; /* Transfer time */
2528 * Set our stats pointer, remember when the RPC operation started, and
2529 * tally the operation.
2531 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2535 TM_GetTimeOfDay(&opStartTime, 0);
2536 #endif /* FS_STATS_DETAILED */
2538 ViceLog(1, ("SAFS_BulkStatus\n"));
2540 AFSCallStats.TotalCalls++;
2542 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2543 if (nfiles <= 0) { /* Sanity check */
2545 goto Audit_and_Return;
2548 /* allocate space for return output parameters */
2549 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2550 malloc(nfiles * sizeof(struct AFSFetchStatus));
2551 if (!OutStats->AFSBulkStats_val) {
2552 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2555 OutStats->AFSBulkStats_len = nfiles;
2556 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2557 malloc(nfiles * sizeof(struct AFSCallBack));
2558 if (!CallBacks->AFSCBs_val) {
2559 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2562 CallBacks->AFSCBs_len = nfiles;
2564 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2565 goto Bad_BulkStatus;
2567 tfid = Fids->AFSCBFids_val;
2568 for (i = 0; i < nfiles; i++, tfid++) {
2570 * Get volume/vnode for the fetched file; caller's rights to it
2574 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2575 &parentwhentargetnotdir, &client, READ_LOCK,
2576 &rights, &anyrights)))
2577 goto Bad_BulkStatus;
2578 /* set volume synchronization information, but only once per call */
2580 SetVolumeSync(Sync, volptr);
2582 /* Are we allowed to fetch Fid's status? */
2583 if (targetptr->disk.type != vDirectory) {
2585 Check_PermissionRights(targetptr, client, rights,
2586 CHK_FETCHSTATUS, 0))) {
2587 if (rx_GetCallAbortCode(acall) == errorCode)
2588 rx_SetCallAbortCode(acall, 0);
2589 goto Bad_BulkStatus;
2593 /* set OutStatus From the Fid */
2594 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2595 anyrights, parentwhentargetnotdir);
2597 /* If a r/w volume, also set the CallBack state */
2598 if (VolumeWriteable(volptr))
2599 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2600 &CallBacks->AFSCBs_val[i]);
2602 struct AFSFid myFid;
2603 memset(&myFid, 0, sizeof(struct AFSFid));
2604 myFid.Volume = tfid->Volume;
2605 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2606 &CallBacks->AFSCBs_val[i]);
2609 /* put back the file ID and volume */
2610 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2612 parentwhentargetnotdir = (Vnode *) 0;
2613 targetptr = (Vnode *) 0;
2614 volptr = (Volume *) 0;
2615 client = (struct client *)0;
2619 /* Update and store volume/vnode and parent vnodes back */
2620 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2622 errorCode = CallPostamble(tcon, errorCode, thost);
2624 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2626 #if FS_STATS_DETAILED
2627 TM_GetTimeOfDay(&opStopTime, 0);
2628 if (errorCode == 0) {
2630 (opP->numSuccesses)++;
2631 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2632 fs_stats_AddTo((opP->sumTime), elapsedTime);
2633 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2634 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2635 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2637 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2638 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2642 #endif /* FS_STATS_DETAILED */
2645 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2646 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2647 AUD_ID, t_client ? t_client->ViceId : 0,
2648 AUD_FIDS, Fids, AUD_END);
2651 } /*SRXAFS_BulkStatus */
2655 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2656 struct AFSBulkStats * OutStats,
2657 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2661 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2662 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2663 int errorCode = 0; /* return code to caller */
2664 Volume *volptr = 0; /* pointer to the volume */
2665 struct client *client = 0; /* pointer to the client data */
2666 afs_int32 rights, anyrights; /* rights for this and any user */
2667 register struct AFSFid *tfid; /* file id we're dealing with now */
2668 struct rx_connection *tcon;
2670 struct client *t_client = NULL; /* tmp ptr to client data */
2671 AFSFetchStatus *tstatus;
2672 #if FS_STATS_DETAILED
2673 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2674 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2675 struct timeval elapsedTime; /* Transfer time */
2678 * Set our stats pointer, remember when the RPC operation started, and
2679 * tally the operation.
2681 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2685 TM_GetTimeOfDay(&opStartTime, 0);
2686 #endif /* FS_STATS_DETAILED */
2688 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2690 AFSCallStats.TotalCalls++;
2692 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2693 if (nfiles <= 0) { /* Sanity check */
2695 goto Audit_and_Return;
2698 /* allocate space for return output parameters */
2699 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2700 malloc(nfiles * sizeof(struct AFSFetchStatus));
2701 if (!OutStats->AFSBulkStats_val) {
2702 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2705 OutStats->AFSBulkStats_len = nfiles;
2706 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2707 malloc(nfiles * sizeof(struct AFSCallBack));
2708 if (!CallBacks->AFSCBs_val) {
2709 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2712 CallBacks->AFSCBs_len = nfiles;
2714 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2715 goto Bad_InlineBulkStatus;
2718 tfid = Fids->AFSCBFids_val;
2719 for (i = 0; i < nfiles; i++, tfid++) {
2721 * Get volume/vnode for the fetched file; caller's rights to it
2725 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2726 &parentwhentargetnotdir, &client, READ_LOCK,
2727 &rights, &anyrights))) {
2728 tstatus = &OutStats->AFSBulkStats_val[i];
2729 tstatus->errorCode = errorCode;
2730 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2732 parentwhentargetnotdir = (Vnode *) 0;
2733 targetptr = (Vnode *) 0;
2734 volptr = (Volume *) 0;
2735 client = (struct client *)0;
2739 /* set volume synchronization information, but only once per call */
2741 SetVolumeSync(Sync, volptr);
2743 /* Are we allowed to fetch Fid's status? */
2744 if (targetptr->disk.type != vDirectory) {
2746 Check_PermissionRights(targetptr, client, rights,
2747 CHK_FETCHSTATUS, 0))) {
2748 tstatus = &OutStats->AFSBulkStats_val[i];
2749 tstatus->errorCode = errorCode;
2750 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2751 (Vnode *) 0, volptr, &client);
2752 parentwhentargetnotdir = (Vnode *) 0;
2753 targetptr = (Vnode *) 0;
2754 volptr = (Volume *) 0;
2755 client = (struct client *)0;
2760 /* set OutStatus From the Fid */
2761 GetStatus(targetptr,
2762 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2763 rights, anyrights, parentwhentargetnotdir);
2765 /* If a r/w volume, also set the CallBack state */
2766 if (VolumeWriteable(volptr))
2767 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2768 &CallBacks->AFSCBs_val[i]);
2770 struct AFSFid myFid;
2771 memset(&myFid, 0, sizeof(struct AFSFid));
2772 myFid.Volume = tfid->Volume;
2773 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2774 &CallBacks->AFSCBs_val[i]);
2777 /* put back the file ID and volume */
2778 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2780 parentwhentargetnotdir = (Vnode *) 0;
2781 targetptr = (Vnode *) 0;
2782 volptr = (Volume *) 0;
2783 client = (struct client *)0;
2786 Bad_InlineBulkStatus:
2787 /* Update and store volume/vnode and parent vnodes back */
2788 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2790 errorCode = CallPostamble(tcon, errorCode, thost);
2792 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2794 #if FS_STATS_DETAILED
2795 TM_GetTimeOfDay(&opStopTime, 0);
2796 if (errorCode == 0) {
2798 (opP->numSuccesses)++;
2799 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2800 fs_stats_AddTo((opP->sumTime), elapsedTime);
2801 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2802 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2803 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2805 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2806 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2810 #endif /* FS_STATS_DETAILED */
2813 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2814 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2815 AUD_ID, t_client ? t_client->ViceId : 0,
2816 AUD_FIDS, Fids, AUD_END);
2819 } /*SRXAFS_InlineBulkStatus */
2823 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2824 struct AFSFetchStatus * OutStatus,
2825 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2828 struct rx_connection *tcon;
2830 struct client *t_client = NULL; /* tmp ptr to client data */
2831 #if FS_STATS_DETAILED
2832 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2833 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2834 struct timeval elapsedTime; /* Transfer time */
2837 * Set our stats pointer, remember when the RPC operation started, and
2838 * tally the operation.
2840 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2844 TM_GetTimeOfDay(&opStartTime, 0);
2845 #endif /* FS_STATS_DETAILED */
2847 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2848 goto Bad_FetchStatus;
2850 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2853 code = CallPostamble(tcon, code, thost);
2855 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2857 #if FS_STATS_DETAILED
2858 TM_GetTimeOfDay(&opStopTime, 0);
2861 (opP->numSuccesses)++;
2862 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2863 fs_stats_AddTo((opP->sumTime), elapsedTime);
2864 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2865 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2866 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2868 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2869 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2873 #endif /* FS_STATS_DETAILED */
2875 osi_auditU(acall, FetchStatusEvent, code,
2876 AUD_ID, t_client ? t_client->ViceId : 0,
2877 AUD_FID, Fid, AUD_END);
2880 } /*SRXAFS_FetchStatus */
2884 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2885 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2886 afs_fsize_t Length, afs_fsize_t FileLength,
2887 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2889 Vnode *targetptr = 0; /* pointer to input fid */
2890 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2891 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2892 int errorCode = 0; /* return code for caller */
2893 int fileCode = 0; /* return code from vol package */
2894 Volume *volptr = 0; /* pointer to the volume header */
2895 struct client *client = 0; /* pointer to client structure */
2896 afs_int32 rights, anyrights; /* rights for this and any user */
2897 struct client *t_client = NULL; /* tmp ptr to client data */
2898 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2899 struct rx_connection *tcon;
2901 #if FS_STATS_DETAILED
2902 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2903 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2904 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2905 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2906 struct timeval elapsedTime; /* Transfer time */
2907 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2908 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2909 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2912 * Set our stats pointers, remember when the RPC operation started, and
2913 * tally the operation.
2915 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2916 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2921 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2923 TM_GetTimeOfDay(&opStartTime, 0);
2924 #endif /* FS_STATS_DETAILED */
2927 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2929 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2932 /* Get ptr to client data for user Id for logging */
2933 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2934 logHostAddr.s_addr = rxr_HostOf(tcon);
2936 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2937 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2938 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2941 * Get associated volume/vnode for the stored file; caller's rights
2945 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
2946 &parentwhentargetnotdir, &client, WRITE_LOCK,
2947 &rights, &anyrights))) {
2951 /* set volume synchronization information */
2952 SetVolumeSync(Sync, volptr);
2954 if ((targetptr->disk.type == vSymlink)) {
2955 /* Should we return a better error code here??? */
2960 /* Check if we're allowed to store the data */
2962 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2968 * Drop the read lock on the parent directory after saving the parent
2969 * vnode information we need to pass to GetStatus
2971 if (parentwhentargetnotdir != NULL) {
2972 tparentwhentargetnotdir = *parentwhentargetnotdir;
2973 VPutVnode(&fileCode, parentwhentargetnotdir);
2974 assert(!fileCode || (fileCode == VSALVAGE));
2975 parentwhentargetnotdir = NULL;
2977 #if FS_STATS_DETAILED
2979 * Remember when the data transfer started.
2981 TM_GetTimeOfDay(&xferStartTime, 0);
2982 #endif /* FS_STATS_DETAILED */
2984 /* Do the actual storing of the data */
2985 #if FS_STATS_DETAILED
2987 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2988 FileLength, (InStatus->Mask & AFS_FSYNC),
2989 &bytesToXfer, &bytesXferred);
2992 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2993 FileLength, (InStatus->Mask & AFS_FSYNC));
2994 if (errorCode && (!targetptr->changed_newTime))
2996 #endif /* FS_STATS_DETAILED */
2997 #if FS_STATS_DETAILED
2999 * At this point, the data transfer is done, for good or ill. Remember
3000 * when the transfer ended, bump the number of successes/failures, and
3001 * integrate the transfer size and elapsed time into the stats. If the
3002 * operation failed, we jump to the appropriate point.
3004 TM_GetTimeOfDay(&xferStopTime, 0);
3006 (xferP->numXfers)++;
3008 (xferP->numSuccesses)++;
3011 * Bump the xfer sum by the number of bytes actually sent, NOT the
3014 tot_bytesXferred += bytesXferred;
3015 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3016 tot_bytesXferred &= 0x3FF;
3017 if (bytesXferred < xferP->minBytes)
3018 xferP->minBytes = bytesXferred;
3019 if (bytesXferred > xferP->maxBytes)
3020 xferP->maxBytes = bytesXferred;
3023 * Tally the size of the object. Note: we tally the actual size,
3024 * NOT the number of bytes that made it out over the wire.
3026 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3027 (xferP->count[0])++;
3028 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3029 (xferP->count[1])++;
3030 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3031 (xferP->count[2])++;
3032 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3033 (xferP->count[3])++;
3034 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3035 (xferP->count[4])++;
3036 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3037 (xferP->count[5])++;
3038 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3039 (xferP->count[6])++;
3040 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3041 (xferP->count[7])++;
3043 (xferP->count[8])++;
3045 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3046 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3047 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3048 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3049 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3051 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3052 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3057 * Finally, go off to tell our caller the bad news in case the
3060 if (errorCode && (!targetptr->changed_newTime))
3062 #endif /* FS_STATS_DETAILED */
3064 /* Update the status of the target's vnode */
3065 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3066 targetptr, volptr, 0);
3068 /* Get the updated File's status back to the caller */
3069 GetStatus(targetptr, OutStatus, rights, anyrights,
3070 &tparentwhentargetnotdir);
3073 /* Update and store volume/vnode and parent vnodes back */
3074 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3076 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3078 errorCode = CallPostamble(tcon, errorCode, thost);
3080 #if FS_STATS_DETAILED
3081 TM_GetTimeOfDay(&opStopTime, 0);
3082 if (errorCode == 0) {
3084 (opP->numSuccesses)++;
3085 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3086 fs_stats_AddTo((opP->sumTime), elapsedTime);
3087 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3088 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3089 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3091 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3092 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3096 #endif /* FS_STATS_DETAILED */
3097 osi_auditU(acall, StoreDataEvent, errorCode,
3098 AUD_ID, t_client ? t_client->ViceId : 0,
3099 AUD_FID, Fid, AUD_END);
3101 } /*common_StoreData64 */
3104 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3105 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3106 afs_uint32 Length, afs_uint32 FileLength,
3107 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3109 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3110 (0x7fffffff - Pos) < Length)
3113 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3115 } /*SRXAFS_StoreData */
3118 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3119 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3120 afs_uint64 Length, afs_uint64 FileLength,
3121 struct AFSFetchStatus * OutStatus,
3122 struct AFSVolSync * Sync)
3126 afs_fsize_t tLength;
3127 afs_fsize_t tFileLength;
3129 #ifdef AFS_64BIT_ENV
3130 #ifndef AFS_LARGEFILE_ENV
3131 if (FileLength > 0x7fffffff)
3133 #endif /* !AFS_LARGEFILE_ENV */
3134 tPos = (afs_fsize_t) Pos;
3135 tLength = (afs_fsize_t) Length;
3136 tFileLength = (afs_fsize_t) FileLength;
3137 #else /* AFS_64BIT_ENV */
3138 if (FileLength.high)
3141 tLength = Length.low;
3142 tFileLength = FileLength.low;
3143 #endif /* AFS_64BIT_ENV */
3146 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3152 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3153 struct AFSOpaque * AccessList,
3154 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3156 Vnode *targetptr = 0; /* pointer to input fid */
3157 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3158 int errorCode = 0; /* return code for caller */
3159 struct AFSStoreStatus InStatus; /* Input status for fid */
3160 Volume *volptr = 0; /* pointer to the volume header */
3161 struct client *client = 0; /* pointer to client structure */
3162 afs_int32 rights, anyrights; /* rights for this and any user */
3163 struct rx_connection *tcon;
3165 struct client *t_client = NULL; /* tmp ptr to client data */
3166 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3167 #if FS_STATS_DETAILED
3168 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3169 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3170 struct timeval elapsedTime; /* Transfer time */
3173 * Set our stats pointer, remember when the RPC operation started, and
3174 * tally the operation.
3176 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3180 TM_GetTimeOfDay(&opStartTime, 0);
3181 #endif /* FS_STATS_DETAILED */
3182 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3185 /* Get ptr to client data for user Id for logging */
3186 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3187 logHostAddr.s_addr = rxr_HostOf(tcon);
3189 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3190 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3191 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3193 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3195 InStatus.Mask = 0; /* not storing any status */
3198 * Get associated volume/vnode for the target dir; caller's rights
3199 * are also returned.
3202 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3203 &parentwhentargetnotdir, &client, WRITE_LOCK,
3204 &rights, &anyrights))) {
3208 /* set volume synchronization information */
3209 SetVolumeSync(Sync, volptr);
3211 /* Check if we have permission to change the dir's ACL */
3213 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3218 /* Build and store the new Access List for the dir */
3219 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3223 targetptr->changed_newTime = 1; /* status change of directory */
3225 /* convert the write lock to a read lock before breaking callbacks */
3226 VVnodeWriteToRead(&errorCode, targetptr);
3227 assert(!errorCode || errorCode == VSALVAGE);
3229 /* break call backs on the directory */
3230 BreakCallBack(client->host, Fid, 0);
3232 /* Get the updated dir's status back to the caller */
3233 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3236 /* Update and store volume/vnode and parent vnodes back */
3237 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3239 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3240 errorCode = CallPostamble(tcon, errorCode, thost);
3242 #if FS_STATS_DETAILED
3243 TM_GetTimeOfDay(&opStopTime, 0);
3244 if (errorCode == 0) {
3246 (opP->numSuccesses)++;
3247 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3248 fs_stats_AddTo((opP->sumTime), elapsedTime);
3249 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3250 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3251 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3253 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3254 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3258 #endif /* FS_STATS_DETAILED */
3260 osi_auditU(acall, StoreACLEvent, errorCode,
3261 AUD_ID, t_client ? t_client->ViceId : 0,
3262 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3265 } /*SRXAFS_StoreACL */
3269 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3270 * should be merged when possible.
3273 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3274 struct AFSStoreStatus *InStatus,
3275 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3277 Vnode *targetptr = 0; /* pointer to input fid */
3278 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3279 int errorCode = 0; /* return code for caller */
3280 Volume *volptr = 0; /* pointer to the volume header */
3281 struct client *client = 0; /* pointer to client structure */
3282 afs_int32 rights, anyrights; /* rights for this and any user */
3283 struct client *t_client = NULL; /* tmp ptr to client data */
3284 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3285 struct rx_connection *tcon = rx_ConnectionOf(acall);
3287 /* Get ptr to client data for user Id for logging */
3288 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3289 logHostAddr.s_addr = rxr_HostOf(tcon);
3291 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3292 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3293 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3295 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3298 * Get volume/vnode for the target file; caller's rights to it are
3302 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3303 &parentwhentargetnotdir, &client, WRITE_LOCK,
3304 &rights, &anyrights))) {
3305 goto Bad_StoreStatus;
3308 /* set volume synchronization information */
3309 SetVolumeSync(Sync, volptr);
3311 /* Check if the caller has proper permissions to store status to Fid */
3313 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3315 goto Bad_StoreStatus;
3318 * Check for a symbolic link; we can't chmod these (otherwise could
3319 * change a symlink to a mt pt or vice versa)
3321 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3323 goto Bad_StoreStatus;
3326 /* Update the status of the target's vnode */
3327 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3328 (parentwhentargetnotdir ? parentwhentargetnotdir
3329 : targetptr), volptr, 0);
3331 /* convert the write lock to a read lock before breaking callbacks */
3332 VVnodeWriteToRead(&errorCode, targetptr);
3333 assert(!errorCode || errorCode == VSALVAGE);
3335 /* Break call backs on Fid */
3336 BreakCallBack(client->host, Fid, 0);
3338 /* Return the updated status back to caller */
3339 GetStatus(targetptr, OutStatus, rights, anyrights,
3340 parentwhentargetnotdir);
3343 /* Update and store volume/vnode and parent vnodes back */
3344 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3346 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3349 } /*SAFSS_StoreStatus */
3353 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3354 struct AFSStoreStatus * InStatus,
3355 struct AFSFetchStatus * OutStatus,
3356 struct AFSVolSync * Sync)
3359 struct rx_connection *tcon;
3361 struct client *t_client = NULL; /* tmp ptr to client data */
3362 #if FS_STATS_DETAILED
3363 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3364 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3365 struct timeval elapsedTime; /* Transfer time */
3368 * Set our stats pointer, remember when the RPC operation started, and
3369 * tally the operation.
3371 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3375 TM_GetTimeOfDay(&opStartTime, 0);
3376 #endif /* FS_STATS_DETAILED */
3378 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3379 goto Bad_StoreStatus;
3381 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3384 code = CallPostamble(tcon, code, thost);
3386 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3388 #if FS_STATS_DETAILED
3389 TM_GetTimeOfDay(&opStopTime, 0);
3392 (opP->numSuccesses)++;
3393 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3394 fs_stats_AddTo((opP->sumTime), elapsedTime);
3395 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3396 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3397 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3399 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3400 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3404 #endif /* FS_STATS_DETAILED */
3406 osi_auditU(acall, StoreStatusEvent, code,
3407 AUD_ID, t_client ? t_client->ViceId : 0,
3408 AUD_FID, Fid, AUD_END);
3411 } /*SRXAFS_StoreStatus */
3415 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3416 * merged in when possible.
3419 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3420 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3422 Vnode *parentptr = 0; /* vnode of input Directory */
3423 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3424 Vnode *targetptr = 0; /* file to be deleted */
3425 Volume *volptr = 0; /* pointer to the volume header */
3426 AFSFid fileFid; /* area for Fid from the directory */
3427 int errorCode = 0; /* error code */
3428 DirHandle dir; /* Handle for dir package I/O */
3429 struct client *client = 0; /* pointer to client structure */
3430 afs_int32 rights, anyrights; /* rights for this and any user */
3431 struct client *t_client; /* tmp ptr to client data */
3432 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3433 struct rx_connection *tcon = rx_ConnectionOf(acall);
3436 /* Get ptr to client data for user Id for logging */
3437 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3438 logHostAddr.s_addr = rxr_HostOf(tcon);
3440 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3441 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3442 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3444 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3447 * Get volume/vnode for the parent dir; caller's access rights are
3451 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3452 &parentwhentargetnotdir, &client, WRITE_LOCK,
3453 &rights, &anyrights))) {
3454 goto Bad_RemoveFile;
3456 /* set volume synchronization information */
3457 SetVolumeSync(Sync, volptr);
3459 /* Does the caller has delete (& write) access to the parent directory? */
3460 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3461 goto Bad_RemoveFile;
3464 /* Actually delete the desired file */
3466 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3468 goto Bad_RemoveFile;
3471 /* Update the vnode status of the parent dir */
3472 #if FS_STATS_DETAILED
3473 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3474 parentptr->disk.linkCount,
3475 client->InSameNetwork);
3477 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3478 parentptr->disk.linkCount);
3479 #endif /* FS_STATS_DETAILED */
3481 /* Return the updated parent dir's status back to caller */
3482 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3484 /* Handle internal callback state for the parent and the deleted file */
3485 if (targetptr->disk.linkCount == 0) {
3486 /* no references left, discard entry */
3487 DeleteFileCallBacks(&fileFid);
3488 /* convert the parent lock to a read lock before breaking callbacks */
3489 VVnodeWriteToRead(&errorCode, parentptr);
3490 assert(!errorCode || errorCode == VSALVAGE);
3492 /* convert the parent lock to a read lock before breaking callbacks */
3493 VVnodeWriteToRead(&errorCode, parentptr);
3494 assert(!errorCode || errorCode == VSALVAGE);
3495 /* convert the target lock to a read lock before breaking callbacks */
3496 VVnodeWriteToRead(&errorCode, targetptr);
3497 assert(!errorCode || errorCode == VSALVAGE);
3498 /* tell all the file has changed */
3499 BreakCallBack(client->host, &fileFid, 1);
3502 /* break call back on the directory */
3503 BreakCallBack(client->host, DirFid, 0);
3506 /* Update and store volume/vnode and parent vnodes back */
3507 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3510 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3513 } /*SAFSS_RemoveFile */
3517 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3518 struct AFSFetchStatus * OutDirStatus,
3519 struct AFSVolSync * Sync)
3522 struct rx_connection *tcon;
3524 struct client *t_client = NULL; /* tmp ptr to client data */
3525 #if FS_STATS_DETAILED
3526 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3527 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3528 struct timeval elapsedTime; /* Transfer time */
3531 * Set our stats pointer, remember when the RPC operation started, and
3532 * tally the operation.
3534 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3538 TM_GetTimeOfDay(&opStartTime, 0);
3539 #endif /* FS_STATS_DETAILED */
3541 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3542 goto Bad_RemoveFile;
3544 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3547 code = CallPostamble(tcon, code, thost);
3549 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3551 #if FS_STATS_DETAILED
3552 TM_GetTimeOfDay(&opStopTime, 0);
3555 (opP->numSuccesses)++;
3556 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3557 fs_stats_AddTo((opP->sumTime), elapsedTime);
3558 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3559 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3560 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3562 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3563 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3567 #endif /* FS_STATS_DETAILED */
3569 osi_auditU(acall, RemoveFileEvent, code,
3570 AUD_ID, t_client ? t_client->ViceId : 0,
3571 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3574 } /*SRXAFS_RemoveFile */
3578 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3579 * be merged in when possible.
3582 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3583 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3584 struct AFSFetchStatus *OutFidStatus,
3585 struct AFSFetchStatus *OutDirStatus,
3586 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3588 Vnode *parentptr = 0; /* vnode of input Directory */
3589 Vnode *targetptr = 0; /* vnode of the new file */
3590 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3591 Volume *volptr = 0; /* pointer to the volume header */
3592 int errorCode = 0; /* error code */
3593 DirHandle dir; /* Handle for dir package I/O */
3594 struct client *client = 0; /* pointer to client structure */
3595 afs_int32 rights, anyrights; /* rights for this and any user */
3596 struct client *t_client; /* tmp ptr to client data */
3597 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3598 struct rx_connection *tcon = rx_ConnectionOf(acall);
3602 /* Get ptr to client data for user Id for logging */
3603 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3604 logHostAddr.s_addr = rxr_HostOf(tcon);
3606 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3607 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3608 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3610 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3612 if (!FileNameOK(Name)) {
3614 goto Bad_CreateFile;
3618 * Get associated volume/vnode for the parent dir; caller long are
3622 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3623 &parentwhentargetnotdir, &client, WRITE_LOCK,
3624 &rights, &anyrights))) {
3625 goto Bad_CreateFile;
3628 /* set volume synchronization information */
3629 SetVolumeSync(Sync, volptr);
3631 /* Can we write (and insert) onto the parent directory? */
3632 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3633 goto Bad_CreateFile;
3635 /* get a new vnode for the file to be created and set it up */
3637 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3638 vFile, nBlocks(0)))) {
3639 goto Bad_CreateFile;
3642 /* update the status of the parent vnode */
3643 #if FS_STATS_DETAILED
3644 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3645 parentptr->disk.linkCount,
3646 client->InSameNetwork);
3648 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3649 parentptr->disk.linkCount);
3650 #endif /* FS_STATS_DETAILED */
3652 /* update the status of the new file's vnode */
3653 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3654 parentptr, volptr, 0);
3656 /* 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 */
3657 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3658 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3660 /* convert the write lock to a read lock before breaking callbacks */
3661 VVnodeWriteToRead(&errorCode, parentptr);
3662 assert(!errorCode || errorCode == VSALVAGE);
3664 /* break call back on parent dir */
3665 BreakCallBack(client->host, DirFid, 0);
3667 /* Return a callback promise for the newly created file to the caller */
3668 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3671 /* Update and store volume/vnode and parent vnodes back */
3672 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3675 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3678 } /*SAFSS_CreateFile */
3682 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3683 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3684 struct AFSFetchStatus * OutFidStatus,
3685 struct AFSFetchStatus * OutDirStatus,
3686 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3689 struct rx_connection *tcon;
3691 struct client *t_client = NULL; /* tmp ptr to client data */
3692 #if FS_STATS_DETAILED
3693 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3694 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3695 struct timeval elapsedTime; /* Transfer time */
3698 * Set our stats pointer, remember when the RPC operation started, and
3699 * tally the operation.
3701 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3705 TM_GetTimeOfDay(&opStartTime, 0);
3706 #endif /* FS_STATS_DETAILED */
3708 memset(OutFid, 0, sizeof(struct AFSFid));
3710 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3711 goto Bad_CreateFile;
3714 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3715 OutDirStatus, CallBack, Sync);
3718 code = CallPostamble(tcon, code, thost);
3720 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3722 #if FS_STATS_DETAILED
3723 TM_GetTimeOfDay(&opStopTime, 0);
3726 (opP->numSuccesses)++;
3727 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3728 fs_stats_AddTo((opP->sumTime), elapsedTime);
3729 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3730 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3731 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3733 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3734 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3738 #endif /* FS_STATS_DETAILED */
3740 osi_auditU(acall, CreateFileEvent, code,
3741 AUD_ID, t_client ? t_client->ViceId : 0,
3742 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3745 } /*SRXAFS_CreateFile */
3749 * This routine is called exclusively from SRXAFS_Rename(), and should be
3750 * merged in when possible.
3753 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3754 struct AFSFid *NewDirFid, char *NewName,
3755 struct AFSFetchStatus *OutOldDirStatus,
3756 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3758 Vnode *oldvptr = 0; /* vnode of the old Directory */
3759 Vnode *newvptr = 0; /* vnode of the new Directory */
3760 Vnode *fileptr = 0; /* vnode of the file to move */
3761 Vnode *newfileptr = 0; /* vnode of the file to delete */
3762 Vnode *testvptr = 0; /* used in directory tree walk */
3763 Vnode *parent = 0; /* parent for use in SetAccessList */
3764 int errorCode = 0; /* error code */
3765 int fileCode = 0; /* used when writing Vnodes */
3766 VnodeId testnode; /* used in directory tree walk */
3767 AFSFid fileFid; /* Fid of file to move */
3768 AFSFid newFileFid; /* Fid of new file */
3769 DirHandle olddir; /* Handle for dir package I/O */
3770 DirHandle newdir; /* Handle for dir package I/O */
3771 DirHandle filedir; /* Handle for dir package I/O */
3772 DirHandle newfiledir; /* Handle for dir package I/O */
3773 Volume *volptr = 0; /* pointer to the volume header */
3774 struct client *client = 0; /* pointer to client structure */
3775 afs_int32 rights, anyrights; /* rights for this and any user */
3776 afs_int32 newrights; /* rights for this user */
3777 afs_int32 newanyrights; /* rights for any user */
3778 int doDelete; /* deleted the rename target (ref count now 0) */
3780 struct client *t_client; /* tmp ptr to client data */
3781 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3782 struct rx_connection *tcon = rx_ConnectionOf(acall);
3787 FidZero(&newfiledir);
3789 /* Get ptr to client data for user Id for logging */
3790 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3791 logHostAddr.s_addr = rxr_HostOf(tcon);
3793 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3794 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3795 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3796 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3798 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3800 if (!FileNameOK(NewName)) {
3804 if (OldDirFid->Volume != NewDirFid->Volume) {
3809 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3810 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3811 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3817 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3819 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3820 &parent, &client, WRITE_LOCK, &rights,
3825 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3827 newrights = rights, newanyrights = anyrights;
3830 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3831 MustBeDIR, &parent, &client, WRITE_LOCK,
3832 &newrights, &newanyrights))) {
3838 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3839 &parent, &client, WRITE_LOCK, &newrights,
3845 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3846 &parent, &client, WRITE_LOCK, &rights,
3853 /* set volume synchronization information */
3854 SetVolumeSync(Sync, volptr);
3856 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3859 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3863 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3864 * call to CopyOnWrite returns error, it is not necessary to revert back
3865 * the effects of the first call because the contents of the volume is
3866 * not modified, it is only replicated.
3868 if (oldvptr->disk.cloned) {
3869 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3870 if ((errorCode = CopyOnWrite(oldvptr, volptr)))
3873 SetDirHandle(&olddir, oldvptr);
3874 if (newvptr->disk.cloned) {
3875 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3876 if ((errorCode = CopyOnWrite(newvptr, volptr)))
3880 SetDirHandle(&newdir, newvptr);
3882 /* Lookup the file to delete its vnode */
3883 if (Lookup(&olddir, OldName, &fileFid)) {
3887 if (fileFid.Vnode == oldvptr->vnodeNumber
3888 || fileFid.Vnode == newvptr->vnodeNumber) {
3889 errorCode = FSERR_ELOOP;
3892 fileFid.Volume = V_id(volptr);
3893 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3894 if (errorCode != 0) {
3896 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3897 OldName, errorCode));
3898 VTakeOffline(volptr);
3901 if (fileptr->disk.uniquifier != fileFid.Unique) {
3903 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3905 VTakeOffline(volptr);
3910 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3911 && fileptr->disk.linkCount != 1) {
3913 * Hard links exist to this file - cannot move one of the links to
3914 * a new directory because of AFS restrictions (this is the same
3915 * reason that links cannot be made across directories, i.e.
3922 /* Lookup the new file */
3923 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3924 if (readonlyServer) {
3925 errorCode = VREADONLY;
3928 if (!(newrights & PRSFS_DELETE)) {
3932 if (newFileFid.Vnode == oldvptr->vnodeNumber
3933 || newFileFid.Vnode == newvptr->vnodeNumber
3934 || newFileFid.Vnode == fileFid.Vnode) {
3938 newFileFid.Volume = V_id(volptr);
3940 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3941 if (errorCode != 0) {
3943 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
3944 NewName, errorCode));
3945 VTakeOffline(volptr);
3948 if (fileptr->disk.uniquifier != fileFid.Unique) {
3950 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
3952 VTakeOffline(volptr);
3956 SetDirHandle(&newfiledir, newfileptr);
3957 /* Now check that we're moving directories over directories properly, etc.
3958 * return proper POSIX error codes:
3959 * if fileptr is a file and new is a dir: EISDIR.
3960 * if fileptr is a dir and new is a file: ENOTDIR.
3961 * Also, dir to be removed must be empty, of course.
3963 if (newfileptr->disk.type == vDirectory) {
3964 if (fileptr->disk.type != vDirectory) {
3968 if ((IsEmpty(&newfiledir))) {
3973 if (fileptr->disk.type == vDirectory) {
3974 errorCode = ENOTDIR;
3981 * ok - now we check that the old name is not above new name in the
3982 * directory structure. This is to prevent removing a subtree alltogether
3984 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
3985 afs_int32 forpass = 0, vnum = 0, top = 0;
3986 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
3987 if (testnode > vnum) vnum = testnode;
3988 if (forpass > vnum) {
3989 errorCode = FSERR_ELOOP;
3992 if (testnode == oldvptr->vnodeNumber) {
3993 testnode = oldvptr->disk.parent;
3996 if ((testnode == fileptr->vnodeNumber)
3997 || (testnode == newvptr->vnodeNumber)) {
3998 errorCode = FSERR_ELOOP;
4001 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
4002 errorCode = FSERR_ELOOP;
4005 if (testnode == 1) top = 1;
4006 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
4007 assert(errorCode == 0);
4008 testnode = testvptr->disk.parent;
4009 VPutVnode(&errorCode, testvptr);
4010 if ((top == 1) && (testnode != 0)) {
4011 VTakeOffline(volptr);
4013 ("Volume %u now offline, must be salvaged.\n",
4018 assert(errorCode == 0);
4021 /* Do the CopyonWrite first before modifying anything else. Copying is
4022 * required because we may have to change entries for ..
4024 if ((fileptr->disk.type == vDirectory) && (fileptr->disk.cloned)) {
4025 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
4026 if ((errorCode = CopyOnWrite(fileptr, volptr)))
4030 /* If the new name exists already, delete it and the file it points to */
4033 /* Delete NewName from its directory */
4034 code = Delete(&newdir, NewName);
4037 /* Drop the link count */
4038 newfileptr->disk.linkCount--;
4039 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4040 afs_fsize_t newSize;
4041 VN_GET_LEN(newSize, newfileptr);
4042 VAdjustDiskUsage((Error *) & errorCode, volptr,
4043 (afs_sfsize_t) - nBlocks(newSize), 0);
4044 if (VN_GET_INO(newfileptr)) {
4045 IH_REALLYCLOSE(newfileptr->handle);
4047 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
4048 V_parentId(volptr));
4049 IH_RELEASE(newfileptr->handle);
4050 if (errorCode == -1) {
4052 ("Del: inode=%s, name=%s, errno=%d\n",
4053 PrintInode(NULL, VN_GET_INO(newfileptr)),
4055 if ((errno != ENOENT) && (errno != EIO)
4056 && (errno != ENXIO))
4057 ViceLog(0, ("Do we need to fsck?"));
4060 VN_SET_INO(newfileptr, (Inode) 0);
4061 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4064 /* Link count did not drop to zero.
4065 * Mark NewName vnode as changed - updates stime.
4067 newfileptr->changed_newTime = 1;
4072 * If the create below fails, and the delete above worked, we have
4073 * removed the new name and not replaced it. This is not very likely,
4074 * but possible. We could try to put the old file back, but it is
4075 * highly unlikely that it would work since it would involve issuing
4078 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4081 /* Delete the old name */
4082 assert(Delete(&olddir, (char *)OldName) == 0);
4084 /* if the directory length changes, reflect it in the statistics */
4085 #if FS_STATS_DETAILED
4086 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4087 oldvptr->disk.linkCount, client->InSameNetwork);
4088 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4089 newvptr->disk.linkCount, client->InSameNetwork);
4091 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4092 oldvptr->disk.linkCount);
4093 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4094 newvptr->disk.linkCount);
4095 #endif /* FS_STATS_DETAILED */
4097 if (oldvptr == newvptr)
4098 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4100 fileptr->disk.parent = newvptr->vnodeNumber;
4101 fileptr->changed_newTime = 1; /* status change of moved file */
4103 /* if we are dealing with a rename of a directory */
4104 if (fileptr->disk.type == vDirectory) {
4105 assert(!fileptr->disk.cloned);
4106 SetDirHandle(&filedir, fileptr);
4107 /* fix .. to point to the correct place */
4108 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4109 assert(Create(&filedir, "..", NewDirFid) == 0);
4110 fileptr->disk.dataVersion++;
4111 /* if the parent directories are different the link counts have to be */
4112 /* changed due to .. in the renamed directory */
4113 if (oldvptr != newvptr) {
4114 oldvptr->disk.linkCount--;
4115 newvptr->disk.linkCount++;
4119 /* set up return status */
4120 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4121 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4122 if (newfileptr && doDelete) {
4123 DeleteFileCallBacks(&newFileFid); /* no other references */
4128 /* convert the write locks to a read locks before breaking callbacks */
4129 VVnodeWriteToRead(&errorCode, newvptr);
4130 assert(!errorCode || errorCode == VSALVAGE);
4131 if (oldvptr != newvptr) {
4132 VVnodeWriteToRead(&errorCode, oldvptr);
4133 assert(!errorCode || errorCode == VSALVAGE);
4135 if (newfileptr && !doDelete) {
4136 /* convert the write lock to a read lock before breaking callbacks */
4137 VVnodeWriteToRead(&errorCode, newfileptr);
4138 assert(!errorCode || errorCode == VSALVAGE);
4141 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4142 BreakCallBack(client->host, NewDirFid, 0);
4143 if (oldvptr != newvptr) {
4144 BreakCallBack(client->host, OldDirFid, 0);
4145 if (fileptr->disk.type == vDirectory) /* if a dir moved, .. changed */
4146 BreakCallBack(client->host, &fileFid, 0);
4149 /* Note: it is not necessary to break the callback */
4151 DeleteFileCallBacks(&newFileFid); /* no other references */
4153 /* other's still exist (with wrong link count) */
4154 BreakCallBack(client->host, &newFileFid, 1);
4159 VPutVnode(&fileCode, newfileptr);
4160 assert(fileCode == 0);
4162 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
4163 newvptr : 0), oldvptr, volptr, &client);
4167 FidZap(&newfiledir);
4168 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4175 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4176 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4177 struct AFSFetchStatus * OutOldDirStatus,
4178 struct AFSFetchStatus * OutNewDirStatus,
4179 struct AFSVolSync * Sync)
4182 struct rx_connection *tcon;
4184 struct client *t_client = NULL; /* tmp ptr to client data */
4185 #if FS_STATS_DETAILED
4186 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4187 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4188 struct timeval elapsedTime; /* Transfer time */
4191 * Set our stats pointer, remember when the RPC operation started, and
4192 * tally the operation.
4194 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4198 TM_GetTimeOfDay(&opStartTime, 0);
4199 #endif /* FS_STATS_DETAILED */
4201 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4205 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4206 OutOldDirStatus, OutNewDirStatus, Sync);
4209 code = CallPostamble(tcon, code, thost);
4211 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4213 #if FS_STATS_DETAILED
4214 TM_GetTimeOfDay(&opStopTime, 0);
4217 (opP->numSuccesses)++;
4218 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4219 fs_stats_AddTo((opP->sumTime), elapsedTime);
4220 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4221 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4222 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4224 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4225 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4229 #endif /* FS_STATS_DETAILED */
4231 osi_auditU(acall, RenameFileEvent, code,
4232 AUD_ID, t_client ? t_client->ViceId : 0,
4233 AUD_FID, OldDirFid, AUD_STR, OldName,
4234 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4237 } /*SRXAFS_Rename */
4241 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4242 * merged into it when possible.
4245 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4246 char *LinkContents, struct AFSStoreStatus *InStatus,
4247 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4248 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4250 Vnode *parentptr = 0; /* vnode of input Directory */
4251 Vnode *targetptr = 0; /* vnode of the new link */
4252 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4253 int errorCode = 0; /* error code */
4255 DirHandle dir; /* Handle for dir package I/O */
4256 Volume *volptr = 0; /* pointer to the volume header */
4257 struct client *client = 0; /* pointer to client structure */
4258 afs_int32 rights, anyrights; /* rights for this and any user */
4259 struct client *t_client; /* tmp ptr to client data */
4260 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4262 struct rx_connection *tcon = rx_ConnectionOf(acall);
4266 /* Get ptr to client data for user Id for logging */
4267 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4268 logHostAddr.s_addr = rxr_HostOf(tcon);
4270 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4271 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4272 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4274 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4276 if (!FileNameOK(Name)) {
4282 * Get the vnode and volume for the parent dir along with the caller's
4286 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4287 &parentwhentargetnotdir, &client, WRITE_LOCK,
4288 &rights, &anyrights))) {
4292 /* set volume synchronization information */
4293 SetVolumeSync(Sync, volptr);
4295 /* Does the caller has insert (and write) access to the parent directory? */
4296 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4301 * If we're creating a mount point (any x bits clear), we must have
4302 * administer access to the directory, too. Always allow sysadmins
4305 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4306 if (readonlyServer) {
4307 errorCode = VREADONLY;
4311 * We have a mountpoint, 'cause we're trying to set the Unix mode
4312 * bits to something with some x bits missing (default mode bits
4313 * if AFS_SETMODE is false is 0777)
4315 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4321 /* get a new vnode for the symlink and set it up */
4323 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4324 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4328 /* update the status of the parent vnode */
4329 #if FS_STATS_DETAILED
4330 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4331 parentptr->disk.linkCount,
4332 client->InSameNetwork);
4334 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4335 parentptr->disk.linkCount);
4336 #endif /* FS_STATS_DETAILED */
4338 /* update the status of the new symbolic link file vnode */
4339 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4340 parentptr, volptr, strlen((char *)LinkContents));
4342 /* Write the contents of the symbolic link name into the target inode */
4343 fdP = IH_OPEN(targetptr->handle);
4345 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4347 VTakeOffline(volptr);
4348 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
4352 len = strlen((char *) LinkContents);
4353 code = (len == FDH_WRITE(fdP, (char *) LinkContents, len)) ? 0 : VDISKFULL;
4355 ViceLog(0, ("SAFSS_Symlink FDH_WRITE failed for len=%d, Fid=%u.%d.%d\n", len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4358 * Set up and return modified status for the parent dir and new symlink
4361 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4362 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4364 /* convert the write lock to a read lock before breaking callbacks */
4365 VVnodeWriteToRead(&errorCode, parentptr);
4366 assert(!errorCode || errorCode == VSALVAGE);
4368 /* break call back on the parent dir */
4369 BreakCallBack(client->host, DirFid, 0);
4372 /* Write the all modified vnodes (parent, new files) and volume back */
4373 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4376 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4377 return ( errorCode ? errorCode : code );
4379 } /*SAFSS_Symlink */
4383 SRXAFS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4384 OutFidStatus, OutDirStatus, Sync)
4385 struct AFSVolSync *Sync;
4386 struct rx_call *acall; /* Rx call */
4387 struct AFSFid *DirFid; /* Parent dir's fid */
4388 char *Name; /* File name to create */
4389 char *LinkContents; /* Contents of the new created file */
4390 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
4391 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
4392 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
4393 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
4397 struct rx_connection *tcon;
4399 struct client *t_client = NULL; /* tmp ptr to client data */
4400 #if FS_STATS_DETAILED
4401 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4402 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4403 struct timeval elapsedTime; /* Transfer time */
4406 * Set our stats pointer, remember when the RPC operation started, and
4407 * tally the operation.
4409 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4413 TM_GetTimeOfDay(&opStartTime, 0);
4414 #endif /* FS_STATS_DETAILED */
4416 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4420 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4421 OutFidStatus, OutDirStatus, Sync);
4424 code = CallPostamble(tcon, code, thost);
4426 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4428 #if FS_STATS_DETAILED
4429 TM_GetTimeOfDay(&opStopTime, 0);
4432 (opP->numSuccesses)++;
4433 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4434 fs_stats_AddTo((opP->sumTime), elapsedTime);
4435 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4436 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4437 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4439 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4440 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4444 #endif /* FS_STATS_DETAILED */
4446 osi_auditU(acall, SymlinkEvent, code,
4447 AUD_ID, t_client ? t_client->ViceId : 0,
4448 AUD_FID, DirFid, AUD_STR, Name,
4449 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4452 } /*SRXAFS_Symlink */
4456 * This routine is called exclusively by SRXAFS_Link(), and should be
4457 * merged into it when possible.
4460 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4461 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4462 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4464 Vnode *parentptr = 0; /* vnode of input Directory */
4465 Vnode *targetptr = 0; /* vnode of the new file */
4466 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4467 Volume *volptr = 0; /* pointer to the volume header */
4468 int errorCode = 0; /* error code */
4469 DirHandle dir; /* Handle for dir package I/O */
4470 struct client *client = 0; /* pointer to client structure */
4471 afs_int32 rights, anyrights; /* rights for this and any user */
4472 struct client *t_client; /* tmp ptr to client data */
4473 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4474 struct rx_connection *tcon = rx_ConnectionOf(acall);
4478 /* Get ptr to client data for user Id for logging */
4479 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4480 logHostAddr.s_addr = rxr_HostOf(tcon);
4482 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4483 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4484 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4485 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4487 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4489 if (DirFid->Volume != ExistingFid->Volume) {
4493 if (!FileNameOK(Name)) {
4499 * Get the vnode and volume for the parent dir along with the caller's
4503 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4504 &parentwhentargetnotdir, &client, WRITE_LOCK,
4505 &rights, &anyrights))) {
4509 /* set volume synchronization information */
4510 SetVolumeSync(Sync, volptr);
4512 /* Can the caller insert into the parent directory? */
4513 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4517 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4518 /* AFS fileservers always have directory vnodes that are odd. */
4523 /* get the file vnode */
4525 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4528 if (targetptr->disk.type != vFile) {
4532 if (targetptr->disk.parent != DirFid->Vnode) {
4536 if (parentptr->disk.cloned) {
4537 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4538 if ((errorCode = CopyOnWrite(parentptr, volptr)))
4539 goto Bad_Link; /* disk full error */
4542 /* add the name to the directory */
4543 SetDirHandle(&dir, parentptr);
4544 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4548 /* update the status in the parent vnode */
4549 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4550 #if FS_STATS_DETAILED
4551 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4552 parentptr->disk.linkCount,
4553 client->InSameNetwork);
4555 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4556 parentptr->disk.linkCount);
4557 #endif /* FS_STATS_DETAILED */
4559 targetptr->disk.linkCount++;
4560 targetptr->disk.author = client->ViceId;
4561 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4563 /* set up return status */
4564 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4565 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4567 /* convert the write locks to read locks before breaking callbacks */
4568 VVnodeWriteToRead(&errorCode, targetptr);
4569 assert(!errorCode || errorCode == VSALVAGE);
4570 VVnodeWriteToRead(&errorCode, parentptr);
4571 assert(!errorCode || errorCode == VSALVAGE);
4573 /* break call back on DirFid */
4574 BreakCallBack(client->host, DirFid, 0);
4576 * We also need to break the callback for the file that is hard-linked since part
4577 * of its status (like linkcount) is changed
4579 BreakCallBack(client->host, ExistingFid, 0);
4582 /* Write the all modified vnodes (parent, new files) and volume back */
4583 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4586 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4593 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4594 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4595 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4598 struct rx_connection *tcon;
4600 struct client *t_client = NULL; /* tmp ptr to client data */
4601 #if FS_STATS_DETAILED
4602 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4603 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4604 struct timeval elapsedTime; /* Transfer time */
4607 * Set our stats pointer, remember when the RPC operation started, and
4608 * tally the operation.
4610 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4614 TM_GetTimeOfDay(&opStartTime, 0);
4615 #endif /* FS_STATS_DETAILED */
4617 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4621 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4622 OutDirStatus, Sync);
4625 code = CallPostamble(tcon, code, thost);
4627 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4629 #if FS_STATS_DETAILED
4630 TM_GetTimeOfDay(&opStopTime, 0);
4633 (opP->numSuccesses)++;
4634 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4635 fs_stats_AddTo((opP->sumTime), elapsedTime);
4636 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4637 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4638 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4640 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4641 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4645 #endif /* FS_STATS_DETAILED */
4647 osi_auditU(acall, LinkEvent, code,
4648 AUD_ID, t_client ? t_client->ViceId : 0,
4649 AUD_FID, DirFid, AUD_STR, Name,
4650 AUD_FID, ExistingFid, AUD_END);
4657 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4658 * merged into it when possible.
4661 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4662 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4663 struct AFSFetchStatus *OutFidStatus,
4664 struct AFSFetchStatus *OutDirStatus,
4665 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4667 Vnode *parentptr = 0; /* vnode of input Directory */
4668 Vnode *targetptr = 0; /* vnode of the new file */
4669 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4670 Volume *volptr = 0; /* pointer to the volume header */
4671 int errorCode = 0; /* error code */
4672 struct acl_accessList *newACL; /* Access list */
4673 int newACLSize; /* Size of access list */
4674 DirHandle dir; /* Handle for dir package I/O */
4675 DirHandle parentdir; /* Handle for dir package I/O */
4676 struct client *client = 0; /* pointer to client structure */
4677 afs_int32 rights, anyrights; /* rights for this and any user */
4678 struct client *t_client; /* tmp ptr to client data */
4679 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4680 struct rx_connection *tcon = rx_ConnectionOf(acall);
4683 FidZero(&parentdir);
4685 /* Get ptr to client data for user Id for logging */
4686 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4687 logHostAddr.s_addr = rxr_HostOf(tcon);
4689 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4690 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4691 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4693 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4695 if (!FileNameOK(Name)) {
4701 * Get the vnode and volume for the parent dir along with the caller's
4705 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4706 &parentwhentargetnotdir, &client, WRITE_LOCK,
4707 &rights, &anyrights))) {
4711 /* set volume synchronization information */
4712 SetVolumeSync(Sync, volptr);
4714 /* Write access to the parent directory? */
4715 #ifdef DIRCREATE_NEED_WRITE
4717 * requires w access for the user to create a directory. this
4718 * closes a loophole in the current security arrangement, since a
4719 * user with i access only can create a directory and get the
4720 * implcit a access that goes with dir ownership, and proceed to
4721 * subvert quota in the volume.
4723 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4724 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4726 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4727 #endif /* DIRCREATE_NEED_WRITE */
4730 #define EMPTYDIRBLOCKS 2
4731 /* get a new vnode and set it up */
4733 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4734 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4738 /* Update the status for the parent dir */
4739 #if FS_STATS_DETAILED
4740 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4741 parentptr->disk.linkCount + 1,
4742 client->InSameNetwork);
4744 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4745 parentptr->disk.linkCount + 1);
4746 #endif /* FS_STATS_DETAILED */
4748 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4749 assert((SetAccessList
4750 (&targetptr, &volptr, &newACL, &newACLSize,
4751 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4752 assert(parentwhentargetnotdir == 0);
4753 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4755 /* update the status for the target vnode */
4756 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4757 parentptr, volptr, 0);
4759 /* Actually create the New directory in the directory package */
4760 SetDirHandle(&dir, targetptr);
4761 assert(!(MakeDir(&dir, OutFid, DirFid)));
4763 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4765 /* set up return status */
4766 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4767 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4769 /* convert the write lock to a read lock before breaking callbacks */
4770 VVnodeWriteToRead(&errorCode, parentptr);
4771 assert(!errorCode || errorCode == VSALVAGE);
4773 /* break call back on DirFid */
4774 BreakCallBack(client->host, DirFid, 0);
4776 /* Return a callback promise to caller */
4777 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4780 /* Write the all modified vnodes (parent, new files) and volume back */
4781 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4785 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4788 } /*SAFSS_MakeDir */
4792 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4793 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4794 struct AFSFetchStatus * OutFidStatus,
4795 struct AFSFetchStatus * OutDirStatus,
4796 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4799 struct rx_connection *tcon;
4801 struct client *t_client = NULL; /* tmp ptr to client data */
4802 #if FS_STATS_DETAILED
4803 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4804 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4805 struct timeval elapsedTime; /* Transfer time */
4808 * Set our stats pointer, remember when the RPC operation started, and
4809 * tally the operation.
4811 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
4815 TM_GetTimeOfDay(&opStartTime, 0);
4816 #endif /* FS_STATS_DETAILED */
4817 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4821 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4822 OutDirStatus, CallBack, Sync);
4825 code = CallPostamble(tcon, code, thost);
4827 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4829 #if FS_STATS_DETAILED
4830 TM_GetTimeOfDay(&opStopTime, 0);
4833 (opP->numSuccesses)++;
4834 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4835 fs_stats_AddTo((opP->sumTime), elapsedTime);
4836 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4837 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4838 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4840 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4841 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4845 #endif /* FS_STATS_DETAILED */
4847 osi_auditU(acall, MakeDirEvent, code,
4848 AUD_ID, t_client ? t_client->ViceId : 0,
4849 AUD_FID, DirFid, AUD_STR, Name,
4850 AUD_FID, OutFid, AUD_END);
4853 } /*SRXAFS_MakeDir */
4857 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4858 * merged into it when possible.
4861 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4862 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4864 Vnode *parentptr = 0; /* vnode of input Directory */
4865 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4866 Vnode *targetptr = 0; /* file to be deleted */
4867 AFSFid fileFid; /* area for Fid from the directory */
4868 int errorCode = 0; /* error code */
4869 DirHandle dir; /* Handle for dir package I/O */
4870 Volume *volptr = 0; /* pointer to the volume header */
4871 struct client *client = 0; /* pointer to client structure */
4872 afs_int32 rights, anyrights; /* rights for this and any user */
4873 Vnode debugvnode1, debugvnode2;
4874 struct client *t_client; /* tmp ptr to client data */
4875 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4876 struct rx_connection *tcon = rx_ConnectionOf(acall);
4880 /* Get ptr to client data for user Id for logging */
4881 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4882 logHostAddr.s_addr = rxr_HostOf(tcon);
4884 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4885 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4886 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4888 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4891 * Get the vnode and volume for the parent dir along with the caller's
4895 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4896 &parentwhentargetnotdir, &client, WRITE_LOCK,
4897 &rights, &anyrights))) {
4900 debugvnode1 = *parentptr;
4902 /* set volume synchronization information */
4903 SetVolumeSync(Sync, volptr);
4905 /* Does the caller has delete (&write) access to the parent dir? */
4906 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
4910 debugvnode2 = *parentptr;
4911 /* Do the actual delete of the desired (empty) directory, Name */
4913 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
4918 /* Update the status for the parent dir; link count is also adjusted */
4919 #if FS_STATS_DETAILED
4920 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4921 parentptr->disk.linkCount - 1,
4922 client->InSameNetwork);
4924 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4925 parentptr->disk.linkCount - 1);
4926 #endif /* FS_STATS_DETAILED */
4928 /* Return to the caller the updated parent dir status */
4929 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4932 * Note: it is not necessary to break the callback on fileFid, since
4933 * refcount is now 0, so no one should be able to refer to the dir
4936 DeleteFileCallBacks(&fileFid);
4938 /* convert the write lock to a read lock before breaking callbacks */
4939 VVnodeWriteToRead(&errorCode, parentptr);
4940 assert(!errorCode || errorCode == VSALVAGE);
4942 /* break call back on DirFid and fileFid */
4943 BreakCallBack(client->host, DirFid, 0);
4946 /* Write the all modified vnodes (parent, new files) and volume back */
4947 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4950 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
4953 } /*SAFSS_RemoveDir */
4957 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4958 struct AFSFetchStatus * OutDirStatus,
4959 struct AFSVolSync * Sync)
4962 struct rx_connection *tcon;
4964 struct client *t_client = NULL; /* tmp ptr to client data */
4965 #if FS_STATS_DETAILED
4966 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4967 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4968 struct timeval elapsedTime; /* Transfer time */
4971 * Set our stats pointer, remember when the RPC operation started, and
4972 * tally the operation.
4974 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
4978 TM_GetTimeOfDay(&opStartTime, 0);
4979 #endif /* FS_STATS_DETAILED */
4981 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4984 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
4987 code = CallPostamble(tcon, code, thost);
4989 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4991 #if FS_STATS_DETAILED
4992 TM_GetTimeOfDay(&opStopTime, 0);
4995 (opP->numSuccesses)++;
4996 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4997 fs_stats_AddTo((opP->sumTime), elapsedTime);
4998 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4999 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5000 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5002 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5003 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5007 #endif /* FS_STATS_DETAILED */
5009 osi_auditU(acall, RemoveDirEvent, code,
5010 AUD_ID, t_client ? t_client->ViceId : 0,
5011 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
5014 } /*SRXAFS_RemoveDir */
5018 * This routine is called exclusively by SRXAFS_SetLock(), and should be
5019 * merged into it when possible.
5022 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
5023 struct AFSVolSync *Sync)
5025 Vnode *targetptr = 0; /* vnode of input file */
5026 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5027 int errorCode = 0; /* error code */
5028 Volume *volptr = 0; /* pointer to the volume header */
5029 struct client *client = 0; /* pointer to client structure */
5030 afs_int32 rights, anyrights; /* rights for this and any user */
5031 struct client *t_client; /* tmp ptr to client data */
5032 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5033 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
5034 struct rx_connection *tcon = rx_ConnectionOf(acall);
5036 if (type != LockRead && type != LockWrite) {
5040 /* Get ptr to client data for user Id for logging */
5041 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5042 logHostAddr.s_addr = rxr_HostOf(tcon);
5044 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
5045 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
5046 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5048 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
5051 * Get the vnode and volume for the desired file along with the caller's
5055 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5056 &parentwhentargetnotdir, &client, WRITE_LOCK,
5057 &rights, &anyrights))) {
5061 /* set volume synchronization information */
5062 SetVolumeSync(Sync, volptr);
5064 /* Handle the particular type of set locking, type */
5065 errorCode = HandleLocking(targetptr, client, rights, type);
5068 /* Write the all modified vnodes (parent, new files) and volume back */
5069 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5072 if ((errorCode == VREADONLY) && (type == LockRead))
5073 errorCode = 0; /* allow read locks on RO volumes without saving state */
5075 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
5078 } /*SAFSS_SetLock */
5082 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
5083 ViceLockType type, struct AFSVolSync * Sync)
5085 return SRXAFS_SetLock(acall, Fid, type, Sync);
5086 } /*SRXAFS_OldSetLock */
5090 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
5091 struct AFSVolSync * Sync)
5094 struct rx_connection *tcon;
5096 struct client *t_client = NULL; /* tmp ptr to client data */
5097 #if FS_STATS_DETAILED
5098 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5099 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5100 struct timeval elapsedTime; /* Transfer time */
5103 * Set our stats pointer, remember when the RPC operation started, and
5104 * tally the operation.
5106 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5110 TM_GetTimeOfDay(&opStartTime, 0);
5111 #endif /* FS_STATS_DETAILED */
5113 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5116 code = SAFSS_SetLock(acall, Fid, type, Sync);
5119 code = CallPostamble(tcon, code, thost);
5121 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5123 #if FS_STATS_DETAILED
5124 TM_GetTimeOfDay(&opStopTime, 0);
5127 (opP->numSuccesses)++;
5128 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5129 fs_stats_AddTo((opP->sumTime), elapsedTime);
5130 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5131 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5132 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5134 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5135 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5139 #endif /* FS_STATS_DETAILED */
5141 osi_auditU(acall, SetLockEvent, code,
5142 AUD_ID, t_client ? t_client->ViceId : 0,
5143 AUD_FID, Fid, AUD_LONG, type, AUD_END);
5145 } /*SRXAFS_SetLock */
5149 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5150 * merged into it when possible.
5153 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5154 struct AFSVolSync *Sync)
5156 Vnode *targetptr = 0; /* vnode of input file */
5157 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5158 int errorCode = 0; /* error code */
5159 Volume *volptr = 0; /* pointer to the volume header */
5160 struct client *client = 0; /* pointer to client structure */
5161 afs_int32 rights, anyrights; /* rights for this and any user */
5162 struct client *t_client; /* tmp ptr to client data */
5163 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5164 struct rx_connection *tcon = rx_ConnectionOf(acall);
5166 /* Get ptr to client data for user Id for logging */
5167 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5168 logHostAddr.s_addr = rxr_HostOf(tcon);
5170 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5171 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5172 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5174 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5177 * Get the vnode and volume for the desired file along with the caller's
5181 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5182 &parentwhentargetnotdir, &client, WRITE_LOCK,
5183 &rights, &anyrights))) {
5184 goto Bad_ExtendLock;
5187 /* set volume synchronization information */
5188 SetVolumeSync(Sync, volptr);
5190 /* Handle the actual lock extension */
5191 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
5194 /* Put back file's vnode and volume */
5195 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5198 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5199 errorCode = 0; /* under our generous policy re RO vols */
5201 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5204 } /*SAFSS_ExtendLock */
5208 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5209 struct AFSVolSync * Sync)
5211 return SRXAFS_ExtendLock(acall, Fid, Sync);
5212 } /*SRXAFS_OldExtendLock */
5216 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5217 struct AFSVolSync * Sync)
5220 struct rx_connection *tcon;
5222 struct client *t_client = NULL; /* tmp ptr to client data */
5223 #if FS_STATS_DETAILED
5224 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5225 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5226 struct timeval elapsedTime; /* Transfer time */
5229 * Set our stats pointer, remember when the RPC operation started, and
5230 * tally the operation.
5232 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5236 TM_GetTimeOfDay(&opStartTime, 0);
5237 #endif /* FS_STATS_DETAILED */
5239 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5240 goto Bad_ExtendLock;
5242 code = SAFSS_ExtendLock(acall, Fid, Sync);
5245 code = CallPostamble(tcon, code, thost);
5247 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5249 #if FS_STATS_DETAILED
5250 TM_GetTimeOfDay(&opStopTime, 0);
5253 (opP->numSuccesses)++;
5254 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5255 fs_stats_AddTo((opP->sumTime), elapsedTime);
5256 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5257 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5258 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5260 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5261 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5265 #endif /* FS_STATS_DETAILED */
5267 osi_auditU(acall, ExtendLockEvent, code,
5268 AUD_ID, t_client ? t_client->ViceId : 0,
5269 AUD_FID, Fid, AUD_END);
5272 } /*SRXAFS_ExtendLock */
5276 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5277 * merged into it when possible.
5280 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5281 struct AFSVolSync *Sync)
5283 Vnode *targetptr = 0; /* vnode of input file */
5284 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5285 int errorCode = 0; /* error code */
5286 Volume *volptr = 0; /* pointer to the volume header */
5287 struct client *client = 0; /* pointer to client structure */
5288 afs_int32 rights, anyrights; /* rights for this and any user */
5289 struct client *t_client; /* tmp ptr to client data */
5290 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5291 struct rx_connection *tcon = rx_ConnectionOf(acall);
5293 /* Get ptr to client data for user Id for logging */
5294 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5295 logHostAddr.s_addr = rxr_HostOf(tcon);
5297 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5298 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5299 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5301 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5304 * Get the vnode and volume for the desired file along with the caller's
5308 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5309 &parentwhentargetnotdir, &client, WRITE_LOCK,
5310 &rights, &anyrights))) {
5311 goto Bad_ReleaseLock;
5314 /* set volume synchronization information */
5315 SetVolumeSync(Sync, volptr);
5317 /* Handle the actual lock release */
5318 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
5319 goto Bad_ReleaseLock;
5321 /* if no more locks left, a callback would be triggered here */
5322 if (targetptr->disk.lock.lockCount <= 0) {
5323 /* convert the write lock to a read lock before breaking callbacks */
5324 VVnodeWriteToRead(&errorCode, targetptr);
5325 assert(!errorCode || errorCode == VSALVAGE);
5326 BreakCallBack(client->host, Fid, 0);
5330 /* Put back file's vnode and volume */
5331 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5334 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5335 errorCode = 0; /* under our generous policy re RO vols */
5337 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5340 } /*SAFSS_ReleaseLock */
5344 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5345 struct AFSVolSync * Sync)
5347 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5348 } /*SRXAFS_OldReleaseLock */
5352 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5353 struct AFSVolSync * Sync)
5356 struct rx_connection *tcon;
5358 struct client *t_client = NULL; /* tmp ptr to client data */
5359 #if FS_STATS_DETAILED
5360 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5361 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5362 struct timeval elapsedTime; /* Transfer time */
5365 * Set our stats pointer, remember when the RPC operation started, and
5366 * tally the operation.
5368 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5372 TM_GetTimeOfDay(&opStartTime, 0);
5373 #endif /* FS_STATS_DETAILED */
5375 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5376 goto Bad_ReleaseLock;
5378 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5381 code = CallPostamble(tcon, code, thost);
5383 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5385 #if FS_STATS_DETAILED
5386 TM_GetTimeOfDay(&opStopTime, 0);
5389 (opP->numSuccesses)++;
5390 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5391 fs_stats_AddTo((opP->sumTime), elapsedTime);
5392 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5393 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5394 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5396 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5397 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5401 #endif /* FS_STATS_DETAILED */
5403 osi_auditU(acall, ReleaseLockEvent, code,
5404 AUD_ID, t_client ? t_client->ViceId : 0,
5405 AUD_FID, Fid, AUD_END);
5408 } /*SRXAFS_ReleaseLock */
5412 SetSystemStats(struct AFSStatistics *stats)
5414 /* Fix this sometime soon.. */
5415 /* Because hey, it's not like we have a network monitoring protocol... */
5416 struct timeval time;
5418 /* this works on all system types */
5419 TM_GetTimeOfDay(&time, 0);
5420 stats->CurrentTime = time.tv_sec;
5421 } /*SetSystemStats */
5424 SetAFSStats(struct AFSStatistics *stats)
5426 extern afs_int32 StartTime, CurrentConnections;
5430 stats->CurrentMsgNumber = 0;
5431 stats->OldestMsgNumber = 0;
5432 stats->StartTime = StartTime;
5433 stats->CurrentConnections = CurrentConnections;
5434 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5435 stats->TotalFetchs =
5436 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5437 AFSCallStats.FetchStatus;
5438 stats->FetchDatas = AFSCallStats.FetchData;
5439 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5440 seconds = AFSCallStats.AccumFetchTime / 1000;
5443 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5444 stats->TotalStores =
5445 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5446 AFSCallStats.StoreStatus;
5447 stats->StoreDatas = AFSCallStats.StoreData;
5448 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5449 seconds = AFSCallStats.AccumStoreTime / 1000;
5452 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5454 stats->ProcessSize = -1; /* TODO: */
5456 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5459 h_GetWorkStats((int *)&(stats->WorkStations),
5460 (int *)&(stats->ActiveWorkStations), (int *)0,
5461 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5465 /* Get disk related information from all AFS partitions. */
5468 SetVolumeStats(struct AFSStatistics *stats)
5470 struct DiskPartition64 *part;
5473 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5474 part = part->next) {
5475 stats->Disks[i].TotalBlocks = RoundInt64ToInt32(part->totalUsable);
5476 stats->Disks[i].BlocksAvailable = RoundInt64ToInt32(part->free);
5477 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5478 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5481 while (i < AFS_MSTATDISKS) {
5482 stats->Disks[i].TotalBlocks = -1;
5485 } /*SetVolumeStats */
5488 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5491 struct rx_connection *tcon = rx_ConnectionOf(acall);
5493 struct client *t_client = NULL; /* tmp ptr to client data */
5494 #if FS_STATS_DETAILED
5495 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5496 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5497 struct timeval elapsedTime; /* Transfer time */
5500 * Set our stats pointer, remember when the RPC operation started, and
5501 * tally the operation.
5503 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5507 TM_GetTimeOfDay(&opStartTime, 0);
5508 #endif /* FS_STATS_DETAILED */
5510 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5511 goto Bad_GetStatistics;
5513 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5515 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5517 memset(Statistics, 0, sizeof(*Statistics));
5518 SetAFSStats((struct AFSStatistics *)Statistics);
5519 SetVolumeStats((struct AFSStatistics *)Statistics);
5520 SetSystemStats((struct AFSStatistics *)Statistics);
5523 code = CallPostamble(tcon, code, thost);
5525 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5527 #if FS_STATS_DETAILED
5528 TM_GetTimeOfDay(&opStopTime, 0);
5531 (opP->numSuccesses)++;
5532 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5533 fs_stats_AddTo((opP->sumTime), elapsedTime);
5534 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5535 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5536 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5538 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5539 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5543 #endif /* FS_STATS_DETAILED */
5545 osi_auditU(acall, GetStatisticsEvent, code,
5546 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5548 } /*SRXAFS_GetStatistics */
5552 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5554 extern afs_int32 StartTime, CurrentConnections;
5557 struct rx_connection *tcon = rx_ConnectionOf(acall);
5559 struct client *t_client = NULL; /* tmp ptr to client data */
5560 struct timeval time;
5561 #if FS_STATS_DETAILED
5562 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5563 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5564 struct timeval elapsedTime; /* Transfer time */
5567 * Set our stats pointer, remember when the RPC operation started, and
5568 * tally the operation.
5570 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5574 TM_GetTimeOfDay(&opStartTime, 0);
5575 #endif /* FS_STATS_DETAILED */
5577 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5578 goto Bad_GetStatistics64;
5580 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5581 Statistics->ViceStatistics64_val =
5582 malloc(statsVersion*sizeof(afs_int64));
5583 Statistics->ViceStatistics64_len = statsVersion;
5585 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5586 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5587 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5589 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5590 AFSCallStats.TotalCalls;
5591 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5592 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5593 AFSCallStats.FetchStatus;
5594 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5595 AFSCallStats.FetchData;
5596 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5597 AFSCallStats.TotalFetchedBytes;
5598 seconds = AFSCallStats.AccumFetchTime / 1000;
5601 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5602 AFSCallStats.TotalFetchedBytes / seconds;
5603 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5604 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5605 AFSCallStats.StoreStatus;
5606 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5607 AFSCallStats.StoreData;
5608 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5609 AFSCallStats.TotalStoredBytes;
5610 seconds = AFSCallStats.AccumStoreTime / 1000;
5613 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5614 AFSCallStats.TotalStoredBytes / seconds;
5616 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = -1;
5618 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] =
5619 (afs_int32) ((long)sbrk(0) >> 10);
5622 h_GetWorkStats((int *)&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5623 (int *)&(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5625 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5629 /* this works on all system types */
5630 TM_GetTimeOfDay(&time, 0);
5631 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
5633 Bad_GetStatistics64:
5634 code = CallPostamble(tcon, code, thost);
5636 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5638 #if FS_STATS_DETAILED
5639 TM_GetTimeOfDay(&opStopTime, 0);
5642 (opP->numSuccesses)++;
5643 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5644 fs_stats_AddTo((opP->sumTime), elapsedTime);
5645 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5646 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5647 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5649 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5650 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5654 #endif /* FS_STATS_DETAILED */
5656 osi_auditU(acall, GetStatisticsEvent, code,
5657 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5659 } /*SRXAFS_GetStatistics */
5662 /*------------------------------------------------------------------------
5663 * EXPORTED SRXAFS_XStatsVersion
5666 * Routine called by the server-side RPC interface to implement
5667 * pulling out the xstat version number for the File Server.
5670 * a_versionP : Ptr to the version number variable to set.
5676 * Nothing interesting.
5680 *------------------------------------------------------------------------*/
5683 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5684 { /*SRXAFS_XStatsVersion */
5686 struct client *t_client = NULL; /* tmp ptr to client data */
5687 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5688 #if FS_STATS_DETAILED
5689 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5690 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5691 struct timeval elapsedTime; /* Transfer time */
5694 * Set our stats pointer, remember when the RPC operation started, and
5695 * tally the operation.
5697 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5701 TM_GetTimeOfDay(&opStartTime, 0);
5702 #endif /* FS_STATS_DETAILED */
5704 *a_versionP = AFS_XSTAT_VERSION;
5706 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5708 #if FS_STATS_DETAILED
5709 TM_GetTimeOfDay(&opStopTime, 0);
5710 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5711 fs_stats_AddTo((opP->sumTime), elapsedTime);
5712 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5713 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5714 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5716 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5717 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5720 (opP->numSuccesses)++;
5722 #endif /* FS_STATS_DETAILED */
5724 osi_auditU(a_call, XStatsVersionEvent, 0,
5725 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5727 } /*SRXAFS_XStatsVersion */
5730 /*------------------------------------------------------------------------
5731 * PRIVATE FillPerfValues
5734 * Routine called to fill a regular performance data structure.
5737 * a_perfP : Ptr to perf structure to fill
5743 * Various collections need this info, so the guts were put in
5744 * this separate routine.
5748 *------------------------------------------------------------------------*/
5751 FillPerfValues(struct afs_PerfStats *a_perfP)
5752 { /*FillPerfValues */
5754 int dir_Buffers; /*# buffers in use by dir package */
5755 int dir_Calls; /*# read calls in dir package */
5756 int dir_IOs; /*# I/O ops in dir package */
5759 * Vnode cache section.
5761 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5762 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5763 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5764 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5765 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5766 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5767 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5768 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5769 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5770 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5771 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5772 SplitInt64(VStats.hdr_gets, hi, lo);
5773 a_perfP->vcache_H_Gets = lo;
5774 SplitInt64(VStats.hdr_loads, hi, lo);
5775 a_perfP->vcache_H_Replacements = lo;
5778 * Directory section.
5780 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5781 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5782 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5783 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5788 a_perfP->rx_packetRequests = (afs_int32) rx_stats.packetRequests;
5789 a_perfP->rx_noPackets_RcvClass =
5790 (afs_int32) rx_stats.receivePktAllocFailures;
5791 a_perfP->rx_noPackets_SendClass =
5792 (afs_int32) rx_stats.sendPktAllocFailures;
5793 a_perfP->rx_noPackets_SpecialClass =
5794 (afs_int32) rx_stats.specialPktAllocFailures;
5795 a_perfP->rx_socketGreedy = (afs_int32) rx_stats.socketGreedy;
5796 a_perfP->rx_bogusPacketOnRead = (afs_int32) rx_stats.bogusPacketOnRead;
5797 a_perfP->rx_bogusHost = (afs_int32) rx_stats.bogusHost;
5798 a_perfP->rx_noPacketOnRead = (afs_int32) rx_stats.noPacketOnRead;
5799 a_perfP->rx_noPacketBuffersOnRead =
5800 (afs_int32) rx_stats.noPacketBuffersOnRead;
5801 a_perfP->rx_selects = (afs_int32) rx_stats.selects;
5802 a_perfP->rx_sendSelects = (afs_int32) rx_stats.sendSelects;
5803 a_perfP->rx_packetsRead_RcvClass =
5804 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
5805 a_perfP->rx_packetsRead_SendClass =
5806 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
5807 a_perfP->rx_packetsRead_SpecialClass =
5808 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
5809 a_perfP->rx_dataPacketsRead = (afs_int32) rx_stats.dataPacketsRead;
5810 a_perfP->rx_ackPacketsRead = (afs_int32) rx_stats.ackPacketsRead;
5811 a_perfP->rx_dupPacketsRead = (afs_int32) rx_stats.dupPacketsRead;
5812 a_perfP->rx_spuriousPacketsRead =
5813 (afs_int32) rx_stats.spuriousPacketsRead;
5814 a_perfP->rx_packetsSent_RcvClass =
5815 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
5816 a_perfP->rx_packetsSent_SendClass =
5817 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
5818 a_perfP->rx_packetsSent_SpecialClass =
5819 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
5820 a_perfP->rx_ackPacketsSent = (afs_int32) rx_stats.ackPacketsSent;
5821 a_perfP->rx_pingPacketsSent = (afs_int32) rx_stats.pingPacketsSent;
5822 a_perfP->rx_abortPacketsSent = (afs_int32) rx_stats.abortPacketsSent;
5823 a_perfP->rx_busyPacketsSent = (afs_int32) rx_stats.busyPacketsSent;
5824 a_perfP->rx_dataPacketsSent = (afs_int32) rx_stats.dataPacketsSent;
5825 a_perfP->rx_dataPacketsReSent = (afs_int32) rx_stats.dataPacketsReSent;
5826 a_perfP->rx_dataPacketsPushed = (afs_int32) rx_stats.dataPacketsPushed;
5827 a_perfP->rx_ignoreAckedPacket = (afs_int32) rx_stats.ignoreAckedPacket;
5828 a_perfP->rx_totalRtt_Sec = (afs_int32) rx_stats.totalRtt.sec;
5829 a_perfP->rx_totalRtt_Usec = (afs_int32) rx_stats.totalRtt.usec;
5830 a_perfP->rx_minRtt_Sec = (afs_int32) rx_stats.minRtt.sec;
5831 a_perfP->rx_minRtt_Usec = (afs_int32) rx_stats.minRtt.usec;
5832 a_perfP->rx_maxRtt_Sec = (afs_int32) rx_stats.maxRtt.sec;
5833 a_perfP->rx_maxRtt_Usec = (afs_int32) rx_stats.maxRtt.usec;
5834 a_perfP->rx_nRttSamples = (afs_int32) rx_stats.nRttSamples;
5835 a_perfP->rx_nServerConns = (afs_int32) rx_stats.nServerConns;
5836 a_perfP->rx_nClientConns = (afs_int32) rx_stats.nClientConns;
5837 a_perfP->rx_nPeerStructs = (afs_int32) rx_stats.nPeerStructs;
5838 a_perfP->rx_nCallStructs = (afs_int32) rx_stats.nCallStructs;
5839 a_perfP->rx_nFreeCallStructs = (afs_int32) rx_stats.nFreeCallStructs;
5841 a_perfP->host_NumHostEntries = HTs;
5842 a_perfP->host_HostBlocks = HTBlocks;
5843 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5844 &(a_perfP->host_HostsInSameNetOrSubnet),
5845 &(a_perfP->host_HostsInDiffSubnet),
5846 &(a_perfP->host_HostsInDiffNetwork));
5847 a_perfP->host_NumClients = CEs;
5848 a_perfP->host_ClientBlocks = CEBlocks;
5850 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5851 a_perfP->rx_nBusies = (afs_int32) rx_stats.nBusies;
5852 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5853 } /*FillPerfValues */
5856 /*------------------------------------------------------------------------
5857 * EXPORTED SRXAFS_GetXStats
5860 * Routine called by the server-side callback RPC interface to
5861 * implement getting the given data collection from the extended
5862 * File Server statistics.
5865 * a_call : Ptr to Rx call on which this request came in.
5866 * a_clientVersionNum : Client version number.
5867 * a_opCode : Desired operation.
5868 * a_serverVersionNumP : Ptr to version number to set.
5869 * a_timeP : Ptr to time value (seconds) to set.
5870 * a_dataP : Ptr to variable array structure to return
5877 * Nothing interesting.
5881 *------------------------------------------------------------------------*/
5884 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5885 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5886 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5887 { /*SRXAFS_GetXStats */
5889 register int code; /*Return value */
5890 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5891 afs_int32 dataBytes; /*Bytes in data buffer */
5892 #if FS_STATS_DETAILED
5893 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5894 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5895 struct timeval elapsedTime; /* Transfer time */
5898 * Set our stats pointer, remember when the RPC operation started, and
5899 * tally the operation.
5901 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
5905 TM_GetTimeOfDay(&opStartTime, 0);
5906 #endif /* FS_STATS_DETAILED */
5909 * Record the time of day and the server version number.
5911 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5912 *a_timeP = FT_ApproxTime();
5915 * Stuff the appropriate data in there (assume victory)
5920 ("Received GetXStats call for collection %d\n",
5921 a_collectionNumber));
5925 * We're not keeping stats, so just return successfully with
5928 a_dataP->AFS_CollData_len = 0;
5929 a_dataP->AFS_CollData_val = NULL;
5932 switch (a_collectionNumber) {
5933 case AFS_XSTATSCOLL_CALL_INFO:
5935 * Pass back all the call-count-related data.
5937 * >>> We are forced to allocate a separate area in which to
5938 * >>> put this stuff in by the RPC stub generator, since it
5939 * >>> will be freed at the tail end of the server stub code.
5943 * I don't think call-level stats are being collected yet
5944 * for the File Server.
5946 dataBytes = sizeof(struct afs_Stats);
5947 dataBuffP = (afs_int32 *) malloc(dataBytes);
5948 memcpy(dataBuffP, &afs_cmstats, dataBytes);
5949 a_dataP->AFS_CollData_len = dataBytes >> 2;
5950 a_dataP->AFS_CollData_val = dataBuffP;
5952 a_dataP->AFS_CollData_len = 0;
5953 a_dataP->AFS_CollData_val = NULL;
5957 case AFS_XSTATSCOLL_PERF_INFO:
5959 * Pass back all the regular performance-related data.
5961 * >>> We are forced to allocate a separate area in which to
5962 * >>> put this stuff in by the RPC stub generator, since it
5963 * >>> will be freed at the tail end of the server stub code.
5966 afs_perfstats.numPerfCalls++;
5967 FillPerfValues(&afs_perfstats);
5970 * Don't overwrite the spares at the end.
5973 dataBytes = sizeof(struct afs_PerfStats);
5974 dataBuffP = (afs_int32 *) malloc(dataBytes);
5975 memcpy(dataBuffP, &afs_perfstats, dataBytes);
5976 a_dataP->AFS_CollData_len = dataBytes >> 2;
5977 a_dataP->AFS_CollData_val = dataBuffP;
5980 case AFS_XSTATSCOLL_FULL_PERF_INFO:
5982 * Pass back the full collection of performance-related data.
5983 * We have to stuff the basic, overall numbers in, but the
5984 * detailed numbers are kept in the structure already.
5986 * >>> We are forced to allocate a separate area in which to
5987 * >>> put this stuff in by the RPC stub generator, since it
5988 * >>> will be freed at the tail end of the server stub code.
5991 afs_perfstats.numPerfCalls++;
5992 #if FS_STATS_DETAILED
5993 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
5994 FillPerfValues(&afs_FullPerfStats.overall);
5997 * Don't overwrite the spares at the end.
6000 dataBytes = sizeof(struct fs_stats_FullPerfStats);
6001 dataBuffP = (afs_int32 *) malloc(dataBytes);
6002 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
6003 a_dataP->AFS_CollData_len = dataBytes >> 2;
6004 a_dataP->AFS_CollData_val = dataBuffP;
6008 case AFS_XSTATSCOLL_CBSTATS:
6009 afs_perfstats.numPerfCalls++;
6011 dataBytes = sizeof(struct cbcounters);
6012 dataBuffP = (afs_int32 *) malloc(dataBytes);
6014 extern struct cbcounters cbstuff;
6015 dataBuffP[0]=cbstuff.DeleteFiles;
6016 dataBuffP[1]=cbstuff.DeleteCallBacks;
6017 dataBuffP[2]=cbstuff.BreakCallBacks;
6018 dataBuffP[3]=cbstuff.AddCallBacks;
6019 dataBuffP[4]=cbstuff.GotSomeSpaces;
6020 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
6021 dataBuffP[6]=cbstuff.nFEs;
6022 dataBuffP[7]=cbstuff.nCBs;
6023 dataBuffP[8]=cbstuff.nblks;
6024 dataBuffP[9]=cbstuff.CBsTimedOut;
6025 dataBuffP[10]=cbstuff.nbreakers;
6026 dataBuffP[11]=cbstuff.GSS1;
6027 dataBuffP[12]=cbstuff.GSS2;
6028 dataBuffP[13]=cbstuff.GSS3;
6029 dataBuffP[14]=cbstuff.GSS4;
6030 dataBuffP[15]=cbstuff.GSS5;
6033 a_dataP->AFS_CollData_len = dataBytes >> 2;
6034 a_dataP->AFS_CollData_val = dataBuffP;
6040 * Illegal collection number.
6042 a_dataP->AFS_CollData_len = 0;
6043 a_dataP->AFS_CollData_val = NULL;
6045 } /*Switch on collection number */
6047 #if FS_STATS_DETAILED
6048 TM_GetTimeOfDay(&opStopTime, 0);
6051 (opP->numSuccesses)++;
6052 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6053 fs_stats_AddTo((opP->sumTime), elapsedTime);
6054 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6055 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6056 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6058 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6059 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6063 #endif /* FS_STATS_DETAILED */
6067 } /*SRXAFS_GetXStats */
6071 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
6072 struct AFSCBs *CallBackArray)
6074 afs_int32 errorCode = 0;
6076 struct client *client = 0;
6077 struct rx_connection *tcon;
6079 #if FS_STATS_DETAILED
6080 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6081 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6082 struct timeval elapsedTime; /* Transfer time */
6085 * Set our stats pointer, remember when the RPC operation started, and
6086 * tally the operation.
6089 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
6093 TM_GetTimeOfDay(&opStartTime, 0);
6094 #endif /* FS_STATS_DETAILED */
6098 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
6099 FidArray->AFSCBFids_len));
6102 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
6104 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6105 goto Bad_GiveUpCallBacks;
6107 if (!FidArray && !CallBackArray) {
6109 ("SAFS_GiveUpAllCallBacks: host=%x\n",
6110 (tcon->peer ? tcon->peer->host : 0)));
6111 errorCode = GetClient(tcon, &client);
6114 DeleteAllCallBacks_r(client->host, 1);
6119 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
6121 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
6122 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
6123 (tcon->peer ? tcon->peer->host : 0)));
6125 goto Bad_GiveUpCallBacks;
6128 errorCode = GetClient(tcon, &client);
6130 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
6131 register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
6132 DeleteCallBack(client->host, fid);
6138 Bad_GiveUpCallBacks:
6139 errorCode = CallPostamble(tcon, errorCode, thost);
6141 #if FS_STATS_DETAILED
6142 TM_GetTimeOfDay(&opStopTime, 0);
6143 if (errorCode == 0) {
6145 (opP->numSuccesses)++;
6146 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6147 fs_stats_AddTo((opP->sumTime), elapsedTime);
6148 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6149 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6150 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6152 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6153 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6157 #endif /* FS_STATS_DETAILED */
6160 } /*common_GiveUpCallBacks */
6164 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
6165 struct AFSCBs * CallBackArray)
6167 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
6168 } /*SRXAFS_GiveUpCallBacks */
6171 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
6173 return common_GiveUpCallBacks(acall, 0, 0);
6174 } /*SRXAFS_GiveUpAllCallBacks */
6178 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
6179 struct AFSVolumeInfo * avolinfo)
6181 return (VNOVOL); /* XXX Obsolete routine XXX */
6183 } /*SRXAFS_NGetVolumeInfo */
6187 * Dummy routine. Should never be called (the cache manager should only
6188 * invoke this interface when communicating with a AFS/DFS Protocol
6192 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
6193 char *afs_name_p, struct AFSFid * afs_fid_p,
6194 struct AFSFetchStatus * afs_status_p,
6195 struct AFSFetchStatus * afs_dir_status_p,
6196 struct AFSCallBack * afs_callback_p,
6197 struct AFSVolSync * afs_sync_p)
6204 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
6207 struct rx_connection *tcon;
6209 afs_int32 *dataBuffP;
6210 afs_int32 dataBytes;
6213 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
6214 afs_FullPerfStats.overall.fs_nGetCaps++;
6216 ViceLog(2, ("SAFS_GetCapabilties\n"));
6218 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6221 dataBytes = 1 * sizeof(afs_int32);
6222 dataBuffP = (afs_int32 *) malloc(dataBytes);
6223 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
6224 #if defined(AFS_64BIT_ENV) && defined(AFS_LARGEFILE_ENV)
6225 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
6228 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
6230 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
6231 capabilities->Capabilities_val = dataBuffP;
6234 code = CallPostamble(tcon, code, thost);
6241 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
6242 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
6246 afs_int32 nids, naddrs;
6247 afs_int32 *vd, *addr;
6248 int errorCode = 0; /* return code to caller */
6249 struct client *client = 0;
6250 struct rx_connection *tcon = rx_ConnectionOf(acall);
6252 ViceLog(1, ("SRXAFS_FlushCPS\n"));
6254 AFSCallStats.TotalCalls++;
6256 nids = vids->ViceIds_len; /* # of users in here */
6257 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
6258 if (nids < 0 || naddrs < 0) {
6263 vd = vids->ViceIds_val;
6264 for (i = 0; i < nids; i++, vd++) {
6267 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
6271 client->prfail = 2; /* Means re-eval client's cps */
6274 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6277 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6278 free(client->CPS.prlist_val);
6279 client->CPS.prlist_val = NULL;
6280 client->CPS.prlist_len = 0;
6282 ReleaseWriteLock(&client->lock);
6286 addr = addrs->IPAddrs_val;
6287 for (i = 0; i < naddrs; i++, addr++) {
6289 h_flushhostcps(*addr, htons(7001));
6293 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6295 } /*SRXAFS_FlushCPS */
6297 /* worthless hack to let CS keep running ancient software */
6299 afs_vtoi(register char *aname)
6301 register afs_int32 temp;
6305 while ((tc = *aname++)) {
6306 if (tc > '9' || tc < '0')
6307 return 0; /* invalid name */
6315 * may get name or #, but must handle all weird cases (recognize readonly
6316 * or backup volumes by name or #
6319 CopyVolumeEntry(char *aname, register struct vldbentry *ave,
6320 register struct VolumeInfo *av)
6322 register int i, j, vol;
6323 afs_int32 mask, whichType;
6324 afs_uint32 *serverHost, *typePtr;
6326 /* figure out what type we want if by name */
6328 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6329 whichType = BACKVOL;
6330 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6335 vol = afs_vtoi(aname);
6337 vol = ave->volumeId[whichType];
6340 * Now vol has volume # we're interested in. Next, figure out the type
6341 * of the volume by looking finding it in the vldb entry
6343 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6346 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6349 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6350 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6351 whichType = BACKVOL;
6353 return EINVAL; /* error: can't find volume in vldb entry */
6355 typePtr = &av->Type0;
6356 serverHost = &av->Server0;
6358 av->Type = whichType;
6359 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6360 if (ave->flags & VLF_RWEXISTS)
6361 typePtr[RWVOL] = ave->volumeId[RWVOL];
6362 if (ave->flags & VLF_ROEXISTS)
6363 typePtr[ROVOL] = ave->volumeId[ROVOL];
6364 if (ave->flags & VLF_BACKEXISTS)
6365 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6367 for (i = 0, j = 0; i < ave->nServers; i++) {
6368 if ((ave->serverFlags[i] & mask) == 0)
6369 continue; /* wrong volume */
6370 serverHost[j] = ave->serverNumber[i];
6373 av->ServerCount = j;
6375 serverHost[j++] = 0; /* bogus 8, but compat only now */
6380 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6382 static struct rx_connection *vlConn = 0;
6383 static int down = 0;
6384 static afs_int32 lastDownTime = 0;
6385 struct vldbentry tve;
6386 struct rx_securityClass *vlSec;
6387 register afs_int32 code;
6390 vlSec = rxnull_NewClientSecurityObject();
6392 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6393 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6395 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6396 return 1; /* failure */
6399 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6401 down = 0; /* call worked */
6404 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6410 /* otherwise convert to old format vldb entry */
6411 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6421 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6422 struct VolumeInfo * avolinfo)
6425 struct rx_connection *tcon;
6427 #if FS_STATS_DETAILED
6428 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6429 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6430 struct timeval elapsedTime; /* Transfer time */
6433 * Set our stats pointer, remember when the RPC operation started, and
6434 * tally the operation.
6436 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6440 TM_GetTimeOfDay(&opStartTime, 0);
6441 #endif /* FS_STATS_DETAILED */
6442 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6443 goto Bad_GetVolumeInfo;
6446 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6448 code = TryLocalVLServer(avolid, avolinfo);
6450 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6451 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6452 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6453 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6456 code = CallPostamble(tcon, code, thost);
6458 #if FS_STATS_DETAILED
6459 TM_GetTimeOfDay(&opStopTime, 0);
6462 (opP->numSuccesses)++;
6463 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6464 fs_stats_AddTo((opP->sumTime), elapsedTime);
6465 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6466 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6467 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6469 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6470 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6474 #endif /* FS_STATS_DETAILED */
6478 } /*SRXAFS_GetVolumeInfo */
6482 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6483 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6484 char **OfflineMsg, char **Motd)
6486 Vnode *targetptr = 0; /* vnode of the new file */
6487 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6488 int errorCode = 0; /* error code */
6489 Volume *volptr = 0; /* pointer to the volume header */
6490 struct client *client = 0; /* pointer to client entry */
6491 afs_int32 rights, anyrights; /* rights for this and any user */
6493 struct rx_connection *tcon;
6495 struct client *t_client = NULL; /* tmp ptr to client data */
6496 #if FS_STATS_DETAILED
6497 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6498 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6499 struct timeval elapsedTime; /* Transfer time */
6502 * Set our stats pointer, remember when the RPC operation started, and
6503 * tally the operation.
6506 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6510 TM_GetTimeOfDay(&opStartTime, 0);
6511 #endif /* FS_STATS_DETAILED */
6513 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6514 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6515 goto Bad_GetVolumeStatus;
6518 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6522 goto Bad_GetVolumeStatus;
6524 dummyFid.Volume = avolid, dummyFid.Vnode =
6525 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6528 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6529 &parentwhentargetnotdir, &client, READ_LOCK,
6530 &rights, &anyrights)))
6531 goto Bad_GetVolumeStatus;
6533 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6535 goto Bad_GetVolumeStatus;
6537 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6539 Bad_GetVolumeStatus:
6540 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6542 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6543 /* next is to guarantee out strings exist for stub */
6545 *Name = (char *)malloc(1);
6549 *Motd = (char *)malloc(1);
6552 if (*OfflineMsg == 0) {
6553 *OfflineMsg = (char *)malloc(1);
6556 errorCode = CallPostamble(tcon, errorCode, thost);
6558 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6560 #if FS_STATS_DETAILED
6561 TM_GetTimeOfDay(&opStopTime, 0);
6562 if (errorCode == 0) {
6564 (opP->numSuccesses)++;
6565 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6566 fs_stats_AddTo((opP->sumTime), elapsedTime);
6567 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6568 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6569 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6571 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6572 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6576 #endif /* FS_STATS_DETAILED */
6578 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
6579 AUD_ID, t_client ? t_client->ViceId : 0,
6580 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
6583 } /*SRXAFS_GetVolumeStatus */
6587 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6588 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6589 char *OfflineMsg, char *Motd)
6591 Vnode *targetptr = 0; /* vnode of the new file */
6592 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6593 int errorCode = 0; /* error code */
6594 Volume *volptr = 0; /* pointer to the volume header */
6595 struct client *client = 0; /* pointer to client entry */
6596 afs_int32 rights, anyrights; /* rights for this and any user */
6598 struct rx_connection *tcon = rx_ConnectionOf(acall);
6600 struct client *t_client = NULL; /* tmp ptr to client data */
6601 #if FS_STATS_DETAILED
6602 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6603 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6604 struct timeval elapsedTime; /* Transfer time */
6607 * Set our stats pointer, remember when the RPC operation started, and
6608 * tally the operation.
6611 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6615 TM_GetTimeOfDay(&opStartTime, 0);
6616 #endif /* FS_STATS_DETAILED */
6618 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6619 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6620 goto Bad_SetVolumeStatus;
6623 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6627 goto Bad_SetVolumeStatus;
6629 dummyFid.Volume = avolid, dummyFid.Vnode =
6630 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6633 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6634 &parentwhentargetnotdir, &client, READ_LOCK,
6635 &rights, &anyrights)))
6636 goto Bad_SetVolumeStatus;
6638 if (readonlyServer) {
6639 errorCode = VREADONLY;
6640 goto Bad_SetVolumeStatus;
6642 if (VanillaUser(client)) {
6644 goto Bad_SetVolumeStatus;
6648 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6650 Bad_SetVolumeStatus:
6651 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6653 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6654 errorCode = CallPostamble(tcon, errorCode, thost);
6656 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6658 #if FS_STATS_DETAILED
6659 TM_GetTimeOfDay(&opStopTime, 0);
6660 if (errorCode == 0) {
6662 (opP->numSuccesses)++;
6663 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6664 fs_stats_AddTo((opP->sumTime), elapsedTime);
6665 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6666 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6667 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6669 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6670 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6674 #endif /* FS_STATS_DETAILED */
6676 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6677 AUD_ID, t_client ? t_client->ViceId : 0,
6678 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6680 } /*SRXAFS_SetVolumeStatus */
6682 #define DEFAULTVOLUME "root.afs"
6685 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6691 struct rx_connection *tcon;
6695 #if FS_STATS_DETAILED
6696 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6697 struct timeval opStartTime; /* Start time for RPC op */
6699 struct timeval opStopTime;
6700 struct timeval elapsedTime; /* Transfer time */
6704 * Set our stats pointer, remember when the RPC operation started, and
6705 * tally the operation.
6707 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6711 TM_GetTimeOfDay(&opStartTime, 0);
6712 #endif /* FS_STATS_DETAILED */
6714 return FSERR_EOPNOTSUPP;
6717 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
6718 goto Bad_GetRootVolume;
6720 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6723 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6725 strcpy(temp, DEFAULTVOLUME);
6727 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6728 lockf(fd, F_LOCK, 0);
6732 len = read(fd, temp, 256);
6733 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6734 lockf(fd, F_ULOCK, 0);
6739 if (temp[len - 1] == '\n')
6743 *VolumeName = temp; /* freed by rx server-side stub */
6746 errorCode = CallPostamble(tcon, errorCode, thost);
6748 #if FS_STATS_DETAILED
6749 TM_GetTimeOfDay(&opStopTime, 0);
6750 if (errorCode == 0) {
6752 (opP->numSuccesses)++;
6753 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6754 fs_stats_AddTo((opP->sumTime), elapsedTime);
6755 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6756 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6757 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6759 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6760 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6764 #endif /* FS_STATS_DETAILED */
6769 } /*SRXAFS_GetRootVolume */
6772 /* still works because a struct CBS is the same as a struct AFSOpaque */
6774 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6775 struct AFSOpaque * Token)
6778 struct rx_connection *tcon;
6780 #if FS_STATS_DETAILED
6781 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6782 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6783 struct timeval elapsedTime; /* Transfer time */
6786 * Set our stats pointer, remember when the RPC operation started, and
6787 * tally the operation.
6789 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6793 TM_GetTimeOfDay(&opStartTime, 0);
6794 #endif /* FS_STATS_DETAILED */
6796 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6797 goto Bad_CheckToken;
6799 code = FSERR_ECONNREFUSED;
6802 code = CallPostamble(tcon, code, thost);
6804 #if FS_STATS_DETAILED
6805 TM_GetTimeOfDay(&opStopTime, 0);
6808 (opP->numSuccesses)++;
6809 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6810 fs_stats_AddTo((opP->sumTime), elapsedTime);
6811 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6812 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6813 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6815 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6816 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6820 #endif /* FS_STATS_DETAILED */
6824 } /*SRXAFS_CheckToken */
6827 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6828 afs_uint32 * USeconds)
6831 struct rx_connection *tcon;
6834 #if FS_STATS_DETAILED
6835 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6836 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6837 struct timeval elapsedTime; /* Transfer time */
6840 * Set our stats pointer, remember when the RPC operation started, and
6841 * tally the operation.
6843 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
6847 TM_GetTimeOfDay(&opStartTime, 0);
6848 #endif /* FS_STATS_DETAILED */
6850 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6854 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6856 TM_GetTimeOfDay(&tpl, 0);
6857 *Seconds = tpl.tv_sec;
6858 *USeconds = tpl.tv_usec;
6860 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6863 code = CallPostamble(tcon, code, thost);
6865 #if FS_STATS_DETAILED
6866 TM_GetTimeOfDay(&opStopTime, 0);
6867 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6870 (opP->numSuccesses)++;
6871 fs_stats_AddTo((opP->sumTime), elapsedTime);
6872 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6873 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6874 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6876 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6877 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6881 #endif /* FS_STATS_DETAILED */
6885 } /*SRXAFS_GetTime */
6892 * Implement a client's data fetch using Rx.
6895 * volptr : Ptr to the given volume's info.
6896 * targetptr : Pointer to the vnode involved.
6897 * Call : Ptr to the Rx call involved.
6898 * Pos : Offset within the file.
6899 * Len : Length in bytes to read; this value is bogus!
6900 * if FS_STATS_DETAILED
6901 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6903 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6909 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
6910 register struct rx_call * Call, afs_sfsize_t Pos,
6911 afs_sfsize_t Len, afs_int32 Int64Mode,
6912 #if FS_STATS_DETAILED
6913 afs_sfsize_t * a_bytesToFetchP,
6914 afs_sfsize_t * a_bytesFetchedP
6915 #endif /* FS_STATS_DETAILED */
6918 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6919 int errorCode = 0; /* Returned error code to caller */
6923 register char *tbuffer;
6924 #else /* AFS_NT40_ENV */
6925 struct iovec tiov[RX_MAXIOVECS];
6927 #endif /* AFS_NT40_ENV */
6931 #if FS_STATS_DETAILED
6933 * Initialize the byte count arguments.
6935 (*a_bytesToFetchP) = 0;
6936 (*a_bytesFetchedP) = 0;
6937 #endif /* FS_STATS_DETAILED */
6941 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
6942 (afs_uintmax_t) Len));
6944 if (!VN_GET_INO(targetptr)) {
6945 afs_int32 zero = htonl(0);
6947 * This is used for newly created files; we simply send 0 bytes
6948 * back to make the cache manager happy...
6951 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6952 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6955 TM_GetTimeOfDay(&StartTime, 0);
6956 ihP = targetptr->handle;
6959 VTakeOffline(volptr);
6960 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6964 optSize = sendBufSize;
6965 tlen = FDH_SIZE(fdP);
6967 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
6970 VTakeOffline(volptr);
6971 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
6979 if (Pos + Len > tlen)
6980 Len = tlen - Pos; /* get length we should send */
6981 (void)FDH_SEEK(fdP, Pos, 0);
6983 afs_int32 high, low;
6984 SplitOffsetOrSize(Len, high, low);
6985 assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
6988 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
6991 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
6993 #if FS_STATS_DETAILED
6994 (*a_bytesToFetchP) = Len;
6995 #endif /* FS_STATS_DETAILED */
6997 tbuffer = AllocSendBuffer();
6998 #endif /* AFS_NT40_ENV */
7006 errorCode = FDH_READ(fdP, tbuffer, wlen);
7007 if (errorCode != wlen) {
7009 FreeSendBuffer((struct afs_buffer *)tbuffer);
7010 VTakeOffline(volptr);
7011 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7015 errorCode = rx_Write(Call, tbuffer, wlen);
7016 #else /* AFS_NT40_ENV */
7017 errorCode = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
7018 if (errorCode <= 0) {
7023 errorCode = FDH_READV(fdP, tiov, tnio);
7024 if (errorCode != wlen) {
7026 VTakeOffline(volptr);
7027 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7031 errorCode = rx_Writev(Call, tiov, tnio, wlen);
7032 #endif /* AFS_NT40_ENV */
7033 #if FS_STATS_DETAILED
7035 * Bump the number of bytes actually sent by the number from this
7038 (*a_bytesFetchedP) += errorCode;
7039 #endif /* FS_STATS_DETAILED */
7040 if (errorCode != wlen) {
7043 FreeSendBuffer((struct afs_buffer *)tbuffer);
7044 #endif /* AFS_NT40_ENV */
7050 FreeSendBuffer((struct afs_buffer *)tbuffer);
7051 #endif /* AFS_NT40_ENV */
7053 TM_GetTimeOfDay(&StopTime, 0);
7055 /* Adjust all Fetch Data related stats */
7057 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
7058 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
7059 AFSCallStats.AccumFetchTime +=
7060 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
7061 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
7063 afs_fsize_t targLen;
7064 VN_GET_LEN(targLen, targetptr);
7065 AFSCallStats.TotalFetchedBytes += targLen;
7066 AFSCallStats.FetchSize1++;
7067 if (targLen < SIZE2)
7068 AFSCallStats.FetchSize2++;
7069 else if (targLen < SIZE3)
7070 AFSCallStats.FetchSize3++;
7071 else if (targLen < SIZE4)
7072 AFSCallStats.FetchSize4++;
7074 AFSCallStats.FetchSize5++;
7079 } /*FetchData_RXStyle */
7082 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
7083 afs_sfsize_t * size)
7085 #ifdef AFS_NAMEI_ENV
7087 lhp = IH_OPEN(V_linkHandle(vp));
7091 *lc = nt_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
7093 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
7098 *size = OS_SIZE(fdP->fd_fd);
7099 return (*size == -1) ? -1 : 0;
7101 struct afs_stat status;
7103 if (afs_fstat(fdP->fd_fd, &status) < 0) {
7107 *lc = GetLinkCount(vp, &status);
7108 *size = status.st_size;
7117 * Implement a client's data store using Rx.
7120 * volptr : Ptr to the given volume's info.
7121 * targetptr : Pointer to the vnode involved.
7122 * Call : Ptr to the Rx call involved.
7123 * Pos : Offset within the file.
7124 * Len : Length in bytes to store; this value is bogus!
7125 * if FS_STATS_DETAILED
7126 * a_bytesToStoreP : Set to the number of bytes to be stored to
7128 * a_bytesStoredP : Set to the actual number of bytes stored to
7133 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
7134 struct client * client, register struct rx_call * Call,
7135 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
7137 #if FS_STATS_DETAILED
7138 afs_sfsize_t * a_bytesToStoreP,
7139 afs_sfsize_t * a_bytesStoredP
7140 #endif /* FS_STATS_DETAILED */
7143 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
7144 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
7145 int errorCode = 0; /* Returned error code to caller */
7147 register char *tbuffer; /* data copying buffer */
7148 #else /* AFS_NT40_ENV */
7149 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
7150 int tnio; /* temp for iovec size */
7151 #endif /* AFS_NT40_ENV */
7152 afs_sfsize_t tlen; /* temp for xfr length */
7153 Inode tinode; /* inode for I/O */
7154 afs_int32 optSize; /* optimal transfer size */
7155 afs_sfsize_t DataLength; /* size of inode */
7156 afs_sfsize_t TruncatedLength; /* size after ftruncate */
7157 afs_fsize_t NewLength; /* size after this store completes */
7158 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
7159 int linkCount; /* link count on inode */
7161 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
7163 #if FS_STATS_DETAILED
7165 * Initialize the byte count arguments.
7167 (*a_bytesToStoreP) = 0;
7168 (*a_bytesStoredP) = 0;
7169 #endif /* FS_STATS_DETAILED */
7172 * We break the callbacks here so that the following signal will not
7175 BreakCallBack(client->host, Fid, 0);
7177 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
7178 /* the inode should have been created in Alloc_NewVnode */
7179 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
7181 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
7182 Fid->Volume, Fid->Vnode, Fid->Unique,
7183 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
7184 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
7185 return ENOENT; /* is this proper error code? */
7188 * See if the file has several links (from other volumes). If it
7189 * does, then we have to make a copy before changing it to avoid
7190 *changing read-only clones of this dude
7193 ("StoreData_RXStyle : Opening inode %s\n",
7194 PrintInode(NULL, VN_GET_INO(targetptr))));
7195 fdP = IH_OPEN(targetptr->handle);
7198 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
7200 VTakeOffline(volptr);
7201 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7206 if (linkCount != 1) {
7209 ("StoreData_RXStyle : inode %s has more than onelink\n",
7210 PrintInode(NULL, VN_GET_INO(targetptr))));
7211 /* other volumes share this data, better copy it first */
7213 /* Adjust the disk block count by the creation of the new inode.
7214 * We call the special VDiskUsage so we don't adjust the volume's
7215 * quota since we don't want to penalyze the user for afs's internal
7216 * mechanisms (i.e. copy on write overhead.) Also the right size
7217 * of the disk will be recorded...
7220 VN_GET_LEN(size, targetptr);
7221 volptr->partition->flags &= ~PART_DONTUPDATE;
7222 VSetPartitionDiskUsage(volptr->partition);
7223 volptr->partition->flags |= PART_DONTUPDATE;
7224 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
7225 volptr->partition->flags &= ~PART_DONTUPDATE;
7229 ViceLog(25, ("StoreData : calling CopyOnWrite on target dir\n"));
7230 if ((errorCode = CopyOnWrite(targetptr, volptr))) {
7231 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
7232 volptr->partition->flags &= ~PART_DONTUPDATE;
7235 volptr->partition->flags &= ~PART_DONTUPDATE;
7236 VSetPartitionDiskUsage(volptr->partition);
7237 fdP = IH_OPEN(targetptr->handle);
7240 ("StoreData : Reopen after CopyOnWrite failed\n"));
7244 tinode = VN_GET_INO(targetptr);
7246 if (!VALID_INO(tinode)) {
7247 VTakeOffline(volptr);
7248 ViceLog(0,("Volume %u now offline, must be salvaged.\n",
7253 /* compute new file length */
7254 NewLength = DataLength;
7255 if (FileLength < NewLength)
7256 /* simulate truncate */
7257 NewLength = FileLength;
7258 TruncatedLength = NewLength; /* remember length after possible ftruncate */
7259 if (Pos + Length > NewLength)
7260 NewLength = Pos + Length; /* and write */
7262 /* adjust the disk block count by the difference in the files */
7264 afs_fsize_t targSize;
7265 VN_GET_LEN(targSize, targetptr);
7266 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
7269 AdjustDiskUsage(volptr, adjustSize,
7270 adjustSize - SpareComp(volptr)))) {
7275 /* can signal cache manager to proceed from close now */
7276 /* this bit means that the locks are set and protections are OK */
7277 rx_SetLocalStatus(Call, 1);
7279 TM_GetTimeOfDay(&StartTime, 0);
7281 optSize = sendBufSize;
7283 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
7284 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
7285 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
7287 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
7288 if (FileLength < DataLength)
7289 FDH_TRUNC(fdP, FileLength);
7291 FDH_SEEK(fdP, Pos, 0);
7292 bytesTransfered = 0;
7294 tbuffer = AllocSendBuffer();
7295 #endif /* AFS_NT40_ENV */
7296 /* if length == 0, the loop below isn't going to do anything, including
7297 * extend the length of the inode, which it must do, since the file system
7298 * assumes that the inode length == vnode's file length. So, we extend
7299 * the file length manually if need be. Note that if file is bigger than
7300 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7301 * do what we're going to do below.
7303 if (Length == 0 && Pos > TruncatedLength) {
7304 /* Set the file's length; we've already done an lseek to the right
7307 errorCode = FDH_WRITE(fdP, &tlen, 1);
7310 errorCode = FDH_TRUNC(fdP, Pos);
7312 /* have some data to copy */
7313 #if FS_STATS_DETAILED
7314 (*a_bytesToStoreP) = Length;
7315 #endif /* FS_STATS_DETAILED */
7318 if (bytesTransfered >= Length) {
7322 tlen = Length - bytesTransfered; /* how much more to do */
7324 rlen = optSize; /* bound by buffer size */
7328 errorCode = rx_Read(Call, tbuffer, rlen);
7329 #else /* AFS_NT40_ENV */
7330 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7331 #endif /* AFS_NT40_ENV */
7332 #if FS_STATS_DETAILED
7333 (*a_bytesStoredP) += errorCode;
7334 #endif /* FS_STATS_DETAILED */
7335 if (errorCode <= 0) {
7341 errorCode = FDH_WRITE(fdP, tbuffer, rlen);
7342 #else /* AFS_NT40_ENV */
7343 errorCode = FDH_WRITEV(fdP, tiov, tnio);
7344 #endif /* AFS_NT40_ENV */
7345 if (errorCode != rlen) {
7346 errorCode = VDISKFULL;
7349 bytesTransfered += rlen;
7354 FreeSendBuffer((struct afs_buffer *)tbuffer);
7355 #endif /* AFS_NT40_ENV */
7360 afs_fsize_t nfSize = (afs_fsize_t) FDH_SIZE(fdP);
7361 /* something went wrong: adjust size and return */
7362 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7363 /* changed_newTime is tested in StoreData to detemine if we
7364 * need to update the target vnode.
7366 targetptr->changed_newTime = 1;
7368 /* set disk usage to be correct */
7369 VAdjustDiskUsage(&errorCode, volptr,
7370 (afs_sfsize_t) (nBlocks(nfSize) -
7371 nBlocks(NewLength)), 0);
7376 TM_GetTimeOfDay(&StopTime, 0);
7378 VN_SET_LEN(targetptr, NewLength);
7380 /* Update all StoreData related stats */
7382 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7383 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7384 AFSCallStats.StoreSize1++; /* Piggybacked data */
7386 afs_fsize_t targLen;
7387 VN_GET_LEN(targLen, targetptr);
7388 if (targLen < SIZE2)
7389 AFSCallStats.StoreSize2++;
7390 else if (targLen < SIZE3)
7391 AFSCallStats.StoreSize3++;
7392 else if (targLen < SIZE4)
7393 AFSCallStats.StoreSize4++;
7395 AFSCallStats.StoreSize5++;
7400 } /*StoreData_RXStyle */
7402 static int sys2et[512];
7405 init_sys_error_to_et(void)
7407 memset(&sys2et, 0, sizeof(sys2et));
7408 sys2et[EPERM] = UAEPERM;
7409 sys2et[ENOENT] = UAENOENT;
7410 sys2et[ESRCH] = UAESRCH;
7411 sys2et[EINTR] = UAEINTR;
7412 sys2et[EIO] = UAEIO;
7413 sys2et[ENXIO] = UAENXIO;
7414 sys2et[E2BIG] = UAE2BIG;
7415 sys2et[ENOEXEC] = UAENOEXEC;
7416 sys2et[EBADF] = UAEBADF;
7417 sys2et[ECHILD] = UAECHILD;
7418 sys2et[EAGAIN] = UAEAGAIN;
7419 sys2et[ENOMEM] = UAENOMEM;
7420 sys2et[EACCES] = UAEACCES;
7421 sys2et[EFAULT] = UAEFAULT;
7422 sys2et[ENOTBLK] = UAENOTBLK;
7423 sys2et[EBUSY] = UAEBUSY;
7424 sys2et[EEXIST] = UAEEXIST;
7425 sys2et[EXDEV] = UAEXDEV;
7426 sys2et[ENODEV] = UAENODEV;
7427 sys2et[ENOTDIR] = UAENOTDIR;
7428 sys2et[EISDIR] = UAEISDIR;
7429 sys2et[EINVAL] = UAEINVAL;
7430 sys2et[ENFILE] = UAENFILE;
7431 sys2et[EMFILE] = UAEMFILE;
7432 sys2et[ENOTTY] = UAENOTTY;
7433 sys2et[ETXTBSY] = UAETXTBSY;
7434 sys2et[EFBIG] = UAEFBIG;
7435 sys2et[ENOSPC] = UAENOSPC;
7436 sys2et[ESPIPE] = UAESPIPE;
7437 sys2et[EROFS] = UAEROFS;
7438 sys2et[EMLINK] = UAEMLINK;
7439 sys2et[EPIPE] = UAEPIPE;
7440 sys2et[EDOM] = UAEDOM;
7441 sys2et[ERANGE] = UAERANGE;
7442 sys2et[EDEADLK] = UAEDEADLK;
7443 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7444 sys2et[ENOLCK] = UAENOLCK;
7445 sys2et[ENOSYS] = UAENOSYS;
7446 #if (ENOTEMPTY != EEXIST)
7447 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7449 sys2et[ELOOP] = UAELOOP;
7450 #if (EWOULDBLOCK != EAGAIN)
7451 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7453 sys2et[ENOMSG] = UAENOMSG;
7454 sys2et[EIDRM] = UAEIDRM;
7455 sys2et[ECHRNG] = UAECHRNG;
7456 sys2et[EL2NSYNC] = UAEL2NSYNC;
7457 sys2et[EL3HLT] = UAEL3HLT;
7458 sys2et[EL3RST] = UAEL3RST;
7459 sys2et[ELNRNG] = UAELNRNG;
7460 sys2et[EUNATCH] = UAEUNATCH;
7461 sys2et[ENOCSI] = UAENOCSI;
7462 sys2et[EL2HLT] = UAEL2HLT;
7463 sys2et[EBADE] = UAEBADE;
7464 sys2et[EBADR] = UAEBADR;
7465 sys2et[EXFULL] = UAEXFULL;
7466 sys2et[ENOANO] = UAENOANO;
7467 sys2et[EBADRQC] = UAEBADRQC;
7468 sys2et[EBADSLT] = UAEBADSLT;
7469 sys2et[EDEADLK] = UAEDEADLK;
7470 sys2et[EBFONT] = UAEBFONT;
7471 sys2et[ENOSTR] = UAENOSTR;
7472 sys2et[ENODATA] = UAENODATA;
7473 sys2et[ETIME] = UAETIME;
7474 sys2et[ENOSR] = UAENOSR;
7475 sys2et[ENONET] = UAENONET;
7476 sys2et[ENOPKG] = UAENOPKG;
7477 sys2et[EREMOTE] = UAEREMOTE;
7478 sys2et[ENOLINK] = UAENOLINK;
7479 sys2et[EADV] = UAEADV;
7480 sys2et[ESRMNT] = UAESRMNT;
7481 sys2et[ECOMM] = UAECOMM;
7482 sys2et[EPROTO] = UAEPROTO;
7483 sys2et[EMULTIHOP] = UAEMULTIHOP;
7484 sys2et[EDOTDOT] = UAEDOTDOT;
7485 sys2et[EBADMSG] = UAEBADMSG;
7486 sys2et[EOVERFLOW] = UAEOVERFLOW;
7487 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7488 sys2et[EBADFD] = UAEBADFD;
7489 sys2et[EREMCHG] = UAEREMCHG;
7490 sys2et[ELIBACC] = UAELIBACC;
7491 sys2et[ELIBBAD] = UAELIBBAD;
7492 sys2et[ELIBSCN] = UAELIBSCN;
7493 sys2et[ELIBMAX] = UAELIBMAX;
7494 sys2et[ELIBEXEC] = UAELIBEXEC;
7495 sys2et[EILSEQ] = UAEILSEQ;
7496 sys2et[ERESTART] = UAERESTART;
7497 sys2et[ESTRPIPE] = UAESTRPIPE;
7498 sys2et[EUSERS] = UAEUSERS;
7499 sys2et[ENOTSOCK] = UAENOTSOCK;
7500 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7501 sys2et[EMSGSIZE] = UAEMSGSIZE;
7502 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7503 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7504 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7505 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7506 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7507 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7508 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7509 sys2et[EADDRINUSE] = UAEADDRINUSE;
7510 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7511 sys2et[ENETDOWN] = UAENETDOWN;
7512 sys2et[ENETUNREACH] = UAENETUNREACH;
7513 sys2et[ENETRESET] = UAENETRESET;
7514 sys2et[ECONNABORTED] = UAECONNABORTED;
7515 sys2et[ECONNRESET] = UAECONNRESET;
7516 sys2et[ENOBUFS] = UAENOBUFS;
7517 sys2et[EISCONN] = UAEISCONN;
7518 sys2et[ENOTCONN] = UAENOTCONN;
7519 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7520 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7521 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7522 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7523 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7524 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7525 sys2et[EALREADY] = UAEALREADY;
7526 sys2et[EINPROGRESS] = UAEINPROGRESS;
7527 sys2et[ESTALE] = UAESTALE;
7528 sys2et[EUCLEAN] = UAEUCLEAN;
7529 sys2et[ENOTNAM] = UAENOTNAM;
7530 sys2et[ENAVAIL] = UAENAVAIL;
7531 sys2et[EISNAM] = UAEISNAM;
7532 sys2et[EREMOTEIO] = UAEREMOTEIO;
7533 sys2et[EDQUOT] = UAEDQUOT;
7534 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7535 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7537 sys2et[EIO] = UAEIO;
7541 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
7542 * - pass back the connection, client, and host from CallPreamble
7543 * - keep a ref on the client, which we don't now
7544 * - keep a hold on the host, which we already do
7545 * - pass the connection, client, and host down into SAFSS_*, and use
7546 * them instead of independently discovering them via rx_ConnectionOf
7547 * (safe) and rx_GetSpecific (not so safe)
7548 * The idea being that we decide what client and host we're going to use
7549 * when CallPreamble is called, and stay consistent throughout the call.
7550 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
7554 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7556 Error errorCode = 0;
7557 struct rx_connection *tcon;
7558 struct host *tcallhost;
7559 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7561 struct client *tclient;
7562 static struct rx_securityClass *sc = 0;
7564 struct rx_connection *conn;
7567 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost))
7568 goto Bad_CallBackRxConnAddr1;
7570 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7574 tclient = h_FindClient_r(tcon);
7577 goto Bad_CallBackRxConnAddr;
7579 thost = tclient->host;
7581 /* nothing more can be done */
7582 if ( !thost->interface )
7583 goto Bad_CallBackRxConnAddr;
7585 /* the only address is the primary interface */
7586 /* can't change when there's only 1 address, anyway */
7587 if ( thost->interface->numberOfInterfaces <= 1 )
7588 goto Bad_CallBackRxConnAddr;
7590 /* initialise a security object only once */
7592 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7594 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7596 if ( *addr == thost->interface->addr[i] ) {
7601 if ( *addr != thost->interface->addr[i] )
7602 goto Bad_CallBackRxConnAddr;
7604 conn = rx_NewConnection (thost->interface->addr[i],
7605 thost->port, 1, sc, 0);
7606 rx_SetConnDeadTime(conn, 2);
7607 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7609 errorCode = RXAFSCB_Probe(conn);
7612 if ( thost->callback_rxcon )
7613 rx_DestroyConnection(thost->callback_rxcon);
7614 thost->callback_rxcon = conn;
7616 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7617 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7618 h_ReleaseClient_r(tclient);
7619 /* The hold on thost will be released by CallPostamble */
7621 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7624 rx_DestroyConnection(conn);
7626 Bad_CallBackRxConnAddr:
7627 h_ReleaseClient_r(tclient);
7628 /* The hold on thost will be released by CallPostamble */
7632 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7633 Bad_CallBackRxConnAddr1:
7634 return errorCode; /* failure */
7638 sys_error_to_et(afs_int32 in)
7642 if (in < 0 || in > 511)
7644 if (in >= VICE_SPECIAL_ERRORS && in <= VIO || in == VRESTRICTED)
7646 if (sys2et[in] != 0)