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>
59 #ifndef AFS_LINUX20_ENV
61 #include <netinet/if_ether.h>
65 /* included early because of name conflict on IOPEN */
66 #include <sys/inode.h>
70 #endif /* AFS_HPUX_ENV */
74 #include <afs/assert.h>
77 #include <afs/afsint.h>
78 #include <afs/vldbint.h>
79 #include <afs/errors.h>
80 #include <afs/ihandle.h>
81 #include <afs/vnode.h>
82 #include <afs/volume.h>
83 #include <afs/ptclient.h>
84 #include <afs/ptuser.h>
85 #include <afs/prs_fs.h>
88 #include <rx/rx_globals.h>
90 #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)
93 #if !defined(AFS_NT40_ENV)
96 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
98 #include <sys/statfs.h>
99 #include <sys/lockf.h>
101 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
106 #include <afs/cellconfig.h>
107 #include <afs/keys.h>
109 #include <afs/auth.h>
111 #include <afs/partition.h>
112 #include "viced_prototypes.h"
115 #include "callback.h"
116 #include <afs/unified_afs.h>
117 #include <afs/audit.h>
118 #include <afs/afsutil.h>
121 extern void SetDirHandle(register DirHandle * dir, register Vnode * vnode);
122 extern void FidZap(DirHandle * file);
123 extern void FidZero(DirHandle * file);
125 #ifdef AFS_PTHREAD_ENV
126 pthread_mutex_t fileproc_glock_mutex;
127 #endif /* AFS_PTHREAD_ENV */
130 #define afs_stat stat64
131 #define afs_fstat fstat64
132 #define afs_open open64
133 #else /* !O_LARGEFILE */
134 #define afs_stat stat
135 #define afs_fstat fstat
136 #define afs_open open
137 #endif /* !O_LARGEFILE */
140 /* Useful local defines used by this module */
143 #define MustNOTBeDIR 1
147 #define TVS_SSTATUS 2
150 #define TVS_MKDIR 0x10
152 #define CHK_FETCH 0x10
153 #define CHK_FETCHDATA 0x10
154 #define CHK_FETCHACL 0x11
155 #define CHK_FETCHSTATUS 0x12
156 #define CHK_STOREDATA 0x00
157 #define CHK_STOREACL 0x01
158 #define CHK_STORESTATUS 0x02
160 #define OWNERREAD 0400
161 #define OWNERWRITE 0200
162 #define OWNEREXEC 0100
163 #ifdef USE_GROUP_PERMS
164 #define GROUPREAD 0040
165 #define GROUPWRITE 0020
166 #define GROUPREXEC 0010
169 /* The following errors were not defined in NT. They are given unique
170 * names here to avoid any potential collision.
172 #define FSERR_ELOOP 90
173 #define FSERR_EOPNOTSUPP 122
174 #define FSERR_ECONNREFUSED 130
176 #define NOTACTIVECALL 0
179 #define CREATE_SGUID_ADMIN_ONLY 1
181 extern struct afsconf_dir *confDir;
182 extern afs_int32 dataVersionHigh;
185 static struct AFSCallStatistics AFSCallStats;
186 #if FS_STATS_DETAILED
187 struct fs_stats_FullPerfStats afs_FullPerfStats;
188 extern int AnonymousID;
189 #endif /* FS_STATS_DETAILED */
190 #if OPENAFS_VOL_STATS
191 static const char nullString[] = "";
192 #endif /* OPENAFS_VOL_STATS */
195 afs_int32 NothingYet;
198 struct afs_FSStats afs_fsstats;
200 void ResetDebug(), SetDebug(), Terminate();
205 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
207 extern afs_int32 implicitAdminRights;
208 extern afs_int32 readonlyServer;
211 * Externals used by the xstat code.
213 extern VolPkgStats VStats;
214 extern int CEs, CEBlocks;
216 extern int HTs, HTBlocks;
218 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
219 register struct rx_call *Call, afs_sfsize_t Pos,
220 afs_sfsize_t Len, afs_int32 Int64Mode,
221 #if FS_STATS_DETAILED
222 afs_sfsize_t * a_bytesToFetchP,
223 afs_sfsize_t * a_bytesFetchedP
224 #endif /* FS_STATS_DETAILED */
227 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
228 struct AFSFid *Fid, struct client *client,
229 register struct rx_call *Call, afs_fsize_t Pos,
230 afs_fsize_t Length, afs_fsize_t FileLength,
232 #if FS_STATS_DETAILED
233 afs_sfsize_t * a_bytesToStoreP,
234 afs_sfsize_t * a_bytesStoredP
235 #endif /* FS_STATS_DETAILED */
238 #ifdef AFS_SGI_XFS_IOPS_ENV
239 #include <afs/xfsattrs.h>
241 GetLinkCount(Volume * avp, struct stat *astat)
243 if (!strcmp("xfs", astat->st_fstype)) {
244 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
246 return astat->st_nlink;
249 #define GetLinkCount(V, S) (S)->st_nlink
253 SpareComp(Volume * avolp)
255 register afs_int32 temp;
259 temp = V_maxquota(avolp);
261 /* no matter; doesn't check in this case */
265 temp = (temp * PctSpare) / 100;
276 * Set the volume synchronization parameter for this volume. If it changes,
277 * the Cache Manager knows that the volume must be purged from the stat cache.
280 SetVolumeSync(register struct AFSVolSync *async, register Volume * avol)
283 /* date volume instance was created */
286 async->spare1 = avol->header->diskstuff.creationDate;
299 * Note that this function always returns a held host, so
300 * that CallPostamble can block without the host's disappearing.
301 * Call returns rx connection in passed in *tconn
304 CallPreamble(register struct rx_call *acall, int activecall,
305 struct rx_connection **tconn, struct host **ahostp)
308 struct client *tclient;
311 char hoststr[16], hoststr2[16];
313 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
316 *tconn = rx_ConnectionOf(acall);
320 tclient = h_FindClient_r(*tconn);
321 thost = tclient->host;
322 if (tclient->prfail == 1) { /* couldn't get the CPS */
324 h_ReleaseClient_r(tclient);
326 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
330 retry_flag = 0; /* Retry once */
332 /* Take down the old connection and re-read the key file */
334 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
336 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
339 h_ReleaseClient_r(tclient);
342 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
346 tclient->prfail = 2; /* Means re-eval client's cps */
347 h_ReleaseClient_r(tclient);
352 tclient->LastCall = thost->LastCall = FT_ApproxTime();
353 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
354 thost->ActiveCall = thost->LastCall;
357 if (thost->hostFlags & HOSTDELETED) {
359 ("Discarded a packet for deleted host %s:%d\n",
360 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
361 code = VBUSY; /* raced, so retry */
362 } else if ((thost->hostFlags & VENUSDOWN)
363 || (thost->hostFlags & HFE_LATER)) {
364 if (BreakDelayedCallBacks_r(thost)) {
366 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
367 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
368 ntohs(rxr_PortOf(*tconn))));
369 if (MultiProbeAlternateAddress_r(thost)) {
371 ("MultiProbe failed to find new address for host %s:%d\n",
372 afs_inet_ntoa_r(thost->host, hoststr),
373 ntohs(thost->port)));
377 ("MultiProbe found new address for host %s:%d\n",
378 afs_inet_ntoa_r(thost->host, hoststr),
379 ntohs(thost->port)));
380 if (BreakDelayedCallBacks_r(thost)) {
382 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
383 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
384 ntohs(rxr_PortOf(*tconn))));
393 h_ReleaseClient_r(tclient);
403 CallPostamble(register struct rx_connection *aconn, afs_int32 ret,
407 struct client *tclient;
412 tclient = h_FindClient_r(aconn);
413 thost = tclient->host;
414 if (thost->hostFlags & HERRORTRANS)
416 h_ReleaseClient_r(tclient);
417 held = h_Held_r(thost);
420 if (ahost != thost) {
421 char hoststr[16], hoststr2[16];
422 ViceLog(0, ("CallPostamble: ahost %s:%d (%x) != thost %s:%d (%x)\n",
423 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port),
425 afs_inet_ntoa_r(thost->host, hoststr2), ntohs(thost->port),
430 return (translate ? sys_error_to_et(ret) : ret);
434 * Returns the volume and vnode pointers associated with file Fid; the lock
435 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
436 * are incremented and they must be eventualy released.
439 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
442 afs_int32 local_errorCode, errorCode = -1;
443 static struct timeval restartedat = { 0, 0 };
445 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
447 if ((*volptr) == 0) {
452 *volptr = VGetVolume(&local_errorCode, &errorCode, (afs_int32) fid->Volume);
457 if ((errorCode == VOFFLINE) && (VInit < 2)) {
458 /* The volume we want may not be attached yet because
459 * the volume initialization is not yet complete.
460 * We can do several things:
461 * 1. return -1, which will cause users to see
462 * "connection timed out". This is more or
463 * less the same as always, except that the servers
464 * may appear to bounce up and down while they
465 * are actually restarting.
466 * 2. return VBUSY which will cause clients to
467 * sleep and retry for 6.5 - 15 minutes, depending
468 * on what version of the CM they are running. If
469 * the file server takes longer than that interval
470 * to attach the desired volume, then the application
471 * will see an ENODEV or EIO. This approach has
472 * the advantage that volumes which have been attached
473 * are immediately available, it keeps the server's
474 * immediate backlog low, and the call is interruptible
475 * by the user. Users see "waiting for busy volume."
476 * 3. sleep here and retry. Some people like this approach
477 * because there is no danger of seeing errors. However,
478 * this approach only works with a bounded number of
479 * clients, since the pending queues will grow without
480 * stopping. It might be better to find a way to take
481 * this call and stick it back on a queue in order to
482 * recycle this thread for a different request.
483 * 4. Return a new error code, which new cache managers will
484 * know enough to interpret as "sleep and retry", without
485 * the upper bound of 6-15 minutes that is imposed by the
486 * VBUSY handling. Users will see "waiting for
487 * busy volume," so they know that something is
488 * happening. Old cache managers must be able to do
489 * something reasonable with this, for instance, mark the
490 * server down. Fortunately, any error code < 0
491 * will elicit that behavior. See #1.
492 * 5. Some combination of the above. I like doing #2 for 10
493 * minutes, followed by #4. 3.1b and 3.2 cache managers
494 * will be fine as long as the restart period is
495 * not longer than 6.5 minutes, otherwise they may
496 * return ENODEV to users. 3.3 cache managers will be
497 * fine for 10 minutes, then will return
498 * ETIMEDOUT. 3.4 cache managers will just wait
499 * until the call works or fails definitively.
500 * NB. The problem with 2,3,4,5 is that old clients won't
501 * fail over to an alternate read-only replica while this
502 * server is restarting. 3.4 clients will fail over right away.
504 if (restartedat.tv_sec == 0) {
505 /* I'm not really worried about when we restarted, I'm */
506 /* just worried about when the first VBUSY was returned. */
507 TM_GetTimeOfDay(&restartedat, 0);
510 afs_perfstats.fs_nBusies++;
513 return (busyonrst ? VBUSY : VRESTARTING);
516 TM_GetTimeOfDay(&now, 0);
517 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
520 afs_perfstats.fs_nBusies++;
523 return (busyonrst ? VBUSY : VRESTARTING);
525 return (VRESTARTING);
529 /* allow read operations on busy volume.
530 * must check local_errorCode because demand attach fs
531 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
532 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
535 } else if (errorCode)
542 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
545 if ((*vptr)->disk.uniquifier != fid->Unique) {
546 VPutVnode(&fileCode, *vptr);
547 assert(fileCode == 0);
549 return (VNOVNODE); /* return the right error code, at least */
555 * This routine returns the ACL associated with the targetptr. If the
556 * targetptr isn't a directory, we access its parent dir and get the ACL
557 * thru the parent; in such case the parent's vnode is returned in
561 SetAccessList(Vnode ** targetptr, Volume ** volume,
562 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
563 AFSFid * Fid, int Lock)
565 if ((*targetptr)->disk.type == vDirectory) {
567 *ACL = VVnodeACL(*targetptr);
568 *ACLSize = VAclSize(*targetptr);
576 parentvnode = (*targetptr)->disk.parent;
577 VPutVnode(&errorCode, *targetptr);
581 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
584 *ACL = VVnodeACL(*parent);
585 *ACLSize = VAclSize(*parent);
586 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
588 if ((*targetptr)->disk.parent != parentvnode) {
589 VPutVnode(&errorCode, *parent);
600 /* Must not be called with H_LOCK held */
602 client_CheckRights(struct client *client, struct acl_accessList *ACL,
606 ObtainReadLock(&client->lock);
607 if (client->CPS.prlist_len > 0 && !client->deleted &&
608 client->host && !(client->host->hostFlags & HOSTDELETED))
609 acl_CheckRights(ACL, &client->CPS, rights);
610 ReleaseReadLock(&client->lock);
613 /* Must not be called with H_LOCK held */
615 client_HasAsMember(struct client *client, afs_int32 id)
619 ObtainReadLock(&client->lock);
620 if (client->CPS.prlist_len > 0 && !client->deleted &&
621 client->host && !(client->host->hostFlags & HOSTDELETED))
622 code = acl_IsAMember(id, &client->CPS);
623 ReleaseReadLock(&client->lock);
628 * Compare the directory's ACL with the user's access rights in the client
629 * connection and return the user's and everybody else's access permissions
630 * in rights and anyrights, respectively
633 GetRights(struct client *client, struct acl_accessList *ACL,
634 afs_int32 * rights, afs_int32 * anyrights)
636 extern prlist SystemAnyUserCPS;
637 afs_int32 hrights = 0;
638 #ifndef AFS_PTHREAD_ENV
642 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
643 ViceLog(0, ("CheckRights failed\n"));
648 client_CheckRights(client, ACL, rights);
650 /* wait if somebody else is already doing the getCPS call */
652 while (client->host->hostFlags & HCPS_INPROGRESS) {
653 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
654 #ifdef AFS_PTHREAD_ENV
655 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
656 #else /* AFS_PTHREAD_ENV */
658 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
659 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
660 #endif /* AFS_PTHREAD_ENV */
663 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
666 ("CheckRights: len=%u, for host=%s:%d\n",
667 client->host->hcps.prlist_len,
668 afs_inet_ntoa_r(client->host->host, hoststr),
669 ntohs(client->host->port)));
671 acl_CheckRights(ACL, &client->host->hcps, &hrights);
673 /* Allow system:admin the rights given with the -implicit option */
674 if (client_HasAsMember(client, SystemId))
675 *rights |= implicitAdminRights;
678 *anyrights |= hrights;
685 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
686 * a System:Administrator)
689 VanillaUser(struct client *client)
691 if (client_HasAsMember(client, SystemId))
692 return (0); /* not a system administrator, then you're "vanilla" */
699 * This unusual afs_int32-parameter routine encapsulates all volume package related
700 * operations together in a single function; it's called by almost all AFS
704 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
705 Vnode ** targetptr, int chkforDir, Vnode ** parent,
706 struct client **client, int locktype, afs_int32 * rights,
707 afs_int32 * anyrights)
709 struct acl_accessList *aCL; /* Internal access List */
710 int aCLSize; /* size of the access list */
711 int errorCode = 0; /* return code to caller */
713 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
716 if (chkforDir == MustNOTBeDIR
717 && ((*targetptr)->disk.type == vDirectory))
719 else if (chkforDir == MustBeDIR
720 && ((*targetptr)->disk.type != vDirectory))
724 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
725 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
726 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
728 if (chkforDir == MustBeDIR)
729 assert((*parent) == 0);
731 if ((errorCode = GetClient(tcon, client)) != 0)
736 GetRights(*client, aCL, rights, anyrights);
737 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
738 if ((*targetptr)->disk.type != vDirectory) {
739 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
740 if ((*targetptr)->disk.owner == (*client)->ViceId)
741 (*rights) |= PRSFS_ADMINISTER;
743 (*rights) &= ~PRSFS_ADMINISTER;
745 #ifdef ADMIN_IMPLICIT_LOOKUP
746 /* admins get automatic lookup on everything */
747 if (!VanillaUser(*client))
748 (*rights) |= PRSFS_LOOKUP;
749 #endif /* ADMIN_IMPLICIT_LOOKUP */
752 } /*GetVolumePackage */
756 * This is the opposite of GetVolumePackage(), and is always used at the end of
757 * AFS calls to put back all used vnodes and the volume in the proper order!
760 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
761 Vnode * parentptr, Volume * volptr, struct client **client)
763 int fileCode = 0; /* Error code returned by the volume package */
765 if (parentwhentargetnotdir) {
766 VPutVnode(&fileCode, parentwhentargetnotdir);
767 assert(!fileCode || (fileCode == VSALVAGE));
770 VPutVnode(&fileCode, targetptr);
771 assert(!fileCode || (fileCode == VSALVAGE));
774 VPutVnode(&fileCode, parentptr);
775 assert(!fileCode || (fileCode == VSALVAGE));
783 } /*PutVolumePackage */
786 VolumeOwner(register struct client *client, register Vnode * targetptr)
788 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
791 return (client->ViceId == owner);
794 * We don't have to check for host's cps since only regular
795 * viceid are volume owners.
797 return (client_HasAsMember(client, owner));
803 VolumeRootVnode(Vnode * targetptr)
805 return ((targetptr->vnodeNumber == ROOTVNODE)
806 && (targetptr->disk.uniquifier == 1));
808 } /*VolumeRootVnode */
811 * Check if target file has the proper access permissions for the Fetch
812 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
813 * StoreStatus) related calls
815 /* this code should probably just set a "priv" flag where all the audit events
816 * are now, and only generate the audit event once at the end of the routine,
817 * thus only generating the event if all the checks succeed, but only because
818 * of the privilege XXX
821 Check_PermissionRights(Vnode * targetptr, struct client *client,
822 afs_int32 rights, int CallingRoutine,
823 AFSStoreStatus * InStatus)
826 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
827 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
828 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
830 if (CallingRoutine & CHK_FETCH) {
831 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
832 if (targetptr->disk.type == vDirectory
833 || targetptr->disk.type == vSymlink) {
834 if (!(rights & PRSFS_LOOKUP)
835 #ifdef ADMIN_IMPLICIT_LOOKUP
836 /* grant admins fetch on all directories */
837 && VanillaUser(client)
838 #endif /* ADMIN_IMPLICIT_LOOKUP */
839 && !VolumeOwner(client, targetptr))
842 /* must have read access, or be owner and have insert access */
843 if (!(rights & PRSFS_READ)
844 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
847 if (CallingRoutine == CHK_FETCHDATA
848 && targetptr->disk.type == vFile)
849 #ifdef USE_GROUP_PERMS
850 if (!OWNSp(client, targetptr)
851 && !client_HasAsMember(client, targetptr->disk.owner)) {
853 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
857 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
862 * The check with the ownership below is a kludge to allow
863 * reading of files created with no read permission. The owner
864 * of the file is always allowed to read it.
866 if ((client->ViceId != targetptr->disk.owner)
867 && VanillaUser(client))
869 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
870 modeBits) ? 0 : EACCES);
872 } else { /* !VanillaUser(client) && !FetchData */
874 osi_audit(PrivilegeEvent, 0, AUD_ID,
875 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
878 } else { /* a store operation */
879 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
880 && (CallingRoutine != CHK_STOREACL)
881 && (targetptr->disk.type == vFile)) {
882 /* bypass protection checks on first store after a create
883 * for the creator; also prevent chowns during this time
884 * unless you are a system administrator */
885 /****** InStatus->Owner && UnixModeBits better be SET!! */
886 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
889 else if (VanillaUser(client))
890 return (EPERM); /* Was EACCES */
892 osi_audit(PrivilegeEvent, 0, AUD_ID,
893 (client ? client->ViceId : 0), AUD_INT,
894 CallingRoutine, AUD_END);
897 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
898 osi_audit(PrivilegeEvent, 0, AUD_ID,
899 (client ? client->ViceId : 0), AUD_INT,
900 CallingRoutine, AUD_END);
902 if (readonlyServer) {
905 if (CallingRoutine == CHK_STOREACL) {
906 if (!(rights & PRSFS_ADMINISTER)
907 && !VolumeOwner(client, targetptr))
909 } else { /* store data or status */
910 /* watch for chowns and chgrps */
911 if (CHOWN(InStatus, targetptr)
912 || CHGRP(InStatus, targetptr)) {
915 else if (VanillaUser(client))
916 return (EPERM); /* Was EACCES */
918 osi_audit(PrivilegeEvent, 0, AUD_ID,
919 (client ? client->ViceId : 0), AUD_INT,
920 CallingRoutine, AUD_END);
922 /* must be sysadmin to set suid/sgid bits */
923 if ((InStatus->Mask & AFS_SETMODE) &&
925 (InStatus->UnixModeBits & 0xc00) != 0) {
927 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
931 if (VanillaUser(client))
934 osi_audit(PrivSetID, 0, AUD_ID,
935 (client ? client->ViceId : 0), AUD_INT,
936 CallingRoutine, AUD_END);
938 if (CallingRoutine == CHK_STOREDATA) {
941 if (!(rights & PRSFS_WRITE))
943 /* Next thing is tricky. We want to prevent people
944 * from writing files sans 0200 bit, but we want
945 * creating new files with 0444 mode to work. We
946 * don't check the 0200 bit in the "you are the owner"
947 * path above, but here we check the bit. However, if
948 * you're a system administrator, we ignore the 0200
949 * bit anyway, since you may have fchowned the file,
951 #ifdef USE_GROUP_PERMS
952 if ((targetptr->disk.type == vFile)
953 && VanillaUser(client)) {
954 if (!OWNSp(client, targetptr)
955 && !client_HasAsMember(client, targetptr->disk.owner)) {
957 ((GROUPWRITE & targetptr->disk.modeBits)
961 ((OWNERWRITE & targetptr->disk.modeBits)
966 if ((targetptr->disk.type != vDirectory)
967 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
970 if (VanillaUser(client))
973 osi_audit(PrivilegeEvent, 0, AUD_ID,
974 (client ? client->ViceId : 0),
975 AUD_INT, CallingRoutine, AUD_END);
977 } else { /* a status store */
980 if (targetptr->disk.type == vDirectory) {
981 if (!(rights & PRSFS_DELETE)
982 && !(rights & PRSFS_INSERT))
984 } else { /* a file or symlink */
985 if (!(rights & PRSFS_WRITE))
995 } /*Check_PermissionRights */
999 * The Access List information is converted from its internal form in the
1000 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1001 * external form and returned back to the caller, via the AccessList
1005 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1006 struct AFSOpaque *AccessList)
1008 char *eACL; /* External access list placeholder */
1011 ((targetptr->disk.type ==
1012 vDirectory ? VVnodeACL(targetptr) :
1013 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1016 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1017 acl_FreeExternalACL(&eACL);
1020 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1021 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1023 acl_FreeExternalACL(&eACL);
1026 } /*RXFetch_AccessList */
1030 * The Access List information is converted from its external form in the
1031 * input AccessList structure to the internal representation and copied into
1032 * the target dir's vnode storage.
1035 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1037 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1039 if (acl_Internalize(AccessList->AFSOpaque_val, &newACL) != 0)
1041 if ((newACL->size + 4) > VAclSize(targetptr))
1043 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1044 acl_FreeACL(&newACL);
1047 } /*RXStore_AccessList */
1050 /* In our current implementation, each successive data store (new file
1051 * data version) creates a new inode. This function creates the new
1052 * inode, copies the old inode's contents to the new one, remove the old
1053 * inode (i.e. decrement inode count -- if it's currently used the delete
1054 * will be delayed), and modify some fields (i.e. vnode's
1055 * disk.inodeNumber and cloned)
1057 #define COPYBUFFSIZE 8192
1059 CopyOnWrite(Vnode * targetptr, Volume * volptr)
1061 Inode ino, nearInode;
1064 register afs_fsize_t size;
1065 register int length;
1067 int rc; /* return code */
1068 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1069 FdHandle_t *targFdP; /* Source Inode file handle */
1070 FdHandle_t *newFdP; /* Dest Inode file handle */
1072 if (targetptr->disk.type == vDirectory)
1073 DFlush(); /* just in case? */
1075 VN_GET_LEN(size, targetptr);
1076 buff = (char *)malloc(COPYBUFFSIZE);
1081 ino = VN_GET_INO(targetptr);
1082 assert(VALID_INO(ino));
1083 targFdP = IH_OPEN(targetptr->handle);
1084 if (targFdP == NULL) {
1087 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1088 targetptr->vnodeNumber, V_id(volptr), rc));
1090 VTakeOffline(volptr);
1094 nearInode = VN_GET_INO(targetptr);
1096 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1097 VPartitionPath(V_partition(volptr)), nearInode,
1098 V_id(volptr), targetptr->vnodeNumber,
1099 targetptr->disk.uniquifier,
1100 (int)targetptr->disk.dataVersion);
1101 if (!VALID_INO(ino)) {
1103 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1104 volptr->partition->name, V_id(volptr), errno));
1109 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1110 newFdP = IH_OPEN(newH);
1111 assert(newFdP != NULL);
1114 if (size > COPYBUFFSIZE) { /* more than a buffer */
1115 length = COPYBUFFSIZE;
1116 size -= COPYBUFFSIZE;
1121 rdlen = FDH_READ(targFdP, buff, length);
1122 if (rdlen == length)
1123 wrlen = FDH_WRITE(newFdP, buff, length);
1126 /* Callers of this function are not prepared to recover
1127 * from error that put the filesystem in an inconsistent
1128 * state. Make sure that we force the volume off-line if
1129 * we some error other than ENOSPC - 4.29.99)
1131 * In case we are unable to write the required bytes, and the
1132 * error code indicates that the disk is full, we roll-back to
1133 * the initial state.
1135 if ((rdlen != length) || (wrlen != length))
1136 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1138 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1139 volptr->partition->name, V_id(volptr)));
1140 /* remove destination inode which was partially copied till now */
1141 FDH_REALLYCLOSE(newFdP);
1143 FDH_REALLYCLOSE(targFdP);
1144 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1147 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1148 rc, V_id(volptr), volptr->partition->name));
1149 VTakeOffline(volptr);
1155 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1156 V_id(volptr), volptr->partition->name, length, rdlen,
1158 #ifdef FAST_RESTART /* if running in no-salvage, don't core the server */
1159 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1160 #elif defined(AFS_DEMAND_ATTACH_FS)
1161 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1162 #else /* Avoid further corruption and try to get a core. */
1165 /* Decrement this inode so salvager doesn't find it. */
1166 FDH_REALLYCLOSE(newFdP);
1168 FDH_REALLYCLOSE(targFdP);
1169 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1171 VTakeOffline(volptr);
1174 #ifndef AFS_PTHREAD_ENV
1176 #endif /* !AFS_PTHREAD_ENV */
1178 FDH_REALLYCLOSE(targFdP);
1179 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1180 V_parentId(volptr));
1182 IH_RELEASE(targetptr->handle);
1184 rc = FDH_SYNC(newFdP);
1187 targetptr->handle = newH;
1188 VN_SET_INO(targetptr, ino);
1189 targetptr->disk.cloned = 0;
1190 /* Internal change to vnode, no user level change to volume - def 5445 */
1191 targetptr->changed_oldTime = 1;
1193 return 0; /* success */
1198 * Common code to handle with removing the Name (file when it's called from
1199 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1200 * given directory, parentptr.
1202 int DT1 = 0, DT0 = 0;
1204 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1205 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1207 DirHandle childdir; /* Handle for dir package I/O */
1211 /* watch for invalid names */
1212 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1214 if (parentptr->disk.cloned) {
1215 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1216 if ((errorCode = CopyOnWrite(parentptr, volptr))) {
1218 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1224 /* check that the file is in the directory */
1225 SetDirHandle(dir, parentptr);
1226 if (Lookup(dir, Name, fileFid))
1228 fileFid->Volume = V_id(volptr);
1230 /* just-in-case check for something causing deadlock */
1231 if (fileFid->Vnode == parentptr->vnodeNumber)
1234 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1238 if (ChkForDir == MustBeDIR) {
1239 if ((*targetptr)->disk.type != vDirectory)
1241 } else if ((*targetptr)->disk.type == vDirectory)
1244 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1246 * If the uniquifiers dont match then instead of asserting
1247 * take the volume offline and return VSALVAGE
1249 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1250 VTakeOffline(volptr);
1251 errorCode = VSALVAGE;
1255 if (ChkForDir == MustBeDIR) {
1256 SetDirHandle(&childdir, *targetptr);
1257 if (IsEmpty(&childdir) != 0)
1260 (*targetptr)->delete = 1;
1261 } else if ((--(*targetptr)->disk.linkCount) == 0)
1262 (*targetptr)->delete = 1;
1263 if ((*targetptr)->delete) {
1264 if (VN_GET_INO(*targetptr)) {
1266 IH_REALLYCLOSE((*targetptr)->handle);
1268 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1269 V_parentId(volptr));
1270 IH_RELEASE((*targetptr)->handle);
1271 if (errorCode == -1) {
1273 ("DT: inode=%s, name=%s, errno=%d\n",
1274 PrintInode(NULL, VN_GET_INO(*targetptr)), Name,
1276 if (errno != ENOENT)
1279 ("Volume %u now offline, must be salvaged.\n",
1281 VTakeOffline(volptr);
1288 VN_SET_INO(*targetptr, (Inode) 0);
1290 afs_fsize_t adjLength;
1291 VN_GET_LEN(adjLength, *targetptr);
1292 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1296 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1298 code = Delete(dir, (char *)Name);
1301 ("Error %d deleting %s\n", code,
1302 (((*targetptr)->disk.type ==
1303 Directory) ? "directory" : "file")));
1305 ("Volume %u now offline, must be salvaged.\n",
1307 VTakeOffline(volptr);
1319 * This routine updates the parent directory's status block after the
1320 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1321 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1325 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1326 int author, int linkcount,
1327 #if FS_STATS_DETAILED
1328 char a_inSameNetwork
1329 #endif /* FS_STATS_DETAILED */
1332 afs_fsize_t newlength; /* Holds new directory length */
1333 afs_fsize_t parentLength;
1335 #if FS_STATS_DETAILED
1336 Date currDate; /*Current date */
1337 int writeIdx; /*Write index to bump */
1338 int timeIdx; /*Authorship time index to bump */
1339 #endif /* FS_STATS_DETAILED */
1341 parentptr->disk.dataVersion++;
1342 newlength = (afs_fsize_t) Length(dir);
1344 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1345 * (create, symlink, link, makedir) so we need to check if we have enough space
1346 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1347 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1349 VN_GET_LEN(parentLength, parentptr);
1350 if (nBlocks(newlength) != nBlocks(parentLength)) {
1351 VAdjustDiskUsage(&errorCode, volptr,
1352 (nBlocks(newlength) - nBlocks(parentLength)),
1353 (nBlocks(newlength) - nBlocks(parentLength)));
1355 VN_SET_LEN(parentptr, newlength);
1357 #if FS_STATS_DETAILED
1359 * Update directory write stats for this volume. Note that the auth
1360 * counter is located immediately after its associated ``distance''
1363 if (a_inSameNetwork)
1364 writeIdx = VOL_STATS_SAME_NET;
1366 writeIdx = VOL_STATS_DIFF_NET;
1367 V_stat_writes(volptr, writeIdx)++;
1368 if (author != AnonymousID) {
1369 V_stat_writes(volptr, writeIdx + 1)++;
1373 * Update the volume's authorship information in response to this
1374 * directory operation. Get the current time, decide to which time
1375 * slot this operation belongs, and bump the appropriate slot.
1377 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1379 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1380 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1381 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1382 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1383 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1384 if (parentptr->disk.author == author) {
1385 V_stat_dirSameAuthor(volptr, timeIdx)++;
1387 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1389 #endif /* FS_STATS_DETAILED */
1391 parentptr->disk.author = author;
1392 parentptr->disk.linkCount = linkcount;
1393 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1394 parentptr->disk.serverModifyTime = FT_ApproxTime();
1395 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1400 * Update the target file's (or dir's) status block after the specified
1401 * operation is complete. Note that some other fields maybe updated by
1402 * the individual module.
1405 /* XXX INCOMPLETE - More attention is needed here! */
1407 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1408 struct client *client, AFSStoreStatus * InStatus,
1409 Vnode * parentptr, Volume * volptr,
1412 #if FS_STATS_DETAILED
1413 Date currDate; /*Current date */
1414 int writeIdx; /*Write index to bump */
1415 int timeIdx; /*Authorship time index to bump */
1416 #endif /* FS_STATS_DETAILED */
1418 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1419 targetptr->disk.parent = parentptr->vnodeNumber;
1420 VN_SET_LEN(targetptr, length);
1421 /* targetptr->disk.group = 0; save some cycles */
1422 targetptr->disk.modeBits = 0777;
1423 targetptr->disk.owner = client->ViceId;
1424 targetptr->disk.dataVersion = 0; /* consistent with the client */
1425 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1426 /* the inode was created in Alloc_NewVnode() */
1428 #if FS_STATS_DETAILED
1430 * Update file write stats for this volume. Note that the auth
1431 * counter is located immediately after its associated ``distance''
1434 if (client->InSameNetwork)
1435 writeIdx = VOL_STATS_SAME_NET;
1437 writeIdx = VOL_STATS_DIFF_NET;
1438 V_stat_writes(volptr, writeIdx)++;
1439 if (client->ViceId != AnonymousID) {
1440 V_stat_writes(volptr, writeIdx + 1)++;
1444 * We only count operations that DON'T involve creating new objects
1445 * (files, symlinks, directories) or simply setting status as
1446 * authorship-change operations.
1448 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1450 * Update the volume's authorship information in response to this
1451 * file operation. Get the current time, decide to which time
1452 * slot this operation belongs, and bump the appropriate slot.
1454 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1457 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1458 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1459 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1460 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1461 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1462 VOL_STATS_TIME_IDX_5);
1463 if (targetptr->disk.author == client->ViceId) {
1464 V_stat_fileSameAuthor(volptr, timeIdx)++;
1466 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1469 #endif /* FS_STATS_DETAILED */
1471 if (!(Caller & TVS_SSTATUS))
1472 targetptr->disk.author = client->ViceId;
1473 if (Caller & TVS_SDATA) {
1474 targetptr->disk.dataVersion++;
1475 if (VanillaUser(client)) {
1476 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1477 #ifdef CREATE_SGUID_ADMIN_ONLY
1478 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1482 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1483 /* store status, must explicitly request to change the date */
1484 if (InStatus->Mask & AFS_SETMODTIME)
1485 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1486 } else { /* other: date always changes, but perhaps to what is specified by caller */
1487 targetptr->disk.unixModifyTime =
1488 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1489 ClientModTime : FT_ApproxTime());
1491 if (InStatus->Mask & AFS_SETOWNER) {
1492 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1493 if (VanillaUser(client)) {
1494 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1495 #ifdef CREATE_SGUID_ADMIN_ONLY
1496 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1499 targetptr->disk.owner = InStatus->Owner;
1500 if (VolumeRootVnode(targetptr)) {
1501 Error errorCode = 0; /* what should be done with this? */
1503 V_owner(targetptr->volumePtr) = InStatus->Owner;
1504 VUpdateVolume(&errorCode, targetptr->volumePtr);
1507 if (InStatus->Mask & AFS_SETMODE) {
1508 int modebits = InStatus->UnixModeBits;
1509 #define CREATE_SGUID_ADMIN_ONLY 1
1510 #ifdef CREATE_SGUID_ADMIN_ONLY
1511 if (VanillaUser(client))
1512 modebits = modebits & 0777;
1514 if (VanillaUser(client)) {
1515 targetptr->disk.modeBits = modebits;
1517 targetptr->disk.modeBits = modebits;
1520 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1521 CHK_STOREDATA, AUD_END);
1525 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1526 CHK_STORESTATUS, AUD_END);
1533 targetptr->disk.serverModifyTime = FT_ApproxTime();
1534 if (InStatus->Mask & AFS_SETGROUP)
1535 targetptr->disk.group = InStatus->Group;
1536 /* vnode changed : to be written back by VPutVnode */
1537 targetptr->changed_newTime = 1;
1539 } /*Update_TargetVnodeStatus */
1543 * Fills the CallBack structure with the expiration time and type of callback
1544 * structure. Warning: this function is currently incomplete.
1547 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1549 /* CallBackTime could not be 0 */
1550 if (CallBackTime == 0) {
1551 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1552 CallBack->ExpirationTime = 0;
1554 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1555 CallBack->CallBackVersion = CALLBACK_VERSION;
1556 CallBack->CallBackType = CB_SHARED; /* The default for now */
1558 } /*SetCallBackStruct */
1562 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1563 * allocation; if some error occured (exceeded volume quota or partition
1564 * was full, or whatever), it frees the space back and returns the code.
1565 * We usually pre-adjust the volume space to make sure that there's
1566 * enough space before consuming some.
1569 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1570 afs_sfsize_t checkLength)
1575 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1577 VAdjustDiskUsage(&nc, volptr, -length, 0);
1578 if (rc == VOVERQUOTA) {
1580 ("Volume %u (%s) is full\n", V_id(volptr),
1584 if (rc == VDISKFULL) {
1586 ("Partition %s that contains volume %u is full\n",
1587 volptr->partition->name, V_id(volptr)));
1590 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1595 } /*AdjustDiskUsage */
1598 * Common code that handles the creation of a new file (SAFS_CreateFile and
1599 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1602 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1603 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1604 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1606 int errorCode = 0; /* Error code returned back */
1609 Inode nearInode; /* hint for inode allocation in solaris */
1612 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1613 BlocksPreallocatedForVnode))) {
1615 ("Insufficient space to allocate %lld blocks\n",
1616 (afs_intmax_t) BlocksPreallocatedForVnode));
1620 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1621 if (errorCode != 0) {
1622 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1625 OutFid->Volume = V_id(volptr);
1626 OutFid->Vnode = (*targetptr)->vnodeNumber;
1627 OutFid->Unique = (*targetptr)->disk.uniquifier;
1629 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1631 /* create the inode now itself */
1633 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1634 VPartitionPath(V_partition(volptr)), nearInode,
1635 V_id(volptr), (*targetptr)->vnodeNumber,
1636 (*targetptr)->disk.uniquifier, 1);
1638 /* error in creating inode */
1639 if (!VALID_INO(inode)) {
1641 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1642 (*targetptr)->volumePtr->header->diskstuff.id,
1643 (*targetptr)->vnodeNumber, errno));
1644 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1645 (*targetptr)->delete = 1; /* delete vnode */
1648 VN_SET_INO(*targetptr, inode);
1649 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1651 /* copy group from parent dir */
1652 (*targetptr)->disk.group = parentptr->disk.group;
1654 if (parentptr->disk.cloned) {
1655 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1656 if ((errorCode = CopyOnWrite(parentptr, volptr))) { /* disk full */
1657 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1658 /* delete the vnode previously allocated */
1659 (*targetptr)->delete = 1;
1660 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1661 IH_REALLYCLOSE((*targetptr)->handle);
1662 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1664 ("Alloc_NewVnode: partition %s idec %s failed\n",
1665 volptr->partition->name, PrintInode(NULL, inode)));
1666 IH_RELEASE((*targetptr)->handle);
1672 /* add the name to the directory */
1673 SetDirHandle(dir, parentptr);
1674 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1675 (*targetptr)->delete = 1;
1676 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1677 IH_REALLYCLOSE((*targetptr)->handle);
1678 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1680 ("Alloc_NewVnode: partition %s idec %s failed\n",
1681 volptr->partition->name, PrintInode(NULL, inode)));
1682 IH_RELEASE((*targetptr)->handle);
1688 } /*Alloc_NewVnode */
1692 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1696 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1698 int Time; /* Used for time */
1699 int writeVnode = targetptr->changed_oldTime; /* save original status */
1701 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1702 Time = FT_ApproxTime();
1703 switch (LockingType) {
1706 if (Time > targetptr->disk.lock.lockTime)
1707 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1709 Time += AFS_LOCKWAIT;
1710 if (LockingType == LockRead) {
1711 if ( !(rights & PRSFS_LOCK) )
1714 if (targetptr->disk.lock.lockCount >= 0) {
1715 ++(targetptr->disk.lock.lockCount);
1716 targetptr->disk.lock.lockTime = Time;
1719 } else if (LockingType == LockWrite) {
1720 if ( !(rights & PRSFS_WRITE) &&
1721 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1724 if (targetptr->disk.lock.lockCount == 0) {
1725 targetptr->disk.lock.lockCount = -1;
1726 targetptr->disk.lock.lockTime = Time;
1732 Time += AFS_LOCKWAIT;
1733 if (targetptr->disk.lock.lockCount != 0)
1734 targetptr->disk.lock.lockTime = Time;
1739 if ((--targetptr->disk.lock.lockCount) <= 0)
1740 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1744 targetptr->changed_oldTime = writeVnode; /* restore old status */
1745 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1748 } /*HandleLocking */
1750 /* 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. */
1753 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1757 if (!(rights & Prfs_Mode))
1759 if ((targetptr->disk.type != vDirectory)
1760 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1766 * If some flags (i.e. min or max quota) are set, the volume's in disk
1767 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1768 * update, if applicable.
1771 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1772 char *Name, char *OfflineMsg, char *Motd)
1774 Error errorCode = 0;
1776 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1777 V_minquota(volptr) = StoreVolStatus->MinQuota;
1778 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1779 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1780 if (strlen(OfflineMsg) > 0) {
1781 strcpy(V_offlineMessage(volptr), OfflineMsg);
1783 if (strlen(Name) > 0) {
1784 strcpy(V_name(volptr), Name);
1786 #if OPENAFS_VOL_STATS
1788 * We don't overwrite the motd field, since it's now being used
1792 if (strlen(Motd) > 0) {
1793 strcpy(V_motd(volptr), Motd);
1795 #endif /* FS_STATS_DETAILED */
1796 VUpdateVolume(&errorCode, volptr);
1799 } /*RXUpdate_VolumeStatus */
1803 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1804 char **motd, Volume * volptr)
1808 status->Vid = V_id(volptr);
1809 status->ParentId = V_parentId(volptr);
1810 status->Online = V_inUse(volptr);
1811 status->InService = V_inService(volptr);
1812 status->Blessed = V_blessed(volptr);
1813 status->NeedsSalvage = V_needsSalvaged(volptr);
1814 if (VolumeWriteable(volptr))
1815 status->Type = ReadWrite;
1817 status->Type = ReadOnly;
1818 status->MinQuota = V_minquota(volptr);
1819 status->MaxQuota = V_maxquota(volptr);
1820 status->BlocksInUse = V_diskused(volptr);
1821 status->PartBlocksAvail = volptr->partition->free;
1822 status->PartMaxBlocks = volptr->partition->totalUsable;
1824 /* now allocate and copy these things; they're freed by the RXGEN stub */
1825 temp = strlen(V_name(volptr)) + 1;
1826 *name = malloc(temp);
1828 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1831 strcpy(*name, V_name(volptr));
1832 temp = strlen(V_offlineMessage(volptr)) + 1;
1833 *offMsg = malloc(temp);
1835 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1838 strcpy(*offMsg, V_offlineMessage(volptr));
1839 #if OPENAFS_VOL_STATS
1842 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1845 strcpy(*motd, nullString);
1847 temp = strlen(V_motd(volptr)) + 1;
1848 *motd = malloc(temp);
1850 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1853 strcpy(*motd, V_motd(volptr));
1854 #endif /* FS_STATS_DETAILED */
1856 } /*RXGetVolumeStatus */
1860 FileNameOK(register char *aname)
1862 register afs_int32 i, tc;
1865 /* watch for @sys on the right */
1866 if (strcmp(aname + i - 4, "@sys") == 0)
1869 while ((tc = *aname++)) {
1871 return 0; /* very bad character to encounter */
1873 return 1; /* file name is ok */
1879 * This variant of symlink is expressly to support the AFS/DFS translator
1880 * and is not supported by the AFS fileserver. We just return EINVAL.
1881 * The cache manager should not generate this call to an AFS cache manager.
1884 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
1885 char *LinkContents, struct AFSStoreStatus *InStatus,
1886 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
1887 struct AFSFetchStatus *OutDirStatus,
1888 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
1894 SRXAFS_ResidencyCmd(struct rx_call * acall, struct AFSFid * Fid,
1895 struct ResidencyCmdInputs * Inputs,
1896 struct ResidencyCmdOutputs * Outputs)
1902 static struct afs_buffer {
1903 struct afs_buffer *next;
1904 } *freeBufferList = 0;
1905 static int afs_buffersAlloced = 0;
1908 FreeSendBuffer(register struct afs_buffer *adata)
1911 afs_buffersAlloced--;
1912 adata->next = freeBufferList;
1913 freeBufferList = adata;
1917 } /*FreeSendBuffer */
1919 /* allocate space for sender */
1923 register struct afs_buffer *tp;
1926 afs_buffersAlloced++;
1927 if (!freeBufferList) {
1930 tmp = malloc(sendBufSize);
1932 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
1937 tp = freeBufferList;
1938 freeBufferList = tp->next;
1942 } /*AllocSendBuffer */
1943 #endif /* AFS_NT40_ENV */
1946 * This routine returns the status info associated with the targetptr vnode
1947 * in the AFSFetchStatus structure. Some of the newer fields, such as
1948 * SegSize and Group are not yet implemented
1952 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
1953 afs_int32 anyrights, Vnode * parentptr)
1955 /* initialize return status from a vnode */
1956 status->InterfaceVersion = 1;
1957 status->SyncCounter = status->dataVersionHigh = status->lockCount =
1958 status->errorCode = 0;
1959 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
1960 if (targetptr->disk.type == vFile)
1961 status->FileType = File;
1962 else if (targetptr->disk.type == vDirectory)
1963 status->FileType = Directory;
1964 else if (targetptr->disk.type == vSymlink)
1965 status->FileType = SymbolicLink;
1967 status->FileType = Invalid; /*invalid type field */
1968 status->LinkCount = targetptr->disk.linkCount;
1970 afs_fsize_t targetLen;
1971 VN_GET_LEN(targetLen, targetptr);
1972 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
1974 status->DataVersion = targetptr->disk.dataVersion;
1975 status->Author = targetptr->disk.author;
1976 status->Owner = targetptr->disk.owner;
1977 status->CallerAccess = rights;
1978 status->AnonymousAccess = anyrights;
1979 status->UnixModeBits = targetptr->disk.modeBits;
1980 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
1981 status->ParentVnode =
1982 (status->FileType ==
1983 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
1984 status->ParentUnique =
1985 (status->FileType ==
1986 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
1987 status->ServerModTime = targetptr->disk.serverModifyTime;
1988 status->Group = targetptr->disk.group;
1989 status->lockCount = targetptr->disk.lock.lockCount;
1990 status->errorCode = 0;
1996 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
1997 afs_sfsize_t Pos, afs_sfsize_t Len,
1998 struct AFSFetchStatus *OutStatus,
1999 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2002 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2003 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2004 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2005 int errorCode = 0; /* return code to caller */
2006 int fileCode = 0; /* return code from vol package */
2007 Volume *volptr = 0; /* pointer to the volume */
2008 struct client *client = 0; /* pointer to the client data */
2009 struct rx_connection *tcon; /* the connection we're part of */
2011 afs_int32 rights, anyrights; /* rights for this and any user */
2012 struct client *t_client = NULL; /* tmp ptr to client data */
2013 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2014 #if FS_STATS_DETAILED
2015 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2016 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2017 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2018 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2019 struct timeval elapsedTime; /* Transfer time */
2020 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2021 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2022 int readIdx; /* Index of read stats array to bump */
2023 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2026 * Set our stats pointers, remember when the RPC operation started, and
2027 * tally the operation.
2029 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2030 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2034 TM_GetTimeOfDay(&opStartTime, 0);
2035 #endif /* FS_STATS_DETAILED */
2038 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2041 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2043 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2046 /* Get ptr to client data for user Id for logging */
2047 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2048 logHostAddr.s_addr = rxr_HostOf(tcon);
2050 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2051 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2052 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2054 * Get volume/vnode for the fetched file; caller's access rights to
2055 * it are also returned
2058 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2059 &parentwhentargetnotdir, &client, READ_LOCK,
2060 &rights, &anyrights)))
2063 SetVolumeSync(Sync, volptr);
2065 #if FS_STATS_DETAILED
2067 * Remember that another read operation was performed.
2070 if (client->InSameNetwork)
2071 readIdx = VOL_STATS_SAME_NET;
2073 readIdx = VOL_STATS_DIFF_NET;
2074 V_stat_reads(volptr, readIdx)++;
2075 if (client->ViceId != AnonymousID) {
2076 V_stat_reads(volptr, readIdx + 1)++;
2079 #endif /* FS_STATS_DETAILED */
2080 /* Check whether the caller has permission access to fetch the data */
2082 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2086 * Drop the read lock on the parent directory after saving the parent
2087 * vnode information we need to pass to GetStatus
2089 if (parentwhentargetnotdir != NULL) {
2090 tparentwhentargetnotdir = *parentwhentargetnotdir;
2091 VPutVnode(&fileCode, parentwhentargetnotdir);
2092 assert(!fileCode || (fileCode == VSALVAGE));
2093 parentwhentargetnotdir = NULL;
2095 #if FS_STATS_DETAILED
2097 * Remember when the data transfer started.
2099 TM_GetTimeOfDay(&xferStartTime, 0);
2100 #endif /* FS_STATS_DETAILED */
2102 /* actually do the data transfer */
2103 #if FS_STATS_DETAILED
2105 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2106 &bytesToXfer, &bytesXferred);
2109 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2111 #endif /* FS_STATS_DETAILED */
2113 #if FS_STATS_DETAILED
2115 * At this point, the data transfer is done, for good or ill. Remember
2116 * when the transfer ended, bump the number of successes/failures, and
2117 * integrate the transfer size and elapsed time into the stats. If the
2118 * operation failed, we jump to the appropriate point.
2120 TM_GetTimeOfDay(&xferStopTime, 0);
2122 (xferP->numXfers)++;
2124 (xferP->numSuccesses)++;
2127 * Bump the xfer sum by the number of bytes actually sent, NOT the
2130 tot_bytesXferred += bytesXferred;
2131 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2132 tot_bytesXferred &= 0x3FF;
2133 if (bytesXferred < xferP->minBytes)
2134 xferP->minBytes = bytesXferred;
2135 if (bytesXferred > xferP->maxBytes)
2136 xferP->maxBytes = bytesXferred;
2139 * Tally the size of the object. Note: we tally the actual size,
2140 * NOT the number of bytes that made it out over the wire.
2142 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2143 (xferP->count[0])++;
2144 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2145 (xferP->count[1])++;
2146 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2147 (xferP->count[2])++;
2148 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2149 (xferP->count[3])++;
2150 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2151 (xferP->count[4])++;
2152 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2153 (xferP->count[5])++;
2154 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2155 (xferP->count[6])++;
2156 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2157 (xferP->count[7])++;
2159 (xferP->count[8])++;
2161 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2162 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2163 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2164 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2165 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2167 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2168 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2173 * Finally, go off to tell our caller the bad news in case the
2178 #endif /* FS_STATS_DETAILED */
2180 /* write back the OutStatus from the target vnode */
2181 GetStatus(targetptr, OutStatus, rights, anyrights,
2182 &tparentwhentargetnotdir);
2184 /* if a r/w volume, promise a callback to the caller */
2185 if (VolumeWriteable(volptr))
2186 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2188 struct AFSFid myFid;
2189 memset(&myFid, 0, sizeof(struct AFSFid));
2190 myFid.Volume = Fid->Volume;
2191 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2195 /* Update and store volume/vnode and parent vnodes back */
2196 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2198 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2199 errorCode = CallPostamble(tcon, errorCode, thost);
2201 #if FS_STATS_DETAILED
2202 TM_GetTimeOfDay(&opStopTime, 0);
2203 if (errorCode == 0) {
2205 (opP->numSuccesses)++;
2206 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2207 fs_stats_AddTo((opP->sumTime), elapsedTime);
2208 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2209 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2210 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2212 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2213 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2217 #endif /* FS_STATS_DETAILED */
2219 osi_auditU(acall, FetchDataEvent, errorCode,
2220 AUD_ID, t_client ? t_client->ViceId : 0,
2221 AUD_FID, Fid, AUD_END);
2224 } /*SRXAFS_FetchData */
2227 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2228 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2229 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2231 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2236 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2237 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2238 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2241 afs_sfsize_t tPos, tLen;
2243 #ifdef AFS_64BIT_ENV
2244 #ifndef AFS_LARGEFILE_ENV
2245 if (Pos + Len > 0x7fffffff)
2247 #endif /* !AFS_LARGEFILE_ENV */
2248 tPos = (afs_sfsize_t) Pos;
2249 tLen = (afs_sfsize_t) Len;
2250 #else /* AFS_64BIT_ENV */
2251 if (Pos.high || Len.high)
2255 #endif /* AFS_64BIT_ENV */
2258 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2264 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2265 struct AFSOpaque * AccessList,
2266 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2268 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2269 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2270 int errorCode = 0; /* return error code to caller */
2271 Volume *volptr = 0; /* pointer to the volume */
2272 struct client *client = 0; /* pointer to the client data */
2273 afs_int32 rights, anyrights; /* rights for this and any user */
2274 struct rx_connection *tcon = rx_ConnectionOf(acall);
2276 struct client *t_client = NULL; /* tmp ptr to client data */
2277 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2278 #if FS_STATS_DETAILED
2279 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2280 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2281 struct timeval elapsedTime; /* Transfer time */
2284 * Set our stats pointer, remember when the RPC operation started, and
2285 * tally the operation.
2287 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2291 TM_GetTimeOfDay(&opStartTime, 0);
2292 #endif /* FS_STATS_DETAILED */
2295 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2298 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2300 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2303 /* Get ptr to client data for user Id for logging */
2304 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2305 logHostAddr.s_addr = rxr_HostOf(tcon);
2307 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2308 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2309 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2311 AccessList->AFSOpaque_len = 0;
2312 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2313 if (!AccessList->AFSOpaque_val) {
2314 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2319 * Get volume/vnode for the fetched file; caller's access rights to it
2323 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2324 &parentwhentargetnotdir, &client, READ_LOCK,
2325 &rights, &anyrights)))
2328 SetVolumeSync(Sync, volptr);
2330 /* Check whether we have permission to fetch the ACL */
2332 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2335 /* Get the Access List from the dir's vnode */
2337 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2340 /* Get OutStatus back From the target Vnode */
2341 GetStatus(targetptr, OutStatus, rights, anyrights,
2342 parentwhentargetnotdir);
2345 /* Update and store volume/vnode and parent vnodes back */
2346 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2349 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2350 AccessList->AFSOpaque_val));
2351 errorCode = CallPostamble(tcon, errorCode, thost);
2353 #if FS_STATS_DETAILED
2354 TM_GetTimeOfDay(&opStopTime, 0);
2355 if (errorCode == 0) {
2357 (opP->numSuccesses)++;
2358 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2359 fs_stats_AddTo((opP->sumTime), elapsedTime);
2360 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2361 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2362 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2364 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2365 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2369 #endif /* FS_STATS_DETAILED */
2371 osi_auditU(acall, FetchACLEvent, errorCode,
2372 AUD_ID, t_client ? t_client->ViceId : 0,
2374 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2376 } /*SRXAFS_FetchACL */
2380 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2381 * merged into it when possible.
2385 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2386 struct AFSFetchStatus *OutStatus,
2387 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2389 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2390 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2391 int errorCode = 0; /* return code to caller */
2392 Volume *volptr = 0; /* pointer to the volume */
2393 struct client *client = 0; /* pointer to the client data */
2394 afs_int32 rights, anyrights; /* rights for this and any user */
2395 struct client *t_client = NULL; /* tmp ptr to client data */
2396 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2397 struct rx_connection *tcon = rx_ConnectionOf(acall);
2399 /* Get ptr to client data for user Id for logging */
2400 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2401 logHostAddr.s_addr = rxr_HostOf(tcon);
2403 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2404 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2405 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2407 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2410 * Get volume/vnode for the fetched file; caller's rights to it are
2414 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2415 &parentwhentargetnotdir, &client, READ_LOCK,
2416 &rights, &anyrights)))
2417 goto Bad_FetchStatus;
2419 /* set volume synchronization information */
2420 SetVolumeSync(Sync, volptr);
2422 /* Are we allowed to fetch Fid's status? */
2423 if (targetptr->disk.type != vDirectory) {
2425 Check_PermissionRights(targetptr, client, rights,
2426 CHK_FETCHSTATUS, 0))) {
2427 if (rx_GetCallAbortCode(acall) == errorCode)
2428 rx_SetCallAbortCode(acall, 0);
2429 goto Bad_FetchStatus;
2433 /* set OutStatus From the Fid */
2434 GetStatus(targetptr, OutStatus, rights, anyrights,
2435 parentwhentargetnotdir);
2437 /* If a r/w volume, also set the CallBack state */
2438 if (VolumeWriteable(volptr))
2439 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2441 struct AFSFid myFid;
2442 memset(&myFid, 0, sizeof(struct AFSFid));
2443 myFid.Volume = Fid->Volume;
2444 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2448 /* Update and store volume/vnode and parent vnodes back */
2449 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2451 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2454 } /*SAFSS_FetchStatus */
2458 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2459 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2460 struct AFSVolSync * Sync)
2464 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2465 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2466 int errorCode = 0; /* return code to caller */
2467 Volume *volptr = 0; /* pointer to the volume */
2468 struct client *client = 0; /* pointer to the client data */
2469 afs_int32 rights, anyrights; /* rights for this and any user */
2470 register struct AFSFid *tfid; /* file id we're dealing with now */
2471 struct rx_connection *tcon = rx_ConnectionOf(acall);
2473 struct client *t_client = NULL; /* tmp pointer to the client data */
2474 #if FS_STATS_DETAILED
2475 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2476 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2477 struct timeval elapsedTime; /* Transfer time */
2480 * Set our stats pointer, remember when the RPC operation started, and
2481 * tally the operation.
2483 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2487 TM_GetTimeOfDay(&opStartTime, 0);
2488 #endif /* FS_STATS_DETAILED */
2490 ViceLog(1, ("SAFS_BulkStatus\n"));
2492 AFSCallStats.TotalCalls++;
2494 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2495 if (nfiles <= 0) { /* Sanity check */
2497 goto Audit_and_Return;
2500 /* allocate space for return output parameters */
2501 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2502 malloc(nfiles * sizeof(struct AFSFetchStatus));
2503 if (!OutStats->AFSBulkStats_val) {
2504 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2507 OutStats->AFSBulkStats_len = nfiles;
2508 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2509 malloc(nfiles * sizeof(struct AFSCallBack));
2510 if (!CallBacks->AFSCBs_val) {
2511 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2514 CallBacks->AFSCBs_len = nfiles;
2516 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2517 goto Bad_BulkStatus;
2519 tfid = Fids->AFSCBFids_val;
2520 for (i = 0; i < nfiles; i++, tfid++) {
2522 * Get volume/vnode for the fetched file; caller's rights to it
2526 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2527 &parentwhentargetnotdir, &client, READ_LOCK,
2528 &rights, &anyrights)))
2529 goto Bad_BulkStatus;
2530 /* set volume synchronization information, but only once per call */
2532 SetVolumeSync(Sync, volptr);
2534 /* Are we allowed to fetch Fid's status? */
2535 if (targetptr->disk.type != vDirectory) {
2537 Check_PermissionRights(targetptr, client, rights,
2538 CHK_FETCHSTATUS, 0))) {
2539 if (rx_GetCallAbortCode(acall) == errorCode)
2540 rx_SetCallAbortCode(acall, 0);
2541 goto Bad_BulkStatus;
2545 /* set OutStatus From the Fid */
2546 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2547 anyrights, parentwhentargetnotdir);
2549 /* If a r/w volume, also set the CallBack state */
2550 if (VolumeWriteable(volptr))
2551 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2552 &CallBacks->AFSCBs_val[i]);
2554 struct AFSFid myFid;
2555 memset(&myFid, 0, sizeof(struct AFSFid));
2556 myFid.Volume = tfid->Volume;
2557 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2558 &CallBacks->AFSCBs_val[i]);
2561 /* put back the file ID and volume */
2562 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2564 parentwhentargetnotdir = (Vnode *) 0;
2565 targetptr = (Vnode *) 0;
2566 volptr = (Volume *) 0;
2567 client = (struct client *)0;
2571 /* Update and store volume/vnode and parent vnodes back */
2572 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2574 errorCode = CallPostamble(tcon, errorCode, thost);
2576 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2578 #if FS_STATS_DETAILED
2579 TM_GetTimeOfDay(&opStopTime, 0);
2580 if (errorCode == 0) {
2582 (opP->numSuccesses)++;
2583 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2584 fs_stats_AddTo((opP->sumTime), elapsedTime);
2585 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2586 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2587 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2589 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2590 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2594 #endif /* FS_STATS_DETAILED */
2597 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2598 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2599 AUD_ID, t_client ? t_client->ViceId : 0,
2600 AUD_FIDS, Fids, AUD_END);
2603 } /*SRXAFS_BulkStatus */
2607 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2608 struct AFSBulkStats * OutStats,
2609 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2613 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2614 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2615 int errorCode = 0; /* return code to caller */
2616 Volume *volptr = 0; /* pointer to the volume */
2617 struct client *client = 0; /* pointer to the client data */
2618 afs_int32 rights, anyrights; /* rights for this and any user */
2619 register struct AFSFid *tfid; /* file id we're dealing with now */
2620 struct rx_connection *tcon;
2622 struct client *t_client = NULL; /* tmp ptr to client data */
2623 AFSFetchStatus *tstatus;
2624 #if FS_STATS_DETAILED
2625 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2626 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2627 struct timeval elapsedTime; /* Transfer time */
2630 * Set our stats pointer, remember when the RPC operation started, and
2631 * tally the operation.
2633 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2637 TM_GetTimeOfDay(&opStartTime, 0);
2638 #endif /* FS_STATS_DETAILED */
2640 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2642 AFSCallStats.TotalCalls++;
2644 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2645 if (nfiles <= 0) { /* Sanity check */
2647 goto Audit_and_Return;
2650 /* allocate space for return output parameters */
2651 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2652 malloc(nfiles * sizeof(struct AFSFetchStatus));
2653 if (!OutStats->AFSBulkStats_val) {
2654 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2657 OutStats->AFSBulkStats_len = nfiles;
2658 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2659 malloc(nfiles * sizeof(struct AFSCallBack));
2660 if (!CallBacks->AFSCBs_val) {
2661 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2664 CallBacks->AFSCBs_len = nfiles;
2666 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2667 goto Bad_InlineBulkStatus;
2670 tfid = Fids->AFSCBFids_val;
2671 for (i = 0; i < nfiles; i++, tfid++) {
2673 * Get volume/vnode for the fetched file; caller's rights to it
2677 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2678 &parentwhentargetnotdir, &client, READ_LOCK,
2679 &rights, &anyrights))) {
2680 tstatus = &OutStats->AFSBulkStats_val[i];
2681 tstatus->errorCode = errorCode;
2682 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2684 parentwhentargetnotdir = (Vnode *) 0;
2685 targetptr = (Vnode *) 0;
2686 volptr = (Volume *) 0;
2687 client = (struct client *)0;
2691 /* set volume synchronization information, but only once per call */
2693 SetVolumeSync(Sync, volptr);
2695 /* Are we allowed to fetch Fid's status? */
2696 if (targetptr->disk.type != vDirectory) {
2698 Check_PermissionRights(targetptr, client, rights,
2699 CHK_FETCHSTATUS, 0))) {
2700 tstatus = &OutStats->AFSBulkStats_val[i];
2701 tstatus->errorCode = errorCode;
2702 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2703 (Vnode *) 0, volptr, &client);
2704 parentwhentargetnotdir = (Vnode *) 0;
2705 targetptr = (Vnode *) 0;
2706 volptr = (Volume *) 0;
2707 client = (struct client *)0;
2712 /* set OutStatus From the Fid */
2713 GetStatus(targetptr,
2714 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2715 rights, anyrights, parentwhentargetnotdir);
2717 /* If a r/w volume, also set the CallBack state */
2718 if (VolumeWriteable(volptr))
2719 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2720 &CallBacks->AFSCBs_val[i]);
2722 struct AFSFid myFid;
2723 memset(&myFid, 0, sizeof(struct AFSFid));
2724 myFid.Volume = tfid->Volume;
2725 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2726 &CallBacks->AFSCBs_val[i]);
2729 /* put back the file ID and volume */
2730 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2732 parentwhentargetnotdir = (Vnode *) 0;
2733 targetptr = (Vnode *) 0;
2734 volptr = (Volume *) 0;
2735 client = (struct client *)0;
2738 Bad_InlineBulkStatus:
2739 /* Update and store volume/vnode and parent vnodes back */
2740 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2742 errorCode = CallPostamble(tcon, errorCode, thost);
2744 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2746 #if FS_STATS_DETAILED
2747 TM_GetTimeOfDay(&opStopTime, 0);
2748 if (errorCode == 0) {
2750 (opP->numSuccesses)++;
2751 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2752 fs_stats_AddTo((opP->sumTime), elapsedTime);
2753 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2754 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2755 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2757 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2758 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2762 #endif /* FS_STATS_DETAILED */
2765 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2766 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2767 AUD_ID, t_client ? t_client->ViceId : 0,
2768 AUD_FIDS, Fids, AUD_END);
2771 } /*SRXAFS_InlineBulkStatus */
2775 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2776 struct AFSFetchStatus * OutStatus,
2777 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2780 struct rx_connection *tcon;
2782 struct client *t_client = NULL; /* tmp ptr to client data */
2783 #if FS_STATS_DETAILED
2784 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2785 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2786 struct timeval elapsedTime; /* Transfer time */
2789 * Set our stats pointer, remember when the RPC operation started, and
2790 * tally the operation.
2792 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2796 TM_GetTimeOfDay(&opStartTime, 0);
2797 #endif /* FS_STATS_DETAILED */
2799 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2800 goto Bad_FetchStatus;
2802 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2805 code = CallPostamble(tcon, code, thost);
2807 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2809 #if FS_STATS_DETAILED
2810 TM_GetTimeOfDay(&opStopTime, 0);
2813 (opP->numSuccesses)++;
2814 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2815 fs_stats_AddTo((opP->sumTime), elapsedTime);
2816 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2817 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2818 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2820 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2821 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2825 #endif /* FS_STATS_DETAILED */
2827 osi_auditU(acall, FetchStatusEvent, code,
2828 AUD_ID, t_client ? t_client->ViceId : 0,
2829 AUD_FID, Fid, AUD_END);
2832 } /*SRXAFS_FetchStatus */
2836 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2837 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2838 afs_fsize_t Length, afs_fsize_t FileLength,
2839 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2841 Vnode *targetptr = 0; /* pointer to input fid */
2842 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2843 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2844 int errorCode = 0; /* return code for caller */
2845 int fileCode = 0; /* return code from vol package */
2846 Volume *volptr = 0; /* pointer to the volume header */
2847 struct client *client = 0; /* pointer to client structure */
2848 afs_int32 rights, anyrights; /* rights for this and any user */
2849 struct client *t_client = NULL; /* tmp ptr to client data */
2850 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2851 struct rx_connection *tcon;
2853 #if FS_STATS_DETAILED
2854 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2855 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2856 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2857 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2858 struct timeval elapsedTime; /* Transfer time */
2859 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2860 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2861 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2864 * Set our stats pointers, remember when the RPC operation started, and
2865 * tally the operation.
2867 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2868 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2873 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2875 TM_GetTimeOfDay(&opStartTime, 0);
2876 #endif /* FS_STATS_DETAILED */
2879 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2881 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2884 /* Get ptr to client data for user Id for logging */
2885 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2886 logHostAddr.s_addr = rxr_HostOf(tcon);
2888 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2889 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2890 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2893 * Get associated volume/vnode for the stored file; caller's rights
2897 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
2898 &parentwhentargetnotdir, &client, WRITE_LOCK,
2899 &rights, &anyrights))) {
2903 /* set volume synchronization information */
2904 SetVolumeSync(Sync, volptr);
2906 if ((targetptr->disk.type == vSymlink)) {
2907 /* Should we return a better error code here??? */
2912 /* Check if we're allowed to store the data */
2914 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2920 * Drop the read lock on the parent directory after saving the parent
2921 * vnode information we need to pass to GetStatus
2923 if (parentwhentargetnotdir != NULL) {
2924 tparentwhentargetnotdir = *parentwhentargetnotdir;
2925 VPutVnode(&fileCode, parentwhentargetnotdir);
2926 assert(!fileCode || (fileCode == VSALVAGE));
2927 parentwhentargetnotdir = NULL;
2929 #if FS_STATS_DETAILED
2931 * Remember when the data transfer started.
2933 TM_GetTimeOfDay(&xferStartTime, 0);
2934 #endif /* FS_STATS_DETAILED */
2936 /* Do the actual storing of the data */
2937 #if FS_STATS_DETAILED
2939 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2940 FileLength, (InStatus->Mask & AFS_FSYNC),
2941 &bytesToXfer, &bytesXferred);
2944 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2945 FileLength, (InStatus->Mask & AFS_FSYNC));
2946 if (errorCode && (!targetptr->changed_newTime))
2948 #endif /* FS_STATS_DETAILED */
2949 #if FS_STATS_DETAILED
2951 * At this point, the data transfer is done, for good or ill. Remember
2952 * when the transfer ended, bump the number of successes/failures, and
2953 * integrate the transfer size and elapsed time into the stats. If the
2954 * operation failed, we jump to the appropriate point.
2956 TM_GetTimeOfDay(&xferStopTime, 0);
2958 (xferP->numXfers)++;
2960 (xferP->numSuccesses)++;
2963 * Bump the xfer sum by the number of bytes actually sent, NOT the
2966 tot_bytesXferred += bytesXferred;
2967 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2968 tot_bytesXferred &= 0x3FF;
2969 if (bytesXferred < xferP->minBytes)
2970 xferP->minBytes = bytesXferred;
2971 if (bytesXferred > xferP->maxBytes)
2972 xferP->maxBytes = bytesXferred;
2975 * Tally the size of the object. Note: we tally the actual size,
2976 * NOT the number of bytes that made it out over the wire.
2978 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2979 (xferP->count[0])++;
2980 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2981 (xferP->count[1])++;
2982 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2983 (xferP->count[2])++;
2984 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2985 (xferP->count[3])++;
2986 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2987 (xferP->count[4])++;
2988 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2989 (xferP->count[5])++;
2990 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2991 (xferP->count[6])++;
2992 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2993 (xferP->count[7])++;
2995 (xferP->count[8])++;
2997 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2998 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2999 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3000 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3001 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3003 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3004 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3009 * Finally, go off to tell our caller the bad news in case the
3012 if (errorCode && (!targetptr->changed_newTime))
3014 #endif /* FS_STATS_DETAILED */
3016 /* Update the status of the target's vnode */
3017 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3018 targetptr, volptr, 0);
3020 /* Get the updated File's status back to the caller */
3021 GetStatus(targetptr, OutStatus, rights, anyrights,
3022 &tparentwhentargetnotdir);
3025 /* Update and store volume/vnode and parent vnodes back */
3026 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3028 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3030 errorCode = CallPostamble(tcon, errorCode, thost);
3032 #if FS_STATS_DETAILED
3033 TM_GetTimeOfDay(&opStopTime, 0);
3034 if (errorCode == 0) {
3036 (opP->numSuccesses)++;
3037 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3038 fs_stats_AddTo((opP->sumTime), elapsedTime);
3039 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3040 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3041 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3043 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3044 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3048 #endif /* FS_STATS_DETAILED */
3049 osi_auditU(acall, StoreDataEvent, errorCode,
3050 AUD_ID, t_client ? t_client->ViceId : 0,
3051 AUD_FID, Fid, AUD_END);
3053 } /*common_StoreData64 */
3056 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3057 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3058 afs_uint32 Length, afs_uint32 FileLength,
3059 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3061 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3062 (0x7fffffff - Pos) < Length)
3065 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3067 } /*SRXAFS_StoreData */
3070 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3071 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3072 afs_uint64 Length, afs_uint64 FileLength,
3073 struct AFSFetchStatus * OutStatus,
3074 struct AFSVolSync * Sync)
3078 afs_fsize_t tLength;
3079 afs_fsize_t tFileLength;
3081 #ifdef AFS_64BIT_ENV
3082 #ifndef AFS_LARGEFILE_ENV
3083 if (FileLength > 0x7fffffff)
3085 #endif /* !AFS_LARGEFILE_ENV */
3086 tPos = (afs_fsize_t) Pos;
3087 tLength = (afs_fsize_t) Length;
3088 tFileLength = (afs_fsize_t) FileLength;
3089 #else /* AFS_64BIT_ENV */
3090 if (FileLength.high)
3093 tLength = Length.low;
3094 tFileLength = FileLength.low;
3095 #endif /* AFS_64BIT_ENV */
3098 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3104 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3105 struct AFSOpaque * AccessList,
3106 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3108 Vnode *targetptr = 0; /* pointer to input fid */
3109 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3110 int errorCode = 0; /* return code for caller */
3111 struct AFSStoreStatus InStatus; /* Input status for fid */
3112 Volume *volptr = 0; /* pointer to the volume header */
3113 struct client *client = 0; /* pointer to client structure */
3114 afs_int32 rights, anyrights; /* rights for this and any user */
3115 struct rx_connection *tcon;
3117 struct client *t_client = NULL; /* tmp ptr to client data */
3118 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3119 #if FS_STATS_DETAILED
3120 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3121 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3122 struct timeval elapsedTime; /* Transfer time */
3125 * Set our stats pointer, remember when the RPC operation started, and
3126 * tally the operation.
3128 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3132 TM_GetTimeOfDay(&opStartTime, 0);
3133 #endif /* FS_STATS_DETAILED */
3134 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3137 /* Get ptr to client data for user Id for logging */
3138 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3139 logHostAddr.s_addr = rxr_HostOf(tcon);
3141 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3142 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3143 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3145 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3147 InStatus.Mask = 0; /* not storing any status */
3150 * Get associated volume/vnode for the target dir; caller's rights
3151 * are also returned.
3154 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3155 &parentwhentargetnotdir, &client, WRITE_LOCK,
3156 &rights, &anyrights))) {
3160 /* set volume synchronization information */
3161 SetVolumeSync(Sync, volptr);
3163 /* Check if we have permission to change the dir's ACL */
3165 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3170 /* Build and store the new Access List for the dir */
3171 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3175 targetptr->changed_newTime = 1; /* status change of directory */
3177 /* convert the write lock to a read lock before breaking callbacks */
3178 VVnodeWriteToRead(&errorCode, targetptr);
3179 assert(!errorCode || errorCode == VSALVAGE);
3181 /* break call backs on the directory */
3182 BreakCallBack(client->host, Fid, 0);
3184 /* Get the updated dir's status back to the caller */
3185 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3188 /* Update and store volume/vnode and parent vnodes back */
3189 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3191 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3192 errorCode = CallPostamble(tcon, errorCode, thost);
3194 #if FS_STATS_DETAILED
3195 TM_GetTimeOfDay(&opStopTime, 0);
3196 if (errorCode == 0) {
3198 (opP->numSuccesses)++;
3199 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3200 fs_stats_AddTo((opP->sumTime), elapsedTime);
3201 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3202 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3203 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3205 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3206 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3210 #endif /* FS_STATS_DETAILED */
3212 osi_auditU(acall, StoreACLEvent, errorCode,
3213 AUD_ID, t_client ? t_client->ViceId : 0,
3214 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3217 } /*SRXAFS_StoreACL */
3221 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3222 * should be merged when possible.
3225 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3226 struct AFSStoreStatus *InStatus,
3227 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3229 Vnode *targetptr = 0; /* pointer to input fid */
3230 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3231 int errorCode = 0; /* return code for caller */
3232 Volume *volptr = 0; /* pointer to the volume header */
3233 struct client *client = 0; /* pointer to client structure */
3234 afs_int32 rights, anyrights; /* rights for this and any user */
3235 struct client *t_client = NULL; /* tmp ptr to client data */
3236 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3237 struct rx_connection *tcon = rx_ConnectionOf(acall);
3239 /* Get ptr to client data for user Id for logging */
3240 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3241 logHostAddr.s_addr = rxr_HostOf(tcon);
3243 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3244 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3245 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3247 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3250 * Get volume/vnode for the target file; caller's rights to it are
3254 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3255 &parentwhentargetnotdir, &client, WRITE_LOCK,
3256 &rights, &anyrights))) {
3257 goto Bad_StoreStatus;
3260 /* set volume synchronization information */
3261 SetVolumeSync(Sync, volptr);
3263 /* Check if the caller has proper permissions to store status to Fid */
3265 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3267 goto Bad_StoreStatus;
3270 * Check for a symbolic link; we can't chmod these (otherwise could
3271 * change a symlink to a mt pt or vice versa)
3273 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3275 goto Bad_StoreStatus;
3278 /* Update the status of the target's vnode */
3279 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3280 (parentwhentargetnotdir ? parentwhentargetnotdir
3281 : targetptr), volptr, 0);
3283 /* convert the write lock to a read lock before breaking callbacks */
3284 VVnodeWriteToRead(&errorCode, targetptr);
3285 assert(!errorCode || errorCode == VSALVAGE);
3287 /* Break call backs on Fid */
3288 BreakCallBack(client->host, Fid, 0);
3290 /* Return the updated status back to caller */
3291 GetStatus(targetptr, OutStatus, rights, anyrights,
3292 parentwhentargetnotdir);
3295 /* Update and store volume/vnode and parent vnodes back */
3296 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3298 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3301 } /*SAFSS_StoreStatus */
3305 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3306 struct AFSStoreStatus * InStatus,
3307 struct AFSFetchStatus * OutStatus,
3308 struct AFSVolSync * Sync)
3311 struct rx_connection *tcon;
3313 struct client *t_client = NULL; /* tmp ptr to client data */
3314 #if FS_STATS_DETAILED
3315 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3316 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3317 struct timeval elapsedTime; /* Transfer time */
3320 * Set our stats pointer, remember when the RPC operation started, and
3321 * tally the operation.
3323 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3327 TM_GetTimeOfDay(&opStartTime, 0);
3328 #endif /* FS_STATS_DETAILED */
3330 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3331 goto Bad_StoreStatus;
3333 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3336 code = CallPostamble(tcon, code, thost);
3338 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3340 #if FS_STATS_DETAILED
3341 TM_GetTimeOfDay(&opStopTime, 0);
3344 (opP->numSuccesses)++;
3345 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3346 fs_stats_AddTo((opP->sumTime), elapsedTime);
3347 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3348 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3349 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3351 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3352 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3356 #endif /* FS_STATS_DETAILED */
3358 osi_auditU(acall, StoreStatusEvent, code,
3359 AUD_ID, t_client ? t_client->ViceId : 0,
3360 AUD_FID, Fid, AUD_END);
3363 } /*SRXAFS_StoreStatus */
3367 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3368 * merged in when possible.
3371 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3372 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3374 Vnode *parentptr = 0; /* vnode of input Directory */
3375 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3376 Vnode *targetptr = 0; /* file to be deleted */
3377 Volume *volptr = 0; /* pointer to the volume header */
3378 AFSFid fileFid; /* area for Fid from the directory */
3379 int errorCode = 0; /* error code */
3380 DirHandle dir; /* Handle for dir package I/O */
3381 struct client *client = 0; /* pointer to client structure */
3382 afs_int32 rights, anyrights; /* rights for this and any user */
3383 struct client *t_client; /* tmp ptr to client data */
3384 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3385 struct rx_connection *tcon = rx_ConnectionOf(acall);
3388 /* Get ptr to client data for user Id for logging */
3389 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3390 logHostAddr.s_addr = rxr_HostOf(tcon);
3392 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3393 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3394 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3396 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3399 * Get volume/vnode for the parent dir; caller's access rights are
3403 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3404 &parentwhentargetnotdir, &client, WRITE_LOCK,
3405 &rights, &anyrights))) {
3406 goto Bad_RemoveFile;
3408 /* set volume synchronization information */
3409 SetVolumeSync(Sync, volptr);
3411 /* Does the caller has delete (& write) access to the parent directory? */
3412 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3413 goto Bad_RemoveFile;
3416 /* Actually delete the desired file */
3418 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3420 goto Bad_RemoveFile;
3423 /* Update the vnode status of the parent dir */
3424 #if FS_STATS_DETAILED
3425 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3426 parentptr->disk.linkCount,
3427 client->InSameNetwork);
3429 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3430 parentptr->disk.linkCount);
3431 #endif /* FS_STATS_DETAILED */
3433 /* Return the updated parent dir's status back to caller */
3434 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3436 /* Handle internal callback state for the parent and the deleted file */
3437 if (targetptr->disk.linkCount == 0) {
3438 /* no references left, discard entry */
3439 DeleteFileCallBacks(&fileFid);
3440 /* convert the parent lock to a read lock before breaking callbacks */
3441 VVnodeWriteToRead(&errorCode, parentptr);
3442 assert(!errorCode || errorCode == VSALVAGE);
3444 /* convert the parent lock to a read lock before breaking callbacks */
3445 VVnodeWriteToRead(&errorCode, parentptr);
3446 assert(!errorCode || errorCode == VSALVAGE);
3447 /* convert the target lock to a read lock before breaking callbacks */
3448 VVnodeWriteToRead(&errorCode, targetptr);
3449 assert(!errorCode || errorCode == VSALVAGE);
3450 /* tell all the file has changed */
3451 BreakCallBack(client->host, &fileFid, 1);
3454 /* break call back on the directory */
3455 BreakCallBack(client->host, DirFid, 0);
3458 /* Update and store volume/vnode and parent vnodes back */
3459 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3462 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3465 } /*SAFSS_RemoveFile */
3469 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3470 struct AFSFetchStatus * OutDirStatus,
3471 struct AFSVolSync * Sync)
3474 struct rx_connection *tcon;
3476 struct client *t_client = NULL; /* tmp ptr to client data */
3477 #if FS_STATS_DETAILED
3478 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3479 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3480 struct timeval elapsedTime; /* Transfer time */
3483 * Set our stats pointer, remember when the RPC operation started, and
3484 * tally the operation.
3486 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3490 TM_GetTimeOfDay(&opStartTime, 0);
3491 #endif /* FS_STATS_DETAILED */
3493 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3494 goto Bad_RemoveFile;
3496 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3499 code = CallPostamble(tcon, code, thost);
3501 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3503 #if FS_STATS_DETAILED
3504 TM_GetTimeOfDay(&opStopTime, 0);
3507 (opP->numSuccesses)++;
3508 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3509 fs_stats_AddTo((opP->sumTime), elapsedTime);
3510 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3511 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3512 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3514 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3515 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3519 #endif /* FS_STATS_DETAILED */
3521 osi_auditU(acall, RemoveFileEvent, code,
3522 AUD_ID, t_client ? t_client->ViceId : 0,
3523 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3526 } /*SRXAFS_RemoveFile */
3530 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3531 * be merged in when possible.
3534 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3535 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3536 struct AFSFetchStatus *OutFidStatus,
3537 struct AFSFetchStatus *OutDirStatus,
3538 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3540 Vnode *parentptr = 0; /* vnode of input Directory */
3541 Vnode *targetptr = 0; /* vnode of the new file */
3542 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3543 Volume *volptr = 0; /* pointer to the volume header */
3544 int errorCode = 0; /* error code */
3545 DirHandle dir; /* Handle for dir package I/O */
3546 struct client *client = 0; /* pointer to client structure */
3547 afs_int32 rights, anyrights; /* rights for this and any user */
3548 struct client *t_client; /* tmp ptr to client data */
3549 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3550 struct rx_connection *tcon = rx_ConnectionOf(acall);
3554 /* Get ptr to client data for user Id for logging */
3555 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3556 logHostAddr.s_addr = rxr_HostOf(tcon);
3558 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3559 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3560 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3562 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3564 if (!FileNameOK(Name)) {
3566 goto Bad_CreateFile;
3570 * Get associated volume/vnode for the parent dir; caller long are
3574 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3575 &parentwhentargetnotdir, &client, WRITE_LOCK,
3576 &rights, &anyrights))) {
3577 goto Bad_CreateFile;
3580 /* set volume synchronization information */
3581 SetVolumeSync(Sync, volptr);
3583 /* Can we write (and insert) onto the parent directory? */
3584 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3585 goto Bad_CreateFile;
3587 /* get a new vnode for the file to be created and set it up */
3589 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3590 vFile, nBlocks(0)))) {
3591 goto Bad_CreateFile;
3594 /* update the status of the parent vnode */
3595 #if FS_STATS_DETAILED
3596 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3597 parentptr->disk.linkCount,
3598 client->InSameNetwork);
3600 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3601 parentptr->disk.linkCount);
3602 #endif /* FS_STATS_DETAILED */
3604 /* update the status of the new file's vnode */
3605 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3606 parentptr, volptr, 0);
3608 /* 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 */
3609 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3610 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3612 /* convert the write lock to a read lock before breaking callbacks */
3613 VVnodeWriteToRead(&errorCode, parentptr);
3614 assert(!errorCode || errorCode == VSALVAGE);
3616 /* break call back on parent dir */
3617 BreakCallBack(client->host, DirFid, 0);
3619 /* Return a callback promise for the newly created file to the caller */
3620 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3623 /* Update and store volume/vnode and parent vnodes back */
3624 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3627 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3630 } /*SAFSS_CreateFile */
3634 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3635 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3636 struct AFSFetchStatus * OutFidStatus,
3637 struct AFSFetchStatus * OutDirStatus,
3638 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3641 struct rx_connection *tcon;
3643 struct client *t_client = NULL; /* tmp ptr to client data */
3644 #if FS_STATS_DETAILED
3645 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3646 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3647 struct timeval elapsedTime; /* Transfer time */
3650 * Set our stats pointer, remember when the RPC operation started, and
3651 * tally the operation.
3653 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3657 TM_GetTimeOfDay(&opStartTime, 0);
3658 #endif /* FS_STATS_DETAILED */
3660 memset(OutFid, 0, sizeof(struct AFSFid));
3662 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3663 goto Bad_CreateFile;
3666 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3667 OutDirStatus, CallBack, Sync);
3670 code = CallPostamble(tcon, code, thost);
3672 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3674 #if FS_STATS_DETAILED
3675 TM_GetTimeOfDay(&opStopTime, 0);
3678 (opP->numSuccesses)++;
3679 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3680 fs_stats_AddTo((opP->sumTime), elapsedTime);
3681 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3682 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3683 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3685 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3686 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3690 #endif /* FS_STATS_DETAILED */
3692 osi_auditU(acall, CreateFileEvent, code,
3693 AUD_ID, t_client ? t_client->ViceId : 0,
3694 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3697 } /*SRXAFS_CreateFile */
3701 * This routine is called exclusively from SRXAFS_Rename(), and should be
3702 * merged in when possible.
3705 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3706 struct AFSFid *NewDirFid, char *NewName,
3707 struct AFSFetchStatus *OutOldDirStatus,
3708 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3710 Vnode *oldvptr = 0; /* vnode of the old Directory */
3711 Vnode *newvptr = 0; /* vnode of the new Directory */
3712 Vnode *fileptr = 0; /* vnode of the file to move */
3713 Vnode *newfileptr = 0; /* vnode of the file to delete */
3714 Vnode *testvptr = 0; /* used in directory tree walk */
3715 Vnode *parent = 0; /* parent for use in SetAccessList */
3716 int errorCode = 0; /* error code */
3717 int fileCode = 0; /* used when writing Vnodes */
3718 VnodeId testnode; /* used in directory tree walk */
3719 AFSFid fileFid; /* Fid of file to move */
3720 AFSFid newFileFid; /* Fid of new file */
3721 DirHandle olddir; /* Handle for dir package I/O */
3722 DirHandle newdir; /* Handle for dir package I/O */
3723 DirHandle filedir; /* Handle for dir package I/O */
3724 DirHandle newfiledir; /* Handle for dir package I/O */
3725 Volume *volptr = 0; /* pointer to the volume header */
3726 struct client *client = 0; /* pointer to client structure */
3727 afs_int32 rights, anyrights; /* rights for this and any user */
3728 afs_int32 newrights; /* rights for this user */
3729 afs_int32 newanyrights; /* rights for any user */
3730 int doDelete; /* deleted the rename target (ref count now 0) */
3732 struct client *t_client; /* tmp ptr to client data */
3733 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3734 struct rx_connection *tcon = rx_ConnectionOf(acall);
3739 FidZero(&newfiledir);
3741 /* Get ptr to client data for user Id for logging */
3742 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3743 logHostAddr.s_addr = rxr_HostOf(tcon);
3745 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3746 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3747 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3748 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3750 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3752 if (!FileNameOK(NewName)) {
3756 if (OldDirFid->Volume != NewDirFid->Volume) {
3761 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3762 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3763 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3769 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3771 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3772 &parent, &client, WRITE_LOCK, &rights,
3777 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3779 newrights = rights, newanyrights = anyrights;
3782 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3783 MustBeDIR, &parent, &client, WRITE_LOCK,
3784 &newrights, &newanyrights))) {
3790 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3791 &parent, &client, WRITE_LOCK, &newrights,
3797 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3798 &parent, &client, WRITE_LOCK, &rights,
3805 /* set volume synchronization information */
3806 SetVolumeSync(Sync, volptr);
3808 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3811 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3815 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3816 * call to CopyOnWrite returns error, it is not necessary to revert back
3817 * the effects of the first call because the contents of the volume is
3818 * not modified, it is only replicated.
3820 if (oldvptr->disk.cloned) {
3821 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3822 if ((errorCode = CopyOnWrite(oldvptr, volptr)))
3825 SetDirHandle(&olddir, oldvptr);
3826 if (newvptr->disk.cloned) {
3827 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3828 if ((errorCode = CopyOnWrite(newvptr, volptr)))
3832 SetDirHandle(&newdir, newvptr);
3834 /* Lookup the file to delete its vnode */
3835 if (Lookup(&olddir, OldName, &fileFid)) {
3839 if (fileFid.Vnode == oldvptr->vnodeNumber
3840 || fileFid.Vnode == newvptr->vnodeNumber) {
3841 errorCode = FSERR_ELOOP;
3844 fileFid.Volume = V_id(volptr);
3845 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3846 if (errorCode != 0) {
3848 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3849 OldName, errorCode));
3850 VTakeOffline(volptr);
3853 if (fileptr->disk.uniquifier != fileFid.Unique) {
3855 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3857 VTakeOffline(volptr);
3862 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3863 && fileptr->disk.linkCount != 1) {
3865 * Hard links exist to this file - cannot move one of the links to
3866 * a new directory because of AFS restrictions (this is the same
3867 * reason that links cannot be made across directories, i.e.
3874 /* Lookup the new file */
3875 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3876 if (readonlyServer) {
3877 errorCode = VREADONLY;
3880 if (!(newrights & PRSFS_DELETE)) {
3884 if (newFileFid.Vnode == oldvptr->vnodeNumber
3885 || newFileFid.Vnode == newvptr->vnodeNumber
3886 || newFileFid.Vnode == fileFid.Vnode) {
3890 newFileFid.Volume = V_id(volptr);
3892 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3893 if (errorCode != 0) {
3895 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
3896 NewName, errorCode));
3897 VTakeOffline(volptr);
3900 if (fileptr->disk.uniquifier != fileFid.Unique) {
3902 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
3904 VTakeOffline(volptr);
3908 SetDirHandle(&newfiledir, newfileptr);
3909 /* Now check that we're moving directories over directories properly, etc.
3910 * return proper POSIX error codes:
3911 * if fileptr is a file and new is a dir: EISDIR.
3912 * if fileptr is a dir and new is a file: ENOTDIR.
3913 * Also, dir to be removed must be empty, of course.
3915 if (newfileptr->disk.type == vDirectory) {
3916 if (fileptr->disk.type != vDirectory) {
3920 if ((IsEmpty(&newfiledir))) {
3925 if (fileptr->disk.type == vDirectory) {
3926 errorCode = ENOTDIR;
3933 * ok - now we check that the old name is not above new name in the
3934 * directory structure. This is to prevent removing a subtree alltogether
3936 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
3937 afs_int32 forpass = 0, vnum = 0, top = 0;
3938 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
3939 if (testnode > vnum) vnum = testnode;
3940 if (forpass > vnum) {
3941 errorCode = FSERR_ELOOP;
3944 if (testnode == oldvptr->vnodeNumber) {
3945 testnode = oldvptr->disk.parent;
3948 if ((testnode == fileptr->vnodeNumber)
3949 || (testnode == newvptr->vnodeNumber)) {
3950 errorCode = FSERR_ELOOP;
3953 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
3954 errorCode = FSERR_ELOOP;
3957 if (testnode == 1) top = 1;
3958 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
3959 assert(errorCode == 0);
3960 testnode = testvptr->disk.parent;
3961 VPutVnode(&errorCode, testvptr);
3962 if ((top == 1) && (testnode != 0)) {
3963 VTakeOffline(volptr);
3967 assert(errorCode == 0);
3970 /* Do the CopyonWrite first before modifying anything else. Copying is
3971 * required because we may have to change entries for ..
3973 if ((fileptr->disk.type == vDirectory) && (fileptr->disk.cloned)) {
3974 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
3975 if ((errorCode = CopyOnWrite(fileptr, volptr)))
3979 /* If the new name exists already, delete it and the file it points to */
3982 /* Delete NewName from its directory */
3983 code = Delete(&newdir, NewName);
3986 /* Drop the link count */
3987 newfileptr->disk.linkCount--;
3988 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
3989 afs_fsize_t newSize;
3990 VN_GET_LEN(newSize, newfileptr);
3991 VAdjustDiskUsage((Error *) & errorCode, volptr,
3992 (afs_sfsize_t) - nBlocks(newSize), 0);
3993 if (VN_GET_INO(newfileptr)) {
3994 IH_REALLYCLOSE(newfileptr->handle);
3996 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
3997 V_parentId(volptr));
3998 IH_RELEASE(newfileptr->handle);
3999 if (errorCode == -1) {
4001 ("Del: inode=%s, name=%s, errno=%d\n",
4002 PrintInode(NULL, VN_GET_INO(newfileptr)),
4004 if ((errno != ENOENT) && (errno != EIO)
4005 && (errno != ENXIO))
4006 ViceLog(0, ("Do we need to fsck?"));
4009 VN_SET_INO(newfileptr, (Inode) 0);
4010 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4013 /* Link count did not drop to zero.
4014 * Mark NewName vnode as changed - updates stime.
4016 newfileptr->changed_newTime = 1;
4021 * If the create below fails, and the delete above worked, we have
4022 * removed the new name and not replaced it. This is not very likely,
4023 * but possible. We could try to put the old file back, but it is
4024 * highly unlikely that it would work since it would involve issuing
4027 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4030 /* Delete the old name */
4031 assert(Delete(&olddir, (char *)OldName) == 0);
4033 /* if the directory length changes, reflect it in the statistics */
4034 #if FS_STATS_DETAILED
4035 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4036 oldvptr->disk.linkCount, client->InSameNetwork);
4037 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4038 newvptr->disk.linkCount, client->InSameNetwork);
4040 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4041 oldvptr->disk.linkCount);
4042 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4043 newvptr->disk.linkCount);
4044 #endif /* FS_STATS_DETAILED */
4046 if (oldvptr == newvptr)
4047 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4049 fileptr->disk.parent = newvptr->vnodeNumber;
4050 fileptr->changed_newTime = 1; /* status change of moved file */
4052 /* if we are dealing with a rename of a directory */
4053 if (fileptr->disk.type == vDirectory) {
4054 assert(!fileptr->disk.cloned);
4055 SetDirHandle(&filedir, fileptr);
4056 /* fix .. to point to the correct place */
4057 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4058 assert(Create(&filedir, "..", NewDirFid) == 0);
4059 fileptr->disk.dataVersion++;
4060 /* if the parent directories are different the link counts have to be */
4061 /* changed due to .. in the renamed directory */
4062 if (oldvptr != newvptr) {
4063 oldvptr->disk.linkCount--;
4064 newvptr->disk.linkCount++;
4068 /* set up return status */
4069 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4070 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4071 if (newfileptr && doDelete) {
4072 DeleteFileCallBacks(&newFileFid); /* no other references */
4077 /* convert the write locks to a read locks before breaking callbacks */
4078 VVnodeWriteToRead(&errorCode, newvptr);
4079 assert(!errorCode || errorCode == VSALVAGE);
4080 if (oldvptr != newvptr) {
4081 VVnodeWriteToRead(&errorCode, oldvptr);
4082 assert(!errorCode || errorCode == VSALVAGE);
4084 if (newfileptr && !doDelete) {
4085 /* convert the write lock to a read lock before breaking callbacks */
4086 VVnodeWriteToRead(&errorCode, newfileptr);
4087 assert(!errorCode || errorCode == VSALVAGE);
4090 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4091 BreakCallBack(client->host, NewDirFid, 0);
4092 if (oldvptr != newvptr) {
4093 BreakCallBack(client->host, OldDirFid, 0);
4094 if (fileptr->disk.type == vDirectory) /* if a dir moved, .. changed */
4095 BreakCallBack(client->host, &fileFid, 0);
4098 /* Note: it is not necessary to break the callback */
4100 DeleteFileCallBacks(&newFileFid); /* no other references */
4102 /* other's still exist (with wrong link count) */
4103 BreakCallBack(client->host, &newFileFid, 1);
4108 VPutVnode(&fileCode, newfileptr);
4109 assert(fileCode == 0);
4111 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
4112 newvptr : 0), oldvptr, volptr, &client);
4116 FidZap(&newfiledir);
4117 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4124 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4125 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4126 struct AFSFetchStatus * OutOldDirStatus,
4127 struct AFSFetchStatus * OutNewDirStatus,
4128 struct AFSVolSync * Sync)
4131 struct rx_connection *tcon;
4133 struct client *t_client = NULL; /* tmp ptr to client data */
4134 #if FS_STATS_DETAILED
4135 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4136 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4137 struct timeval elapsedTime; /* Transfer time */
4140 * Set our stats pointer, remember when the RPC operation started, and
4141 * tally the operation.
4143 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4147 TM_GetTimeOfDay(&opStartTime, 0);
4148 #endif /* FS_STATS_DETAILED */
4150 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4154 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4155 OutOldDirStatus, OutNewDirStatus, Sync);
4158 code = CallPostamble(tcon, code, thost);
4160 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4162 #if FS_STATS_DETAILED
4163 TM_GetTimeOfDay(&opStopTime, 0);
4166 (opP->numSuccesses)++;
4167 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4168 fs_stats_AddTo((opP->sumTime), elapsedTime);
4169 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4170 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4171 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4173 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4174 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4178 #endif /* FS_STATS_DETAILED */
4180 osi_auditU(acall, RenameFileEvent, code,
4181 AUD_ID, t_client ? t_client->ViceId : 0,
4182 AUD_FID, OldDirFid, AUD_STR, OldName,
4183 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4186 } /*SRXAFS_Rename */
4190 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4191 * merged into it when possible.
4194 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4195 char *LinkContents, struct AFSStoreStatus *InStatus,
4196 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4197 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4199 Vnode *parentptr = 0; /* vnode of input Directory */
4200 Vnode *targetptr = 0; /* vnode of the new link */
4201 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4202 int errorCode = 0; /* error code */
4204 DirHandle dir; /* Handle for dir package I/O */
4205 Volume *volptr = 0; /* pointer to the volume header */
4206 struct client *client = 0; /* pointer to client structure */
4207 afs_int32 rights, anyrights; /* rights for this and any user */
4208 struct client *t_client; /* tmp ptr to client data */
4209 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4211 struct rx_connection *tcon = rx_ConnectionOf(acall);
4215 /* Get ptr to client data for user Id for logging */
4216 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4217 logHostAddr.s_addr = rxr_HostOf(tcon);
4219 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4220 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4221 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4223 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4225 if (!FileNameOK(Name)) {
4231 * Get the vnode and volume for the parent dir along with the caller's
4235 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4236 &parentwhentargetnotdir, &client, WRITE_LOCK,
4237 &rights, &anyrights))) {
4241 /* set volume synchronization information */
4242 SetVolumeSync(Sync, volptr);
4244 /* Does the caller has insert (and write) access to the parent directory? */
4245 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4250 * If we're creating a mount point (any x bits clear), we must have
4251 * administer access to the directory, too. Always allow sysadmins
4254 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4255 if (readonlyServer) {
4256 errorCode = VREADONLY;
4260 * We have a mountpoint, 'cause we're trying to set the Unix mode
4261 * bits to something with some x bits missing (default mode bits
4262 * if AFS_SETMODE is false is 0777)
4264 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4270 /* get a new vnode for the symlink and set it up */
4272 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4273 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4277 /* update the status of the parent vnode */
4278 #if FS_STATS_DETAILED
4279 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4280 parentptr->disk.linkCount,
4281 client->InSameNetwork);
4283 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4284 parentptr->disk.linkCount);
4285 #endif /* FS_STATS_DETAILED */
4287 /* update the status of the new symbolic link file vnode */
4288 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4289 parentptr, volptr, strlen((char *)LinkContents));
4291 /* Write the contents of the symbolic link name into the target inode */
4292 fdP = IH_OPEN(targetptr->handle);
4293 assert(fdP != NULL);
4294 len = strlen((char *) LinkContents);
4295 code = (len == FDH_WRITE(fdP, (char *) LinkContents, len)) ? 0 : VDISKFULL;
4296 if (code) ViceLog(0, ("SAFSS_Symlink FDH_WRITE failed for len=%d, Fid=%u.%d.%d\n", len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4299 * Set up and return modified status for the parent dir and new symlink
4302 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4303 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4305 /* convert the write lock to a read lock before breaking callbacks */
4306 VVnodeWriteToRead(&errorCode, parentptr);
4307 assert(!errorCode || errorCode == VSALVAGE);
4309 /* break call back on the parent dir */
4310 BreakCallBack(client->host, DirFid, 0);
4313 /* Write the all modified vnodes (parent, new files) and volume back */
4314 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4317 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4318 return ( errorCode ? errorCode : code );
4320 } /*SAFSS_Symlink */
4324 SRXAFS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4325 OutFidStatus, OutDirStatus, Sync)
4326 struct AFSVolSync *Sync;
4327 struct rx_call *acall; /* Rx call */
4328 struct AFSFid *DirFid; /* Parent dir's fid */
4329 char *Name; /* File name to create */
4330 char *LinkContents; /* Contents of the new created file */
4331 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
4332 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
4333 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
4334 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
4338 struct rx_connection *tcon;
4340 struct client *t_client = NULL; /* tmp ptr to client data */
4341 #if FS_STATS_DETAILED
4342 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4343 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4344 struct timeval elapsedTime; /* Transfer time */
4347 * Set our stats pointer, remember when the RPC operation started, and
4348 * tally the operation.
4350 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4354 TM_GetTimeOfDay(&opStartTime, 0);
4355 #endif /* FS_STATS_DETAILED */
4357 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4361 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4362 OutFidStatus, OutDirStatus, Sync);
4365 code = CallPostamble(tcon, code, thost);
4367 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4369 #if FS_STATS_DETAILED
4370 TM_GetTimeOfDay(&opStopTime, 0);
4373 (opP->numSuccesses)++;
4374 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4375 fs_stats_AddTo((opP->sumTime), elapsedTime);
4376 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4377 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4378 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4380 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4381 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4385 #endif /* FS_STATS_DETAILED */
4387 osi_auditU(acall, SymlinkEvent, code,
4388 AUD_ID, t_client ? t_client->ViceId : 0,
4389 AUD_FID, DirFid, AUD_STR, Name,
4390 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4393 } /*SRXAFS_Symlink */
4397 * This routine is called exclusively by SRXAFS_Link(), and should be
4398 * merged into it when possible.
4401 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4402 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4403 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4405 Vnode *parentptr = 0; /* vnode of input Directory */
4406 Vnode *targetptr = 0; /* vnode of the new file */
4407 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4408 Volume *volptr = 0; /* pointer to the volume header */
4409 int errorCode = 0; /* error code */
4410 DirHandle dir; /* Handle for dir package I/O */
4411 struct client *client = 0; /* pointer to client structure */
4412 afs_int32 rights, anyrights; /* rights for this and any user */
4413 struct client *t_client; /* tmp ptr to client data */
4414 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4415 struct rx_connection *tcon = rx_ConnectionOf(acall);
4419 /* Get ptr to client data for user Id for logging */
4420 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4421 logHostAddr.s_addr = rxr_HostOf(tcon);
4423 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4424 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4425 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4426 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4428 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4430 if (DirFid->Volume != ExistingFid->Volume) {
4434 if (!FileNameOK(Name)) {
4440 * Get the vnode and volume for the parent dir along with the caller's
4444 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4445 &parentwhentargetnotdir, &client, WRITE_LOCK,
4446 &rights, &anyrights))) {
4450 /* set volume synchronization information */
4451 SetVolumeSync(Sync, volptr);
4453 /* Can the caller insert into the parent directory? */
4454 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4458 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4459 /* AFS fileservers always have directory vnodes that are odd. */
4464 /* get the file vnode */
4466 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4469 if (targetptr->disk.type != vFile) {
4473 if (targetptr->disk.parent != DirFid->Vnode) {
4477 if (parentptr->disk.cloned) {
4478 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4479 if ((errorCode = CopyOnWrite(parentptr, volptr)))
4480 goto Bad_Link; /* disk full error */
4483 /* add the name to the directory */
4484 SetDirHandle(&dir, parentptr);
4485 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4489 /* update the status in the parent vnode */
4490 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4491 #if FS_STATS_DETAILED
4492 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4493 parentptr->disk.linkCount,
4494 client->InSameNetwork);
4496 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4497 parentptr->disk.linkCount);
4498 #endif /* FS_STATS_DETAILED */
4500 targetptr->disk.linkCount++;
4501 targetptr->disk.author = client->ViceId;
4502 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4504 /* set up return status */
4505 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4506 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4508 /* convert the write locks to read locks before breaking callbacks */
4509 VVnodeWriteToRead(&errorCode, targetptr);
4510 assert(!errorCode || errorCode == VSALVAGE);
4511 VVnodeWriteToRead(&errorCode, parentptr);
4512 assert(!errorCode || errorCode == VSALVAGE);
4514 /* break call back on DirFid */
4515 BreakCallBack(client->host, DirFid, 0);
4517 * We also need to break the callback for the file that is hard-linked since part
4518 * of its status (like linkcount) is changed
4520 BreakCallBack(client->host, ExistingFid, 0);
4523 /* Write the all modified vnodes (parent, new files) and volume back */
4524 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4527 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4534 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4535 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4536 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4539 struct rx_connection *tcon;
4541 struct client *t_client = NULL; /* tmp ptr to client data */
4542 #if FS_STATS_DETAILED
4543 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4544 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4545 struct timeval elapsedTime; /* Transfer time */
4548 * Set our stats pointer, remember when the RPC operation started, and
4549 * tally the operation.
4551 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4555 TM_GetTimeOfDay(&opStartTime, 0);
4556 #endif /* FS_STATS_DETAILED */
4558 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4562 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4563 OutDirStatus, Sync);
4566 code = CallPostamble(tcon, code, thost);
4568 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4570 #if FS_STATS_DETAILED
4571 TM_GetTimeOfDay(&opStopTime, 0);
4574 (opP->numSuccesses)++;
4575 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4576 fs_stats_AddTo((opP->sumTime), elapsedTime);
4577 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4578 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4579 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4581 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4582 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4586 #endif /* FS_STATS_DETAILED */
4588 osi_auditU(acall, LinkEvent, code,
4589 AUD_ID, t_client ? t_client->ViceId : 0,
4590 AUD_FID, DirFid, AUD_STR, Name,
4591 AUD_FID, ExistingFid, AUD_END);
4598 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4599 * merged into it when possible.
4602 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4603 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4604 struct AFSFetchStatus *OutFidStatus,
4605 struct AFSFetchStatus *OutDirStatus,
4606 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4608 Vnode *parentptr = 0; /* vnode of input Directory */
4609 Vnode *targetptr = 0; /* vnode of the new file */
4610 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4611 Volume *volptr = 0; /* pointer to the volume header */
4612 int errorCode = 0; /* error code */
4613 struct acl_accessList *newACL; /* Access list */
4614 int newACLSize; /* Size of access list */
4615 DirHandle dir; /* Handle for dir package I/O */
4616 DirHandle parentdir; /* Handle for dir package I/O */
4617 struct client *client = 0; /* pointer to client structure */
4618 afs_int32 rights, anyrights; /* rights for this and any user */
4619 struct client *t_client; /* tmp ptr to client data */
4620 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4621 struct rx_connection *tcon = rx_ConnectionOf(acall);
4624 FidZero(&parentdir);
4626 /* Get ptr to client data for user Id for logging */
4627 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4628 logHostAddr.s_addr = rxr_HostOf(tcon);
4630 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4631 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4632 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4634 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4636 if (!FileNameOK(Name)) {
4642 * Get the vnode and volume for the parent dir along with the caller's
4646 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4647 &parentwhentargetnotdir, &client, WRITE_LOCK,
4648 &rights, &anyrights))) {
4652 /* set volume synchronization information */
4653 SetVolumeSync(Sync, volptr);
4655 /* Write access to the parent directory? */
4656 #ifdef DIRCREATE_NEED_WRITE
4658 * requires w access for the user to create a directory. this
4659 * closes a loophole in the current security arrangement, since a
4660 * user with i access only can create a directory and get the
4661 * implcit a access that goes with dir ownership, and proceed to
4662 * subvert quota in the volume.
4664 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4665 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4667 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4668 #endif /* DIRCREATE_NEED_WRITE */
4671 #define EMPTYDIRBLOCKS 2
4672 /* get a new vnode and set it up */
4674 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4675 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4679 /* Update the status for the parent dir */
4680 #if FS_STATS_DETAILED
4681 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4682 parentptr->disk.linkCount + 1,
4683 client->InSameNetwork);
4685 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4686 parentptr->disk.linkCount + 1);
4687 #endif /* FS_STATS_DETAILED */
4689 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4690 assert((SetAccessList
4691 (&targetptr, &volptr, &newACL, &newACLSize,
4692 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4693 assert(parentwhentargetnotdir == 0);
4694 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4696 /* update the status for the target vnode */
4697 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4698 parentptr, volptr, 0);
4700 /* Actually create the New directory in the directory package */
4701 SetDirHandle(&dir, targetptr);
4702 assert(!(MakeDir(&dir, OutFid, DirFid)));
4704 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4706 /* set up return status */
4707 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4708 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4710 /* convert the write lock to a read lock before breaking callbacks */
4711 VVnodeWriteToRead(&errorCode, parentptr);
4712 assert(!errorCode || errorCode == VSALVAGE);
4714 /* break call back on DirFid */
4715 BreakCallBack(client->host, DirFid, 0);
4717 /* Return a callback promise to caller */
4718 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4721 /* Write the all modified vnodes (parent, new files) and volume back */
4722 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4726 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4729 } /*SAFSS_MakeDir */
4733 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4734 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4735 struct AFSFetchStatus * OutFidStatus,
4736 struct AFSFetchStatus * OutDirStatus,
4737 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4740 struct rx_connection *tcon;
4742 struct client *t_client = NULL; /* tmp ptr to client data */
4743 #if FS_STATS_DETAILED
4744 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4745 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4746 struct timeval elapsedTime; /* Transfer time */
4749 * Set our stats pointer, remember when the RPC operation started, and
4750 * tally the operation.
4752 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
4756 TM_GetTimeOfDay(&opStartTime, 0);
4757 #endif /* FS_STATS_DETAILED */
4758 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4762 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4763 OutDirStatus, CallBack, Sync);
4766 code = CallPostamble(tcon, code, thost);
4768 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4770 #if FS_STATS_DETAILED
4771 TM_GetTimeOfDay(&opStopTime, 0);
4774 (opP->numSuccesses)++;
4775 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4776 fs_stats_AddTo((opP->sumTime), elapsedTime);
4777 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4778 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4779 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4781 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4782 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4786 #endif /* FS_STATS_DETAILED */
4788 osi_auditU(acall, MakeDirEvent, code,
4789 AUD_ID, t_client ? t_client->ViceId : 0,
4790 AUD_FID, DirFid, AUD_STR, Name,
4791 AUD_FID, OutFid, AUD_END);
4794 } /*SRXAFS_MakeDir */
4798 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4799 * merged into it when possible.
4802 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4803 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4805 Vnode *parentptr = 0; /* vnode of input Directory */
4806 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4807 Vnode *targetptr = 0; /* file to be deleted */
4808 AFSFid fileFid; /* area for Fid from the directory */
4809 int errorCode = 0; /* error code */
4810 DirHandle dir; /* Handle for dir package I/O */
4811 Volume *volptr = 0; /* pointer to the volume header */
4812 struct client *client = 0; /* pointer to client structure */
4813 afs_int32 rights, anyrights; /* rights for this and any user */
4814 Vnode debugvnode1, debugvnode2;
4815 struct client *t_client; /* tmp ptr to client data */
4816 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4817 struct rx_connection *tcon = rx_ConnectionOf(acall);
4821 /* Get ptr to client data for user Id for logging */
4822 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4823 logHostAddr.s_addr = rxr_HostOf(tcon);
4825 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4826 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4827 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4829 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4832 * Get the vnode and volume for the parent dir along with the caller's
4836 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4837 &parentwhentargetnotdir, &client, WRITE_LOCK,
4838 &rights, &anyrights))) {
4841 debugvnode1 = *parentptr;
4843 /* set volume synchronization information */
4844 SetVolumeSync(Sync, volptr);
4846 /* Does the caller has delete (&write) access to the parent dir? */
4847 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
4851 debugvnode2 = *parentptr;
4852 /* Do the actual delete of the desired (empty) directory, Name */
4854 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
4859 /* Update the status for the parent dir; link count is also adjusted */
4860 #if FS_STATS_DETAILED
4861 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4862 parentptr->disk.linkCount - 1,
4863 client->InSameNetwork);
4865 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4866 parentptr->disk.linkCount - 1);
4867 #endif /* FS_STATS_DETAILED */
4869 /* Return to the caller the updated parent dir status */
4870 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4873 * Note: it is not necessary to break the callback on fileFid, since
4874 * refcount is now 0, so no one should be able to refer to the dir
4877 DeleteFileCallBacks(&fileFid);
4879 /* convert the write lock to a read lock before breaking callbacks */
4880 VVnodeWriteToRead(&errorCode, parentptr);
4881 assert(!errorCode || errorCode == VSALVAGE);
4883 /* break call back on DirFid and fileFid */
4884 BreakCallBack(client->host, DirFid, 0);
4887 /* Write the all modified vnodes (parent, new files) and volume back */
4888 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4891 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
4894 } /*SAFSS_RemoveDir */
4898 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4899 struct AFSFetchStatus * OutDirStatus,
4900 struct AFSVolSync * Sync)
4903 struct rx_connection *tcon;
4905 struct client *t_client = NULL; /* tmp ptr to client data */
4906 #if FS_STATS_DETAILED
4907 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4908 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4909 struct timeval elapsedTime; /* Transfer time */
4912 * Set our stats pointer, remember when the RPC operation started, and
4913 * tally the operation.
4915 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
4919 TM_GetTimeOfDay(&opStartTime, 0);
4920 #endif /* FS_STATS_DETAILED */
4922 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4925 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
4928 code = CallPostamble(tcon, code, thost);
4930 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4932 #if FS_STATS_DETAILED
4933 TM_GetTimeOfDay(&opStopTime, 0);
4936 (opP->numSuccesses)++;
4937 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4938 fs_stats_AddTo((opP->sumTime), elapsedTime);
4939 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4940 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4941 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4943 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4944 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4948 #endif /* FS_STATS_DETAILED */
4950 osi_auditU(acall, RemoveDirEvent, code,
4951 AUD_ID, t_client ? t_client->ViceId : 0,
4952 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
4955 } /*SRXAFS_RemoveDir */
4959 * This routine is called exclusively by SRXAFS_SetLock(), and should be
4960 * merged into it when possible.
4963 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
4964 struct AFSVolSync *Sync)
4966 Vnode *targetptr = 0; /* vnode of input file */
4967 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4968 int errorCode = 0; /* error code */
4969 Volume *volptr = 0; /* pointer to the volume header */
4970 struct client *client = 0; /* pointer to client structure */
4971 afs_int32 rights, anyrights; /* rights for this and any user */
4972 struct client *t_client; /* tmp ptr to client data */
4973 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4974 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
4975 struct rx_connection *tcon = rx_ConnectionOf(acall);
4977 if (type != LockRead && type != LockWrite) {
4981 /* Get ptr to client data for user Id for logging */
4982 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4983 logHostAddr.s_addr = rxr_HostOf(tcon);
4985 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4986 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
4987 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4989 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
4992 * Get the vnode and volume for the desired file along with the caller's
4996 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
4997 &parentwhentargetnotdir, &client, WRITE_LOCK,
4998 &rights, &anyrights))) {
5002 /* set volume synchronization information */
5003 SetVolumeSync(Sync, volptr);
5005 /* Handle the particular type of set locking, type */
5006 errorCode = HandleLocking(targetptr, client, rights, type);
5009 /* Write the all modified vnodes (parent, new files) and volume back */
5010 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5013 if ((errorCode == VREADONLY) && (type == LockRead))
5014 errorCode = 0; /* allow read locks on RO volumes without saving state */
5016 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
5019 } /*SAFSS_SetLock */
5023 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
5024 ViceLockType type, struct AFSVolSync * Sync)
5026 return SRXAFS_SetLock(acall, Fid, type, Sync);
5027 } /*SRXAFS_OldSetLock */
5031 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
5032 struct AFSVolSync * Sync)
5035 struct rx_connection *tcon;
5037 struct client *t_client = NULL; /* tmp ptr to client data */
5038 #if FS_STATS_DETAILED
5039 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5040 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5041 struct timeval elapsedTime; /* Transfer time */
5044 * Set our stats pointer, remember when the RPC operation started, and
5045 * tally the operation.
5047 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5051 TM_GetTimeOfDay(&opStartTime, 0);
5052 #endif /* FS_STATS_DETAILED */
5054 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5057 code = SAFSS_SetLock(acall, Fid, type, Sync);
5060 code = CallPostamble(tcon, code, thost);
5062 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5064 #if FS_STATS_DETAILED
5065 TM_GetTimeOfDay(&opStopTime, 0);
5068 (opP->numSuccesses)++;
5069 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5070 fs_stats_AddTo((opP->sumTime), elapsedTime);
5071 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5072 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5073 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5075 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5076 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5080 #endif /* FS_STATS_DETAILED */
5082 osi_auditU(acall, SetLockEvent, code,
5083 AUD_ID, t_client ? t_client->ViceId : 0,
5084 AUD_FID, Fid, AUD_LONG, type, AUD_END);
5086 } /*SRXAFS_SetLock */
5090 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5091 * merged into it when possible.
5094 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5095 struct AFSVolSync *Sync)
5097 Vnode *targetptr = 0; /* vnode of input file */
5098 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5099 int errorCode = 0; /* error code */
5100 Volume *volptr = 0; /* pointer to the volume header */
5101 struct client *client = 0; /* pointer to client structure */
5102 afs_int32 rights, anyrights; /* rights for this and any user */
5103 struct client *t_client; /* tmp ptr to client data */
5104 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5105 struct rx_connection *tcon = rx_ConnectionOf(acall);
5107 /* Get ptr to client data for user Id for logging */
5108 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5109 logHostAddr.s_addr = rxr_HostOf(tcon);
5111 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5112 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5113 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5115 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5118 * Get the vnode and volume for the desired file along with the caller's
5122 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5123 &parentwhentargetnotdir, &client, WRITE_LOCK,
5124 &rights, &anyrights))) {
5125 goto Bad_ExtendLock;
5128 /* set volume synchronization information */
5129 SetVolumeSync(Sync, volptr);
5131 /* Handle the actual lock extension */
5132 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
5135 /* Put back file's vnode and volume */
5136 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5139 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5140 errorCode = 0; /* under our generous policy re RO vols */
5142 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5145 } /*SAFSS_ExtendLock */
5149 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5150 struct AFSVolSync * Sync)
5152 return SRXAFS_ExtendLock(acall, Fid, Sync);
5153 } /*SRXAFS_OldExtendLock */
5157 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5158 struct AFSVolSync * Sync)
5161 struct rx_connection *tcon;
5163 struct client *t_client = NULL; /* tmp ptr to client data */
5164 #if FS_STATS_DETAILED
5165 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5166 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5167 struct timeval elapsedTime; /* Transfer time */
5170 * Set our stats pointer, remember when the RPC operation started, and
5171 * tally the operation.
5173 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5177 TM_GetTimeOfDay(&opStartTime, 0);
5178 #endif /* FS_STATS_DETAILED */
5180 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5181 goto Bad_ExtendLock;
5183 code = SAFSS_ExtendLock(acall, Fid, Sync);
5186 code = CallPostamble(tcon, code, thost);
5188 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5190 #if FS_STATS_DETAILED
5191 TM_GetTimeOfDay(&opStopTime, 0);
5194 (opP->numSuccesses)++;
5195 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5196 fs_stats_AddTo((opP->sumTime), elapsedTime);
5197 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5198 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5199 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5201 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5202 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5206 #endif /* FS_STATS_DETAILED */
5208 osi_auditU(acall, ExtendLockEvent, code,
5209 AUD_ID, t_client ? t_client->ViceId : 0,
5210 AUD_FID, Fid, AUD_END);
5213 } /*SRXAFS_ExtendLock */
5217 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5218 * merged into it when possible.
5221 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5222 struct AFSVolSync *Sync)
5224 Vnode *targetptr = 0; /* vnode of input file */
5225 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5226 int errorCode = 0; /* error code */
5227 Volume *volptr = 0; /* pointer to the volume header */
5228 struct client *client = 0; /* pointer to client structure */
5229 afs_int32 rights, anyrights; /* rights for this and any user */
5230 struct client *t_client; /* tmp ptr to client data */
5231 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5232 struct rx_connection *tcon = rx_ConnectionOf(acall);
5234 /* Get ptr to client data for user Id for logging */
5235 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5236 logHostAddr.s_addr = rxr_HostOf(tcon);
5238 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5239 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5240 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5242 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5245 * Get the vnode and volume for the desired file along with the caller's
5249 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5250 &parentwhentargetnotdir, &client, WRITE_LOCK,
5251 &rights, &anyrights))) {
5252 goto Bad_ReleaseLock;
5255 /* set volume synchronization information */
5256 SetVolumeSync(Sync, volptr);
5258 /* Handle the actual lock release */
5259 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
5260 goto Bad_ReleaseLock;
5262 /* if no more locks left, a callback would be triggered here */
5263 if (targetptr->disk.lock.lockCount <= 0) {
5264 /* convert the write lock to a read lock before breaking callbacks */
5265 VVnodeWriteToRead(&errorCode, targetptr);
5266 assert(!errorCode || errorCode == VSALVAGE);
5267 BreakCallBack(client->host, Fid, 0);
5271 /* Put back file's vnode and volume */
5272 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5275 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5276 errorCode = 0; /* under our generous policy re RO vols */
5278 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5281 } /*SAFSS_ReleaseLock */
5285 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5286 struct AFSVolSync * Sync)
5288 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5289 } /*SRXAFS_OldReleaseLock */
5293 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5294 struct AFSVolSync * Sync)
5297 struct rx_connection *tcon;
5299 struct client *t_client = NULL; /* tmp ptr to client data */
5300 #if FS_STATS_DETAILED
5301 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5302 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5303 struct timeval elapsedTime; /* Transfer time */
5306 * Set our stats pointer, remember when the RPC operation started, and
5307 * tally the operation.
5309 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5313 TM_GetTimeOfDay(&opStartTime, 0);
5314 #endif /* FS_STATS_DETAILED */
5316 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5317 goto Bad_ReleaseLock;
5319 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5322 code = CallPostamble(tcon, code, thost);
5324 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5326 #if FS_STATS_DETAILED
5327 TM_GetTimeOfDay(&opStopTime, 0);
5330 (opP->numSuccesses)++;
5331 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5332 fs_stats_AddTo((opP->sumTime), elapsedTime);
5333 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5334 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5335 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5337 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5338 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5342 #endif /* FS_STATS_DETAILED */
5344 osi_auditU(acall, ReleaseLockEvent, code,
5345 AUD_ID, t_client ? t_client->ViceId : 0,
5346 AUD_FID, Fid, AUD_END);
5349 } /*SRXAFS_ReleaseLock */
5353 SetSystemStats(struct AFSStatistics *stats)
5355 /* Fix this sometime soon.. */
5356 /* Because hey, it's not like we have a network monitoring protocol... */
5357 struct timeval time;
5359 /* this works on all system types */
5360 TM_GetTimeOfDay(&time, 0);
5361 stats->CurrentTime = time.tv_sec;
5362 } /*SetSystemStats */
5365 SetAFSStats(struct AFSStatistics *stats)
5367 extern afs_int32 StartTime, CurrentConnections;
5371 stats->CurrentMsgNumber = 0;
5372 stats->OldestMsgNumber = 0;
5373 stats->StartTime = StartTime;
5374 stats->CurrentConnections = CurrentConnections;
5375 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5376 stats->TotalFetchs =
5377 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5378 AFSCallStats.FetchStatus;
5379 stats->FetchDatas = AFSCallStats.FetchData;
5380 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5381 seconds = AFSCallStats.AccumFetchTime / 1000;
5384 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5385 stats->TotalStores =
5386 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5387 AFSCallStats.StoreStatus;
5388 stats->StoreDatas = AFSCallStats.StoreData;
5389 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5390 seconds = AFSCallStats.AccumStoreTime / 1000;
5393 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5395 stats->ProcessSize = -1; /* TODO: */
5397 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5400 h_GetWorkStats((int *)&(stats->WorkStations),
5401 (int *)&(stats->ActiveWorkStations), (int *)0,
5402 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5406 /* Get disk related information from all AFS partitions. */
5409 SetVolumeStats(struct AFSStatistics *stats)
5411 struct DiskPartition *part;
5414 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5415 part = part->next) {
5416 stats->Disks[i].TotalBlocks = part->totalUsable;
5417 stats->Disks[i].BlocksAvailable = part->free;
5418 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5419 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5422 while (i < AFS_MSTATDISKS) {
5423 stats->Disks[i].TotalBlocks = -1;
5426 } /*SetVolumeStats */
5429 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5432 struct rx_connection *tcon = rx_ConnectionOf(acall);
5434 struct client *t_client = NULL; /* tmp ptr to client data */
5435 #if FS_STATS_DETAILED
5436 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5437 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5438 struct timeval elapsedTime; /* Transfer time */
5441 * Set our stats pointer, remember when the RPC operation started, and
5442 * tally the operation.
5444 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5448 TM_GetTimeOfDay(&opStartTime, 0);
5449 #endif /* FS_STATS_DETAILED */
5451 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5452 goto Bad_GetStatistics;
5454 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5456 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5458 memset(Statistics, 0, sizeof(*Statistics));
5459 SetAFSStats((struct AFSStatistics *)Statistics);
5460 SetVolumeStats((struct AFSStatistics *)Statistics);
5461 SetSystemStats((struct AFSStatistics *)Statistics);
5464 code = CallPostamble(tcon, code, thost);
5466 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5468 #if FS_STATS_DETAILED
5469 TM_GetTimeOfDay(&opStopTime, 0);
5472 (opP->numSuccesses)++;
5473 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5474 fs_stats_AddTo((opP->sumTime), elapsedTime);
5475 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5476 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5477 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5479 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5480 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5484 #endif /* FS_STATS_DETAILED */
5486 osi_auditU(acall, GetStatisticsEvent, code,
5487 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5489 } /*SRXAFS_GetStatistics */
5492 /*------------------------------------------------------------------------
5493 * EXPORTED SRXAFS_XStatsVersion
5496 * Routine called by the server-side RPC interface to implement
5497 * pulling out the xstat version number for the File Server.
5500 * a_versionP : Ptr to the version number variable to set.
5506 * Nothing interesting.
5510 *------------------------------------------------------------------------*/
5513 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5514 { /*SRXAFS_XStatsVersion */
5516 struct client *t_client = NULL; /* tmp ptr to client data */
5517 struct rx_connection *tcon;
5518 #if FS_STATS_DETAILED
5519 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5520 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5521 struct timeval elapsedTime; /* Transfer time */
5524 * Set our stats pointer, remember when the RPC operation started, and
5525 * tally the operation.
5527 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5531 TM_GetTimeOfDay(&opStartTime, 0);
5532 #endif /* FS_STATS_DETAILED */
5534 *a_versionP = AFS_XSTAT_VERSION;
5536 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5538 #if FS_STATS_DETAILED
5539 TM_GetTimeOfDay(&opStopTime, 0);
5540 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5541 fs_stats_AddTo((opP->sumTime), elapsedTime);
5542 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5543 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5544 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5546 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5547 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5550 (opP->numSuccesses)++;
5552 #endif /* FS_STATS_DETAILED */
5554 osi_auditU(a_call, XStatsVersionEvent, 0,
5555 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5557 } /*SRXAFS_XStatsVersion */
5560 /*------------------------------------------------------------------------
5561 * PRIVATE FillPerfValues
5564 * Routine called to fill a regular performance data structure.
5567 * a_perfP : Ptr to perf structure to fill
5573 * Various collections need this info, so the guts were put in
5574 * this separate routine.
5578 *------------------------------------------------------------------------*/
5581 FillPerfValues(struct afs_PerfStats *a_perfP)
5582 { /*FillPerfValues */
5584 int dir_Buffers; /*# buffers in use by dir package */
5585 int dir_Calls; /*# read calls in dir package */
5586 int dir_IOs; /*# I/O ops in dir package */
5589 * Vnode cache section.
5591 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5592 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5593 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5594 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5595 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5596 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5597 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5598 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5599 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5600 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5601 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5602 SplitInt64(VStats.hdr_gets, hi, lo);
5603 a_perfP->vcache_H_Gets = lo;
5604 SplitInt64(VStats.hdr_loads, hi, lo);
5605 a_perfP->vcache_H_Replacements = lo;
5608 * Directory section.
5610 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5611 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5612 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5613 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5618 a_perfP->rx_packetRequests = (afs_int32) rx_stats.packetRequests;
5619 a_perfP->rx_noPackets_RcvClass =
5620 (afs_int32) rx_stats.receivePktAllocFailures;
5621 a_perfP->rx_noPackets_SendClass =
5622 (afs_int32) rx_stats.sendPktAllocFailures;
5623 a_perfP->rx_noPackets_SpecialClass =
5624 (afs_int32) rx_stats.specialPktAllocFailures;
5625 a_perfP->rx_socketGreedy = (afs_int32) rx_stats.socketGreedy;
5626 a_perfP->rx_bogusPacketOnRead = (afs_int32) rx_stats.bogusPacketOnRead;
5627 a_perfP->rx_bogusHost = (afs_int32) rx_stats.bogusHost;
5628 a_perfP->rx_noPacketOnRead = (afs_int32) rx_stats.noPacketOnRead;
5629 a_perfP->rx_noPacketBuffersOnRead =
5630 (afs_int32) rx_stats.noPacketBuffersOnRead;
5631 a_perfP->rx_selects = (afs_int32) rx_stats.selects;
5632 a_perfP->rx_sendSelects = (afs_int32) rx_stats.sendSelects;
5633 a_perfP->rx_packetsRead_RcvClass =
5634 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
5635 a_perfP->rx_packetsRead_SendClass =
5636 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
5637 a_perfP->rx_packetsRead_SpecialClass =
5638 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
5639 a_perfP->rx_dataPacketsRead = (afs_int32) rx_stats.dataPacketsRead;
5640 a_perfP->rx_ackPacketsRead = (afs_int32) rx_stats.ackPacketsRead;
5641 a_perfP->rx_dupPacketsRead = (afs_int32) rx_stats.dupPacketsRead;
5642 a_perfP->rx_spuriousPacketsRead =
5643 (afs_int32) rx_stats.spuriousPacketsRead;
5644 a_perfP->rx_packetsSent_RcvClass =
5645 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
5646 a_perfP->rx_packetsSent_SendClass =
5647 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
5648 a_perfP->rx_packetsSent_SpecialClass =
5649 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
5650 a_perfP->rx_ackPacketsSent = (afs_int32) rx_stats.ackPacketsSent;
5651 a_perfP->rx_pingPacketsSent = (afs_int32) rx_stats.pingPacketsSent;
5652 a_perfP->rx_abortPacketsSent = (afs_int32) rx_stats.abortPacketsSent;
5653 a_perfP->rx_busyPacketsSent = (afs_int32) rx_stats.busyPacketsSent;
5654 a_perfP->rx_dataPacketsSent = (afs_int32) rx_stats.dataPacketsSent;
5655 a_perfP->rx_dataPacketsReSent = (afs_int32) rx_stats.dataPacketsReSent;
5656 a_perfP->rx_dataPacketsPushed = (afs_int32) rx_stats.dataPacketsPushed;
5657 a_perfP->rx_ignoreAckedPacket = (afs_int32) rx_stats.ignoreAckedPacket;
5658 a_perfP->rx_totalRtt_Sec = (afs_int32) rx_stats.totalRtt.sec;
5659 a_perfP->rx_totalRtt_Usec = (afs_int32) rx_stats.totalRtt.usec;
5660 a_perfP->rx_minRtt_Sec = (afs_int32) rx_stats.minRtt.sec;
5661 a_perfP->rx_minRtt_Usec = (afs_int32) rx_stats.minRtt.usec;
5662 a_perfP->rx_maxRtt_Sec = (afs_int32) rx_stats.maxRtt.sec;
5663 a_perfP->rx_maxRtt_Usec = (afs_int32) rx_stats.maxRtt.usec;
5664 a_perfP->rx_nRttSamples = (afs_int32) rx_stats.nRttSamples;
5665 a_perfP->rx_nServerConns = (afs_int32) rx_stats.nServerConns;
5666 a_perfP->rx_nClientConns = (afs_int32) rx_stats.nClientConns;
5667 a_perfP->rx_nPeerStructs = (afs_int32) rx_stats.nPeerStructs;
5668 a_perfP->rx_nCallStructs = (afs_int32) rx_stats.nCallStructs;
5669 a_perfP->rx_nFreeCallStructs = (afs_int32) rx_stats.nFreeCallStructs;
5671 a_perfP->host_NumHostEntries = HTs;
5672 a_perfP->host_HostBlocks = HTBlocks;
5673 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5674 &(a_perfP->host_HostsInSameNetOrSubnet),
5675 &(a_perfP->host_HostsInDiffSubnet),
5676 &(a_perfP->host_HostsInDiffNetwork));
5677 a_perfP->host_NumClients = CEs;
5678 a_perfP->host_ClientBlocks = CEBlocks;
5680 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5681 a_perfP->rx_nBusies = (afs_int32) rx_stats.nBusies;
5682 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5683 } /*FillPerfValues */
5686 /*------------------------------------------------------------------------
5687 * EXPORTED SRXAFS_GetXStats
5690 * Routine called by the server-side callback RPC interface to
5691 * implement getting the given data collection from the extended
5692 * File Server statistics.
5695 * a_call : Ptr to Rx call on which this request came in.
5696 * a_clientVersionNum : Client version number.
5697 * a_opCode : Desired operation.
5698 * a_serverVersionNumP : Ptr to version number to set.
5699 * a_timeP : Ptr to time value (seconds) to set.
5700 * a_dataP : Ptr to variable array structure to return
5707 * Nothing interesting.
5711 *------------------------------------------------------------------------*/
5714 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5715 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5716 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5717 { /*SRXAFS_GetXStats */
5719 register int code; /*Return value */
5720 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5721 afs_int32 dataBytes; /*Bytes in data buffer */
5722 #if FS_STATS_DETAILED
5723 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5724 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5725 struct timeval elapsedTime; /* Transfer time */
5728 * Set our stats pointer, remember when the RPC operation started, and
5729 * tally the operation.
5731 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
5735 TM_GetTimeOfDay(&opStartTime, 0);
5736 #endif /* FS_STATS_DETAILED */
5739 * Record the time of day and the server version number.
5741 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5742 *a_timeP = FT_ApproxTime();
5745 * Stuff the appropriate data in there (assume victory)
5750 ("Received GetXStats call for collection %d\n",
5751 a_collectionNumber));
5755 * We're not keeping stats, so just return successfully with
5758 a_dataP->AFS_CollData_len = 0;
5759 a_dataP->AFS_CollData_val = NULL;
5762 switch (a_collectionNumber) {
5763 case AFS_XSTATSCOLL_CALL_INFO:
5765 * Pass back all the call-count-related data.
5767 * >>> We are forced to allocate a separate area in which to
5768 * >>> put this stuff in by the RPC stub generator, since it
5769 * >>> will be freed at the tail end of the server stub code.
5773 * I don't think call-level stats are being collected yet
5774 * for the File Server.
5776 dataBytes = sizeof(struct afs_Stats);
5777 dataBuffP = (afs_int32 *) malloc(dataBytes);
5778 memcpy(dataBuffP, &afs_cmstats, dataBytes);
5779 a_dataP->AFS_CollData_len = dataBytes >> 2;
5780 a_dataP->AFS_CollData_val = dataBuffP;
5782 a_dataP->AFS_CollData_len = 0;
5783 a_dataP->AFS_CollData_val = NULL;
5787 case AFS_XSTATSCOLL_PERF_INFO:
5789 * Pass back all the regular performance-related data.
5791 * >>> We are forced to allocate a separate area in which to
5792 * >>> put this stuff in by the RPC stub generator, since it
5793 * >>> will be freed at the tail end of the server stub code.
5796 afs_perfstats.numPerfCalls++;
5797 FillPerfValues(&afs_perfstats);
5800 * Don't overwrite the spares at the end.
5803 dataBytes = sizeof(struct afs_PerfStats);
5804 dataBuffP = (afs_int32 *) malloc(dataBytes);
5805 memcpy(dataBuffP, &afs_perfstats, dataBytes);
5806 a_dataP->AFS_CollData_len = dataBytes >> 2;
5807 a_dataP->AFS_CollData_val = dataBuffP;
5810 case AFS_XSTATSCOLL_FULL_PERF_INFO:
5812 * Pass back the full collection of performance-related data.
5813 * We have to stuff the basic, overall numbers in, but the
5814 * detailed numbers are kept in the structure already.
5816 * >>> We are forced to allocate a separate area in which to
5817 * >>> put this stuff in by the RPC stub generator, since it
5818 * >>> will be freed at the tail end of the server stub code.
5821 afs_perfstats.numPerfCalls++;
5822 #if FS_STATS_DETAILED
5823 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
5824 FillPerfValues(&afs_FullPerfStats.overall);
5827 * Don't overwrite the spares at the end.
5830 dataBytes = sizeof(struct fs_stats_FullPerfStats);
5831 dataBuffP = (afs_int32 *) malloc(dataBytes);
5832 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
5833 a_dataP->AFS_CollData_len = dataBytes >> 2;
5834 a_dataP->AFS_CollData_val = dataBuffP;
5838 case AFS_XSTATSCOLL_CBSTATS:
5839 afs_perfstats.numPerfCalls++;
5841 dataBytes = sizeof(struct cbcounters);
5842 dataBuffP = (afs_int32 *) malloc(dataBytes);
5844 extern struct cbcounters cbstuff;
5845 dataBuffP[0]=cbstuff.DeleteFiles;
5846 dataBuffP[1]=cbstuff.DeleteCallBacks;
5847 dataBuffP[2]=cbstuff.BreakCallBacks;
5848 dataBuffP[3]=cbstuff.AddCallBacks;
5849 dataBuffP[4]=cbstuff.GotSomeSpaces;
5850 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
5851 dataBuffP[6]=cbstuff.nFEs;
5852 dataBuffP[7]=cbstuff.nCBs;
5853 dataBuffP[8]=cbstuff.nblks;
5854 dataBuffP[9]=cbstuff.CBsTimedOut;
5855 dataBuffP[10]=cbstuff.nbreakers;
5856 dataBuffP[11]=cbstuff.GSS1;
5857 dataBuffP[12]=cbstuff.GSS2;
5858 dataBuffP[13]=cbstuff.GSS3;
5859 dataBuffP[14]=cbstuff.GSS4;
5860 dataBuffP[15]=cbstuff.GSS5;
5863 a_dataP->AFS_CollData_len = dataBytes >> 2;
5864 a_dataP->AFS_CollData_val = dataBuffP;
5870 * Illegal collection number.
5872 a_dataP->AFS_CollData_len = 0;
5873 a_dataP->AFS_CollData_val = NULL;
5875 } /*Switch on collection number */
5877 #if FS_STATS_DETAILED
5878 TM_GetTimeOfDay(&opStopTime, 0);
5881 (opP->numSuccesses)++;
5882 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5883 fs_stats_AddTo((opP->sumTime), elapsedTime);
5884 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5885 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5886 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5888 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5889 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5893 #endif /* FS_STATS_DETAILED */
5897 } /*SRXAFS_GetXStats */
5901 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
5902 struct AFSCBs *CallBackArray)
5904 afs_int32 errorCode = 0;
5906 struct client *client = 0;
5907 struct rx_connection *tcon;
5909 #if FS_STATS_DETAILED
5910 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5911 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5912 struct timeval elapsedTime; /* Transfer time */
5915 * Set our stats pointer, remember when the RPC operation started, and
5916 * tally the operation.
5919 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
5923 TM_GetTimeOfDay(&opStartTime, 0);
5924 #endif /* FS_STATS_DETAILED */
5928 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
5929 FidArray->AFSCBFids_len));
5932 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
5934 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5935 goto Bad_GiveUpCallBacks;
5937 if (!FidArray && !CallBackArray) {
5939 ("SAFS_GiveUpAllCallBacks: host=%x\n",
5940 (tcon->peer ? tcon->peer->host : 0)));
5941 errorCode = GetClient(tcon, &client);
5943 DeleteAllCallBacks_r(client->host, 1);
5947 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
5949 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
5950 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
5951 (tcon->peer ? tcon->peer->host : 0)));
5953 goto Bad_GiveUpCallBacks;
5956 errorCode = GetClient(tcon, &client);
5958 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
5959 register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
5960 DeleteCallBack(client->host, fid);
5966 Bad_GiveUpCallBacks:
5967 errorCode = CallPostamble(tcon, errorCode, thost);
5969 #if FS_STATS_DETAILED
5970 TM_GetTimeOfDay(&opStopTime, 0);
5971 if (errorCode == 0) {
5973 (opP->numSuccesses)++;
5974 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5975 fs_stats_AddTo((opP->sumTime), elapsedTime);
5976 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5977 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5978 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5980 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5981 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5985 #endif /* FS_STATS_DETAILED */
5988 } /*common_GiveUpCallBacks */
5992 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
5993 struct AFSCBs * CallBackArray)
5995 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
5996 } /*SRXAFS_GiveUpCallBacks */
5999 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
6001 return common_GiveUpCallBacks(acall, 0, 0);
6002 } /*SRXAFS_GiveUpAllCallBacks */
6006 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
6007 struct AFSVolumeInfo * avolinfo)
6009 return (VNOVOL); /* XXX Obsolete routine XXX */
6011 } /*SRXAFS_NGetVolumeInfo */
6015 * Dummy routine. Should never be called (the cache manager should only
6016 * invoke this interface when communicating with a AFS/DFS Protocol
6020 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
6021 char *afs_name_p, struct AFSFid * afs_fid_p,
6022 struct AFSFetchStatus * afs_status_p,
6023 struct AFSFetchStatus * afs_dir_status_p,
6024 struct AFSCallBack * afs_callback_p,
6025 struct AFSVolSync * afs_sync_p)
6032 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
6035 struct rx_connection *tcon;
6037 afs_int32 *dataBuffP;
6038 afs_int32 dataBytes;
6041 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
6042 afs_FullPerfStats.overall.fs_nGetCaps++;
6044 ViceLog(2, ("SAFS_GetCapabilties\n"));
6046 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6049 dataBytes = 1 * sizeof(afs_int32);
6050 dataBuffP = (afs_int32 *) malloc(dataBytes);
6051 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS;
6052 #if defined(AFS_64BIT_ENV) && defined(AFS_LARGEFILE_ENV)
6053 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
6056 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
6057 capabilities->Capabilities_val = dataBuffP;
6060 code = CallPostamble(tcon, code, thost);
6067 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
6068 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
6072 afs_int32 nids, naddrs;
6073 afs_int32 *vd, *addr;
6074 int errorCode = 0; /* return code to caller */
6075 struct client *client = 0;
6076 struct rx_connection *tcon = rx_ConnectionOf(acall);
6078 ViceLog(1, ("SRXAFS_FlushCPS\n"));
6080 AFSCallStats.TotalCalls++;
6082 nids = vids->ViceIds_len; /* # of users in here */
6083 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
6084 if (nids < 0 || naddrs < 0) {
6089 vd = vids->ViceIds_val;
6090 for (i = 0; i < nids; i++, vd++) {
6093 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
6097 client->prfail = 2; /* Means re-eval client's cps */
6100 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6103 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6104 free(client->CPS.prlist_val);
6105 client->CPS.prlist_val = NULL;
6106 client->CPS.prlist_len = 0;
6108 ReleaseWriteLock(&client->lock);
6112 addr = addrs->IPAddrs_val;
6113 for (i = 0; i < naddrs; i++, addr++) {
6115 h_flushhostcps(*addr, htons(7001));
6119 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6121 } /*SRXAFS_FlushCPS */
6123 /* worthless hack to let CS keep running ancient software */
6125 afs_vtoi(register char *aname)
6127 register afs_int32 temp;
6131 while ((tc = *aname++)) {
6132 if (tc > '9' || tc < '0')
6133 return 0; /* invalid name */
6141 * may get name or #, but must handle all weird cases (recognize readonly
6142 * or backup volumes by name or #
6145 CopyVolumeEntry(char *aname, register struct vldbentry *ave,
6146 register struct VolumeInfo *av)
6148 register int i, j, vol;
6149 afs_int32 mask, whichType;
6150 afs_uint32 *serverHost, *typePtr;
6152 /* figure out what type we want if by name */
6154 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6155 whichType = BACKVOL;
6156 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6161 vol = afs_vtoi(aname);
6163 vol = ave->volumeId[whichType];
6166 * Now vol has volume # we're interested in. Next, figure out the type
6167 * of the volume by looking finding it in the vldb entry
6169 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6172 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6175 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6176 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6177 whichType = BACKVOL;
6179 return EINVAL; /* error: can't find volume in vldb entry */
6181 typePtr = &av->Type0;
6182 serverHost = &av->Server0;
6184 av->Type = whichType;
6185 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6186 if (ave->flags & VLF_RWEXISTS)
6187 typePtr[RWVOL] = ave->volumeId[RWVOL];
6188 if (ave->flags & VLF_ROEXISTS)
6189 typePtr[ROVOL] = ave->volumeId[ROVOL];
6190 if (ave->flags & VLF_BACKEXISTS)
6191 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6193 for (i = 0, j = 0; i < ave->nServers; i++) {
6194 if ((ave->serverFlags[i] & mask) == 0)
6195 continue; /* wrong volume */
6196 serverHost[j] = ave->serverNumber[i];
6199 av->ServerCount = j;
6201 serverHost[j++] = 0; /* bogus 8, but compat only now */
6206 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6208 static struct rx_connection *vlConn = 0;
6209 static int down = 0;
6210 static afs_int32 lastDownTime = 0;
6211 struct vldbentry tve;
6212 struct rx_securityClass *vlSec;
6213 register afs_int32 code;
6216 vlSec = rxnull_NewClientSecurityObject();
6218 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6219 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6221 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6222 return 1; /* failure */
6225 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6227 down = 0; /* call worked */
6230 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6236 /* otherwise convert to old format vldb entry */
6237 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6247 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6248 struct VolumeInfo * avolinfo)
6251 struct rx_connection *tcon;
6253 #if FS_STATS_DETAILED
6254 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6255 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6256 struct timeval elapsedTime; /* Transfer time */
6259 * Set our stats pointer, remember when the RPC operation started, and
6260 * tally the operation.
6262 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6266 TM_GetTimeOfDay(&opStartTime, 0);
6267 #endif /* FS_STATS_DETAILED */
6268 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6269 goto Bad_GetVolumeInfo;
6272 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6274 code = TryLocalVLServer(avolid, avolinfo);
6276 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6277 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6278 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6279 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6282 code = CallPostamble(tcon, code, thost);
6284 #if FS_STATS_DETAILED
6285 TM_GetTimeOfDay(&opStopTime, 0);
6288 (opP->numSuccesses)++;
6289 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6290 fs_stats_AddTo((opP->sumTime), elapsedTime);
6291 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6292 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6293 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6295 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6296 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6300 #endif /* FS_STATS_DETAILED */
6304 } /*SRXAFS_GetVolumeInfo */
6308 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6309 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6310 char **OfflineMsg, char **Motd)
6312 Vnode *targetptr = 0; /* vnode of the new file */
6313 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6314 int errorCode = 0; /* error code */
6315 Volume *volptr = 0; /* pointer to the volume header */
6316 struct client *client = 0; /* pointer to client entry */
6317 afs_int32 rights, anyrights; /* rights for this and any user */
6319 struct rx_connection *tcon;
6321 struct client *t_client = NULL; /* tmp ptr to client data */
6322 #if FS_STATS_DETAILED
6323 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6324 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6325 struct timeval elapsedTime; /* Transfer time */
6328 * Set our stats pointer, remember when the RPC operation started, and
6329 * tally the operation.
6332 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6336 TM_GetTimeOfDay(&opStartTime, 0);
6337 #endif /* FS_STATS_DETAILED */
6339 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6340 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6341 goto Bad_GetVolumeStatus;
6344 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6348 goto Bad_GetVolumeStatus;
6350 dummyFid.Volume = avolid, dummyFid.Vnode =
6351 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6354 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6355 &parentwhentargetnotdir, &client, READ_LOCK,
6356 &rights, &anyrights)))
6357 goto Bad_GetVolumeStatus;
6359 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6361 goto Bad_GetVolumeStatus;
6363 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6365 Bad_GetVolumeStatus:
6366 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6368 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6369 /* next is to guarantee out strings exist for stub */
6371 *Name = (char *)malloc(1);
6375 *Motd = (char *)malloc(1);
6378 if (*OfflineMsg == 0) {
6379 *OfflineMsg = (char *)malloc(1);
6382 errorCode = CallPostamble(tcon, errorCode, thost);
6384 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6386 #if FS_STATS_DETAILED
6387 TM_GetTimeOfDay(&opStopTime, 0);
6388 if (errorCode == 0) {
6390 (opP->numSuccesses)++;
6391 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6392 fs_stats_AddTo((opP->sumTime), elapsedTime);
6393 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6394 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6395 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6397 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6398 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6402 #endif /* FS_STATS_DETAILED */
6404 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
6405 AUD_ID, t_client ? t_client->ViceId : 0,
6406 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
6409 } /*SRXAFS_GetVolumeStatus */
6413 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6414 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6415 char *OfflineMsg, char *Motd)
6417 Vnode *targetptr = 0; /* vnode of the new file */
6418 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6419 int errorCode = 0; /* error code */
6420 Volume *volptr = 0; /* pointer to the volume header */
6421 struct client *client = 0; /* pointer to client entry */
6422 afs_int32 rights, anyrights; /* rights for this and any user */
6424 struct rx_connection *tcon = rx_ConnectionOf(acall);
6426 struct client *t_client = NULL; /* tmp ptr to client data */
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.
6437 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6441 TM_GetTimeOfDay(&opStartTime, 0);
6442 #endif /* FS_STATS_DETAILED */
6444 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6445 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6446 goto Bad_SetVolumeStatus;
6449 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6453 goto Bad_SetVolumeStatus;
6455 dummyFid.Volume = avolid, dummyFid.Vnode =
6456 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6459 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6460 &parentwhentargetnotdir, &client, READ_LOCK,
6461 &rights, &anyrights)))
6462 goto Bad_SetVolumeStatus;
6464 if (readonlyServer) {
6465 errorCode = VREADONLY;
6466 goto Bad_SetVolumeStatus;
6468 if (VanillaUser(client)) {
6470 goto Bad_SetVolumeStatus;
6474 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6476 Bad_SetVolumeStatus:
6477 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6479 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6480 errorCode = CallPostamble(tcon, errorCode, thost);
6482 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6484 #if FS_STATS_DETAILED
6485 TM_GetTimeOfDay(&opStopTime, 0);
6486 if (errorCode == 0) {
6488 (opP->numSuccesses)++;
6489 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6490 fs_stats_AddTo((opP->sumTime), elapsedTime);
6491 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6492 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6493 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6495 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6496 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6500 #endif /* FS_STATS_DETAILED */
6502 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6503 AUD_ID, t_client ? t_client->ViceId : 0,
6504 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6506 } /*SRXAFS_SetVolumeStatus */
6508 #define DEFAULTVOLUME "root.afs"
6511 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6517 struct rx_connection *tcon;
6521 #if FS_STATS_DETAILED
6522 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6523 struct timeval opStartTime; /* Start time for RPC op */
6525 struct timeval opStopTime;
6526 struct timeval elapsedTime; /* Transfer time */
6530 * Set our stats pointer, remember when the RPC operation started, and
6531 * tally the operation.
6533 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6537 TM_GetTimeOfDay(&opStartTime, 0);
6538 #endif /* FS_STATS_DETAILED */
6540 return FSERR_EOPNOTSUPP;
6543 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
6544 goto Bad_GetRootVolume;
6546 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6549 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6551 strcpy(temp, DEFAULTVOLUME);
6553 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6554 lockf(fd, F_LOCK, 0);
6558 len = read(fd, temp, 256);
6559 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6560 lockf(fd, F_ULOCK, 0);
6565 if (temp[len - 1] == '\n')
6569 *VolumeName = temp; /* freed by rx server-side stub */
6572 errorCode = CallPostamble(tcon, errorCode, thost);
6574 #if FS_STATS_DETAILED
6575 TM_GetTimeOfDay(&opStopTime, 0);
6576 if (errorCode == 0) {
6578 (opP->numSuccesses)++;
6579 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6580 fs_stats_AddTo((opP->sumTime), elapsedTime);
6581 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6582 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6583 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6585 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6586 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6590 #endif /* FS_STATS_DETAILED */
6595 } /*SRXAFS_GetRootVolume */
6598 /* still works because a struct CBS is the same as a struct AFSOpaque */
6600 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6601 struct AFSOpaque * Token)
6604 struct rx_connection *tcon;
6606 #if FS_STATS_DETAILED
6607 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6608 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6609 struct timeval elapsedTime; /* Transfer time */
6612 * Set our stats pointer, remember when the RPC operation started, and
6613 * tally the operation.
6615 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6619 TM_GetTimeOfDay(&opStartTime, 0);
6620 #endif /* FS_STATS_DETAILED */
6622 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6623 goto Bad_CheckToken;
6625 code = FSERR_ECONNREFUSED;
6628 code = CallPostamble(tcon, code, thost);
6630 #if FS_STATS_DETAILED
6631 TM_GetTimeOfDay(&opStopTime, 0);
6634 (opP->numSuccesses)++;
6635 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6636 fs_stats_AddTo((opP->sumTime), elapsedTime);
6637 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6638 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6639 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6641 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6642 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6646 #endif /* FS_STATS_DETAILED */
6650 } /*SRXAFS_CheckToken */
6653 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6654 afs_uint32 * USeconds)
6657 struct rx_connection *tcon;
6660 #if FS_STATS_DETAILED
6661 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6662 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6663 struct timeval elapsedTime; /* Transfer time */
6666 * Set our stats pointer, remember when the RPC operation started, and
6667 * tally the operation.
6669 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
6673 TM_GetTimeOfDay(&opStartTime, 0);
6674 #endif /* FS_STATS_DETAILED */
6676 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6680 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6682 TM_GetTimeOfDay(&tpl, 0);
6683 *Seconds = tpl.tv_sec;
6684 *USeconds = tpl.tv_usec;
6686 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6689 code = CallPostamble(tcon, code, thost);
6691 #if FS_STATS_DETAILED
6692 TM_GetTimeOfDay(&opStopTime, 0);
6693 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6696 (opP->numSuccesses)++;
6697 fs_stats_AddTo((opP->sumTime), elapsedTime);
6698 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6699 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6700 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6702 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6703 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6707 #endif /* FS_STATS_DETAILED */
6711 } /*SRXAFS_GetTime */
6718 * Implement a client's data fetch using Rx.
6721 * volptr : Ptr to the given volume's info.
6722 * targetptr : Pointer to the vnode involved.
6723 * Call : Ptr to the Rx call involved.
6724 * Pos : Offset within the file.
6725 * Len : Length in bytes to read; this value is bogus!
6726 * if FS_STATS_DETAILED
6727 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6729 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6735 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
6736 register struct rx_call * Call, afs_sfsize_t Pos,
6737 afs_sfsize_t Len, afs_int32 Int64Mode,
6738 #if FS_STATS_DETAILED
6739 afs_sfsize_t * a_bytesToFetchP,
6740 afs_sfsize_t * a_bytesFetchedP
6741 #endif /* FS_STATS_DETAILED */
6744 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6745 int errorCode = 0; /* Returned error code to caller */
6749 register char *tbuffer;
6750 #else /* AFS_NT40_ENV */
6751 struct iovec tiov[RX_MAXIOVECS];
6753 #endif /* AFS_NT40_ENV */
6757 #if FS_STATS_DETAILED
6759 * Initialize the byte count arguments.
6761 (*a_bytesToFetchP) = 0;
6762 (*a_bytesFetchedP) = 0;
6763 #endif /* FS_STATS_DETAILED */
6767 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
6768 (afs_uintmax_t) Len));
6770 if (!VN_GET_INO(targetptr)) {
6771 afs_int32 zero = htonl(0);
6773 * This is used for newly created files; we simply send 0 bytes
6774 * back to make the cache manager happy...
6777 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6778 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6781 TM_GetTimeOfDay(&StartTime, 0);
6782 ihP = targetptr->handle;
6785 VTakeOffline(volptr);
6788 optSize = sendBufSize;
6789 tlen = FDH_SIZE(fdP);
6791 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
6794 VTakeOffline(volptr);
6801 if (Pos + Len > tlen)
6802 Len = tlen - Pos; /* get length we should send */
6803 (void)FDH_SEEK(fdP, Pos, 0);
6805 afs_int32 high, low;
6806 SplitOffsetOrSize(Len, high, low);
6807 assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
6810 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
6813 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
6815 #if FS_STATS_DETAILED
6816 (*a_bytesToFetchP) = Len;
6817 #endif /* FS_STATS_DETAILED */
6819 tbuffer = AllocSendBuffer();
6820 #endif /* AFS_NT40_ENV */
6828 errorCode = FDH_READ(fdP, tbuffer, wlen);
6829 if (errorCode != wlen) {
6831 FreeSendBuffer((struct afs_buffer *)tbuffer);
6832 VTakeOffline(volptr);
6835 errorCode = rx_Write(Call, tbuffer, wlen);
6836 #else /* AFS_NT40_ENV */
6837 errorCode = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
6838 if (errorCode <= 0) {
6843 errorCode = FDH_READV(fdP, tiov, tnio);
6844 if (errorCode != wlen) {
6846 VTakeOffline(volptr);
6849 errorCode = rx_Writev(Call, tiov, tnio, wlen);
6850 #endif /* AFS_NT40_ENV */
6851 #if FS_STATS_DETAILED
6853 * Bump the number of bytes actually sent by the number from this
6856 (*a_bytesFetchedP) += errorCode;
6857 #endif /* FS_STATS_DETAILED */
6858 if (errorCode != wlen) {
6861 FreeSendBuffer((struct afs_buffer *)tbuffer);
6862 #endif /* AFS_NT40_ENV */
6868 FreeSendBuffer((struct afs_buffer *)tbuffer);
6869 #endif /* AFS_NT40_ENV */
6871 TM_GetTimeOfDay(&StopTime, 0);
6873 /* Adjust all Fetch Data related stats */
6875 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
6876 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
6877 AFSCallStats.AccumFetchTime +=
6878 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
6879 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
6881 afs_fsize_t targLen;
6882 VN_GET_LEN(targLen, targetptr);
6883 AFSCallStats.TotalFetchedBytes += targLen;
6884 AFSCallStats.FetchSize1++;
6885 if (targLen < SIZE2)
6886 AFSCallStats.FetchSize2++;
6887 else if (targLen < SIZE3)
6888 AFSCallStats.FetchSize3++;
6889 else if (targLen < SIZE4)
6890 AFSCallStats.FetchSize4++;
6892 AFSCallStats.FetchSize5++;
6897 } /*FetchData_RXStyle */
6900 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
6901 afs_sfsize_t * size)
6903 #ifdef AFS_NAMEI_ENV
6905 lhp = IH_OPEN(V_linkHandle(vp));
6909 *lc = nt_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
6911 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
6916 *size = OS_SIZE(fdP->fd_fd);
6917 return (*size == -1) ? -1 : 0;
6919 struct afs_stat status;
6921 if (afs_fstat(fdP->fd_fd, &status) < 0) {
6925 *lc = GetLinkCount(vp, &status);
6926 *size = status.st_size;
6935 * Implement a client's data store using Rx.
6938 * volptr : Ptr to the given volume's info.
6939 * targetptr : Pointer to the vnode involved.
6940 * Call : Ptr to the Rx call involved.
6941 * Pos : Offset within the file.
6942 * Len : Length in bytes to store; this value is bogus!
6943 * if FS_STATS_DETAILED
6944 * a_bytesToStoreP : Set to the number of bytes to be stored to
6946 * a_bytesStoredP : Set to the actual number of bytes stored to
6951 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
6952 struct client * client, register struct rx_call * Call,
6953 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
6955 #if FS_STATS_DETAILED
6956 afs_sfsize_t * a_bytesToStoreP,
6957 afs_sfsize_t * a_bytesStoredP
6958 #endif /* FS_STATS_DETAILED */
6961 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
6962 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
6963 int errorCode = 0; /* Returned error code to caller */
6965 register char *tbuffer; /* data copying buffer */
6966 #else /* AFS_NT40_ENV */
6967 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
6968 int tnio; /* temp for iovec size */
6969 #endif /* AFS_NT40_ENV */
6970 afs_sfsize_t tlen; /* temp for xfr length */
6971 Inode tinode; /* inode for I/O */
6972 afs_int32 optSize; /* optimal transfer size */
6973 afs_sfsize_t DataLength; /* size of inode */
6974 afs_sfsize_t TruncatedLength; /* size after ftruncate */
6975 afs_fsize_t NewLength; /* size after this store completes */
6976 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
6977 int linkCount; /* link count on inode */
6979 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
6981 #if FS_STATS_DETAILED
6983 * Initialize the byte count arguments.
6985 (*a_bytesToStoreP) = 0;
6986 (*a_bytesStoredP) = 0;
6987 #endif /* FS_STATS_DETAILED */
6990 * We break the callbacks here so that the following signal will not
6993 BreakCallBack(client->host, Fid, 0);
6995 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
6996 /* the inode should have been created in Alloc_NewVnode */
6997 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
6999 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
7000 Fid->Volume, Fid->Vnode, Fid->Unique,
7001 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
7002 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
7003 return ENOENT; /* is this proper error code? */
7006 * See if the file has several links (from other volumes). If it
7007 * does, then we have to make a copy before changing it to avoid
7008 *changing read-only clones of this dude
7011 ("StoreData_RXStyle : Opening inode %s\n",
7012 PrintInode(NULL, VN_GET_INO(targetptr))));
7013 fdP = IH_OPEN(targetptr->handle);
7016 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
7018 VTakeOffline(volptr);
7022 if (linkCount != 1) {
7025 ("StoreData_RXStyle : inode %s has more than onelink\n",
7026 PrintInode(NULL, VN_GET_INO(targetptr))));
7027 /* other volumes share this data, better copy it first */
7029 /* Adjust the disk block count by the creation of the new inode.
7030 * We call the special VDiskUsage so we don't adjust the volume's
7031 * quota since we don't want to penalyze the user for afs's internal
7032 * mechanisms (i.e. copy on write overhead.) Also the right size
7033 * of the disk will be recorded...
7036 VN_GET_LEN(size, targetptr);
7037 volptr->partition->flags &= ~PART_DONTUPDATE;
7038 VSetPartitionDiskUsage(volptr->partition);
7039 volptr->partition->flags |= PART_DONTUPDATE;
7040 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
7041 volptr->partition->flags &= ~PART_DONTUPDATE;
7045 ViceLog(25, ("StoreData : calling CopyOnWrite on target dir\n"));
7046 if ((errorCode = CopyOnWrite(targetptr, volptr))) {
7047 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
7048 volptr->partition->flags &= ~PART_DONTUPDATE;
7051 volptr->partition->flags &= ~PART_DONTUPDATE;
7052 VSetPartitionDiskUsage(volptr->partition);
7053 fdP = IH_OPEN(targetptr->handle);
7056 ("StoreData : Reopen after CopyOnWrite failed\n"));
7060 tinode = VN_GET_INO(targetptr);
7062 assert(VALID_INO(tinode));
7064 /* compute new file length */
7065 NewLength = DataLength;
7066 if (FileLength < NewLength)
7067 /* simulate truncate */
7068 NewLength = FileLength;
7069 TruncatedLength = NewLength; /* remember length after possible ftruncate */
7070 if (Pos + Length > NewLength)
7071 NewLength = Pos + Length; /* and write */
7073 /* adjust the disk block count by the difference in the files */
7075 afs_fsize_t targSize;
7076 VN_GET_LEN(targSize, targetptr);
7077 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
7080 AdjustDiskUsage(volptr, adjustSize,
7081 adjustSize - SpareComp(volptr)))) {
7086 /* can signal cache manager to proceed from close now */
7087 /* this bit means that the locks are set and protections are OK */
7088 rx_SetLocalStatus(Call, 1);
7090 TM_GetTimeOfDay(&StartTime, 0);
7092 optSize = sendBufSize;
7094 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
7095 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
7096 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
7098 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
7099 if (FileLength < DataLength)
7100 FDH_TRUNC(fdP, FileLength);
7102 FDH_SEEK(fdP, Pos, 0);
7103 bytesTransfered = 0;
7105 tbuffer = AllocSendBuffer();
7106 #endif /* AFS_NT40_ENV */
7107 /* if length == 0, the loop below isn't going to do anything, including
7108 * extend the length of the inode, which it must do, since the file system
7109 * assumes that the inode length == vnode's file length. So, we extend
7110 * the file length manually if need be. Note that if file is bigger than
7111 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7112 * do what we're going to do below.
7114 if (Length == 0 && Pos > TruncatedLength) {
7115 /* Set the file's length; we've already done an lseek to the right
7118 errorCode = FDH_WRITE(fdP, &tlen, 1);
7121 errorCode = FDH_TRUNC(fdP, Pos);
7123 /* have some data to copy */
7124 #if FS_STATS_DETAILED
7125 (*a_bytesToStoreP) = Length;
7126 #endif /* FS_STATS_DETAILED */
7129 if (bytesTransfered >= Length) {
7133 tlen = Length - bytesTransfered; /* how much more to do */
7135 rlen = optSize; /* bound by buffer size */
7139 errorCode = rx_Read(Call, tbuffer, rlen);
7140 #else /* AFS_NT40_ENV */
7141 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7142 #endif /* AFS_NT40_ENV */
7143 #if FS_STATS_DETAILED
7144 (*a_bytesStoredP) += errorCode;
7145 #endif /* FS_STATS_DETAILED */
7146 if (errorCode <= 0) {
7152 errorCode = FDH_WRITE(fdP, tbuffer, rlen);
7153 #else /* AFS_NT40_ENV */
7154 errorCode = FDH_WRITEV(fdP, tiov, tnio);
7155 #endif /* AFS_NT40_ENV */
7156 if (errorCode != rlen) {
7157 errorCode = VDISKFULL;
7160 bytesTransfered += rlen;
7165 FreeSendBuffer((struct afs_buffer *)tbuffer);
7166 #endif /* AFS_NT40_ENV */
7171 afs_fsize_t nfSize = (afs_fsize_t) FDH_SIZE(fdP);
7172 /* something went wrong: adjust size and return */
7173 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7174 /* changed_newTime is tested in StoreData to detemine if we
7175 * need to update the target vnode.
7177 targetptr->changed_newTime = 1;
7179 /* set disk usage to be correct */
7180 VAdjustDiskUsage(&errorCode, volptr,
7181 (afs_sfsize_t) (nBlocks(nfSize) -
7182 nBlocks(NewLength)), 0);
7187 TM_GetTimeOfDay(&StopTime, 0);
7189 VN_SET_LEN(targetptr, NewLength);
7191 /* Update all StoreData related stats */
7193 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7194 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7195 AFSCallStats.StoreSize1++; /* Piggybacked data */
7197 afs_fsize_t targLen;
7198 VN_GET_LEN(targLen, targetptr);
7199 if (targLen < SIZE2)
7200 AFSCallStats.StoreSize2++;
7201 else if (targLen < SIZE3)
7202 AFSCallStats.StoreSize3++;
7203 else if (targLen < SIZE4)
7204 AFSCallStats.StoreSize4++;
7206 AFSCallStats.StoreSize5++;
7211 } /*StoreData_RXStyle */
7213 static int sys2et[512];
7216 init_sys_error_to_et(void)
7218 memset(&sys2et, 0, sizeof(sys2et));
7219 sys2et[EPERM] = UAEPERM;
7220 sys2et[ENOENT] = UAENOENT;
7221 sys2et[ESRCH] = UAESRCH;
7222 sys2et[EINTR] = UAEINTR;
7223 sys2et[EIO] = UAEIO;
7224 sys2et[ENXIO] = UAENXIO;
7225 sys2et[E2BIG] = UAE2BIG;
7226 sys2et[ENOEXEC] = UAENOEXEC;
7227 sys2et[EBADF] = UAEBADF;
7228 sys2et[ECHILD] = UAECHILD;
7229 sys2et[EAGAIN] = UAEAGAIN;
7230 sys2et[ENOMEM] = UAENOMEM;
7231 sys2et[EACCES] = UAEACCES;
7232 sys2et[EFAULT] = UAEFAULT;
7233 sys2et[ENOTBLK] = UAENOTBLK;
7234 sys2et[EBUSY] = UAEBUSY;
7235 sys2et[EEXIST] = UAEEXIST;
7236 sys2et[EXDEV] = UAEXDEV;
7237 sys2et[ENODEV] = UAENODEV;
7238 sys2et[ENOTDIR] = UAENOTDIR;
7239 sys2et[EISDIR] = UAEISDIR;
7240 sys2et[EINVAL] = UAEINVAL;
7241 sys2et[ENFILE] = UAENFILE;
7242 sys2et[EMFILE] = UAEMFILE;
7243 sys2et[ENOTTY] = UAENOTTY;
7244 sys2et[ETXTBSY] = UAETXTBSY;
7245 sys2et[EFBIG] = UAEFBIG;
7246 sys2et[ENOSPC] = UAENOSPC;
7247 sys2et[ESPIPE] = UAESPIPE;
7248 sys2et[EROFS] = UAEROFS;
7249 sys2et[EMLINK] = UAEMLINK;
7250 sys2et[EPIPE] = UAEPIPE;
7251 sys2et[EDOM] = UAEDOM;
7252 sys2et[ERANGE] = UAERANGE;
7253 sys2et[EDEADLK] = UAEDEADLK;
7254 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7255 sys2et[ENOLCK] = UAENOLCK;
7256 sys2et[ENOSYS] = UAENOSYS;
7257 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7258 sys2et[ELOOP] = UAELOOP;
7259 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7260 sys2et[ENOMSG] = UAENOMSG;
7261 sys2et[EIDRM] = UAEIDRM;
7262 sys2et[ECHRNG] = UAECHRNG;
7263 sys2et[EL2NSYNC] = UAEL2NSYNC;
7264 sys2et[EL3HLT] = UAEL3HLT;
7265 sys2et[EL3RST] = UAEL3RST;
7266 sys2et[ELNRNG] = UAELNRNG;
7267 sys2et[EUNATCH] = UAEUNATCH;
7268 sys2et[ENOCSI] = UAENOCSI;
7269 sys2et[EL2HLT] = UAEL2HLT;
7270 sys2et[EBADE] = UAEBADE;
7271 sys2et[EBADR] = UAEBADR;
7272 sys2et[EXFULL] = UAEXFULL;
7273 sys2et[ENOANO] = UAENOANO;
7274 sys2et[EBADRQC] = UAEBADRQC;
7275 sys2et[EBADSLT] = UAEBADSLT;
7276 sys2et[EDEADLK] = UAEDEADLK;
7277 sys2et[EBFONT] = UAEBFONT;
7278 sys2et[ENOSTR] = UAENOSTR;
7279 sys2et[ENODATA] = UAENODATA;
7280 sys2et[ETIME] = UAETIME;
7281 sys2et[ENOSR] = UAENOSR;
7282 sys2et[ENONET] = UAENONET;
7283 sys2et[ENOPKG] = UAENOPKG;
7284 sys2et[EREMOTE] = UAEREMOTE;
7285 sys2et[ENOLINK] = UAENOLINK;
7286 sys2et[EADV] = UAEADV;
7287 sys2et[ESRMNT] = UAESRMNT;
7288 sys2et[ECOMM] = UAECOMM;
7289 sys2et[EPROTO] = UAEPROTO;
7290 sys2et[EMULTIHOP] = UAEMULTIHOP;
7291 sys2et[EDOTDOT] = UAEDOTDOT;
7292 sys2et[EBADMSG] = UAEBADMSG;
7293 sys2et[EOVERFLOW] = UAEOVERFLOW;
7294 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7295 sys2et[EBADFD] = UAEBADFD;
7296 sys2et[EREMCHG] = UAEREMCHG;
7297 sys2et[ELIBACC] = UAELIBACC;
7298 sys2et[ELIBBAD] = UAELIBBAD;
7299 sys2et[ELIBSCN] = UAELIBSCN;
7300 sys2et[ELIBMAX] = UAELIBMAX;
7301 sys2et[ELIBEXEC] = UAELIBEXEC;
7302 sys2et[EILSEQ] = UAEILSEQ;
7303 sys2et[ERESTART] = UAERESTART;
7304 sys2et[ESTRPIPE] = UAESTRPIPE;
7305 sys2et[EUSERS] = UAEUSERS;
7306 sys2et[ENOTSOCK] = UAENOTSOCK;
7307 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7308 sys2et[EMSGSIZE] = UAEMSGSIZE;
7309 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7310 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7311 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7312 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7313 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7314 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7315 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7316 sys2et[EADDRINUSE] = UAEADDRINUSE;
7317 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7318 sys2et[ENETDOWN] = UAENETDOWN;
7319 sys2et[ENETUNREACH] = UAENETUNREACH;
7320 sys2et[ENETRESET] = UAENETRESET;
7321 sys2et[ECONNABORTED] = UAECONNABORTED;
7322 sys2et[ECONNRESET] = UAECONNRESET;
7323 sys2et[ENOBUFS] = UAENOBUFS;
7324 sys2et[EISCONN] = UAEISCONN;
7325 sys2et[ENOTCONN] = UAENOTCONN;
7326 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7327 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7328 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7329 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7330 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7331 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7332 sys2et[EALREADY] = UAEALREADY;
7333 sys2et[EINPROGRESS] = UAEINPROGRESS;
7334 sys2et[ESTALE] = UAESTALE;
7335 sys2et[EUCLEAN] = UAEUCLEAN;
7336 sys2et[ENOTNAM] = UAENOTNAM;
7337 sys2et[ENAVAIL] = UAENAVAIL;
7338 sys2et[EISNAM] = UAEISNAM;
7339 sys2et[EREMOTEIO] = UAEREMOTEIO;
7340 sys2et[EDQUOT] = UAEDQUOT;
7341 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7342 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7346 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
7347 * - pass back the connection, client, and host from CallPreamble
7348 * - keep a ref on the client, which we don't now
7349 * - keep a hold on the host, which we already do
7350 * - pass the connection, client, and host down into SAFSS_*, and use
7351 * them instead of independently discovering them via rx_ConnectionOf
7352 * (safe) and rx_GetSpecific (not so safe)
7353 * The idea being that we decide what client and host we're going to use
7354 * when CallPreamble is called, and stay consistent throughout the call.
7355 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
7359 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7361 Error errorCode = 0;
7362 struct rx_connection *tcon;
7363 struct host *tcallhost;
7364 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7366 struct client *tclient;
7367 static struct rx_securityClass *sc = 0;
7369 struct rx_connection *conn;
7372 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost))
7373 goto Bad_CallBackRxConnAddr1;
7375 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7379 tclient = h_FindClient_r(tcon);
7380 thost = tclient->host;
7382 /* nothing more can be done */
7383 if ( !thost->interface )
7384 goto Bad_CallBackRxConnAddr;
7386 assert(thost->interface->numberOfInterfaces > 0 );
7388 /* the only address is the primary interface */
7389 /* can't change when there's only 1 address, anyway */
7390 if ( thost->interface->numberOfInterfaces == 1 )
7391 goto Bad_CallBackRxConnAddr;
7393 /* initialise a security object only once */
7395 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7397 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7399 if ( *addr == thost->interface->addr[i] ) {
7404 if ( *addr != thost->interface->addr[i] )
7405 goto Bad_CallBackRxConnAddr;
7407 conn = rx_NewConnection (thost->interface->addr[i],
7408 thost->port, 1, sc, 0);
7409 rx_SetConnDeadTime(conn, 2);
7410 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7412 errorCode = RXAFSCB_Probe(conn);
7415 if ( thost->callback_rxcon )
7416 rx_DestroyConnection(thost->callback_rxcon);
7417 thost->callback_rxcon = conn;
7419 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7420 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7421 h_ReleaseClient_r(tclient);
7422 /* The hold on thost will be released by CallPostamble */
7424 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7427 rx_DestroyConnection(conn);
7429 Bad_CallBackRxConnAddr:
7430 h_ReleaseClient_r(tclient);
7431 /* The hold on thost will be released by CallPostamble */
7435 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7436 Bad_CallBackRxConnAddr1:
7437 return errorCode; /* failure */
7441 sys_error_to_et(afs_int32 in)
7445 if (in < 0 || in > 511)
7447 if (in >= VICE_SPECIAL_ERRORS && in <= VIO || in == VRESTRICTED)
7449 if (sys2et[in] != 0)