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>
110 #include <afs/partition.h>
111 #include "viced_prototypes.h"
114 #include "callback.h"
115 #include <afs/unified_afs.h>
116 #include <afs/audit.h>
117 #include <afs/afsutil.h>
120 extern void SetDirHandle(register DirHandle * dir, register Vnode * vnode);
121 extern void FidZap(DirHandle * file);
122 extern void FidZero(DirHandle * file);
124 #ifdef AFS_PTHREAD_ENV
125 pthread_mutex_t fileproc_glock_mutex;
126 #endif /* AFS_PTHREAD_ENV */
129 #define afs_stat stat64
130 #define afs_fstat fstat64
131 #define afs_open open64
132 #else /* !O_LARGEFILE */
133 #define afs_stat stat
134 #define afs_fstat fstat
135 #define afs_open open
136 #endif /* !O_LARGEFILE */
139 /* Useful local defines used by this module */
142 #define MustNOTBeDIR 1
146 #define TVS_SSTATUS 2
149 #define TVS_MKDIR 0x10
151 #define CHK_FETCH 0x10
152 #define CHK_FETCHDATA 0x10
153 #define CHK_FETCHACL 0x11
154 #define CHK_FETCHSTATUS 0x12
155 #define CHK_STOREDATA 0x00
156 #define CHK_STOREACL 0x01
157 #define CHK_STORESTATUS 0x02
159 #define OWNERREAD 0400
160 #define OWNERWRITE 0200
161 #define OWNEREXEC 0100
162 #ifdef USE_GROUP_PERMS
163 #define GROUPREAD 0040
164 #define GROUPWRITE 0020
165 #define GROUPREXEC 0010
168 /* The following errors were not defined in NT. They are given unique
169 * names here to avoid any potential collision.
171 #define FSERR_ELOOP 90
172 #define FSERR_EOPNOTSUPP 122
173 #define FSERR_ECONNREFUSED 130
175 #define NOTACTIVECALL 0
178 #define CREATE_SGUID_ADMIN_ONLY 1
180 extern struct afsconf_dir *confDir;
181 extern afs_int32 dataVersionHigh;
184 static struct AFSCallStatistics AFSCallStats;
185 #if FS_STATS_DETAILED
186 struct fs_stats_FullPerfStats afs_FullPerfStats;
187 extern int AnonymousID;
188 #endif /* FS_STATS_DETAILED */
189 #if OPENAFS_VOL_STATS
190 static const char nullString[] = "";
191 #endif /* OPENAFS_VOL_STATS */
194 afs_int32 NothingYet;
197 struct afs_FSStats afs_fsstats;
199 void ResetDebug(), SetDebug(), Terminate();
204 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
206 extern afs_int32 implicitAdminRights;
207 extern afs_int32 readonlyServer;
210 * Externals used by the xstat code.
212 extern VolPkgStats VStats;
213 extern int CEs, CEBlocks;
215 extern int HTs, HTBlocks;
217 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
218 register struct rx_call *Call, afs_sfsize_t Pos,
219 afs_sfsize_t Len, afs_int32 Int64Mode,
220 #if FS_STATS_DETAILED
221 afs_sfsize_t * a_bytesToFetchP,
222 afs_sfsize_t * a_bytesFetchedP
223 #endif /* FS_STATS_DETAILED */
226 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
227 struct AFSFid *Fid, struct client *client,
228 register struct rx_call *Call, afs_fsize_t Pos,
229 afs_fsize_t Length, afs_fsize_t FileLength,
231 #if FS_STATS_DETAILED
232 afs_sfsize_t * a_bytesToStoreP,
233 afs_sfsize_t * a_bytesStoredP
234 #endif /* FS_STATS_DETAILED */
237 #ifdef AFS_SGI_XFS_IOPS_ENV
238 #include <afs/xfsattrs.h>
240 GetLinkCount(Volume * avp, struct stat *astat)
242 if (!strcmp("xfs", astat->st_fstype)) {
243 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
245 return astat->st_nlink;
248 #define GetLinkCount(V, S) (S)->st_nlink
252 SpareComp(Volume * avolp)
254 register afs_int32 temp;
258 temp = V_maxquota(avolp);
260 /* no matter; doesn't check in this case */
264 temp = (temp * PctSpare) / 100;
275 * Set the volume synchronization parameter for this volume. If it changes,
276 * the Cache Manager knows that the volume must be purged from the stat cache.
279 SetVolumeSync(register struct AFSVolSync *async, register Volume * avol)
282 /* date volume instance was created */
285 async->spare1 = avol->header->diskstuff.creationDate;
298 * Note that this function always returns a held host, so
299 * that CallPostamble can block without the host's disappearing.
300 * Call returns rx connection in passed in *tconn
303 CallPreamble(register struct rx_call *acall, int activecall,
304 struct rx_connection **tconn, struct host **ahostp)
307 struct client *tclient;
310 char hoststr[16], hoststr2[16];
311 struct ubik_client *uclient;
316 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
319 *tconn = rx_ConnectionOf(acall);
323 tclient = h_FindClient_r(*tconn);
324 thost = tclient->host;
325 if (tclient->prfail == 1) { /* couldn't get the CPS */
327 h_ReleaseClient_r(tclient);
329 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
333 retry_flag = 0; /* Retry once */
335 /* Take down the old connection and re-read the key file */
337 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
338 #ifdef AFS_PTHREAD_ENV
339 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
341 /* Is it still necessary to drop this? We hit the net, we should... */
345 code = hpr_Initialize(&uclient);
347 assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
350 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
353 h_ReleaseClient_r(tclient);
356 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
360 tclient->prfail = 2; /* Means re-eval client's cps */
361 h_ReleaseClient_r(tclient);
366 tclient->LastCall = thost->LastCall = FT_ApproxTime();
367 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
368 thost->ActiveCall = thost->LastCall;
371 if (thost->hostFlags & HOSTDELETED) {
373 ("Discarded a packet for deleted host %s:%d\n",
374 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
375 code = VBUSY; /* raced, so retry */
376 } else if ((thost->hostFlags & VENUSDOWN)
377 || (thost->hostFlags & HFE_LATER)) {
378 if (BreakDelayedCallBacks_r(thost)) {
380 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
381 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
382 ntohs(rxr_PortOf(*tconn))));
383 if (MultiProbeAlternateAddress_r(thost)) {
385 ("MultiProbe failed to find new address for host %s:%d\n",
386 afs_inet_ntoa_r(thost->host, hoststr),
387 ntohs(thost->port)));
391 ("MultiProbe found new address for host %s:%d\n",
392 afs_inet_ntoa_r(thost->host, hoststr),
393 ntohs(thost->port)));
394 if (BreakDelayedCallBacks_r(thost)) {
396 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
397 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
398 ntohs(rxr_PortOf(*tconn))));
407 h_ReleaseClient_r(tclient);
417 CallPostamble(register struct rx_connection *aconn, afs_int32 ret,
421 struct client *tclient;
426 tclient = h_FindClient_r(aconn);
427 thost = tclient->host;
428 if (thost->hostFlags & HERRORTRANS)
430 h_ReleaseClient_r(tclient);
431 held = h_Held_r(thost);
434 if (ahost && ahost != thost) {
435 char hoststr[16], hoststr2[16];
436 ViceLog(0, ("CallPostamble: ahost %s:%d (%x) != thost %s:%d (%x)\n",
437 afs_inet_ntoa_r(ahost->host, hoststr), ntohs(ahost->port),
439 afs_inet_ntoa_r(thost->host, hoststr2), ntohs(thost->port),
444 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%x)\n",
445 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port),
449 return (translate ? sys_error_to_et(ret) : ret);
453 * Returns the volume and vnode pointers associated with file Fid; the lock
454 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
455 * are incremented and they must be eventualy released.
458 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
461 afs_int32 local_errorCode, errorCode = -1;
462 static struct timeval restartedat = { 0, 0 };
464 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
466 if ((*volptr) == 0) {
471 *volptr = VGetVolume(&local_errorCode, &errorCode, (afs_int32) fid->Volume);
476 if ((errorCode == VOFFLINE) && (VInit < 2)) {
477 /* The volume we want may not be attached yet because
478 * the volume initialization is not yet complete.
479 * We can do several things:
480 * 1. return -1, which will cause users to see
481 * "connection timed out". This is more or
482 * less the same as always, except that the servers
483 * may appear to bounce up and down while they
484 * are actually restarting.
485 * 2. return VBUSY which will cause clients to
486 * sleep and retry for 6.5 - 15 minutes, depending
487 * on what version of the CM they are running. If
488 * the file server takes longer than that interval
489 * to attach the desired volume, then the application
490 * will see an ENODEV or EIO. This approach has
491 * the advantage that volumes which have been attached
492 * are immediately available, it keeps the server's
493 * immediate backlog low, and the call is interruptible
494 * by the user. Users see "waiting for busy volume."
495 * 3. sleep here and retry. Some people like this approach
496 * because there is no danger of seeing errors. However,
497 * this approach only works with a bounded number of
498 * clients, since the pending queues will grow without
499 * stopping. It might be better to find a way to take
500 * this call and stick it back on a queue in order to
501 * recycle this thread for a different request.
502 * 4. Return a new error code, which new cache managers will
503 * know enough to interpret as "sleep and retry", without
504 * the upper bound of 6-15 minutes that is imposed by the
505 * VBUSY handling. Users will see "waiting for
506 * busy volume," so they know that something is
507 * happening. Old cache managers must be able to do
508 * something reasonable with this, for instance, mark the
509 * server down. Fortunately, any error code < 0
510 * will elicit that behavior. See #1.
511 * 5. Some combination of the above. I like doing #2 for 10
512 * minutes, followed by #4. 3.1b and 3.2 cache managers
513 * will be fine as long as the restart period is
514 * not longer than 6.5 minutes, otherwise they may
515 * return ENODEV to users. 3.3 cache managers will be
516 * fine for 10 minutes, then will return
517 * ETIMEDOUT. 3.4 cache managers will just wait
518 * until the call works or fails definitively.
519 * NB. The problem with 2,3,4,5 is that old clients won't
520 * fail over to an alternate read-only replica while this
521 * server is restarting. 3.4 clients will fail over right away.
523 if (restartedat.tv_sec == 0) {
524 /* I'm not really worried about when we restarted, I'm */
525 /* just worried about when the first VBUSY was returned. */
526 TM_GetTimeOfDay(&restartedat, 0);
529 afs_perfstats.fs_nBusies++;
532 return (busyonrst ? VBUSY : VRESTARTING);
535 TM_GetTimeOfDay(&now, 0);
536 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
539 afs_perfstats.fs_nBusies++;
542 return (busyonrst ? VBUSY : VRESTARTING);
544 return (VRESTARTING);
548 /* allow read operations on busy volume.
549 * must check local_errorCode because demand attach fs
550 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
551 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
554 } else if (errorCode)
561 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
564 if ((*vptr)->disk.uniquifier != fid->Unique) {
565 VPutVnode(&fileCode, *vptr);
566 assert(fileCode == 0);
568 return (VNOVNODE); /* return the right error code, at least */
574 * This routine returns the ACL associated with the targetptr. If the
575 * targetptr isn't a directory, we access its parent dir and get the ACL
576 * thru the parent; in such case the parent's vnode is returned in
580 SetAccessList(Vnode ** targetptr, Volume ** volume,
581 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
582 AFSFid * Fid, int Lock)
584 if ((*targetptr)->disk.type == vDirectory) {
586 *ACL = VVnodeACL(*targetptr);
587 *ACLSize = VAclSize(*targetptr);
595 parentvnode = (*targetptr)->disk.parent;
596 VPutVnode(&errorCode, *targetptr);
600 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
603 *ACL = VVnodeACL(*parent);
604 *ACLSize = VAclSize(*parent);
605 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
607 if ((*targetptr)->disk.parent != parentvnode) {
608 VPutVnode(&errorCode, *parent);
619 /* Must not be called with H_LOCK held */
621 client_CheckRights(struct client *client, struct acl_accessList *ACL,
625 ObtainReadLock(&client->lock);
626 if (client->CPS.prlist_len > 0 && !client->deleted &&
627 client->host && !(client->host->hostFlags & HOSTDELETED))
628 acl_CheckRights(ACL, &client->CPS, rights);
629 ReleaseReadLock(&client->lock);
632 /* Must not be called with H_LOCK held */
634 client_HasAsMember(struct client *client, afs_int32 id)
638 ObtainReadLock(&client->lock);
639 if (client->CPS.prlist_len > 0 && !client->deleted &&
640 client->host && !(client->host->hostFlags & HOSTDELETED))
641 code = acl_IsAMember(id, &client->CPS);
642 ReleaseReadLock(&client->lock);
647 * Compare the directory's ACL with the user's access rights in the client
648 * connection and return the user's and everybody else's access permissions
649 * in rights and anyrights, respectively
652 GetRights(struct client *client, struct acl_accessList *ACL,
653 afs_int32 * rights, afs_int32 * anyrights)
655 extern prlist SystemAnyUserCPS;
656 afs_int32 hrights = 0;
657 #ifndef AFS_PTHREAD_ENV
661 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
662 ViceLog(0, ("CheckRights failed\n"));
667 client_CheckRights(client, ACL, rights);
669 /* wait if somebody else is already doing the getCPS call */
671 while (client->host->hostFlags & HCPS_INPROGRESS) {
672 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
673 #ifdef AFS_PTHREAD_ENV
674 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
675 #else /* AFS_PTHREAD_ENV */
677 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
678 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
679 #endif /* AFS_PTHREAD_ENV */
682 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
685 ("CheckRights: len=%u, for host=%s:%d\n",
686 client->host->hcps.prlist_len,
687 afs_inet_ntoa_r(client->host->host, hoststr),
688 ntohs(client->host->port)));
690 acl_CheckRights(ACL, &client->host->hcps, &hrights);
692 /* Allow system:admin the rights given with the -implicit option */
693 if (client_HasAsMember(client, SystemId))
694 *rights |= implicitAdminRights;
697 *anyrights |= hrights;
704 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
705 * a System:Administrator)
708 VanillaUser(struct client *client)
710 if (client_HasAsMember(client, SystemId))
711 return (0); /* not a system administrator, then you're "vanilla" */
718 * This unusual afs_int32-parameter routine encapsulates all volume package related
719 * operations together in a single function; it's called by almost all AFS
723 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
724 Vnode ** targetptr, int chkforDir, Vnode ** parent,
725 struct client **client, int locktype, afs_int32 * rights,
726 afs_int32 * anyrights)
728 struct acl_accessList *aCL; /* Internal access List */
729 int aCLSize; /* size of the access list */
730 int errorCode = 0; /* return code to caller */
732 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
735 if (chkforDir == MustNOTBeDIR
736 && ((*targetptr)->disk.type == vDirectory))
738 else if (chkforDir == MustBeDIR
739 && ((*targetptr)->disk.type != vDirectory))
743 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
744 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
745 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
747 if (chkforDir == MustBeDIR)
748 assert((*parent) == 0);
750 if ((errorCode = GetClient(tcon, client)) != 0)
755 GetRights(*client, aCL, rights, anyrights);
756 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
757 if ((*targetptr)->disk.type != vDirectory) {
758 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
759 if ((*targetptr)->disk.owner == (*client)->ViceId)
760 (*rights) |= PRSFS_ADMINISTER;
762 (*rights) &= ~PRSFS_ADMINISTER;
764 #ifdef ADMIN_IMPLICIT_LOOKUP
765 /* admins get automatic lookup on everything */
766 if (!VanillaUser(*client))
767 (*rights) |= PRSFS_LOOKUP;
768 #endif /* ADMIN_IMPLICIT_LOOKUP */
771 } /*GetVolumePackage */
775 * This is the opposite of GetVolumePackage(), and is always used at the end of
776 * AFS calls to put back all used vnodes and the volume in the proper order!
779 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
780 Vnode * parentptr, Volume * volptr, struct client **client)
782 int fileCode = 0; /* Error code returned by the volume package */
784 if (parentwhentargetnotdir) {
785 VPutVnode(&fileCode, parentwhentargetnotdir);
786 assert(!fileCode || (fileCode == VSALVAGE));
789 VPutVnode(&fileCode, targetptr);
790 assert(!fileCode || (fileCode == VSALVAGE));
793 VPutVnode(&fileCode, parentptr);
794 assert(!fileCode || (fileCode == VSALVAGE));
802 } /*PutVolumePackage */
805 VolumeOwner(register struct client *client, register Vnode * targetptr)
807 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
810 return (client->ViceId == owner);
813 * We don't have to check for host's cps since only regular
814 * viceid are volume owners.
816 return (client_HasAsMember(client, owner));
822 VolumeRootVnode(Vnode * targetptr)
824 return ((targetptr->vnodeNumber == ROOTVNODE)
825 && (targetptr->disk.uniquifier == 1));
827 } /*VolumeRootVnode */
830 * Check if target file has the proper access permissions for the Fetch
831 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
832 * StoreStatus) related calls
834 /* this code should probably just set a "priv" flag where all the audit events
835 * are now, and only generate the audit event once at the end of the routine,
836 * thus only generating the event if all the checks succeed, but only because
837 * of the privilege XXX
840 Check_PermissionRights(Vnode * targetptr, struct client *client,
841 afs_int32 rights, int CallingRoutine,
842 AFSStoreStatus * InStatus)
845 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
846 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
847 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
849 if (CallingRoutine & CHK_FETCH) {
850 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
851 if (targetptr->disk.type == vDirectory
852 || targetptr->disk.type == vSymlink) {
853 if (!(rights & PRSFS_LOOKUP)
854 #ifdef ADMIN_IMPLICIT_LOOKUP
855 /* grant admins fetch on all directories */
856 && VanillaUser(client)
857 #endif /* ADMIN_IMPLICIT_LOOKUP */
858 && !VolumeOwner(client, targetptr))
861 /* must have read access, or be owner and have insert access */
862 if (!(rights & PRSFS_READ)
863 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
866 if (CallingRoutine == CHK_FETCHDATA
867 && targetptr->disk.type == vFile)
868 #ifdef USE_GROUP_PERMS
869 if (!OWNSp(client, targetptr)
870 && !client_HasAsMember(client, targetptr->disk.owner)) {
872 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
876 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
881 * The check with the ownership below is a kludge to allow
882 * reading of files created with no read permission. The owner
883 * of the file is always allowed to read it.
885 if ((client->ViceId != targetptr->disk.owner)
886 && VanillaUser(client))
888 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
889 modeBits) ? 0 : EACCES);
891 } else { /* !VanillaUser(client) && !FetchData */
893 osi_audit(PrivilegeEvent, 0, AUD_ID,
894 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
897 } else { /* a store operation */
898 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
899 && (CallingRoutine != CHK_STOREACL)
900 && (targetptr->disk.type == vFile)) {
901 /* bypass protection checks on first store after a create
902 * for the creator; also prevent chowns during this time
903 * unless you are a system administrator */
904 /****** InStatus->Owner && UnixModeBits better be SET!! */
905 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
908 else if (VanillaUser(client))
909 return (EPERM); /* Was EACCES */
911 osi_audit(PrivilegeEvent, 0, AUD_ID,
912 (client ? client->ViceId : 0), AUD_INT,
913 CallingRoutine, AUD_END);
916 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
917 osi_audit(PrivilegeEvent, 0, AUD_ID,
918 (client ? client->ViceId : 0), AUD_INT,
919 CallingRoutine, AUD_END);
921 if (readonlyServer) {
924 if (CallingRoutine == CHK_STOREACL) {
925 if (!(rights & PRSFS_ADMINISTER)
926 && !VolumeOwner(client, targetptr))
928 } else { /* store data or status */
929 /* watch for chowns and chgrps */
930 if (CHOWN(InStatus, targetptr)
931 || CHGRP(InStatus, targetptr)) {
934 else if (VanillaUser(client))
935 return (EPERM); /* Was EACCES */
937 osi_audit(PrivilegeEvent, 0, AUD_ID,
938 (client ? client->ViceId : 0), AUD_INT,
939 CallingRoutine, AUD_END);
941 /* must be sysadmin to set suid/sgid bits */
942 if ((InStatus->Mask & AFS_SETMODE) &&
944 (InStatus->UnixModeBits & 0xc00) != 0) {
946 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
950 if (VanillaUser(client))
953 osi_audit(PrivSetID, 0, AUD_ID,
954 (client ? client->ViceId : 0), AUD_INT,
955 CallingRoutine, AUD_END);
957 if (CallingRoutine == CHK_STOREDATA) {
960 if (!(rights & PRSFS_WRITE))
962 /* Next thing is tricky. We want to prevent people
963 * from writing files sans 0200 bit, but we want
964 * creating new files with 0444 mode to work. We
965 * don't check the 0200 bit in the "you are the owner"
966 * path above, but here we check the bit. However, if
967 * you're a system administrator, we ignore the 0200
968 * bit anyway, since you may have fchowned the file,
970 #ifdef USE_GROUP_PERMS
971 if ((targetptr->disk.type == vFile)
972 && VanillaUser(client)) {
973 if (!OWNSp(client, targetptr)
974 && !client_HasAsMember(client, targetptr->disk.owner)) {
976 ((GROUPWRITE & targetptr->disk.modeBits)
980 ((OWNERWRITE & targetptr->disk.modeBits)
985 if ((targetptr->disk.type != vDirectory)
986 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
989 if (VanillaUser(client))
992 osi_audit(PrivilegeEvent, 0, AUD_ID,
993 (client ? client->ViceId : 0),
994 AUD_INT, CallingRoutine, AUD_END);
996 } else { /* a status store */
999 if (targetptr->disk.type == vDirectory) {
1000 if (!(rights & PRSFS_DELETE)
1001 && !(rights & PRSFS_INSERT))
1003 } else { /* a file or symlink */
1004 if (!(rights & PRSFS_WRITE))
1014 } /*Check_PermissionRights */
1018 * The Access List information is converted from its internal form in the
1019 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1020 * external form and returned back to the caller, via the AccessList
1024 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1025 struct AFSOpaque *AccessList)
1027 char *eACL; /* External access list placeholder */
1030 ((targetptr->disk.type ==
1031 vDirectory ? VVnodeACL(targetptr) :
1032 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1035 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1036 acl_FreeExternalACL(&eACL);
1039 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1040 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1042 acl_FreeExternalACL(&eACL);
1045 } /*RXFetch_AccessList */
1049 * The Access List information is converted from its external form in the
1050 * input AccessList structure to the internal representation and copied into
1051 * the target dir's vnode storage.
1054 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1056 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1058 if (acl_Internalize(AccessList->AFSOpaque_val, &newACL) != 0)
1060 if ((newACL->size + 4) > VAclSize(targetptr))
1062 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1063 acl_FreeACL(&newACL);
1066 } /*RXStore_AccessList */
1069 /* In our current implementation, each successive data store (new file
1070 * data version) creates a new inode. This function creates the new
1071 * inode, copies the old inode's contents to the new one, remove the old
1072 * inode (i.e. decrement inode count -- if it's currently used the delete
1073 * will be delayed), and modify some fields (i.e. vnode's
1074 * disk.inodeNumber and cloned)
1076 #define COPYBUFFSIZE 8192
1078 CopyOnWrite(Vnode * targetptr, Volume * volptr)
1080 Inode ino, nearInode;
1083 register afs_fsize_t size;
1084 register int length;
1086 int rc; /* return code */
1087 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1088 FdHandle_t *targFdP; /* Source Inode file handle */
1089 FdHandle_t *newFdP; /* Dest Inode file handle */
1091 if (targetptr->disk.type == vDirectory)
1092 DFlush(); /* just in case? */
1094 VN_GET_LEN(size, targetptr);
1095 buff = (char *)malloc(COPYBUFFSIZE);
1100 ino = VN_GET_INO(targetptr);
1101 assert(VALID_INO(ino));
1102 targFdP = IH_OPEN(targetptr->handle);
1103 if (targFdP == NULL) {
1106 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1107 targetptr->vnodeNumber, V_id(volptr), rc));
1109 VTakeOffline(volptr);
1113 nearInode = VN_GET_INO(targetptr);
1115 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1116 VPartitionPath(V_partition(volptr)), nearInode,
1117 V_id(volptr), targetptr->vnodeNumber,
1118 targetptr->disk.uniquifier,
1119 (int)targetptr->disk.dataVersion);
1120 if (!VALID_INO(ino)) {
1122 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1123 volptr->partition->name, V_id(volptr), errno));
1128 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1129 newFdP = IH_OPEN(newH);
1130 assert(newFdP != NULL);
1133 if (size > COPYBUFFSIZE) { /* more than a buffer */
1134 length = COPYBUFFSIZE;
1135 size -= COPYBUFFSIZE;
1140 rdlen = FDH_READ(targFdP, buff, length);
1141 if (rdlen == length)
1142 wrlen = FDH_WRITE(newFdP, buff, length);
1145 /* Callers of this function are not prepared to recover
1146 * from error that put the filesystem in an inconsistent
1147 * state. Make sure that we force the volume off-line if
1148 * we some error other than ENOSPC - 4.29.99)
1150 * In case we are unable to write the required bytes, and the
1151 * error code indicates that the disk is full, we roll-back to
1152 * the initial state.
1154 if ((rdlen != length) || (wrlen != length))
1155 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1157 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1158 volptr->partition->name, V_id(volptr)));
1159 /* remove destination inode which was partially copied till now */
1160 FDH_REALLYCLOSE(newFdP);
1162 FDH_REALLYCLOSE(targFdP);
1163 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1166 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1167 rc, V_id(volptr), volptr->partition->name));
1168 VTakeOffline(volptr);
1174 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1175 V_id(volptr), volptr->partition->name, length, rdlen,
1177 #if defined(AFS_DEMAND_ATTACH_FS)
1178 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1180 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1182 /* Decrement this inode so salvager doesn't find it. */
1183 FDH_REALLYCLOSE(newFdP);
1185 FDH_REALLYCLOSE(targFdP);
1186 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1188 VTakeOffline(volptr);
1191 #ifndef AFS_PTHREAD_ENV
1193 #endif /* !AFS_PTHREAD_ENV */
1195 FDH_REALLYCLOSE(targFdP);
1196 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1197 V_parentId(volptr));
1199 IH_RELEASE(targetptr->handle);
1201 rc = FDH_SYNC(newFdP);
1204 targetptr->handle = newH;
1205 VN_SET_INO(targetptr, ino);
1206 targetptr->disk.cloned = 0;
1207 /* Internal change to vnode, no user level change to volume - def 5445 */
1208 targetptr->changed_oldTime = 1;
1210 return 0; /* success */
1215 * Common code to handle with removing the Name (file when it's called from
1216 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1217 * given directory, parentptr.
1219 int DT1 = 0, DT0 = 0;
1221 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1222 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1224 DirHandle childdir; /* Handle for dir package I/O */
1228 /* watch for invalid names */
1229 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1231 if (parentptr->disk.cloned) {
1232 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1233 if ((errorCode = CopyOnWrite(parentptr, volptr))) {
1235 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1241 /* check that the file is in the directory */
1242 SetDirHandle(dir, parentptr);
1243 if (Lookup(dir, Name, fileFid))
1245 fileFid->Volume = V_id(volptr);
1247 /* just-in-case check for something causing deadlock */
1248 if (fileFid->Vnode == parentptr->vnodeNumber)
1251 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1255 if (ChkForDir == MustBeDIR) {
1256 if ((*targetptr)->disk.type != vDirectory)
1258 } else if ((*targetptr)->disk.type == vDirectory)
1261 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1263 * If the uniquifiers dont match then instead of asserting
1264 * take the volume offline and return VSALVAGE
1266 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1267 VTakeOffline(volptr);
1268 errorCode = VSALVAGE;
1272 if (ChkForDir == MustBeDIR) {
1273 SetDirHandle(&childdir, *targetptr);
1274 if (IsEmpty(&childdir) != 0)
1277 (*targetptr)->delete = 1;
1278 } else if ((--(*targetptr)->disk.linkCount) == 0)
1279 (*targetptr)->delete = 1;
1280 if ((*targetptr)->delete) {
1281 if (VN_GET_INO(*targetptr)) {
1283 IH_REALLYCLOSE((*targetptr)->handle);
1285 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1286 V_parentId(volptr));
1287 IH_RELEASE((*targetptr)->handle);
1288 if (errorCode == -1) {
1290 ("DT: inode=%s, name=%s, errno=%d\n",
1291 PrintInode(NULL, VN_GET_INO(*targetptr)), Name,
1293 if (errno != ENOENT)
1296 ("Volume %u now offline, must be salvaged.\n",
1298 VTakeOffline(volptr);
1305 VN_SET_INO(*targetptr, (Inode) 0);
1307 afs_fsize_t adjLength;
1308 VN_GET_LEN(adjLength, *targetptr);
1309 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1313 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1315 code = Delete(dir, (char *)Name);
1318 ("Error %d deleting %s\n", code,
1319 (((*targetptr)->disk.type ==
1320 Directory) ? "directory" : "file")));
1322 ("Volume %u now offline, must be salvaged.\n",
1324 VTakeOffline(volptr);
1336 * This routine updates the parent directory's status block after the
1337 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1338 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1342 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1343 int author, int linkcount,
1344 #if FS_STATS_DETAILED
1345 char a_inSameNetwork
1346 #endif /* FS_STATS_DETAILED */
1349 afs_fsize_t newlength; /* Holds new directory length */
1350 afs_fsize_t parentLength;
1352 #if FS_STATS_DETAILED
1353 Date currDate; /*Current date */
1354 int writeIdx; /*Write index to bump */
1355 int timeIdx; /*Authorship time index to bump */
1356 #endif /* FS_STATS_DETAILED */
1358 parentptr->disk.dataVersion++;
1359 newlength = (afs_fsize_t) Length(dir);
1361 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1362 * (create, symlink, link, makedir) so we need to check if we have enough space
1363 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1364 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1366 VN_GET_LEN(parentLength, parentptr);
1367 if (nBlocks(newlength) != nBlocks(parentLength)) {
1368 VAdjustDiskUsage(&errorCode, volptr,
1369 (nBlocks(newlength) - nBlocks(parentLength)),
1370 (nBlocks(newlength) - nBlocks(parentLength)));
1372 VN_SET_LEN(parentptr, newlength);
1374 #if FS_STATS_DETAILED
1376 * Update directory write stats for this volume. Note that the auth
1377 * counter is located immediately after its associated ``distance''
1380 if (a_inSameNetwork)
1381 writeIdx = VOL_STATS_SAME_NET;
1383 writeIdx = VOL_STATS_DIFF_NET;
1384 V_stat_writes(volptr, writeIdx)++;
1385 if (author != AnonymousID) {
1386 V_stat_writes(volptr, writeIdx + 1)++;
1390 * Update the volume's authorship information in response to this
1391 * directory operation. Get the current time, decide to which time
1392 * slot this operation belongs, and bump the appropriate slot.
1394 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1396 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1397 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1398 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1399 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1400 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1401 if (parentptr->disk.author == author) {
1402 V_stat_dirSameAuthor(volptr, timeIdx)++;
1404 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1406 #endif /* FS_STATS_DETAILED */
1408 parentptr->disk.author = author;
1409 parentptr->disk.linkCount = linkcount;
1410 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1411 parentptr->disk.serverModifyTime = FT_ApproxTime();
1412 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1417 * Update the target file's (or dir's) status block after the specified
1418 * operation is complete. Note that some other fields maybe updated by
1419 * the individual module.
1422 /* XXX INCOMPLETE - More attention is needed here! */
1424 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1425 struct client *client, AFSStoreStatus * InStatus,
1426 Vnode * parentptr, Volume * volptr,
1429 #if FS_STATS_DETAILED
1430 Date currDate; /*Current date */
1431 int writeIdx; /*Write index to bump */
1432 int timeIdx; /*Authorship time index to bump */
1433 #endif /* FS_STATS_DETAILED */
1435 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1436 targetptr->disk.parent = parentptr->vnodeNumber;
1437 VN_SET_LEN(targetptr, length);
1438 /* targetptr->disk.group = 0; save some cycles */
1439 targetptr->disk.modeBits = 0777;
1440 targetptr->disk.owner = client->ViceId;
1441 targetptr->disk.dataVersion = 0; /* consistent with the client */
1442 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1443 /* the inode was created in Alloc_NewVnode() */
1445 #if FS_STATS_DETAILED
1447 * Update file write stats for this volume. Note that the auth
1448 * counter is located immediately after its associated ``distance''
1451 if (client->InSameNetwork)
1452 writeIdx = VOL_STATS_SAME_NET;
1454 writeIdx = VOL_STATS_DIFF_NET;
1455 V_stat_writes(volptr, writeIdx)++;
1456 if (client->ViceId != AnonymousID) {
1457 V_stat_writes(volptr, writeIdx + 1)++;
1461 * We only count operations that DON'T involve creating new objects
1462 * (files, symlinks, directories) or simply setting status as
1463 * authorship-change operations.
1465 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1467 * Update the volume's authorship information in response to this
1468 * file operation. Get the current time, decide to which time
1469 * slot this operation belongs, and bump the appropriate slot.
1471 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1474 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1475 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1476 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1477 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1478 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1479 VOL_STATS_TIME_IDX_5);
1480 if (targetptr->disk.author == client->ViceId) {
1481 V_stat_fileSameAuthor(volptr, timeIdx)++;
1483 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1486 #endif /* FS_STATS_DETAILED */
1488 if (!(Caller & TVS_SSTATUS))
1489 targetptr->disk.author = client->ViceId;
1490 if (Caller & TVS_SDATA) {
1491 targetptr->disk.dataVersion++;
1492 if (VanillaUser(client)) {
1493 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1494 #ifdef CREATE_SGUID_ADMIN_ONLY
1495 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1499 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1500 /* store status, must explicitly request to change the date */
1501 if (InStatus->Mask & AFS_SETMODTIME)
1502 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1503 } else { /* other: date always changes, but perhaps to what is specified by caller */
1504 targetptr->disk.unixModifyTime =
1505 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1506 ClientModTime : FT_ApproxTime());
1508 if (InStatus->Mask & AFS_SETOWNER) {
1509 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1510 if (VanillaUser(client)) {
1511 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1512 #ifdef CREATE_SGUID_ADMIN_ONLY
1513 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1516 targetptr->disk.owner = InStatus->Owner;
1517 if (VolumeRootVnode(targetptr)) {
1518 Error errorCode = 0; /* what should be done with this? */
1520 V_owner(targetptr->volumePtr) = InStatus->Owner;
1521 VUpdateVolume(&errorCode, targetptr->volumePtr);
1524 if (InStatus->Mask & AFS_SETMODE) {
1525 int modebits = InStatus->UnixModeBits;
1526 #define CREATE_SGUID_ADMIN_ONLY 1
1527 #ifdef CREATE_SGUID_ADMIN_ONLY
1528 if (VanillaUser(client))
1529 modebits = modebits & 0777;
1531 if (VanillaUser(client)) {
1532 targetptr->disk.modeBits = modebits;
1534 targetptr->disk.modeBits = modebits;
1537 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1538 CHK_STOREDATA, AUD_END);
1542 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1543 CHK_STORESTATUS, AUD_END);
1550 targetptr->disk.serverModifyTime = FT_ApproxTime();
1551 if (InStatus->Mask & AFS_SETGROUP)
1552 targetptr->disk.group = InStatus->Group;
1553 /* vnode changed : to be written back by VPutVnode */
1554 targetptr->changed_newTime = 1;
1556 } /*Update_TargetVnodeStatus */
1560 * Fills the CallBack structure with the expiration time and type of callback
1561 * structure. Warning: this function is currently incomplete.
1564 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1566 /* CallBackTime could not be 0 */
1567 if (CallBackTime == 0) {
1568 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1569 CallBack->ExpirationTime = 0;
1571 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1572 CallBack->CallBackVersion = CALLBACK_VERSION;
1573 CallBack->CallBackType = CB_SHARED; /* The default for now */
1575 } /*SetCallBackStruct */
1579 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1580 * allocation; if some error occured (exceeded volume quota or partition
1581 * was full, or whatever), it frees the space back and returns the code.
1582 * We usually pre-adjust the volume space to make sure that there's
1583 * enough space before consuming some.
1586 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1587 afs_sfsize_t checkLength)
1592 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1594 VAdjustDiskUsage(&nc, volptr, -length, 0);
1595 if (rc == VOVERQUOTA) {
1597 ("Volume %u (%s) is full\n", V_id(volptr),
1601 if (rc == VDISKFULL) {
1603 ("Partition %s that contains volume %u is full\n",
1604 volptr->partition->name, V_id(volptr)));
1607 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1612 } /*AdjustDiskUsage */
1615 * Common code that handles the creation of a new file (SAFS_CreateFile and
1616 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1619 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1620 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1621 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1623 int errorCode = 0; /* Error code returned back */
1626 Inode nearInode; /* hint for inode allocation in solaris */
1629 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1630 BlocksPreallocatedForVnode))) {
1632 ("Insufficient space to allocate %lld blocks\n",
1633 (afs_intmax_t) BlocksPreallocatedForVnode));
1637 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1638 if (errorCode != 0) {
1639 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1642 OutFid->Volume = V_id(volptr);
1643 OutFid->Vnode = (*targetptr)->vnodeNumber;
1644 OutFid->Unique = (*targetptr)->disk.uniquifier;
1646 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1648 /* create the inode now itself */
1650 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1651 VPartitionPath(V_partition(volptr)), nearInode,
1652 V_id(volptr), (*targetptr)->vnodeNumber,
1653 (*targetptr)->disk.uniquifier, 1);
1655 /* error in creating inode */
1656 if (!VALID_INO(inode)) {
1658 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1659 (*targetptr)->volumePtr->header->diskstuff.id,
1660 (*targetptr)->vnodeNumber, errno));
1661 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1662 (*targetptr)->delete = 1; /* delete vnode */
1665 VN_SET_INO(*targetptr, inode);
1666 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1668 /* copy group from parent dir */
1669 (*targetptr)->disk.group = parentptr->disk.group;
1671 if (parentptr->disk.cloned) {
1672 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1673 if ((errorCode = CopyOnWrite(parentptr, volptr))) { /* disk full */
1674 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1675 /* delete the vnode previously allocated */
1676 (*targetptr)->delete = 1;
1677 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1678 IH_REALLYCLOSE((*targetptr)->handle);
1679 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1681 ("Alloc_NewVnode: partition %s idec %s failed\n",
1682 volptr->partition->name, PrintInode(NULL, inode)));
1683 IH_RELEASE((*targetptr)->handle);
1689 /* add the name to the directory */
1690 SetDirHandle(dir, parentptr);
1691 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1692 (*targetptr)->delete = 1;
1693 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1694 IH_REALLYCLOSE((*targetptr)->handle);
1695 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1697 ("Alloc_NewVnode: partition %s idec %s failed\n",
1698 volptr->partition->name, PrintInode(NULL, inode)));
1699 IH_RELEASE((*targetptr)->handle);
1705 } /*Alloc_NewVnode */
1709 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1713 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1715 int Time; /* Used for time */
1716 int writeVnode = targetptr->changed_oldTime; /* save original status */
1718 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1719 Time = FT_ApproxTime();
1720 switch (LockingType) {
1723 if (Time > targetptr->disk.lock.lockTime)
1724 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1726 Time += AFS_LOCKWAIT;
1727 if (LockingType == LockRead) {
1728 if ( !(rights & PRSFS_LOCK) &&
1729 !(rights & PRSFS_WRITE) &&
1730 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1734 if (targetptr->disk.lock.lockCount >= 0) {
1735 ++(targetptr->disk.lock.lockCount);
1736 targetptr->disk.lock.lockTime = Time;
1739 } else if (LockingType == LockWrite) {
1740 if ( !(rights & PRSFS_WRITE) &&
1741 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1744 if (targetptr->disk.lock.lockCount == 0) {
1745 targetptr->disk.lock.lockCount = -1;
1746 targetptr->disk.lock.lockTime = Time;
1752 Time += AFS_LOCKWAIT;
1753 if (targetptr->disk.lock.lockCount != 0)
1754 targetptr->disk.lock.lockTime = Time;
1759 if ((--targetptr->disk.lock.lockCount) <= 0)
1760 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1764 targetptr->changed_oldTime = writeVnode; /* restore old status */
1765 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1768 } /*HandleLocking */
1770 /* 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. */
1773 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1777 if (!(rights & Prfs_Mode))
1779 if ((targetptr->disk.type != vDirectory)
1780 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1786 * If some flags (i.e. min or max quota) are set, the volume's in disk
1787 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1788 * update, if applicable.
1791 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1792 char *Name, char *OfflineMsg, char *Motd)
1794 Error errorCode = 0;
1796 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1797 V_minquota(volptr) = StoreVolStatus->MinQuota;
1798 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1799 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1800 if (strlen(OfflineMsg) > 0) {
1801 strcpy(V_offlineMessage(volptr), OfflineMsg);
1803 if (strlen(Name) > 0) {
1804 strcpy(V_name(volptr), Name);
1806 #if OPENAFS_VOL_STATS
1808 * We don't overwrite the motd field, since it's now being used
1812 if (strlen(Motd) > 0) {
1813 strcpy(V_motd(volptr), Motd);
1815 #endif /* FS_STATS_DETAILED */
1816 VUpdateVolume(&errorCode, volptr);
1819 } /*RXUpdate_VolumeStatus */
1823 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1824 char **motd, Volume * volptr)
1828 status->Vid = V_id(volptr);
1829 status->ParentId = V_parentId(volptr);
1830 status->Online = V_inUse(volptr);
1831 status->InService = V_inService(volptr);
1832 status->Blessed = V_blessed(volptr);
1833 status->NeedsSalvage = V_needsSalvaged(volptr);
1834 if (VolumeWriteable(volptr))
1835 status->Type = ReadWrite;
1837 status->Type = ReadOnly;
1838 status->MinQuota = V_minquota(volptr);
1839 status->MaxQuota = V_maxquota(volptr);
1840 status->BlocksInUse = V_diskused(volptr);
1841 status->PartBlocksAvail = volptr->partition->free;
1842 status->PartMaxBlocks = volptr->partition->totalUsable;
1844 /* now allocate and copy these things; they're freed by the RXGEN stub */
1845 temp = strlen(V_name(volptr)) + 1;
1846 *name = malloc(temp);
1848 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1851 strcpy(*name, V_name(volptr));
1852 temp = strlen(V_offlineMessage(volptr)) + 1;
1853 *offMsg = malloc(temp);
1855 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1858 strcpy(*offMsg, V_offlineMessage(volptr));
1859 #if OPENAFS_VOL_STATS
1862 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1865 strcpy(*motd, nullString);
1867 temp = strlen(V_motd(volptr)) + 1;
1868 *motd = malloc(temp);
1870 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1873 strcpy(*motd, V_motd(volptr));
1874 #endif /* FS_STATS_DETAILED */
1876 } /*RXGetVolumeStatus */
1880 FileNameOK(register char *aname)
1882 register afs_int32 i, tc;
1885 /* watch for @sys on the right */
1886 if (strcmp(aname + i - 4, "@sys") == 0)
1889 while ((tc = *aname++)) {
1891 return 0; /* very bad character to encounter */
1893 return 1; /* file name is ok */
1899 * This variant of symlink is expressly to support the AFS/DFS translator
1900 * and is not supported by the AFS fileserver. We just return EINVAL.
1901 * The cache manager should not generate this call to an AFS cache manager.
1904 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
1905 char *LinkContents, struct AFSStoreStatus *InStatus,
1906 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
1907 struct AFSFetchStatus *OutDirStatus,
1908 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
1914 SRXAFS_ResidencyCmd(struct rx_call * acall, struct AFSFid * Fid,
1915 struct ResidencyCmdInputs * Inputs,
1916 struct ResidencyCmdOutputs * Outputs)
1922 static struct afs_buffer {
1923 struct afs_buffer *next;
1924 } *freeBufferList = 0;
1925 static int afs_buffersAlloced = 0;
1928 FreeSendBuffer(register struct afs_buffer *adata)
1931 afs_buffersAlloced--;
1932 adata->next = freeBufferList;
1933 freeBufferList = adata;
1937 } /*FreeSendBuffer */
1939 /* allocate space for sender */
1943 register struct afs_buffer *tp;
1946 afs_buffersAlloced++;
1947 if (!freeBufferList) {
1950 tmp = malloc(sendBufSize);
1952 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
1957 tp = freeBufferList;
1958 freeBufferList = tp->next;
1962 } /*AllocSendBuffer */
1963 #endif /* AFS_NT40_ENV */
1966 * This routine returns the status info associated with the targetptr vnode
1967 * in the AFSFetchStatus structure. Some of the newer fields, such as
1968 * SegSize and Group are not yet implemented
1972 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
1973 afs_int32 anyrights, Vnode * parentptr)
1975 /* initialize return status from a vnode */
1976 status->InterfaceVersion = 1;
1977 status->SyncCounter = status->dataVersionHigh = status->lockCount =
1978 status->errorCode = 0;
1979 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
1980 if (targetptr->disk.type == vFile)
1981 status->FileType = File;
1982 else if (targetptr->disk.type == vDirectory)
1983 status->FileType = Directory;
1984 else if (targetptr->disk.type == vSymlink)
1985 status->FileType = SymbolicLink;
1987 status->FileType = Invalid; /*invalid type field */
1988 status->LinkCount = targetptr->disk.linkCount;
1990 afs_fsize_t targetLen;
1991 VN_GET_LEN(targetLen, targetptr);
1992 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
1994 status->DataVersion = targetptr->disk.dataVersion;
1995 status->Author = targetptr->disk.author;
1996 status->Owner = targetptr->disk.owner;
1997 status->CallerAccess = rights;
1998 status->AnonymousAccess = anyrights;
1999 status->UnixModeBits = targetptr->disk.modeBits;
2000 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2001 status->ParentVnode =
2002 (status->FileType ==
2003 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2004 status->ParentUnique =
2005 (status->FileType ==
2006 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2007 status->ServerModTime = targetptr->disk.serverModifyTime;
2008 status->Group = targetptr->disk.group;
2009 status->lockCount = targetptr->disk.lock.lockCount;
2010 status->errorCode = 0;
2016 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2017 afs_sfsize_t Pos, afs_sfsize_t Len,
2018 struct AFSFetchStatus *OutStatus,
2019 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2022 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2023 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2024 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2025 int errorCode = 0; /* return code to caller */
2026 int fileCode = 0; /* return code from vol package */
2027 Volume *volptr = 0; /* pointer to the volume */
2028 struct client *client = 0; /* pointer to the client data */
2029 struct rx_connection *tcon; /* the connection we're part of */
2031 afs_int32 rights, anyrights; /* rights for this and any user */
2032 struct client *t_client = NULL; /* tmp ptr to client data */
2033 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2034 #if FS_STATS_DETAILED
2035 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2036 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2037 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2038 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2039 struct timeval elapsedTime; /* Transfer time */
2040 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2041 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2042 int readIdx; /* Index of read stats array to bump */
2043 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2046 * Set our stats pointers, remember when the RPC operation started, and
2047 * tally the operation.
2049 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2050 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2054 TM_GetTimeOfDay(&opStartTime, 0);
2055 #endif /* FS_STATS_DETAILED */
2058 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2061 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2063 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2066 /* Get ptr to client data for user Id for logging */
2067 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2068 logHostAddr.s_addr = rxr_HostOf(tcon);
2070 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2071 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2072 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2074 * Get volume/vnode for the fetched file; caller's access rights to
2075 * it are also returned
2078 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2079 &parentwhentargetnotdir, &client, READ_LOCK,
2080 &rights, &anyrights)))
2083 SetVolumeSync(Sync, volptr);
2085 #if FS_STATS_DETAILED
2087 * Remember that another read operation was performed.
2090 if (client->InSameNetwork)
2091 readIdx = VOL_STATS_SAME_NET;
2093 readIdx = VOL_STATS_DIFF_NET;
2094 V_stat_reads(volptr, readIdx)++;
2095 if (client->ViceId != AnonymousID) {
2096 V_stat_reads(volptr, readIdx + 1)++;
2099 #endif /* FS_STATS_DETAILED */
2100 /* Check whether the caller has permission access to fetch the data */
2102 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2106 * Drop the read lock on the parent directory after saving the parent
2107 * vnode information we need to pass to GetStatus
2109 if (parentwhentargetnotdir != NULL) {
2110 tparentwhentargetnotdir = *parentwhentargetnotdir;
2111 VPutVnode(&fileCode, parentwhentargetnotdir);
2112 assert(!fileCode || (fileCode == VSALVAGE));
2113 parentwhentargetnotdir = NULL;
2115 #if FS_STATS_DETAILED
2117 * Remember when the data transfer started.
2119 TM_GetTimeOfDay(&xferStartTime, 0);
2120 #endif /* FS_STATS_DETAILED */
2122 /* actually do the data transfer */
2123 #if FS_STATS_DETAILED
2125 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2126 &bytesToXfer, &bytesXferred);
2129 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2131 #endif /* FS_STATS_DETAILED */
2133 #if FS_STATS_DETAILED
2135 * At this point, the data transfer is done, for good or ill. Remember
2136 * when the transfer ended, bump the number of successes/failures, and
2137 * integrate the transfer size and elapsed time into the stats. If the
2138 * operation failed, we jump to the appropriate point.
2140 TM_GetTimeOfDay(&xferStopTime, 0);
2142 (xferP->numXfers)++;
2144 (xferP->numSuccesses)++;
2147 * Bump the xfer sum by the number of bytes actually sent, NOT the
2150 tot_bytesXferred += bytesXferred;
2151 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2152 tot_bytesXferred &= 0x3FF;
2153 if (bytesXferred < xferP->minBytes)
2154 xferP->minBytes = bytesXferred;
2155 if (bytesXferred > xferP->maxBytes)
2156 xferP->maxBytes = bytesXferred;
2159 * Tally the size of the object. Note: we tally the actual size,
2160 * NOT the number of bytes that made it out over the wire.
2162 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2163 (xferP->count[0])++;
2164 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2165 (xferP->count[1])++;
2166 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2167 (xferP->count[2])++;
2168 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2169 (xferP->count[3])++;
2170 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2171 (xferP->count[4])++;
2172 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2173 (xferP->count[5])++;
2174 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2175 (xferP->count[6])++;
2176 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2177 (xferP->count[7])++;
2179 (xferP->count[8])++;
2181 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2182 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2183 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2184 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2185 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2187 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2188 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2193 * Finally, go off to tell our caller the bad news in case the
2198 #endif /* FS_STATS_DETAILED */
2200 /* write back the OutStatus from the target vnode */
2201 GetStatus(targetptr, OutStatus, rights, anyrights,
2202 &tparentwhentargetnotdir);
2204 /* if a r/w volume, promise a callback to the caller */
2205 if (VolumeWriteable(volptr))
2206 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2208 struct AFSFid myFid;
2209 memset(&myFid, 0, sizeof(struct AFSFid));
2210 myFid.Volume = Fid->Volume;
2211 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2215 /* Update and store volume/vnode and parent vnodes back */
2216 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2218 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2219 errorCode = CallPostamble(tcon, errorCode, thost);
2221 #if FS_STATS_DETAILED
2222 TM_GetTimeOfDay(&opStopTime, 0);
2223 if (errorCode == 0) {
2225 (opP->numSuccesses)++;
2226 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2227 fs_stats_AddTo((opP->sumTime), elapsedTime);
2228 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2229 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2230 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2232 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2233 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2237 #endif /* FS_STATS_DETAILED */
2239 osi_auditU(acall, FetchDataEvent, errorCode,
2240 AUD_ID, t_client ? t_client->ViceId : 0,
2241 AUD_FID, Fid, AUD_END);
2244 } /*SRXAFS_FetchData */
2247 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2248 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2249 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2251 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2256 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2257 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2258 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2261 afs_sfsize_t tPos, tLen;
2263 #ifdef AFS_64BIT_ENV
2264 #ifndef AFS_LARGEFILE_ENV
2265 if (Pos + Len > 0x7fffffff)
2267 #endif /* !AFS_LARGEFILE_ENV */
2268 tPos = (afs_sfsize_t) Pos;
2269 tLen = (afs_sfsize_t) Len;
2270 #else /* AFS_64BIT_ENV */
2271 if (Pos.high || Len.high)
2275 #endif /* AFS_64BIT_ENV */
2278 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2284 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2285 struct AFSOpaque * AccessList,
2286 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2288 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2289 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2290 int errorCode = 0; /* return error code to caller */
2291 Volume *volptr = 0; /* pointer to the volume */
2292 struct client *client = 0; /* pointer to the client data */
2293 afs_int32 rights, anyrights; /* rights for this and any user */
2294 struct rx_connection *tcon = rx_ConnectionOf(acall);
2296 struct client *t_client = NULL; /* tmp ptr to client data */
2297 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2298 #if FS_STATS_DETAILED
2299 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2300 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2301 struct timeval elapsedTime; /* Transfer time */
2304 * Set our stats pointer, remember when the RPC operation started, and
2305 * tally the operation.
2307 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2311 TM_GetTimeOfDay(&opStartTime, 0);
2312 #endif /* FS_STATS_DETAILED */
2315 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2318 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2320 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2323 /* Get ptr to client data for user Id for logging */
2324 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2325 logHostAddr.s_addr = rxr_HostOf(tcon);
2327 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2328 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2329 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2331 AccessList->AFSOpaque_len = 0;
2332 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2333 if (!AccessList->AFSOpaque_val) {
2334 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2339 * Get volume/vnode for the fetched file; caller's access rights to it
2343 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2344 &parentwhentargetnotdir, &client, READ_LOCK,
2345 &rights, &anyrights)))
2348 SetVolumeSync(Sync, volptr);
2350 /* Check whether we have permission to fetch the ACL */
2352 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2355 /* Get the Access List from the dir's vnode */
2357 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2360 /* Get OutStatus back From the target Vnode */
2361 GetStatus(targetptr, OutStatus, rights, anyrights,
2362 parentwhentargetnotdir);
2365 /* Update and store volume/vnode and parent vnodes back */
2366 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2369 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2370 AccessList->AFSOpaque_val));
2371 errorCode = CallPostamble(tcon, errorCode, thost);
2373 #if FS_STATS_DETAILED
2374 TM_GetTimeOfDay(&opStopTime, 0);
2375 if (errorCode == 0) {
2377 (opP->numSuccesses)++;
2378 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2379 fs_stats_AddTo((opP->sumTime), elapsedTime);
2380 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2381 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2382 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2384 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2385 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2389 #endif /* FS_STATS_DETAILED */
2391 osi_auditU(acall, FetchACLEvent, errorCode,
2392 AUD_ID, t_client ? t_client->ViceId : 0,
2394 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2396 } /*SRXAFS_FetchACL */
2400 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2401 * merged into it when possible.
2405 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2406 struct AFSFetchStatus *OutStatus,
2407 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2409 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2410 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2411 int errorCode = 0; /* return code to caller */
2412 Volume *volptr = 0; /* pointer to the volume */
2413 struct client *client = 0; /* pointer to the client data */
2414 afs_int32 rights, anyrights; /* rights for this and any user */
2415 struct client *t_client = NULL; /* tmp ptr to client data */
2416 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2417 struct rx_connection *tcon = rx_ConnectionOf(acall);
2419 /* Get ptr to client data for user Id for logging */
2420 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2421 logHostAddr.s_addr = rxr_HostOf(tcon);
2423 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2424 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2425 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2427 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2430 * Get volume/vnode for the fetched file; caller's rights to it are
2434 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2435 &parentwhentargetnotdir, &client, READ_LOCK,
2436 &rights, &anyrights)))
2437 goto Bad_FetchStatus;
2439 /* set volume synchronization information */
2440 SetVolumeSync(Sync, volptr);
2442 /* Are we allowed to fetch Fid's status? */
2443 if (targetptr->disk.type != vDirectory) {
2445 Check_PermissionRights(targetptr, client, rights,
2446 CHK_FETCHSTATUS, 0))) {
2447 if (rx_GetCallAbortCode(acall) == errorCode)
2448 rx_SetCallAbortCode(acall, 0);
2449 goto Bad_FetchStatus;
2453 /* set OutStatus From the Fid */
2454 GetStatus(targetptr, OutStatus, rights, anyrights,
2455 parentwhentargetnotdir);
2457 /* If a r/w volume, also set the CallBack state */
2458 if (VolumeWriteable(volptr))
2459 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2461 struct AFSFid myFid;
2462 memset(&myFid, 0, sizeof(struct AFSFid));
2463 myFid.Volume = Fid->Volume;
2464 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2468 /* Update and store volume/vnode and parent vnodes back */
2469 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2471 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2474 } /*SAFSS_FetchStatus */
2478 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2479 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2480 struct AFSVolSync * Sync)
2484 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2485 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2486 int errorCode = 0; /* return code to caller */
2487 Volume *volptr = 0; /* pointer to the volume */
2488 struct client *client = 0; /* pointer to the client data */
2489 afs_int32 rights, anyrights; /* rights for this and any user */
2490 register struct AFSFid *tfid; /* file id we're dealing with now */
2491 struct rx_connection *tcon = rx_ConnectionOf(acall);
2493 struct client *t_client = NULL; /* tmp pointer to the client data */
2494 #if FS_STATS_DETAILED
2495 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2496 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2497 struct timeval elapsedTime; /* Transfer time */
2500 * Set our stats pointer, remember when the RPC operation started, and
2501 * tally the operation.
2503 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2507 TM_GetTimeOfDay(&opStartTime, 0);
2508 #endif /* FS_STATS_DETAILED */
2510 ViceLog(1, ("SAFS_BulkStatus\n"));
2512 AFSCallStats.TotalCalls++;
2514 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2515 if (nfiles <= 0) { /* Sanity check */
2517 goto Audit_and_Return;
2520 /* allocate space for return output parameters */
2521 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2522 malloc(nfiles * sizeof(struct AFSFetchStatus));
2523 if (!OutStats->AFSBulkStats_val) {
2524 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2527 OutStats->AFSBulkStats_len = nfiles;
2528 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2529 malloc(nfiles * sizeof(struct AFSCallBack));
2530 if (!CallBacks->AFSCBs_val) {
2531 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2534 CallBacks->AFSCBs_len = nfiles;
2536 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2537 goto Bad_BulkStatus;
2539 tfid = Fids->AFSCBFids_val;
2540 for (i = 0; i < nfiles; i++, tfid++) {
2542 * Get volume/vnode for the fetched file; caller's rights to it
2546 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2547 &parentwhentargetnotdir, &client, READ_LOCK,
2548 &rights, &anyrights)))
2549 goto Bad_BulkStatus;
2550 /* set volume synchronization information, but only once per call */
2552 SetVolumeSync(Sync, volptr);
2554 /* Are we allowed to fetch Fid's status? */
2555 if (targetptr->disk.type != vDirectory) {
2557 Check_PermissionRights(targetptr, client, rights,
2558 CHK_FETCHSTATUS, 0))) {
2559 if (rx_GetCallAbortCode(acall) == errorCode)
2560 rx_SetCallAbortCode(acall, 0);
2561 goto Bad_BulkStatus;
2565 /* set OutStatus From the Fid */
2566 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2567 anyrights, parentwhentargetnotdir);
2569 /* If a r/w volume, also set the CallBack state */
2570 if (VolumeWriteable(volptr))
2571 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2572 &CallBacks->AFSCBs_val[i]);
2574 struct AFSFid myFid;
2575 memset(&myFid, 0, sizeof(struct AFSFid));
2576 myFid.Volume = tfid->Volume;
2577 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2578 &CallBacks->AFSCBs_val[i]);
2581 /* put back the file ID and volume */
2582 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2584 parentwhentargetnotdir = (Vnode *) 0;
2585 targetptr = (Vnode *) 0;
2586 volptr = (Volume *) 0;
2587 client = (struct client *)0;
2591 /* Update and store volume/vnode and parent vnodes back */
2592 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2594 errorCode = CallPostamble(tcon, errorCode, thost);
2596 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2598 #if FS_STATS_DETAILED
2599 TM_GetTimeOfDay(&opStopTime, 0);
2600 if (errorCode == 0) {
2602 (opP->numSuccesses)++;
2603 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2604 fs_stats_AddTo((opP->sumTime), elapsedTime);
2605 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2606 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2607 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2609 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2610 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2614 #endif /* FS_STATS_DETAILED */
2617 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2618 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2619 AUD_ID, t_client ? t_client->ViceId : 0,
2620 AUD_FIDS, Fids, AUD_END);
2623 } /*SRXAFS_BulkStatus */
2627 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2628 struct AFSBulkStats * OutStats,
2629 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2633 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2634 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2635 int errorCode = 0; /* return code to caller */
2636 Volume *volptr = 0; /* pointer to the volume */
2637 struct client *client = 0; /* pointer to the client data */
2638 afs_int32 rights, anyrights; /* rights for this and any user */
2639 register struct AFSFid *tfid; /* file id we're dealing with now */
2640 struct rx_connection *tcon;
2642 struct client *t_client = NULL; /* tmp ptr to client data */
2643 AFSFetchStatus *tstatus;
2644 #if FS_STATS_DETAILED
2645 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2646 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2647 struct timeval elapsedTime; /* Transfer time */
2650 * Set our stats pointer, remember when the RPC operation started, and
2651 * tally the operation.
2653 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2657 TM_GetTimeOfDay(&opStartTime, 0);
2658 #endif /* FS_STATS_DETAILED */
2660 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2662 AFSCallStats.TotalCalls++;
2664 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2665 if (nfiles <= 0) { /* Sanity check */
2667 goto Audit_and_Return;
2670 /* allocate space for return output parameters */
2671 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2672 malloc(nfiles * sizeof(struct AFSFetchStatus));
2673 if (!OutStats->AFSBulkStats_val) {
2674 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2677 OutStats->AFSBulkStats_len = nfiles;
2678 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2679 malloc(nfiles * sizeof(struct AFSCallBack));
2680 if (!CallBacks->AFSCBs_val) {
2681 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2684 CallBacks->AFSCBs_len = nfiles;
2686 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2687 goto Bad_InlineBulkStatus;
2690 tfid = Fids->AFSCBFids_val;
2691 for (i = 0; i < nfiles; i++, tfid++) {
2693 * Get volume/vnode for the fetched file; caller's rights to it
2697 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2698 &parentwhentargetnotdir, &client, READ_LOCK,
2699 &rights, &anyrights))) {
2700 tstatus = &OutStats->AFSBulkStats_val[i];
2701 tstatus->errorCode = errorCode;
2702 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2704 parentwhentargetnotdir = (Vnode *) 0;
2705 targetptr = (Vnode *) 0;
2706 volptr = (Volume *) 0;
2707 client = (struct client *)0;
2711 /* set volume synchronization information, but only once per call */
2713 SetVolumeSync(Sync, volptr);
2715 /* Are we allowed to fetch Fid's status? */
2716 if (targetptr->disk.type != vDirectory) {
2718 Check_PermissionRights(targetptr, client, rights,
2719 CHK_FETCHSTATUS, 0))) {
2720 tstatus = &OutStats->AFSBulkStats_val[i];
2721 tstatus->errorCode = errorCode;
2722 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2723 (Vnode *) 0, volptr, &client);
2724 parentwhentargetnotdir = (Vnode *) 0;
2725 targetptr = (Vnode *) 0;
2726 volptr = (Volume *) 0;
2727 client = (struct client *)0;
2732 /* set OutStatus From the Fid */
2733 GetStatus(targetptr,
2734 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2735 rights, anyrights, parentwhentargetnotdir);
2737 /* If a r/w volume, also set the CallBack state */
2738 if (VolumeWriteable(volptr))
2739 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2740 &CallBacks->AFSCBs_val[i]);
2742 struct AFSFid myFid;
2743 memset(&myFid, 0, sizeof(struct AFSFid));
2744 myFid.Volume = tfid->Volume;
2745 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2746 &CallBacks->AFSCBs_val[i]);
2749 /* put back the file ID and volume */
2750 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2752 parentwhentargetnotdir = (Vnode *) 0;
2753 targetptr = (Vnode *) 0;
2754 volptr = (Volume *) 0;
2755 client = (struct client *)0;
2758 Bad_InlineBulkStatus:
2759 /* Update and store volume/vnode and parent vnodes back */
2760 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2762 errorCode = CallPostamble(tcon, errorCode, thost);
2764 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2766 #if FS_STATS_DETAILED
2767 TM_GetTimeOfDay(&opStopTime, 0);
2768 if (errorCode == 0) {
2770 (opP->numSuccesses)++;
2771 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2772 fs_stats_AddTo((opP->sumTime), elapsedTime);
2773 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2774 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2775 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2777 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2778 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2782 #endif /* FS_STATS_DETAILED */
2785 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2786 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2787 AUD_ID, t_client ? t_client->ViceId : 0,
2788 AUD_FIDS, Fids, AUD_END);
2791 } /*SRXAFS_InlineBulkStatus */
2795 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2796 struct AFSFetchStatus * OutStatus,
2797 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2800 struct rx_connection *tcon;
2802 struct client *t_client = NULL; /* tmp ptr to client data */
2803 #if FS_STATS_DETAILED
2804 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2805 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2806 struct timeval elapsedTime; /* Transfer time */
2809 * Set our stats pointer, remember when the RPC operation started, and
2810 * tally the operation.
2812 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2816 TM_GetTimeOfDay(&opStartTime, 0);
2817 #endif /* FS_STATS_DETAILED */
2819 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2820 goto Bad_FetchStatus;
2822 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2825 code = CallPostamble(tcon, code, thost);
2827 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2829 #if FS_STATS_DETAILED
2830 TM_GetTimeOfDay(&opStopTime, 0);
2833 (opP->numSuccesses)++;
2834 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2835 fs_stats_AddTo((opP->sumTime), elapsedTime);
2836 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2837 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2838 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2840 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2841 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2845 #endif /* FS_STATS_DETAILED */
2847 osi_auditU(acall, FetchStatusEvent, code,
2848 AUD_ID, t_client ? t_client->ViceId : 0,
2849 AUD_FID, Fid, AUD_END);
2852 } /*SRXAFS_FetchStatus */
2856 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2857 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2858 afs_fsize_t Length, afs_fsize_t FileLength,
2859 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2861 Vnode *targetptr = 0; /* pointer to input fid */
2862 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2863 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2864 int errorCode = 0; /* return code for caller */
2865 int fileCode = 0; /* return code from vol package */
2866 Volume *volptr = 0; /* pointer to the volume header */
2867 struct client *client = 0; /* pointer to client structure */
2868 afs_int32 rights, anyrights; /* rights for this and any user */
2869 struct client *t_client = NULL; /* tmp ptr to client data */
2870 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2871 struct rx_connection *tcon;
2873 #if FS_STATS_DETAILED
2874 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2875 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2876 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2877 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2878 struct timeval elapsedTime; /* Transfer time */
2879 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2880 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2881 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2884 * Set our stats pointers, remember when the RPC operation started, and
2885 * tally the operation.
2887 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2888 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2893 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2895 TM_GetTimeOfDay(&opStartTime, 0);
2896 #endif /* FS_STATS_DETAILED */
2899 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2901 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2904 /* Get ptr to client data for user Id for logging */
2905 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2906 logHostAddr.s_addr = rxr_HostOf(tcon);
2908 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2909 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2910 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2913 * Get associated volume/vnode for the stored file; caller's rights
2917 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
2918 &parentwhentargetnotdir, &client, WRITE_LOCK,
2919 &rights, &anyrights))) {
2923 /* set volume synchronization information */
2924 SetVolumeSync(Sync, volptr);
2926 if ((targetptr->disk.type == vSymlink)) {
2927 /* Should we return a better error code here??? */
2932 /* Check if we're allowed to store the data */
2934 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2940 * Drop the read lock on the parent directory after saving the parent
2941 * vnode information we need to pass to GetStatus
2943 if (parentwhentargetnotdir != NULL) {
2944 tparentwhentargetnotdir = *parentwhentargetnotdir;
2945 VPutVnode(&fileCode, parentwhentargetnotdir);
2946 assert(!fileCode || (fileCode == VSALVAGE));
2947 parentwhentargetnotdir = NULL;
2949 #if FS_STATS_DETAILED
2951 * Remember when the data transfer started.
2953 TM_GetTimeOfDay(&xferStartTime, 0);
2954 #endif /* FS_STATS_DETAILED */
2956 /* Do the actual storing of the data */
2957 #if FS_STATS_DETAILED
2959 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2960 FileLength, (InStatus->Mask & AFS_FSYNC),
2961 &bytesToXfer, &bytesXferred);
2964 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2965 FileLength, (InStatus->Mask & AFS_FSYNC));
2966 if (errorCode && (!targetptr->changed_newTime))
2968 #endif /* FS_STATS_DETAILED */
2969 #if FS_STATS_DETAILED
2971 * At this point, the data transfer is done, for good or ill. Remember
2972 * when the transfer ended, bump the number of successes/failures, and
2973 * integrate the transfer size and elapsed time into the stats. If the
2974 * operation failed, we jump to the appropriate point.
2976 TM_GetTimeOfDay(&xferStopTime, 0);
2978 (xferP->numXfers)++;
2980 (xferP->numSuccesses)++;
2983 * Bump the xfer sum by the number of bytes actually sent, NOT the
2986 tot_bytesXferred += bytesXferred;
2987 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2988 tot_bytesXferred &= 0x3FF;
2989 if (bytesXferred < xferP->minBytes)
2990 xferP->minBytes = bytesXferred;
2991 if (bytesXferred > xferP->maxBytes)
2992 xferP->maxBytes = bytesXferred;
2995 * Tally the size of the object. Note: we tally the actual size,
2996 * NOT the number of bytes that made it out over the wire.
2998 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2999 (xferP->count[0])++;
3000 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3001 (xferP->count[1])++;
3002 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3003 (xferP->count[2])++;
3004 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3005 (xferP->count[3])++;
3006 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3007 (xferP->count[4])++;
3008 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3009 (xferP->count[5])++;
3010 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3011 (xferP->count[6])++;
3012 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3013 (xferP->count[7])++;
3015 (xferP->count[8])++;
3017 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3018 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3019 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3020 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3021 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3023 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3024 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3029 * Finally, go off to tell our caller the bad news in case the
3032 if (errorCode && (!targetptr->changed_newTime))
3034 #endif /* FS_STATS_DETAILED */
3036 /* Update the status of the target's vnode */
3037 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3038 targetptr, volptr, 0);
3040 /* Get the updated File's status back to the caller */
3041 GetStatus(targetptr, OutStatus, rights, anyrights,
3042 &tparentwhentargetnotdir);
3045 /* Update and store volume/vnode and parent vnodes back */
3046 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3048 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3050 errorCode = CallPostamble(tcon, errorCode, thost);
3052 #if FS_STATS_DETAILED
3053 TM_GetTimeOfDay(&opStopTime, 0);
3054 if (errorCode == 0) {
3056 (opP->numSuccesses)++;
3057 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3058 fs_stats_AddTo((opP->sumTime), elapsedTime);
3059 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3060 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3061 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3063 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3064 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3068 #endif /* FS_STATS_DETAILED */
3069 osi_auditU(acall, StoreDataEvent, errorCode,
3070 AUD_ID, t_client ? t_client->ViceId : 0,
3071 AUD_FID, Fid, AUD_END);
3073 } /*common_StoreData64 */
3076 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3077 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3078 afs_uint32 Length, afs_uint32 FileLength,
3079 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3081 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3082 (0x7fffffff - Pos) < Length)
3085 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3087 } /*SRXAFS_StoreData */
3090 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3091 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3092 afs_uint64 Length, afs_uint64 FileLength,
3093 struct AFSFetchStatus * OutStatus,
3094 struct AFSVolSync * Sync)
3098 afs_fsize_t tLength;
3099 afs_fsize_t tFileLength;
3101 #ifdef AFS_64BIT_ENV
3102 #ifndef AFS_LARGEFILE_ENV
3103 if (FileLength > 0x7fffffff)
3105 #endif /* !AFS_LARGEFILE_ENV */
3106 tPos = (afs_fsize_t) Pos;
3107 tLength = (afs_fsize_t) Length;
3108 tFileLength = (afs_fsize_t) FileLength;
3109 #else /* AFS_64BIT_ENV */
3110 if (FileLength.high)
3113 tLength = Length.low;
3114 tFileLength = FileLength.low;
3115 #endif /* AFS_64BIT_ENV */
3118 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3124 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3125 struct AFSOpaque * AccessList,
3126 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3128 Vnode *targetptr = 0; /* pointer to input fid */
3129 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3130 int errorCode = 0; /* return code for caller */
3131 struct AFSStoreStatus InStatus; /* Input status for fid */
3132 Volume *volptr = 0; /* pointer to the volume header */
3133 struct client *client = 0; /* pointer to client structure */
3134 afs_int32 rights, anyrights; /* rights for this and any user */
3135 struct rx_connection *tcon;
3137 struct client *t_client = NULL; /* tmp ptr to client data */
3138 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3139 #if FS_STATS_DETAILED
3140 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3141 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3142 struct timeval elapsedTime; /* Transfer time */
3145 * Set our stats pointer, remember when the RPC operation started, and
3146 * tally the operation.
3148 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3152 TM_GetTimeOfDay(&opStartTime, 0);
3153 #endif /* FS_STATS_DETAILED */
3154 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3157 /* Get ptr to client data for user Id for logging */
3158 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3159 logHostAddr.s_addr = rxr_HostOf(tcon);
3161 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3162 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3163 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3165 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3167 InStatus.Mask = 0; /* not storing any status */
3170 * Get associated volume/vnode for the target dir; caller's rights
3171 * are also returned.
3174 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3175 &parentwhentargetnotdir, &client, WRITE_LOCK,
3176 &rights, &anyrights))) {
3180 /* set volume synchronization information */
3181 SetVolumeSync(Sync, volptr);
3183 /* Check if we have permission to change the dir's ACL */
3185 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3190 /* Build and store the new Access List for the dir */
3191 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3195 targetptr->changed_newTime = 1; /* status change of directory */
3197 /* convert the write lock to a read lock before breaking callbacks */
3198 VVnodeWriteToRead(&errorCode, targetptr);
3199 assert(!errorCode || errorCode == VSALVAGE);
3201 /* break call backs on the directory */
3202 BreakCallBack(client->host, Fid, 0);
3204 /* Get the updated dir's status back to the caller */
3205 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3208 /* Update and store volume/vnode and parent vnodes back */
3209 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3211 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3212 errorCode = CallPostamble(tcon, errorCode, thost);
3214 #if FS_STATS_DETAILED
3215 TM_GetTimeOfDay(&opStopTime, 0);
3216 if (errorCode == 0) {
3218 (opP->numSuccesses)++;
3219 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3220 fs_stats_AddTo((opP->sumTime), elapsedTime);
3221 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3222 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3223 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3225 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3226 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3230 #endif /* FS_STATS_DETAILED */
3232 osi_auditU(acall, StoreACLEvent, errorCode,
3233 AUD_ID, t_client ? t_client->ViceId : 0,
3234 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3237 } /*SRXAFS_StoreACL */
3241 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3242 * should be merged when possible.
3245 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3246 struct AFSStoreStatus *InStatus,
3247 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3249 Vnode *targetptr = 0; /* pointer to input fid */
3250 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3251 int errorCode = 0; /* return code for caller */
3252 Volume *volptr = 0; /* pointer to the volume header */
3253 struct client *client = 0; /* pointer to client structure */
3254 afs_int32 rights, anyrights; /* rights for this and any user */
3255 struct client *t_client = NULL; /* tmp ptr to client data */
3256 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3257 struct rx_connection *tcon = rx_ConnectionOf(acall);
3259 /* Get ptr to client data for user Id for logging */
3260 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3261 logHostAddr.s_addr = rxr_HostOf(tcon);
3263 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3264 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3265 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3267 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3270 * Get volume/vnode for the target file; caller's rights to it are
3274 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3275 &parentwhentargetnotdir, &client, WRITE_LOCK,
3276 &rights, &anyrights))) {
3277 goto Bad_StoreStatus;
3280 /* set volume synchronization information */
3281 SetVolumeSync(Sync, volptr);
3283 /* Check if the caller has proper permissions to store status to Fid */
3285 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3287 goto Bad_StoreStatus;
3290 * Check for a symbolic link; we can't chmod these (otherwise could
3291 * change a symlink to a mt pt or vice versa)
3293 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3295 goto Bad_StoreStatus;
3298 /* Update the status of the target's vnode */
3299 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3300 (parentwhentargetnotdir ? parentwhentargetnotdir
3301 : targetptr), volptr, 0);
3303 /* convert the write lock to a read lock before breaking callbacks */
3304 VVnodeWriteToRead(&errorCode, targetptr);
3305 assert(!errorCode || errorCode == VSALVAGE);
3307 /* Break call backs on Fid */
3308 BreakCallBack(client->host, Fid, 0);
3310 /* Return the updated status back to caller */
3311 GetStatus(targetptr, OutStatus, rights, anyrights,
3312 parentwhentargetnotdir);
3315 /* Update and store volume/vnode and parent vnodes back */
3316 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3318 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3321 } /*SAFSS_StoreStatus */
3325 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3326 struct AFSStoreStatus * InStatus,
3327 struct AFSFetchStatus * OutStatus,
3328 struct AFSVolSync * Sync)
3331 struct rx_connection *tcon;
3333 struct client *t_client = NULL; /* tmp ptr to client data */
3334 #if FS_STATS_DETAILED
3335 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3336 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3337 struct timeval elapsedTime; /* Transfer time */
3340 * Set our stats pointer, remember when the RPC operation started, and
3341 * tally the operation.
3343 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3347 TM_GetTimeOfDay(&opStartTime, 0);
3348 #endif /* FS_STATS_DETAILED */
3350 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3351 goto Bad_StoreStatus;
3353 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3356 code = CallPostamble(tcon, code, thost);
3358 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3360 #if FS_STATS_DETAILED
3361 TM_GetTimeOfDay(&opStopTime, 0);
3364 (opP->numSuccesses)++;
3365 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3366 fs_stats_AddTo((opP->sumTime), elapsedTime);
3367 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3368 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3369 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3371 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3372 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3376 #endif /* FS_STATS_DETAILED */
3378 osi_auditU(acall, StoreStatusEvent, code,
3379 AUD_ID, t_client ? t_client->ViceId : 0,
3380 AUD_FID, Fid, AUD_END);
3383 } /*SRXAFS_StoreStatus */
3387 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3388 * merged in when possible.
3391 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3392 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3394 Vnode *parentptr = 0; /* vnode of input Directory */
3395 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3396 Vnode *targetptr = 0; /* file to be deleted */
3397 Volume *volptr = 0; /* pointer to the volume header */
3398 AFSFid fileFid; /* area for Fid from the directory */
3399 int errorCode = 0; /* error code */
3400 DirHandle dir; /* Handle for dir package I/O */
3401 struct client *client = 0; /* pointer to client structure */
3402 afs_int32 rights, anyrights; /* rights for this and any user */
3403 struct client *t_client; /* tmp ptr to client data */
3404 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3405 struct rx_connection *tcon = rx_ConnectionOf(acall);
3408 /* Get ptr to client data for user Id for logging */
3409 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3410 logHostAddr.s_addr = rxr_HostOf(tcon);
3412 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3413 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3414 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3416 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3419 * Get volume/vnode for the parent dir; caller's access rights are
3423 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3424 &parentwhentargetnotdir, &client, WRITE_LOCK,
3425 &rights, &anyrights))) {
3426 goto Bad_RemoveFile;
3428 /* set volume synchronization information */
3429 SetVolumeSync(Sync, volptr);
3431 /* Does the caller has delete (& write) access to the parent directory? */
3432 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3433 goto Bad_RemoveFile;
3436 /* Actually delete the desired file */
3438 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3440 goto Bad_RemoveFile;
3443 /* Update the vnode status of the parent dir */
3444 #if FS_STATS_DETAILED
3445 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3446 parentptr->disk.linkCount,
3447 client->InSameNetwork);
3449 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3450 parentptr->disk.linkCount);
3451 #endif /* FS_STATS_DETAILED */
3453 /* Return the updated parent dir's status back to caller */
3454 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3456 /* Handle internal callback state for the parent and the deleted file */
3457 if (targetptr->disk.linkCount == 0) {
3458 /* no references left, discard entry */
3459 DeleteFileCallBacks(&fileFid);
3460 /* convert the parent lock to a read lock before breaking callbacks */
3461 VVnodeWriteToRead(&errorCode, parentptr);
3462 assert(!errorCode || errorCode == VSALVAGE);
3464 /* convert the parent lock to a read lock before breaking callbacks */
3465 VVnodeWriteToRead(&errorCode, parentptr);
3466 assert(!errorCode || errorCode == VSALVAGE);
3467 /* convert the target lock to a read lock before breaking callbacks */
3468 VVnodeWriteToRead(&errorCode, targetptr);
3469 assert(!errorCode || errorCode == VSALVAGE);
3470 /* tell all the file has changed */
3471 BreakCallBack(client->host, &fileFid, 1);
3474 /* break call back on the directory */
3475 BreakCallBack(client->host, DirFid, 0);
3478 /* Update and store volume/vnode and parent vnodes back */
3479 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3482 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3485 } /*SAFSS_RemoveFile */
3489 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3490 struct AFSFetchStatus * OutDirStatus,
3491 struct AFSVolSync * Sync)
3494 struct rx_connection *tcon;
3496 struct client *t_client = NULL; /* tmp ptr to client data */
3497 #if FS_STATS_DETAILED
3498 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3499 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3500 struct timeval elapsedTime; /* Transfer time */
3503 * Set our stats pointer, remember when the RPC operation started, and
3504 * tally the operation.
3506 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3510 TM_GetTimeOfDay(&opStartTime, 0);
3511 #endif /* FS_STATS_DETAILED */
3513 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3514 goto Bad_RemoveFile;
3516 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3519 code = CallPostamble(tcon, code, thost);
3521 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3523 #if FS_STATS_DETAILED
3524 TM_GetTimeOfDay(&opStopTime, 0);
3527 (opP->numSuccesses)++;
3528 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3529 fs_stats_AddTo((opP->sumTime), elapsedTime);
3530 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3531 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3532 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3534 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3535 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3539 #endif /* FS_STATS_DETAILED */
3541 osi_auditU(acall, RemoveFileEvent, code,
3542 AUD_ID, t_client ? t_client->ViceId : 0,
3543 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3546 } /*SRXAFS_RemoveFile */
3550 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3551 * be merged in when possible.
3554 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3555 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3556 struct AFSFetchStatus *OutFidStatus,
3557 struct AFSFetchStatus *OutDirStatus,
3558 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3560 Vnode *parentptr = 0; /* vnode of input Directory */
3561 Vnode *targetptr = 0; /* vnode of the new file */
3562 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3563 Volume *volptr = 0; /* pointer to the volume header */
3564 int errorCode = 0; /* error code */
3565 DirHandle dir; /* Handle for dir package I/O */
3566 struct client *client = 0; /* pointer to client structure */
3567 afs_int32 rights, anyrights; /* rights for this and any user */
3568 struct client *t_client; /* tmp ptr to client data */
3569 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3570 struct rx_connection *tcon = rx_ConnectionOf(acall);
3574 /* Get ptr to client data for user Id for logging */
3575 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3576 logHostAddr.s_addr = rxr_HostOf(tcon);
3578 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3579 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3580 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3582 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3584 if (!FileNameOK(Name)) {
3586 goto Bad_CreateFile;
3590 * Get associated volume/vnode for the parent dir; caller long are
3594 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3595 &parentwhentargetnotdir, &client, WRITE_LOCK,
3596 &rights, &anyrights))) {
3597 goto Bad_CreateFile;
3600 /* set volume synchronization information */
3601 SetVolumeSync(Sync, volptr);
3603 /* Can we write (and insert) onto the parent directory? */
3604 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3605 goto Bad_CreateFile;
3607 /* get a new vnode for the file to be created and set it up */
3609 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3610 vFile, nBlocks(0)))) {
3611 goto Bad_CreateFile;
3614 /* update the status of the parent vnode */
3615 #if FS_STATS_DETAILED
3616 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3617 parentptr->disk.linkCount,
3618 client->InSameNetwork);
3620 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3621 parentptr->disk.linkCount);
3622 #endif /* FS_STATS_DETAILED */
3624 /* update the status of the new file's vnode */
3625 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3626 parentptr, volptr, 0);
3628 /* 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 */
3629 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3630 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3632 /* convert the write lock to a read lock before breaking callbacks */
3633 VVnodeWriteToRead(&errorCode, parentptr);
3634 assert(!errorCode || errorCode == VSALVAGE);
3636 /* break call back on parent dir */
3637 BreakCallBack(client->host, DirFid, 0);
3639 /* Return a callback promise for the newly created file to the caller */
3640 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3643 /* Update and store volume/vnode and parent vnodes back */
3644 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3647 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3650 } /*SAFSS_CreateFile */
3654 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3655 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3656 struct AFSFetchStatus * OutFidStatus,
3657 struct AFSFetchStatus * OutDirStatus,
3658 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3661 struct rx_connection *tcon;
3663 struct client *t_client = NULL; /* tmp ptr to client data */
3664 #if FS_STATS_DETAILED
3665 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3666 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3667 struct timeval elapsedTime; /* Transfer time */
3670 * Set our stats pointer, remember when the RPC operation started, and
3671 * tally the operation.
3673 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3677 TM_GetTimeOfDay(&opStartTime, 0);
3678 #endif /* FS_STATS_DETAILED */
3680 memset(OutFid, 0, sizeof(struct AFSFid));
3682 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3683 goto Bad_CreateFile;
3686 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3687 OutDirStatus, CallBack, Sync);
3690 code = CallPostamble(tcon, code, thost);
3692 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3694 #if FS_STATS_DETAILED
3695 TM_GetTimeOfDay(&opStopTime, 0);
3698 (opP->numSuccesses)++;
3699 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3700 fs_stats_AddTo((opP->sumTime), elapsedTime);
3701 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3702 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3703 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3705 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3706 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3710 #endif /* FS_STATS_DETAILED */
3712 osi_auditU(acall, CreateFileEvent, code,
3713 AUD_ID, t_client ? t_client->ViceId : 0,
3714 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3717 } /*SRXAFS_CreateFile */
3721 * This routine is called exclusively from SRXAFS_Rename(), and should be
3722 * merged in when possible.
3725 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3726 struct AFSFid *NewDirFid, char *NewName,
3727 struct AFSFetchStatus *OutOldDirStatus,
3728 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3730 Vnode *oldvptr = 0; /* vnode of the old Directory */
3731 Vnode *newvptr = 0; /* vnode of the new Directory */
3732 Vnode *fileptr = 0; /* vnode of the file to move */
3733 Vnode *newfileptr = 0; /* vnode of the file to delete */
3734 Vnode *testvptr = 0; /* used in directory tree walk */
3735 Vnode *parent = 0; /* parent for use in SetAccessList */
3736 int errorCode = 0; /* error code */
3737 int fileCode = 0; /* used when writing Vnodes */
3738 VnodeId testnode; /* used in directory tree walk */
3739 AFSFid fileFid; /* Fid of file to move */
3740 AFSFid newFileFid; /* Fid of new file */
3741 DirHandle olddir; /* Handle for dir package I/O */
3742 DirHandle newdir; /* Handle for dir package I/O */
3743 DirHandle filedir; /* Handle for dir package I/O */
3744 DirHandle newfiledir; /* Handle for dir package I/O */
3745 Volume *volptr = 0; /* pointer to the volume header */
3746 struct client *client = 0; /* pointer to client structure */
3747 afs_int32 rights, anyrights; /* rights for this and any user */
3748 afs_int32 newrights; /* rights for this user */
3749 afs_int32 newanyrights; /* rights for any user */
3750 int doDelete; /* deleted the rename target (ref count now 0) */
3752 struct client *t_client; /* tmp ptr to client data */
3753 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3754 struct rx_connection *tcon = rx_ConnectionOf(acall);
3759 FidZero(&newfiledir);
3761 /* Get ptr to client data for user Id for logging */
3762 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3763 logHostAddr.s_addr = rxr_HostOf(tcon);
3765 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3766 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3767 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3768 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3770 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3772 if (!FileNameOK(NewName)) {
3776 if (OldDirFid->Volume != NewDirFid->Volume) {
3781 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3782 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3783 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3789 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3791 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3792 &parent, &client, WRITE_LOCK, &rights,
3797 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3799 newrights = rights, newanyrights = anyrights;
3802 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3803 MustBeDIR, &parent, &client, WRITE_LOCK,
3804 &newrights, &newanyrights))) {
3810 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3811 &parent, &client, WRITE_LOCK, &newrights,
3817 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3818 &parent, &client, WRITE_LOCK, &rights,
3825 /* set volume synchronization information */
3826 SetVolumeSync(Sync, volptr);
3828 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3831 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3835 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3836 * call to CopyOnWrite returns error, it is not necessary to revert back
3837 * the effects of the first call because the contents of the volume is
3838 * not modified, it is only replicated.
3840 if (oldvptr->disk.cloned) {
3841 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3842 if ((errorCode = CopyOnWrite(oldvptr, volptr)))
3845 SetDirHandle(&olddir, oldvptr);
3846 if (newvptr->disk.cloned) {
3847 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3848 if ((errorCode = CopyOnWrite(newvptr, volptr)))
3852 SetDirHandle(&newdir, newvptr);
3854 /* Lookup the file to delete its vnode */
3855 if (Lookup(&olddir, OldName, &fileFid)) {
3859 if (fileFid.Vnode == oldvptr->vnodeNumber
3860 || fileFid.Vnode == newvptr->vnodeNumber) {
3861 errorCode = FSERR_ELOOP;
3864 fileFid.Volume = V_id(volptr);
3865 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3866 if (errorCode != 0) {
3868 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3869 OldName, errorCode));
3870 VTakeOffline(volptr);
3873 if (fileptr->disk.uniquifier != fileFid.Unique) {
3875 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3877 VTakeOffline(volptr);
3882 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3883 && fileptr->disk.linkCount != 1) {
3885 * Hard links exist to this file - cannot move one of the links to
3886 * a new directory because of AFS restrictions (this is the same
3887 * reason that links cannot be made across directories, i.e.
3894 /* Lookup the new file */
3895 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3896 if (readonlyServer) {
3897 errorCode = VREADONLY;
3900 if (!(newrights & PRSFS_DELETE)) {
3904 if (newFileFid.Vnode == oldvptr->vnodeNumber
3905 || newFileFid.Vnode == newvptr->vnodeNumber
3906 || newFileFid.Vnode == fileFid.Vnode) {
3910 newFileFid.Volume = V_id(volptr);
3912 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3913 if (errorCode != 0) {
3915 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
3916 NewName, errorCode));
3917 VTakeOffline(volptr);
3920 if (fileptr->disk.uniquifier != fileFid.Unique) {
3922 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
3924 VTakeOffline(volptr);
3928 SetDirHandle(&newfiledir, newfileptr);
3929 /* Now check that we're moving directories over directories properly, etc.
3930 * return proper POSIX error codes:
3931 * if fileptr is a file and new is a dir: EISDIR.
3932 * if fileptr is a dir and new is a file: ENOTDIR.
3933 * Also, dir to be removed must be empty, of course.
3935 if (newfileptr->disk.type == vDirectory) {
3936 if (fileptr->disk.type != vDirectory) {
3940 if ((IsEmpty(&newfiledir))) {
3945 if (fileptr->disk.type == vDirectory) {
3946 errorCode = ENOTDIR;
3953 * ok - now we check that the old name is not above new name in the
3954 * directory structure. This is to prevent removing a subtree alltogether
3956 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
3957 afs_int32 forpass = 0, vnum = 0, top = 0;
3958 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
3959 if (testnode > vnum) vnum = testnode;
3960 if (forpass > vnum) {
3961 errorCode = FSERR_ELOOP;
3964 if (testnode == oldvptr->vnodeNumber) {
3965 testnode = oldvptr->disk.parent;
3968 if ((testnode == fileptr->vnodeNumber)
3969 || (testnode == newvptr->vnodeNumber)) {
3970 errorCode = FSERR_ELOOP;
3973 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
3974 errorCode = FSERR_ELOOP;
3977 if (testnode == 1) top = 1;
3978 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
3979 assert(errorCode == 0);
3980 testnode = testvptr->disk.parent;
3981 VPutVnode(&errorCode, testvptr);
3982 if ((top == 1) && (testnode != 0)) {
3983 VTakeOffline(volptr);
3987 assert(errorCode == 0);
3990 /* Do the CopyonWrite first before modifying anything else. Copying is
3991 * required because we may have to change entries for ..
3993 if ((fileptr->disk.type == vDirectory) && (fileptr->disk.cloned)) {
3994 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
3995 if ((errorCode = CopyOnWrite(fileptr, volptr)))
3999 /* If the new name exists already, delete it and the file it points to */
4002 /* Delete NewName from its directory */
4003 code = Delete(&newdir, NewName);
4006 /* Drop the link count */
4007 newfileptr->disk.linkCount--;
4008 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4009 afs_fsize_t newSize;
4010 VN_GET_LEN(newSize, newfileptr);
4011 VAdjustDiskUsage((Error *) & errorCode, volptr,
4012 (afs_sfsize_t) - nBlocks(newSize), 0);
4013 if (VN_GET_INO(newfileptr)) {
4014 IH_REALLYCLOSE(newfileptr->handle);
4016 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
4017 V_parentId(volptr));
4018 IH_RELEASE(newfileptr->handle);
4019 if (errorCode == -1) {
4021 ("Del: inode=%s, name=%s, errno=%d\n",
4022 PrintInode(NULL, VN_GET_INO(newfileptr)),
4024 if ((errno != ENOENT) && (errno != EIO)
4025 && (errno != ENXIO))
4026 ViceLog(0, ("Do we need to fsck?"));
4029 VN_SET_INO(newfileptr, (Inode) 0);
4030 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4033 /* Link count did not drop to zero.
4034 * Mark NewName vnode as changed - updates stime.
4036 newfileptr->changed_newTime = 1;
4041 * If the create below fails, and the delete above worked, we have
4042 * removed the new name and not replaced it. This is not very likely,
4043 * but possible. We could try to put the old file back, but it is
4044 * highly unlikely that it would work since it would involve issuing
4047 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4050 /* Delete the old name */
4051 assert(Delete(&olddir, (char *)OldName) == 0);
4053 /* if the directory length changes, reflect it in the statistics */
4054 #if FS_STATS_DETAILED
4055 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4056 oldvptr->disk.linkCount, client->InSameNetwork);
4057 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4058 newvptr->disk.linkCount, client->InSameNetwork);
4060 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4061 oldvptr->disk.linkCount);
4062 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4063 newvptr->disk.linkCount);
4064 #endif /* FS_STATS_DETAILED */
4066 if (oldvptr == newvptr)
4067 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4069 fileptr->disk.parent = newvptr->vnodeNumber;
4070 fileptr->changed_newTime = 1; /* status change of moved file */
4072 /* if we are dealing with a rename of a directory */
4073 if (fileptr->disk.type == vDirectory) {
4074 assert(!fileptr->disk.cloned);
4075 SetDirHandle(&filedir, fileptr);
4076 /* fix .. to point to the correct place */
4077 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4078 assert(Create(&filedir, "..", NewDirFid) == 0);
4079 fileptr->disk.dataVersion++;
4080 /* if the parent directories are different the link counts have to be */
4081 /* changed due to .. in the renamed directory */
4082 if (oldvptr != newvptr) {
4083 oldvptr->disk.linkCount--;
4084 newvptr->disk.linkCount++;
4088 /* set up return status */
4089 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4090 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4091 if (newfileptr && doDelete) {
4092 DeleteFileCallBacks(&newFileFid); /* no other references */
4097 /* convert the write locks to a read locks before breaking callbacks */
4098 VVnodeWriteToRead(&errorCode, newvptr);
4099 assert(!errorCode || errorCode == VSALVAGE);
4100 if (oldvptr != newvptr) {
4101 VVnodeWriteToRead(&errorCode, oldvptr);
4102 assert(!errorCode || errorCode == VSALVAGE);
4104 if (newfileptr && !doDelete) {
4105 /* convert the write lock to a read lock before breaking callbacks */
4106 VVnodeWriteToRead(&errorCode, newfileptr);
4107 assert(!errorCode || errorCode == VSALVAGE);
4110 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4111 BreakCallBack(client->host, NewDirFid, 0);
4112 if (oldvptr != newvptr) {
4113 BreakCallBack(client->host, OldDirFid, 0);
4114 if (fileptr->disk.type == vDirectory) /* if a dir moved, .. changed */
4115 BreakCallBack(client->host, &fileFid, 0);
4118 /* Note: it is not necessary to break the callback */
4120 DeleteFileCallBacks(&newFileFid); /* no other references */
4122 /* other's still exist (with wrong link count) */
4123 BreakCallBack(client->host, &newFileFid, 1);
4128 VPutVnode(&fileCode, newfileptr);
4129 assert(fileCode == 0);
4131 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
4132 newvptr : 0), oldvptr, volptr, &client);
4136 FidZap(&newfiledir);
4137 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4144 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4145 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4146 struct AFSFetchStatus * OutOldDirStatus,
4147 struct AFSFetchStatus * OutNewDirStatus,
4148 struct AFSVolSync * Sync)
4151 struct rx_connection *tcon;
4153 struct client *t_client = NULL; /* tmp ptr to client data */
4154 #if FS_STATS_DETAILED
4155 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4156 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4157 struct timeval elapsedTime; /* Transfer time */
4160 * Set our stats pointer, remember when the RPC operation started, and
4161 * tally the operation.
4163 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4167 TM_GetTimeOfDay(&opStartTime, 0);
4168 #endif /* FS_STATS_DETAILED */
4170 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4174 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4175 OutOldDirStatus, OutNewDirStatus, Sync);
4178 code = CallPostamble(tcon, code, thost);
4180 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4182 #if FS_STATS_DETAILED
4183 TM_GetTimeOfDay(&opStopTime, 0);
4186 (opP->numSuccesses)++;
4187 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4188 fs_stats_AddTo((opP->sumTime), elapsedTime);
4189 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4190 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4191 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4193 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4194 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4198 #endif /* FS_STATS_DETAILED */
4200 osi_auditU(acall, RenameFileEvent, code,
4201 AUD_ID, t_client ? t_client->ViceId : 0,
4202 AUD_FID, OldDirFid, AUD_STR, OldName,
4203 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4206 } /*SRXAFS_Rename */
4210 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4211 * merged into it when possible.
4214 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4215 char *LinkContents, struct AFSStoreStatus *InStatus,
4216 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4217 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4219 Vnode *parentptr = 0; /* vnode of input Directory */
4220 Vnode *targetptr = 0; /* vnode of the new link */
4221 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4222 int errorCode = 0; /* error code */
4224 DirHandle dir; /* Handle for dir package I/O */
4225 Volume *volptr = 0; /* pointer to the volume header */
4226 struct client *client = 0; /* pointer to client structure */
4227 afs_int32 rights, anyrights; /* rights for this and any user */
4228 struct client *t_client; /* tmp ptr to client data */
4229 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4231 struct rx_connection *tcon = rx_ConnectionOf(acall);
4235 /* Get ptr to client data for user Id for logging */
4236 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4237 logHostAddr.s_addr = rxr_HostOf(tcon);
4239 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4240 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4241 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4243 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4245 if (!FileNameOK(Name)) {
4251 * Get the vnode and volume for the parent dir along with the caller's
4255 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4256 &parentwhentargetnotdir, &client, WRITE_LOCK,
4257 &rights, &anyrights))) {
4261 /* set volume synchronization information */
4262 SetVolumeSync(Sync, volptr);
4264 /* Does the caller has insert (and write) access to the parent directory? */
4265 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4270 * If we're creating a mount point (any x bits clear), we must have
4271 * administer access to the directory, too. Always allow sysadmins
4274 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4275 if (readonlyServer) {
4276 errorCode = VREADONLY;
4280 * We have a mountpoint, 'cause we're trying to set the Unix mode
4281 * bits to something with some x bits missing (default mode bits
4282 * if AFS_SETMODE is false is 0777)
4284 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4290 /* get a new vnode for the symlink and set it up */
4292 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4293 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4297 /* update the status of the parent vnode */
4298 #if FS_STATS_DETAILED
4299 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4300 parentptr->disk.linkCount,
4301 client->InSameNetwork);
4303 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4304 parentptr->disk.linkCount);
4305 #endif /* FS_STATS_DETAILED */
4307 /* update the status of the new symbolic link file vnode */
4308 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4309 parentptr, volptr, strlen((char *)LinkContents));
4311 /* Write the contents of the symbolic link name into the target inode */
4312 fdP = IH_OPEN(targetptr->handle);
4313 assert(fdP != NULL);
4314 len = strlen((char *) LinkContents);
4315 code = (len == FDH_WRITE(fdP, (char *) LinkContents, len)) ? 0 : VDISKFULL;
4316 if (code) ViceLog(0, ("SAFSS_Symlink FDH_WRITE failed for len=%d, Fid=%u.%d.%d\n", len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4319 * Set up and return modified status for the parent dir and new symlink
4322 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4323 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4325 /* convert the write lock to a read lock before breaking callbacks */
4326 VVnodeWriteToRead(&errorCode, parentptr);
4327 assert(!errorCode || errorCode == VSALVAGE);
4329 /* break call back on the parent dir */
4330 BreakCallBack(client->host, DirFid, 0);
4333 /* Write the all modified vnodes (parent, new files) and volume back */
4334 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4337 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4338 return ( errorCode ? errorCode : code );
4340 } /*SAFSS_Symlink */
4344 SRXAFS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4345 OutFidStatus, OutDirStatus, Sync)
4346 struct AFSVolSync *Sync;
4347 struct rx_call *acall; /* Rx call */
4348 struct AFSFid *DirFid; /* Parent dir's fid */
4349 char *Name; /* File name to create */
4350 char *LinkContents; /* Contents of the new created file */
4351 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
4352 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
4353 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
4354 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
4358 struct rx_connection *tcon;
4360 struct client *t_client = NULL; /* tmp ptr to client data */
4361 #if FS_STATS_DETAILED
4362 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4363 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4364 struct timeval elapsedTime; /* Transfer time */
4367 * Set our stats pointer, remember when the RPC operation started, and
4368 * tally the operation.
4370 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4374 TM_GetTimeOfDay(&opStartTime, 0);
4375 #endif /* FS_STATS_DETAILED */
4377 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4381 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4382 OutFidStatus, OutDirStatus, Sync);
4385 code = CallPostamble(tcon, code, thost);
4387 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4389 #if FS_STATS_DETAILED
4390 TM_GetTimeOfDay(&opStopTime, 0);
4393 (opP->numSuccesses)++;
4394 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4395 fs_stats_AddTo((opP->sumTime), elapsedTime);
4396 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4397 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4398 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4400 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4401 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4405 #endif /* FS_STATS_DETAILED */
4407 osi_auditU(acall, SymlinkEvent, code,
4408 AUD_ID, t_client ? t_client->ViceId : 0,
4409 AUD_FID, DirFid, AUD_STR, Name,
4410 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4413 } /*SRXAFS_Symlink */
4417 * This routine is called exclusively by SRXAFS_Link(), and should be
4418 * merged into it when possible.
4421 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4422 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4423 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4425 Vnode *parentptr = 0; /* vnode of input Directory */
4426 Vnode *targetptr = 0; /* vnode of the new file */
4427 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4428 Volume *volptr = 0; /* pointer to the volume header */
4429 int errorCode = 0; /* error code */
4430 DirHandle dir; /* Handle for dir package I/O */
4431 struct client *client = 0; /* pointer to client structure */
4432 afs_int32 rights, anyrights; /* rights for this and any user */
4433 struct client *t_client; /* tmp ptr to client data */
4434 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4435 struct rx_connection *tcon = rx_ConnectionOf(acall);
4439 /* Get ptr to client data for user Id for logging */
4440 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4441 logHostAddr.s_addr = rxr_HostOf(tcon);
4443 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4444 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4445 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4446 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4448 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4450 if (DirFid->Volume != ExistingFid->Volume) {
4454 if (!FileNameOK(Name)) {
4460 * Get the vnode and volume for the parent dir along with the caller's
4464 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4465 &parentwhentargetnotdir, &client, WRITE_LOCK,
4466 &rights, &anyrights))) {
4470 /* set volume synchronization information */
4471 SetVolumeSync(Sync, volptr);
4473 /* Can the caller insert into the parent directory? */
4474 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4478 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4479 /* AFS fileservers always have directory vnodes that are odd. */
4484 /* get the file vnode */
4486 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4489 if (targetptr->disk.type != vFile) {
4493 if (targetptr->disk.parent != DirFid->Vnode) {
4497 if (parentptr->disk.cloned) {
4498 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4499 if ((errorCode = CopyOnWrite(parentptr, volptr)))
4500 goto Bad_Link; /* disk full error */
4503 /* add the name to the directory */
4504 SetDirHandle(&dir, parentptr);
4505 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4509 /* update the status in the parent vnode */
4510 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4511 #if FS_STATS_DETAILED
4512 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4513 parentptr->disk.linkCount,
4514 client->InSameNetwork);
4516 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4517 parentptr->disk.linkCount);
4518 #endif /* FS_STATS_DETAILED */
4520 targetptr->disk.linkCount++;
4521 targetptr->disk.author = client->ViceId;
4522 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4524 /* set up return status */
4525 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4526 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4528 /* convert the write locks to read locks before breaking callbacks */
4529 VVnodeWriteToRead(&errorCode, targetptr);
4530 assert(!errorCode || errorCode == VSALVAGE);
4531 VVnodeWriteToRead(&errorCode, parentptr);
4532 assert(!errorCode || errorCode == VSALVAGE);
4534 /* break call back on DirFid */
4535 BreakCallBack(client->host, DirFid, 0);
4537 * We also need to break the callback for the file that is hard-linked since part
4538 * of its status (like linkcount) is changed
4540 BreakCallBack(client->host, ExistingFid, 0);
4543 /* Write the all modified vnodes (parent, new files) and volume back */
4544 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4547 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4554 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4555 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4556 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4559 struct rx_connection *tcon;
4561 struct client *t_client = NULL; /* tmp ptr to client data */
4562 #if FS_STATS_DETAILED
4563 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4564 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4565 struct timeval elapsedTime; /* Transfer time */
4568 * Set our stats pointer, remember when the RPC operation started, and
4569 * tally the operation.
4571 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4575 TM_GetTimeOfDay(&opStartTime, 0);
4576 #endif /* FS_STATS_DETAILED */
4578 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4582 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4583 OutDirStatus, Sync);
4586 code = CallPostamble(tcon, code, thost);
4588 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4590 #if FS_STATS_DETAILED
4591 TM_GetTimeOfDay(&opStopTime, 0);
4594 (opP->numSuccesses)++;
4595 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4596 fs_stats_AddTo((opP->sumTime), elapsedTime);
4597 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4598 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4599 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4601 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4602 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4606 #endif /* FS_STATS_DETAILED */
4608 osi_auditU(acall, LinkEvent, code,
4609 AUD_ID, t_client ? t_client->ViceId : 0,
4610 AUD_FID, DirFid, AUD_STR, Name,
4611 AUD_FID, ExistingFid, AUD_END);
4618 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4619 * merged into it when possible.
4622 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4623 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4624 struct AFSFetchStatus *OutFidStatus,
4625 struct AFSFetchStatus *OutDirStatus,
4626 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4628 Vnode *parentptr = 0; /* vnode of input Directory */
4629 Vnode *targetptr = 0; /* vnode of the new file */
4630 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4631 Volume *volptr = 0; /* pointer to the volume header */
4632 int errorCode = 0; /* error code */
4633 struct acl_accessList *newACL; /* Access list */
4634 int newACLSize; /* Size of access list */
4635 DirHandle dir; /* Handle for dir package I/O */
4636 DirHandle parentdir; /* Handle for dir package I/O */
4637 struct client *client = 0; /* pointer to client structure */
4638 afs_int32 rights, anyrights; /* rights for this and any user */
4639 struct client *t_client; /* tmp ptr to client data */
4640 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4641 struct rx_connection *tcon = rx_ConnectionOf(acall);
4644 FidZero(&parentdir);
4646 /* Get ptr to client data for user Id for logging */
4647 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4648 logHostAddr.s_addr = rxr_HostOf(tcon);
4650 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4651 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4652 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4654 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4656 if (!FileNameOK(Name)) {
4662 * Get the vnode and volume for the parent dir along with the caller's
4666 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4667 &parentwhentargetnotdir, &client, WRITE_LOCK,
4668 &rights, &anyrights))) {
4672 /* set volume synchronization information */
4673 SetVolumeSync(Sync, volptr);
4675 /* Write access to the parent directory? */
4676 #ifdef DIRCREATE_NEED_WRITE
4678 * requires w access for the user to create a directory. this
4679 * closes a loophole in the current security arrangement, since a
4680 * user with i access only can create a directory and get the
4681 * implcit a access that goes with dir ownership, and proceed to
4682 * subvert quota in the volume.
4684 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4685 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4687 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4688 #endif /* DIRCREATE_NEED_WRITE */
4691 #define EMPTYDIRBLOCKS 2
4692 /* get a new vnode and set it up */
4694 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4695 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4699 /* Update the status for the parent dir */
4700 #if FS_STATS_DETAILED
4701 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4702 parentptr->disk.linkCount + 1,
4703 client->InSameNetwork);
4705 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4706 parentptr->disk.linkCount + 1);
4707 #endif /* FS_STATS_DETAILED */
4709 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4710 assert((SetAccessList
4711 (&targetptr, &volptr, &newACL, &newACLSize,
4712 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4713 assert(parentwhentargetnotdir == 0);
4714 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4716 /* update the status for the target vnode */
4717 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4718 parentptr, volptr, 0);
4720 /* Actually create the New directory in the directory package */
4721 SetDirHandle(&dir, targetptr);
4722 assert(!(MakeDir(&dir, OutFid, DirFid)));
4724 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4726 /* set up return status */
4727 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4728 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4730 /* convert the write lock to a read lock before breaking callbacks */
4731 VVnodeWriteToRead(&errorCode, parentptr);
4732 assert(!errorCode || errorCode == VSALVAGE);
4734 /* break call back on DirFid */
4735 BreakCallBack(client->host, DirFid, 0);
4737 /* Return a callback promise to caller */
4738 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4741 /* Write the all modified vnodes (parent, new files) and volume back */
4742 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4746 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4749 } /*SAFSS_MakeDir */
4753 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4754 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4755 struct AFSFetchStatus * OutFidStatus,
4756 struct AFSFetchStatus * OutDirStatus,
4757 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4760 struct rx_connection *tcon;
4762 struct client *t_client = NULL; /* tmp ptr to client data */
4763 #if FS_STATS_DETAILED
4764 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4765 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4766 struct timeval elapsedTime; /* Transfer time */
4769 * Set our stats pointer, remember when the RPC operation started, and
4770 * tally the operation.
4772 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
4776 TM_GetTimeOfDay(&opStartTime, 0);
4777 #endif /* FS_STATS_DETAILED */
4778 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4782 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4783 OutDirStatus, CallBack, Sync);
4786 code = CallPostamble(tcon, code, thost);
4788 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4790 #if FS_STATS_DETAILED
4791 TM_GetTimeOfDay(&opStopTime, 0);
4794 (opP->numSuccesses)++;
4795 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4796 fs_stats_AddTo((opP->sumTime), elapsedTime);
4797 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4798 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4799 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4801 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4802 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4806 #endif /* FS_STATS_DETAILED */
4808 osi_auditU(acall, MakeDirEvent, code,
4809 AUD_ID, t_client ? t_client->ViceId : 0,
4810 AUD_FID, DirFid, AUD_STR, Name,
4811 AUD_FID, OutFid, AUD_END);
4814 } /*SRXAFS_MakeDir */
4818 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4819 * merged into it when possible.
4822 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4823 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4825 Vnode *parentptr = 0; /* vnode of input Directory */
4826 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4827 Vnode *targetptr = 0; /* file to be deleted */
4828 AFSFid fileFid; /* area for Fid from the directory */
4829 int errorCode = 0; /* error code */
4830 DirHandle dir; /* Handle for dir package I/O */
4831 Volume *volptr = 0; /* pointer to the volume header */
4832 struct client *client = 0; /* pointer to client structure */
4833 afs_int32 rights, anyrights; /* rights for this and any user */
4834 Vnode debugvnode1, debugvnode2;
4835 struct client *t_client; /* tmp ptr to client data */
4836 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4837 struct rx_connection *tcon = rx_ConnectionOf(acall);
4841 /* Get ptr to client data for user Id for logging */
4842 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4843 logHostAddr.s_addr = rxr_HostOf(tcon);
4845 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4846 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4847 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4849 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4852 * Get the vnode and volume for the parent dir along with the caller's
4856 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4857 &parentwhentargetnotdir, &client, WRITE_LOCK,
4858 &rights, &anyrights))) {
4861 debugvnode1 = *parentptr;
4863 /* set volume synchronization information */
4864 SetVolumeSync(Sync, volptr);
4866 /* Does the caller has delete (&write) access to the parent dir? */
4867 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
4871 debugvnode2 = *parentptr;
4872 /* Do the actual delete of the desired (empty) directory, Name */
4874 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
4879 /* Update the status for the parent dir; link count is also adjusted */
4880 #if FS_STATS_DETAILED
4881 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4882 parentptr->disk.linkCount - 1,
4883 client->InSameNetwork);
4885 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4886 parentptr->disk.linkCount - 1);
4887 #endif /* FS_STATS_DETAILED */
4889 /* Return to the caller the updated parent dir status */
4890 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4893 * Note: it is not necessary to break the callback on fileFid, since
4894 * refcount is now 0, so no one should be able to refer to the dir
4897 DeleteFileCallBacks(&fileFid);
4899 /* convert the write lock to a read lock before breaking callbacks */
4900 VVnodeWriteToRead(&errorCode, parentptr);
4901 assert(!errorCode || errorCode == VSALVAGE);
4903 /* break call back on DirFid and fileFid */
4904 BreakCallBack(client->host, DirFid, 0);
4907 /* Write the all modified vnodes (parent, new files) and volume back */
4908 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4911 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
4914 } /*SAFSS_RemoveDir */
4918 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4919 struct AFSFetchStatus * OutDirStatus,
4920 struct AFSVolSync * Sync)
4923 struct rx_connection *tcon;
4925 struct client *t_client = NULL; /* tmp ptr to client data */
4926 #if FS_STATS_DETAILED
4927 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4928 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4929 struct timeval elapsedTime; /* Transfer time */
4932 * Set our stats pointer, remember when the RPC operation started, and
4933 * tally the operation.
4935 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
4939 TM_GetTimeOfDay(&opStartTime, 0);
4940 #endif /* FS_STATS_DETAILED */
4942 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4945 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
4948 code = CallPostamble(tcon, code, thost);
4950 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4952 #if FS_STATS_DETAILED
4953 TM_GetTimeOfDay(&opStopTime, 0);
4956 (opP->numSuccesses)++;
4957 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4958 fs_stats_AddTo((opP->sumTime), elapsedTime);
4959 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4960 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4961 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4963 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4964 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4968 #endif /* FS_STATS_DETAILED */
4970 osi_auditU(acall, RemoveDirEvent, code,
4971 AUD_ID, t_client ? t_client->ViceId : 0,
4972 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
4975 } /*SRXAFS_RemoveDir */
4979 * This routine is called exclusively by SRXAFS_SetLock(), and should be
4980 * merged into it when possible.
4983 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
4984 struct AFSVolSync *Sync)
4986 Vnode *targetptr = 0; /* vnode of input file */
4987 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4988 int errorCode = 0; /* error code */
4989 Volume *volptr = 0; /* pointer to the volume header */
4990 struct client *client = 0; /* pointer to client structure */
4991 afs_int32 rights, anyrights; /* rights for this and any user */
4992 struct client *t_client; /* tmp ptr to client data */
4993 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4994 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
4995 struct rx_connection *tcon = rx_ConnectionOf(acall);
4997 if (type != LockRead && type != LockWrite) {
5001 /* Get ptr to client data for user Id for logging */
5002 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5003 logHostAddr.s_addr = rxr_HostOf(tcon);
5005 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
5006 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
5007 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5009 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
5012 * Get the vnode and volume for the desired file along with the caller's
5016 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5017 &parentwhentargetnotdir, &client, WRITE_LOCK,
5018 &rights, &anyrights))) {
5022 /* set volume synchronization information */
5023 SetVolumeSync(Sync, volptr);
5025 /* Handle the particular type of set locking, type */
5026 errorCode = HandleLocking(targetptr, client, rights, type);
5029 /* Write the all modified vnodes (parent, new files) and volume back */
5030 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5033 if ((errorCode == VREADONLY) && (type == LockRead))
5034 errorCode = 0; /* allow read locks on RO volumes without saving state */
5036 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
5039 } /*SAFSS_SetLock */
5043 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
5044 ViceLockType type, struct AFSVolSync * Sync)
5046 return SRXAFS_SetLock(acall, Fid, type, Sync);
5047 } /*SRXAFS_OldSetLock */
5051 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
5052 struct AFSVolSync * Sync)
5055 struct rx_connection *tcon;
5057 struct client *t_client = NULL; /* tmp ptr to client data */
5058 #if FS_STATS_DETAILED
5059 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5060 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5061 struct timeval elapsedTime; /* Transfer time */
5064 * Set our stats pointer, remember when the RPC operation started, and
5065 * tally the operation.
5067 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5071 TM_GetTimeOfDay(&opStartTime, 0);
5072 #endif /* FS_STATS_DETAILED */
5074 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5077 code = SAFSS_SetLock(acall, Fid, type, Sync);
5080 code = CallPostamble(tcon, code, thost);
5082 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5084 #if FS_STATS_DETAILED
5085 TM_GetTimeOfDay(&opStopTime, 0);
5088 (opP->numSuccesses)++;
5089 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5090 fs_stats_AddTo((opP->sumTime), elapsedTime);
5091 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5092 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5093 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5095 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5096 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5100 #endif /* FS_STATS_DETAILED */
5102 osi_auditU(acall, SetLockEvent, code,
5103 AUD_ID, t_client ? t_client->ViceId : 0,
5104 AUD_FID, Fid, AUD_LONG, type, AUD_END);
5106 } /*SRXAFS_SetLock */
5110 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5111 * merged into it when possible.
5114 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5115 struct AFSVolSync *Sync)
5117 Vnode *targetptr = 0; /* vnode of input file */
5118 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5119 int errorCode = 0; /* error code */
5120 Volume *volptr = 0; /* pointer to the volume header */
5121 struct client *client = 0; /* pointer to client structure */
5122 afs_int32 rights, anyrights; /* rights for this and any user */
5123 struct client *t_client; /* tmp ptr to client data */
5124 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5125 struct rx_connection *tcon = rx_ConnectionOf(acall);
5127 /* Get ptr to client data for user Id for logging */
5128 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5129 logHostAddr.s_addr = rxr_HostOf(tcon);
5131 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5132 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5133 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5135 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5138 * Get the vnode and volume for the desired file along with the caller's
5142 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5143 &parentwhentargetnotdir, &client, WRITE_LOCK,
5144 &rights, &anyrights))) {
5145 goto Bad_ExtendLock;
5148 /* set volume synchronization information */
5149 SetVolumeSync(Sync, volptr);
5151 /* Handle the actual lock extension */
5152 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
5155 /* Put back file's vnode and volume */
5156 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5159 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5160 errorCode = 0; /* under our generous policy re RO vols */
5162 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5165 } /*SAFSS_ExtendLock */
5169 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5170 struct AFSVolSync * Sync)
5172 return SRXAFS_ExtendLock(acall, Fid, Sync);
5173 } /*SRXAFS_OldExtendLock */
5177 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5178 struct AFSVolSync * Sync)
5181 struct rx_connection *tcon;
5183 struct client *t_client = NULL; /* tmp ptr to client data */
5184 #if FS_STATS_DETAILED
5185 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5186 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5187 struct timeval elapsedTime; /* Transfer time */
5190 * Set our stats pointer, remember when the RPC operation started, and
5191 * tally the operation.
5193 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5197 TM_GetTimeOfDay(&opStartTime, 0);
5198 #endif /* FS_STATS_DETAILED */
5200 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5201 goto Bad_ExtendLock;
5203 code = SAFSS_ExtendLock(acall, Fid, Sync);
5206 code = CallPostamble(tcon, code, thost);
5208 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5210 #if FS_STATS_DETAILED
5211 TM_GetTimeOfDay(&opStopTime, 0);
5214 (opP->numSuccesses)++;
5215 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5216 fs_stats_AddTo((opP->sumTime), elapsedTime);
5217 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5218 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5219 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5221 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5222 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5226 #endif /* FS_STATS_DETAILED */
5228 osi_auditU(acall, ExtendLockEvent, code,
5229 AUD_ID, t_client ? t_client->ViceId : 0,
5230 AUD_FID, Fid, AUD_END);
5233 } /*SRXAFS_ExtendLock */
5237 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5238 * merged into it when possible.
5241 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5242 struct AFSVolSync *Sync)
5244 Vnode *targetptr = 0; /* vnode of input file */
5245 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5246 int errorCode = 0; /* error code */
5247 Volume *volptr = 0; /* pointer to the volume header */
5248 struct client *client = 0; /* pointer to client structure */
5249 afs_int32 rights, anyrights; /* rights for this and any user */
5250 struct client *t_client; /* tmp ptr to client data */
5251 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5252 struct rx_connection *tcon = rx_ConnectionOf(acall);
5254 /* Get ptr to client data for user Id for logging */
5255 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5256 logHostAddr.s_addr = rxr_HostOf(tcon);
5258 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5259 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5260 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5262 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5265 * Get the vnode and volume for the desired file along with the caller's
5269 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5270 &parentwhentargetnotdir, &client, WRITE_LOCK,
5271 &rights, &anyrights))) {
5272 goto Bad_ReleaseLock;
5275 /* set volume synchronization information */
5276 SetVolumeSync(Sync, volptr);
5278 /* Handle the actual lock release */
5279 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
5280 goto Bad_ReleaseLock;
5282 /* if no more locks left, a callback would be triggered here */
5283 if (targetptr->disk.lock.lockCount <= 0) {
5284 /* convert the write lock to a read lock before breaking callbacks */
5285 VVnodeWriteToRead(&errorCode, targetptr);
5286 assert(!errorCode || errorCode == VSALVAGE);
5287 BreakCallBack(client->host, Fid, 0);
5291 /* Put back file's vnode and volume */
5292 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5295 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5296 errorCode = 0; /* under our generous policy re RO vols */
5298 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5301 } /*SAFSS_ReleaseLock */
5305 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5306 struct AFSVolSync * Sync)
5308 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5309 } /*SRXAFS_OldReleaseLock */
5313 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5314 struct AFSVolSync * Sync)
5317 struct rx_connection *tcon;
5319 struct client *t_client = NULL; /* tmp ptr to client data */
5320 #if FS_STATS_DETAILED
5321 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5322 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5323 struct timeval elapsedTime; /* Transfer time */
5326 * Set our stats pointer, remember when the RPC operation started, and
5327 * tally the operation.
5329 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5333 TM_GetTimeOfDay(&opStartTime, 0);
5334 #endif /* FS_STATS_DETAILED */
5336 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5337 goto Bad_ReleaseLock;
5339 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5342 code = CallPostamble(tcon, code, thost);
5344 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5346 #if FS_STATS_DETAILED
5347 TM_GetTimeOfDay(&opStopTime, 0);
5350 (opP->numSuccesses)++;
5351 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5352 fs_stats_AddTo((opP->sumTime), elapsedTime);
5353 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5354 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5355 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5357 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5358 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5362 #endif /* FS_STATS_DETAILED */
5364 osi_auditU(acall, ReleaseLockEvent, code,
5365 AUD_ID, t_client ? t_client->ViceId : 0,
5366 AUD_FID, Fid, AUD_END);
5369 } /*SRXAFS_ReleaseLock */
5373 SetSystemStats(struct AFSStatistics *stats)
5375 /* Fix this sometime soon.. */
5376 /* Because hey, it's not like we have a network monitoring protocol... */
5377 struct timeval time;
5379 /* this works on all system types */
5380 TM_GetTimeOfDay(&time, 0);
5381 stats->CurrentTime = time.tv_sec;
5382 } /*SetSystemStats */
5385 SetAFSStats(struct AFSStatistics *stats)
5387 extern afs_int32 StartTime, CurrentConnections;
5391 stats->CurrentMsgNumber = 0;
5392 stats->OldestMsgNumber = 0;
5393 stats->StartTime = StartTime;
5394 stats->CurrentConnections = CurrentConnections;
5395 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5396 stats->TotalFetchs =
5397 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5398 AFSCallStats.FetchStatus;
5399 stats->FetchDatas = AFSCallStats.FetchData;
5400 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5401 seconds = AFSCallStats.AccumFetchTime / 1000;
5404 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5405 stats->TotalStores =
5406 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5407 AFSCallStats.StoreStatus;
5408 stats->StoreDatas = AFSCallStats.StoreData;
5409 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5410 seconds = AFSCallStats.AccumStoreTime / 1000;
5413 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5415 stats->ProcessSize = -1; /* TODO: */
5417 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5420 h_GetWorkStats((int *)&(stats->WorkStations),
5421 (int *)&(stats->ActiveWorkStations), (int *)0,
5422 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5426 /* Get disk related information from all AFS partitions. */
5429 SetVolumeStats(struct AFSStatistics *stats)
5431 struct DiskPartition *part;
5434 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5435 part = part->next) {
5436 stats->Disks[i].TotalBlocks = part->totalUsable;
5437 stats->Disks[i].BlocksAvailable = part->free;
5438 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5439 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5442 while (i < AFS_MSTATDISKS) {
5443 stats->Disks[i].TotalBlocks = -1;
5446 } /*SetVolumeStats */
5449 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5452 struct rx_connection *tcon = rx_ConnectionOf(acall);
5454 struct client *t_client = NULL; /* tmp ptr to client data */
5455 #if FS_STATS_DETAILED
5456 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5457 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5458 struct timeval elapsedTime; /* Transfer time */
5461 * Set our stats pointer, remember when the RPC operation started, and
5462 * tally the operation.
5464 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5468 TM_GetTimeOfDay(&opStartTime, 0);
5469 #endif /* FS_STATS_DETAILED */
5471 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5472 goto Bad_GetStatistics;
5474 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5476 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5478 memset(Statistics, 0, sizeof(*Statistics));
5479 SetAFSStats((struct AFSStatistics *)Statistics);
5480 SetVolumeStats((struct AFSStatistics *)Statistics);
5481 SetSystemStats((struct AFSStatistics *)Statistics);
5484 code = CallPostamble(tcon, code, thost);
5486 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5488 #if FS_STATS_DETAILED
5489 TM_GetTimeOfDay(&opStopTime, 0);
5492 (opP->numSuccesses)++;
5493 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5494 fs_stats_AddTo((opP->sumTime), elapsedTime);
5495 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5496 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5497 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5499 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5500 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5504 #endif /* FS_STATS_DETAILED */
5506 osi_auditU(acall, GetStatisticsEvent, code,
5507 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5509 } /*SRXAFS_GetStatistics */
5512 /*------------------------------------------------------------------------
5513 * EXPORTED SRXAFS_XStatsVersion
5516 * Routine called by the server-side RPC interface to implement
5517 * pulling out the xstat version number for the File Server.
5520 * a_versionP : Ptr to the version number variable to set.
5526 * Nothing interesting.
5530 *------------------------------------------------------------------------*/
5533 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5534 { /*SRXAFS_XStatsVersion */
5536 struct client *t_client = NULL; /* tmp ptr to client data */
5537 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5538 #if FS_STATS_DETAILED
5539 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5540 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5541 struct timeval elapsedTime; /* Transfer time */
5544 * Set our stats pointer, remember when the RPC operation started, and
5545 * tally the operation.
5547 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5551 TM_GetTimeOfDay(&opStartTime, 0);
5552 #endif /* FS_STATS_DETAILED */
5554 *a_versionP = AFS_XSTAT_VERSION;
5556 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5558 #if FS_STATS_DETAILED
5559 TM_GetTimeOfDay(&opStopTime, 0);
5560 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5561 fs_stats_AddTo((opP->sumTime), elapsedTime);
5562 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5563 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5564 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5566 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5567 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5570 (opP->numSuccesses)++;
5572 #endif /* FS_STATS_DETAILED */
5574 osi_auditU(a_call, XStatsVersionEvent, 0,
5575 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5577 } /*SRXAFS_XStatsVersion */
5580 /*------------------------------------------------------------------------
5581 * PRIVATE FillPerfValues
5584 * Routine called to fill a regular performance data structure.
5587 * a_perfP : Ptr to perf structure to fill
5593 * Various collections need this info, so the guts were put in
5594 * this separate routine.
5598 *------------------------------------------------------------------------*/
5601 FillPerfValues(struct afs_PerfStats *a_perfP)
5602 { /*FillPerfValues */
5604 int dir_Buffers; /*# buffers in use by dir package */
5605 int dir_Calls; /*# read calls in dir package */
5606 int dir_IOs; /*# I/O ops in dir package */
5609 * Vnode cache section.
5611 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5612 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5613 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5614 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5615 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5616 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5617 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5618 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5619 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5620 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5621 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5622 SplitInt64(VStats.hdr_gets, hi, lo);
5623 a_perfP->vcache_H_Gets = lo;
5624 SplitInt64(VStats.hdr_loads, hi, lo);
5625 a_perfP->vcache_H_Replacements = lo;
5628 * Directory section.
5630 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5631 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5632 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5633 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5638 a_perfP->rx_packetRequests = (afs_int32) rx_stats.packetRequests;
5639 a_perfP->rx_noPackets_RcvClass =
5640 (afs_int32) rx_stats.receivePktAllocFailures;
5641 a_perfP->rx_noPackets_SendClass =
5642 (afs_int32) rx_stats.sendPktAllocFailures;
5643 a_perfP->rx_noPackets_SpecialClass =
5644 (afs_int32) rx_stats.specialPktAllocFailures;
5645 a_perfP->rx_socketGreedy = (afs_int32) rx_stats.socketGreedy;
5646 a_perfP->rx_bogusPacketOnRead = (afs_int32) rx_stats.bogusPacketOnRead;
5647 a_perfP->rx_bogusHost = (afs_int32) rx_stats.bogusHost;
5648 a_perfP->rx_noPacketOnRead = (afs_int32) rx_stats.noPacketOnRead;
5649 a_perfP->rx_noPacketBuffersOnRead =
5650 (afs_int32) rx_stats.noPacketBuffersOnRead;
5651 a_perfP->rx_selects = (afs_int32) rx_stats.selects;
5652 a_perfP->rx_sendSelects = (afs_int32) rx_stats.sendSelects;
5653 a_perfP->rx_packetsRead_RcvClass =
5654 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
5655 a_perfP->rx_packetsRead_SendClass =
5656 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
5657 a_perfP->rx_packetsRead_SpecialClass =
5658 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
5659 a_perfP->rx_dataPacketsRead = (afs_int32) rx_stats.dataPacketsRead;
5660 a_perfP->rx_ackPacketsRead = (afs_int32) rx_stats.ackPacketsRead;
5661 a_perfP->rx_dupPacketsRead = (afs_int32) rx_stats.dupPacketsRead;
5662 a_perfP->rx_spuriousPacketsRead =
5663 (afs_int32) rx_stats.spuriousPacketsRead;
5664 a_perfP->rx_packetsSent_RcvClass =
5665 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
5666 a_perfP->rx_packetsSent_SendClass =
5667 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
5668 a_perfP->rx_packetsSent_SpecialClass =
5669 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
5670 a_perfP->rx_ackPacketsSent = (afs_int32) rx_stats.ackPacketsSent;
5671 a_perfP->rx_pingPacketsSent = (afs_int32) rx_stats.pingPacketsSent;
5672 a_perfP->rx_abortPacketsSent = (afs_int32) rx_stats.abortPacketsSent;
5673 a_perfP->rx_busyPacketsSent = (afs_int32) rx_stats.busyPacketsSent;
5674 a_perfP->rx_dataPacketsSent = (afs_int32) rx_stats.dataPacketsSent;
5675 a_perfP->rx_dataPacketsReSent = (afs_int32) rx_stats.dataPacketsReSent;
5676 a_perfP->rx_dataPacketsPushed = (afs_int32) rx_stats.dataPacketsPushed;
5677 a_perfP->rx_ignoreAckedPacket = (afs_int32) rx_stats.ignoreAckedPacket;
5678 a_perfP->rx_totalRtt_Sec = (afs_int32) rx_stats.totalRtt.sec;
5679 a_perfP->rx_totalRtt_Usec = (afs_int32) rx_stats.totalRtt.usec;
5680 a_perfP->rx_minRtt_Sec = (afs_int32) rx_stats.minRtt.sec;
5681 a_perfP->rx_minRtt_Usec = (afs_int32) rx_stats.minRtt.usec;
5682 a_perfP->rx_maxRtt_Sec = (afs_int32) rx_stats.maxRtt.sec;
5683 a_perfP->rx_maxRtt_Usec = (afs_int32) rx_stats.maxRtt.usec;
5684 a_perfP->rx_nRttSamples = (afs_int32) rx_stats.nRttSamples;
5685 a_perfP->rx_nServerConns = (afs_int32) rx_stats.nServerConns;
5686 a_perfP->rx_nClientConns = (afs_int32) rx_stats.nClientConns;
5687 a_perfP->rx_nPeerStructs = (afs_int32) rx_stats.nPeerStructs;
5688 a_perfP->rx_nCallStructs = (afs_int32) rx_stats.nCallStructs;
5689 a_perfP->rx_nFreeCallStructs = (afs_int32) rx_stats.nFreeCallStructs;
5691 a_perfP->host_NumHostEntries = HTs;
5692 a_perfP->host_HostBlocks = HTBlocks;
5693 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5694 &(a_perfP->host_HostsInSameNetOrSubnet),
5695 &(a_perfP->host_HostsInDiffSubnet),
5696 &(a_perfP->host_HostsInDiffNetwork));
5697 a_perfP->host_NumClients = CEs;
5698 a_perfP->host_ClientBlocks = CEBlocks;
5700 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5701 a_perfP->rx_nBusies = (afs_int32) rx_stats.nBusies;
5702 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5703 } /*FillPerfValues */
5706 /*------------------------------------------------------------------------
5707 * EXPORTED SRXAFS_GetXStats
5710 * Routine called by the server-side callback RPC interface to
5711 * implement getting the given data collection from the extended
5712 * File Server statistics.
5715 * a_call : Ptr to Rx call on which this request came in.
5716 * a_clientVersionNum : Client version number.
5717 * a_opCode : Desired operation.
5718 * a_serverVersionNumP : Ptr to version number to set.
5719 * a_timeP : Ptr to time value (seconds) to set.
5720 * a_dataP : Ptr to variable array structure to return
5727 * Nothing interesting.
5731 *------------------------------------------------------------------------*/
5734 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5735 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5736 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5737 { /*SRXAFS_GetXStats */
5739 register int code; /*Return value */
5740 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5741 afs_int32 dataBytes; /*Bytes in data buffer */
5742 #if FS_STATS_DETAILED
5743 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5744 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5745 struct timeval elapsedTime; /* Transfer time */
5748 * Set our stats pointer, remember when the RPC operation started, and
5749 * tally the operation.
5751 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
5755 TM_GetTimeOfDay(&opStartTime, 0);
5756 #endif /* FS_STATS_DETAILED */
5759 * Record the time of day and the server version number.
5761 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5762 *a_timeP = FT_ApproxTime();
5765 * Stuff the appropriate data in there (assume victory)
5770 ("Received GetXStats call for collection %d\n",
5771 a_collectionNumber));
5775 * We're not keeping stats, so just return successfully with
5778 a_dataP->AFS_CollData_len = 0;
5779 a_dataP->AFS_CollData_val = NULL;
5782 switch (a_collectionNumber) {
5783 case AFS_XSTATSCOLL_CALL_INFO:
5785 * Pass back all the call-count-related data.
5787 * >>> We are forced to allocate a separate area in which to
5788 * >>> put this stuff in by the RPC stub generator, since it
5789 * >>> will be freed at the tail end of the server stub code.
5793 * I don't think call-level stats are being collected yet
5794 * for the File Server.
5796 dataBytes = sizeof(struct afs_Stats);
5797 dataBuffP = (afs_int32 *) malloc(dataBytes);
5798 memcpy(dataBuffP, &afs_cmstats, dataBytes);
5799 a_dataP->AFS_CollData_len = dataBytes >> 2;
5800 a_dataP->AFS_CollData_val = dataBuffP;
5802 a_dataP->AFS_CollData_len = 0;
5803 a_dataP->AFS_CollData_val = NULL;
5807 case AFS_XSTATSCOLL_PERF_INFO:
5809 * Pass back all the regular performance-related data.
5811 * >>> We are forced to allocate a separate area in which to
5812 * >>> put this stuff in by the RPC stub generator, since it
5813 * >>> will be freed at the tail end of the server stub code.
5816 afs_perfstats.numPerfCalls++;
5817 FillPerfValues(&afs_perfstats);
5820 * Don't overwrite the spares at the end.
5823 dataBytes = sizeof(struct afs_PerfStats);
5824 dataBuffP = (afs_int32 *) malloc(dataBytes);
5825 memcpy(dataBuffP, &afs_perfstats, dataBytes);
5826 a_dataP->AFS_CollData_len = dataBytes >> 2;
5827 a_dataP->AFS_CollData_val = dataBuffP;
5830 case AFS_XSTATSCOLL_FULL_PERF_INFO:
5832 * Pass back the full collection of performance-related data.
5833 * We have to stuff the basic, overall numbers in, but the
5834 * detailed numbers are kept in the structure already.
5836 * >>> We are forced to allocate a separate area in which to
5837 * >>> put this stuff in by the RPC stub generator, since it
5838 * >>> will be freed at the tail end of the server stub code.
5841 afs_perfstats.numPerfCalls++;
5842 #if FS_STATS_DETAILED
5843 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
5844 FillPerfValues(&afs_FullPerfStats.overall);
5847 * Don't overwrite the spares at the end.
5850 dataBytes = sizeof(struct fs_stats_FullPerfStats);
5851 dataBuffP = (afs_int32 *) malloc(dataBytes);
5852 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
5853 a_dataP->AFS_CollData_len = dataBytes >> 2;
5854 a_dataP->AFS_CollData_val = dataBuffP;
5858 case AFS_XSTATSCOLL_CBSTATS:
5859 afs_perfstats.numPerfCalls++;
5861 dataBytes = sizeof(struct cbcounters);
5862 dataBuffP = (afs_int32 *) malloc(dataBytes);
5864 extern struct cbcounters cbstuff;
5865 dataBuffP[0]=cbstuff.DeleteFiles;
5866 dataBuffP[1]=cbstuff.DeleteCallBacks;
5867 dataBuffP[2]=cbstuff.BreakCallBacks;
5868 dataBuffP[3]=cbstuff.AddCallBacks;
5869 dataBuffP[4]=cbstuff.GotSomeSpaces;
5870 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
5871 dataBuffP[6]=cbstuff.nFEs;
5872 dataBuffP[7]=cbstuff.nCBs;
5873 dataBuffP[8]=cbstuff.nblks;
5874 dataBuffP[9]=cbstuff.CBsTimedOut;
5875 dataBuffP[10]=cbstuff.nbreakers;
5876 dataBuffP[11]=cbstuff.GSS1;
5877 dataBuffP[12]=cbstuff.GSS2;
5878 dataBuffP[13]=cbstuff.GSS3;
5879 dataBuffP[14]=cbstuff.GSS4;
5880 dataBuffP[15]=cbstuff.GSS5;
5883 a_dataP->AFS_CollData_len = dataBytes >> 2;
5884 a_dataP->AFS_CollData_val = dataBuffP;
5890 * Illegal collection number.
5892 a_dataP->AFS_CollData_len = 0;
5893 a_dataP->AFS_CollData_val = NULL;
5895 } /*Switch on collection number */
5897 #if FS_STATS_DETAILED
5898 TM_GetTimeOfDay(&opStopTime, 0);
5901 (opP->numSuccesses)++;
5902 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5903 fs_stats_AddTo((opP->sumTime), elapsedTime);
5904 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5905 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5906 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5908 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5909 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5913 #endif /* FS_STATS_DETAILED */
5917 } /*SRXAFS_GetXStats */
5921 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
5922 struct AFSCBs *CallBackArray)
5924 afs_int32 errorCode = 0;
5926 struct client *client = 0;
5927 struct rx_connection *tcon;
5929 #if FS_STATS_DETAILED
5930 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5931 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5932 struct timeval elapsedTime; /* Transfer time */
5935 * Set our stats pointer, remember when the RPC operation started, and
5936 * tally the operation.
5939 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
5943 TM_GetTimeOfDay(&opStartTime, 0);
5944 #endif /* FS_STATS_DETAILED */
5948 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
5949 FidArray->AFSCBFids_len));
5952 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
5954 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5955 goto Bad_GiveUpCallBacks;
5957 if (!FidArray && !CallBackArray) {
5959 ("SAFS_GiveUpAllCallBacks: host=%x\n",
5960 (tcon->peer ? tcon->peer->host : 0)));
5961 errorCode = GetClient(tcon, &client);
5963 DeleteAllCallBacks_r(client->host, 1);
5967 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
5969 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
5970 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
5971 (tcon->peer ? tcon->peer->host : 0)));
5973 goto Bad_GiveUpCallBacks;
5976 errorCode = GetClient(tcon, &client);
5978 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
5979 register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
5980 DeleteCallBack(client->host, fid);
5986 Bad_GiveUpCallBacks:
5987 errorCode = CallPostamble(tcon, errorCode, thost);
5989 #if FS_STATS_DETAILED
5990 TM_GetTimeOfDay(&opStopTime, 0);
5991 if (errorCode == 0) {
5993 (opP->numSuccesses)++;
5994 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5995 fs_stats_AddTo((opP->sumTime), elapsedTime);
5996 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5997 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5998 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6000 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6001 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6005 #endif /* FS_STATS_DETAILED */
6008 } /*common_GiveUpCallBacks */
6012 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
6013 struct AFSCBs * CallBackArray)
6015 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
6016 } /*SRXAFS_GiveUpCallBacks */
6019 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
6021 return common_GiveUpCallBacks(acall, 0, 0);
6022 } /*SRXAFS_GiveUpAllCallBacks */
6026 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
6027 struct AFSVolumeInfo * avolinfo)
6029 return (VNOVOL); /* XXX Obsolete routine XXX */
6031 } /*SRXAFS_NGetVolumeInfo */
6035 * Dummy routine. Should never be called (the cache manager should only
6036 * invoke this interface when communicating with a AFS/DFS Protocol
6040 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
6041 char *afs_name_p, struct AFSFid * afs_fid_p,
6042 struct AFSFetchStatus * afs_status_p,
6043 struct AFSFetchStatus * afs_dir_status_p,
6044 struct AFSCallBack * afs_callback_p,
6045 struct AFSVolSync * afs_sync_p)
6052 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
6055 struct rx_connection *tcon;
6057 afs_int32 *dataBuffP;
6058 afs_int32 dataBytes;
6061 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
6062 afs_FullPerfStats.overall.fs_nGetCaps++;
6064 ViceLog(2, ("SAFS_GetCapabilties\n"));
6066 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6069 dataBytes = 1 * sizeof(afs_int32);
6070 dataBuffP = (afs_int32 *) malloc(dataBytes);
6071 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
6072 #if defined(AFS_64BIT_ENV) && defined(AFS_LARGEFILE_ENV)
6073 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
6076 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
6078 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
6079 capabilities->Capabilities_val = dataBuffP;
6082 code = CallPostamble(tcon, code, thost);
6089 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
6090 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
6094 afs_int32 nids, naddrs;
6095 afs_int32 *vd, *addr;
6096 int errorCode = 0; /* return code to caller */
6097 struct client *client = 0;
6098 struct rx_connection *tcon = rx_ConnectionOf(acall);
6100 ViceLog(1, ("SRXAFS_FlushCPS\n"));
6102 AFSCallStats.TotalCalls++;
6104 nids = vids->ViceIds_len; /* # of users in here */
6105 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
6106 if (nids < 0 || naddrs < 0) {
6111 vd = vids->ViceIds_val;
6112 for (i = 0; i < nids; i++, vd++) {
6115 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
6119 client->prfail = 2; /* Means re-eval client's cps */
6122 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6125 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6126 free(client->CPS.prlist_val);
6127 client->CPS.prlist_val = NULL;
6128 client->CPS.prlist_len = 0;
6130 ReleaseWriteLock(&client->lock);
6134 addr = addrs->IPAddrs_val;
6135 for (i = 0; i < naddrs; i++, addr++) {
6137 h_flushhostcps(*addr, htons(7001));
6141 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6143 } /*SRXAFS_FlushCPS */
6145 /* worthless hack to let CS keep running ancient software */
6147 afs_vtoi(register char *aname)
6149 register afs_int32 temp;
6153 while ((tc = *aname++)) {
6154 if (tc > '9' || tc < '0')
6155 return 0; /* invalid name */
6163 * may get name or #, but must handle all weird cases (recognize readonly
6164 * or backup volumes by name or #
6167 CopyVolumeEntry(char *aname, register struct vldbentry *ave,
6168 register struct VolumeInfo *av)
6170 register int i, j, vol;
6171 afs_int32 mask, whichType;
6172 afs_uint32 *serverHost, *typePtr;
6174 /* figure out what type we want if by name */
6176 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6177 whichType = BACKVOL;
6178 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6183 vol = afs_vtoi(aname);
6185 vol = ave->volumeId[whichType];
6188 * Now vol has volume # we're interested in. Next, figure out the type
6189 * of the volume by looking finding it in the vldb entry
6191 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6194 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6197 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6198 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6199 whichType = BACKVOL;
6201 return EINVAL; /* error: can't find volume in vldb entry */
6203 typePtr = &av->Type0;
6204 serverHost = &av->Server0;
6206 av->Type = whichType;
6207 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6208 if (ave->flags & VLF_RWEXISTS)
6209 typePtr[RWVOL] = ave->volumeId[RWVOL];
6210 if (ave->flags & VLF_ROEXISTS)
6211 typePtr[ROVOL] = ave->volumeId[ROVOL];
6212 if (ave->flags & VLF_BACKEXISTS)
6213 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6215 for (i = 0, j = 0; i < ave->nServers; i++) {
6216 if ((ave->serverFlags[i] & mask) == 0)
6217 continue; /* wrong volume */
6218 serverHost[j] = ave->serverNumber[i];
6221 av->ServerCount = j;
6223 serverHost[j++] = 0; /* bogus 8, but compat only now */
6228 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6230 static struct rx_connection *vlConn = 0;
6231 static int down = 0;
6232 static afs_int32 lastDownTime = 0;
6233 struct vldbentry tve;
6234 struct rx_securityClass *vlSec;
6235 register afs_int32 code;
6238 vlSec = rxnull_NewClientSecurityObject();
6240 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6241 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6243 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6244 return 1; /* failure */
6247 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6249 down = 0; /* call worked */
6252 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6258 /* otherwise convert to old format vldb entry */
6259 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6269 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6270 struct VolumeInfo * avolinfo)
6273 struct rx_connection *tcon;
6275 #if FS_STATS_DETAILED
6276 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6277 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6278 struct timeval elapsedTime; /* Transfer time */
6281 * Set our stats pointer, remember when the RPC operation started, and
6282 * tally the operation.
6284 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6288 TM_GetTimeOfDay(&opStartTime, 0);
6289 #endif /* FS_STATS_DETAILED */
6290 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6291 goto Bad_GetVolumeInfo;
6294 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6296 code = TryLocalVLServer(avolid, avolinfo);
6298 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6299 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6300 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6301 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6304 code = CallPostamble(tcon, code, thost);
6306 #if FS_STATS_DETAILED
6307 TM_GetTimeOfDay(&opStopTime, 0);
6310 (opP->numSuccesses)++;
6311 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6312 fs_stats_AddTo((opP->sumTime), elapsedTime);
6313 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6314 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6315 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6317 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6318 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6322 #endif /* FS_STATS_DETAILED */
6326 } /*SRXAFS_GetVolumeInfo */
6330 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6331 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6332 char **OfflineMsg, char **Motd)
6334 Vnode *targetptr = 0; /* vnode of the new file */
6335 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6336 int errorCode = 0; /* error code */
6337 Volume *volptr = 0; /* pointer to the volume header */
6338 struct client *client = 0; /* pointer to client entry */
6339 afs_int32 rights, anyrights; /* rights for this and any user */
6341 struct rx_connection *tcon;
6343 struct client *t_client = NULL; /* tmp ptr to client data */
6344 #if FS_STATS_DETAILED
6345 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6346 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6347 struct timeval elapsedTime; /* Transfer time */
6350 * Set our stats pointer, remember when the RPC operation started, and
6351 * tally the operation.
6354 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6358 TM_GetTimeOfDay(&opStartTime, 0);
6359 #endif /* FS_STATS_DETAILED */
6361 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6362 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6363 goto Bad_GetVolumeStatus;
6366 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6370 goto Bad_GetVolumeStatus;
6372 dummyFid.Volume = avolid, dummyFid.Vnode =
6373 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6376 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6377 &parentwhentargetnotdir, &client, READ_LOCK,
6378 &rights, &anyrights)))
6379 goto Bad_GetVolumeStatus;
6381 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6383 goto Bad_GetVolumeStatus;
6385 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6387 Bad_GetVolumeStatus:
6388 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6390 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6391 /* next is to guarantee out strings exist for stub */
6393 *Name = (char *)malloc(1);
6397 *Motd = (char *)malloc(1);
6400 if (*OfflineMsg == 0) {
6401 *OfflineMsg = (char *)malloc(1);
6404 errorCode = CallPostamble(tcon, errorCode, thost);
6406 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6408 #if FS_STATS_DETAILED
6409 TM_GetTimeOfDay(&opStopTime, 0);
6410 if (errorCode == 0) {
6412 (opP->numSuccesses)++;
6413 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6414 fs_stats_AddTo((opP->sumTime), elapsedTime);
6415 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6416 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6417 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6419 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6420 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6424 #endif /* FS_STATS_DETAILED */
6426 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
6427 AUD_ID, t_client ? t_client->ViceId : 0,
6428 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
6431 } /*SRXAFS_GetVolumeStatus */
6435 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6436 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6437 char *OfflineMsg, char *Motd)
6439 Vnode *targetptr = 0; /* vnode of the new file */
6440 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6441 int errorCode = 0; /* error code */
6442 Volume *volptr = 0; /* pointer to the volume header */
6443 struct client *client = 0; /* pointer to client entry */
6444 afs_int32 rights, anyrights; /* rights for this and any user */
6446 struct rx_connection *tcon = rx_ConnectionOf(acall);
6448 struct client *t_client = NULL; /* tmp ptr to client data */
6449 #if FS_STATS_DETAILED
6450 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6451 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6452 struct timeval elapsedTime; /* Transfer time */
6455 * Set our stats pointer, remember when the RPC operation started, and
6456 * tally the operation.
6459 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6463 TM_GetTimeOfDay(&opStartTime, 0);
6464 #endif /* FS_STATS_DETAILED */
6466 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6467 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6468 goto Bad_SetVolumeStatus;
6471 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6475 goto Bad_SetVolumeStatus;
6477 dummyFid.Volume = avolid, dummyFid.Vnode =
6478 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6481 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6482 &parentwhentargetnotdir, &client, READ_LOCK,
6483 &rights, &anyrights)))
6484 goto Bad_SetVolumeStatus;
6486 if (readonlyServer) {
6487 errorCode = VREADONLY;
6488 goto Bad_SetVolumeStatus;
6490 if (VanillaUser(client)) {
6492 goto Bad_SetVolumeStatus;
6496 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6498 Bad_SetVolumeStatus:
6499 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6501 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6502 errorCode = CallPostamble(tcon, errorCode, thost);
6504 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6506 #if FS_STATS_DETAILED
6507 TM_GetTimeOfDay(&opStopTime, 0);
6508 if (errorCode == 0) {
6510 (opP->numSuccesses)++;
6511 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6512 fs_stats_AddTo((opP->sumTime), elapsedTime);
6513 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6514 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6515 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6517 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6518 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6522 #endif /* FS_STATS_DETAILED */
6524 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6525 AUD_ID, t_client ? t_client->ViceId : 0,
6526 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6528 } /*SRXAFS_SetVolumeStatus */
6530 #define DEFAULTVOLUME "root.afs"
6533 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6539 struct rx_connection *tcon;
6543 #if FS_STATS_DETAILED
6544 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6545 struct timeval opStartTime; /* Start time for RPC op */
6547 struct timeval opStopTime;
6548 struct timeval elapsedTime; /* Transfer time */
6552 * Set our stats pointer, remember when the RPC operation started, and
6553 * tally the operation.
6555 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6559 TM_GetTimeOfDay(&opStartTime, 0);
6560 #endif /* FS_STATS_DETAILED */
6562 return FSERR_EOPNOTSUPP;
6565 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
6566 goto Bad_GetRootVolume;
6568 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6571 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6573 strcpy(temp, DEFAULTVOLUME);
6575 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6576 lockf(fd, F_LOCK, 0);
6580 len = read(fd, temp, 256);
6581 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6582 lockf(fd, F_ULOCK, 0);
6587 if (temp[len - 1] == '\n')
6591 *VolumeName = temp; /* freed by rx server-side stub */
6594 errorCode = CallPostamble(tcon, errorCode, thost);
6596 #if FS_STATS_DETAILED
6597 TM_GetTimeOfDay(&opStopTime, 0);
6598 if (errorCode == 0) {
6600 (opP->numSuccesses)++;
6601 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6602 fs_stats_AddTo((opP->sumTime), elapsedTime);
6603 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6604 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6605 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6607 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6608 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6612 #endif /* FS_STATS_DETAILED */
6617 } /*SRXAFS_GetRootVolume */
6620 /* still works because a struct CBS is the same as a struct AFSOpaque */
6622 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6623 struct AFSOpaque * Token)
6626 struct rx_connection *tcon;
6628 #if FS_STATS_DETAILED
6629 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6630 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6631 struct timeval elapsedTime; /* Transfer time */
6634 * Set our stats pointer, remember when the RPC operation started, and
6635 * tally the operation.
6637 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6641 TM_GetTimeOfDay(&opStartTime, 0);
6642 #endif /* FS_STATS_DETAILED */
6644 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6645 goto Bad_CheckToken;
6647 code = FSERR_ECONNREFUSED;
6650 code = CallPostamble(tcon, code, thost);
6652 #if FS_STATS_DETAILED
6653 TM_GetTimeOfDay(&opStopTime, 0);
6656 (opP->numSuccesses)++;
6657 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6658 fs_stats_AddTo((opP->sumTime), elapsedTime);
6659 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6660 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6661 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6663 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6664 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6668 #endif /* FS_STATS_DETAILED */
6672 } /*SRXAFS_CheckToken */
6675 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6676 afs_uint32 * USeconds)
6679 struct rx_connection *tcon;
6682 #if FS_STATS_DETAILED
6683 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6684 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6685 struct timeval elapsedTime; /* Transfer time */
6688 * Set our stats pointer, remember when the RPC operation started, and
6689 * tally the operation.
6691 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
6695 TM_GetTimeOfDay(&opStartTime, 0);
6696 #endif /* FS_STATS_DETAILED */
6698 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6702 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6704 TM_GetTimeOfDay(&tpl, 0);
6705 *Seconds = tpl.tv_sec;
6706 *USeconds = tpl.tv_usec;
6708 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6711 code = CallPostamble(tcon, code, thost);
6713 #if FS_STATS_DETAILED
6714 TM_GetTimeOfDay(&opStopTime, 0);
6715 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6718 (opP->numSuccesses)++;
6719 fs_stats_AddTo((opP->sumTime), elapsedTime);
6720 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6721 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6722 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6724 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6725 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6729 #endif /* FS_STATS_DETAILED */
6733 } /*SRXAFS_GetTime */
6740 * Implement a client's data fetch using Rx.
6743 * volptr : Ptr to the given volume's info.
6744 * targetptr : Pointer to the vnode involved.
6745 * Call : Ptr to the Rx call involved.
6746 * Pos : Offset within the file.
6747 * Len : Length in bytes to read; this value is bogus!
6748 * if FS_STATS_DETAILED
6749 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6751 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6757 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
6758 register struct rx_call * Call, afs_sfsize_t Pos,
6759 afs_sfsize_t Len, afs_int32 Int64Mode,
6760 #if FS_STATS_DETAILED
6761 afs_sfsize_t * a_bytesToFetchP,
6762 afs_sfsize_t * a_bytesFetchedP
6763 #endif /* FS_STATS_DETAILED */
6766 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6767 int errorCode = 0; /* Returned error code to caller */
6771 register char *tbuffer;
6772 #else /* AFS_NT40_ENV */
6773 struct iovec tiov[RX_MAXIOVECS];
6775 #endif /* AFS_NT40_ENV */
6779 #if FS_STATS_DETAILED
6781 * Initialize the byte count arguments.
6783 (*a_bytesToFetchP) = 0;
6784 (*a_bytesFetchedP) = 0;
6785 #endif /* FS_STATS_DETAILED */
6789 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
6790 (afs_uintmax_t) Len));
6792 if (!VN_GET_INO(targetptr)) {
6793 afs_int32 zero = htonl(0);
6795 * This is used for newly created files; we simply send 0 bytes
6796 * back to make the cache manager happy...
6799 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6800 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6803 TM_GetTimeOfDay(&StartTime, 0);
6804 ihP = targetptr->handle;
6807 VTakeOffline(volptr);
6810 optSize = sendBufSize;
6811 tlen = FDH_SIZE(fdP);
6813 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
6816 VTakeOffline(volptr);
6823 if (Pos + Len > tlen)
6824 Len = tlen - Pos; /* get length we should send */
6825 (void)FDH_SEEK(fdP, Pos, 0);
6827 afs_int32 high, low;
6828 SplitOffsetOrSize(Len, high, low);
6829 assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
6832 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
6835 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
6837 #if FS_STATS_DETAILED
6838 (*a_bytesToFetchP) = Len;
6839 #endif /* FS_STATS_DETAILED */
6841 tbuffer = AllocSendBuffer();
6842 #endif /* AFS_NT40_ENV */
6850 errorCode = FDH_READ(fdP, tbuffer, wlen);
6851 if (errorCode != wlen) {
6853 FreeSendBuffer((struct afs_buffer *)tbuffer);
6854 VTakeOffline(volptr);
6857 errorCode = rx_Write(Call, tbuffer, wlen);
6858 #else /* AFS_NT40_ENV */
6859 errorCode = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
6860 if (errorCode <= 0) {
6865 errorCode = FDH_READV(fdP, tiov, tnio);
6866 if (errorCode != wlen) {
6868 VTakeOffline(volptr);
6871 errorCode = rx_Writev(Call, tiov, tnio, wlen);
6872 #endif /* AFS_NT40_ENV */
6873 #if FS_STATS_DETAILED
6875 * Bump the number of bytes actually sent by the number from this
6878 (*a_bytesFetchedP) += errorCode;
6879 #endif /* FS_STATS_DETAILED */
6880 if (errorCode != wlen) {
6883 FreeSendBuffer((struct afs_buffer *)tbuffer);
6884 #endif /* AFS_NT40_ENV */
6890 FreeSendBuffer((struct afs_buffer *)tbuffer);
6891 #endif /* AFS_NT40_ENV */
6893 TM_GetTimeOfDay(&StopTime, 0);
6895 /* Adjust all Fetch Data related stats */
6897 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
6898 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
6899 AFSCallStats.AccumFetchTime +=
6900 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
6901 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
6903 afs_fsize_t targLen;
6904 VN_GET_LEN(targLen, targetptr);
6905 AFSCallStats.TotalFetchedBytes += targLen;
6906 AFSCallStats.FetchSize1++;
6907 if (targLen < SIZE2)
6908 AFSCallStats.FetchSize2++;
6909 else if (targLen < SIZE3)
6910 AFSCallStats.FetchSize3++;
6911 else if (targLen < SIZE4)
6912 AFSCallStats.FetchSize4++;
6914 AFSCallStats.FetchSize5++;
6919 } /*FetchData_RXStyle */
6922 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
6923 afs_sfsize_t * size)
6925 #ifdef AFS_NAMEI_ENV
6927 lhp = IH_OPEN(V_linkHandle(vp));
6931 *lc = nt_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
6933 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
6938 *size = OS_SIZE(fdP->fd_fd);
6939 return (*size == -1) ? -1 : 0;
6941 struct afs_stat status;
6943 if (afs_fstat(fdP->fd_fd, &status) < 0) {
6947 *lc = GetLinkCount(vp, &status);
6948 *size = status.st_size;
6957 * Implement a client's data store using Rx.
6960 * volptr : Ptr to the given volume's info.
6961 * targetptr : Pointer to the vnode involved.
6962 * Call : Ptr to the Rx call involved.
6963 * Pos : Offset within the file.
6964 * Len : Length in bytes to store; this value is bogus!
6965 * if FS_STATS_DETAILED
6966 * a_bytesToStoreP : Set to the number of bytes to be stored to
6968 * a_bytesStoredP : Set to the actual number of bytes stored to
6973 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
6974 struct client * client, register struct rx_call * Call,
6975 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
6977 #if FS_STATS_DETAILED
6978 afs_sfsize_t * a_bytesToStoreP,
6979 afs_sfsize_t * a_bytesStoredP
6980 #endif /* FS_STATS_DETAILED */
6983 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
6984 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
6985 int errorCode = 0; /* Returned error code to caller */
6987 register char *tbuffer; /* data copying buffer */
6988 #else /* AFS_NT40_ENV */
6989 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
6990 int tnio; /* temp for iovec size */
6991 #endif /* AFS_NT40_ENV */
6992 afs_sfsize_t tlen; /* temp for xfr length */
6993 Inode tinode; /* inode for I/O */
6994 afs_int32 optSize; /* optimal transfer size */
6995 afs_sfsize_t DataLength; /* size of inode */
6996 afs_sfsize_t TruncatedLength; /* size after ftruncate */
6997 afs_fsize_t NewLength; /* size after this store completes */
6998 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
6999 int linkCount; /* link count on inode */
7001 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
7003 #if FS_STATS_DETAILED
7005 * Initialize the byte count arguments.
7007 (*a_bytesToStoreP) = 0;
7008 (*a_bytesStoredP) = 0;
7009 #endif /* FS_STATS_DETAILED */
7012 * We break the callbacks here so that the following signal will not
7015 BreakCallBack(client->host, Fid, 0);
7017 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
7018 /* the inode should have been created in Alloc_NewVnode */
7019 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
7021 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
7022 Fid->Volume, Fid->Vnode, Fid->Unique,
7023 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
7024 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
7025 return ENOENT; /* is this proper error code? */
7028 * See if the file has several links (from other volumes). If it
7029 * does, then we have to make a copy before changing it to avoid
7030 *changing read-only clones of this dude
7033 ("StoreData_RXStyle : Opening inode %s\n",
7034 PrintInode(NULL, VN_GET_INO(targetptr))));
7035 fdP = IH_OPEN(targetptr->handle);
7038 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
7040 VTakeOffline(volptr);
7044 if (linkCount != 1) {
7047 ("StoreData_RXStyle : inode %s has more than onelink\n",
7048 PrintInode(NULL, VN_GET_INO(targetptr))));
7049 /* other volumes share this data, better copy it first */
7051 /* Adjust the disk block count by the creation of the new inode.
7052 * We call the special VDiskUsage so we don't adjust the volume's
7053 * quota since we don't want to penalyze the user for afs's internal
7054 * mechanisms (i.e. copy on write overhead.) Also the right size
7055 * of the disk will be recorded...
7058 VN_GET_LEN(size, targetptr);
7059 volptr->partition->flags &= ~PART_DONTUPDATE;
7060 VSetPartitionDiskUsage(volptr->partition);
7061 volptr->partition->flags |= PART_DONTUPDATE;
7062 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
7063 volptr->partition->flags &= ~PART_DONTUPDATE;
7067 ViceLog(25, ("StoreData : calling CopyOnWrite on target dir\n"));
7068 if ((errorCode = CopyOnWrite(targetptr, volptr))) {
7069 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
7070 volptr->partition->flags &= ~PART_DONTUPDATE;
7073 volptr->partition->flags &= ~PART_DONTUPDATE;
7074 VSetPartitionDiskUsage(volptr->partition);
7075 fdP = IH_OPEN(targetptr->handle);
7078 ("StoreData : Reopen after CopyOnWrite failed\n"));
7082 tinode = VN_GET_INO(targetptr);
7084 assert(VALID_INO(tinode));
7086 /* compute new file length */
7087 NewLength = DataLength;
7088 if (FileLength < NewLength)
7089 /* simulate truncate */
7090 NewLength = FileLength;
7091 TruncatedLength = NewLength; /* remember length after possible ftruncate */
7092 if (Pos + Length > NewLength)
7093 NewLength = Pos + Length; /* and write */
7095 /* adjust the disk block count by the difference in the files */
7097 afs_fsize_t targSize;
7098 VN_GET_LEN(targSize, targetptr);
7099 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
7102 AdjustDiskUsage(volptr, adjustSize,
7103 adjustSize - SpareComp(volptr)))) {
7108 /* can signal cache manager to proceed from close now */
7109 /* this bit means that the locks are set and protections are OK */
7110 rx_SetLocalStatus(Call, 1);
7112 TM_GetTimeOfDay(&StartTime, 0);
7114 optSize = sendBufSize;
7116 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
7117 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
7118 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
7120 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
7121 if (FileLength < DataLength)
7122 FDH_TRUNC(fdP, FileLength);
7124 FDH_SEEK(fdP, Pos, 0);
7125 bytesTransfered = 0;
7127 tbuffer = AllocSendBuffer();
7128 #endif /* AFS_NT40_ENV */
7129 /* if length == 0, the loop below isn't going to do anything, including
7130 * extend the length of the inode, which it must do, since the file system
7131 * assumes that the inode length == vnode's file length. So, we extend
7132 * the file length manually if need be. Note that if file is bigger than
7133 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7134 * do what we're going to do below.
7136 if (Length == 0 && Pos > TruncatedLength) {
7137 /* Set the file's length; we've already done an lseek to the right
7140 errorCode = FDH_WRITE(fdP, &tlen, 1);
7143 errorCode = FDH_TRUNC(fdP, Pos);
7145 /* have some data to copy */
7146 #if FS_STATS_DETAILED
7147 (*a_bytesToStoreP) = Length;
7148 #endif /* FS_STATS_DETAILED */
7151 if (bytesTransfered >= Length) {
7155 tlen = Length - bytesTransfered; /* how much more to do */
7157 rlen = optSize; /* bound by buffer size */
7161 errorCode = rx_Read(Call, tbuffer, rlen);
7162 #else /* AFS_NT40_ENV */
7163 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7164 #endif /* AFS_NT40_ENV */
7165 #if FS_STATS_DETAILED
7166 (*a_bytesStoredP) += errorCode;
7167 #endif /* FS_STATS_DETAILED */
7168 if (errorCode <= 0) {
7174 errorCode = FDH_WRITE(fdP, tbuffer, rlen);
7175 #else /* AFS_NT40_ENV */
7176 errorCode = FDH_WRITEV(fdP, tiov, tnio);
7177 #endif /* AFS_NT40_ENV */
7178 if (errorCode != rlen) {
7179 errorCode = VDISKFULL;
7182 bytesTransfered += rlen;
7187 FreeSendBuffer((struct afs_buffer *)tbuffer);
7188 #endif /* AFS_NT40_ENV */
7193 afs_fsize_t nfSize = (afs_fsize_t) FDH_SIZE(fdP);
7194 /* something went wrong: adjust size and return */
7195 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7196 /* changed_newTime is tested in StoreData to detemine if we
7197 * need to update the target vnode.
7199 targetptr->changed_newTime = 1;
7201 /* set disk usage to be correct */
7202 VAdjustDiskUsage(&errorCode, volptr,
7203 (afs_sfsize_t) (nBlocks(nfSize) -
7204 nBlocks(NewLength)), 0);
7209 TM_GetTimeOfDay(&StopTime, 0);
7211 VN_SET_LEN(targetptr, NewLength);
7213 /* Update all StoreData related stats */
7215 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7216 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7217 AFSCallStats.StoreSize1++; /* Piggybacked data */
7219 afs_fsize_t targLen;
7220 VN_GET_LEN(targLen, targetptr);
7221 if (targLen < SIZE2)
7222 AFSCallStats.StoreSize2++;
7223 else if (targLen < SIZE3)
7224 AFSCallStats.StoreSize3++;
7225 else if (targLen < SIZE4)
7226 AFSCallStats.StoreSize4++;
7228 AFSCallStats.StoreSize5++;
7233 } /*StoreData_RXStyle */
7235 static int sys2et[512];
7238 init_sys_error_to_et(void)
7240 memset(&sys2et, 0, sizeof(sys2et));
7241 sys2et[EPERM] = UAEPERM;
7242 sys2et[ENOENT] = UAENOENT;
7243 sys2et[ESRCH] = UAESRCH;
7244 sys2et[EINTR] = UAEINTR;
7245 sys2et[EIO] = UAEIO;
7246 sys2et[ENXIO] = UAENXIO;
7247 sys2et[E2BIG] = UAE2BIG;
7248 sys2et[ENOEXEC] = UAENOEXEC;
7249 sys2et[EBADF] = UAEBADF;
7250 sys2et[ECHILD] = UAECHILD;
7251 sys2et[EAGAIN] = UAEAGAIN;
7252 sys2et[ENOMEM] = UAENOMEM;
7253 sys2et[EACCES] = UAEACCES;
7254 sys2et[EFAULT] = UAEFAULT;
7255 sys2et[ENOTBLK] = UAENOTBLK;
7256 sys2et[EBUSY] = UAEBUSY;
7257 sys2et[EEXIST] = UAEEXIST;
7258 sys2et[EXDEV] = UAEXDEV;
7259 sys2et[ENODEV] = UAENODEV;
7260 sys2et[ENOTDIR] = UAENOTDIR;
7261 sys2et[EISDIR] = UAEISDIR;
7262 sys2et[EINVAL] = UAEINVAL;
7263 sys2et[ENFILE] = UAENFILE;
7264 sys2et[EMFILE] = UAEMFILE;
7265 sys2et[ENOTTY] = UAENOTTY;
7266 sys2et[ETXTBSY] = UAETXTBSY;
7267 sys2et[EFBIG] = UAEFBIG;
7268 sys2et[ENOSPC] = UAENOSPC;
7269 sys2et[ESPIPE] = UAESPIPE;
7270 sys2et[EROFS] = UAEROFS;
7271 sys2et[EMLINK] = UAEMLINK;
7272 sys2et[EPIPE] = UAEPIPE;
7273 sys2et[EDOM] = UAEDOM;
7274 sys2et[ERANGE] = UAERANGE;
7275 sys2et[EDEADLK] = UAEDEADLK;
7276 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7277 sys2et[ENOLCK] = UAENOLCK;
7278 sys2et[ENOSYS] = UAENOSYS;
7279 #if (ENOTEMPTY != EEXIST)
7280 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7282 sys2et[ELOOP] = UAELOOP;
7283 #if (EWOULDBLOCK != EAGAIN)
7284 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7286 sys2et[ENOMSG] = UAENOMSG;
7287 sys2et[EIDRM] = UAEIDRM;
7288 sys2et[ECHRNG] = UAECHRNG;
7289 sys2et[EL2NSYNC] = UAEL2NSYNC;
7290 sys2et[EL3HLT] = UAEL3HLT;
7291 sys2et[EL3RST] = UAEL3RST;
7292 sys2et[ELNRNG] = UAELNRNG;
7293 sys2et[EUNATCH] = UAEUNATCH;
7294 sys2et[ENOCSI] = UAENOCSI;
7295 sys2et[EL2HLT] = UAEL2HLT;
7296 sys2et[EBADE] = UAEBADE;
7297 sys2et[EBADR] = UAEBADR;
7298 sys2et[EXFULL] = UAEXFULL;
7299 sys2et[ENOANO] = UAENOANO;
7300 sys2et[EBADRQC] = UAEBADRQC;
7301 sys2et[EBADSLT] = UAEBADSLT;
7302 sys2et[EDEADLK] = UAEDEADLK;
7303 sys2et[EBFONT] = UAEBFONT;
7304 sys2et[ENOSTR] = UAENOSTR;
7305 sys2et[ENODATA] = UAENODATA;
7306 sys2et[ETIME] = UAETIME;
7307 sys2et[ENOSR] = UAENOSR;
7308 sys2et[ENONET] = UAENONET;
7309 sys2et[ENOPKG] = UAENOPKG;
7310 sys2et[EREMOTE] = UAEREMOTE;
7311 sys2et[ENOLINK] = UAENOLINK;
7312 sys2et[EADV] = UAEADV;
7313 sys2et[ESRMNT] = UAESRMNT;
7314 sys2et[ECOMM] = UAECOMM;
7315 sys2et[EPROTO] = UAEPROTO;
7316 sys2et[EMULTIHOP] = UAEMULTIHOP;
7317 sys2et[EDOTDOT] = UAEDOTDOT;
7318 sys2et[EBADMSG] = UAEBADMSG;
7319 sys2et[EOVERFLOW] = UAEOVERFLOW;
7320 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7321 sys2et[EBADFD] = UAEBADFD;
7322 sys2et[EREMCHG] = UAEREMCHG;
7323 sys2et[ELIBACC] = UAELIBACC;
7324 sys2et[ELIBBAD] = UAELIBBAD;
7325 sys2et[ELIBSCN] = UAELIBSCN;
7326 sys2et[ELIBMAX] = UAELIBMAX;
7327 sys2et[ELIBEXEC] = UAELIBEXEC;
7328 sys2et[EILSEQ] = UAEILSEQ;
7329 sys2et[ERESTART] = UAERESTART;
7330 sys2et[ESTRPIPE] = UAESTRPIPE;
7331 sys2et[EUSERS] = UAEUSERS;
7332 sys2et[ENOTSOCK] = UAENOTSOCK;
7333 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7334 sys2et[EMSGSIZE] = UAEMSGSIZE;
7335 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7336 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7337 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7338 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7339 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7340 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7341 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7342 sys2et[EADDRINUSE] = UAEADDRINUSE;
7343 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7344 sys2et[ENETDOWN] = UAENETDOWN;
7345 sys2et[ENETUNREACH] = UAENETUNREACH;
7346 sys2et[ENETRESET] = UAENETRESET;
7347 sys2et[ECONNABORTED] = UAECONNABORTED;
7348 sys2et[ECONNRESET] = UAECONNRESET;
7349 sys2et[ENOBUFS] = UAENOBUFS;
7350 sys2et[EISCONN] = UAEISCONN;
7351 sys2et[ENOTCONN] = UAENOTCONN;
7352 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7353 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7354 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7355 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7356 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7357 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7358 sys2et[EALREADY] = UAEALREADY;
7359 sys2et[EINPROGRESS] = UAEINPROGRESS;
7360 sys2et[ESTALE] = UAESTALE;
7361 sys2et[EUCLEAN] = UAEUCLEAN;
7362 sys2et[ENOTNAM] = UAENOTNAM;
7363 sys2et[ENAVAIL] = UAENAVAIL;
7364 sys2et[EISNAM] = UAEISNAM;
7365 sys2et[EREMOTEIO] = UAEREMOTEIO;
7366 sys2et[EDQUOT] = UAEDQUOT;
7367 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7368 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7370 sys2et[EIO] = UAEIO;
7374 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
7375 * - pass back the connection, client, and host from CallPreamble
7376 * - keep a ref on the client, which we don't now
7377 * - keep a hold on the host, which we already do
7378 * - pass the connection, client, and host down into SAFSS_*, and use
7379 * them instead of independently discovering them via rx_ConnectionOf
7380 * (safe) and rx_GetSpecific (not so safe)
7381 * The idea being that we decide what client and host we're going to use
7382 * when CallPreamble is called, and stay consistent throughout the call.
7383 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
7387 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7389 Error errorCode = 0;
7390 struct rx_connection *tcon;
7391 struct host *tcallhost;
7392 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7394 struct client *tclient;
7395 static struct rx_securityClass *sc = 0;
7397 struct rx_connection *conn;
7400 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost))
7401 goto Bad_CallBackRxConnAddr1;
7403 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7407 tclient = h_FindClient_r(tcon);
7408 thost = tclient->host;
7410 /* nothing more can be done */
7411 if ( !thost->interface )
7412 goto Bad_CallBackRxConnAddr;
7414 assert(thost->interface->numberOfInterfaces > 0 );
7416 /* the only address is the primary interface */
7417 /* can't change when there's only 1 address, anyway */
7418 if ( thost->interface->numberOfInterfaces == 1 )
7419 goto Bad_CallBackRxConnAddr;
7421 /* initialise a security object only once */
7423 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7425 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7427 if ( *addr == thost->interface->addr[i] ) {
7432 if ( *addr != thost->interface->addr[i] )
7433 goto Bad_CallBackRxConnAddr;
7435 conn = rx_NewConnection (thost->interface->addr[i],
7436 thost->port, 1, sc, 0);
7437 rx_SetConnDeadTime(conn, 2);
7438 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7440 errorCode = RXAFSCB_Probe(conn);
7443 if ( thost->callback_rxcon )
7444 rx_DestroyConnection(thost->callback_rxcon);
7445 thost->callback_rxcon = conn;
7447 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7448 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7449 h_ReleaseClient_r(tclient);
7450 /* The hold on thost will be released by CallPostamble */
7452 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7455 rx_DestroyConnection(conn);
7457 Bad_CallBackRxConnAddr:
7458 h_ReleaseClient_r(tclient);
7459 /* The hold on thost will be released by CallPostamble */
7463 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7464 Bad_CallBackRxConnAddr1:
7465 return errorCode; /* failure */
7469 sys_error_to_et(afs_int32 in)
7473 if (in < 0 || in > 511)
7475 if (in >= VICE_SPECIAL_ERRORS && in <= VIO || in == VRESTRICTED)
7477 if (sys2et[in] != 0)