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>
37 #undef SHARED /* XXX */
42 #include <sys/param.h>
44 #include <netinet/in.h>
46 #include <sys/ioctl.h>
47 #include <sys/socket.h>
57 #ifndef AFS_LINUX20_ENV
59 #include <netinet/if_ether.h>
63 /* included early because of name conflict on IOPEN */
64 #include <sys/inode.h>
68 #endif /* AFS_HPUX_ENV */
72 #include <afs/assert.h>
75 #include <afs/afsint.h>
76 #include <afs/vldbint.h>
77 #include <afs/errors.h>
78 #include <afs/ihandle.h>
79 #include <afs/vnode.h>
80 #include <afs/volume.h>
82 #include <afs/ptclient.h>
83 #include <afs/prs_fs.h>
85 #include <rx/rx_globals.h>
87 #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)
90 #if !defined(AFS_NT40_ENV)
93 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
95 #include <sys/statfs.h>
96 #include <sys/lockf.h>
98 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
103 #include <afs/cellconfig.h>
104 #include <afs/keys.h>
106 #include <afs/auth.h>
108 #include <afs/partition.h>
109 #include "viced_prototypes.h"
112 #include <afs/audit.h>
113 #include <afs/afsutil.h>
115 #ifdef AFS_PTHREAD_ENV
116 pthread_mutex_t fileproc_glock_mutex;
117 #endif /* AFS_PTHREAD_ENV */
120 /* Useful local defines used by this module */
123 #define MustNOTBeDIR 1
127 #define TVS_SSTATUS 2
130 #define TVS_MKDIR 0x10
132 #define CHK_FETCH 0x10
133 #define CHK_FETCHDATA 0x10
134 #define CHK_FETCHACL 0x11
135 #define CHK_FETCHSTATUS 0x12
136 #define CHK_STOREDATA 0x00
137 #define CHK_STOREACL 0x01
138 #define CHK_STORESTATUS 0x02
140 #define OWNERREAD 0400
141 #define OWNERWRITE 0200
142 #define OWNEREXEC 0100
143 #ifdef USE_GROUP_PERMS
144 #define GROUPREAD 0040
145 #define GROUPWRITE 0020
146 #define GROUPREXEC 0010
149 /* The following errors were not defined in NT. They are given unique
150 * names here to avoid any potential collision.
152 #define FSERR_ELOOP 90
153 #define FSERR_EOPNOTSUPP 122
154 #define FSERR_ECONNREFUSED 130
156 #define NOTACTIVECALL 0
159 #define CREATE_SGUID_ADMIN_ONLY 1
161 extern struct afsconf_dir *confDir;
162 extern afs_int32 dataVersionHigh;
165 static struct AFSCallStatistics AFSCallStats;
166 #if FS_STATS_DETAILED
167 struct fs_stats_FullPerfStats afs_FullPerfStats;
168 extern int AnonymousID;
169 #endif /* FS_STATS_DETAILED */
170 #if TRANSARC_VOL_STATS
171 static const char nullString[] = "";
172 #endif /* TRANSARC_VOL_STATS */
175 afs_int32 NothingYet;
178 struct afs_FSStats afs_fsstats;
180 void ResetDebug(), SetDebug(), Terminate();
185 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
187 extern afs_int32 implicitAdminRights;
188 extern afs_int32 readonlyServer;
191 * Externals used by the xstat code.
193 extern int VolumeCacheSize, VolumeGets, VolumeReplacements;
194 extern int CEs, CEBlocks;
196 extern int HTs, HTBlocks;
199 FetchData_RXStyle(Volume *volptr,
201 register struct rx_call *Call,
205 #if FS_STATS_DETAILED
206 afs_size_t *a_bytesToFetchP,
207 afs_size_t *a_bytesFetchedP
208 #endif /* FS_STATS_DETAILED */
212 StoreData_RXStyle(Volume *volptr,
215 struct client *client,
216 register struct rx_call *Call,
219 afs_offs_t FileLength,
221 #if FS_STATS_DETAILED
222 afs_size_t *a_bytesToStoreP,
223 afs_size_t *a_bytesStoredP
224 #endif /* FS_STATS_DETAILED */
227 #ifdef AFS_SGI_XFS_IOPS_ENV
228 #include <afs/xfsattrs.h>
229 static int GetLinkCount(Volume *avp, struct stat *astat)
231 if (!strcmp("xfs", astat->st_fstype)) {
232 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
235 return astat->st_nlink;
238 #define GetLinkCount(V, S) (S)->st_nlink
241 afs_int32 SpareComp(Volume *avolp)
243 register afs_int32 temp;
247 temp = V_maxquota(avolp);
249 /* no matter; doesn't check in this case */
253 temp = (temp * PctSpare) / 100;
266 * Set the volume synchronization parameter for this volume. If it changes,
267 * the Cache Manager knows that the volume must be purged from the stat cache.
269 static void SetVolumeSync(register struct AFSVolSync *async,
270 register Volume *avol)
273 /* date volume instance was created */
276 async->spare1 = avol->header->diskstuff.creationDate;
289 * Note that this function always returns a held host, so
290 * that CallPostamble can block without the host's disappearing.
291 * Call returns rx connection in passed in *tconn
293 static int CallPreamble(register struct rx_call *acall, int activecall,
294 struct rx_connection **tconn)
297 struct client *tclient;
302 ViceLog (0, ("CallPreamble: unexpected null tconn!\n"));
305 *tconn = rx_ConnectionOf(acall);
309 tclient = h_FindClient_r(*tconn);
310 if (tclient->prfail == 1) { /* couldn't get the CPS */
312 h_ReleaseClient_r(tclient);
313 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
317 retry_flag=0; /* Retry once */
319 /* Take down the old connection and re-read the key file */
320 ViceLog(0, ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
322 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
325 h_ReleaseClient_r(tclient);
327 ViceLog(0,("CallPreamble: couldn't reconnect to ptserver\n"));
331 tclient->prfail = 2; /* Means re-eval client's cps */
332 h_ReleaseClient_r(tclient);
336 thost = tclient->host;
337 tclient->LastCall = thost->LastCall = FT_ApproxTime();
338 if (activecall) /* For all but "GetTime" calls */
339 thost->ActiveCall = thost->LastCall;
342 if (thost->hostFlags & HOSTDELETED) {
343 ViceLog(3,("Discarded a packet for deleted host %s\n",afs_inet_ntoa_r(thost->host,hoststr)));
344 code = VBUSY; /* raced, so retry */
346 else if ((thost->hostFlags & VENUSDOWN) || (thost->hostFlags & HFE_LATER)){
347 if (BreakDelayedCallBacks_r(thost)) {
348 ViceLog(0,("BreakDelayedCallbacks FAILED for host %s which IS UP. Possible network or routing failure.\n",
349 afs_inet_ntoa_r(thost->host, hoststr)));
350 if ( MultiProbeAlternateAddress_r (thost) ) {
351 ViceLog(0, ("MultiProbe failed to find new address for host %s:%d\n",
352 afs_inet_ntoa_r(thost->host, hoststr),
353 ntohs(thost->port)));
356 ViceLog(0, ("MultiProbe found new address for host %s:%d\n",
357 afs_inet_ntoa_r(thost->host, hoststr),
358 ntohs(thost->port)));
359 if (BreakDelayedCallBacks_r(thost)) {
360 ViceLog(0,("BreakDelayedCallbacks FAILED AGAIN for host %s which IS UP. Possible network or routing failure.\n",
361 afs_inet_ntoa_r(thost->host, hoststr)));
370 h_ReleaseClient_r(tclient);
378 static void CallPostamble(register struct rx_connection *aconn)
381 struct client *tclient;
384 tclient = h_FindClient_r(aconn);
385 thost = tclient->host;
386 h_ReleaseClient_r(tclient);
393 * Returns the volume and vnode pointers associated with file Fid; the lock
394 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
395 * are incremented and they must be eventualy released.
398 CheckVnode(AFSFid *fid, Volume **volptr, Vnode **vptr, int lock)
402 static struct timeval restartedat = {0,0};
404 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
406 if ((*volptr) == 0) {
411 *volptr = VGetVolume(&errorCode, (afs_int32)fid->Volume);
416 if ((errorCode == VOFFLINE) && (VInit < 2)) {
417 /* The volume we want may not be attached yet because
418 * the volume initialization is not yet complete.
419 * We can do several things:
420 * 1. return -1, which will cause users to see
421 * "connection timed out". This is more or
422 * less the same as always, except that the servers
423 * may appear to bounce up and down while they
424 * are actually restarting.
425 * 2. return VBUSY which will cause clients to
426 * sleep and retry for 6.5 - 15 minutes, depending
427 * on what version of the CM they are running. If
428 * the file server takes longer than that interval
429 * to attach the desired volume, then the application
430 * will see an ENODEV or EIO. This approach has
431 * the advantage that volumes which have been attached
432 * are immediately available, it keeps the server's
433 * immediate backlog low, and the call is interruptible
434 * by the user. Users see "waiting for busy volume."
435 * 3. sleep here and retry. Some people like this approach
436 * because there is no danger of seeing errors. However,
437 * this approach only works with a bounded number of
438 * clients, since the pending queues will grow without
439 * stopping. It might be better to find a way to take
440 * this call and stick it back on a queue in order to
441 * recycle this thread for a different request.
442 * 4. Return a new error code, which new cache managers will
443 * know enough to interpret as "sleep and retry", without
444 * the upper bound of 6-15 minutes that is imposed by the
445 * VBUSY handling. Users will see "waiting for
446 * busy volume," so they know that something is
447 * happening. Old cache managers must be able to do
448 * something reasonable with this, for instance, mark the
449 * server down. Fortunately, any error code < 0
450 * will elicit that behavior. See #1.
451 * 5. Some combination of the above. I like doing #2 for 10
452 * minutes, followed by #4. 3.1b and 3.2 cache managers
453 * will be fine as long as the restart period is
454 * not longer than 6.5 minutes, otherwise they may
455 * return ENODEV to users. 3.3 cache managers will be
456 * fine for 10 minutes, then will return
457 * ETIMEDOUT. 3.4 cache managers will just wait
458 * until the call works or fails definitively.
459 * NB. The problem with 2,3,4,5 is that old clients won't
460 * fail over to an alternate read-only replica while this
461 * server is restarting. 3.4 clients will fail over right away.
463 if (restartedat.tv_sec == 0) {
464 /* I'm not really worried about when we restarted, I'm */
465 /* just worried about when the first VBUSY was returned. */
466 TM_GetTimeOfDay(&restartedat, 0);
467 return(busyonrst?VBUSY:VRESTARTING);
471 TM_GetTimeOfDay(&now, 0);
472 if ((now.tv_sec - restartedat.tv_sec) < (11*60)) {
473 return(busyonrst?VBUSY:VRESTARTING);
476 return (VRESTARTING);
480 /* allow read operations on busy volume */
481 else if(errorCode==VBUSY && lock==READ_LOCK) {
492 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
495 if ((*vptr)->disk.uniquifier != fid->Unique) {
496 VPutVnode(&fileCode, *vptr);
497 assert(fileCode == 0);
499 return(VNOVNODE); /* return the right error code, at least */
505 * This routine returns the ACL associated with the targetptr. If the
506 * targetptr isn't a directory, we access its parent dir and get the ACL
507 * thru the parent; in such case the parent's vnode is returned in
511 SetAccessList(Vnode **targetptr,
513 struct acl_accessList **ACL,
519 if ((*targetptr)->disk.type == vDirectory) {
521 *ACL = VVnodeACL(*targetptr);
522 *ACLSize = VAclSize(*targetptr);
531 parentvnode = (*targetptr)->disk.parent;
532 VPutVnode(&errorCode,*targetptr);
534 if (errorCode) return(errorCode);
535 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
536 if (errorCode) return(errorCode);
537 *ACL = VVnodeACL(*parent);
538 *ACLSize = VAclSize(*parent);
539 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
541 if ((*targetptr)->disk.parent != parentvnode) {
542 VPutVnode(&errorCode, *parent);
544 if (errorCode) return(errorCode);
553 * Compare the directory's ACL with the user's access rights in the client
554 * connection and return the user's and everybody else's access permissions
555 * in rights and anyrights, respectively
558 GetRights (struct client *client,
559 struct acl_accessList *ACL,
561 afs_int32 *anyrights)
563 extern prlist SystemAnyUserCPS;
564 afs_int32 hrights = 0;
567 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
569 ViceLog(0,("CheckRights failed\n"));
573 acl_CheckRights(ACL, &client->CPS, rights);
575 /* wait if somebody else is already doing the getCPS call */
577 while ( client->host->hostFlags & HCPS_INPROGRESS )
579 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
580 #ifdef AFS_PTHREAD_ENV
581 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
582 #else /* AFS_PTHREAD_ENV */
583 if ((code=LWP_WaitProcess( &(client->host->hostFlags))) !=LWP_SUCCESS)
584 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
585 #endif /* AFS_PTHREAD_ENV */
588 if (client->host->hcps.prlist_len && !client->host->hcps.prlist_val) {
589 ViceLog(0,("CheckRights: len=%d, for host=0x%x\n", client->host->hcps.prlist_len, client->host->host));
591 acl_CheckRights(ACL, &client->host->hcps, &hrights);
593 /* Allow system:admin the rights given with the -implicit option */
594 if (acl_IsAMember(SystemId, &client->CPS))
595 *rights |= implicitAdminRights;
597 *anyrights |= hrights;
604 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
605 * a System:Administrator)
608 VanillaUser(struct client *client)
610 if (acl_IsAMember(SystemId, &client->CPS))
611 return(0); /* not a system administrator, then you're "vanilla" */
618 * This unusual afs_int32-parameter routine encapsulates all volume package related
619 * operations together in a single function; it's called by almost all AFS
623 GetVolumePackage(struct rx_connection *tcon,
629 struct client **client,
632 afs_int32 *anyrights)
634 struct acl_accessList * aCL; /* Internal access List */
635 int aCLSize; /* size of the access list */
636 int errorCode = 0; /* return code to caller */
638 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
641 if (chkforDir == MustNOTBeDIR && ((*targetptr)->disk.type == vDirectory))
643 else if (chkforDir == MustBeDIR && ((*targetptr)->disk.type != vDirectory))
646 if ((errorCode = SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent, (chkforDir == MustBeDIR ? (AFSFid *)0 : Fid), (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
648 if (chkforDir == MustBeDIR) assert((*parent) == 0);
649 if ((errorCode = GetClient(tcon, client)) != 0)
653 assert(GetRights(*client, aCL, rights, anyrights) == 0);
654 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
655 if ((*targetptr)->disk.type != vDirectory) {
656 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
657 if ((*targetptr)->disk.owner == (*client)->ViceId)
658 (*rights) |= PRSFS_ADMINISTER;
660 (*rights) &= ~PRSFS_ADMINISTER;
662 #ifdef ADMIN_IMPLICIT_LOOKUP
663 /* admins get automatic lookup on everything */
664 if (!VanillaUser(*client)) (*rights) |= PRSFS_LOOKUP;
665 #endif /* ADMIN_IMPLICIT_LOOKUP */
668 } /*GetVolumePackage*/
672 * This is the opposite of GetVolumePackage(), and is always used at the end of
673 * AFS calls to put back all used vnodes and the volume in the proper order!
676 PutVolumePackage(Vnode *parentwhentargetnotdir,
681 int fileCode = 0; /* Error code returned by the volume package */
683 if (parentwhentargetnotdir) {
684 VPutVnode(&fileCode, parentwhentargetnotdir);
685 assert(!fileCode || (fileCode == VSALVAGE));
688 VPutVnode(&fileCode, targetptr);
689 assert(!fileCode || (fileCode == VSALVAGE));
692 VPutVnode(&fileCode, parentptr);
693 assert(!fileCode || (fileCode == VSALVAGE));
698 } /*PutVolumePackage*/
700 static int VolumeOwner (register struct client *client,
701 register Vnode *targetptr)
703 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
706 return (client->ViceId == owner);
709 * We don't have to check for host's cps since only regular
710 * viceid are volume owners.
712 return (acl_IsAMember(owner, &client->CPS));
717 static int VolumeRootVnode (Vnode *targetptr)
719 return ((targetptr->vnodeNumber == ROOTVNODE) &&
720 (targetptr->disk.uniquifier == 1));
722 } /*VolumeRootVnode*/
725 * Check if target file has the proper access permissions for the Fetch
726 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
727 * StoreStatus) related calls
729 /* this code should probably just set a "priv" flag where all the audit events
730 * are now, and only generate the audit event once at the end of the routine,
731 * thus only generating the event if all the checks succeed, but only because
732 * of the privilege XXX
735 Check_PermissionRights(Vnode *targetptr,
736 struct client *client,
739 AFSStoreStatus *InStatus)
742 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
743 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
744 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
746 if (CallingRoutine & CHK_FETCH) {
748 if (VanillaUser(client))
750 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client))
753 if (targetptr->disk.type == vDirectory || targetptr->disk.type == vSymlink) {
754 if ( !(rights & PRSFS_LOOKUP)
755 #ifdef ADMIN_IMPLICIT_LOOKUP
756 /* grant admins fetch on all directories */
757 && VanillaUser(client)
758 #endif /* ADMIN_IMPLICIT_LOOKUP */
759 && !VolumeOwner(client, targetptr))
762 /* must have read access, or be owner and have insert access */
763 if (!(rights & PRSFS_READ) &&
764 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
767 if (CallingRoutine == CHK_FETCHDATA && targetptr->disk.type == vFile)
768 #ifdef USE_GROUP_PERMS
769 if (!OWNSp(client, targetptr) &&
770 !acl_IsAMember(targetptr->disk.owner, &client->CPS)) {
771 errorCode = (((GROUPREAD|GROUPEXEC) & targetptr->disk.modeBits)
774 errorCode =(((OWNERREAD|OWNEREXEC) & targetptr->disk.modeBits)
779 * The check with the ownership below is a kludge to allow
780 * reading of files created with no read permission. The owner
781 * of the file is always allowed to read it.
783 if ((client->ViceId != targetptr->disk.owner) && VanillaUser(client))
784 errorCode =(((OWNERREAD|OWNEREXEC) & targetptr->disk.modeBits) ? 0: EACCES);
787 else /* !VanillaUser(client) && !FetchData */ {
788 osi_audit( PrivilegeEvent, 0, AUD_INT, (client ? client->ViceId : 0),
789 AUD_INT, CallingRoutine, AUD_END);
792 else { /* a store operation */
793 if ( (rights & PRSFS_INSERT) && OWNSp(client, targetptr)
794 && (CallingRoutine != CHK_STOREACL)
795 && (targetptr->disk.type == vFile))
797 /* bypass protection checks on first store after a create
798 * for the creator; also prevent chowns during this time
799 * unless you are a system administrator */
800 /****** InStatus->Owner && UnixModeBits better be SET!! */
801 if ( CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
804 else if (VanillaUser (client))
805 return(EPERM); /* Was EACCES */
807 osi_audit( PrivilegeEvent, 0, AUD_INT, (client ? client->ViceId : 0),
808 AUD_INT, CallingRoutine, AUD_END);
811 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
812 osi_audit( PrivilegeEvent, 0, AUD_INT, (client ? client->ViceId : 0),
813 AUD_INT, CallingRoutine, AUD_END);
816 if (readonlyServer) {
819 if (CallingRoutine == CHK_STOREACL) {
820 if (!(rights & PRSFS_ADMINISTER) &&
821 !VolumeOwner(client, targetptr)) return(EACCES);
823 else { /* store data or status */
824 /* watch for chowns and chgrps */
825 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
828 else if (VanillaUser (client))
829 return(EPERM); /* Was EACCES */
831 osi_audit(PrivilegeEvent, 0,
832 AUD_INT, (client ? client->ViceId : 0),
833 AUD_INT, CallingRoutine, AUD_END);
835 /* must be sysadmin to set suid/sgid bits */
836 if ((InStatus->Mask & AFS_SETMODE) &&
838 (InStatus->UnixModeBits & 0xc00) != 0) {
840 (InStatus->UnixModeBits & (S_ISUID|S_ISGID)) != 0) {
844 if (VanillaUser(client))
846 else osi_audit( PrivSetID, 0, AUD_INT, (client ? client->ViceId : 0),
847 AUD_INT, CallingRoutine, AUD_END);
849 if (CallingRoutine == CHK_STOREDATA) {
852 if (!(rights & PRSFS_WRITE))
854 /* Next thing is tricky. We want to prevent people
855 * from writing files sans 0200 bit, but we want
856 * creating new files with 0444 mode to work. We
857 * don't check the 0200 bit in the "you are the owner"
858 * path above, but here we check the bit. However, if
859 * you're a system administrator, we ignore the 0200
860 * bit anyway, since you may have fchowned the file,
862 #ifdef USE_GROUP_PERMS
863 if ((targetptr->disk.type == vFile)
864 && VanillaUser(client)) {
865 if (!OWNSp(client, targetptr) &&
866 !acl_IsAMember(targetptr->disk.owner,
868 errorCode = ((GROUPWRITE & targetptr->disk.modeBits)
871 errorCode = ((OWNERWRITE & targetptr->disk.modeBits)
876 if ((targetptr->disk.type != vDirectory)
877 && (!(targetptr->disk.modeBits & OWNERWRITE)))
880 if (VanillaUser(client))
882 else osi_audit( PrivilegeEvent, 0, AUD_INT, (client ? client->ViceId : 0),
883 AUD_INT, CallingRoutine, AUD_END);
885 else { /* a status store */
888 if (targetptr->disk.type == vDirectory) {
889 if (!(rights & PRSFS_DELETE) && !(rights & PRSFS_INSERT))
892 else { /* a file or symlink */
893 if (!(rights & PRSFS_WRITE)) return(EACCES);
902 } /*Check_PermissionRights*/
906 * The Access List information is converted from its internal form in the
907 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
908 * external form and returned back to the caller, via the AccessList
912 RXFetch_AccessList(Vnode *targetptr,
913 Vnode *parentwhentargetnotdir,
914 struct AFSOpaque *AccessList)
916 char * eACL; /* External access list placeholder */
918 if (acl_Externalize((targetptr->disk.type == vDirectory ?
919 VVnodeACL(targetptr) :
920 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
923 if ((strlen(eACL)+1) > AFSOPAQUEMAX) {
924 acl_FreeExternalACL(&eACL);
927 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
928 AccessList->AFSOpaque_len = strlen(eACL) +1;
930 acl_FreeExternalACL(&eACL);
933 } /*RXFetch_AccessList*/
937 * The Access List information is converted from its external form in the
938 * input AccessList structure to the internal representation and copied into
939 * the target dir's vnode storage.
942 RXStore_AccessList(Vnode *targetptr, struct AFSOpaque *AccessList)
944 struct acl_accessList * newACL; /* PlaceHolder for new access list */
946 if (acl_Internalize(AccessList->AFSOpaque_val, &newACL) != 0)
948 if ((newACL->size + 4) > VAclSize(targetptr))
950 memcpy((char *) VVnodeACL(targetptr), (char *) newACL, (int)(newACL->size));
951 acl_FreeACL(&newACL);
954 } /*RXStore_AccessList*/
958 Fetch_AccessList(Vnode *targetptr, Vnode *parentwhentargetnotdir,
959 struct AFSAccessList *AccessList)
961 char * eACL; /* External access list placeholder */
963 assert(acl_Externalize((targetptr->disk.type == vDirectory ?
964 VVnodeACL(targetptr) :
965 VVnodeACL(parentwhentargetnotdir)), &eACL) == 0);
966 if ((strlen(eACL)+1) > AccessList->MaxSeqLen) {
967 acl_FreeExternalACL(&eACL);
970 strcpy((char *)(AccessList->SeqBody), (char *)eACL);
971 AccessList->SeqLen = strlen(eACL) +1;
973 acl_FreeExternalACL(&eACL);
976 } /*Fetch_AccessList*/
979 * The Access List information is converted from its external form in the
980 * input AccessList structure to the internal representation and copied into
981 * the target dir's vnode storage.
984 Store_AccessList(Vnode *targetptr, struct AFSAccessList *AccessList)
986 struct acl_accessList * newACL; /* PlaceHolder for new access list */
988 if (acl_Internalize(AccessList->SeqBody, &newACL) != 0)
990 if ((newACL->size + 4) > VAclSize(targetptr))
992 memcpy((char *) VVnodeACL(targetptr), (char *) newACL, (int)(newACL->size));
993 acl_FreeACL(&newACL);
996 } /*Store_AccessList*/
999 /* In our current implementation, each successive data store (new file
1000 * data version) creates a new inode. This function creates the new
1001 * inode, copies the old inode's contents to the new one, remove the old
1002 * inode (i.e. decrement inode count -- if it's currently used the delete
1003 * will be delayed), and modify some fields (i.e. vnode's
1004 * disk.inodeNumber and cloned)
1006 #define COPYBUFFSIZE 8192
1007 static int CopyOnWrite(Vnode *targetptr, Volume *volptr)
1009 Inode ino, nearInode;
1012 register afs_size_t size;
1013 register int length;
1016 int rc; /* return code */
1017 IHandle_t *newH; /* Use until finished copying, then cp to vnode.*/
1018 FdHandle_t *targFdP; /* Source Inode file handle */
1019 FdHandle_t *newFdP; /* Dest Inode file handle */
1021 if (targetptr->disk.type == vDirectory) DFlush(); /* just in case? */
1023 VN_GET_LEN(size, targetptr);
1024 buff = (char *)malloc(COPYBUFFSIZE);
1029 ino = VN_GET_INO(targetptr);
1030 assert(VALID_INO(ino));
1031 targFdP = IH_OPEN(targetptr->handle);
1032 if (targFdP == NULL) {
1034 ViceLog(0, ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n", targetptr->vnodeNumber, V_id(volptr), rc));
1036 VTakeOffline (volptr);
1040 nearInode = VN_GET_INO(targetptr);
1041 ino = IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1042 VPartitionPath(V_partition(volptr)),nearInode, V_id(volptr),
1043 targetptr->vnodeNumber, targetptr->disk.uniquifier,
1044 (int)targetptr->disk.dataVersion);
1045 if (!VALID_INO(ino))
1047 ViceLog(0,("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n", volptr->partition->name, V_id(volptr), errno));
1052 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1053 newFdP = IH_OPEN(newH);
1054 assert(newFdP != NULL);
1057 if (size > COPYBUFFSIZE) { /* more than a buffer */
1058 length = COPYBUFFSIZE;
1059 size -= COPYBUFFSIZE;
1064 rdlen = FDH_READ(targFdP, buff, length);
1065 if (rdlen == length)
1066 wrlen = FDH_WRITE(newFdP, buff, length);
1069 /* Callers of this function are not prepared to recover
1070 * from error that put the filesystem in an inconsistent
1071 * state. Make sure that we force the volume off-line if
1072 * we some error other than ENOSPC - 4.29.99)
1074 * In case we are unable to write the required bytes, and the
1075 * error code indicates that the disk is full, we roll-back to
1076 * the initial state.
1078 if((rdlen != length) || (wrlen != length))
1079 if ( (wrlen < 0) && (errno == ENOSPC) ) /* disk full */
1081 ViceLog(0,("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1082 volptr->partition->name, V_id(volptr)));
1083 /* remove destination inode which was partially copied till now*/
1084 FDH_REALLYCLOSE(newFdP);
1086 FDH_REALLYCLOSE(targFdP);
1087 rc = IH_DEC(V_linkHandle(volptr), ino,
1088 V_parentId(volptr));
1090 ViceLog(0,("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1092 volptr->partition->name));
1093 VTakeOffline (volptr);
1099 ViceLog(0,("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1100 V_id(volptr), volptr->partition->name, length,
1101 rdlen, wrlen, errno));
1102 #ifdef FAST_RESTART /* if running in no-salvage, don't core the server */
1103 ViceLog(0,("CopyOnWrite failed: taking volume offline\n"));
1104 #else /* Avoid further corruption and try to get a core. */
1107 /* Decrement this inode so salvager doesn't find it. */
1108 FDH_REALLYCLOSE(newFdP);
1110 FDH_REALLYCLOSE(targFdP);
1111 rc = IH_DEC(V_linkHandle(volptr), ino,
1112 V_parentId(volptr));
1114 VTakeOffline (volptr);
1117 #ifndef AFS_PTHREAD_ENV
1119 #endif /* !AFS_PTHREAD_ENV */
1121 FDH_REALLYCLOSE(targFdP);
1122 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1123 V_parentId(volptr)) ;
1125 IH_RELEASE(targetptr->handle);
1127 rc = FDH_SYNC(newFdP);
1130 targetptr->handle = newH;
1131 VN_SET_INO(targetptr, ino);
1132 targetptr->disk.cloned = 0;
1133 /* Internal change to vnode, no user level change to volume - def 5445 */
1134 targetptr->changed_oldTime = 1;
1136 return 0; /* success */
1141 * Common code to handle with removing the Name (file when it's called from
1142 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1143 * given directory, parentptr.
1147 DeleteTarget(Vnode *parentptr,
1155 DirHandle childdir; /* Handle for dir package I/O */
1159 /* watch for invalid names */
1160 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1162 if (parentptr->disk.cloned)
1164 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1165 if ((errorCode = CopyOnWrite(parentptr, volptr)))
1167 ViceLog(20, ("DeleteTarget %s: CopyOnWrite failed %d\n",Name,errorCode));
1172 /* check that the file is in the directory */
1173 SetDirHandle(dir, parentptr);
1174 if (Lookup(dir, Name, fileFid))
1176 fileFid->Volume = V_id(volptr);
1178 /* just-in-case check for something causing deadlock */
1179 if (fileFid->Vnode == parentptr->vnodeNumber)
1182 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1186 if (ChkForDir == MustBeDIR) {
1187 if ((*targetptr)->disk.type != vDirectory)
1189 } else if ((*targetptr)->disk.type == vDirectory)
1192 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique);*/
1194 * If the uniquifiers dont match then instead of asserting
1195 * take the volume offline and return VSALVAGE
1197 if ( (*targetptr)->disk.uniquifier != fileFid->Unique ) {
1198 VTakeOffline(volptr);
1199 errorCode = VSALVAGE;
1203 if (ChkForDir == MustBeDIR) {
1204 SetDirHandle(&childdir, *targetptr);
1205 if (IsEmpty(&childdir) != 0)
1208 (*targetptr)->delete = 1;
1209 } else if ((--(*targetptr)->disk.linkCount) == 0)
1210 (*targetptr)->delete = 1;
1211 if ((*targetptr)->delete) {
1212 if (VN_GET_INO(*targetptr)) {
1214 IH_REALLYCLOSE((*targetptr)->handle);
1215 errorCode = IH_DEC(V_linkHandle(volptr),
1216 VN_GET_INO(*targetptr),
1217 V_parentId(volptr));
1218 IH_RELEASE((*targetptr)->handle);
1219 if (errorCode == -1) {
1220 ViceLog(0, ("DT: inode=%s, name=%s, errno=%d\n",
1221 PrintInode(NULL, VN_GET_INO(*targetptr)),
1224 if ((errno != ENOENT) && (errno != EIO) && (errno != ENXIO))
1226 if (errno != ENOENT)
1229 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1231 VTakeOffline(volptr);
1238 VN_SET_INO(*targetptr, (Inode)0);
1240 afs_size_t adjLength;
1241 VN_GET_LEN(adjLength, *targetptr);
1242 VAdjustDiskUsage(&errorCode, volptr,
1243 -nBlocks(adjLength),
1248 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1250 code = Delete(dir,(char *) Name);
1252 ViceLog(0, ("Error %d deleting %s\n", code,
1253 (((*targetptr)->disk.type== Directory)?"directory":"file")));
1254 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1256 VTakeOffline(volptr);
1257 if (!errorCode) errorCode = code;
1267 * This routine updates the parent directory's status block after the
1268 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1269 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1273 Update_ParentVnodeStatus(Vnode *parentptr,
1278 #if FS_STATS_DETAILED
1279 char a_inSameNetwork
1280 #endif /* FS_STATS_DETAILED */
1283 afs_offs_t newlength; /* Holds new directory length */
1284 afs_offs_t parentLength;
1286 #if FS_STATS_DETAILED
1287 Date currDate; /*Current date*/
1288 int writeIdx; /*Write index to bump*/
1289 int timeIdx; /*Authorship time index to bump*/
1290 #endif /* FS_STATS_DETAILED */
1292 parentptr->disk.dataVersion++;
1293 newlength = Length(dir);
1295 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1296 * (create, symlink, link, makedir) so we need to check if we have enough space
1297 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1298 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1300 VN_GET_LEN(parentLength, parentptr);
1301 if (nBlocks(newlength) != nBlocks(parentLength)) {
1302 VAdjustDiskUsage(&errorCode, volptr,
1303 (nBlocks(newlength) - nBlocks(parentLength)),
1304 (nBlocks(newlength) - nBlocks(parentLength)));
1306 VN_SET_LEN(parentptr, newlength);
1308 #if FS_STATS_DETAILED
1310 * Update directory write stats for this volume. Note that the auth
1311 * counter is located immediately after its associated ``distance''
1314 if (a_inSameNetwork)
1315 writeIdx = VOL_STATS_SAME_NET;
1317 writeIdx = VOL_STATS_DIFF_NET;
1318 V_stat_writes(volptr, writeIdx)++;
1319 if (author != AnonymousID) {
1320 V_stat_writes(volptr, writeIdx+1)++;
1324 * Update the volume's authorship information in response to this
1325 * directory operation. Get the current time, decide to which time
1326 * slot this operation belongs, and bump the appropriate slot.
1328 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1329 timeIdx = (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 :
1330 currDate < VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 :
1331 currDate < VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 :
1332 currDate < VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 :
1333 currDate < VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1334 VOL_STATS_TIME_IDX_5);
1335 if (parentptr->disk.author == author) {
1336 V_stat_dirSameAuthor(volptr, timeIdx)++;
1339 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1341 #endif /* FS_STATS_DETAILED */
1343 parentptr->disk.author = author;
1344 parentptr->disk.linkCount = linkcount;
1345 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1346 parentptr->disk.serverModifyTime = FT_ApproxTime();
1347 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1352 * Update the target file's (or dir's) status block after the specified
1353 * operation is complete. Note that some other fields maybe updated by
1354 * the individual module.
1357 /* XXX INCOMPLETE - More attention is needed here! */
1359 Update_TargetVnodeStatus(Vnode *targetptr,
1361 struct client *client,
1362 AFSStoreStatus *InStatus,
1367 #if FS_STATS_DETAILED
1368 Date currDate; /*Current date*/
1369 int writeIdx; /*Write index to bump*/
1370 int timeIdx; /*Authorship time index to bump*/
1371 #endif /* FS_STATS_DETAILED */
1373 if (Caller & (TVS_CFILE|TVS_SLINK|TVS_MKDIR)) { /* initialize new file */
1374 targetptr->disk.parent = parentptr->vnodeNumber;
1375 VN_SET_LEN(targetptr, length);
1376 /* targetptr->disk.group = 0; save some cycles */
1377 targetptr->disk.modeBits = 0777;
1378 targetptr->disk.owner = client->ViceId;
1379 targetptr->disk.dataVersion = 0 ; /* consistent with the client */
1380 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1381 /* the inode was created in Alloc_NewVnode() */
1384 #if FS_STATS_DETAILED
1386 * Update file write stats for this volume. Note that the auth
1387 * counter is located immediately after its associated ``distance''
1390 if (client->InSameNetwork)
1391 writeIdx = VOL_STATS_SAME_NET;
1393 writeIdx = VOL_STATS_DIFF_NET;
1394 V_stat_writes(volptr, writeIdx)++;
1395 if (client->ViceId != AnonymousID) {
1396 V_stat_writes(volptr, writeIdx+1)++;
1400 * We only count operations that DON'T involve creating new objects
1401 * (files, symlinks, directories) or simply setting status as
1402 * authorship-change operations.
1404 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1406 * Update the volume's authorship information in response to this
1407 * file operation. Get the current time, decide to which time
1408 * slot this operation belongs, and bump the appropriate slot.
1410 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1411 timeIdx = (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 :
1412 currDate < VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 :
1413 currDate < VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 :
1414 currDate < VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 :
1415 currDate < VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1416 VOL_STATS_TIME_IDX_5);
1417 if (targetptr->disk.author == client->ViceId) {
1418 V_stat_fileSameAuthor(volptr, timeIdx)++;
1420 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1423 #endif /* FS_STATS_DETAILED */
1425 if (!(Caller & TVS_SSTATUS))
1426 targetptr->disk.author = client->ViceId;
1427 if (Caller & TVS_SDATA) {
1428 targetptr->disk.dataVersion++;
1429 if (VanillaUser(client))
1431 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1432 #ifdef CREATE_SGUID_ADMIN_ONLY
1433 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1437 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1438 /* store status, must explicitly request to change the date */
1439 if (InStatus->Mask & AFS_SETMODTIME)
1440 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1442 else {/* other: date always changes, but perhaps to what is specified by caller */
1443 targetptr->disk.unixModifyTime = (InStatus->Mask & AFS_SETMODTIME ? InStatus->ClientModTime : FT_ApproxTime());
1445 if (InStatus->Mask & AFS_SETOWNER) {
1446 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1447 if (VanillaUser(client))
1449 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1450 #ifdef CREATE_SGUID_ADMIN_ONLY
1451 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1454 targetptr->disk.owner = InStatus->Owner;
1455 if (VolumeRootVnode (targetptr)) {
1456 Error errorCode = 0; /* what should be done with this? */
1458 V_owner(targetptr->volumePtr) = InStatus->Owner;
1459 VUpdateVolume(&errorCode, targetptr->volumePtr);
1462 if (InStatus->Mask & AFS_SETMODE) {
1463 int modebits = InStatus->UnixModeBits;
1464 #define CREATE_SGUID_ADMIN_ONLY 1
1465 #ifdef CREATE_SGUID_ADMIN_ONLY
1466 if (VanillaUser(client))
1467 modebits = modebits & 0777;
1469 if (VanillaUser(client)) {
1470 targetptr->disk.modeBits = modebits;
1473 targetptr->disk.modeBits = modebits;
1475 case TVS_SDATA: osi_audit( PrivSetID, 0, AUD_INT, client->ViceId,
1476 AUD_INT, CHK_STOREDATA, AUD_END); break;
1478 case TVS_SSTATUS: osi_audit( PrivSetID, 0, AUD_INT, client->ViceId,
1479 AUD_INT, CHK_STORESTATUS, AUD_END); break;
1484 targetptr->disk.serverModifyTime = FT_ApproxTime();
1485 if (InStatus->Mask & AFS_SETGROUP)
1486 targetptr->disk.group = InStatus->Group;
1487 /* vnode changed : to be written back by VPutVnode */
1488 targetptr->changed_newTime = 1;
1490 } /*Update_TargetVnodeStatus*/
1494 * Fills the CallBack structure with the expiration time and type of callback
1495 * structure. Warning: this function is currently incomplete.
1498 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1500 /* CallBackTime could not be 0 */
1501 if (CallBackTime == 0) {
1502 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1503 CallBack->ExpirationTime = 0;
1505 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1506 CallBack->CallBackVersion = CALLBACK_VERSION;
1507 CallBack->CallBackType = CB_SHARED; /* The default for now */
1509 } /*SetCallBackStruct*/
1513 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1514 * allocation; if some error occured (exceeded volume quota or partition
1515 * was full, or whatever), it frees the space back and returns the code.
1516 * We usually pre-adjust the volume space to make sure that there's
1517 * enough space before consuming some.
1520 AdjustDiskUsage(Volume *volptr, afs_size_t length, afs_size_t checkLength)
1525 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1527 VAdjustDiskUsage(&nc, volptr, -length, (afs_size_t) 0);
1528 if (rc == VOVERQUOTA) {
1529 ViceLog(2,("Volume %u (%s) is full\n",
1530 V_id(volptr), V_name(volptr)));
1533 if (rc == VDISKFULL) {
1534 ViceLog(0,("Partition %s that contains volume %u is full\n",
1535 volptr->partition->name, V_id(volptr)));
1538 ViceLog(0,("Got error return %d from VAdjustDiskUsage\n",rc));
1543 } /*AdjustDiskUsage*/
1546 * Common code that handles the creation of a new file (SAFS_CreateFile and
1547 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1550 Alloc_NewVnode(Vnode *parentptr,
1555 struct AFSFid *OutFid,
1557 afs_size_t BlocksPreallocatedForVnode)
1559 int errorCode = 0; /* Error code returned back */
1562 Inode nearInode; /* hint for inode allocation in solaris */
1564 if ((errorCode = AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1565 BlocksPreallocatedForVnode))) {
1566 ViceLog(25, ("Insufficient space to allocate %d blocks\n",
1567 BlocksPreallocatedForVnode));
1571 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1572 if (errorCode != 0) {
1573 VAdjustDiskUsage(&temp, volptr, - BlocksPreallocatedForVnode,
1577 OutFid->Volume = V_id(volptr);
1578 OutFid->Vnode = (*targetptr)->vnodeNumber;
1579 OutFid->Unique = (*targetptr)->disk.uniquifier;
1581 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1583 /* create the inode now itself */
1584 inode = IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1585 VPartitionPath(V_partition(volptr)), nearInode,
1586 V_id(volptr), (*targetptr)->vnodeNumber,
1587 (*targetptr)->disk.uniquifier, 1);
1589 /* error in creating inode */
1590 if (!VALID_INO(inode))
1592 ViceLog(0, ("Volume : %d vnode = %d Failed to create inode: errno = %d\n",
1593 (*targetptr)->volumePtr->header->diskstuff.id,
1594 (*targetptr)->vnodeNumber,
1596 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode,
1598 (*targetptr)->delete = 1; /* delete vnode */
1601 VN_SET_INO(*targetptr, inode);
1602 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1604 /* copy group from parent dir */
1605 (*targetptr)->disk.group = parentptr->disk.group;
1607 if (parentptr->disk.cloned)
1609 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1610 if ((errorCode = CopyOnWrite(parentptr, volptr))) /* disk full */
1612 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1613 /* delete the vnode previously allocated */
1614 (*targetptr)->delete = 1;
1615 VAdjustDiskUsage(&temp, volptr,
1616 -BlocksPreallocatedForVnode, (afs_size_t) 0);
1617 IH_REALLYCLOSE((*targetptr)->handle);
1618 if ( IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)) )
1619 ViceLog(0,("Alloc_NewVnode: partition %s idec %s failed\n",
1620 volptr->partition->name,
1621 PrintInode(NULL, inode)));
1622 IH_RELEASE((*targetptr)->handle);
1628 /* add the name to the directory */
1629 SetDirHandle(dir, parentptr);
1630 if ((errorCode = Create(dir,(char *)Name, OutFid))) {
1631 (*targetptr)->delete = 1;
1632 VAdjustDiskUsage(&temp, volptr, - BlocksPreallocatedForVnode,
1634 IH_REALLYCLOSE((*targetptr)->handle);
1635 if ( IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1636 ViceLog(0,("Alloc_NewVnode: partition %s idec %s failed\n",
1637 volptr->partition->name,
1638 PrintInode(NULL, inode)));
1639 IH_RELEASE((*targetptr)->handle);
1645 } /*Alloc_NewVnode*/
1649 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1653 HandleLocking(Vnode *targetptr, afs_int32 rights, ViceLockType LockingType)
1655 int Time; /* Used for time */
1656 int writeVnode = targetptr->changed_oldTime; /* save original status */
1658 /* Does the caller has Lock priviledges; root extends locks, however */
1659 if (LockingType != LockExtend && !(rights & PRSFS_LOCK))
1661 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1662 Time = FT_ApproxTime();
1663 switch (LockingType) {
1666 if (Time > targetptr->disk.lock.lockTime)
1667 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount = 0;
1668 Time += AFS_LOCKWAIT;
1669 if (LockingType == LockRead) {
1670 if (targetptr->disk.lock.lockCount >= 0) {
1671 ++(targetptr->disk.lock.lockCount);
1672 targetptr->disk.lock.lockTime = Time;
1673 } else return(EAGAIN);
1675 if (targetptr->disk.lock.lockCount == 0) {
1676 targetptr->disk.lock.lockCount = -1;
1677 targetptr->disk.lock.lockTime = Time;
1678 } else return(EAGAIN);
1682 Time += AFS_LOCKWAIT;
1683 if (targetptr->disk.lock.lockCount != 0)
1684 targetptr->disk.lock.lockTime = Time;
1685 else return(EINVAL);
1688 if ((--targetptr->disk.lock.lockCount) <= 0)
1689 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime = 0;
1692 targetptr->changed_oldTime = writeVnode; /* restore old status */
1693 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1698 /* 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. */
1701 CheckWriteMode(Vnode *targetptr, afs_int32 rights, int Prfs_Mode)
1705 if (!(rights & Prfs_Mode))
1707 if ((targetptr->disk.type != vDirectory) && (!(targetptr->disk.modeBits & OWNERWRITE)))
1713 * If some flags (i.e. min or max quota) are set, the volume's in disk
1714 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1715 * update, if applicable.
1718 RXUpdate_VolumeStatus(Volume *volptr, AFSStoreVolumeStatus* StoreVolStatus,
1719 char *Name, char *OfflineMsg, char *Motd)
1721 Error errorCode = 0;
1723 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1724 V_minquota(volptr) = StoreVolStatus->MinQuota;
1725 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1726 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1727 if (strlen(OfflineMsg) > 0) {
1728 strcpy(V_offlineMessage(volptr), OfflineMsg);
1730 if (strlen(Name) > 0) {
1731 strcpy(V_name(volptr), Name);
1733 #if TRANSARC_VOL_STATS
1735 * We don't overwrite the motd field, since it's now being used
1739 if (strlen(Motd) > 0) {
1740 strcpy(V_motd(volptr), Motd);
1742 #endif /* FS_STATS_DETAILED */
1743 VUpdateVolume(&errorCode, volptr);
1746 } /*RXUpdate_VolumeStatus*/
1751 Update_VolumeStatus(Volume *volptr, VolumeStatus *StoreVolStatus,
1752 struct BBS *Name, struct BBS *OfflineMsg,
1755 Error errorCode = 0;
1757 if (StoreVolStatus->MinQuota > -1)
1758 V_minquota(volptr) = StoreVolStatus->MinQuota;
1759 if (StoreVolStatus->MaxQuota > -1)
1760 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1761 if (OfflineMsg->SeqLen > 1)
1762 strcpy(V_offlineMessage(volptr), OfflineMsg->SeqBody);
1763 if (Name->SeqLen > 1)
1764 strcpy(V_name(volptr), Name->SeqBody);
1765 #if TRANSARC_VOL_STATS
1767 * We don't overwrite the motd field, since it's now being used
1771 if (Motd->SeqLen > 1)
1772 strcpy(V_motd(volptr), Motd->SeqBody);
1773 #endif /* FS_STATS_DETAILED */
1774 VUpdateVolume(&errorCode, volptr);
1777 } /*Update_VolumeStatus*/
1781 * Get internal volume-related statistics from the Volume disk label
1782 * structure and put it into the VolumeStatus structure, status; it's
1783 * used by both SAFS_GetVolumeStatus and SAFS_SetVolumeStatus to return
1784 * the volume status to the caller.
1787 GetVolumeStatus(VolumeStatus *status, struct BBS *name, struct BBS *offMsg,
1788 struct BBS *motd, Volume *volptr)
1790 status->Vid = V_id(volptr);
1791 status->ParentId = V_parentId(volptr);
1792 status->Online = V_inUse(volptr);
1793 status->InService = V_inService(volptr);
1794 status->Blessed = V_blessed(volptr);
1795 status->NeedsSalvage = V_needsSalvaged(volptr);
1796 if (VolumeWriteable(volptr))
1797 status->Type = ReadWrite;
1799 status->Type = ReadOnly;
1800 status->MinQuota = V_minquota(volptr);
1801 status->MaxQuota = V_maxquota(volptr);
1802 status->BlocksInUse = V_diskused(volptr);
1803 status->PartBlocksAvail = volptr->partition->free;
1804 status->PartMaxBlocks = volptr->partition->totalUsable;
1805 strncpy(name->SeqBody, V_name(volptr), (int)name->MaxSeqLen);
1806 name->SeqLen = strlen(V_name(volptr)) + 1;
1807 if (name->SeqLen > name->MaxSeqLen) name->SeqLen = name -> MaxSeqLen;
1808 strncpy(offMsg->SeqBody, V_offlineMessage(volptr), (int)name->MaxSeqLen);
1809 offMsg->SeqLen = strlen(V_offlineMessage(volptr)) + 1;
1810 if (offMsg->SeqLen > offMsg->MaxSeqLen)
1811 offMsg->SeqLen = offMsg -> MaxSeqLen;
1813 /*Don't do anything with the motd field*/
1814 strncpy(motd->SeqBody, nullString, (int)offMsg->MaxSeqLen);
1815 motd->SeqLen = strlen(nullString) + 1;
1817 if (motd->SeqLen > motd->MaxSeqLen)
1818 motd->SeqLen = motd -> MaxSeqLen;
1820 } /*GetVolumeStatus*/
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 TRANSARC_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) return 0;
1888 while ((tc = *aname++)) {
1889 if (tc == '/') return 0; /* very bad character to encounter */
1891 return 1; /* file name is ok */
1896 /* Debugging tool to print Volume Statu's contents */
1898 PrintVolumeStatus(VolumeStatus *status)
1900 ViceLog(5,("Volume header contains:\n"));
1901 ViceLog(5,("Vid = %u, Parent = %u, Online = %d, InService = %d, Blessed = %d, NeedsSalvage = %d\n",
1902 status->Vid, status->ParentId, status->Online, status->InService,
1903 status->Blessed, status->NeedsSalvage));
1904 ViceLog(5,("MinQuota = %d, MaxQuota = %d\n", status->MinQuota, status->MaxQuota));
1905 ViceLog(5,("Type = %d, BlocksInUse = %d, PartBlocksAvail = %d, PartMaxBlocks = %d\n",
1906 status->Type, status->BlocksInUse, status->PartBlocksAvail, status->PartMaxBlocks));
1908 } /*PrintVolumeStatus*/
1912 * This variant of symlink is expressly to support the AFS/DFS translator
1913 * and is not supported by the AFS fileserver. We just return EINVAL.
1914 * The cache manager should not generate this call to an AFS cache manager.
1916 afs_int32 SRXAFS_DFSSymlink (struct rx_call *acall,
1917 struct AFSFid *DirFid,
1920 struct AFSStoreStatus *InStatus,
1921 struct AFSFid *OutFid,
1922 struct AFSFetchStatus *OutFidStatus,
1923 struct AFSFetchStatus *OutDirStatus,
1924 struct AFSCallBack *CallBack,
1925 struct AFSVolSync *Sync)
1930 afs_int32 SRXAFS_ResidencyCmd (struct rx_call *acall, struct AFSFid *Fid,
1931 struct ResidencyCmdInputs *Inputs,
1932 struct ResidencyCmdOutputs *Outputs)
1937 static struct afs_buffer {
1938 struct afs_buffer *next;
1939 } *freeBufferList = 0;
1940 static int afs_buffersAlloced = 0;
1942 static FreeSendBuffer(register struct afs_buffer *adata)
1945 afs_buffersAlloced--;
1946 adata->next = freeBufferList;
1947 freeBufferList = adata;
1951 } /*FreeSendBuffer*/
1953 /* allocate space for sender */
1954 static char *AllocSendBuffer()
1956 register struct afs_buffer *tp;
1959 afs_buffersAlloced++;
1960 if (!freeBufferList) {
1964 tmp = malloc(sendBufSize);
1966 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
1971 tp = freeBufferList;
1972 freeBufferList = tp->next;
1976 } /*AllocSendBuffer*/
1979 * This routine returns the status info associated with the targetptr vnode
1980 * in the AFSFetchStatus structure. Some of the newer fields, such as
1981 * SegSize and Group are not yet implemented
1984 void GetStatus(Vnode *targetptr,
1985 AFSFetchStatus *status,
1987 afs_int32 anyrights,
1990 /* initialize return status from a vnode */
1991 status->InterfaceVersion = 1;
1992 status->SyncCounter = status->dataVersionHigh = status->lockCount =
1993 status->errorCode = 0;
1994 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
1995 if (targetptr->disk.type == vFile)
1996 status->FileType = File;
1997 else if (targetptr->disk.type == vDirectory)
1998 status->FileType = Directory;
1999 else if (targetptr->disk.type == vSymlink)
2000 status->FileType = SymbolicLink;
2002 status->FileType = Invalid; /*invalid type field */
2003 status->LinkCount = targetptr->disk.linkCount;
2004 SET_STATUS_LEN(status, targetptr);
2005 status->DataVersion = targetptr->disk.dataVersion;
2006 status->Author = targetptr->disk.author;
2007 status->Owner = targetptr->disk.owner;
2008 status->CallerAccess = rights;
2009 status->AnonymousAccess = anyrights;
2010 status->UnixModeBits = targetptr->disk.modeBits;
2011 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2012 status->ParentVnode = (status->FileType == Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2013 status->ParentUnique = (status->FileType == Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2014 status->ServerModTime = targetptr->disk.serverModifyTime;
2015 status->Group = targetptr->disk.group;
2016 status->lockCount = targetptr->disk.lock.lockCount;
2017 status->errorCode = 0;
2022 afs_int32 common_FetchData64 (struct rx_call *acall,
2026 struct AFSFetchStatus *OutStatus,
2027 struct AFSCallBack *CallBack,
2028 struct AFSVolSync *Sync,
2031 Vnode * targetptr = 0; /* pointer to vnode to fetch */
2032 Vnode * parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2033 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2034 int errorCode = 0; /* return code to caller */
2035 int fileCode = 0; /* return code from vol package */
2036 Volume * volptr = 0; /* pointer to the volume */
2037 struct client *client; /* pointer to the client data */
2038 struct rx_connection *tcon; /* the connection we're part of */
2039 afs_int32 rights, anyrights; /* rights for this and any user */
2040 struct client *t_client; /* tmp ptr to client data */
2041 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2042 #if FS_STATS_DETAILED
2043 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2044 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2045 struct timeval opStartTime,
2046 opStopTime; /* Start/stop times for RPC op*/
2047 struct timeval xferStartTime,
2048 xferStopTime; /* Start/stop times for xfer portion*/
2049 struct timeval elapsedTime; /* Transfer time */
2050 afs_size_t bytesToXfer; /* # bytes to xfer*/
2051 afs_size_t bytesXferred; /* # bytes actually xferred*/
2052 int readIdx; /* Index of read stats array to bump*/
2053 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2056 * Set our stats pointers, remember when the RPC operation started, and
2057 * tally the operation.
2059 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2060 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2064 TM_GetTimeOfDay(&opStartTime, 0);
2065 #endif /* FS_STATS_DETAILED */
2067 ViceLog(1,("SRXAFS_FetchData, Fid = %u.%d.%d\n",
2068 Fid->Volume, Fid->Vnode, Fid->Unique));
2070 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2073 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
2076 /* Get ptr to client data for user Id for logging */
2077 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2078 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2079 ViceLog(5,("SRXAFS_FetchData, Fid = %u.%d.%d, Host %s, Id %d\n",
2080 Fid->Volume, Fid->Vnode, Fid->Unique,
2081 inet_ntoa(logHostAddr), t_client->ViceId));
2083 * Get volume/vnode for the fetched file; caller's access rights to
2084 * it are also returned
2086 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
2087 DONTCHECK, &parentwhentargetnotdir,
2088 &client, READ_LOCK, &rights, &anyrights)))
2091 SetVolumeSync(Sync, volptr);
2093 #if FS_STATS_DETAILED
2095 * Remember that another read operation was performed.
2098 if (client->InSameNetwork)
2099 readIdx = VOL_STATS_SAME_NET;
2101 readIdx = VOL_STATS_DIFF_NET;
2102 V_stat_reads(volptr, readIdx)++;
2103 if (client->ViceId != AnonymousID) {
2104 V_stat_reads(volptr, readIdx+1)++;
2107 #endif /* FS_STATS_DETAILED */
2109 /* Check whether the caller has permission access to fetch the data */
2110 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
2115 * Drop the read lock on the parent directory after saving the parent
2116 * vnode information we need to pass to GetStatus
2118 if (parentwhentargetnotdir != NULL) {
2119 tparentwhentargetnotdir = *parentwhentargetnotdir;
2120 VPutVnode(&fileCode, parentwhentargetnotdir);
2121 assert(!fileCode || (fileCode == VSALVAGE));
2122 parentwhentargetnotdir = NULL;
2125 #if FS_STATS_DETAILED
2127 * Remember when the data transfer started.
2129 TM_GetTimeOfDay(&xferStartTime, 0);
2130 #endif /* FS_STATS_DETAILED */
2132 /* actually do the data transfer */
2133 #if FS_STATS_DETAILED
2134 errorCode = FetchData_RXStyle(volptr, targetptr, acall,
2135 (afs_size_t) Pos, (afs_size_t) Len, type,
2136 &bytesToXfer, &bytesXferred);
2138 if ((errorCode = FetchData_RXStyle(volptr, targetptr, acall,
2139 (afs_size_t) Pos, (afs_size_t) Len,
2142 #endif /* FS_STATS_DETAILED */
2144 #if FS_STATS_DETAILED
2146 * At this point, the data transfer is done, for good or ill. Remember
2147 * when the transfer ended, bump the number of successes/failures, and
2148 * integrate the transfer size and elapsed time into the stats. If the
2149 * operation failed, we jump to the appropriate point.
2151 TM_GetTimeOfDay(&xferStopTime, 0);
2153 (xferP->numXfers)++;
2155 (xferP->numSuccesses)++;
2158 * Bump the xfer sum by the number of bytes actually sent, NOT the
2161 tot_bytesXferred += bytesXferred;
2162 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2163 tot_bytesXferred &= 0x3FF;
2164 if (bytesXferred < xferP->minBytes)
2165 xferP->minBytes = bytesXferred;
2166 if (bytesXferred > xferP->maxBytes)
2167 xferP->maxBytes = bytesXferred;
2170 * Tally the size of the object. Note: we tally the actual size,
2171 * NOT the number of bytes that made it out over the wire.
2173 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2174 (xferP->count[0])++;
2176 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2177 (xferP->count[1])++;
2179 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2180 (xferP->count[2])++;
2182 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2183 (xferP->count[3])++;
2185 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2186 (xferP->count[4])++;
2188 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2189 (xferP->count[5])++;
2191 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2192 (xferP->count[6])++;
2194 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2195 (xferP->count[7])++;
2197 (xferP->count[8])++;
2199 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2200 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2201 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2202 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2203 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2205 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2206 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2211 * Finally, go off to tell our caller the bad news in case the
2216 #endif /* FS_STATS_DETAILED */
2218 /* write back the OutStatus from the target vnode */
2219 GetStatus(targetptr, OutStatus, rights, anyrights, &tparentwhentargetnotdir);
2221 /* if a r/w volume, promise a callback to the caller */
2222 if (VolumeWriteable(volptr))
2223 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2225 struct AFSFid myFid;
2226 memset(&myFid, 0, sizeof(struct AFSFid));
2227 myFid.Volume = Fid->Volume;
2228 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2232 /* Update and store volume/vnode and parent vnodes back */
2233 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
2234 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2235 CallPostamble(tcon);
2237 #if FS_STATS_DETAILED
2238 TM_GetTimeOfDay(&opStopTime, 0);
2239 if (errorCode == 0) {
2241 (opP->numSuccesses)++;
2242 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2243 fs_stats_AddTo((opP->sumTime), elapsedTime);
2244 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2245 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2246 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2248 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2249 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2254 #endif /* FS_STATS_DETAILED */
2256 osi_auditU (acall, FetchDataEvent, errorCode, AUD_FID, Fid, AUD_END);
2259 } /*common_FetchData64*/
2261 afs_int32 SRXAFS_FetchData (struct rx_call *acall,
2265 struct AFSFetchStatus *OutStatus,
2266 struct AFSCallBack *CallBack,
2267 struct AFSVolSync *Sync)
2272 code = common_FetchData64 (acall, Fid,
2273 (afs_size_t) Pos, (afs_size_t) Len,
2279 afs_int32 SRXAFS_FetchData64 (struct rx_call *acall,
2283 struct AFSFetchStatus *OutStatus,
2284 struct AFSCallBack *CallBack,
2285 struct AFSVolSync *Sync)
2288 afs_size_t tPos, tLen;
2290 #ifdef AFS_64BIT_ENV
2291 #ifndef AFS_LARGEFILE_ENV
2292 if (Pos + Len > 0x7fffffff)
2294 #endif /* !AFS_LARGEFILE_ENV */
2297 #else /* AFS_64BIT_ENV */
2298 if (Pos.high || Len.high)
2302 #endif /* AFS_64BIT_ENV */
2304 code = common_FetchData64 (acall, Fid, tPos, tLen, OutStatus,
2309 afs_int32 SRXAFS_FetchACL (struct rx_call *acall,
2311 struct AFSOpaque *AccessList,
2312 struct AFSFetchStatus *OutStatus,
2313 struct AFSVolSync *Sync)
2315 Vnode * targetptr = 0; /* pointer to vnode to fetch */
2316 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2317 int errorCode = 0; /* return error code to caller */
2318 Volume * volptr = 0; /* pointer to the volume */
2319 struct client *client; /* pointer to the client data */
2320 afs_int32 rights, anyrights; /* rights for this and any user */
2321 struct rx_connection *tcon = rx_ConnectionOf(acall);
2322 struct client *t_client; /* tmp ptr to client data */
2323 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2324 #if FS_STATS_DETAILED
2325 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2326 struct timeval opStartTime,
2327 opStopTime; /* Start/stop times for RPC op*/
2328 struct timeval elapsedTime; /* Transfer time */
2331 * Set our stats pointer, remember when the RPC operation started, and
2332 * tally the operation.
2334 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2338 TM_GetTimeOfDay(&opStartTime, 0);
2339 #endif /* FS_STATS_DETAILED */
2341 ViceLog(1, ("SAFS_FetchACL, Fid = %u.%d.%d\n",
2342 Fid->Volume, Fid->Vnode, Fid->Unique));
2344 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2346 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2349 /* Get ptr to client data for user Id for logging */
2350 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2351 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2352 ViceLog(5, ("SAFS_FetchACL, Fid = %u.%d.%d, Host %s, Id %d\n",
2353 Fid->Volume, Fid->Vnode, Fid->Unique,
2354 inet_ntoa(logHostAddr), t_client->ViceId));
2356 AccessList->AFSOpaque_len = 0;
2357 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2358 if (!AccessList->AFSOpaque_val) {
2359 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2364 * Get volume/vnode for the fetched file; caller's access rights to it
2367 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
2368 DONTCHECK, &parentwhentargetnotdir,
2369 &client, READ_LOCK, &rights, &anyrights)))
2372 SetVolumeSync(Sync, volptr);
2374 /* Check whether we have permission to fetch the ACL */
2375 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
2379 /* Get the Access List from the dir's vnode */
2380 if ((errorCode = RXFetch_AccessList(targetptr, parentwhentargetnotdir,
2384 /* Get OutStatus back From the target Vnode */
2385 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
2388 /* Update and store volume/vnode and parent vnodes back */
2389 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
2390 ViceLog(2, ("SAFS_FetchACL returns %d (ACL=%s)\n",
2391 errorCode, AccessList->AFSOpaque_val));
2392 CallPostamble(tcon);
2394 #if FS_STATS_DETAILED
2395 TM_GetTimeOfDay(&opStopTime, 0);
2396 if (errorCode == 0) {
2398 (opP->numSuccesses)++;
2399 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2400 fs_stats_AddTo((opP->sumTime), elapsedTime);
2401 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2402 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2403 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2405 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2406 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2411 #endif /* FS_STATS_DETAILED */
2413 osi_auditU (acall, FetchACLEvent, errorCode, AUD_FID, Fid, AUD_END);
2415 } /*SRXAFS_FetchACL*/
2419 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2420 * merged into it when possible.
2423 afs_int32 SAFSS_FetchStatus (struct rx_call *acall,
2425 struct AFSFetchStatus *OutStatus,
2426 struct AFSCallBack *CallBack,
2427 struct AFSVolSync *Sync)
2429 Vnode * targetptr = 0; /* pointer to vnode to fetch */
2430 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2431 int errorCode = 0; /* return code to caller */
2432 Volume * volptr = 0; /* pointer to the volume */
2433 struct client *client; /* pointer to the client data */
2434 afs_int32 rights, anyrights; /* rights for this and any user */
2435 struct client *t_client; /* tmp ptr to client data */
2436 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2437 struct rx_connection *tcon = rx_ConnectionOf(acall);
2439 /* Get ptr to client data for user Id for logging */
2440 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2441 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2442 ViceLog(1, ("SAFS_FetchStatus, Fid = %u.%d.%d, Host %s, Id %d\n",
2443 Fid->Volume, Fid->Vnode, Fid->Unique,
2444 inet_ntoa(logHostAddr), t_client->ViceId));
2446 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2449 * Get volume/vnode for the fetched file; caller's rights to it are
2452 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
2453 DONTCHECK, &parentwhentargetnotdir,
2454 &client, READ_LOCK, &rights, &anyrights)))
2455 goto Bad_FetchStatus;
2457 /* set volume synchronization information */
2458 SetVolumeSync(Sync, volptr);
2460 /* Are we allowed to fetch Fid's status? */
2461 if (targetptr->disk.type != vDirectory) {
2462 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
2463 CHK_FETCHSTATUS, 0))) {
2464 if (rx_GetCallAbortCode(acall) == errorCode)
2465 rx_SetCallAbortCode(acall, 0);
2466 goto Bad_FetchStatus;
2470 /* set OutStatus From the Fid */
2471 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
2473 /* If a r/w volume, also set the CallBack state */
2474 if (VolumeWriteable(volptr))
2475 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2477 struct AFSFid myFid;
2478 memset(&myFid, 0, sizeof(struct AFSFid));
2479 myFid.Volume = Fid->Volume;
2480 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2484 /* Update and store volume/vnode and parent vnodes back */
2485 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
2486 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2489 } /*SAFSS_FetchStatus*/
2492 afs_int32 SRXAFS_BulkStatus(struct rx_call *acall,
2493 struct AFSCBFids *Fids,
2494 struct AFSBulkStats *OutStats,
2495 struct AFSCBs *CallBacks,
2496 struct AFSVolSync *Sync)
2500 Vnode * targetptr = 0; /* pointer to vnode to fetch */
2501 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2502 int errorCode = 0; /* return code to caller */
2503 Volume * volptr = 0; /* pointer to the volume */
2504 struct client *client; /* pointer to the client data */
2505 afs_int32 rights, anyrights; /* rights for this and any user */
2506 register struct AFSFid *tfid; /* file id we're dealing with now */
2507 struct rx_connection *tcon = rx_ConnectionOf(acall);
2508 #if FS_STATS_DETAILED
2509 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2510 struct timeval opStartTime,
2511 opStopTime; /* Start/stop times for RPC op*/
2512 struct timeval elapsedTime; /* Transfer time */
2515 * Set our stats pointer, remember when the RPC operation started, and
2516 * tally the operation.
2518 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2522 TM_GetTimeOfDay(&opStartTime, 0);
2523 #endif /* FS_STATS_DETAILED */
2525 ViceLog(1, ("SAFS_BulkStatus\n"));
2527 AFSCallStats.TotalCalls++;
2530 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2531 if (nfiles <= 0) { /* Sanity check */
2533 goto Audit_and_Return;
2536 /* allocate space for return output parameters */
2537 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2538 malloc(nfiles * sizeof(struct AFSFetchStatus));
2539 if (!OutStats->AFSBulkStats_val) {
2540 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2543 OutStats->AFSBulkStats_len = nfiles;
2544 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2545 malloc(nfiles * sizeof(struct AFSCallBack));
2546 if (!CallBacks->AFSCBs_val) {
2547 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2550 CallBacks->AFSCBs_len = nfiles;
2552 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2553 goto Bad_BulkStatus;
2555 tfid = Fids->AFSCBFids_val;
2556 for (i=0; i<nfiles; i++, tfid++) {
2558 * Get volume/vnode for the fetched file; caller's rights to it
2562 GetVolumePackage(tcon, tfid, &volptr, &targetptr,
2563 DONTCHECK, &parentwhentargetnotdir, &client,
2564 READ_LOCK, &rights, &anyrights)))
2565 goto Bad_BulkStatus;
2566 /* set volume synchronization information, but only once per call */
2568 SetVolumeSync(Sync, volptr);
2570 /* Are we allowed to fetch Fid's status? */
2571 if (targetptr->disk.type != vDirectory) {
2572 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
2573 CHK_FETCHSTATUS, 0))) {
2574 if (rx_GetCallAbortCode(acall) == errorCode)
2575 rx_SetCallAbortCode(acall, 0);
2576 goto Bad_BulkStatus;
2580 /* set OutStatus From the Fid */
2581 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i],
2582 rights, anyrights, parentwhentargetnotdir);
2584 /* If a r/w volume, also set the CallBack state */
2585 if (VolumeWriteable(volptr))
2586 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2587 &CallBacks->AFSCBs_val[i]);
2589 struct AFSFid myFid;
2590 memset(&myFid, 0, sizeof(struct AFSFid));
2591 myFid.Volume = tfid->Volume;
2592 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2593 &CallBacks->AFSCBs_val[i]);
2596 /* put back the file ID and volume */
2597 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
2598 parentwhentargetnotdir = (Vnode *) 0;
2599 targetptr = (Vnode *) 0;
2600 volptr = (Volume *) 0;
2604 /* Update and store volume/vnode and parent vnodes back */
2605 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
2606 CallPostamble(tcon);
2608 #if FS_STATS_DETAILED
2609 TM_GetTimeOfDay(&opStopTime, 0);
2610 if (errorCode == 0) {
2612 (opP->numSuccesses)++;
2613 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2614 fs_stats_AddTo((opP->sumTime), elapsedTime);
2615 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2616 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2617 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2619 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2620 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2625 #endif /* FS_STATS_DETAILED */
2628 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2629 osi_auditU (acall, BulkFetchStatusEvent, errorCode, AUD_FIDS, Fids, AUD_END);
2632 } /*SRXAFS_BulkStatus*/
2635 afs_int32 SRXAFS_InlineBulkStatus(struct rx_call *acall,
2636 struct AFSCBFids *Fids,
2637 struct AFSBulkStats *OutStats,
2638 struct AFSCBs *CallBacks,
2639 struct AFSVolSync *Sync)
2643 Vnode * targetptr = 0; /* pointer to vnode to fetch */
2644 Vnode * parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2645 int errorCode = 0; /* return code to caller */
2646 Volume * volptr = 0; /* pointer to the volume */
2647 struct client *client; /* pointer to the client data */
2648 afs_int32 rights, anyrights; /* rights for this and any user */
2649 register struct AFSFid *tfid; /* file id we're dealing with now */
2650 struct rx_connection *tcon;
2651 AFSFetchStatus *tstatus;
2652 #if FS_STATS_DETAILED
2653 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2654 struct timeval opStartTime,
2655 opStopTime; /* Start/stop times for RPC op*/
2656 struct timeval elapsedTime; /* Transfer time */
2659 * Set our stats pointer, remember when the RPC operation started, and
2660 * tally the operation.
2662 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2666 TM_GetTimeOfDay(&opStartTime, 0);
2667 #endif /* FS_STATS_DETAILED */
2669 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2671 AFSCallStats.TotalCalls++;
2674 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2675 if (nfiles <= 0) { /* Sanity check */
2677 goto Audit_and_Return;
2680 /* allocate space for return output parameters */
2681 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2682 malloc(nfiles * sizeof(struct AFSFetchStatus));
2683 if (!OutStats->AFSBulkStats_val) {
2684 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2687 OutStats->AFSBulkStats_len = nfiles;
2688 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2689 malloc(nfiles * sizeof(struct AFSCallBack));
2690 if (!CallBacks->AFSCBs_val) {
2691 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2694 CallBacks->AFSCBs_len = nfiles;
2696 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon))) {
2697 goto Bad_InlineBulkStatus;
2700 tfid = Fids->AFSCBFids_val;
2701 for (i=0; i<nfiles; i++, tfid++) {
2703 * Get volume/vnode for the fetched file; caller's rights to it
2707 GetVolumePackage(tcon, tfid, &volptr, &targetptr,
2708 DONTCHECK, &parentwhentargetnotdir, &client,
2709 READ_LOCK, &rights, &anyrights))) {
2710 tstatus = &OutStats->AFSBulkStats_val[i];
2711 tstatus->errorCode = errorCode;
2712 parentwhentargetnotdir = (Vnode *) 0;
2713 targetptr = (Vnode *) 0;
2714 volptr = (Volume *) 0;
2718 /* set volume synchronization information, but only once per call */
2720 SetVolumeSync(Sync, volptr);
2722 /* Are we allowed to fetch Fid's status? */
2723 if (targetptr->disk.type != vDirectory) {
2724 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
2725 CHK_FETCHSTATUS, 0))) {
2726 tstatus = &OutStats->AFSBulkStats_val[i];
2727 tstatus->errorCode = errorCode;
2728 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
2729 parentwhentargetnotdir = (Vnode *) 0;
2730 targetptr = (Vnode *) 0;
2731 volptr = (Volume *) 0;
2736 /* set OutStatus From the Fid */
2737 GetStatus(targetptr, (struct AFSFetchStatus *) &OutStats->AFSBulkStats_val[i],
2738 rights, anyrights, parentwhentargetnotdir);
2740 /* If a r/w volume, also set the CallBack state */
2741 if (VolumeWriteable(volptr))
2742 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2743 &CallBacks->AFSCBs_val[i]);
2745 struct AFSFid myFid;
2746 memset(&myFid, 0, sizeof(struct AFSFid));
2747 myFid.Volume = tfid->Volume;
2748 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2749 &CallBacks->AFSCBs_val[i]);
2752 /* put back the file ID and volume */
2753 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0, volptr);
2754 parentwhentargetnotdir = (Vnode *) 0;
2755 targetptr = (Vnode *) 0;
2756 volptr = (Volume *) 0;
2759 Bad_InlineBulkStatus:
2760 /* Update and store volume/vnode and parent vnodes back */
2761 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
2762 CallPostamble(tcon);
2764 #if FS_STATS_DETAILED
2765 TM_GetTimeOfDay(&opStopTime, 0);
2766 if (errorCode == 0) {
2768 (opP->numSuccesses)++;
2769 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2770 fs_stats_AddTo((opP->sumTime), elapsedTime);
2771 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2772 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2773 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2775 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2776 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2781 #endif /* FS_STATS_DETAILED */
2784 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2785 osi_auditU (acall, InlineBulkFetchStatusEvent, errorCode, AUD_FIDS, Fids, AUD_END);
2788 } /*SRXAFS_InlineBulkStatus*/
2791 afs_int32 SRXAFS_FetchStatus (struct rx_call *acall,
2793 struct AFSFetchStatus *OutStatus,
2794 struct AFSCallBack *CallBack,
2795 struct AFSVolSync *Sync)
2798 struct rx_connection *tcon;
2799 #if FS_STATS_DETAILED
2800 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2801 struct timeval opStartTime,
2802 opStopTime; /* Start/stop times for RPC op*/
2803 struct timeval elapsedTime; /* Transfer time */
2806 * Set our stats pointer, remember when the RPC operation started, and
2807 * tally the operation.
2809 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2813 TM_GetTimeOfDay(&opStartTime, 0);
2814 #endif /* FS_STATS_DETAILED */
2816 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
2817 goto Bad_FetchStatus;
2819 code = SAFSS_FetchStatus (acall, Fid, OutStatus, CallBack, Sync);
2822 CallPostamble(tcon);
2824 #if FS_STATS_DETAILED
2825 TM_GetTimeOfDay(&opStopTime, 0);
2828 (opP->numSuccesses)++;
2829 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2830 fs_stats_AddTo((opP->sumTime), elapsedTime);
2831 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2832 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2833 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2835 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2836 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2841 #endif /* FS_STATS_DETAILED */
2843 osi_auditU (acall, FetchStatusEvent, code, AUD_FID, Fid, AUD_END);
2846 } /*SRXAFS_FetchStatus*/
2849 afs_int32 common_StoreData64 (struct rx_call *acall,
2851 struct AFSStoreStatus *InStatus,
2854 afs_offs_t FileLength,
2855 struct AFSFetchStatus *OutStatus,
2856 struct AFSVolSync *Sync)
2858 Vnode * targetptr = 0; /* pointer to input fid */
2859 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2860 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2861 int errorCode = 0; /* return code for caller */
2862 int fileCode = 0; /* return code from vol package */
2863 Volume * volptr = 0; /* pointer to the volume header */
2864 struct client * client; /* pointer to client structure */
2865 afs_int32 rights, anyrights; /* rights for this and any user */
2866 struct client *t_client; /* tmp ptr to client data */
2867 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2868 struct rx_connection *tcon;
2869 #if FS_STATS_DETAILED
2870 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2871 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2872 struct timeval opStartTime,
2873 opStopTime; /* Start/stop times for RPC op*/
2874 struct timeval xferStartTime,
2875 xferStopTime; /* Start/stop times for xfer portion*/
2876 struct timeval elapsedTime; /* Transfer time */
2877 afs_size_t bytesToXfer; /* # bytes to xfer */
2878 afs_size_t bytesXferred; /* # bytes actually xfer */
2879 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2882 * Set our stats pointers, remember when the RPC operation started, and
2883 * tally the operation.
2885 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2886 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2891 ViceLog(1, ("StoreData: Fid = %u.%d.%d\n",
2892 Fid->Volume, Fid->Vnode, Fid->Unique));
2893 TM_GetTimeOfDay(&opStartTime, 0);
2894 #endif /* FS_STATS_DETAILED */
2897 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2900 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2903 /* Get ptr to client data for user Id for logging */
2904 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
2905 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
2906 ViceLog(5, ("StoreData: Fid = %u.%d.%d, Host %s, Id %d\n",
2907 Fid->Volume, Fid->Vnode, Fid->Unique,
2908 inet_ntoa(logHostAddr), t_client->ViceId));
2909 #ifdef AFS_LARGEFILE_ENV
2910 ViceLog(25, ("StoreData: Fid = %u.%d.%d, Host %s, Id %d, Pos (0X%x,0X%x), Len (0X%x,0X%x), FileLen (0X%x,0X%x)\n",
2911 Fid->Volume, Fid->Vnode, Fid->Unique,
2912 inet_ntoa(logHostAddr), t_client->ViceId,
2913 (unsigned) (Pos >> 32), (unsigned) (Pos & 0xffffffff),
2914 (unsigned) (Length >> 32), (unsigned) (Length & 0xffffffff),
2915 (unsigned) (FileLength >> 32), (unsigned) (FileLength & 0xffffffff)));
2916 #else /* !AFS_LARGEFILE_ENV */
2917 ViceLog(25, ("StoreData: Fid = %u.%d.%d, Host %s, Id %d, Pos 0X%x, Len 0X%x, FileLen 0X%x\n",
2918 Fid->Volume, Fid->Vnode, Fid->Unique,
2919 inet_ntoa(logHostAddr), t_client->ViceId,
2923 #endif /* !AFS_LARGEFILE_ENV */
2927 * Get associated volume/vnode for the stored file; caller's rights
2930 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
2931 MustNOTBeDIR, &parentwhentargetnotdir,
2932 &client, WRITE_LOCK, &rights, &anyrights))) {
2936 /* set volume synchronization information */
2937 SetVolumeSync(Sync, volptr);
2939 if ((targetptr->disk.type == vSymlink)) {
2940 /* Should we return a better error code here??? */
2945 /* Check if we're allowed to store the data */
2946 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
2947 CHK_STOREDATA, InStatus))) {
2952 * Drop the read lock on the parent directory after saving the parent
2953 * vnode information we need to pass to GetStatus
2955 if (parentwhentargetnotdir != NULL) {
2956 tparentwhentargetnotdir = *parentwhentargetnotdir;
2957 VPutVnode(&fileCode, parentwhentargetnotdir);
2958 assert(!fileCode || (fileCode == VSALVAGE));
2959 parentwhentargetnotdir = NULL;
2964 #if FS_STATS_DETAILED
2966 * Remember when the data transfer started.
2968 TM_GetTimeOfDay(&xferStartTime, 0);
2969 #endif /* FS_STATS_DETAILED */
2971 /* Do the actual storing of the data */
2972 #if FS_STATS_DETAILED
2973 errorCode = StoreData_RXStyle(volptr, targetptr, Fid, client, acall,
2974 (afs_size_t) Pos, (afs_size_t) Length,
2975 (afs_size_t) FileLength,
2976 (InStatus->Mask & AFS_FSYNC),
2977 &bytesToXfer, &bytesXferred);
2979 errorCode = StoreData_RXStyle(volptr, targetptr, Fid, client,
2981 (afs_size_t) Pos, (afs_size_t) Length,
2982 (afs_size_t) FileLength,
2983 (InStatus->Mask & AFS_FSYNC));
2984 if (errorCode && (!targetptr->changed_newTime))
2986 #endif /* FS_STATS_DETAILED */
2987 #if FS_STATS_DETAILED
2989 * At this point, the data transfer is done, for good or ill. Remember
2990 * when the transfer ended, bump the number of successes/failures, and
2991 * integrate the transfer size and elapsed time into the stats. If the
2992 * operation failed, we jump to the appropriate point.
2994 TM_GetTimeOfDay(&xferStopTime, 0);
2996 (xferP->numXfers)++;
2998 (xferP->numSuccesses)++;
3001 * Bump the xfer sum by the number of bytes actually sent, NOT the
3004 tot_bytesXferred += bytesXferred;
3005 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3006 tot_bytesXferred &= 0x3FF;
3007 if (bytesXferred < xferP->minBytes)
3008 xferP->minBytes = bytesXferred;
3009 if (bytesXferred > xferP->maxBytes)
3010 xferP->maxBytes = bytesXferred;
3013 * Tally the size of the object. Note: we tally the actual size,
3014 * NOT the number of bytes that made it out over the wire.
3016 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3017 (xferP->count[0])++;
3019 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3020 (xferP->count[1])++;
3022 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3023 (xferP->count[2])++;
3025 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3026 (xferP->count[3])++;
3028 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3029 (xferP->count[4])++;
3031 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3032 (xferP->count[5])++;
3034 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3035 (xferP->count[6])++;
3037 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3038 (xferP->count[7])++;
3040 (xferP->count[8])++;
3042 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3043 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3044 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3045 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3046 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3048 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3049 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3055 * Finally, go off to tell our caller the bad news in case the
3058 if (errorCode && (!targetptr->changed_newTime))
3060 #endif /* FS_STATS_DETAILED */
3062 /* Update the status of the target's vnode */
3063 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus, targetptr,
3064 volptr, (afs_size_t) 0);
3066 /* Get the updated File's status back to the caller */
3067 GetStatus(targetptr, OutStatus, rights, anyrights, &tparentwhentargetnotdir);
3070 /* Update and store volume/vnode and parent vnodes back */
3071 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3072 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3074 CallPostamble(tcon);
3076 #if FS_STATS_DETAILED
3077 TM_GetTimeOfDay(&opStopTime, 0);
3078 if (errorCode == 0) {
3080 (opP->numSuccesses)++;
3081 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3082 fs_stats_AddTo((opP->sumTime), elapsedTime);
3083 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3084 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3085 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3087 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3088 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3092 #endif /* FS_STATS_DETAILED */
3094 osi_auditU (acall, StoreDataEvent, errorCode, AUD_FID, Fid, AUD_END);
3097 } /*common_StoreData64*/
3099 afs_int32 SRXAFS_StoreData (struct rx_call *acall,
3101 struct AFSStoreStatus *InStatus,
3104 afs_uint32 FileLength,
3105 struct AFSFetchStatus *OutStatus,
3106 struct AFSVolSync *Sync)
3110 code = common_StoreData64 (acall, Fid, InStatus, Pos, Length, FileLength,
3114 } /*SRXAFS_StoreData*/
3116 afs_int32 SRXAFS_StoreData64 (struct rx_call *acall,
3118 struct AFSStoreStatus *InStatus,
3121 afs_uint64 FileLength,
3122 struct AFSFetchStatus *OutStatus,
3123 struct AFSVolSync *Sync)
3128 afs_offs_t tFileLength;
3130 #ifdef AFS_64BIT_ENV
3131 #ifndef AFS_LARGEFILE_ENV
3132 if (FileLength > 0x7fffffff)
3134 #endif /* !AFS_LARGEFILE_ENV */
3137 tFileLength = FileLength;
3138 #else /* AFS_64BIT_ENV */
3139 if (FileLength.high)
3142 tLength = Length.low;
3143 tFileLength = FileLength.low;
3144 #endif /* AFS_64BIT_ENV */
3146 code = common_StoreData64 (acall, Fid, InStatus, tPos, tLength, tFileLength,
3151 afs_int32 SRXAFS_StoreACL (struct rx_call *acall,
3153 struct AFSOpaque *AccessList,
3154 struct AFSFetchStatus *OutStatus,
3155 struct AFSVolSync *Sync)
3157 Vnode * targetptr = 0; /* pointer to input fid */
3158 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3159 int errorCode = 0; /* return code for caller */
3160 struct AFSStoreStatus InStatus; /* Input status for fid */
3161 Volume * volptr = 0; /* pointer to the volume header */
3162 struct client * client; /* pointer to client structure */
3163 afs_int32 rights, anyrights; /* rights for this and any user */
3164 struct rx_connection *tcon;
3165 struct client *t_client; /* tmp ptr to client data */
3166 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3167 #if FS_STATS_DETAILED
3168 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3169 struct timeval opStartTime,
3170 opStopTime; /* Start/stop times for RPC op*/
3171 struct timeval elapsedTime; /* Transfer time */
3174 * Set our stats pointer, remember when the RPC operation started, and
3175 * tally the operation.
3177 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3181 TM_GetTimeOfDay(&opStartTime, 0);
3182 #endif /* FS_STATS_DETAILED */
3183 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
3186 /* Get ptr to client data for user Id for logging */
3187 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3188 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3189 ViceLog(1, ("SAFS_StoreACL, Fid = %u.%d.%d, ACL=%s, Host %s, Id %d\n",
3190 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3191 inet_ntoa(logHostAddr), t_client->ViceId));
3193 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3196 InStatus.Mask = 0; /* not storing any status */
3199 * Get associated volume/vnode for the target dir; caller's rights
3200 * are also returned.
3202 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3203 MustBeDIR, &parentwhentargetnotdir,
3204 &client, WRITE_LOCK, &rights, &anyrights))) {
3208 /* set volume synchronization information */
3209 SetVolumeSync(Sync, volptr);
3211 /* Check if we have permission to change the dir's ACL */
3212 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
3213 CHK_STOREACL, &InStatus))) {
3217 /* Build and store the new Access List for the dir */
3218 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3222 targetptr->changed_newTime = 1; /* status change of directory */
3224 /* convert the write lock to a read lock before breaking callbacks */
3225 VVnodeWriteToRead(&errorCode, targetptr);
3226 assert(!errorCode || errorCode == VSALVAGE);
3228 /* break call backs on the directory */
3229 BreakCallBack(client->host, Fid, 0);
3231 /* Get the updated dir's status back to the caller */
3232 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3235 /* Update and store volume/vnode and parent vnodes back */
3236 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3237 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3238 CallPostamble(tcon);
3240 #if FS_STATS_DETAILED
3241 TM_GetTimeOfDay(&opStopTime, 0);
3242 if (errorCode == 0) {
3244 (opP->numSuccesses)++;
3245 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3246 fs_stats_AddTo((opP->sumTime), elapsedTime);
3247 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3248 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3249 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3251 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3252 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3256 #endif /* FS_STATS_DETAILED */
3258 osi_auditU (acall, StoreACLEvent, errorCode, AUD_FID, Fid, AUD_END);
3261 } /*SRXAFS_StoreACL*/
3265 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3266 * should be merged when possible.
3269 SAFSS_StoreStatus (struct rx_call *acall,
3271 struct AFSStoreStatus *InStatus,
3272 struct AFSFetchStatus *OutStatus,
3273 struct AFSVolSync *Sync)
3276 Vnode * targetptr = 0; /* pointer to input fid */
3277 Vnode * parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3278 int errorCode = 0; /* return code for caller */
3279 Volume * volptr = 0; /* pointer to the volume header */
3280 struct client * client; /* pointer to client structure */
3281 afs_int32 rights, anyrights; /* rights for this and any user */
3282 struct client *t_client; /* tmp ptr to client data */
3283 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3284 struct rx_connection *tcon = rx_ConnectionOf(acall);
3286 /* Get ptr to client data for user Id for logging */
3287 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3288 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3289 ViceLog(1, ("SAFS_StoreStatus, Fid = %u.%d.%d, Host %s, Id %d\n",
3290 Fid->Volume, Fid->Vnode, Fid->Unique,
3291 inet_ntoa(logHostAddr), t_client->ViceId));
3293 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3296 * Get volume/vnode for the target file; caller's rights to it are
3299 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
3300 DONTCHECK, &parentwhentargetnotdir,
3301 &client, WRITE_LOCK, &rights, &anyrights))) {
3302 goto Bad_StoreStatus;
3305 /* set volume synchronization information */
3306 SetVolumeSync(Sync, volptr);
3308 /* Check if the caller has proper permissions to store status to Fid */
3309 if ((errorCode = Check_PermissionRights(targetptr, client, rights,
3310 CHK_STORESTATUS, InStatus))) {
3311 goto Bad_StoreStatus;
3314 * Check for a symbolic link; we can't chmod these (otherwise could
3315 * change a symlink to a mt pt or vice versa)
3317 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3319 goto Bad_StoreStatus;
3322 /* Update the status of the target's vnode */
3323 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3324 (parentwhentargetnotdir ?
3325 parentwhentargetnotdir : targetptr), volptr,
3328 /* convert the write lock to a read lock before breaking callbacks */
3329 VVnodeWriteToRead(&errorCode, targetptr);
3330 assert(!errorCode || errorCode == VSALVAGE);
3332 /* Break call backs on Fid */
3333 BreakCallBack(client->host, Fid, 0);
3335 /* Return the updated status back to caller */
3336 GetStatus(targetptr, OutStatus, rights, anyrights, parentwhentargetnotdir);
3339 /* Update and store volume/vnode and parent vnodes back */
3340 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
3341 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3344 } /*SAFSS_StoreStatus*/
3347 afs_int32 SRXAFS_StoreStatus (struct rx_call *acall,
3349 struct AFSStoreStatus *InStatus,
3350 struct AFSFetchStatus *OutStatus,
3351 struct AFSVolSync *Sync)
3354 struct rx_connection *tcon;
3355 #if FS_STATS_DETAILED
3356 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3357 struct timeval opStartTime,
3358 opStopTime; /* Start/stop times for RPC op*/
3359 struct timeval elapsedTime; /* Transfer time */
3362 * Set our stats pointer, remember when the RPC operation started, and
3363 * tally the operation.
3365 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3369 TM_GetTimeOfDay(&opStartTime, 0);
3370 #endif /* FS_STATS_DETAILED */
3372 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3373 goto Bad_StoreStatus;
3375 code = SAFSS_StoreStatus (acall, Fid, InStatus, OutStatus, Sync);
3378 CallPostamble(tcon);
3380 #if FS_STATS_DETAILED
3381 TM_GetTimeOfDay(&opStopTime, 0);
3384 (opP->numSuccesses)++;
3385 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3386 fs_stats_AddTo((opP->sumTime), elapsedTime);
3387 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3388 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3389 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3391 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3392 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3397 #endif /* FS_STATS_DETAILED */
3399 osi_auditU (acall, StoreStatusEvent, code, AUD_FID, Fid, AUD_END);
3402 } /*SRXAFS_StoreStatus*/
3406 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3407 * merged in when possible.
3410 SAFSS_RemoveFile (struct rx_call *acall,
3411 struct AFSFid *DirFid,
3413 struct AFSFetchStatus *OutDirStatus,
3414 struct AFSVolSync *Sync)
3416 Vnode * parentptr = 0; /* vnode of input Directory */
3417 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3418 Vnode * targetptr = 0; /* file to be deleted */
3419 Volume * volptr = 0; /* pointer to the volume header */
3420 AFSFid fileFid; /* area for Fid from the directory */
3421 int errorCode = 0; /* error code */
3422 DirHandle dir; /* Handle for dir package I/O */
3423 struct client * client; /* pointer to client structure */
3424 afs_int32 rights, anyrights; /* rights for this and any user */
3425 struct client *t_client; /* tmp ptr to client data */
3426 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3427 struct rx_connection *tcon = rx_ConnectionOf(acall);
3430 /* Get ptr to client data for user Id for logging */
3431 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3432 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3433 ViceLog(1, ("SAFS_RemoveFile %s, Did = %u.%d.%d, Host %s, Id %d\n",
3434 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3435 inet_ntoa(logHostAddr), t_client->ViceId));
3437 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3440 * Get volume/vnode for the parent dir; caller's access rights are
3443 if ((errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
3444 MustBeDIR, &parentwhentargetnotdir,
3445 &client, WRITE_LOCK, &rights, &anyrights))) {
3446 goto Bad_RemoveFile;
3448 /* set volume synchronization information */
3449 SetVolumeSync(Sync, volptr);
3451 /* Does the caller has delete (& write) access to the parent directory? */
3452 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3453 goto Bad_RemoveFile;
3456 /* Actually delete the desired file */
3457 if ((errorCode = DeleteTarget(parentptr, volptr, &targetptr, &dir,
3458 &fileFid, Name, MustNOTBeDIR))) {
3459 goto Bad_RemoveFile;
3462 /* Update the vnode status of the parent dir */
3463 #if FS_STATS_DETAILED
3464 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3465 parentptr->disk.linkCount, client->InSameNetwork);
3467 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3468 parentptr->disk.linkCount);
3469 #endif /* FS_STATS_DETAILED */
3471 /* Return the updated parent dir's status back to caller */
3472 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3474 /* Handle internal callback state for the parent and the deleted file */
3475 if (targetptr->disk.linkCount == 0) {
3476 /* no references left, discard entry */
3477 DeleteFileCallBacks(&fileFid);
3478 /* convert the parent lock to a read lock before breaking callbacks */
3479 VVnodeWriteToRead(&errorCode, parentptr);
3480 assert(!errorCode || errorCode == VSALVAGE);
3482 /* convert the parent lock to a read lock before breaking callbacks */
3483 VVnodeWriteToRead(&errorCode, parentptr);
3484 assert(!errorCode || errorCode == VSALVAGE);
3485 /* convert the target lock to a read lock before breaking callbacks */
3486 VVnodeWriteToRead(&errorCode, targetptr);
3487 assert(!errorCode || errorCode == VSALVAGE);
3488 /* tell all the file has changed */
3489 BreakCallBack(client->host, &fileFid, 1);
3492 /* break call back on the directory */
3493 BreakCallBack(client->host, DirFid, 0);
3496 /* Update and store volume/vnode and parent vnodes back */
3497 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
3499 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3502 } /*SAFSS_RemoveFile*/
3505 afs_int32 SRXAFS_RemoveFile (struct rx_call *acall,
3506 struct AFSFid *DirFid,
3508 struct AFSFetchStatus *OutDirStatus,
3509 struct AFSVolSync *Sync)
3512 struct rx_connection *tcon;
3513 #if FS_STATS_DETAILED
3514 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3515 struct timeval opStartTime,
3516 opStopTime; /* Start/stop times for RPC op*/
3517 struct timeval elapsedTime; /* Transfer time */
3520 * Set our stats pointer, remember when the RPC operation started, and
3521 * tally the operation.
3523 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3527 TM_GetTimeOfDay(&opStartTime, 0);
3528 #endif /* FS_STATS_DETAILED */
3530 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3531 goto Bad_RemoveFile;
3533 code = SAFSS_RemoveFile (acall, DirFid, Name, OutDirStatus, Sync);
3536 CallPostamble(tcon);
3538 #if FS_STATS_DETAILED
3539 TM_GetTimeOfDay(&opStopTime, 0);
3542 (opP->numSuccesses)++;
3543 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3544 fs_stats_AddTo((opP->sumTime), elapsedTime);
3545 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3546 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3547 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3549 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3550 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3555 #endif /* FS_STATS_DETAILED */
3557 osi_auditU (acall, RemoveFileEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3560 } /*SRXAFS_RemoveFile*/
3564 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3565 * be merged in when possible.
3568 SAFSS_CreateFile (struct rx_call *acall,
3569 struct AFSFid *DirFid,
3571 struct AFSStoreStatus *InStatus,
3572 struct AFSFid *OutFid,
3573 struct AFSFetchStatus *OutFidStatus,
3574 struct AFSFetchStatus *OutDirStatus,
3575 struct AFSCallBack *CallBack,
3576 struct AFSVolSync *Sync)
3578 Vnode * parentptr = 0; /* vnode of input Directory */
3579 Vnode * targetptr = 0; /* vnode of the new file */
3580 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3581 Volume * volptr = 0; /* pointer to the volume header */
3582 int errorCode = 0; /* error code */
3583 DirHandle dir; /* Handle for dir package I/O */
3584 struct client * client; /* pointer to client structure */
3585 afs_int32 rights, anyrights; /* rights for this and any user */
3586 struct client *t_client; /* tmp ptr to client data */
3587 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3588 struct rx_connection *tcon = rx_ConnectionOf(acall);
3592 /* Get ptr to client data for user Id for logging */
3593 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3594 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3595 ViceLog(1, ("SAFS_CreateFile %s, Did = %u.%d.%d, Host %s, Id %d\n",
3596 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3597 inet_ntoa(logHostAddr), t_client->ViceId));
3599 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3601 if (!FileNameOK(Name)) {
3603 goto Bad_CreateFile;
3607 * Get associated volume/vnode for the parent dir; caller long are
3610 if ((errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
3611 MustBeDIR, &parentwhentargetnotdir,
3612 &client, WRITE_LOCK, &rights, &anyrights))) {
3613 goto Bad_CreateFile;
3616 /* set volume synchronization information */
3617 SetVolumeSync(Sync, volptr);
3619 /* Can we write (and insert) onto the parent directory? */
3620 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3621 goto Bad_CreateFile;
3623 /* get a new vnode for the file to be created and set it up */
3624 if ((errorCode = Alloc_NewVnode(parentptr, &dir, volptr, &targetptr,
3625 Name, OutFid, vFile, nBlocks(0)))) {
3626 goto Bad_CreateFile;
3629 /* update the status of the parent vnode */
3630 #if FS_STATS_DETAILED
3631 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3632 parentptr->disk.linkCount, client->InSameNetwork);
3634 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3635 parentptr->disk.linkCount);
3636 #endif /* FS_STATS_DETAILED */
3638 /* update the status of the new file's vnode */
3639 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3640 parentptr, volptr, (afs_size_t)0);
3642 /* set up the return status for the parent dir and the newly created file */
3643 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
3644 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3646 /* convert the write lock to a read lock before breaking callbacks */
3647 VVnodeWriteToRead(&errorCode, parentptr);
3648 assert(!errorCode || errorCode == VSALVAGE);
3650 /* break call back on parent dir */
3651 BreakCallBack(client->host, DirFid, 0);
3653 /* Return a callback promise for the newly created file to the caller */
3654 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3657 /* Update and store volume/vnode and parent vnodes back */
3658 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
3660 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3663 } /*SAFSS_CreateFile*/
3666 afs_int32 SRXAFS_CreateFile (struct rx_call *acall,
3667 struct AFSFid *DirFid,
3669 struct AFSStoreStatus *InStatus,
3670 struct AFSFid *OutFid,
3671 struct AFSFetchStatus *OutFidStatus,
3672 struct AFSFetchStatus *OutDirStatus,
3673 struct AFSCallBack *CallBack,
3674 struct AFSVolSync *Sync)
3677 struct rx_connection *tcon;
3678 #if FS_STATS_DETAILED
3679 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3680 struct timeval opStartTime,
3681 opStopTime; /* Start/stop times for RPC op*/
3682 struct timeval elapsedTime; /* Transfer time */
3685 * Set our stats pointer, remember when the RPC operation started, and
3686 * tally the operation.
3688 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3692 TM_GetTimeOfDay(&opStartTime, 0);
3693 #endif /* FS_STATS_DETAILED */
3695 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3696 goto Bad_CreateFile;
3698 code = SAFSS_CreateFile (acall, DirFid, Name, InStatus, OutFid,
3699 OutFidStatus, OutDirStatus, CallBack, Sync);
3702 CallPostamble(tcon);
3704 #if FS_STATS_DETAILED
3705 TM_GetTimeOfDay(&opStopTime, 0);
3708 (opP->numSuccesses)++;
3709 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3710 fs_stats_AddTo((opP->sumTime), elapsedTime);
3711 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3712 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3713 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3715 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3716 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3720 #endif /* FS_STATS_DETAILED */
3722 osi_auditU (acall, CreateFileEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3725 } /*SRXAFS_CreateFile*/
3729 * This routine is called exclusively from SRXAFS_Rename(), and should be
3730 * merged in when possible.
3733 SAFSS_Rename (struct rx_call *acall,
3734 struct AFSFid *OldDirFid,
3736 struct AFSFid *NewDirFid,
3738 struct AFSFetchStatus *OutOldDirStatus,
3739 struct AFSFetchStatus *OutNewDirStatus,
3740 struct AFSVolSync *Sync)
3742 Vnode * oldvptr = 0; /* vnode of the old Directory */
3743 Vnode * newvptr = 0; /* vnode of the new Directory */
3744 Vnode * fileptr = 0; /* vnode of the file to move */
3745 Vnode * newfileptr = 0; /* vnode of the file to delete */
3746 Vnode * testvptr = 0; /* used in directory tree walk */
3747 Vnode * parent = 0; /* parent for use in SetAccessList */
3748 int errorCode = 0; /* error code */
3749 int fileCode = 0; /* used when writing Vnodes */
3750 VnodeId testnode; /* used in directory tree walk */
3751 AFSFid fileFid; /* Fid of file to move */
3752 AFSFid newFileFid; /* Fid of new file */
3753 DirHandle olddir; /* Handle for dir package I/O */
3754 DirHandle newdir; /* Handle for dir package I/O */
3755 DirHandle filedir; /* Handle for dir package I/O */
3756 DirHandle newfiledir; /* Handle for dir package I/O */
3757 Volume * volptr = 0; /* pointer to the volume header */
3758 struct client * client; /* pointer to client structure */
3759 afs_int32 rights, anyrights; /* rights for this and any user */
3760 afs_int32 newrights; /* rights for this user */
3761 afs_int32 newanyrights; /* rights for any user */
3762 int doDelete; /* deleted the rename target (ref count now 0) */
3764 struct client *t_client; /* tmp ptr to client data */
3765 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3766 struct rx_connection *tcon = rx_ConnectionOf(acall);
3771 FidZero(&newfiledir);
3773 /* Get ptr to client data for user Id for logging */
3774 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
3775 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
3776 ViceLog(1, ("SAFS_Rename %s to %s, Fid = %u.%d.%d to %u.%d.%d, Host %s, Id %d\n",
3777 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3778 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3780 inet_ntoa(logHostAddr), t_client->ViceId));
3782 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3784 if (!FileNameOK(NewName)) {
3788 if (OldDirFid->Volume != NewDirFid->Volume) {
3793 if ( (strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0) ||
3794 (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0) ||
3795 (strlen(NewName) == 0) || (strlen(OldName) == 0) ) {
3801 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3802 if (errorCode = GetVolumePackage(tcon, OldDirFid, &volptr,
3803 &oldvptr, MustBeDIR, &parent,
3804 &client, WRITE_LOCK, &rights,
3809 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3811 newrights = rights, newanyrights = anyrights;
3814 if ((errorCode = GetVolumePackage(tcon, NewDirFid, &volptr,
3815 &newvptr, MustBeDIR, &parent,
3816 &client, WRITE_LOCK, &newrights,
3823 if ((errorCode = GetVolumePackage(tcon, NewDirFid, &volptr,
3824 &newvptr, MustBeDIR, &parent,
3825 &client, WRITE_LOCK, &newrights,
3830 if ((errorCode = GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr,
3831 MustBeDIR, &parent, &client, WRITE_LOCK,
3832 &rights, &anyrights))) {
3838 /* set volume synchronization information */
3839 SetVolumeSync(Sync, volptr);
3841 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3844 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3848 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3849 * call to CopyOnWrite returns error, it is not necessary to revert back
3850 * the effects of the first call because the contents of the volume is
3851 * not modified, it is only replicated.
3853 if (oldvptr->disk.cloned)
3855 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3856 if ( ( errorCode = CopyOnWrite(oldvptr, volptr) ) )
3859 SetDirHandle(&olddir, oldvptr);
3860 if (newvptr->disk.cloned)
3862 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3863 if ( ( errorCode = CopyOnWrite(newvptr, volptr) ) )
3867 SetDirHandle(&newdir, newvptr);
3869 /* Lookup the file to delete its vnode */
3870 if (Lookup(&olddir, OldName, &fileFid)) {
3874 if (fileFid.Vnode == oldvptr->vnodeNumber ||
3875 fileFid.Vnode == newvptr->vnodeNumber) {
3876 errorCode = FSERR_ELOOP;
3879 fileFid.Volume = V_id(volptr);
3880 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3881 if (errorCode != 0) {
3882 ViceLog (0, ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n", OldName, errorCode));
3883 VTakeOffline (volptr);
3886 if (fileptr->disk.uniquifier != fileFid.Unique) {
3887 ViceLog (0, ("SAFSS_Rename(): Old file %s uniquifier mismatch\n", OldName));
3888 VTakeOffline (volptr);
3893 if (fileptr->disk.type != vDirectory &&
3894 oldvptr != newvptr &&
3895 fileptr->disk.linkCount != 1) {
3897 * Hard links exist to this file - cannot move one of the links to
3898 * a new directory because of AFS restrictions (this is the same
3899 * reason that links cannot be made across directories, i.e.
3906 /* Lookup the new file */
3907 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3908 if (readonlyServer) {
3909 errorCode = VREADONLY;
3912 if (!(newrights & PRSFS_DELETE)) {
3916 if (newFileFid.Vnode == oldvptr->vnodeNumber ||
3917 newFileFid.Vnode == newvptr->vnodeNumber ||
3918 newFileFid.Vnode == fileFid.Vnode) {
3922 newFileFid.Volume = V_id(volptr);
3923 newfileptr = VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3924 if (errorCode != 0) {
3925 ViceLog (0, ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n", NewName, errorCode));
3926 VTakeOffline (volptr);
3929 if (fileptr->disk.uniquifier != fileFid.Unique) {
3930 ViceLog (0, ("SAFSS_Rename(): New file %s uniquifier mismatch\n", NewName));
3931 VTakeOffline (volptr);
3935 SetDirHandle(&newfiledir, newfileptr);
3936 /* Now check that we're moving directories over directories properly, etc.
3937 * return proper POSIX error codes:
3938 * if fileptr is a file and new is a dir: EISDIR.
3939 * if fileptr is a dir and new is a file: ENOTDIR.
3940 * Also, dir to be removed must be empty, of course.
3942 if (newfileptr->disk.type == vDirectory) {
3943 if (fileptr->disk.type != vDirectory) {
3947 if ((IsEmpty(&newfiledir))) {
3953 if (fileptr->disk.type == vDirectory) {
3954 errorCode = ENOTDIR;
3961 * ok - now we check that the old name is not above new name in the
3962 * directory structure. This is to prevent removing a subtree alltogether
3964 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
3965 for (testnode = newvptr->disk.parent; testnode != 0;) {
3966 if (testnode == oldvptr->vnodeNumber) {
3967 testnode = oldvptr->disk.parent;
3970 if ((testnode == fileptr->vnodeNumber) ||
3971 (testnode == newvptr->vnodeNumber)) {
3972 errorCode = FSERR_ELOOP;
3975 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
3976 errorCode = FSERR_ELOOP;
3979 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
3980 assert(errorCode == 0);
3981 testnode = testvptr->disk.parent;
3982 VPutVnode(&errorCode, testvptr);
3983 assert(errorCode == 0);
3986 /* Do the CopyonWrite first before modifying anything else. Copying is
3987 * required because we may have to change entries for ..
3989 if ((fileptr->disk.type == vDirectory ) && (fileptr->disk.cloned) )
3991 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
3992 if ( ( errorCode = CopyOnWrite(fileptr, volptr) ) )
3996 /* If the new name exists already, delete it and the file it points to */
3999 /* Delete NewName from its directory */
4000 code = Delete(&newdir, NewName);
4003 /* Drop the link count */
4004 newfileptr->disk.linkCount--;
4005 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4007 VN_GET_LEN(newSize, newfileptr);
4008 VAdjustDiskUsage(&errorCode, volptr,
4009 -nBlocks(newSize), (afs_size_t) 0);
4010 if (VN_GET_INO(newfileptr)) {
4011 IH_REALLYCLOSE(newfileptr->handle);
4012 errorCode = IH_DEC(V_linkHandle(volptr),
4013 VN_GET_INO(newfileptr),
4014 V_parentId(volptr));
4015 IH_RELEASE(newfileptr->handle);
4016 if (errorCode == -1) {
4017 ViceLog(0, ("Del: inode=%s, name=%s, errno=%d\n",
4018 PrintInode(NULL, VN_GET_INO(newfileptr)),
4020 if ((errno != ENOENT) && (errno != EIO) && (errno != ENXIO))
4021 ViceLog(0, ("Do we need to fsck?"));
4024 VN_SET_INO(newfileptr, (Inode)0);
4025 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4028 /* Link count did not drop to zero.
4029 * Mark NewName vnode as changed - updates stime.
4031 newfileptr->changed_newTime = 1;
4036 * If the create below fails, and the delete above worked, we have
4037 * removed the new name and not replaced it. This is not very likely,
4038 * but possible. We could try to put the old file back, but it is
4039 * highly unlikely that it would work since it would involve issuing
4042 if ((errorCode = Create(&newdir,(char *) NewName, &fileFid)))
4045 /* Delete the old name */
4046 assert(Delete(&olddir,(char *) OldName) == 0);
4048 /* if the directory length changes, reflect it in the statistics */
4049 #if FS_STATS_DETAILED
4050 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4051 oldvptr->disk.linkCount, client->InSameNetwork);
4052 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4053 newvptr->disk.linkCount, client->InSameNetwork);
4055 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4056 oldvptr->disk.linkCount);
4057 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4058 newvptr->disk.linkCount);
4059 #endif /* FS_STATS_DETAILED */
4061 if (oldvptr == newvptr)
4062 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4064 fileptr->disk.parent = newvptr->vnodeNumber;
4065 fileptr->changed_newTime = 1; /* status change of moved file */
4067 /* if we are dealing with a rename of a directory */
4068 if (fileptr->disk.type == vDirectory) {
4069 assert(!fileptr->disk.cloned);
4070 SetDirHandle(&filedir, fileptr);
4071 /* fix .. to point to the correct place */
4072 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4073 assert(Create(&filedir, "..", NewDirFid) == 0);
4074 fileptr->disk.dataVersion++;
4075 /* if the parent directories are different the link counts have to be */
4076 /* changed due to .. in the renamed directory */
4077 if (oldvptr != newvptr) {
4078 oldvptr->disk.linkCount--;
4079 newvptr->disk.linkCount++;
4083 /* set up return status */
4084 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4085 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4086 if (newfileptr && doDelete) {
4087 DeleteFileCallBacks(&newFileFid); /* no other references */
4092 /* convert the write locks to a read locks before breaking callbacks */
4093 VVnodeWriteToRead(&errorCode, newvptr);
4094 assert(!errorCode || errorCode == VSALVAGE);
4095 if (oldvptr != newvptr) {
4096 VVnodeWriteToRead(&errorCode, oldvptr);
4097 assert(!errorCode || errorCode == VSALVAGE);
4099 if (newfileptr && !doDelete) {
4100 /* convert the write lock to a read lock before breaking callbacks */
4101 VVnodeWriteToRead(&errorCode, newfileptr);
4102 assert(!errorCode || errorCode == VSALVAGE);
4105 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4106 BreakCallBack(client->host, NewDirFid, 0);
4107 if (oldvptr != newvptr) {
4108 BreakCallBack(client->host, OldDirFid, 0);
4109 if (fileptr->disk.type == vDirectory) /* if a dir moved, .. changed */
4110 BreakCallBack(client->host, &fileFid, 0);
4113 /* Note: it is not necessary to break the callback */
4115 DeleteFileCallBacks(&newFileFid); /* no other references */
4117 /* other's still exist (with wrong link count) */
4118 BreakCallBack(client->host, &newFileFid, 1);
4123 VPutVnode(&fileCode, newfileptr);
4124 assert(fileCode == 0);
4126 PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr? newvptr : 0),
4131 FidZap(&newfiledir);
4132 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4138 afs_int32 SRXAFS_Rename (struct rx_call *acall,
4139 struct AFSFid *OldDirFid,
4141 struct AFSFid *NewDirFid,
4143 struct AFSFetchStatus *OutOldDirStatus,
4144 struct AFSFetchStatus *OutNewDirStatus,
4145 struct AFSVolSync *Sync)
4148 struct rx_connection *tcon;
4149 #if FS_STATS_DETAILED
4150 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4151 struct timeval opStartTime,
4152 opStopTime; /* Start/stop times for RPC op*/
4153 struct timeval elapsedTime; /* Transfer time */
4156 * Set our stats pointer, remember when the RPC operation started, and
4157 * tally the operation.
4159 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4163 TM_GetTimeOfDay(&opStartTime, 0);
4164 #endif /* FS_STATS_DETAILED */
4166 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4169 code = SAFSS_Rename (acall, OldDirFid, OldName, NewDirFid, NewName,
4170 OutOldDirStatus, OutNewDirStatus, Sync);
4173 CallPostamble(tcon);
4175 #if FS_STATS_DETAILED
4176 TM_GetTimeOfDay(&opStopTime, 0);
4179 (opP->numSuccesses)++;
4180 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4181 fs_stats_AddTo((opP->sumTime), elapsedTime);
4182 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4183 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4184 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4186 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4187 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4192 #endif /* FS_STATS_DETAILED */
4194 osi_auditU (acall, RenameFileEvent, code, AUD_FID, OldDirFid, AUD_STR, OldName, AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4201 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4202 * merged into it when possible.
4205 SAFSS_Symlink (struct rx_call *acall,
4206 struct AFSFid *DirFid,
4209 struct AFSStoreStatus *InStatus,
4210 struct AFSFid *OutFid,
4211 struct AFSFetchStatus *OutFidStatus,
4212 struct AFSFetchStatus *OutDirStatus,
4213 struct AFSVolSync *Sync)
4216 Vnode * parentptr = 0; /* vnode of input Directory */
4217 Vnode * targetptr = 0; /* vnode of the new link */
4218 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4219 int errorCode = 0; /* error code */
4221 DirHandle dir; /* Handle for dir package I/O */
4222 Volume * volptr = 0; /* pointer to the volume header */
4223 struct client * client; /* pointer to client structure */
4224 afs_int32 rights, anyrights, fd; /* rights for this and any user */
4225 struct client *t_client; /* tmp ptr to client data */
4226 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4228 struct rx_connection *tcon = rx_ConnectionOf(acall);
4232 /* Get ptr to client data for user Id for logging */
4233 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
4234 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
4235 ViceLog(1, ("SAFS_Symlink %s to %s, Did = %u.%d.%d, Host %s, Id %d\n", Name,
4236 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4237 inet_ntoa(logHostAddr), t_client->ViceId));
4239 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4241 if (!FileNameOK(Name)) {
4247 * Get the vnode and volume for the parent dir along with the caller's
4250 if ((errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
4251 MustBeDIR, &parentwhentargetnotdir,
4252 &client, WRITE_LOCK, &rights, &anyrights))) {
4256 /* set volume synchronization information */
4257 SetVolumeSync(Sync, volptr);
4259 /* Does the caller has insert (and write) access to the parent directory? */
4260 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4265 * If we're creating a mount point (any x bits clear), we must have
4266 * administer access to the directory, too. Always allow sysadmins
4269 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4270 if (readonlyServer) {
4271 errorCode = VREADONLY;
4275 * We have a mountpoint, 'cause we're trying to set the Unix mode
4276 * bits to something with some x bits missing (default mode bits
4277 * if AFS_SETMODE is false is 0777)
4279 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4285 /* get a new vnode for the symlink and set it up */
4286 if ((errorCode = Alloc_NewVnode(parentptr, &dir, volptr, &targetptr,
4287 Name, OutFid, vSymlink,
4288 nBlocks(strlen((char *) LinkContents))))) {
4292 /* update the status of the parent vnode */
4293 #if FS_STATS_DETAILED
4294 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4295 parentptr->disk.linkCount, client->InSameNetwork);
4297 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4298 parentptr->disk.linkCount);
4299 #endif /* FS_STATS_DETAILED */
4301 /* update the status of the new symbolic link file vnode */
4302 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus, parentptr,
4303 volptr, (afs_size_t)strlen((char *)LinkContents));
4305 /* Write the contents of the symbolic link name into the target inode */
4306 fdP = IH_OPEN(targetptr->handle);
4307 assert(fdP != NULL);
4308 assert(FDH_WRITE(fdP, (char *) LinkContents, strlen((char *) LinkContents)) == strlen((char *) LinkContents));
4311 * Set up and return modified status for the parent dir and new symlink
4314 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4315 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4317 /* convert the write lock to a read lock before breaking callbacks */
4318 VVnodeWriteToRead(&errorCode, parentptr);
4319 assert(!errorCode || errorCode == VSALVAGE);
4321 /* break call back on the parent dir */
4322 BreakCallBack(client->host, DirFid, 0);
4325 /* Write the all modified vnodes (parent, new files) and volume back */
4326 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
4328 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4334 afs_int32 SRXAFS_Symlink (acall, DirFid, Name, LinkContents, InStatus, OutFid, OutFidStatus, OutDirStatus, Sync)
4335 struct AFSVolSync *Sync;
4336 struct rx_call *acall; /* Rx call */
4337 struct AFSFid *DirFid; /* Parent dir's fid */
4338 char *Name; /* File name to create */
4339 char *LinkContents; /* Contents of the new created file */
4340 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
4341 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
4342 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
4343 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
4347 struct rx_connection *tcon;
4348 #if FS_STATS_DETAILED
4349 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4350 struct timeval opStartTime,
4351 opStopTime; /* Start/stop times for RPC op*/
4352 struct timeval elapsedTime; /* Transfer time */
4355 * Set our stats pointer, remember when the RPC operation started, and
4356 * tally the operation.
4358 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4362 TM_GetTimeOfDay(&opStartTime, 0);
4363 #endif /* FS_STATS_DETAILED */
4365 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4368 code = SAFSS_Symlink (acall, DirFid, Name, LinkContents, InStatus, OutFid,
4369 OutFidStatus, OutDirStatus, Sync);
4372 CallPostamble(tcon);
4374 #if FS_STATS_DETAILED
4375 TM_GetTimeOfDay(&opStopTime, 0);
4378 (opP->numSuccesses)++;
4379 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4380 fs_stats_AddTo((opP->sumTime), elapsedTime);
4381 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4382 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4383 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4385 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4386 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4391 #endif /* FS_STATS_DETAILED */
4393 osi_auditU (acall, SymlinkEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
4396 } /*SRXAFS_Symlink*/
4400 * This routine is called exclusively by SRXAFS_Link(), and should be
4401 * merged into it when possible.
4404 SAFSS_Link (struct rx_call *acall,
4405 struct AFSFid *DirFid,
4407 struct AFSFid *ExistingFid,
4408 struct AFSFetchStatus *OutFidStatus,
4409 struct AFSFetchStatus *OutDirStatus,
4410 struct AFSVolSync *Sync)
4412 Vnode * parentptr = 0; /* vnode of input Directory */
4413 Vnode * targetptr = 0; /* vnode of the new file */
4414 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4415 Volume * volptr = 0; /* pointer to the volume header */
4416 int errorCode = 0; /* error code */
4417 DirHandle dir; /* Handle for dir package I/O */
4418 struct client * client; /* pointer to client structure */
4419 afs_int32 rights, anyrights; /* rights for this and any user */
4420 struct client *t_client; /* tmp ptr to client data */
4421 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4422 struct rx_connection *tcon = rx_ConnectionOf(acall);
4426 /* Get ptr to client data for user Id for logging */
4427 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
4428 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
4429 ViceLog(1, ("SAFS_Link %s, Did = %u.%d.%d, Fid = %u.%d.%d, Host %s, Id %d\n",
4430 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4431 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4432 inet_ntoa(logHostAddr), t_client->ViceId));
4434 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4436 if (DirFid->Volume != ExistingFid->Volume) {
4440 if (!FileNameOK(Name)) {
4446 * Get the vnode and volume for the parent dir along with the caller's
4449 if ((errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
4450 MustBeDIR, &parentwhentargetnotdir,
4451 &client, WRITE_LOCK, &rights, &anyrights))) {
4455 /* set volume synchronization information */
4456 SetVolumeSync(Sync, volptr);
4458 /* Can the caller insert into the parent directory? */
4459 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4463 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) ||
4464 (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4465 /* AFS fileservers always have directory vnodes that are odd. */
4470 /* get the file vnode */
4471 if ((errorCode = CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4474 if (targetptr->disk.type != vFile) {
4478 if (targetptr->disk.parent != DirFid->Vnode) {
4482 if (parentptr->disk.cloned)
4484 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4485 if ( ( errorCode = CopyOnWrite(parentptr, volptr)))
4486 goto Bad_Link; /* disk full error */
4489 /* add the name to the directory */
4490 SetDirHandle(&dir, parentptr);
4491 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4495 /* update the status in the parent vnode */
4496 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4497 #if FS_STATS_DETAILED
4498 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4499 parentptr->disk.linkCount, client->InSameNetwork);
4501 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4502 parentptr->disk.linkCount);
4503 #endif /* FS_STATS_DETAILED */
4505 targetptr->disk.linkCount++;
4506 targetptr->disk.author = client->ViceId;
4507 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4509 /* set up return status */
4510 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4511 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4513 /* convert the write locks to read locks before breaking callbacks */
4514 VVnodeWriteToRead(&errorCode, targetptr);
4515 assert(!errorCode || errorCode == VSALVAGE);
4516 VVnodeWriteToRead(&errorCode, parentptr);
4517 assert(!errorCode || errorCode == VSALVAGE);
4519 /* break call back on DirFid */
4520 BreakCallBack(client->host, DirFid, 0);
4522 * We also need to break the callback for the file that is hard-linked since part
4523 * of its status (like linkcount) is changed
4525 BreakCallBack(client->host, ExistingFid, 0);
4528 /* Write the all modified vnodes (parent, new files) and volume back */
4529 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
4531 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4537 afs_int32 SRXAFS_Link (struct rx_call *acall,
4538 struct AFSFid *DirFid,
4540 struct AFSFid *ExistingFid,
4541 struct AFSFetchStatus *OutFidStatus,
4542 struct AFSFetchStatus *OutDirStatus,
4543 struct AFSVolSync *Sync)
4546 struct rx_connection *tcon;
4547 #if FS_STATS_DETAILED
4548 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4549 struct timeval opStartTime,
4550 opStopTime; /* Start/stop times for RPC op*/
4551 struct timeval elapsedTime; /* Transfer time */
4554 * Set our stats pointer, remember when the RPC operation started, and
4555 * tally the operation.
4557 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4561 TM_GetTimeOfDay(&opStartTime, 0);
4562 #endif /* FS_STATS_DETAILED */
4564 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4567 code = SAFSS_Link (acall, DirFid, Name, ExistingFid, OutFidStatus,
4568 OutDirStatus, Sync);
4571 CallPostamble(tcon);
4573 #if FS_STATS_DETAILED
4574 TM_GetTimeOfDay(&opStopTime, 0);
4577 (opP->numSuccesses)++;
4578 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4579 fs_stats_AddTo((opP->sumTime), elapsedTime);
4580 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4581 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4582 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4584 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4585 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4590 #endif /* FS_STATS_DETAILED */
4592 osi_auditU (acall, LinkEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_FID, ExistingFid, AUD_END);
4599 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4600 * merged into it when possible.
4603 SAFSS_MakeDir (struct rx_call *acall,
4604 struct AFSFid *DirFid,
4606 struct AFSStoreStatus *InStatus,
4607 struct AFSFid *OutFid,
4608 struct AFSFetchStatus *OutFidStatus,
4609 struct AFSFetchStatus *OutDirStatus,
4610 struct AFSCallBack *CallBack,
4611 struct AFSVolSync *Sync)
4614 Vnode * parentptr = 0; /* vnode of input Directory */
4615 Vnode * targetptr = 0; /* vnode of the new file */
4616 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4617 Volume * volptr = 0; /* pointer to the volume header */
4618 int errorCode = 0; /* error code */
4619 struct acl_accessList * newACL; /* Access list */
4620 int newACLSize; /* Size of access list */
4621 DirHandle dir; /* Handle for dir package I/O */
4622 DirHandle parentdir; /* Handle for dir package I/O */
4623 struct client * client; /* pointer to client structure */
4624 afs_int32 rights, anyrights; /* rights for this and any user */
4625 struct client *t_client; /* tmp ptr to client data */
4626 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4627 struct rx_connection *tcon = rx_ConnectionOf(acall);
4630 FidZero(&parentdir);
4632 /* Get ptr to client data for user Id for logging */
4633 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
4634 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
4635 ViceLog(1, ("SAFS_MakeDir %s, Did = %u.%d.%d, Host %s, Id %d\n",
4636 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4637 inet_ntoa(logHostAddr), t_client->ViceId));
4639 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4641 if (!FileNameOK(Name)) {
4647 * Get the vnode and volume for the parent dir along with the caller's
4650 if ((errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
4651 MustBeDIR, &parentwhentargetnotdir,
4652 &client, WRITE_LOCK, &rights, &anyrights))) {
4656 /* set volume synchronization information */
4657 SetVolumeSync(Sync, volptr);
4659 /* Write access to the parent directory? */
4660 #ifdef DIRCREATE_NEED_WRITE
4662 * requires w access for the user to create a directory. this
4663 * closes a loophole in the current security arrangement, since a
4664 * user with i access only can create a directory and get the
4665 * implcit a access that goes with dir ownership, and proceed to
4666 * subvert quota in the volume.
4668 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT)) ||
4669 (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4671 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4672 #endif /* DIRCREATE_NEED_WRITE */
4676 #define EMPTYDIRBLOCKS 2
4677 /* get a new vnode and set it up */
4678 if ((errorCode = Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr,
4679 Name, OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4683 /* Update the status for the parent dir */
4684 #if FS_STATS_DETAILED
4685 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4686 parentptr->disk.linkCount+1, client->InSameNetwork);
4688 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4689 parentptr->disk.linkCount+1);
4690 #endif /* FS_STATS_DETAILED */
4692 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4693 assert((SetAccessList(&targetptr, &volptr, &newACL, &newACLSize,
4694 &parentwhentargetnotdir, (AFSFid *)0, 0)) == 0);
4695 assert(parentwhentargetnotdir == 0);
4696 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4698 /* update the status for the target vnode */
4699 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4700 parentptr, volptr, (afs_size_t)0);
4702 /* Actually create the New directory in the directory package */
4703 SetDirHandle(&dir, targetptr);
4704 assert(!(MakeDir(&dir, OutFid, DirFid)));
4706 VN_SET_LEN(targetptr, (afs_size_t) Length(&dir));
4708 /* set up return status */
4709 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4710 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4712 /* convert the write lock to a read lock before breaking callbacks */
4713 VVnodeWriteToRead(&errorCode, parentptr);
4714 assert(!errorCode || errorCode == VSALVAGE);
4716 /* break call back on DirFid */
4717 BreakCallBack(client->host, DirFid, 0);
4719 /* Return a callback promise to caller */
4720 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4723 /* Write the all modified vnodes (parent, new files) and volume back */
4724 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
4727 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4733 afs_int32 SRXAFS_MakeDir (struct rx_call *acall,
4734 struct AFSFid *DirFid,
4736 struct AFSStoreStatus *InStatus,
4737 struct AFSFid *OutFid,
4738 struct AFSFetchStatus *OutFidStatus,
4739 struct AFSFetchStatus *OutDirStatus,
4740 struct AFSCallBack *CallBack,
4741 struct AFSVolSync *Sync)
4744 struct rx_connection *tcon;
4745 #if FS_STATS_DETAILED
4746 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4747 struct timeval opStartTime,
4748 opStopTime; /* Start/stop times for RPC op*/
4749 struct timeval elapsedTime; /* Transfer time */
4752 * Set our stats pointer, remember when the RPC operation started, and
4753 * tally the operation.
4755 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
4759 TM_GetTimeOfDay(&opStartTime, 0);
4760 #endif /* FS_STATS_DETAILED */
4761 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4764 code = SAFSS_MakeDir (acall, DirFid, Name, InStatus, OutFid,
4765 OutFidStatus, OutDirStatus, CallBack, Sync);
4768 CallPostamble(tcon);
4770 #if FS_STATS_DETAILED
4771 TM_GetTimeOfDay(&opStopTime, 0);
4774 (opP->numSuccesses)++;
4775 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4776 fs_stats_AddTo((opP->sumTime), elapsedTime);
4777 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4778 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4779 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4781 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4782 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4787 #endif /* FS_STATS_DETAILED */
4789 osi_auditU (acall, MakeDirEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
4792 } /*SRXAFS_MakeDir*/
4796 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4797 * merged into it when possible.
4800 SAFSS_RemoveDir (struct rx_call *acall,
4801 struct AFSFid *DirFid,
4803 struct AFSFetchStatus *OutDirStatus,
4804 struct AFSVolSync *Sync)
4807 Vnode * parentptr = 0; /* vnode of input Directory */
4808 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4809 Vnode * targetptr = 0; /* file to be deleted */
4810 AFSFid fileFid; /* area for Fid from the directory */
4811 int errorCode = 0; /* error code */
4812 DirHandle dir; /* Handle for dir package I/O */
4813 Volume * volptr = 0; /* pointer to the volume header */
4814 struct client * client; /* pointer to client structure */
4815 afs_int32 rights, anyrights; /* rights for this and any user */
4816 Vnode debugvnode1, debugvnode2;
4817 struct client *t_client; /* tmp ptr to client data */
4818 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4819 struct rx_connection *tcon = rx_ConnectionOf(acall);
4823 /* Get ptr to client data for user Id for logging */
4824 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
4825 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
4826 ViceLog(1, ("SAFS_RemoveDir %s, Did = %u.%d.%d, Host %s, Id %d\n",
4827 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4828 inet_ntoa(logHostAddr), t_client->ViceId));
4830 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4833 * Get the vnode and volume for the parent dir along with the caller's
4836 if ((errorCode = GetVolumePackage(tcon, DirFid, &volptr, &parentptr,
4837 MustBeDIR, &parentwhentargetnotdir,
4838 &client, WRITE_LOCK, &rights, &anyrights))) {
4841 debugvnode1 = *parentptr;
4843 /* set volume synchronization information */
4844 SetVolumeSync(Sync, volptr);
4846 /* Does the caller has delete (&write) access to the parent dir? */
4847 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
4851 debugvnode2 = *parentptr;
4852 /* Do the actual delete of the desired (empty) directory, Name */
4853 if ((errorCode = DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid,
4854 Name, MustBeDIR))) {
4858 /* Update the status for the parent dir; link count is also adjusted */
4859 #if FS_STATS_DETAILED
4860 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4861 parentptr->disk.linkCount-1, client->InSameNetwork);
4863 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4864 parentptr->disk.linkCount-1);
4865 #endif /* FS_STATS_DETAILED */
4867 /* Return to the caller the updated parent dir status */
4868 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4871 * Note: it is not necessary to break the callback on fileFid, since
4872 * refcount is now 0, so no one should be able to refer to the dir
4875 DeleteFileCallBacks(&fileFid);
4877 /* convert the write lock to a read lock before breaking callbacks */
4878 VVnodeWriteToRead(&errorCode, parentptr);
4879 assert(!errorCode || errorCode == VSALVAGE);
4881 /* break call back on DirFid and fileFid */
4882 BreakCallBack(client->host, DirFid, 0);
4885 /* Write the all modified vnodes (parent, new files) and volume back */
4886 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr, volptr);
4888 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
4891 } /*SAFSS_RemoveDir*/
4894 afs_int32 SRXAFS_RemoveDir (struct rx_call *acall,
4895 struct AFSFid *DirFid,
4897 struct AFSFetchStatus *OutDirStatus,
4898 struct AFSVolSync *Sync)
4901 struct rx_connection *tcon;
4902 #if FS_STATS_DETAILED
4903 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4904 struct timeval opStartTime,
4905 opStopTime; /* Start/stop times for RPC op*/
4906 struct timeval elapsedTime; /* Transfer time */
4909 * Set our stats pointer, remember when the RPC operation started, and
4910 * tally the operation.
4912 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
4916 TM_GetTimeOfDay(&opStartTime, 0);
4917 #endif /* FS_STATS_DETAILED */
4919 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4922 code = SAFSS_RemoveDir (acall, DirFid, Name, OutDirStatus, Sync);
4925 CallPostamble(tcon);
4927 #if FS_STATS_DETAILED
4928 TM_GetTimeOfDay(&opStopTime, 0);
4931 (opP->numSuccesses)++;
4932 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4933 fs_stats_AddTo((opP->sumTime), elapsedTime);
4934 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4935 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4936 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4938 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4939 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4944 #endif /* FS_STATS_DETAILED */
4946 osi_auditU (acall, RemoveDirEvent, code, AUD_FID, DirFid, AUD_STR, Name, AUD_END);
4949 } /*SRXAFS_RemoveDir*/
4953 * This routine is called exclusively by SRXAFS_SetLock(), and should be
4954 * merged into it when possible.
4957 SAFSS_SetLock (struct rx_call *acall,
4960 struct AFSVolSync *Sync)
4962 Vnode * targetptr = 0; /* vnode of input file */
4963 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4964 int errorCode = 0; /* error code */
4965 Volume * volptr = 0; /* pointer to the volume header */
4966 struct client * client; /* pointer to client structure */
4967 afs_int32 rights, anyrights; /* rights for this and any user */
4968 struct client *t_client; /* tmp ptr to client data */
4969 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4970 static char * locktype[2] = {"LockRead","LockWrite"};
4971 struct rx_connection *tcon = rx_ConnectionOf(acall);
4973 if (type != LockRead && type != LockWrite) {
4977 /* Get ptr to client data for user Id for logging */
4978 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
4979 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
4980 ViceLog(1,("SAFS_SetLock type = %s Fid = %u.%d.%d, Host %s, Id %d\n",
4981 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
4982 inet_ntoa(logHostAddr), t_client->ViceId));
4984 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
4988 * Get the vnode and volume for the desired file along with the caller's
4991 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
4992 DONTCHECK, &parentwhentargetnotdir,
4993 &client, WRITE_LOCK, &rights, &anyrights))) {
4997 /* set volume synchronization information */
4998 SetVolumeSync(Sync, volptr);
5000 /* Handle the particular type of set locking, type */
5001 errorCode = HandleLocking(targetptr, rights, type);
5004 /* Write the all modified vnodes (parent, new files) and volume back */
5005 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
5007 if ((errorCode == VREADONLY) && (type == LockRead))
5008 errorCode = 0; /* allow read locks on RO volumes without saving state */
5010 ViceLog(2,("SAFS_SetLock returns %d\n", errorCode));
5016 afs_int32 SRXAFS_OldSetLock(struct rx_call *acall,
5019 struct AFSVolSync *Sync)
5021 return SRXAFS_SetLock(acall, Fid, type, Sync);
5023 } /*SRXAFS_OldSetLock*/
5026 afs_int32 SRXAFS_SetLock (struct rx_call *acall,
5029 struct AFSVolSync *Sync)
5032 struct rx_connection *tcon;
5033 #if FS_STATS_DETAILED
5034 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5035 struct timeval opStartTime,
5036 opStopTime; /* Start/stop times for RPC op*/
5037 struct timeval elapsedTime; /* Transfer time */
5040 * Set our stats pointer, remember when the RPC operation started, and
5041 * tally the operation.
5043 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5047 TM_GetTimeOfDay(&opStartTime, 0);
5048 #endif /* FS_STATS_DETAILED */
5050 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
5053 code = SAFSS_SetLock (acall, Fid, type, Sync);
5056 CallPostamble(tcon);
5058 #if FS_STATS_DETAILED
5059 TM_GetTimeOfDay(&opStopTime, 0);
5062 (opP->numSuccesses)++;
5063 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5064 fs_stats_AddTo((opP->sumTime), elapsedTime);
5065 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5066 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5067 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5069 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5070 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5074 #endif /* FS_STATS_DETAILED */
5076 osi_auditU (acall, SetLockEvent, code, AUD_FID, Fid, AUD_LONG, type, AUD_END);
5079 } /*SRXAFS_SetLock*/
5083 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5084 * merged into it when possible.
5087 SAFSS_ExtendLock (struct rx_call *acall,
5089 struct AFSVolSync *Sync)
5092 Vnode * targetptr = 0; /* vnode of input file */
5093 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5094 int errorCode = 0; /* error code */
5095 Volume * volptr = 0; /* pointer to the volume header */
5096 struct client * client; /* pointer to client structure */
5097 afs_int32 rights, anyrights; /* rights for this and any user */
5098 struct client *t_client; /* tmp ptr to client data */
5099 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5100 struct rx_connection *tcon = rx_ConnectionOf(acall);
5102 /* Get ptr to client data for user Id for logging */
5103 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
5104 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
5105 ViceLog(1,("SAFS_ExtendLock Fid = %u.%d.%d, Host %s, Id %d\n",
5106 Fid->Volume, Fid->Vnode, Fid->Unique,
5107 inet_ntoa(logHostAddr), t_client->ViceId));
5109 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5112 * Get the vnode and volume for the desired file along with the caller's
5115 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
5116 DONTCHECK, &parentwhentargetnotdir,
5117 &client, WRITE_LOCK, &rights, &anyrights))) {
5118 goto Bad_ExtendLock;
5121 /* set volume synchronization information */
5122 SetVolumeSync(Sync, volptr);
5124 /* Handle the actual lock extension */
5125 errorCode = HandleLocking(targetptr, rights, LockExtend);
5128 /* Put back file's vnode and volume */
5129 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
5131 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5132 errorCode = 0; /* under our generous policy re RO vols */
5134 ViceLog(2,("SAFS_ExtendLock returns %d\n", errorCode));
5137 } /*SAFSS_ExtendLock*/
5140 afs_int32 SRXAFS_OldExtendLock (struct rx_call *acall,
5142 struct AFSVolSync *Sync)
5144 return SRXAFS_ExtendLock(acall, Fid, Sync);
5146 } /*SRXAFS_OldExtendLock*/
5149 afs_int32 SRXAFS_ExtendLock (struct rx_call *acall,
5151 struct AFSVolSync *Sync)
5154 struct rx_connection *tcon;
5155 #if FS_STATS_DETAILED
5156 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5157 struct timeval opStartTime,
5158 opStopTime; /* Start/stop times for RPC op*/
5159 struct timeval elapsedTime; /* Transfer time */
5162 * Set our stats pointer, remember when the RPC operation started, and
5163 * tally the operation.
5165 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5169 TM_GetTimeOfDay(&opStartTime, 0);
5170 #endif /* FS_STATS_DETAILED */
5172 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
5173 goto Bad_ExtendLock;
5175 code = SAFSS_ExtendLock (acall, Fid, Sync);
5178 CallPostamble(tcon);
5180 #if FS_STATS_DETAILED
5181 TM_GetTimeOfDay(&opStopTime, 0);
5184 (opP->numSuccesses)++;
5185 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5186 fs_stats_AddTo((opP->sumTime), elapsedTime);
5187 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5188 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5189 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5191 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5192 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5197 #endif /* FS_STATS_DETAILED */
5199 osi_auditU (acall, ExtendLockEvent, code, AUD_FID, Fid , AUD_END);
5202 } /*SRXAFS_ExtendLock*/
5206 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5207 * merged into it when possible.
5210 SAFSS_ReleaseLock (struct rx_call *acall,
5212 struct AFSVolSync *Sync)
5215 Vnode * targetptr = 0; /* vnode of input file */
5216 Vnode * parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5217 int errorCode = 0; /* error code */
5218 Volume * volptr = 0; /* pointer to the volume header */
5219 struct client * client; /* pointer to client structure */
5220 afs_int32 rights, anyrights; /* rights for this and any user */
5221 struct client *t_client; /* tmp ptr to client data */
5222 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5223 struct rx_connection *tcon = rx_ConnectionOf(acall);
5225 /* Get ptr to client data for user Id for logging */
5226 t_client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
5227 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(tcon));
5228 ViceLog(1,("SAFS_ReleaseLock Fid = %u.%d.%d, Host %s, Id %d\n",
5229 Fid->Volume, Fid->Vnode, Fid->Unique,
5230 inet_ntoa(logHostAddr), t_client->ViceId));
5232 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5235 * Get the vnode and volume for the desired file along with the caller's
5238 if ((errorCode = GetVolumePackage(tcon, Fid, &volptr, &targetptr,
5239 DONTCHECK, &parentwhentargetnotdir,
5240 &client, WRITE_LOCK, &rights, &anyrights))) {
5241 goto Bad_ReleaseLock;
5244 /* set volume synchronization information */
5245 SetVolumeSync(Sync, volptr);
5247 /* Handle the actual lock release */
5248 if ((errorCode = HandleLocking(targetptr, rights, LockRelease)))
5249 goto Bad_ReleaseLock;
5251 /* if no more locks left, a callback would be triggered here */
5252 if (targetptr->disk.lock.lockCount <= 0) {
5253 /* convert the write lock to a read lock before breaking callbacks */
5254 VVnodeWriteToRead(&errorCode, targetptr);
5255 assert(!errorCode || errorCode == VSALVAGE);
5256 BreakCallBack(client->host, Fid, 0);
5260 /* Put back file's vnode and volume */
5261 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
5263 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5264 errorCode = 0; /* under our generous policy re RO vols */
5266 ViceLog(2,("SAFS_ReleaseLock returns %d\n", errorCode));
5269 } /*SAFSS_ReleaseLock*/
5272 afs_int32 SRXAFS_OldReleaseLock (struct rx_call *acall,
5274 struct AFSVolSync *Sync)
5276 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5278 } /*SRXAFS_OldReleaseLock*/
5281 afs_int32 SRXAFS_ReleaseLock (struct rx_call *acall,
5283 struct AFSVolSync *Sync)
5286 struct rx_connection *tcon;
5287 #if FS_STATS_DETAILED
5288 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5289 struct timeval opStartTime,
5290 opStopTime; /* Start/stop times for RPC op*/
5291 struct timeval elapsedTime; /* Transfer time */
5294 * Set our stats pointer, remember when the RPC operation started, and
5295 * tally the operation.
5297 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5301 TM_GetTimeOfDay(&opStartTime, 0);
5302 #endif /* FS_STATS_DETAILED */
5304 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
5305 goto Bad_ReleaseLock;
5307 code = SAFSS_ReleaseLock (acall, Fid, Sync);
5310 CallPostamble(tcon);
5312 #if FS_STATS_DETAILED
5313 TM_GetTimeOfDay(&opStopTime, 0);
5316 (opP->numSuccesses)++;
5317 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5318 fs_stats_AddTo((opP->sumTime), elapsedTime);
5319 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5320 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5321 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5323 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5324 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5329 #endif /* FS_STATS_DETAILED */
5331 osi_auditU (acall, ReleaseLockEvent, code, AUD_FID, Fid , AUD_END);
5334 } /*SRXAFS_ReleaseLock*/
5337 void SetSystemStats(struct AFSStatistics *stats)
5339 /* Fix this sometime soon.. */
5340 /* Because hey, it's not like we have a network monitoring protocol... */
5341 struct timeval time;
5343 /* this works on all system types */
5344 TM_GetTimeOfDay(&time, 0);
5345 stats->CurrentTime = time.tv_sec;
5346 } /*SetSystemStats*/
5348 void SetAFSStats(struct AFSStatistics *stats)
5350 extern afs_int32 StartTime, CurrentConnections;
5354 stats->CurrentMsgNumber = 0;
5355 stats->OldestMsgNumber = 0;
5356 stats->StartTime = StartTime;
5357 stats->CurrentConnections = CurrentConnections;
5358 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5359 stats->TotalFetchs = AFSCallStats.FetchData+AFSCallStats.FetchACL+AFSCallStats.FetchStatus;
5360 stats->FetchDatas = AFSCallStats.FetchData;
5361 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5362 seconds = AFSCallStats.AccumFetchTime/1000;
5363 if (seconds <= 0) seconds = 1;
5364 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes/seconds;
5365 stats->TotalStores = AFSCallStats.StoreData+AFSCallStats.StoreACL+AFSCallStats.StoreStatus;
5366 stats->StoreDatas = AFSCallStats.StoreData;
5367 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5368 seconds = AFSCallStats.AccumStoreTime/1000;
5369 if (seconds <= 0) seconds = 1;
5370 stats->StoreDataRate = AFSCallStats.TotalStoredBytes/seconds;
5372 stats->ProcessSize = -1; /* TODO: */
5374 stats->ProcessSize = (afs_int32)((long) sbrk(0) >> 10);
5377 h_GetWorkStats((int *)&(stats->WorkStations),(int *)&(stats->ActiveWorkStations),
5378 (int *)0, (afs_int32)(FT_ApproxTime())-(15*60));
5382 /* Get disk related information from all AFS partitions. */
5384 void SetVolumeStats(struct AFSStatistics *stats)
5386 struct DiskPartition * part;
5389 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS; part = part->next) {
5390 stats->Disks[i].TotalBlocks = part->totalUsable;
5391 stats->Disks[i].BlocksAvailable = part->free;
5392 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5393 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5396 while (i < AFS_MSTATDISKS) {
5397 stats->Disks[i].TotalBlocks = -1;
5400 } /*SetVolumeStats*/
5402 afs_int32 SRXAFS_GetStatistics (struct rx_call *acall,
5403 struct ViceStatistics *Statistics)
5406 struct rx_connection *tcon;
5407 #if FS_STATS_DETAILED
5408 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5409 struct timeval opStartTime,
5410 opStopTime; /* Start/stop times for RPC op*/
5411 struct timeval elapsedTime; /* Transfer time */
5414 * Set our stats pointer, remember when the RPC operation started, and
5415 * tally the operation.
5417 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5421 TM_GetTimeOfDay(&opStartTime, 0);
5422 #endif /* FS_STATS_DETAILED */
5424 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon)))
5425 goto Bad_GetStatistics;
5427 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5429 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5431 memset(Statistics, 0, sizeof(*Statistics));
5432 SetAFSStats((struct AFSStatistics *)Statistics);
5433 SetVolumeStats((struct AFSStatistics *)Statistics);
5434 SetSystemStats((struct AFSStatistics *)Statistics);
5437 CallPostamble(tcon);
5439 #if FS_STATS_DETAILED
5440 TM_GetTimeOfDay(&opStopTime, 0);
5443 (opP->numSuccesses)++;
5444 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5445 fs_stats_AddTo((opP->sumTime), elapsedTime);
5446 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5447 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5448 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5450 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5451 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5455 #endif /* FS_STATS_DETAILED */
5459 } /*SRXAFS_GetStatistics*/
5462 /*------------------------------------------------------------------------
5463 * EXPORTED SRXAFS_XStatsVersion
5466 * Routine called by the server-side RPC interface to implement
5467 * pulling out the xstat version number for the File Server.
5470 * a_versionP : Ptr to the version number variable to set.
5476 * Nothing interesting.
5480 *------------------------------------------------------------------------*/
5482 afs_int32 SRXAFS_XStatsVersion(struct rx_call *a_call, afs_int32 *a_versionP)
5483 { /*SRXAFS_XStatsVersion*/
5485 #if FS_STATS_DETAILED
5486 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5487 struct timeval opStartTime,
5488 opStopTime; /* Start/stop times for RPC op*/
5489 struct timeval elapsedTime; /* Transfer time */
5492 * Set our stats pointer, remember when the RPC operation started, and
5493 * tally the operation.
5495 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5499 TM_GetTimeOfDay(&opStartTime, 0);
5500 #endif /* FS_STATS_DETAILED */
5502 *a_versionP = AFS_XSTAT_VERSION;
5504 #if FS_STATS_DETAILED
5505 TM_GetTimeOfDay(&opStopTime, 0);
5506 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5507 fs_stats_AddTo((opP->sumTime), elapsedTime);
5508 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5509 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5510 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5512 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5513 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5516 (opP->numSuccesses)++;
5518 #endif /* FS_STATS_DETAILED */
5522 } /*SRXAFS_XStatsVersion*/
5525 /*------------------------------------------------------------------------
5526 * PRIVATE FillPerfValues
5529 * Routine called to fill a regular performance data structure.
5532 * a_perfP : Ptr to perf structure to fill
5538 * Various collections need this info, so the guts were put in
5539 * this separate routine.
5543 *------------------------------------------------------------------------*/
5545 static void FillPerfValues(struct afs_PerfStats *a_perfP)
5546 { /*FillPerfValues*/
5548 int dir_Buffers; /*# buffers in use by dir package*/
5549 int dir_Calls; /*# read calls in dir package*/
5550 int dir_IOs; /*# I/O ops in dir package*/
5553 * Vnode cache section.
5555 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5556 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5557 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5558 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5559 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5560 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5561 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5562 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5563 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5564 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5565 a_perfP->vcache_H_Entries = VolumeCacheSize;
5566 a_perfP->vcache_H_Gets = VolumeGets;
5567 a_perfP->vcache_H_Replacements = VolumeReplacements;
5570 * Directory section.
5572 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5573 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5574 a_perfP->dir_Calls = (afs_int32 )dir_Calls;
5575 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5580 a_perfP->rx_packetRequests =
5581 (afs_int32) rx_stats.packetRequests;
5582 a_perfP->rx_noPackets_RcvClass =
5583 (afs_int32) rx_stats.receivePktAllocFailures;
5584 a_perfP->rx_noPackets_SendClass =
5585 (afs_int32) rx_stats.sendPktAllocFailures;
5586 a_perfP->rx_noPackets_SpecialClass =
5587 (afs_int32) rx_stats.specialPktAllocFailures;
5588 a_perfP->rx_socketGreedy =
5589 (afs_int32) rx_stats.socketGreedy;
5590 a_perfP->rx_bogusPacketOnRead =
5591 (afs_int32) rx_stats.bogusPacketOnRead;
5592 a_perfP->rx_bogusHost =
5593 (afs_int32) rx_stats.bogusHost;
5594 a_perfP->rx_noPacketOnRead =
5595 (afs_int32) rx_stats.noPacketOnRead;
5596 a_perfP->rx_noPacketBuffersOnRead =
5597 (afs_int32) rx_stats.noPacketBuffersOnRead;
5598 a_perfP->rx_selects =
5599 (afs_int32) rx_stats.selects;
5600 a_perfP->rx_sendSelects =
5601 (afs_int32) rx_stats.sendSelects;
5602 a_perfP->rx_packetsRead_RcvClass =
5603 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
5604 a_perfP->rx_packetsRead_SendClass =
5605 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
5606 a_perfP->rx_packetsRead_SpecialClass =
5607 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
5608 a_perfP->rx_dataPacketsRead =
5609 (afs_int32) rx_stats.dataPacketsRead;
5610 a_perfP->rx_ackPacketsRead =
5611 (afs_int32) rx_stats.ackPacketsRead;
5612 a_perfP->rx_dupPacketsRead =
5613 (afs_int32) rx_stats.dupPacketsRead;
5614 a_perfP->rx_spuriousPacketsRead =
5615 (afs_int32) rx_stats.spuriousPacketsRead;
5616 a_perfP->rx_packetsSent_RcvClass =
5617 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
5618 a_perfP->rx_packetsSent_SendClass =
5619 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
5620 a_perfP->rx_packetsSent_SpecialClass =
5621 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
5622 a_perfP->rx_ackPacketsSent =
5623 (afs_int32) rx_stats.ackPacketsSent;
5624 a_perfP->rx_pingPacketsSent =
5625 (afs_int32) rx_stats.pingPacketsSent;
5626 a_perfP->rx_abortPacketsSent =
5627 (afs_int32) rx_stats.abortPacketsSent;
5628 a_perfP->rx_busyPacketsSent =
5629 (afs_int32) rx_stats.busyPacketsSent;
5630 a_perfP->rx_dataPacketsSent =
5631 (afs_int32) rx_stats.dataPacketsSent;
5632 a_perfP->rx_dataPacketsReSent =
5633 (afs_int32) rx_stats.dataPacketsReSent;
5634 a_perfP->rx_dataPacketsPushed =
5635 (afs_int32) rx_stats.dataPacketsPushed;
5636 a_perfP->rx_ignoreAckedPacket =
5637 (afs_int32) rx_stats.ignoreAckedPacket;
5638 a_perfP->rx_totalRtt_Sec =
5639 (afs_int32) rx_stats.totalRtt.sec;
5640 a_perfP->rx_totalRtt_Usec =
5641 (afs_int32) rx_stats.totalRtt.usec;
5642 a_perfP->rx_minRtt_Sec =
5643 (afs_int32) rx_stats.minRtt.sec;
5644 a_perfP->rx_minRtt_Usec =
5645 (afs_int32) rx_stats.minRtt.usec;
5646 a_perfP->rx_maxRtt_Sec =
5647 (afs_int32) rx_stats.maxRtt.sec;
5648 a_perfP->rx_maxRtt_Usec =
5649 (afs_int32) rx_stats.maxRtt.usec;
5650 a_perfP->rx_nRttSamples =
5651 (afs_int32) rx_stats.nRttSamples;
5652 a_perfP->rx_nServerConns =
5653 (afs_int32) rx_stats.nServerConns;
5654 a_perfP->rx_nClientConns =
5655 (afs_int32) rx_stats.nClientConns;
5656 a_perfP->rx_nPeerStructs =
5657 (afs_int32) rx_stats.nPeerStructs;
5658 a_perfP->rx_nCallStructs =
5659 (afs_int32) rx_stats.nCallStructs;
5660 a_perfP->rx_nFreeCallStructs =
5661 (afs_int32) rx_stats.nFreeCallStructs;
5663 a_perfP->host_NumHostEntries = HTs;
5664 a_perfP->host_HostBlocks = HTBlocks;
5665 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5666 &(a_perfP->host_HostsInSameNetOrSubnet),
5667 &(a_perfP->host_HostsInDiffSubnet),
5668 &(a_perfP->host_HostsInDiffNetwork));
5669 a_perfP->host_NumClients = CEs;
5670 a_perfP->host_ClientBlocks = CEBlocks;
5672 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5674 } /*FillPerfValues*/
5677 /*------------------------------------------------------------------------
5678 * EXPORTED SRXAFS_GetXStats
5681 * Routine called by the server-side callback RPC interface to
5682 * implement getting the given data collection from the extended
5683 * File Server statistics.
5686 * a_call : Ptr to Rx call on which this request came in.
5687 * a_clientVersionNum : Client version number.
5688 * a_opCode : Desired operation.
5689 * a_serverVersionNumP : Ptr to version number to set.
5690 * a_timeP : Ptr to time value (seconds) to set.
5691 * a_dataP : Ptr to variable array structure to return
5698 * Nothing interesting.
5702 *------------------------------------------------------------------------*/
5704 afs_int32 SRXAFS_GetXStats(struct rx_call *a_call,
5705 afs_int32 a_clientVersionNum,
5706 afs_int32 a_collectionNumber,
5707 afs_int32 *a_srvVersionNumP,
5709 AFS_CollData *a_dataP)
5710 { /*SRXAFS_GetXStats*/
5712 register int code; /*Return value*/
5713 afs_int32 *dataBuffP; /*Ptr to data to be returned*/
5714 afs_int32 dataBytes; /*Bytes in data buffer*/
5715 #if FS_STATS_DETAILED
5716 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5717 struct timeval opStartTime,
5718 opStopTime; /* Start/stop times for RPC op*/
5719 struct timeval elapsedTime; /* Transfer time */
5722 * Set our stats pointer, remember when the RPC operation started, and
5723 * tally the operation.
5725 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
5729 TM_GetTimeOfDay(&opStartTime, 0);
5730 #endif /* FS_STATS_DETAILED */
5733 * Record the time of day and the server version number.
5735 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5736 *a_timeP = FT_ApproxTime();
5739 * Stuff the appropriate data in there (assume victory)
5743 ViceLog(1, ("Received GetXStats call for collection %d\n", a_collectionNumber));
5747 * We're not keeping stats, so just return successfully with
5750 a_dataP->AFS_CollData_len = 0;
5751 a_dataP->AFS_CollData_val = NULL;
5754 switch(a_collectionNumber) {
5755 case AFS_XSTATSCOLL_CALL_INFO:
5757 * Pass back all the call-count-related data.
5759 * >>> We are forced to allocate a separate area in which to
5760 * >>> put this stuff in by the RPC stub generator, since it
5761 * >>> will be freed at the tail end of the server stub code.
5765 * I don't think call-level stats are being collected yet
5766 * for the File Server.
5768 dataBytes = sizeof(struct afs_Stats);
5769 dataBuffP = (afs_int32 *)malloc(dataBytes);
5770 memcpy(dataBuffP, &afs_cmstats, dataBytes);
5771 a_dataP->AFS_CollData_len = dataBytes>>2;
5772 a_dataP->AFS_CollData_val = dataBuffP;
5774 a_dataP->AFS_CollData_len = 0;
5775 a_dataP->AFS_CollData_val = NULL;
5779 case AFS_XSTATSCOLL_PERF_INFO:
5781 * Pass back all the regular performance-related data.
5783 * >>> We are forced to allocate a separate area in which to
5784 * >>> put this stuff in by the RPC stub generator, since it
5785 * >>> will be freed at the tail end of the server stub code.
5788 afs_perfstats.numPerfCalls++;
5789 FillPerfValues(&afs_perfstats);
5792 * Don't overwrite the spares at the end.
5795 dataBytes = sizeof(struct afs_PerfStats);
5796 dataBuffP = (afs_int32 *)osi_Alloc(dataBytes);
5797 memcpy(dataBuffP, &afs_perfstats, dataBytes);
5798 a_dataP->AFS_CollData_len = dataBytes>>2;
5799 a_dataP->AFS_CollData_val = dataBuffP;
5802 case AFS_XSTATSCOLL_FULL_PERF_INFO:
5804 * Pass back the full collection of performance-related data.
5805 * We have to stuff the basic, overall numbers in, but the
5806 * detailed numbers are kept in the structure already.
5808 * >>> We are forced to allocate a separate area in which to
5809 * >>> put this stuff in by the RPC stub generator, since it
5810 * >>> will be freed at the tail end of the server stub code.
5813 afs_perfstats.numPerfCalls++;
5814 #if FS_STATS_DETAILED
5815 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
5816 FillPerfValues(&afs_FullPerfStats.overall);
5819 * Don't overwrite the spares at the end.
5822 dataBytes = sizeof(struct fs_stats_FullPerfStats);
5823 dataBuffP = (afs_int32 *)osi_Alloc(dataBytes);
5824 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
5825 a_dataP->AFS_CollData_len = dataBytes>>2;
5826 a_dataP->AFS_CollData_val = dataBuffP;
5832 * Illegal collection number.
5834 a_dataP->AFS_CollData_len = 0;
5835 a_dataP->AFS_CollData_val = NULL;
5837 } /*Switch on collection number*/
5839 #if FS_STATS_DETAILED
5840 TM_GetTimeOfDay(&opStopTime, 0);
5843 (opP->numSuccesses)++;
5844 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5845 fs_stats_AddTo((opP->sumTime), elapsedTime);
5846 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5847 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5848 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5850 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5851 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5856 #endif /* FS_STATS_DETAILED */
5860 } /*SRXAFS_GetXStats*/
5863 afs_int32 SRXAFS_GiveUpCallBacks (struct rx_call *acall,
5864 struct AFSCBFids *FidArray,
5865 struct AFSCBs *CallBackArray)
5867 afs_int32 errorCode;
5869 struct client *client;
5870 struct rx_connection *tcon;
5871 #if FS_STATS_DETAILED
5872 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5873 struct timeval opStartTime,
5874 opStopTime; /* Start/stop times for RPC op*/
5875 struct timeval elapsedTime; /* Transfer time */
5878 * Set our stats pointer, remember when the RPC operation started, and
5879 * tally the operation.
5881 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
5885 TM_GetTimeOfDay(&opStartTime, 0);
5886 #endif /* FS_STATS_DETAILED */
5888 ViceLog(1, ("SAFS_GiveUpCallBacks (Noffids=%d)\n", FidArray->AFSCBFids_len));
5890 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
5892 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
5893 goto Bad_GiveUpCallBacks;
5895 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
5896 ViceLog(0, ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
5897 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
5898 (tcon->peer ? tcon->peer->host : 0)));
5900 goto Bad_GiveUpCallBacks;
5903 errorCode = GetClient(tcon, &client);
5905 for (i=0; i < FidArray->AFSCBFids_len; i++) {
5906 register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
5907 DeleteCallBack(client->host, fid);
5911 Bad_GiveUpCallBacks:
5912 CallPostamble(tcon);
5914 #if FS_STATS_DETAILED
5915 TM_GetTimeOfDay(&opStopTime, 0);
5916 if (errorCode == 0) {
5918 (opP->numSuccesses)++;
5919 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5920 fs_stats_AddTo((opP->sumTime), elapsedTime);
5921 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5922 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5923 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5925 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5926 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5930 #endif /* FS_STATS_DETAILED */
5934 } /*SRXAFS_GiveUpCallBacks*/
5937 afs_int32 SRXAFS_NGetVolumeInfo (struct rx_call *acall,
5939 struct AFSVolumeInfo *avolinfo)
5941 return(VNOVOL); /* XXX Obsolete routine XXX */
5943 } /*SRXAFS_NGetVolumeInfo*/
5947 * Dummy routine. Should never be called (the cache manager should only
5948 * invoke this interface when communicating with a AFS/DFS Protocol
5951 afs_int32 SRXAFS_Lookup(struct rx_call *call_p,
5952 struct AFSFid *afs_dfid_p,
5954 struct AFSFid *afs_fid_p,
5955 struct AFSFetchStatus *afs_status_p,
5956 struct AFSFetchStatus *afs_dir_status_p,
5957 struct AFSCallBack *afs_callback_p,
5958 struct AFSVolSync *afs_sync_p)
5964 afs_int32 SRXAFS_FlushCPS(struct rx_call *acall,
5965 struct ViceIds *vids,
5966 struct IPAddrs *addrs,
5972 afs_int32 nids, naddrs;
5973 afs_int32 *vd, *addr;
5974 int errorCode = 0; /* return code to caller */
5975 struct client *client;
5976 struct rx_connection *tcon = rx_ConnectionOf(acall);
5978 ViceLog(1, ("SRXAFS_FlushCPS\n"));
5980 AFSCallStats.TotalCalls++;
5982 nids = vids->ViceIds_len; /* # of users in here */
5983 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
5984 if (nids < 0 || naddrs < 0) {
5989 vd = vids->ViceIds_val;
5990 for (i=0; i<nids; i++, vd++) {
5993 client = h_ID2Client(*vd); /* returns client locked, or NULL */
5997 BoostSharedLock(&client->lock);
5998 client->prfail = 2; /* Means re-eval client's cps */
6001 rx_SetRock(((struct rx_connection *) client->tcon), 0);
6004 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6005 free(client->CPS.prlist_val);
6006 client->CPS.prlist_val = NULL;
6007 client->CPS.prlist_len = 0;
6009 ReleaseWriteLock(&client->lock);
6012 addr = addrs->IPAddrs_val;
6013 for (i=0; i<naddrs; i++, addr++) {
6015 h_flushhostcps(*addr, 7001);
6019 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6021 } /*SRXAFS_FlushCPS */
6023 /* worthless hack to let CS keep running ancient software */
6024 static int afs_vtoi(register char *aname)
6026 register afs_int32 temp;
6030 while((tc = *aname++)) {
6031 if (tc > '9' || tc < '0') return 0; /* invalid name */
6039 * may get name or #, but must handle all weird cases (recognize readonly
6040 * or backup volumes by name or #
6042 static afs_int32 CopyVolumeEntry(char *aname,register struct vldbentry *ave,
6043 register struct VolumeInfo *av)
6045 register int i, j, vol;
6046 afs_int32 mask, whichType;
6047 afs_uint32 *serverHost, *typePtr;
6049 /* figure out what type we want if by name */
6051 if (i >= 8 && strcmp(aname+i-7, ".backup") == 0)
6052 whichType = BACKVOL;
6053 else if (i >= 10 && strcmp(aname+i-9, ".readonly")==0)
6055 else whichType = RWVOL;
6057 vol = afs_vtoi(aname);
6058 if (vol == 0) vol = ave->volumeId[whichType];
6061 * Now vol has volume # we're interested in. Next, figure out the type
6062 * of the volume by looking finding it in the vldb entry
6064 if ((ave->flags&VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6068 else if ((ave->flags&VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6072 else if ((ave->flags&VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6073 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6074 whichType = BACKVOL;
6077 return EINVAL; /* error: can't find volume in vldb entry */
6079 typePtr = &av->Type0;
6080 serverHost = &av->Server0;
6082 av->Type = whichType;
6083 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6084 if (ave->flags & VLF_RWEXISTS) typePtr[RWVOL] = ave->volumeId[RWVOL];
6085 if (ave->flags & VLF_ROEXISTS) typePtr[ROVOL] = ave->volumeId[ROVOL];
6086 if (ave->flags & VLF_BACKEXISTS) typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6088 for(i=0,j=0; i<ave->nServers; i++) {
6089 if ((ave->serverFlags[i] & mask) == 0) continue; /* wrong volume */
6090 serverHost[j] = ave->serverNumber[i];
6093 av->ServerCount = j;
6094 if (j < 8) serverHost[j++] = 0; /* bogus 8, but compat only now */
6098 static afs_int32 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6100 static struct rx_connection *vlConn = 0;
6101 static int down = 0;
6102 static afs_int32 lastDownTime = 0;
6103 struct vldbentry tve;
6104 struct rx_securityClass *vlSec;
6105 register afs_int32 code;
6108 vlSec = rxnull_NewClientSecurityObject();
6109 vlConn = rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6110 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6112 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6113 return 1; /* failure */
6116 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6117 if (code >= 0) down = 0; /* call worked */
6120 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6126 /* otherwise convert to old format vldb entry */
6127 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6136 afs_int32 SRXAFS_GetVolumeInfo (struct rx_call *acall,
6138 struct VolumeInfo *avolinfo)
6141 struct rx_connection *tcon;
6142 #if FS_STATS_DETAILED
6143 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6144 struct timeval opStartTime,
6145 opStopTime; /* Start/stop times for RPC op*/
6146 struct timeval elapsedTime; /* Transfer time */
6149 * Set our stats pointer, remember when the RPC operation started, and
6150 * tally the operation.
6152 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6156 TM_GetTimeOfDay(&opStartTime, 0);
6157 #endif /* FS_STATS_DETAILED */
6158 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
6159 goto Bad_GetVolumeInfo;
6162 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6165 code = TryLocalVLServer(avolid, avolinfo);
6166 ViceLog(1, ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6167 code, avolinfo->Vid, avolinfo->Type,
6168 avolinfo->Server0, avolinfo->Server1, avolinfo->Server2,
6169 avolinfo->Server3));
6170 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6173 CallPostamble(tcon);
6175 #if FS_STATS_DETAILED
6176 TM_GetTimeOfDay(&opStopTime, 0);
6179 (opP->numSuccesses)++;
6180 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6181 fs_stats_AddTo((opP->sumTime), elapsedTime);
6182 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6183 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6184 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6186 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6187 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6192 #endif /* FS_STATS_DETAILED */
6196 } /*SRXAFS_GetVolumeInfo*/
6199 afs_int32 SRXAFS_GetVolumeStatus(struct rx_call *acall,
6201 AFSFetchVolumeStatus *FetchVolStatus,
6206 Vnode * targetptr = 0; /* vnode of the new file */
6207 Vnode * parentwhentargetnotdir = 0; /* vnode of parent */
6208 int errorCode = 0; /* error code */
6209 Volume * volptr = 0; /* pointer to the volume header */
6210 struct client * client; /* pointer to client entry */
6211 afs_int32 rights, anyrights; /* rights for this and any user */
6213 struct rx_connection *tcon;
6214 #if FS_STATS_DETAILED
6215 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6216 struct timeval opStartTime,
6217 opStopTime; /* Start/stop times for RPC op*/
6218 struct timeval elapsedTime; /* Transfer time */
6221 * Set our stats pointer, remember when the RPC operation started, and
6222 * tally the operation.
6224 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6228 TM_GetTimeOfDay(&opStartTime, 0);
6229 #endif /* FS_STATS_DETAILED */
6231 ViceLog(1,("SAFS_GetVolumeStatus for volume %u\n", avolid));
6232 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
6233 goto Bad_GetVolumeStatus;
6236 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6241 goto Bad_GetVolumeStatus;
6243 dummyFid.Volume = avolid, dummyFid.Vnode = (afs_int32)ROOTVNODE, dummyFid.Unique = 1;
6245 if ((errorCode = GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr,
6246 MustBeDIR, &parentwhentargetnotdir,
6247 &client, READ_LOCK, &rights, &anyrights)))
6248 goto Bad_GetVolumeStatus;
6250 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6252 goto Bad_GetVolumeStatus;
6254 RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6256 Bad_GetVolumeStatus:
6257 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
6258 ViceLog(2,("SAFS_GetVolumeStatus returns %d\n",errorCode));
6259 /* next is to guarantee out strings exist for stub */
6260 if (*Name == 0) {*Name = (char *) malloc(1); **Name = 0;}
6261 if (*Motd == 0) {*Motd = (char *) malloc(1); **Motd = 0;}
6262 if (*OfflineMsg == 0) {*OfflineMsg = (char *) malloc(1); **OfflineMsg = 0;}
6263 CallPostamble(tcon);
6265 #if FS_STATS_DETAILED
6266 TM_GetTimeOfDay(&opStopTime, 0);
6267 if (errorCode == 0) {
6269 (opP->numSuccesses)++;
6270 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6271 fs_stats_AddTo((opP->sumTime), elapsedTime);
6272 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6273 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6274 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6276 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6277 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6282 #endif /* FS_STATS_DETAILED */
6285 } /*SRXAFS_GetVolumeStatus*/
6288 afs_int32 SRXAFS_SetVolumeStatus (struct rx_call *acall,
6290 AFSStoreVolumeStatus *StoreVolStatus,
6295 Vnode * targetptr = 0; /* vnode of the new file */
6296 Vnode * parentwhentargetnotdir = 0; /* vnode of parent */
6297 int errorCode = 0; /* error code */
6298 Volume * volptr = 0; /* pointer to the volume header */
6299 struct client * client; /* pointer to client entry */
6300 afs_int32 rights, anyrights; /* rights for this and any user */
6302 struct rx_connection *tcon = rx_ConnectionOf(acall);
6303 #if FS_STATS_DETAILED
6304 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6305 struct timeval opStartTime,
6306 opStopTime; /* Start/stop times for RPC op*/
6307 struct timeval elapsedTime; /* Transfer time */
6310 * Set our stats pointer, remember when the RPC operation started, and
6311 * tally the operation.
6313 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6317 TM_GetTimeOfDay(&opStartTime, 0);
6318 #endif /* FS_STATS_DETAILED */
6320 ViceLog(1,("SAFS_SetVolumeStatus for volume %u\n", avolid));
6321 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
6322 goto Bad_SetVolumeStatus;
6325 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6330 goto Bad_SetVolumeStatus;
6332 dummyFid.Volume = avolid, dummyFid.Vnode = (afs_int32)ROOTVNODE, dummyFid.Unique = 1;
6334 if ((errorCode = GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr,
6335 MustBeDIR, &parentwhentargetnotdir,
6336 &client, READ_LOCK, &rights, &anyrights)))
6337 goto Bad_SetVolumeStatus;
6339 if (readonlyServer) {
6340 errorCode = VREADONLY;
6341 goto Bad_SetVolumeStatus;
6343 if (VanillaUser(client)) {
6345 goto Bad_SetVolumeStatus;
6348 errorCode = RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name,
6351 Bad_SetVolumeStatus:
6352 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *)0, volptr);
6353 ViceLog(2,("SAFS_SetVolumeStatus returns %d\n",errorCode));
6354 CallPostamble(tcon);
6356 #if FS_STATS_DETAILED
6357 TM_GetTimeOfDay(&opStopTime, 0);
6358 if (errorCode == 0) {
6360 (opP->numSuccesses)++;
6361 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6362 fs_stats_AddTo((opP->sumTime), elapsedTime);
6363 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6364 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6365 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6367 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6368 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6373 #endif /* FS_STATS_DETAILED */
6375 osi_auditU (acall, SetVolumeStatusEvent, errorCode, AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6378 } /*SRXAFS_SetVolumeStatus*/
6380 #define DEFAULTVOLUME "root.afs"
6382 afs_int32 SRXAFS_GetRootVolume (struct rx_call *acall, char **VolumeName)
6387 int errorCode = 0; /* error code */
6388 struct rx_connection *tcon;
6389 #if FS_STATS_DETAILED
6390 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6391 struct timeval opStartTime,
6392 opStopTime; /* Start/stop times for RPC op*/
6393 struct timeval elapsedTime; /* Transfer time */
6396 * Set our stats pointer, remember when the RPC operation started, and
6397 * tally the operation.
6399 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6403 TM_GetTimeOfDay(&opStartTime, 0);
6404 #endif /* FS_STATS_DETAILED */
6406 return FSERR_EOPNOTSUPP;
6409 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
6410 goto Bad_GetRootVolume;
6412 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6416 fd = open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6418 strcpy(temp, DEFAULTVOLUME);
6420 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6421 lockf(fd, F_LOCK, 0);
6425 len = read(fd, temp, 256);
6426 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6427 lockf(fd, F_ULOCK, 0);
6432 if (temp[len-1] == '\n') len--;
6435 *VolumeName = temp; /* freed by rx server-side stub */
6438 CallPostamble(tcon);
6440 #if FS_STATS_DETAILED
6441 TM_GetTimeOfDay(&opStopTime, 0);
6442 if (errorCode == 0) {
6444 (opP->numSuccesses)++;
6445 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6446 fs_stats_AddTo((opP->sumTime), elapsedTime);
6447 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6448 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6449 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6451 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6452 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6456 #endif /* FS_STATS_DETAILED */
6461 } /*SRXAFS_GetRootVolume*/
6464 /* still works because a struct CBS is the same as a struct AFSOpaque */
6465 afs_int32 SRXAFS_CheckToken (struct rx_call *acall,
6467 struct AFSOpaque *Token)
6470 struct rx_connection *tcon;
6471 #if FS_STATS_DETAILED
6472 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6473 struct timeval opStartTime,
6474 opStopTime; /* Start/stop times for RPC op*/
6475 struct timeval elapsedTime; /* Transfer time */
6478 * Set our stats pointer, remember when the RPC operation started, and
6479 * tally the operation.
6481 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6485 TM_GetTimeOfDay(&opStartTime, 0);
6486 #endif /* FS_STATS_DETAILED */
6488 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
6489 goto Bad_CheckToken;
6491 code = FSERR_ECONNREFUSED;
6494 CallPostamble(tcon);
6496 #if FS_STATS_DETAILED
6497 TM_GetTimeOfDay(&opStopTime, 0);
6500 (opP->numSuccesses)++;
6501 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6502 fs_stats_AddTo((opP->sumTime), elapsedTime);
6503 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6504 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6505 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6507 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6508 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6513 #endif /* FS_STATS_DETAILED */
6517 } /*SRXAFS_CheckToken*/
6519 afs_int32 SRXAFS_GetTime (struct rx_call *acall,
6520 afs_uint32 *Seconds,
6521 afs_uint32 *USeconds)
6524 struct rx_connection *tcon;
6526 #if FS_STATS_DETAILED
6527 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6528 struct timeval opStartTime,
6529 opStopTime; /* Start/stop times for RPC op*/
6530 struct timeval elapsedTime; /* Transfer time */
6533 * Set our stats pointer, remember when the RPC operation started, and
6534 * tally the operation.
6536 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
6540 TM_GetTimeOfDay(&opStartTime, 0);
6541 #endif /* FS_STATS_DETAILED */
6543 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon)))
6547 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6550 TM_GetTimeOfDay(&tpl, 0);
6551 *Seconds = tpl.tv_sec;
6552 *USeconds = tpl.tv_usec;
6554 ViceLog(2, ("SAFS_GetTime returns %d, %d\n", *Seconds, *USeconds));
6557 CallPostamble(tcon);
6559 #if FS_STATS_DETAILED
6560 TM_GetTimeOfDay(&opStopTime, 0);
6561 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6564 (opP->numSuccesses)++;
6565 fs_stats_AddTo((opP->sumTime), elapsedTime);
6566 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6567 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6568 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6570 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6571 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6576 #endif /* FS_STATS_DETAILED */
6580 } /*SRXAFS_GetTime*/
6587 * Implement a client's data fetch using Rx.
6590 * volptr : Ptr to the given volume's info.
6591 * targetptr : Pointer to the vnode involved.
6592 * Call : Ptr to the Rx call involved.
6593 * Pos : Offset within the file.
6594 * Len : Length in bytes to read; this value is bogus!
6595 * if FS_STATS_DETAILED
6596 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6598 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6604 FetchData_RXStyle(Volume *volptr,
6606 register struct rx_call *Call,
6609 afs_int32 Int64Mode,
6610 #if FS_STATS_DETAILED
6611 afs_size_t *a_bytesToFetchP,
6612 afs_size_t *a_bytesFetchedP
6613 #endif /* FS_STATS_DETAILED */
6616 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6617 int errorCode = 0; /* Returned error code to caller */
6622 register char *tbuffer;
6623 #else /* AFS_NT40_ENV */
6624 struct iovec tiov[RX_MAXIOVECS];
6626 #endif /* AFS_NT40_ENV */
6631 struct statfs tstatfs;
6634 #if FS_STATS_DETAILED
6636 * Initialize the byte count arguments.
6638 (*a_bytesToFetchP) = 0;
6639 (*a_bytesFetchedP) = 0;
6640 #endif /* FS_STATS_DETAILED */
6642 #ifdef AFS_LARGEFILE_ENV
6643 ViceLog(25, ("FetchData_RXStyle: Pos (0X%x,0X%x), Len (0X%x,0X%x)\n",
6644 (unsigned) (Pos >> 32), (unsigned) (Pos & 0xffffffff),
6645 (unsigned) (Len >> 32), (unsigned) (Len & 0xffffffff)));
6646 #else /* !AFS_LARGEFILE_ENV */
6647 ViceLog(25, ("FetchData_RXStyle: Pos 0X%x, Len 0X%x\n",
6650 #endif /* !AFS_LARGEFILE_ENV */
6652 if (!VN_GET_INO(targetptr)) {
6653 afs_int32 zero = htonl(0);
6655 * This is used for newly created files; we simply send 0 bytes
6656 * back to make the cache manager happy...
6659 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6660 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6663 TM_GetTimeOfDay(&StartTime, 0);
6664 ihP = targetptr->handle;
6666 if (fdP == NULL) return EIO;
6667 optSize = sendBufSize;
6668 tlen = FDH_SIZE(fdP);
6669 #ifdef AFS_LARGEFILE_ENV
6670 ViceLog( 25, ("FetchData_RXStyle: file size (0X%x,0X%x)\n",
6671 (unsigned) (tlen >> 32), (unsigned) (tlen & 0xffffffff)));
6672 #else /* !AFS_LARGEFILE_ENV */
6673 ViceLog( 25, ("FetchData_RXStyle: file size 0X%x\n",
6675 #endif /* !AFS_LARGEFILE_ENV */
6681 if (Pos + Len > tlen) Len = tlen - Pos; /* get length we should send */
6682 FDH_SEEK(fdP, Pos, 0);
6684 afs_int32 high, low;
6685 SplitOffsetOrSize(Len, high, low);
6686 assert(Int64Mode || high==0);
6689 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
6692 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
6694 #if FS_STATS_DETAILED
6695 (*a_bytesToFetchP) = Len;
6696 #endif /* FS_STATS_DETAILED */
6698 tbuffer = AllocSendBuffer();
6699 #endif /* AFS_NT40_ENV */
6701 if (Len > optSize) tlen = optSize;
6704 errorCode = FDH_READ(fdP, tbuffer, tlen);
6705 if (errorCode != tlen) {
6707 FreeSendBuffer((struct afs_buffer *) tbuffer);
6710 errorCode = rx_Write(Call, tbuffer, tlen);
6711 #else /* AFS_NT40_ENV */
6712 errorCode = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, tlen);
6713 if (errorCode <= 0) {
6718 errorCode = FDH_READV(fdP, tiov, tnio);
6719 if (errorCode != tlen) {
6723 errorCode = rx_Writev(Call, tiov, tnio, tlen);
6724 #endif /* AFS_NT40_ENV */
6725 #if FS_STATS_DETAILED
6727 * Bump the number of bytes actually sent by the number from this
6730 (*a_bytesFetchedP) += errorCode;
6731 #endif /* FS_STATS_DETAILED */
6732 if (errorCode != tlen) {
6735 FreeSendBuffer((struct afs_buffer *) tbuffer);
6736 #endif /* AFS_NT40_ENV */
6742 FreeSendBuffer((struct afs_buffer *) tbuffer);
6743 #endif /* AFS_NT40_ENV */
6745 TM_GetTimeOfDay(&StopTime, 0);
6747 /* Adjust all Fetch Data related stats */
6749 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
6750 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
6751 AFSCallStats.AccumFetchTime += ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
6752 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
6755 VN_GET_LEN(targLen, targetptr);
6756 AFSCallStats.TotalFetchedBytes += targLen;
6757 AFSCallStats.FetchSize1++;
6758 if (targLen < SIZE2)
6759 AFSCallStats.FetchSize2++;
6760 else if (targLen < SIZE3)
6761 AFSCallStats.FetchSize3++;
6762 else if (targLen < SIZE4)
6763 AFSCallStats.FetchSize4++;
6765 AFSCallStats.FetchSize5++;
6770 } /*FetchData_RXStyle*/
6772 static int GetLinkCountAndSize(Volume *vp, FdHandle_t *fdP, int *lc, afs_size_t *size)
6774 #ifdef AFS_NAMEI_ENV
6776 lhp = IH_OPEN(V_linkHandle(vp));
6780 *lc = nt_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
6782 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
6787 *size = OS_SIZE(fdP->fd_fd);
6788 return (*size == -1) ? -1 : 0;
6792 if (fstat(fdP->fd_fd, &status)<0) {
6796 *lc = GetLinkCount(vp, &status);
6797 *size = status.st_size;
6806 * Implement a client's data store using Rx.
6809 * volptr : Ptr to the given volume's info.
6810 * targetptr : Pointer to the vnode involved.
6811 * Call : Ptr to the Rx call involved.
6812 * Pos : Offset within the file.
6813 * Len : Length in bytes to store; this value is bogus!
6814 * if FS_STATS_DETAILED
6815 * a_bytesToStoreP : Set to the number of bytes to be stored to
6817 * a_bytesStoredP : Set to the actual number of bytes stored to
6822 StoreData_RXStyle(Volume *volptr,
6825 struct client *client,
6826 register struct rx_call *Call,
6829 afs_offs_t FileLength,
6831 #if FS_STATS_DETAILED
6832 afs_size_t *a_bytesToStoreP,
6833 afs_size_t *a_bytesStoredP
6834 #endif /* FS_STATS_DETAILED */
6837 afs_size_t bytesTransfered; /* number of bytes actually transfered */
6838 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
6839 int errorCode = 0; /* Returned error code to caller */
6841 register char *tbuffer; /* data copying buffer */
6842 #else /* AFS_NT40_ENV */
6843 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
6844 int tnio; /* temp for iovec size */
6845 #endif /* AFS_NT40_ENV */
6846 afs_size_t tlen; /* temp for xfr length */
6847 Inode tinode; /* inode for I/O */
6848 afs_size_t optSize; /* optimal transfer size */
6849 afs_size_t DataLength; /* size of inode */
6850 afs_size_t TruncatedLength; /* size after ftruncate */
6851 afs_offs_t NewLength; /* size after this store completes */
6852 afs_size_t adjustSize; /* bytes to call VAdjust... with */
6853 int linkCount; /* link count on inode */
6856 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
6858 #if FS_STATS_DETAILED
6860 * Initialize the byte count arguments.
6862 (*a_bytesToStoreP) = 0;
6863 (*a_bytesStoredP) = 0;
6864 #endif /* FS_STATS_DETAILED */
6867 * We break the callbacks here so that the following signal will not
6870 BreakCallBack(client->host, Fid, 0);
6872 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
6873 /* the inode should have been created in Alloc_NewVnode */
6874 logHostAddr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(Call)));
6875 ViceLog(0, ("StoreData_RXStyle : Inode non-existent Fid = %u.%d.%d, inode = %d, Pos %d Host %s\n",
6876 Fid->Volume, Fid->Vnode, Fid->Unique,
6877 VN_GET_INO(targetptr), Pos, inet_ntoa(logHostAddr) ));
6878 return ENOENT; /* is this proper error code? */
6882 * See if the file has several links (from other volumes). If it
6883 * does, then we have to make a copy before changing it to avoid
6884 *changing read-only clones of this dude
6886 ViceLog(25, ("StoreData_RXStyle : Opening inode %s\n",
6887 PrintInode(NULL, VN_GET_INO(targetptr))));
6888 fdP = IH_OPEN(targetptr->handle);
6891 if (GetLinkCountAndSize(volptr, fdP, &linkCount,
6897 if (linkCount != 1) {
6899 ViceLog(25, ("StoreData_RXStyle : inode %s has more than onelink\n",
6900 PrintInode(NULL, VN_GET_INO(targetptr))));
6901 /* other volumes share this data, better copy it first */
6903 /* Adjust the disk block count by the creation of the new inode.
6904 * We call the special VDiskUsage so we don't adjust the volume's
6905 * quota since we don't want to penalyze the user for afs's internal
6906 * mechanisms (i.e. copy on write overhead.) Also the right size
6907 * of the disk will be recorded...
6910 VN_GET_LEN(size, targetptr);
6911 volptr->partition->flags &= ~PART_DONTUPDATE;
6912 VSetPartitionDiskUsage(volptr->partition);
6913 volptr->partition->flags |= PART_DONTUPDATE;
6914 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
6915 volptr->partition->flags &= ~PART_DONTUPDATE;
6919 ViceLog(25, ("StoreData : calling CopyOnWrite on target dir\n"));
6920 if ((errorCode = CopyOnWrite(targetptr, volptr)))
6922 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
6923 volptr->partition->flags &= ~PART_DONTUPDATE;
6926 volptr->partition->flags &= ~PART_DONTUPDATE;
6927 VSetPartitionDiskUsage(volptr->partition);
6928 fdP = IH_OPEN(targetptr->handle);
6930 ViceLog(25, ("StoreData : Reopen after CopyOnWrite failed\n"));
6934 tinode = VN_GET_INO(targetptr);
6936 assert(VALID_INO(tinode));
6938 /* compute new file length */
6939 NewLength = DataLength;
6940 if (FileLength < NewLength)
6941 /* simulate truncate */
6942 NewLength = FileLength;
6943 TruncatedLength = NewLength; /* remember length after possible ftruncate */
6944 if (Pos + Length > NewLength)
6945 NewLength = Pos+Length; /* and write */
6947 /* adjust the disk block count by the difference in the files */
6949 afs_size_t targSize;
6950 VN_GET_LEN(targSize, targetptr);
6951 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
6953 if((errorCode = AdjustDiskUsage(volptr, adjustSize,
6954 adjustSize - SpareComp(volptr)))) {
6959 /* can signal cache manager to proceed from close now */
6960 /* this bit means that the locks are set and protections are OK */
6961 rx_SetLocalStatus(Call, 1);
6963 TM_GetTimeOfDay(&StartTime, 0);
6965 optSize = sendBufSize;
6967 #ifdef AFS_LARGEFILE_ENV
6968 ViceLog(25, ("StoreData_RXStyle: Pos (0X%x,0X%x), DataLength (0X%x,0X%x), FileLength (0X%x,0X%x), Length (0X%x,0X%x)\n",
6969 (unsigned) (Pos >> 32), (unsigned) (Pos & 0xffffffff),
6970 (unsigned) (DataLength >> 32), (unsigned) (DataLength & 0xffffffff),
6971 (unsigned) (FileLength >> 32), (unsigned) (FileLength & 0xffffffff),
6972 (unsigned) (Length >> 32), (unsigned) (Length & 0xffffffff)));
6973 #else /* !AFS_LARGEFILE_ENV */
6974 ViceLog(25, ("StoreData_RXStyle: Pos 0X%x, DataLength 0X%x, FileLength 0X%x, Length 0X%x\n",
6976 (unsigned) DataLength,
6977 (unsigned) FileLength,
6978 (unsigned) Length));
6979 #endif /* !AFS_LARGEFILE_ENV */
6981 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
6982 if (FileLength < DataLength) FDH_TRUNC(fdP, FileLength);
6983 if (Pos > 0) FDH_SEEK(fdP, Pos, 0);
6984 bytesTransfered = 0;
6986 tbuffer = AllocSendBuffer();
6987 #endif /* AFS_NT40_ENV */
6988 /* if length == 0, the loop below isn't going to do anything, including
6989 * extend the length of the inode, which it must do, since the file system
6990 * assumes that the inode length == vnode's file length. So, we extend
6991 * the file length manually if need be. Note that if file is bigger than
6992 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
6993 * do what we're going to do below.
6995 if (Length == 0 && Pos > TruncatedLength) {
6996 /* Set the file's length; we've already done an lseek to the right
6999 errorCode = FDH_WRITE(fdP, &tlen, 1);
7000 if (errorCode != 1) goto done;
7001 errorCode = FDH_TRUNC(fdP, Pos);
7004 /* have some data to copy */
7005 #if FS_STATS_DETAILED
7006 (*a_bytesToStoreP) = Length;
7007 #endif /* FS_STATS_DETAILED */
7009 if (bytesTransfered >= Length) {
7013 tlen = Length - bytesTransfered; /* how much more to do */
7014 if (tlen > optSize) tlen = optSize; /* bound by buffer size */
7016 errorCode = rx_Read(Call, tbuffer, tlen);
7017 #else /* AFS_NT40_ENV */
7018 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, tlen);
7019 #endif /* AFS_NT40_ENV */
7020 #if FS_STATS_DETAILED
7021 (*a_bytesStoredP) += errorCode;
7022 #endif /* FS_STATS_DETAILED */
7023 if (errorCode <= 0) {
7029 errorCode = FDH_WRITE(fdP, tbuffer, tlen);
7030 #else /* AFS_NT40_ENV */
7031 errorCode = FDH_WRITEV(fdP, tiov, tnio);
7032 #endif /* AFS_NT40_ENV */
7033 if (errorCode != tlen) {
7034 errorCode = VDISKFULL;
7037 bytesTransfered += tlen;
7042 FreeSendBuffer((struct afs_buffer *) tbuffer);
7043 #endif /* AFS_NT40_ENV */
7048 afs_size_t nfSize = FDH_SIZE(fdP);
7049 /* something went wrong: adjust size and return */
7050 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7051 /* changed_newTime is tested in StoreData to detemine if we
7052 * need to update the target vnode.
7054 targetptr->changed_newTime = 1;
7056 /* set disk usage to be correct */
7057 VAdjustDiskUsage(&errorCode, volptr,
7058 (afs_size_t)(nBlocks(nfSize) - nBlocks(NewLength)),
7064 TM_GetTimeOfDay(&StopTime, 0);
7066 VN_SET_LEN(targetptr, NewLength);
7068 /* Update all StoreData related stats */
7070 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7071 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7072 AFSCallStats.StoreSize1++; /* Piggybacked data */
7075 VN_GET_LEN(targLen, targetptr);
7076 if (targLen < SIZE2)
7077 AFSCallStats.StoreSize2++;
7078 else if (targLen < SIZE3)
7079 AFSCallStats.StoreSize3++;
7080 else if (targLen < SIZE4)
7081 AFSCallStats.StoreSize4++;
7083 AFSCallStats.StoreSize5++;
7088 } /*StoreData_RXStyle*/