2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* afs_fileprocs.c - Complete File Server request routines */
12 /* Information Technology Center */
13 /* Carnegie Mellon University */
17 /* Function - A set of routines to handle the various file Server */
18 /* requests; these routines are invoked by rxgen. */
20 /* ********************************************************************** */
23 * in Check_PermissionRights, certain privileges are afforded to the owner
24 * of the volume, or the owner of a file. Are these considered "use of
28 #include <afsconfig.h>
29 #include <afs/param.h>
38 #undef SHARED /* XXX */
43 #include <sys/param.h>
45 #include <sys/ioctl.h>
46 #include <sys/socket.h>
47 #include <netinet/in.h>
48 #include <arpa/inet.h>
59 #ifndef AFS_LINUX20_ENV
61 #include <netinet/if_ether.h>
65 /* included early because of name conflict on IOPEN */
66 #include <sys/inode.h>
70 #endif /* AFS_HPUX_ENV */
74 #include <afs/assert.h>
77 #include <afs/afsint.h>
78 #include <afs/vldbint.h>
79 #include <afs/errors.h>
80 #include <afs/ihandle.h>
81 #include <afs/vnode.h>
82 #include <afs/volume.h>
83 #include <afs/ptclient.h>
84 #include <afs/ptuser.h>
85 #include <afs/prs_fs.h>
88 #include <rx/rx_globals.h>
90 #if ! defined(AFS_SGI_ENV) && ! defined(AFS_AIX32_ENV) && ! defined(AFS_NT40_ENV) && ! defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
93 #if !defined(AFS_NT40_ENV)
96 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
98 #include <sys/statfs.h>
99 #include <sys/lockf.h>
101 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
106 #include <afs/cellconfig.h>
107 #include <afs/keys.h>
109 #include <afs/auth.h>
111 #include <afs/partition.h>
112 #include "viced_prototypes.h"
115 #include <afs/unified_afs.h>
116 #include <afs/audit.h>
117 #include <afs/afsutil.h>
120 extern void SetDirHandle(register DirHandle * dir, register Vnode * vnode);
121 extern void FidZap(DirHandle * file);
122 extern void FidZero(DirHandle * file);
124 #ifdef AFS_PTHREAD_ENV
125 pthread_mutex_t fileproc_glock_mutex;
126 #endif /* AFS_PTHREAD_ENV */
129 #define afs_stat stat64
130 #define afs_fstat fstat64
131 #define afs_open open64
132 #else /* !O_LARGEFILE */
133 #define afs_stat stat
134 #define afs_fstat fstat
135 #define afs_open open
136 #endif /* !O_LARGEFILE */
139 /* Useful local defines used by this module */
142 #define MustNOTBeDIR 1
146 #define TVS_SSTATUS 2
149 #define TVS_MKDIR 0x10
151 #define CHK_FETCH 0x10
152 #define CHK_FETCHDATA 0x10
153 #define CHK_FETCHACL 0x11
154 #define CHK_FETCHSTATUS 0x12
155 #define CHK_STOREDATA 0x00
156 #define CHK_STOREACL 0x01
157 #define CHK_STORESTATUS 0x02
159 #define OWNERREAD 0400
160 #define OWNERWRITE 0200
161 #define OWNEREXEC 0100
162 #ifdef USE_GROUP_PERMS
163 #define GROUPREAD 0040
164 #define GROUPWRITE 0020
165 #define GROUPREXEC 0010
168 /* The following errors were not defined in NT. They are given unique
169 * names here to avoid any potential collision.
171 #define FSERR_ELOOP 90
172 #define FSERR_EOPNOTSUPP 122
173 #define FSERR_ECONNREFUSED 130
175 #define NOTACTIVECALL 0
178 #define CREATE_SGUID_ADMIN_ONLY 1
180 extern struct afsconf_dir *confDir;
181 extern afs_int32 dataVersionHigh;
184 static struct AFSCallStatistics AFSCallStats;
185 #if FS_STATS_DETAILED
186 struct fs_stats_FullPerfStats afs_FullPerfStats;
187 extern int AnonymousID;
188 #endif /* FS_STATS_DETAILED */
189 #if OPENAFS_VOL_STATS
190 static const char nullString[] = "";
191 #endif /* OPENAFS_VOL_STATS */
194 afs_int32 NothingYet;
197 struct afs_FSStats afs_fsstats;
199 void ResetDebug(), SetDebug(), Terminate();
204 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
206 extern afs_int32 implicitAdminRights;
207 extern afs_int32 readonlyServer;
210 * Externals used by the xstat code.
212 extern int VolumeCacheSize, VolumeGets, VolumeReplacements;
213 extern int CEs, CEBlocks;
215 extern int HTs, HTBlocks;
217 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
218 register struct rx_call *Call, afs_sfsize_t Pos,
219 afs_sfsize_t Len, afs_int32 Int64Mode,
220 #if FS_STATS_DETAILED
221 afs_sfsize_t * a_bytesToFetchP,
222 afs_sfsize_t * a_bytesFetchedP
223 #endif /* FS_STATS_DETAILED */
226 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
227 struct AFSFid *Fid, struct client *client,
228 register struct rx_call *Call, afs_fsize_t Pos,
229 afs_fsize_t Length, afs_fsize_t FileLength,
231 #if FS_STATS_DETAILED
232 afs_sfsize_t * a_bytesToStoreP,
233 afs_sfsize_t * a_bytesStoredP
234 #endif /* FS_STATS_DETAILED */
237 #ifdef AFS_SGI_XFS_IOPS_ENV
238 #include <afs/xfsattrs.h>
240 GetLinkCount(Volume * avp, struct stat *astat)
242 if (!strcmp("xfs", astat->st_fstype)) {
243 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
245 return astat->st_nlink;
248 #define GetLinkCount(V, S) (S)->st_nlink
252 SpareComp(Volume * avolp)
254 register afs_int32 temp;
258 temp = V_maxquota(avolp);
260 /* no matter; doesn't check in this case */
264 temp = (temp * PctSpare) / 100;
275 * Set the volume synchronization parameter for this volume. If it changes,
276 * the Cache Manager knows that the volume must be purged from the stat cache.
279 SetVolumeSync(register struct AFSVolSync *async, register Volume * avol)
282 /* date volume instance was created */
285 async->spare1 = avol->header->diskstuff.creationDate;
298 * Note that this function always returns a held host, so
299 * that CallPostamble can block without the host's disappearing.
300 * Call returns rx connection in passed in *tconn
303 CallPreamble(register struct rx_call *acall, int activecall,
304 struct rx_connection **tconn)
307 struct client *tclient;
310 char hoststr[16], hoststr2[16];
312 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
315 *tconn = rx_ConnectionOf(acall);
319 tclient = h_FindClient_r(*tconn);
320 thost = tclient->host;
321 if (tclient->prfail == 1) { /* couldn't get the CPS */
323 h_ReleaseClient_r(tclient);
325 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
329 retry_flag = 0; /* Retry once */
331 /* Take down the old connection and re-read the key file */
333 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
335 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
338 h_ReleaseClient_r(tclient);
341 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
345 tclient->prfail = 2; /* Means re-eval client's cps */
346 h_ReleaseClient_r(tclient);
351 tclient->LastCall = thost->LastCall = FT_ApproxTime();
352 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
353 thost->ActiveCall = thost->LastCall;
356 if (thost->hostFlags & HOSTDELETED) {
358 ("Discarded a packet for deleted host %s:%d\n",
359 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
360 code = VBUSY; /* raced, so retry */
361 } else if ((thost->hostFlags & VENUSDOWN)
362 || (thost->hostFlags & HFE_LATER)) {
363 if (BreakDelayedCallBacks_r(thost)) {
365 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
366 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
367 ntohs(rxr_PortOf(*tconn))));
368 if (MultiProbeAlternateAddress_r(thost)) {
370 ("MultiProbe failed to find new address for host %s:%d\n",
371 afs_inet_ntoa_r(thost->host, hoststr),
372 ntohs(thost->port)));
376 ("MultiProbe found new address for host %s:%d\n",
377 afs_inet_ntoa_r(thost->host, hoststr),
378 ntohs(thost->port)));
379 if (BreakDelayedCallBacks_r(thost)) {
381 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
382 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
383 ntohs(rxr_PortOf(*tconn))));
392 h_ReleaseClient_r(tclient);
401 CallPostamble(register struct rx_connection *aconn, afs_int32 ret)
404 struct client *tclient;
408 tclient = h_FindClient_r(aconn);
409 thost = tclient->host;
410 if (thost->hostFlags & HERRORTRANS)
412 h_ReleaseClient_r(tclient);
415 return (translate ? sys_error_to_et(ret) : ret);
419 * Returns the volume and vnode pointers associated with file Fid; the lock
420 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
421 * are incremented and they must be eventualy released.
424 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
428 static struct timeval restartedat = { 0, 0 };
430 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
432 if ((*volptr) == 0) {
437 *volptr = VGetVolume(&errorCode, (afs_int32) fid->Volume);
442 if ((errorCode == VOFFLINE) && (VInit < 2)) {
443 /* The volume we want may not be attached yet because
444 * the volume initialization is not yet complete.
445 * We can do several things:
446 * 1. return -1, which will cause users to see
447 * "connection timed out". This is more or
448 * less the same as always, except that the servers
449 * may appear to bounce up and down while they
450 * are actually restarting.
451 * 2. return VBUSY which will cause clients to
452 * sleep and retry for 6.5 - 15 minutes, depending
453 * on what version of the CM they are running. If
454 * the file server takes longer than that interval
455 * to attach the desired volume, then the application
456 * will see an ENODEV or EIO. This approach has
457 * the advantage that volumes which have been attached
458 * are immediately available, it keeps the server's
459 * immediate backlog low, and the call is interruptible
460 * by the user. Users see "waiting for busy volume."
461 * 3. sleep here and retry. Some people like this approach
462 * because there is no danger of seeing errors. However,
463 * this approach only works with a bounded number of
464 * clients, since the pending queues will grow without
465 * stopping. It might be better to find a way to take
466 * this call and stick it back on a queue in order to
467 * recycle this thread for a different request.
468 * 4. Return a new error code, which new cache managers will
469 * know enough to interpret as "sleep and retry", without
470 * the upper bound of 6-15 minutes that is imposed by the
471 * VBUSY handling. Users will see "waiting for
472 * busy volume," so they know that something is
473 * happening. Old cache managers must be able to do
474 * something reasonable with this, for instance, mark the
475 * server down. Fortunately, any error code < 0
476 * will elicit that behavior. See #1.
477 * 5. Some combination of the above. I like doing #2 for 10
478 * minutes, followed by #4. 3.1b and 3.2 cache managers
479 * will be fine as long as the restart period is
480 * not longer than 6.5 minutes, otherwise they may
481 * return ENODEV to users. 3.3 cache managers will be
482 * fine for 10 minutes, then will return
483 * ETIMEDOUT. 3.4 cache managers will just wait
484 * until the call works or fails definitively.
485 * NB. The problem with 2,3,4,5 is that old clients won't
486 * fail over to an alternate read-only replica while this
487 * server is restarting. 3.4 clients will fail over right away.
489 if (restartedat.tv_sec == 0) {
490 /* I'm not really worried about when we restarted, I'm */
491 /* just worried about when the first VBUSY was returned. */
492 TM_GetTimeOfDay(&restartedat, 0);
495 afs_perfstats.fs_nBusies++;
498 return (busyonrst ? VBUSY : VRESTARTING);
501 TM_GetTimeOfDay(&now, 0);
502 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
505 afs_perfstats.fs_nBusies++;
508 return (busyonrst ? VBUSY : VRESTARTING);
510 return (VRESTARTING);
514 /* allow read operations on busy volume */
515 else if (errorCode == VBUSY && lock == READ_LOCK) {
518 } else if (errorCode)
525 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
528 if ((*vptr)->disk.uniquifier != fid->Unique) {
529 VPutVnode(&fileCode, *vptr);
530 assert(fileCode == 0);
532 return (VNOVNODE); /* return the right error code, at least */
538 * This routine returns the ACL associated with the targetptr. If the
539 * targetptr isn't a directory, we access its parent dir and get the ACL
540 * thru the parent; in such case the parent's vnode is returned in
544 SetAccessList(Vnode ** targetptr, Volume ** volume,
545 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
546 AFSFid * Fid, int Lock)
548 if ((*targetptr)->disk.type == vDirectory) {
550 *ACL = VVnodeACL(*targetptr);
551 *ACLSize = VAclSize(*targetptr);
559 parentvnode = (*targetptr)->disk.parent;
560 VPutVnode(&errorCode, *targetptr);
564 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
567 *ACL = VVnodeACL(*parent);
568 *ACLSize = VAclSize(*parent);
569 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
571 if ((*targetptr)->disk.parent != parentvnode) {
572 VPutVnode(&errorCode, *parent);
583 /* Must not be called with H_LOCK held */
585 client_CheckRights(struct client *client, struct acl_accessList *ACL,
589 ObtainReadLock(&client->lock);
590 if (client->CPS.prlist_len > 0 && !client->deleted &&
591 client->host && !(client->host->hostFlags & HOSTDELETED))
592 acl_CheckRights(ACL, &client->CPS, rights);
593 ReleaseReadLock(&client->lock);
596 /* Must not be called with H_LOCK held */
598 client_HasAsMember(struct client *client, afs_int32 id)
602 ObtainReadLock(&client->lock);
603 if (client->CPS.prlist_len > 0 && !client->deleted &&
604 client->host && !(client->host->hostFlags & HOSTDELETED))
605 code = acl_IsAMember(id, &client->CPS);
606 ReleaseReadLock(&client->lock);
611 * Compare the directory's ACL with the user's access rights in the client
612 * connection and return the user's and everybody else's access permissions
613 * in rights and anyrights, respectively
616 GetRights(struct client *client, struct acl_accessList *ACL,
617 afs_int32 * rights, afs_int32 * anyrights)
619 extern prlist SystemAnyUserCPS;
620 afs_int32 hrights = 0;
621 #ifndef AFS_PTHREAD_ENV
625 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
626 ViceLog(0, ("CheckRights failed\n"));
631 client_CheckRights(client, ACL, rights);
633 /* wait if somebody else is already doing the getCPS call */
635 while (client->host->hostFlags & HCPS_INPROGRESS) {
636 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
637 #ifdef AFS_PTHREAD_ENV
638 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
639 #else /* AFS_PTHREAD_ENV */
641 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
642 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
643 #endif /* AFS_PTHREAD_ENV */
646 if (client->host->hcps.prlist_len && !client->host->hcps.prlist_val) {
648 ("CheckRights: len=%u, for host=0x%x\n",
649 client->host->hcps.prlist_len, client->host->host));
651 acl_CheckRights(ACL, &client->host->hcps, &hrights);
653 /* Allow system:admin the rights given with the -implicit option */
654 if (client_HasAsMember(client, SystemId))
655 *rights |= implicitAdminRights;
658 *anyrights |= hrights;
665 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
666 * a System:Administrator)
669 VanillaUser(struct client *client)
671 if (client_HasAsMember(client, SystemId))
672 return (0); /* not a system administrator, then you're "vanilla" */
679 * This unusual afs_int32-parameter routine encapsulates all volume package related
680 * operations together in a single function; it's called by almost all AFS
684 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
685 Vnode ** targetptr, int chkforDir, Vnode ** parent,
686 struct client **client, int locktype, afs_int32 * rights,
687 afs_int32 * anyrights)
689 struct acl_accessList *aCL; /* Internal access List */
690 int aCLSize; /* size of the access list */
691 int errorCode = 0; /* return code to caller */
693 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
696 if (chkforDir == MustNOTBeDIR
697 && ((*targetptr)->disk.type == vDirectory))
699 else if (chkforDir == MustBeDIR
700 && ((*targetptr)->disk.type != vDirectory))
704 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
705 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
706 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
708 if (chkforDir == MustBeDIR)
709 assert((*parent) == 0);
711 if ((errorCode = GetClient(tcon, client)) != 0)
716 GetRights(*client, aCL, rights, anyrights);
717 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
718 if ((*targetptr)->disk.type != vDirectory) {
719 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
720 if ((*targetptr)->disk.owner == (*client)->ViceId)
721 (*rights) |= PRSFS_ADMINISTER;
723 (*rights) &= ~PRSFS_ADMINISTER;
725 #ifdef ADMIN_IMPLICIT_LOOKUP
726 /* admins get automatic lookup on everything */
727 if (!VanillaUser(*client))
728 (*rights) |= PRSFS_LOOKUP;
729 #endif /* ADMIN_IMPLICIT_LOOKUP */
732 } /*GetVolumePackage */
736 * This is the opposite of GetVolumePackage(), and is always used at the end of
737 * AFS calls to put back all used vnodes and the volume in the proper order!
740 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
741 Vnode * parentptr, Volume * volptr, struct client **client)
743 int fileCode = 0; /* Error code returned by the volume package */
745 if (parentwhentargetnotdir) {
746 VPutVnode(&fileCode, parentwhentargetnotdir);
747 assert(!fileCode || (fileCode == VSALVAGE));
750 VPutVnode(&fileCode, targetptr);
751 assert(!fileCode || (fileCode == VSALVAGE));
754 VPutVnode(&fileCode, parentptr);
755 assert(!fileCode || (fileCode == VSALVAGE));
763 } /*PutVolumePackage */
766 VolumeOwner(register struct client *client, register Vnode * targetptr)
768 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
771 return (client->ViceId == owner);
774 * We don't have to check for host's cps since only regular
775 * viceid are volume owners.
777 return (client_HasAsMember(client, owner));
783 VolumeRootVnode(Vnode * targetptr)
785 return ((targetptr->vnodeNumber == ROOTVNODE)
786 && (targetptr->disk.uniquifier == 1));
788 } /*VolumeRootVnode */
791 * Check if target file has the proper access permissions for the Fetch
792 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
793 * StoreStatus) related calls
795 /* this code should probably just set a "priv" flag where all the audit events
796 * are now, and only generate the audit event once at the end of the routine,
797 * thus only generating the event if all the checks succeed, but only because
798 * of the privilege XXX
801 Check_PermissionRights(Vnode * targetptr, struct client *client,
802 afs_int32 rights, int CallingRoutine,
803 AFSStoreStatus * InStatus)
806 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
807 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
808 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
810 if (CallingRoutine & CHK_FETCH) {
811 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
812 if (targetptr->disk.type == vDirectory
813 || targetptr->disk.type == vSymlink) {
814 if (!(rights & PRSFS_LOOKUP)
815 #ifdef ADMIN_IMPLICIT_LOOKUP
816 /* grant admins fetch on all directories */
817 && VanillaUser(client)
818 #endif /* ADMIN_IMPLICIT_LOOKUP */
819 && !VolumeOwner(client, targetptr))
822 /* must have read access, or be owner and have insert access */
823 if (!(rights & PRSFS_READ)
824 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
827 if (CallingRoutine == CHK_FETCHDATA
828 && targetptr->disk.type == vFile)
829 #ifdef USE_GROUP_PERMS
830 if (!OWNSp(client, targetptr)
831 && !client_HasAsMember(client, targetptr->disk.owner)) {
833 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
837 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
842 * The check with the ownership below is a kludge to allow
843 * reading of files created with no read permission. The owner
844 * of the file is always allowed to read it.
846 if ((client->ViceId != targetptr->disk.owner)
847 && VanillaUser(client))
849 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
850 modeBits) ? 0 : EACCES);
852 } else { /* !VanillaUser(client) && !FetchData */
854 osi_audit(PrivilegeEvent, 0, AUD_ID,
855 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
858 } else { /* a store operation */
859 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
860 && (CallingRoutine != CHK_STOREACL)
861 && (targetptr->disk.type == vFile)) {
862 /* bypass protection checks on first store after a create
863 * for the creator; also prevent chowns during this time
864 * unless you are a system administrator */
865 /****** InStatus->Owner && UnixModeBits better be SET!! */
866 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
869 else if (VanillaUser(client))
870 return (EPERM); /* Was EACCES */
872 osi_audit(PrivilegeEvent, 0, AUD_ID,
873 (client ? client->ViceId : 0), AUD_INT,
874 CallingRoutine, AUD_END);
877 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
878 osi_audit(PrivilegeEvent, 0, AUD_ID,
879 (client ? client->ViceId : 0), AUD_INT,
880 CallingRoutine, AUD_END);
882 if (readonlyServer) {
885 if (CallingRoutine == CHK_STOREACL) {
886 if (!(rights & PRSFS_ADMINISTER)
887 && !VolumeOwner(client, targetptr))
889 } else { /* store data or status */
890 /* watch for chowns and chgrps */
891 if (CHOWN(InStatus, targetptr)
892 || CHGRP(InStatus, targetptr)) {
895 else if (VanillaUser(client))
896 return (EPERM); /* Was EACCES */
898 osi_audit(PrivilegeEvent, 0, AUD_ID,
899 (client ? client->ViceId : 0), AUD_INT,
900 CallingRoutine, AUD_END);
902 /* must be sysadmin to set suid/sgid bits */
903 if ((InStatus->Mask & AFS_SETMODE) &&
905 (InStatus->UnixModeBits & 0xc00) != 0) {
907 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
911 if (VanillaUser(client))
914 osi_audit(PrivSetID, 0, AUD_ID,
915 (client ? client->ViceId : 0), AUD_INT,
916 CallingRoutine, AUD_END);
918 if (CallingRoutine == CHK_STOREDATA) {
921 if (!(rights & PRSFS_WRITE))
923 /* Next thing is tricky. We want to prevent people
924 * from writing files sans 0200 bit, but we want
925 * creating new files with 0444 mode to work. We
926 * don't check the 0200 bit in the "you are the owner"
927 * path above, but here we check the bit. However, if
928 * you're a system administrator, we ignore the 0200
929 * bit anyway, since you may have fchowned the file,
931 #ifdef USE_GROUP_PERMS
932 if ((targetptr->disk.type == vFile)
933 && VanillaUser(client)) {
934 if (!OWNSp(client, targetptr)
935 && !client_HasAsMember(client, targetptr->disk.owner)) {
937 ((GROUPWRITE & targetptr->disk.modeBits)
941 ((OWNERWRITE & targetptr->disk.modeBits)
946 if ((targetptr->disk.type != vDirectory)
947 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
950 if (VanillaUser(client))
953 osi_audit(PrivilegeEvent, 0, AUD_ID,
954 (client ? client->ViceId : 0),
955 AUD_INT, CallingRoutine, AUD_END);
957 } else { /* a status store */
960 if (targetptr->disk.type == vDirectory) {
961 if (!(rights & PRSFS_DELETE)
962 && !(rights & PRSFS_INSERT))
964 } else { /* a file or symlink */
965 if (!(rights & PRSFS_WRITE))
975 } /*Check_PermissionRights */
979 * The Access List information is converted from its internal form in the
980 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
981 * external form and returned back to the caller, via the AccessList
985 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
986 struct AFSOpaque *AccessList)
988 char *eACL; /* External access list placeholder */
991 ((targetptr->disk.type ==
992 vDirectory ? VVnodeACL(targetptr) :
993 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
996 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
997 acl_FreeExternalACL(&eACL);
1000 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1001 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1003 acl_FreeExternalACL(&eACL);
1006 } /*RXFetch_AccessList */
1010 * The Access List information is converted from its external form in the
1011 * input AccessList structure to the internal representation and copied into
1012 * the target dir's vnode storage.
1015 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1017 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1019 if (acl_Internalize(AccessList->AFSOpaque_val, &newACL) != 0)
1021 if ((newACL->size + 4) > VAclSize(targetptr))
1023 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1024 acl_FreeACL(&newACL);
1027 } /*RXStore_AccessList */
1030 /* In our current implementation, each successive data store (new file
1031 * data version) creates a new inode. This function creates the new
1032 * inode, copies the old inode's contents to the new one, remove the old
1033 * inode (i.e. decrement inode count -- if it's currently used the delete
1034 * will be delayed), and modify some fields (i.e. vnode's
1035 * disk.inodeNumber and cloned)
1037 #define COPYBUFFSIZE 8192
1039 CopyOnWrite(Vnode * targetptr, Volume * volptr)
1041 Inode ino, nearInode;
1044 register afs_fsize_t size;
1045 register int length;
1047 int rc; /* return code */
1048 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1049 FdHandle_t *targFdP; /* Source Inode file handle */
1050 FdHandle_t *newFdP; /* Dest Inode file handle */
1052 if (targetptr->disk.type == vDirectory)
1053 DFlush(); /* just in case? */
1055 VN_GET_LEN(size, targetptr);
1056 buff = (char *)malloc(COPYBUFFSIZE);
1061 ino = VN_GET_INO(targetptr);
1062 assert(VALID_INO(ino));
1063 targFdP = IH_OPEN(targetptr->handle);
1064 if (targFdP == NULL) {
1067 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1068 targetptr->vnodeNumber, V_id(volptr), rc));
1070 VTakeOffline(volptr);
1074 nearInode = VN_GET_INO(targetptr);
1076 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1077 VPartitionPath(V_partition(volptr)), nearInode,
1078 V_id(volptr), targetptr->vnodeNumber,
1079 targetptr->disk.uniquifier,
1080 (int)targetptr->disk.dataVersion);
1081 if (!VALID_INO(ino)) {
1083 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1084 volptr->partition->name, V_id(volptr), errno));
1089 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1090 newFdP = IH_OPEN(newH);
1091 assert(newFdP != NULL);
1094 if (size > COPYBUFFSIZE) { /* more than a buffer */
1095 length = COPYBUFFSIZE;
1096 size -= COPYBUFFSIZE;
1101 rdlen = FDH_READ(targFdP, buff, length);
1102 if (rdlen == length)
1103 wrlen = FDH_WRITE(newFdP, buff, length);
1106 /* Callers of this function are not prepared to recover
1107 * from error that put the filesystem in an inconsistent
1108 * state. Make sure that we force the volume off-line if
1109 * we some error other than ENOSPC - 4.29.99)
1111 * In case we are unable to write the required bytes, and the
1112 * error code indicates that the disk is full, we roll-back to
1113 * the initial state.
1115 if ((rdlen != length) || (wrlen != length))
1116 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1118 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1119 volptr->partition->name, V_id(volptr)));
1120 /* remove destination inode which was partially copied till now */
1121 FDH_REALLYCLOSE(newFdP);
1123 FDH_REALLYCLOSE(targFdP);
1124 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1127 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1128 rc, V_id(volptr), volptr->partition->name));
1129 VTakeOffline(volptr);
1135 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1136 V_id(volptr), volptr->partition->name, length, rdlen,
1138 #ifdef FAST_RESTART /* if running in no-salvage, don't core the server */
1139 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1140 #else /* Avoid further corruption and try to get a core. */
1143 /* Decrement this inode so salvager doesn't find it. */
1144 FDH_REALLYCLOSE(newFdP);
1146 FDH_REALLYCLOSE(targFdP);
1147 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1149 VTakeOffline(volptr);
1152 #ifndef AFS_PTHREAD_ENV
1154 #endif /* !AFS_PTHREAD_ENV */
1156 FDH_REALLYCLOSE(targFdP);
1157 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1158 V_parentId(volptr));
1160 IH_RELEASE(targetptr->handle);
1162 rc = FDH_SYNC(newFdP);
1165 targetptr->handle = newH;
1166 VN_SET_INO(targetptr, ino);
1167 targetptr->disk.cloned = 0;
1168 /* Internal change to vnode, no user level change to volume - def 5445 */
1169 targetptr->changed_oldTime = 1;
1171 return 0; /* success */
1176 * Common code to handle with removing the Name (file when it's called from
1177 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1178 * given directory, parentptr.
1180 int DT1 = 0, DT0 = 0;
1182 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1183 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1185 DirHandle childdir; /* Handle for dir package I/O */
1189 /* watch for invalid names */
1190 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1192 if (parentptr->disk.cloned) {
1193 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1194 if ((errorCode = CopyOnWrite(parentptr, volptr))) {
1196 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1202 /* check that the file is in the directory */
1203 SetDirHandle(dir, parentptr);
1204 if (Lookup(dir, Name, fileFid))
1206 fileFid->Volume = V_id(volptr);
1208 /* just-in-case check for something causing deadlock */
1209 if (fileFid->Vnode == parentptr->vnodeNumber)
1212 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1216 if (ChkForDir == MustBeDIR) {
1217 if ((*targetptr)->disk.type != vDirectory)
1219 } else if ((*targetptr)->disk.type == vDirectory)
1222 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1224 * If the uniquifiers dont match then instead of asserting
1225 * take the volume offline and return VSALVAGE
1227 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1228 VTakeOffline(volptr);
1229 errorCode = VSALVAGE;
1233 if (ChkForDir == MustBeDIR) {
1234 SetDirHandle(&childdir, *targetptr);
1235 if (IsEmpty(&childdir) != 0)
1238 (*targetptr)->delete = 1;
1239 } else if ((--(*targetptr)->disk.linkCount) == 0)
1240 (*targetptr)->delete = 1;
1241 if ((*targetptr)->delete) {
1242 if (VN_GET_INO(*targetptr)) {
1244 IH_REALLYCLOSE((*targetptr)->handle);
1246 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1247 V_parentId(volptr));
1248 IH_RELEASE((*targetptr)->handle);
1249 if (errorCode == -1) {
1251 ("DT: inode=%s, name=%s, errno=%d\n",
1252 PrintInode(NULL, VN_GET_INO(*targetptr)), Name,
1254 if (errno != ENOENT)
1257 ("Volume %u now offline, must be salvaged.\n",
1259 VTakeOffline(volptr);
1266 VN_SET_INO(*targetptr, (Inode) 0);
1268 afs_fsize_t adjLength;
1269 VN_GET_LEN(adjLength, *targetptr);
1270 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1274 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1276 code = Delete(dir, (char *)Name);
1279 ("Error %d deleting %s\n", code,
1280 (((*targetptr)->disk.type ==
1281 Directory) ? "directory" : "file")));
1283 ("Volume %u now offline, must be salvaged.\n",
1285 VTakeOffline(volptr);
1297 * This routine updates the parent directory's status block after the
1298 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1299 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1303 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1304 int author, int linkcount,
1305 #if FS_STATS_DETAILED
1306 char a_inSameNetwork
1307 #endif /* FS_STATS_DETAILED */
1310 afs_fsize_t newlength; /* Holds new directory length */
1311 afs_fsize_t parentLength;
1313 #if FS_STATS_DETAILED
1314 Date currDate; /*Current date */
1315 int writeIdx; /*Write index to bump */
1316 int timeIdx; /*Authorship time index to bump */
1317 #endif /* FS_STATS_DETAILED */
1319 parentptr->disk.dataVersion++;
1320 newlength = (afs_fsize_t) Length(dir);
1322 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1323 * (create, symlink, link, makedir) so we need to check if we have enough space
1324 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1325 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1327 VN_GET_LEN(parentLength, parentptr);
1328 if (nBlocks(newlength) != nBlocks(parentLength)) {
1329 VAdjustDiskUsage(&errorCode, volptr,
1330 (nBlocks(newlength) - nBlocks(parentLength)),
1331 (nBlocks(newlength) - nBlocks(parentLength)));
1333 VN_SET_LEN(parentptr, newlength);
1335 #if FS_STATS_DETAILED
1337 * Update directory write stats for this volume. Note that the auth
1338 * counter is located immediately after its associated ``distance''
1341 if (a_inSameNetwork)
1342 writeIdx = VOL_STATS_SAME_NET;
1344 writeIdx = VOL_STATS_DIFF_NET;
1345 V_stat_writes(volptr, writeIdx)++;
1346 if (author != AnonymousID) {
1347 V_stat_writes(volptr, writeIdx + 1)++;
1351 * Update the volume's authorship information in response to this
1352 * directory operation. Get the current time, decide to which time
1353 * slot this operation belongs, and bump the appropriate slot.
1355 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1357 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1358 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1359 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1360 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1361 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1362 if (parentptr->disk.author == author) {
1363 V_stat_dirSameAuthor(volptr, timeIdx)++;
1365 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1367 #endif /* FS_STATS_DETAILED */
1369 parentptr->disk.author = author;
1370 parentptr->disk.linkCount = linkcount;
1371 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1372 parentptr->disk.serverModifyTime = FT_ApproxTime();
1373 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1378 * Update the target file's (or dir's) status block after the specified
1379 * operation is complete. Note that some other fields maybe updated by
1380 * the individual module.
1383 /* XXX INCOMPLETE - More attention is needed here! */
1385 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1386 struct client *client, AFSStoreStatus * InStatus,
1387 Vnode * parentptr, Volume * volptr,
1390 #if FS_STATS_DETAILED
1391 Date currDate; /*Current date */
1392 int writeIdx; /*Write index to bump */
1393 int timeIdx; /*Authorship time index to bump */
1394 #endif /* FS_STATS_DETAILED */
1396 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1397 targetptr->disk.parent = parentptr->vnodeNumber;
1398 VN_SET_LEN(targetptr, length);
1399 /* targetptr->disk.group = 0; save some cycles */
1400 targetptr->disk.modeBits = 0777;
1401 targetptr->disk.owner = client->ViceId;
1402 targetptr->disk.dataVersion = 0; /* consistent with the client */
1403 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1404 /* the inode was created in Alloc_NewVnode() */
1406 #if FS_STATS_DETAILED
1408 * Update file write stats for this volume. Note that the auth
1409 * counter is located immediately after its associated ``distance''
1412 if (client->InSameNetwork)
1413 writeIdx = VOL_STATS_SAME_NET;
1415 writeIdx = VOL_STATS_DIFF_NET;
1416 V_stat_writes(volptr, writeIdx)++;
1417 if (client->ViceId != AnonymousID) {
1418 V_stat_writes(volptr, writeIdx + 1)++;
1422 * We only count operations that DON'T involve creating new objects
1423 * (files, symlinks, directories) or simply setting status as
1424 * authorship-change operations.
1426 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1428 * Update the volume's authorship information in response to this
1429 * file operation. Get the current time, decide to which time
1430 * slot this operation belongs, and bump the appropriate slot.
1432 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1435 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1436 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1437 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1438 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1439 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1440 VOL_STATS_TIME_IDX_5);
1441 if (targetptr->disk.author == client->ViceId) {
1442 V_stat_fileSameAuthor(volptr, timeIdx)++;
1444 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1447 #endif /* FS_STATS_DETAILED */
1449 if (!(Caller & TVS_SSTATUS))
1450 targetptr->disk.author = client->ViceId;
1451 if (Caller & TVS_SDATA) {
1452 targetptr->disk.dataVersion++;
1453 if (VanillaUser(client)) {
1454 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1455 #ifdef CREATE_SGUID_ADMIN_ONLY
1456 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1460 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1461 /* store status, must explicitly request to change the date */
1462 if (InStatus->Mask & AFS_SETMODTIME)
1463 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1464 } else { /* other: date always changes, but perhaps to what is specified by caller */
1465 targetptr->disk.unixModifyTime =
1466 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1467 ClientModTime : FT_ApproxTime());
1469 if (InStatus->Mask & AFS_SETOWNER) {
1470 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1471 if (VanillaUser(client)) {
1472 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1473 #ifdef CREATE_SGUID_ADMIN_ONLY
1474 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1477 targetptr->disk.owner = InStatus->Owner;
1478 if (VolumeRootVnode(targetptr)) {
1479 Error errorCode = 0; /* what should be done with this? */
1481 V_owner(targetptr->volumePtr) = InStatus->Owner;
1482 VUpdateVolume(&errorCode, targetptr->volumePtr);
1485 if (InStatus->Mask & AFS_SETMODE) {
1486 int modebits = InStatus->UnixModeBits;
1487 #define CREATE_SGUID_ADMIN_ONLY 1
1488 #ifdef CREATE_SGUID_ADMIN_ONLY
1489 if (VanillaUser(client))
1490 modebits = modebits & 0777;
1492 if (VanillaUser(client)) {
1493 targetptr->disk.modeBits = modebits;
1495 targetptr->disk.modeBits = modebits;
1498 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1499 CHK_STOREDATA, AUD_END);
1503 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1504 CHK_STORESTATUS, AUD_END);
1511 targetptr->disk.serverModifyTime = FT_ApproxTime();
1512 if (InStatus->Mask & AFS_SETGROUP)
1513 targetptr->disk.group = InStatus->Group;
1514 /* vnode changed : to be written back by VPutVnode */
1515 targetptr->changed_newTime = 1;
1517 } /*Update_TargetVnodeStatus */
1521 * Fills the CallBack structure with the expiration time and type of callback
1522 * structure. Warning: this function is currently incomplete.
1525 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1527 /* CallBackTime could not be 0 */
1528 if (CallBackTime == 0) {
1529 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1530 CallBack->ExpirationTime = 0;
1532 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1533 CallBack->CallBackVersion = CALLBACK_VERSION;
1534 CallBack->CallBackType = CB_SHARED; /* The default for now */
1536 } /*SetCallBackStruct */
1540 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1541 * allocation; if some error occured (exceeded volume quota or partition
1542 * was full, or whatever), it frees the space back and returns the code.
1543 * We usually pre-adjust the volume space to make sure that there's
1544 * enough space before consuming some.
1547 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1548 afs_sfsize_t checkLength)
1553 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1555 VAdjustDiskUsage(&nc, volptr, -length, 0);
1556 if (rc == VOVERQUOTA) {
1558 ("Volume %u (%s) is full\n", V_id(volptr),
1562 if (rc == VDISKFULL) {
1564 ("Partition %s that contains volume %u is full\n",
1565 volptr->partition->name, V_id(volptr)));
1568 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1573 } /*AdjustDiskUsage */
1576 * Common code that handles the creation of a new file (SAFS_CreateFile and
1577 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1580 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1581 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1582 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1584 int errorCode = 0; /* Error code returned back */
1587 Inode nearInode; /* hint for inode allocation in solaris */
1590 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1591 BlocksPreallocatedForVnode))) {
1593 ("Insufficient space to allocate %lld blocks\n",
1594 (afs_intmax_t) BlocksPreallocatedForVnode));
1598 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1599 if (errorCode != 0) {
1600 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1603 OutFid->Volume = V_id(volptr);
1604 OutFid->Vnode = (*targetptr)->vnodeNumber;
1605 OutFid->Unique = (*targetptr)->disk.uniquifier;
1607 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1609 /* create the inode now itself */
1611 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1612 VPartitionPath(V_partition(volptr)), nearInode,
1613 V_id(volptr), (*targetptr)->vnodeNumber,
1614 (*targetptr)->disk.uniquifier, 1);
1616 /* error in creating inode */
1617 if (!VALID_INO(inode)) {
1619 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1620 (*targetptr)->volumePtr->header->diskstuff.id,
1621 (*targetptr)->vnodeNumber, errno));
1622 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1623 (*targetptr)->delete = 1; /* delete vnode */
1626 VN_SET_INO(*targetptr, inode);
1627 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1629 /* copy group from parent dir */
1630 (*targetptr)->disk.group = parentptr->disk.group;
1632 if (parentptr->disk.cloned) {
1633 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1634 if ((errorCode = CopyOnWrite(parentptr, volptr))) { /* disk full */
1635 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1636 /* delete the vnode previously allocated */
1637 (*targetptr)->delete = 1;
1638 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1639 IH_REALLYCLOSE((*targetptr)->handle);
1640 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1642 ("Alloc_NewVnode: partition %s idec %s failed\n",
1643 volptr->partition->name, PrintInode(NULL, inode)));
1644 IH_RELEASE((*targetptr)->handle);
1650 /* add the name to the directory */
1651 SetDirHandle(dir, parentptr);
1652 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1653 (*targetptr)->delete = 1;
1654 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1655 IH_REALLYCLOSE((*targetptr)->handle);
1656 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1658 ("Alloc_NewVnode: partition %s idec %s failed\n",
1659 volptr->partition->name, PrintInode(NULL, inode)));
1660 IH_RELEASE((*targetptr)->handle);
1666 } /*Alloc_NewVnode */
1670 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1674 HandleLocking(Vnode * targetptr, afs_int32 rights, ViceLockType LockingType)
1676 int Time; /* Used for time */
1677 int writeVnode = targetptr->changed_oldTime; /* save original status */
1679 /* Does the caller has Lock priviledges; root extends locks, however */
1680 if (LockingType != LockExtend && !(rights & PRSFS_LOCK))
1682 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1683 Time = FT_ApproxTime();
1684 switch (LockingType) {
1687 if (Time > targetptr->disk.lock.lockTime)
1688 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1690 Time += AFS_LOCKWAIT;
1691 if (LockingType == LockRead) {
1692 if (targetptr->disk.lock.lockCount >= 0) {
1693 ++(targetptr->disk.lock.lockCount);
1694 targetptr->disk.lock.lockTime = Time;
1698 if (targetptr->disk.lock.lockCount == 0) {
1699 targetptr->disk.lock.lockCount = -1;
1700 targetptr->disk.lock.lockTime = Time;
1706 Time += AFS_LOCKWAIT;
1707 if (targetptr->disk.lock.lockCount != 0)
1708 targetptr->disk.lock.lockTime = Time;
1713 if ((--targetptr->disk.lock.lockCount) <= 0)
1714 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1718 targetptr->changed_oldTime = writeVnode; /* restore old status */
1719 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1722 } /*HandleLocking */
1724 /* 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. */
1727 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1731 if (!(rights & Prfs_Mode))
1733 if ((targetptr->disk.type != vDirectory)
1734 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1740 * If some flags (i.e. min or max quota) are set, the volume's in disk
1741 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1742 * update, if applicable.
1745 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1746 char *Name, char *OfflineMsg, char *Motd)
1748 Error errorCode = 0;
1750 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1751 V_minquota(volptr) = StoreVolStatus->MinQuota;
1752 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1753 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1754 if (strlen(OfflineMsg) > 0) {
1755 strcpy(V_offlineMessage(volptr), OfflineMsg);
1757 if (strlen(Name) > 0) {
1758 strcpy(V_name(volptr), Name);
1760 #if OPENAFS_VOL_STATS
1762 * We don't overwrite the motd field, since it's now being used
1766 if (strlen(Motd) > 0) {
1767 strcpy(V_motd(volptr), Motd);
1769 #endif /* FS_STATS_DETAILED */
1770 VUpdateVolume(&errorCode, volptr);
1773 } /*RXUpdate_VolumeStatus */
1777 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1778 char **motd, Volume * volptr)
1782 status->Vid = V_id(volptr);
1783 status->ParentId = V_parentId(volptr);
1784 status->Online = V_inUse(volptr);
1785 status->InService = V_inService(volptr);
1786 status->Blessed = V_blessed(volptr);
1787 status->NeedsSalvage = V_needsSalvaged(volptr);
1788 if (VolumeWriteable(volptr))
1789 status->Type = ReadWrite;
1791 status->Type = ReadOnly;
1792 status->MinQuota = V_minquota(volptr);
1793 status->MaxQuota = V_maxquota(volptr);
1794 status->BlocksInUse = V_diskused(volptr);
1795 status->PartBlocksAvail = volptr->partition->free;
1796 status->PartMaxBlocks = volptr->partition->totalUsable;
1798 /* now allocate and copy these things; they're freed by the RXGEN stub */
1799 temp = strlen(V_name(volptr)) + 1;
1800 *name = malloc(temp);
1802 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1805 strcpy(*name, V_name(volptr));
1806 temp = strlen(V_offlineMessage(volptr)) + 1;
1807 *offMsg = malloc(temp);
1809 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1812 strcpy(*offMsg, V_offlineMessage(volptr));
1813 #if OPENAFS_VOL_STATS
1816 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1819 strcpy(*motd, nullString);
1821 temp = strlen(V_motd(volptr)) + 1;
1822 *motd = malloc(temp);
1824 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1827 strcpy(*motd, V_motd(volptr));
1828 #endif /* FS_STATS_DETAILED */
1830 } /*RXGetVolumeStatus */
1834 FileNameOK(register char *aname)
1836 register afs_int32 i, tc;
1839 /* watch for @sys on the right */
1840 if (strcmp(aname + i - 4, "@sys") == 0)
1843 while ((tc = *aname++)) {
1845 return 0; /* very bad character to encounter */
1847 return 1; /* file name is ok */
1853 * This variant of symlink is expressly to support the AFS/DFS translator
1854 * and is not supported by the AFS fileserver. We just return EINVAL.
1855 * The cache manager should not generate this call to an AFS cache manager.
1858 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
1859 char *LinkContents, struct AFSStoreStatus *InStatus,
1860 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
1861 struct AFSFetchStatus *OutDirStatus,
1862 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
1868 SRXAFS_ResidencyCmd(struct rx_call * acall, struct AFSFid * Fid,
1869 struct ResidencyCmdInputs * Inputs,
1870 struct ResidencyCmdOutputs * Outputs)
1876 static struct afs_buffer {
1877 struct afs_buffer *next;
1878 } *freeBufferList = 0;
1879 static int afs_buffersAlloced = 0;
1882 FreeSendBuffer(register struct afs_buffer *adata)
1885 afs_buffersAlloced--;
1886 adata->next = freeBufferList;
1887 freeBufferList = adata;
1891 } /*FreeSendBuffer */
1893 /* allocate space for sender */
1897 register struct afs_buffer *tp;
1900 afs_buffersAlloced++;
1901 if (!freeBufferList) {
1904 tmp = malloc(sendBufSize);
1906 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
1911 tp = freeBufferList;
1912 freeBufferList = tp->next;
1916 } /*AllocSendBuffer */
1917 #endif /* AFS_NT40_ENV */
1920 * This routine returns the status info associated with the targetptr vnode
1921 * in the AFSFetchStatus structure. Some of the newer fields, such as
1922 * SegSize and Group are not yet implemented
1926 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
1927 afs_int32 anyrights, Vnode * parentptr)
1929 /* initialize return status from a vnode */
1930 status->InterfaceVersion = 1;
1931 status->SyncCounter = status->dataVersionHigh = status->lockCount =
1932 status->errorCode = 0;
1933 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
1934 if (targetptr->disk.type == vFile)
1935 status->FileType = File;
1936 else if (targetptr->disk.type == vDirectory)
1937 status->FileType = Directory;
1938 else if (targetptr->disk.type == vSymlink)
1939 status->FileType = SymbolicLink;
1941 status->FileType = Invalid; /*invalid type field */
1942 status->LinkCount = targetptr->disk.linkCount;
1944 afs_fsize_t targetLen;
1945 VN_GET_LEN(targetLen, targetptr);
1946 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
1948 status->DataVersion = targetptr->disk.dataVersion;
1949 status->Author = targetptr->disk.author;
1950 status->Owner = targetptr->disk.owner;
1951 status->CallerAccess = rights;
1952 status->AnonymousAccess = anyrights;
1953 status->UnixModeBits = targetptr->disk.modeBits;
1954 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
1955 status->ParentVnode =
1956 (status->FileType ==
1957 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
1958 status->ParentUnique =
1959 (status->FileType ==
1960 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
1961 status->ServerModTime = targetptr->disk.serverModifyTime;
1962 status->Group = targetptr->disk.group;
1963 status->lockCount = targetptr->disk.lock.lockCount;
1964 status->errorCode = 0;
1970 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
1971 afs_sfsize_t Pos, afs_sfsize_t Len,
1972 struct AFSFetchStatus *OutStatus,
1973 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
1976 Vnode *targetptr = 0; /* pointer to vnode to fetch */
1977 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
1978 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
1979 int errorCode = 0; /* return code to caller */
1980 int fileCode = 0; /* return code from vol package */
1981 Volume *volptr = 0; /* pointer to the volume */
1982 struct client *client = 0; /* pointer to the client data */
1983 struct rx_connection *tcon; /* the connection we're part of */
1984 afs_int32 rights, anyrights; /* rights for this and any user */
1985 struct client *t_client = NULL; /* tmp ptr to client data */
1986 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
1987 #if FS_STATS_DETAILED
1988 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
1989 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
1990 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
1991 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
1992 struct timeval elapsedTime; /* Transfer time */
1993 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
1994 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
1995 int readIdx; /* Index of read stats array to bump */
1996 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
1999 * Set our stats pointers, remember when the RPC operation started, and
2000 * tally the operation.
2002 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2003 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2007 TM_GetTimeOfDay(&opStartTime, 0);
2008 #endif /* FS_STATS_DETAILED */
2011 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2014 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2016 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2019 /* Get ptr to client data for user Id for logging */
2020 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2021 logHostAddr.s_addr = rxr_HostOf(tcon);
2023 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2024 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2025 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2027 * Get volume/vnode for the fetched file; caller's access rights to
2028 * it are also returned
2031 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2032 &parentwhentargetnotdir, &client, READ_LOCK,
2033 &rights, &anyrights)))
2036 SetVolumeSync(Sync, volptr);
2038 #if FS_STATS_DETAILED
2040 * Remember that another read operation was performed.
2043 if (client->InSameNetwork)
2044 readIdx = VOL_STATS_SAME_NET;
2046 readIdx = VOL_STATS_DIFF_NET;
2047 V_stat_reads(volptr, readIdx)++;
2048 if (client->ViceId != AnonymousID) {
2049 V_stat_reads(volptr, readIdx + 1)++;
2052 #endif /* FS_STATS_DETAILED */
2053 /* Check whether the caller has permission access to fetch the data */
2055 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2059 * Drop the read lock on the parent directory after saving the parent
2060 * vnode information we need to pass to GetStatus
2062 if (parentwhentargetnotdir != NULL) {
2063 tparentwhentargetnotdir = *parentwhentargetnotdir;
2064 VPutVnode(&fileCode, parentwhentargetnotdir);
2065 assert(!fileCode || (fileCode == VSALVAGE));
2066 parentwhentargetnotdir = NULL;
2068 #if FS_STATS_DETAILED
2070 * Remember when the data transfer started.
2072 TM_GetTimeOfDay(&xferStartTime, 0);
2073 #endif /* FS_STATS_DETAILED */
2075 /* actually do the data transfer */
2076 #if FS_STATS_DETAILED
2078 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2079 &bytesToXfer, &bytesXferred);
2082 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2084 #endif /* FS_STATS_DETAILED */
2086 #if FS_STATS_DETAILED
2088 * At this point, the data transfer is done, for good or ill. Remember
2089 * when the transfer ended, bump the number of successes/failures, and
2090 * integrate the transfer size and elapsed time into the stats. If the
2091 * operation failed, we jump to the appropriate point.
2093 TM_GetTimeOfDay(&xferStopTime, 0);
2095 (xferP->numXfers)++;
2097 (xferP->numSuccesses)++;
2100 * Bump the xfer sum by the number of bytes actually sent, NOT the
2103 tot_bytesXferred += bytesXferred;
2104 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2105 tot_bytesXferred &= 0x3FF;
2106 if (bytesXferred < xferP->minBytes)
2107 xferP->minBytes = bytesXferred;
2108 if (bytesXferred > xferP->maxBytes)
2109 xferP->maxBytes = bytesXferred;
2112 * Tally the size of the object. Note: we tally the actual size,
2113 * NOT the number of bytes that made it out over the wire.
2115 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2116 (xferP->count[0])++;
2117 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2118 (xferP->count[1])++;
2119 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2120 (xferP->count[2])++;
2121 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2122 (xferP->count[3])++;
2123 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2124 (xferP->count[4])++;
2125 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2126 (xferP->count[5])++;
2127 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2128 (xferP->count[6])++;
2129 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2130 (xferP->count[7])++;
2132 (xferP->count[8])++;
2134 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2135 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2136 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2137 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2138 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2140 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2141 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2146 * Finally, go off to tell our caller the bad news in case the
2151 #endif /* FS_STATS_DETAILED */
2153 /* write back the OutStatus from the target vnode */
2154 GetStatus(targetptr, OutStatus, rights, anyrights,
2155 &tparentwhentargetnotdir);
2157 /* if a r/w volume, promise a callback to the caller */
2158 if (VolumeWriteable(volptr))
2159 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2161 struct AFSFid myFid;
2162 memset(&myFid, 0, sizeof(struct AFSFid));
2163 myFid.Volume = Fid->Volume;
2164 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2168 /* Update and store volume/vnode and parent vnodes back */
2169 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2171 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2172 errorCode = CallPostamble(tcon, errorCode);
2174 #if FS_STATS_DETAILED
2175 TM_GetTimeOfDay(&opStopTime, 0);
2176 if (errorCode == 0) {
2178 (opP->numSuccesses)++;
2179 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2180 fs_stats_AddTo((opP->sumTime), elapsedTime);
2181 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2182 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2183 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2185 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2186 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2190 #endif /* FS_STATS_DETAILED */
2192 osi_auditU(acall, FetchDataEvent, errorCode,
2193 AUD_ID, t_client ? t_client->ViceId : 0,
2194 AUD_FID, Fid, AUD_END);
2197 } /*SRXAFS_FetchData */
2200 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2201 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2202 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2204 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2209 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2210 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2211 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2214 afs_sfsize_t tPos, tLen;
2216 #ifdef AFS_64BIT_ENV
2217 #ifndef AFS_LARGEFILE_ENV
2218 if (Pos + Len > 0x7fffffff)
2220 #endif /* !AFS_LARGEFILE_ENV */
2221 tPos = (afs_sfsize_t) Pos;
2222 tLen = (afs_sfsize_t) Len;
2223 #else /* AFS_64BIT_ENV */
2224 if (Pos.high || Len.high)
2228 #endif /* AFS_64BIT_ENV */
2231 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2237 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2238 struct AFSOpaque * AccessList,
2239 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2241 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2242 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2243 int errorCode = 0; /* return error code to caller */
2244 Volume *volptr = 0; /* pointer to the volume */
2245 struct client *client = 0; /* pointer to the client data */
2246 afs_int32 rights, anyrights; /* rights for this and any user */
2247 struct rx_connection *tcon = rx_ConnectionOf(acall);
2248 struct client *t_client = NULL; /* tmp ptr to client data */
2249 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2250 #if FS_STATS_DETAILED
2251 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2252 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2253 struct timeval elapsedTime; /* Transfer time */
2256 * Set our stats pointer, remember when the RPC operation started, and
2257 * tally the operation.
2259 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2263 TM_GetTimeOfDay(&opStartTime, 0);
2264 #endif /* FS_STATS_DETAILED */
2267 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2270 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2272 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2275 /* Get ptr to client data for user Id for logging */
2276 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2277 logHostAddr.s_addr = rxr_HostOf(tcon);
2279 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2280 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2281 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2283 AccessList->AFSOpaque_len = 0;
2284 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2285 if (!AccessList->AFSOpaque_val) {
2286 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2291 * Get volume/vnode for the fetched file; caller's access rights to it
2295 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2296 &parentwhentargetnotdir, &client, READ_LOCK,
2297 &rights, &anyrights)))
2300 SetVolumeSync(Sync, volptr);
2302 /* Check whether we have permission to fetch the ACL */
2304 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2307 /* Get the Access List from the dir's vnode */
2309 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2312 /* Get OutStatus back From the target Vnode */
2313 GetStatus(targetptr, OutStatus, rights, anyrights,
2314 parentwhentargetnotdir);
2317 /* Update and store volume/vnode and parent vnodes back */
2318 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2321 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2322 AccessList->AFSOpaque_val));
2323 errorCode = CallPostamble(tcon, errorCode);
2325 #if FS_STATS_DETAILED
2326 TM_GetTimeOfDay(&opStopTime, 0);
2327 if (errorCode == 0) {
2329 (opP->numSuccesses)++;
2330 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2331 fs_stats_AddTo((opP->sumTime), elapsedTime);
2332 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2333 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2334 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2336 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2337 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2341 #endif /* FS_STATS_DETAILED */
2343 osi_auditU(acall, FetchACLEvent, errorCode,
2344 AUD_ID, t_client ? t_client->ViceId : 0,
2346 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2348 } /*SRXAFS_FetchACL */
2352 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2353 * merged into it when possible.
2357 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2358 struct AFSFetchStatus *OutStatus,
2359 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2361 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2362 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2363 int errorCode = 0; /* return code to caller */
2364 Volume *volptr = 0; /* pointer to the volume */
2365 struct client *client = 0; /* pointer to the client data */
2366 afs_int32 rights, anyrights; /* rights for this and any user */
2367 struct client *t_client = NULL; /* tmp ptr to client data */
2368 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2369 struct rx_connection *tcon = rx_ConnectionOf(acall);
2371 /* Get ptr to client data for user Id for logging */
2372 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2373 logHostAddr.s_addr = rxr_HostOf(tcon);
2375 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2376 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2377 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2379 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2382 * Get volume/vnode for the fetched file; caller's rights to it are
2386 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2387 &parentwhentargetnotdir, &client, READ_LOCK,
2388 &rights, &anyrights)))
2389 goto Bad_FetchStatus;
2391 /* set volume synchronization information */
2392 SetVolumeSync(Sync, volptr);
2394 /* Are we allowed to fetch Fid's status? */
2395 if (targetptr->disk.type != vDirectory) {
2397 Check_PermissionRights(targetptr, client, rights,
2398 CHK_FETCHSTATUS, 0))) {
2399 if (rx_GetCallAbortCode(acall) == errorCode)
2400 rx_SetCallAbortCode(acall, 0);
2401 goto Bad_FetchStatus;
2405 /* set OutStatus From the Fid */
2406 GetStatus(targetptr, OutStatus, rights, anyrights,
2407 parentwhentargetnotdir);
2409 /* If a r/w volume, also set the CallBack state */
2410 if (VolumeWriteable(volptr))
2411 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2413 struct AFSFid myFid;
2414 memset(&myFid, 0, sizeof(struct AFSFid));
2415 myFid.Volume = Fid->Volume;
2416 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2420 /* Update and store volume/vnode and parent vnodes back */
2421 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2423 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2426 } /*SAFSS_FetchStatus */
2430 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2431 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2432 struct AFSVolSync * Sync)
2436 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2437 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2438 int errorCode = 0; /* return code to caller */
2439 Volume *volptr = 0; /* pointer to the volume */
2440 struct client *client = 0; /* pointer to the client data */
2441 afs_int32 rights, anyrights; /* rights for this and any user */
2442 register struct AFSFid *tfid; /* file id we're dealing with now */
2443 struct rx_connection *tcon = rx_ConnectionOf(acall);
2444 struct client *t_client = NULL; /* tmp pointer to the client data */
2445 #if FS_STATS_DETAILED
2446 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2447 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2448 struct timeval elapsedTime; /* Transfer time */
2451 * Set our stats pointer, remember when the RPC operation started, and
2452 * tally the operation.
2454 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2458 TM_GetTimeOfDay(&opStartTime, 0);
2459 #endif /* FS_STATS_DETAILED */
2461 ViceLog(1, ("SAFS_BulkStatus\n"));
2463 AFSCallStats.TotalCalls++;
2465 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2466 if (nfiles <= 0) { /* Sanity check */
2468 goto Audit_and_Return;
2471 /* allocate space for return output parameters */
2472 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2473 malloc(nfiles * sizeof(struct AFSFetchStatus));
2474 if (!OutStats->AFSBulkStats_val) {
2475 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2478 OutStats->AFSBulkStats_len = nfiles;
2479 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2480 malloc(nfiles * sizeof(struct AFSCallBack));
2481 if (!CallBacks->AFSCBs_val) {
2482 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2485 CallBacks->AFSCBs_len = nfiles;
2487 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2488 goto Bad_BulkStatus;
2490 tfid = Fids->AFSCBFids_val;
2491 for (i = 0; i < nfiles; i++, tfid++) {
2493 * Get volume/vnode for the fetched file; caller's rights to it
2497 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2498 &parentwhentargetnotdir, &client, READ_LOCK,
2499 &rights, &anyrights)))
2500 goto Bad_BulkStatus;
2501 /* set volume synchronization information, but only once per call */
2503 SetVolumeSync(Sync, volptr);
2505 /* Are we allowed to fetch Fid's status? */
2506 if (targetptr->disk.type != vDirectory) {
2508 Check_PermissionRights(targetptr, client, rights,
2509 CHK_FETCHSTATUS, 0))) {
2510 if (rx_GetCallAbortCode(acall) == errorCode)
2511 rx_SetCallAbortCode(acall, 0);
2512 goto Bad_BulkStatus;
2516 /* set OutStatus From the Fid */
2517 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2518 anyrights, parentwhentargetnotdir);
2520 /* If a r/w volume, also set the CallBack state */
2521 if (VolumeWriteable(volptr))
2522 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2523 &CallBacks->AFSCBs_val[i]);
2525 struct AFSFid myFid;
2526 memset(&myFid, 0, sizeof(struct AFSFid));
2527 myFid.Volume = tfid->Volume;
2528 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2529 &CallBacks->AFSCBs_val[i]);
2532 /* put back the file ID and volume */
2533 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2535 parentwhentargetnotdir = (Vnode *) 0;
2536 targetptr = (Vnode *) 0;
2537 volptr = (Volume *) 0;
2538 client = (struct client *)0;
2542 /* Update and store volume/vnode and parent vnodes back */
2543 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2545 errorCode = CallPostamble(tcon, errorCode);
2547 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2549 #if FS_STATS_DETAILED
2550 TM_GetTimeOfDay(&opStopTime, 0);
2551 if (errorCode == 0) {
2553 (opP->numSuccesses)++;
2554 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2555 fs_stats_AddTo((opP->sumTime), elapsedTime);
2556 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2557 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2558 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2560 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2561 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2565 #endif /* FS_STATS_DETAILED */
2568 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2569 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2570 AUD_ID, t_client ? t_client->ViceId : 0,
2571 AUD_FIDS, Fids, AUD_END);
2574 } /*SRXAFS_BulkStatus */
2578 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2579 struct AFSBulkStats * OutStats,
2580 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2584 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2585 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2586 int errorCode = 0; /* return code to caller */
2587 Volume *volptr = 0; /* pointer to the volume */
2588 struct client *client = 0; /* pointer to the client data */
2589 afs_int32 rights, anyrights; /* rights for this and any user */
2590 register struct AFSFid *tfid; /* file id we're dealing with now */
2591 struct rx_connection *tcon;
2592 struct client *t_client = NULL; /* tmp ptr to client data */
2593 AFSFetchStatus *tstatus;
2594 #if FS_STATS_DETAILED
2595 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2596 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2597 struct timeval elapsedTime; /* Transfer time */
2600 * Set our stats pointer, remember when the RPC operation started, and
2601 * tally the operation.
2603 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2607 TM_GetTimeOfDay(&opStartTime, 0);
2608 #endif /* FS_STATS_DETAILED */
2610 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2612 AFSCallStats.TotalCalls++;
2614 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2615 if (nfiles <= 0) { /* Sanity check */
2617 goto Audit_and_Return;
2620 /* allocate space for return output parameters */
2621 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2622 malloc(nfiles * sizeof(struct AFSFetchStatus));
2623 if (!OutStats->AFSBulkStats_val) {
2624 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2627 OutStats->AFSBulkStats_len = nfiles;
2628 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2629 malloc(nfiles * sizeof(struct AFSCallBack));
2630 if (!CallBacks->AFSCBs_val) {
2631 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2634 CallBacks->AFSCBs_len = nfiles;
2636 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon))) {
2637 goto Bad_InlineBulkStatus;
2640 tfid = Fids->AFSCBFids_val;
2641 for (i = 0; i < nfiles; i++, tfid++) {
2643 * Get volume/vnode for the fetched file; caller's rights to it
2647 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2648 &parentwhentargetnotdir, &client, READ_LOCK,
2649 &rights, &anyrights))) {
2650 tstatus = &OutStats->AFSBulkStats_val[i];
2651 tstatus->errorCode = errorCode;
2652 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2654 parentwhentargetnotdir = (Vnode *) 0;
2655 targetptr = (Vnode *) 0;
2656 volptr = (Volume *) 0;
2657 client = (struct client *)0;
2661 /* set volume synchronization information, but only once per call */
2663 SetVolumeSync(Sync, volptr);
2665 /* Are we allowed to fetch Fid's status? */
2666 if (targetptr->disk.type != vDirectory) {
2668 Check_PermissionRights(targetptr, client, rights,
2669 CHK_FETCHSTATUS, 0))) {
2670 tstatus = &OutStats->AFSBulkStats_val[i];
2671 tstatus->errorCode = errorCode;
2672 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2673 (Vnode *) 0, volptr, &client);
2674 parentwhentargetnotdir = (Vnode *) 0;
2675 targetptr = (Vnode *) 0;
2676 volptr = (Volume *) 0;
2677 client = (struct client *)0;
2682 /* set OutStatus From the Fid */
2683 GetStatus(targetptr,
2684 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2685 rights, anyrights, parentwhentargetnotdir);
2687 /* If a r/w volume, also set the CallBack state */
2688 if (VolumeWriteable(volptr))
2689 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2690 &CallBacks->AFSCBs_val[i]);
2692 struct AFSFid myFid;
2693 memset(&myFid, 0, sizeof(struct AFSFid));
2694 myFid.Volume = tfid->Volume;
2695 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2696 &CallBacks->AFSCBs_val[i]);
2699 /* put back the file ID and volume */
2700 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2702 parentwhentargetnotdir = (Vnode *) 0;
2703 targetptr = (Vnode *) 0;
2704 volptr = (Volume *) 0;
2705 client = (struct client *)0;
2708 Bad_InlineBulkStatus:
2709 /* Update and store volume/vnode and parent vnodes back */
2710 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2712 errorCode = CallPostamble(tcon, errorCode);
2714 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2716 #if FS_STATS_DETAILED
2717 TM_GetTimeOfDay(&opStopTime, 0);
2718 if (errorCode == 0) {
2720 (opP->numSuccesses)++;
2721 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2722 fs_stats_AddTo((opP->sumTime), elapsedTime);
2723 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2724 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2725 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2727 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2728 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2732 #endif /* FS_STATS_DETAILED */
2735 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2736 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2737 AUD_ID, t_client ? t_client->ViceId : 0,
2738 AUD_FIDS, Fids, AUD_END);
2741 } /*SRXAFS_InlineBulkStatus */
2745 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2746 struct AFSFetchStatus * OutStatus,
2747 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2750 struct rx_connection *tcon;
2751 struct client *t_client = NULL; /* tmp ptr to client data */
2752 #if FS_STATS_DETAILED
2753 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2754 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2755 struct timeval elapsedTime; /* Transfer time */
2758 * Set our stats pointer, remember when the RPC operation started, and
2759 * tally the operation.
2761 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2765 TM_GetTimeOfDay(&opStartTime, 0);
2766 #endif /* FS_STATS_DETAILED */
2768 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
2769 goto Bad_FetchStatus;
2771 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2774 code = CallPostamble(tcon, code);
2776 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2778 #if FS_STATS_DETAILED
2779 TM_GetTimeOfDay(&opStopTime, 0);
2782 (opP->numSuccesses)++;
2783 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2784 fs_stats_AddTo((opP->sumTime), elapsedTime);
2785 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2786 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2787 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2789 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2790 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2794 #endif /* FS_STATS_DETAILED */
2796 osi_auditU(acall, FetchStatusEvent, code,
2797 AUD_ID, t_client ? t_client->ViceId : 0,
2798 AUD_FID, Fid, AUD_END);
2801 } /*SRXAFS_FetchStatus */
2805 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2806 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2807 afs_fsize_t Length, afs_fsize_t FileLength,
2808 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2810 Vnode *targetptr = 0; /* pointer to input fid */
2811 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2812 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2813 int errorCode = 0; /* return code for caller */
2814 int fileCode = 0; /* return code from vol package */
2815 Volume *volptr = 0; /* pointer to the volume header */
2816 struct client *client = 0; /* pointer to client structure */
2817 afs_int32 rights, anyrights; /* rights for this and any user */
2818 struct client *t_client = NULL; /* tmp ptr to client data */
2819 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2820 struct rx_connection *tcon;
2821 #if FS_STATS_DETAILED
2822 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2823 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2824 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2825 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2826 struct timeval elapsedTime; /* Transfer time */
2827 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2828 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2829 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2832 * Set our stats pointers, remember when the RPC operation started, and
2833 * tally the operation.
2835 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2836 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2841 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2843 TM_GetTimeOfDay(&opStartTime, 0);
2844 #endif /* FS_STATS_DETAILED */
2847 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2849 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
2852 /* Get ptr to client data for user Id for logging */
2853 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2854 logHostAddr.s_addr = rxr_HostOf(tcon);
2856 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2857 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2858 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2861 * Get associated volume/vnode for the stored file; caller's rights
2865 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
2866 &parentwhentargetnotdir, &client, WRITE_LOCK,
2867 &rights, &anyrights))) {
2871 /* set volume synchronization information */
2872 SetVolumeSync(Sync, volptr);
2874 if ((targetptr->disk.type == vSymlink)) {
2875 /* Should we return a better error code here??? */
2880 /* Check if we're allowed to store the data */
2882 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
2888 * Drop the read lock on the parent directory after saving the parent
2889 * vnode information we need to pass to GetStatus
2891 if (parentwhentargetnotdir != NULL) {
2892 tparentwhentargetnotdir = *parentwhentargetnotdir;
2893 VPutVnode(&fileCode, parentwhentargetnotdir);
2894 assert(!fileCode || (fileCode == VSALVAGE));
2895 parentwhentargetnotdir = NULL;
2897 #if FS_STATS_DETAILED
2899 * Remember when the data transfer started.
2901 TM_GetTimeOfDay(&xferStartTime, 0);
2902 #endif /* FS_STATS_DETAILED */
2904 /* Do the actual storing of the data */
2905 #if FS_STATS_DETAILED
2907 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2908 FileLength, (InStatus->Mask & AFS_FSYNC),
2909 &bytesToXfer, &bytesXferred);
2912 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
2913 FileLength, (InStatus->Mask & AFS_FSYNC));
2914 if (errorCode && (!targetptr->changed_newTime))
2916 #endif /* FS_STATS_DETAILED */
2917 #if FS_STATS_DETAILED
2919 * At this point, the data transfer is done, for good or ill. Remember
2920 * when the transfer ended, bump the number of successes/failures, and
2921 * integrate the transfer size and elapsed time into the stats. If the
2922 * operation failed, we jump to the appropriate point.
2924 TM_GetTimeOfDay(&xferStopTime, 0);
2926 (xferP->numXfers)++;
2928 (xferP->numSuccesses)++;
2931 * Bump the xfer sum by the number of bytes actually sent, NOT the
2934 tot_bytesXferred += bytesXferred;
2935 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2936 tot_bytesXferred &= 0x3FF;
2937 if (bytesXferred < xferP->minBytes)
2938 xferP->minBytes = bytesXferred;
2939 if (bytesXferred > xferP->maxBytes)
2940 xferP->maxBytes = bytesXferred;
2943 * Tally the size of the object. Note: we tally the actual size,
2944 * NOT the number of bytes that made it out over the wire.
2946 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2947 (xferP->count[0])++;
2948 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2949 (xferP->count[1])++;
2950 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2951 (xferP->count[2])++;
2952 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2953 (xferP->count[3])++;
2954 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2955 (xferP->count[4])++;
2956 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2957 (xferP->count[5])++;
2958 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2959 (xferP->count[6])++;
2960 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2961 (xferP->count[7])++;
2963 (xferP->count[8])++;
2965 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2966 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2967 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2968 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2969 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2971 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2972 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2977 * Finally, go off to tell our caller the bad news in case the
2980 if (errorCode && (!targetptr->changed_newTime))
2982 #endif /* FS_STATS_DETAILED */
2984 /* Update the status of the target's vnode */
2985 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
2986 targetptr, volptr, 0);
2988 /* Get the updated File's status back to the caller */
2989 GetStatus(targetptr, OutStatus, rights, anyrights,
2990 &tparentwhentargetnotdir);
2993 /* Update and store volume/vnode and parent vnodes back */
2994 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2996 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
2998 errorCode = CallPostamble(tcon, errorCode);
3000 #if FS_STATS_DETAILED
3001 TM_GetTimeOfDay(&opStopTime, 0);
3002 if (errorCode == 0) {
3004 (opP->numSuccesses)++;
3005 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3006 fs_stats_AddTo((opP->sumTime), elapsedTime);
3007 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3008 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3009 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3011 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3012 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3016 #endif /* FS_STATS_DETAILED */
3017 osi_auditU(acall, StoreDataEvent, errorCode,
3018 AUD_ID, t_client ? t_client->ViceId : 0,
3019 AUD_FID, Fid, AUD_END);
3021 } /*common_StoreData64 */
3024 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3025 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3026 afs_uint32 Length, afs_uint32 FileLength,
3027 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3029 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3031 } /*SRXAFS_StoreData */
3034 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3035 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3036 afs_uint64 Length, afs_uint64 FileLength,
3037 struct AFSFetchStatus * OutStatus,
3038 struct AFSVolSync * Sync)
3042 afs_fsize_t tLength;
3043 afs_fsize_t tFileLength;
3045 #ifdef AFS_64BIT_ENV
3046 #ifndef AFS_LARGEFILE_ENV
3047 if (FileLength > 0x7fffffff)
3049 #endif /* !AFS_LARGEFILE_ENV */
3050 tPos = (afs_fsize_t) Pos;
3051 tLength = (afs_fsize_t) Length;
3052 tFileLength = (afs_fsize_t) FileLength;
3053 #else /* AFS_64BIT_ENV */
3054 if (FileLength.high)
3057 tLength = Length.low;
3058 tFileLength = FileLength.low;
3059 #endif /* AFS_64BIT_ENV */
3062 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3068 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3069 struct AFSOpaque * AccessList,
3070 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3072 Vnode *targetptr = 0; /* pointer to input fid */
3073 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3074 int errorCode = 0; /* return code for caller */
3075 struct AFSStoreStatus InStatus; /* Input status for fid */
3076 Volume *volptr = 0; /* pointer to the volume header */
3077 struct client *client = 0; /* pointer to client structure */
3078 afs_int32 rights, anyrights; /* rights for this and any user */
3079 struct rx_connection *tcon;
3080 struct client *t_client = NULL; /* tmp ptr to client data */
3081 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3082 #if FS_STATS_DETAILED
3083 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3084 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3085 struct timeval elapsedTime; /* Transfer time */
3088 * Set our stats pointer, remember when the RPC operation started, and
3089 * tally the operation.
3091 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3095 TM_GetTimeOfDay(&opStartTime, 0);
3096 #endif /* FS_STATS_DETAILED */
3097 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
3100 /* Get ptr to client data for user Id for logging */
3101 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3102 logHostAddr.s_addr = rxr_HostOf(tcon);
3104 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3105 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3106 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3108 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3110 InStatus.Mask = 0; /* not storing any status */
3113 * Get associated volume/vnode for the target dir; caller's rights
3114 * are also returned.
3117 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3118 &parentwhentargetnotdir, &client, WRITE_LOCK,
3119 &rights, &anyrights))) {
3123 /* set volume synchronization information */
3124 SetVolumeSync(Sync, volptr);
3126 /* Check if we have permission to change the dir's ACL */
3128 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3133 /* Build and store the new Access List for the dir */
3134 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3138 targetptr->changed_newTime = 1; /* status change of directory */
3140 /* convert the write lock to a read lock before breaking callbacks */
3141 VVnodeWriteToRead(&errorCode, targetptr);
3142 assert(!errorCode || errorCode == VSALVAGE);
3144 /* break call backs on the directory */
3145 BreakCallBack(client->host, Fid, 0);
3147 /* Get the updated dir's status back to the caller */
3148 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3151 /* Update and store volume/vnode and parent vnodes back */
3152 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3154 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3155 errorCode = CallPostamble(tcon, errorCode);
3157 #if FS_STATS_DETAILED
3158 TM_GetTimeOfDay(&opStopTime, 0);
3159 if (errorCode == 0) {
3161 (opP->numSuccesses)++;
3162 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3163 fs_stats_AddTo((opP->sumTime), elapsedTime);
3164 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3165 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3166 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3168 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3169 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3173 #endif /* FS_STATS_DETAILED */
3175 osi_auditU(acall, StoreACLEvent, errorCode,
3176 AUD_ID, t_client ? t_client->ViceId : 0,
3177 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3180 } /*SRXAFS_StoreACL */
3184 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3185 * should be merged when possible.
3188 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3189 struct AFSStoreStatus *InStatus,
3190 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3192 Vnode *targetptr = 0; /* pointer to input fid */
3193 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3194 int errorCode = 0; /* return code for caller */
3195 Volume *volptr = 0; /* pointer to the volume header */
3196 struct client *client = 0; /* pointer to client structure */
3197 afs_int32 rights, anyrights; /* rights for this and any user */
3198 struct client *t_client = NULL; /* tmp ptr to client data */
3199 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3200 struct rx_connection *tcon = rx_ConnectionOf(acall);
3202 /* Get ptr to client data for user Id for logging */
3203 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3204 logHostAddr.s_addr = rxr_HostOf(tcon);
3206 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3207 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3208 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3210 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3213 * Get volume/vnode for the target file; caller's rights to it are
3217 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3218 &parentwhentargetnotdir, &client, WRITE_LOCK,
3219 &rights, &anyrights))) {
3220 goto Bad_StoreStatus;
3223 /* set volume synchronization information */
3224 SetVolumeSync(Sync, volptr);
3226 /* Check if the caller has proper permissions to store status to Fid */
3228 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3230 goto Bad_StoreStatus;
3233 * Check for a symbolic link; we can't chmod these (otherwise could
3234 * change a symlink to a mt pt or vice versa)
3236 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3238 goto Bad_StoreStatus;
3241 /* Update the status of the target's vnode */
3242 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3243 (parentwhentargetnotdir ? parentwhentargetnotdir
3244 : targetptr), volptr, 0);
3246 /* convert the write lock to a read lock before breaking callbacks */
3247 VVnodeWriteToRead(&errorCode, targetptr);
3248 assert(!errorCode || errorCode == VSALVAGE);
3250 /* Break call backs on Fid */
3251 BreakCallBack(client->host, Fid, 0);
3253 /* Return the updated status back to caller */
3254 GetStatus(targetptr, OutStatus, rights, anyrights,
3255 parentwhentargetnotdir);
3258 /* Update and store volume/vnode and parent vnodes back */
3259 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3261 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3264 } /*SAFSS_StoreStatus */
3268 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3269 struct AFSStoreStatus * InStatus,
3270 struct AFSFetchStatus * OutStatus,
3271 struct AFSVolSync * Sync)
3274 struct rx_connection *tcon;
3275 struct client *t_client = NULL; /* tmp ptr to client data */
3276 #if FS_STATS_DETAILED
3277 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3278 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3279 struct timeval elapsedTime; /* Transfer time */
3282 * Set our stats pointer, remember when the RPC operation started, and
3283 * tally the operation.
3285 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3289 TM_GetTimeOfDay(&opStartTime, 0);
3290 #endif /* FS_STATS_DETAILED */
3292 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3293 goto Bad_StoreStatus;
3295 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3298 code = CallPostamble(tcon, code);
3300 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3302 #if FS_STATS_DETAILED
3303 TM_GetTimeOfDay(&opStopTime, 0);
3306 (opP->numSuccesses)++;
3307 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3308 fs_stats_AddTo((opP->sumTime), elapsedTime);
3309 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3310 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3311 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3313 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3314 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3318 #endif /* FS_STATS_DETAILED */
3320 osi_auditU(acall, StoreStatusEvent, code,
3321 AUD_ID, t_client ? t_client->ViceId : 0,
3322 AUD_FID, Fid, AUD_END);
3325 } /*SRXAFS_StoreStatus */
3329 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3330 * merged in when possible.
3333 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3334 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3336 Vnode *parentptr = 0; /* vnode of input Directory */
3337 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3338 Vnode *targetptr = 0; /* file to be deleted */
3339 Volume *volptr = 0; /* pointer to the volume header */
3340 AFSFid fileFid; /* area for Fid from the directory */
3341 int errorCode = 0; /* error code */
3342 DirHandle dir; /* Handle for dir package I/O */
3343 struct client *client = 0; /* pointer to client structure */
3344 afs_int32 rights, anyrights; /* rights for this and any user */
3345 struct client *t_client; /* tmp ptr to client data */
3346 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3347 struct rx_connection *tcon = rx_ConnectionOf(acall);
3350 /* Get ptr to client data for user Id for logging */
3351 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3352 logHostAddr.s_addr = rxr_HostOf(tcon);
3354 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3355 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3356 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3358 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3361 * Get volume/vnode for the parent dir; caller's access rights are
3365 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3366 &parentwhentargetnotdir, &client, WRITE_LOCK,
3367 &rights, &anyrights))) {
3368 goto Bad_RemoveFile;
3370 /* set volume synchronization information */
3371 SetVolumeSync(Sync, volptr);
3373 /* Does the caller has delete (& write) access to the parent directory? */
3374 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3375 goto Bad_RemoveFile;
3378 /* Actually delete the desired file */
3380 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3382 goto Bad_RemoveFile;
3385 /* Update the vnode status of the parent dir */
3386 #if FS_STATS_DETAILED
3387 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3388 parentptr->disk.linkCount,
3389 client->InSameNetwork);
3391 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3392 parentptr->disk.linkCount);
3393 #endif /* FS_STATS_DETAILED */
3395 /* Return the updated parent dir's status back to caller */
3396 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3398 /* Handle internal callback state for the parent and the deleted file */
3399 if (targetptr->disk.linkCount == 0) {
3400 /* no references left, discard entry */
3401 DeleteFileCallBacks(&fileFid);
3402 /* convert the parent lock to a read lock before breaking callbacks */
3403 VVnodeWriteToRead(&errorCode, parentptr);
3404 assert(!errorCode || errorCode == VSALVAGE);
3406 /* convert the parent lock to a read lock before breaking callbacks */
3407 VVnodeWriteToRead(&errorCode, parentptr);
3408 assert(!errorCode || errorCode == VSALVAGE);
3409 /* convert the target lock to a read lock before breaking callbacks */
3410 VVnodeWriteToRead(&errorCode, targetptr);
3411 assert(!errorCode || errorCode == VSALVAGE);
3412 /* tell all the file has changed */
3413 BreakCallBack(client->host, &fileFid, 1);
3416 /* break call back on the directory */
3417 BreakCallBack(client->host, DirFid, 0);
3420 /* Update and store volume/vnode and parent vnodes back */
3421 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3424 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3427 } /*SAFSS_RemoveFile */
3431 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3432 struct AFSFetchStatus * OutDirStatus,
3433 struct AFSVolSync * Sync)
3436 struct rx_connection *tcon;
3437 struct client *t_client = NULL; /* tmp ptr to client data */
3438 #if FS_STATS_DETAILED
3439 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3440 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3441 struct timeval elapsedTime; /* Transfer time */
3444 * Set our stats pointer, remember when the RPC operation started, and
3445 * tally the operation.
3447 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3451 TM_GetTimeOfDay(&opStartTime, 0);
3452 #endif /* FS_STATS_DETAILED */
3454 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3455 goto Bad_RemoveFile;
3457 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3460 code = CallPostamble(tcon, code);
3462 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3464 #if FS_STATS_DETAILED
3465 TM_GetTimeOfDay(&opStopTime, 0);
3468 (opP->numSuccesses)++;
3469 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3470 fs_stats_AddTo((opP->sumTime), elapsedTime);
3471 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3472 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3473 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3475 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3476 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3480 #endif /* FS_STATS_DETAILED */
3482 osi_auditU(acall, RemoveFileEvent, code,
3483 AUD_ID, t_client ? t_client->ViceId : 0,
3484 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3487 } /*SRXAFS_RemoveFile */
3491 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3492 * be merged in when possible.
3495 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3496 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3497 struct AFSFetchStatus *OutFidStatus,
3498 struct AFSFetchStatus *OutDirStatus,
3499 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3501 Vnode *parentptr = 0; /* vnode of input Directory */
3502 Vnode *targetptr = 0; /* vnode of the new file */
3503 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3504 Volume *volptr = 0; /* pointer to the volume header */
3505 int errorCode = 0; /* error code */
3506 DirHandle dir; /* Handle for dir package I/O */
3507 struct client *client = 0; /* pointer to client structure */
3508 afs_int32 rights, anyrights; /* rights for this and any user */
3509 struct client *t_client; /* tmp ptr to client data */
3510 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3511 struct rx_connection *tcon = rx_ConnectionOf(acall);
3515 /* Get ptr to client data for user Id for logging */
3516 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3517 logHostAddr.s_addr = rxr_HostOf(tcon);
3519 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3520 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3521 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3523 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3525 if (!FileNameOK(Name)) {
3527 goto Bad_CreateFile;
3531 * Get associated volume/vnode for the parent dir; caller long are
3535 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3536 &parentwhentargetnotdir, &client, WRITE_LOCK,
3537 &rights, &anyrights))) {
3538 goto Bad_CreateFile;
3541 /* set volume synchronization information */
3542 SetVolumeSync(Sync, volptr);
3544 /* Can we write (and insert) onto the parent directory? */
3545 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3546 goto Bad_CreateFile;
3548 /* get a new vnode for the file to be created and set it up */
3550 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3551 vFile, nBlocks(0)))) {
3552 goto Bad_CreateFile;
3555 /* update the status of the parent vnode */
3556 #if FS_STATS_DETAILED
3557 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3558 parentptr->disk.linkCount,
3559 client->InSameNetwork);
3561 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3562 parentptr->disk.linkCount);
3563 #endif /* FS_STATS_DETAILED */
3565 /* update the status of the new file's vnode */
3566 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3567 parentptr, volptr, 0);
3569 /* set up the return status for the parent dir and the newly created file, and since the newly created file is owned by the creator, give it PRSFS_ADMINISTER to tell the client its the owner of the file */
3570 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3571 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3573 /* convert the write lock to a read lock before breaking callbacks */
3574 VVnodeWriteToRead(&errorCode, parentptr);
3575 assert(!errorCode || errorCode == VSALVAGE);
3577 /* break call back on parent dir */
3578 BreakCallBack(client->host, DirFid, 0);
3580 /* Return a callback promise for the newly created file to the caller */
3581 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3584 /* Update and store volume/vnode and parent vnodes back */
3585 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3588 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3591 } /*SAFSS_CreateFile */
3595 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3596 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3597 struct AFSFetchStatus * OutFidStatus,
3598 struct AFSFetchStatus * OutDirStatus,
3599 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3602 struct rx_connection *tcon;
3603 struct client *t_client = NULL; /* tmp ptr to client data */
3604 #if FS_STATS_DETAILED
3605 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3606 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3607 struct timeval elapsedTime; /* Transfer time */
3610 * Set our stats pointer, remember when the RPC operation started, and
3611 * tally the operation.
3613 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3617 TM_GetTimeOfDay(&opStartTime, 0);
3618 #endif /* FS_STATS_DETAILED */
3620 memset(OutFid, 0, sizeof(struct AFSFid));
3622 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
3623 goto Bad_CreateFile;
3626 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3627 OutDirStatus, CallBack, Sync);
3630 code = CallPostamble(tcon, code);
3632 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3634 #if FS_STATS_DETAILED
3635 TM_GetTimeOfDay(&opStopTime, 0);
3638 (opP->numSuccesses)++;
3639 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3640 fs_stats_AddTo((opP->sumTime), elapsedTime);
3641 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3642 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3643 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3645 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3646 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3650 #endif /* FS_STATS_DETAILED */
3652 osi_auditU(acall, CreateFileEvent, code,
3653 AUD_ID, t_client ? t_client->ViceId : 0,
3654 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3657 } /*SRXAFS_CreateFile */
3661 * This routine is called exclusively from SRXAFS_Rename(), and should be
3662 * merged in when possible.
3665 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3666 struct AFSFid *NewDirFid, char *NewName,
3667 struct AFSFetchStatus *OutOldDirStatus,
3668 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3670 Vnode *oldvptr = 0; /* vnode of the old Directory */
3671 Vnode *newvptr = 0; /* vnode of the new Directory */
3672 Vnode *fileptr = 0; /* vnode of the file to move */
3673 Vnode *newfileptr = 0; /* vnode of the file to delete */
3674 Vnode *testvptr = 0; /* used in directory tree walk */
3675 Vnode *parent = 0; /* parent for use in SetAccessList */
3676 int errorCode = 0; /* error code */
3677 int fileCode = 0; /* used when writing Vnodes */
3678 VnodeId testnode; /* used in directory tree walk */
3679 AFSFid fileFid; /* Fid of file to move */
3680 AFSFid newFileFid; /* Fid of new file */
3681 DirHandle olddir; /* Handle for dir package I/O */
3682 DirHandle newdir; /* Handle for dir package I/O */
3683 DirHandle filedir; /* Handle for dir package I/O */
3684 DirHandle newfiledir; /* Handle for dir package I/O */
3685 Volume *volptr = 0; /* pointer to the volume header */
3686 struct client *client = 0; /* pointer to client structure */
3687 afs_int32 rights, anyrights; /* rights for this and any user */
3688 afs_int32 newrights; /* rights for this user */
3689 afs_int32 newanyrights; /* rights for any user */
3690 int doDelete; /* deleted the rename target (ref count now 0) */
3692 struct client *t_client; /* tmp ptr to client data */
3693 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3694 struct rx_connection *tcon = rx_ConnectionOf(acall);
3699 FidZero(&newfiledir);
3701 /* Get ptr to client data for user Id for logging */
3702 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3703 logHostAddr.s_addr = rxr_HostOf(tcon);
3705 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3706 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3707 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3708 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3710 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3712 if (!FileNameOK(NewName)) {
3716 if (OldDirFid->Volume != NewDirFid->Volume) {
3721 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3722 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3723 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3729 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3731 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3732 &parent, &client, WRITE_LOCK, &rights,
3737 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3739 newrights = rights, newanyrights = anyrights;
3742 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3743 MustBeDIR, &parent, &client, WRITE_LOCK,
3744 &newrights, &newanyrights))) {
3750 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3751 &parent, &client, WRITE_LOCK, &newrights,
3757 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3758 &parent, &client, WRITE_LOCK, &rights,
3765 /* set volume synchronization information */
3766 SetVolumeSync(Sync, volptr);
3768 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3771 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3775 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3776 * call to CopyOnWrite returns error, it is not necessary to revert back
3777 * the effects of the first call because the contents of the volume is
3778 * not modified, it is only replicated.
3780 if (oldvptr->disk.cloned) {
3781 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3782 if ((errorCode = CopyOnWrite(oldvptr, volptr)))
3785 SetDirHandle(&olddir, oldvptr);
3786 if (newvptr->disk.cloned) {
3787 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3788 if ((errorCode = CopyOnWrite(newvptr, volptr)))
3792 SetDirHandle(&newdir, newvptr);
3794 /* Lookup the file to delete its vnode */
3795 if (Lookup(&olddir, OldName, &fileFid)) {
3799 if (fileFid.Vnode == oldvptr->vnodeNumber
3800 || fileFid.Vnode == newvptr->vnodeNumber) {
3801 errorCode = FSERR_ELOOP;
3804 fileFid.Volume = V_id(volptr);
3805 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3806 if (errorCode != 0) {
3808 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3809 OldName, errorCode));
3810 VTakeOffline(volptr);
3813 if (fileptr->disk.uniquifier != fileFid.Unique) {
3815 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3817 VTakeOffline(volptr);
3822 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3823 && fileptr->disk.linkCount != 1) {
3825 * Hard links exist to this file - cannot move one of the links to
3826 * a new directory because of AFS restrictions (this is the same
3827 * reason that links cannot be made across directories, i.e.
3834 /* Lookup the new file */
3835 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3836 if (readonlyServer) {
3837 errorCode = VREADONLY;
3840 if (!(newrights & PRSFS_DELETE)) {
3844 if (newFileFid.Vnode == oldvptr->vnodeNumber
3845 || newFileFid.Vnode == newvptr->vnodeNumber
3846 || newFileFid.Vnode == fileFid.Vnode) {
3850 newFileFid.Volume = V_id(volptr);
3852 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3853 if (errorCode != 0) {
3855 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
3856 NewName, errorCode));
3857 VTakeOffline(volptr);
3860 if (fileptr->disk.uniquifier != fileFid.Unique) {
3862 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
3864 VTakeOffline(volptr);
3868 SetDirHandle(&newfiledir, newfileptr);
3869 /* Now check that we're moving directories over directories properly, etc.
3870 * return proper POSIX error codes:
3871 * if fileptr is a file and new is a dir: EISDIR.
3872 * if fileptr is a dir and new is a file: ENOTDIR.
3873 * Also, dir to be removed must be empty, of course.
3875 if (newfileptr->disk.type == vDirectory) {
3876 if (fileptr->disk.type != vDirectory) {
3880 if ((IsEmpty(&newfiledir))) {
3885 if (fileptr->disk.type == vDirectory) {
3886 errorCode = ENOTDIR;
3893 * ok - now we check that the old name is not above new name in the
3894 * directory structure. This is to prevent removing a subtree alltogether
3896 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
3897 afs_int32 forpass = 0, vnum = 0, top = 0;
3898 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
3899 if (testnode > vnum) vnum = testnode;
3900 if (forpass > vnum) {
3901 errorCode = FSERR_ELOOP;
3904 if (testnode == oldvptr->vnodeNumber) {
3905 testnode = oldvptr->disk.parent;
3908 if ((testnode == fileptr->vnodeNumber)
3909 || (testnode == newvptr->vnodeNumber)) {
3910 errorCode = FSERR_ELOOP;
3913 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
3914 errorCode = FSERR_ELOOP;
3917 if (testnode == 1) top = 1;
3918 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
3919 assert(errorCode == 0);
3920 testnode = testvptr->disk.parent;
3921 VPutVnode(&errorCode, testvptr);
3922 if ((top == 1) && (testnode != 0)) {
3923 VTakeOffline(volptr);
3927 assert(errorCode == 0);
3930 /* Do the CopyonWrite first before modifying anything else. Copying is
3931 * required because we may have to change entries for ..
3933 if ((fileptr->disk.type == vDirectory) && (fileptr->disk.cloned)) {
3934 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
3935 if ((errorCode = CopyOnWrite(fileptr, volptr)))
3939 /* If the new name exists already, delete it and the file it points to */
3942 /* Delete NewName from its directory */
3943 code = Delete(&newdir, NewName);
3946 /* Drop the link count */
3947 newfileptr->disk.linkCount--;
3948 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
3949 afs_fsize_t newSize;
3950 VN_GET_LEN(newSize, newfileptr);
3951 VAdjustDiskUsage((Error *) & errorCode, volptr,
3952 (afs_sfsize_t) - nBlocks(newSize), 0);
3953 if (VN_GET_INO(newfileptr)) {
3954 IH_REALLYCLOSE(newfileptr->handle);
3956 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
3957 V_parentId(volptr));
3958 IH_RELEASE(newfileptr->handle);
3959 if (errorCode == -1) {
3961 ("Del: inode=%s, name=%s, errno=%d\n",
3962 PrintInode(NULL, VN_GET_INO(newfileptr)),
3964 if ((errno != ENOENT) && (errno != EIO)
3965 && (errno != ENXIO))
3966 ViceLog(0, ("Do we need to fsck?"));
3969 VN_SET_INO(newfileptr, (Inode) 0);
3970 newfileptr->delete = 1; /* Mark NewName vnode to delete */
3973 /* Link count did not drop to zero.
3974 * Mark NewName vnode as changed - updates stime.
3976 newfileptr->changed_newTime = 1;
3981 * If the create below fails, and the delete above worked, we have
3982 * removed the new name and not replaced it. This is not very likely,
3983 * but possible. We could try to put the old file back, but it is
3984 * highly unlikely that it would work since it would involve issuing
3987 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
3990 /* Delete the old name */
3991 assert(Delete(&olddir, (char *)OldName) == 0);
3993 /* if the directory length changes, reflect it in the statistics */
3994 #if FS_STATS_DETAILED
3995 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
3996 oldvptr->disk.linkCount, client->InSameNetwork);
3997 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
3998 newvptr->disk.linkCount, client->InSameNetwork);
4000 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4001 oldvptr->disk.linkCount);
4002 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4003 newvptr->disk.linkCount);
4004 #endif /* FS_STATS_DETAILED */
4006 if (oldvptr == newvptr)
4007 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4009 fileptr->disk.parent = newvptr->vnodeNumber;
4010 fileptr->changed_newTime = 1; /* status change of moved file */
4012 /* if we are dealing with a rename of a directory */
4013 if (fileptr->disk.type == vDirectory) {
4014 assert(!fileptr->disk.cloned);
4015 SetDirHandle(&filedir, fileptr);
4016 /* fix .. to point to the correct place */
4017 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4018 assert(Create(&filedir, "..", NewDirFid) == 0);
4019 fileptr->disk.dataVersion++;
4020 /* if the parent directories are different the link counts have to be */
4021 /* changed due to .. in the renamed directory */
4022 if (oldvptr != newvptr) {
4023 oldvptr->disk.linkCount--;
4024 newvptr->disk.linkCount++;
4028 /* set up return status */
4029 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4030 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4031 if (newfileptr && doDelete) {
4032 DeleteFileCallBacks(&newFileFid); /* no other references */
4037 /* convert the write locks to a read locks before breaking callbacks */
4038 VVnodeWriteToRead(&errorCode, newvptr);
4039 assert(!errorCode || errorCode == VSALVAGE);
4040 if (oldvptr != newvptr) {
4041 VVnodeWriteToRead(&errorCode, oldvptr);
4042 assert(!errorCode || errorCode == VSALVAGE);
4044 if (newfileptr && !doDelete) {
4045 /* convert the write lock to a read lock before breaking callbacks */
4046 VVnodeWriteToRead(&errorCode, newfileptr);
4047 assert(!errorCode || errorCode == VSALVAGE);
4050 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4051 BreakCallBack(client->host, NewDirFid, 0);
4052 if (oldvptr != newvptr) {
4053 BreakCallBack(client->host, OldDirFid, 0);
4054 if (fileptr->disk.type == vDirectory) /* if a dir moved, .. changed */
4055 BreakCallBack(client->host, &fileFid, 0);
4058 /* Note: it is not necessary to break the callback */
4060 DeleteFileCallBacks(&newFileFid); /* no other references */
4062 /* other's still exist (with wrong link count) */
4063 BreakCallBack(client->host, &newFileFid, 1);
4068 VPutVnode(&fileCode, newfileptr);
4069 assert(fileCode == 0);
4071 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
4072 newvptr : 0), oldvptr, volptr, &client);
4076 FidZap(&newfiledir);
4077 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4084 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4085 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4086 struct AFSFetchStatus * OutOldDirStatus,
4087 struct AFSFetchStatus * OutNewDirStatus,
4088 struct AFSVolSync * Sync)
4091 struct rx_connection *tcon;
4092 struct client *t_client = NULL; /* tmp ptr to client data */
4093 #if FS_STATS_DETAILED
4094 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4095 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4096 struct timeval elapsedTime; /* Transfer time */
4099 * Set our stats pointer, remember when the RPC operation started, and
4100 * tally the operation.
4102 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4106 TM_GetTimeOfDay(&opStartTime, 0);
4107 #endif /* FS_STATS_DETAILED */
4109 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4113 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4114 OutOldDirStatus, OutNewDirStatus, Sync);
4117 code = CallPostamble(tcon, code);
4119 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4121 #if FS_STATS_DETAILED
4122 TM_GetTimeOfDay(&opStopTime, 0);
4125 (opP->numSuccesses)++;
4126 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4127 fs_stats_AddTo((opP->sumTime), elapsedTime);
4128 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4129 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4130 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4132 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4133 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4137 #endif /* FS_STATS_DETAILED */
4139 osi_auditU(acall, RenameFileEvent, code,
4140 AUD_ID, t_client ? t_client->ViceId : 0,
4141 AUD_FID, OldDirFid, AUD_STR, OldName,
4142 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4145 } /*SRXAFS_Rename */
4149 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4150 * merged into it when possible.
4153 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4154 char *LinkContents, struct AFSStoreStatus *InStatus,
4155 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4156 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4158 Vnode *parentptr = 0; /* vnode of input Directory */
4159 Vnode *targetptr = 0; /* vnode of the new link */
4160 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4161 int errorCode = 0; /* error code */
4163 DirHandle dir; /* Handle for dir package I/O */
4164 Volume *volptr = 0; /* pointer to the volume header */
4165 struct client *client = 0; /* pointer to client structure */
4166 afs_int32 rights, anyrights; /* rights for this and any user */
4167 struct client *t_client; /* tmp ptr to client data */
4168 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4170 struct rx_connection *tcon = rx_ConnectionOf(acall);
4174 /* Get ptr to client data for user Id for logging */
4175 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4176 logHostAddr.s_addr = rxr_HostOf(tcon);
4178 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4179 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4180 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4182 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4184 if (!FileNameOK(Name)) {
4190 * Get the vnode and volume for the parent dir along with the caller's
4194 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4195 &parentwhentargetnotdir, &client, WRITE_LOCK,
4196 &rights, &anyrights))) {
4200 /* set volume synchronization information */
4201 SetVolumeSync(Sync, volptr);
4203 /* Does the caller has insert (and write) access to the parent directory? */
4204 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4209 * If we're creating a mount point (any x bits clear), we must have
4210 * administer access to the directory, too. Always allow sysadmins
4213 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4214 if (readonlyServer) {
4215 errorCode = VREADONLY;
4219 * We have a mountpoint, 'cause we're trying to set the Unix mode
4220 * bits to something with some x bits missing (default mode bits
4221 * if AFS_SETMODE is false is 0777)
4223 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4229 /* get a new vnode for the symlink and set it up */
4231 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4232 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4236 /* update the status of the parent vnode */
4237 #if FS_STATS_DETAILED
4238 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4239 parentptr->disk.linkCount,
4240 client->InSameNetwork);
4242 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4243 parentptr->disk.linkCount);
4244 #endif /* FS_STATS_DETAILED */
4246 /* update the status of the new symbolic link file vnode */
4247 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4248 parentptr, volptr, strlen((char *)LinkContents));
4250 /* Write the contents of the symbolic link name into the target inode */
4251 fdP = IH_OPEN(targetptr->handle);
4252 assert(fdP != NULL);
4253 len = strlen((char *) LinkContents);
4254 code = (len == FDH_WRITE(fdP, (char *) LinkContents, len)) ? 0 : VDISKFULL;
4255 if (code) ViceLog(0, ("SAFSS_Symlink FDH_WRITE failed for len=%d, Fid=%u.%d.%d\n", len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4258 * Set up and return modified status for the parent dir and new symlink
4261 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4262 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4264 /* convert the write lock to a read lock before breaking callbacks */
4265 VVnodeWriteToRead(&errorCode, parentptr);
4266 assert(!errorCode || errorCode == VSALVAGE);
4268 /* break call back on the parent dir */
4269 BreakCallBack(client->host, DirFid, 0);
4272 /* Write the all modified vnodes (parent, new files) and volume back */
4273 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4276 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4277 return ( errorCode ? errorCode : code );
4279 } /*SAFSS_Symlink */
4283 SRXAFS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4284 OutFidStatus, OutDirStatus, Sync)
4285 struct AFSVolSync *Sync;
4286 struct rx_call *acall; /* Rx call */
4287 struct AFSFid *DirFid; /* Parent dir's fid */
4288 char *Name; /* File name to create */
4289 char *LinkContents; /* Contents of the new created file */
4290 struct AFSStoreStatus *InStatus; /* Input status for the new symbolic link */
4291 struct AFSFid *OutFid; /* Fid for newly created symbolic link */
4292 struct AFSFetchStatus *OutFidStatus; /* Output status for new symbolic link */
4293 struct AFSFetchStatus *OutDirStatus; /* Output status for parent dir */
4297 struct rx_connection *tcon;
4298 struct client *t_client = NULL; /* tmp ptr to client data */
4299 #if FS_STATS_DETAILED
4300 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4301 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4302 struct timeval elapsedTime; /* Transfer time */
4305 * Set our stats pointer, remember when the RPC operation started, and
4306 * tally the operation.
4308 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4312 TM_GetTimeOfDay(&opStartTime, 0);
4313 #endif /* FS_STATS_DETAILED */
4315 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4319 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4320 OutFidStatus, OutDirStatus, Sync);
4323 code = CallPostamble(tcon, code);
4325 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4327 #if FS_STATS_DETAILED
4328 TM_GetTimeOfDay(&opStopTime, 0);
4331 (opP->numSuccesses)++;
4332 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4333 fs_stats_AddTo((opP->sumTime), elapsedTime);
4334 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4335 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4336 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4338 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4339 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4343 #endif /* FS_STATS_DETAILED */
4345 osi_auditU(acall, SymlinkEvent, code,
4346 AUD_ID, t_client ? t_client->ViceId : 0,
4347 AUD_FID, DirFid, AUD_STR, Name,
4348 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4351 } /*SRXAFS_Symlink */
4355 * This routine is called exclusively by SRXAFS_Link(), and should be
4356 * merged into it when possible.
4359 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4360 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4361 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4363 Vnode *parentptr = 0; /* vnode of input Directory */
4364 Vnode *targetptr = 0; /* vnode of the new file */
4365 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4366 Volume *volptr = 0; /* pointer to the volume header */
4367 int errorCode = 0; /* error code */
4368 DirHandle dir; /* Handle for dir package I/O */
4369 struct client *client = 0; /* pointer to client structure */
4370 afs_int32 rights, anyrights; /* rights for this and any user */
4371 struct client *t_client; /* tmp ptr to client data */
4372 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4373 struct rx_connection *tcon = rx_ConnectionOf(acall);
4377 /* Get ptr to client data for user Id for logging */
4378 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4379 logHostAddr.s_addr = rxr_HostOf(tcon);
4381 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4382 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4383 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4384 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4386 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4388 if (DirFid->Volume != ExistingFid->Volume) {
4392 if (!FileNameOK(Name)) {
4398 * Get the vnode and volume for the parent dir along with the caller's
4402 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4403 &parentwhentargetnotdir, &client, WRITE_LOCK,
4404 &rights, &anyrights))) {
4408 /* set volume synchronization information */
4409 SetVolumeSync(Sync, volptr);
4411 /* Can the caller insert into the parent directory? */
4412 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4416 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4417 /* AFS fileservers always have directory vnodes that are odd. */
4422 /* get the file vnode */
4424 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4427 if (targetptr->disk.type != vFile) {
4431 if (targetptr->disk.parent != DirFid->Vnode) {
4435 if (parentptr->disk.cloned) {
4436 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4437 if ((errorCode = CopyOnWrite(parentptr, volptr)))
4438 goto Bad_Link; /* disk full error */
4441 /* add the name to the directory */
4442 SetDirHandle(&dir, parentptr);
4443 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4447 /* update the status in the parent vnode */
4448 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4449 #if FS_STATS_DETAILED
4450 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4451 parentptr->disk.linkCount,
4452 client->InSameNetwork);
4454 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4455 parentptr->disk.linkCount);
4456 #endif /* FS_STATS_DETAILED */
4458 targetptr->disk.linkCount++;
4459 targetptr->disk.author = client->ViceId;
4460 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4462 /* set up return status */
4463 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4464 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4466 /* convert the write locks to read locks before breaking callbacks */
4467 VVnodeWriteToRead(&errorCode, targetptr);
4468 assert(!errorCode || errorCode == VSALVAGE);
4469 VVnodeWriteToRead(&errorCode, parentptr);
4470 assert(!errorCode || errorCode == VSALVAGE);
4472 /* break call back on DirFid */
4473 BreakCallBack(client->host, DirFid, 0);
4475 * We also need to break the callback for the file that is hard-linked since part
4476 * of its status (like linkcount) is changed
4478 BreakCallBack(client->host, ExistingFid, 0);
4481 /* Write the all modified vnodes (parent, new files) and volume back */
4482 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4485 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4492 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4493 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4494 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4497 struct rx_connection *tcon;
4498 struct client *t_client = NULL; /* tmp ptr to client data */
4499 #if FS_STATS_DETAILED
4500 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4501 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4502 struct timeval elapsedTime; /* Transfer time */
4505 * Set our stats pointer, remember when the RPC operation started, and
4506 * tally the operation.
4508 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4512 TM_GetTimeOfDay(&opStartTime, 0);
4513 #endif /* FS_STATS_DETAILED */
4515 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4519 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4520 OutDirStatus, Sync);
4523 code = CallPostamble(tcon, code);
4525 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4527 #if FS_STATS_DETAILED
4528 TM_GetTimeOfDay(&opStopTime, 0);
4531 (opP->numSuccesses)++;
4532 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4533 fs_stats_AddTo((opP->sumTime), elapsedTime);
4534 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4535 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4536 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4538 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4539 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4543 #endif /* FS_STATS_DETAILED */
4545 osi_auditU(acall, LinkEvent, code,
4546 AUD_ID, t_client ? t_client->ViceId : 0,
4547 AUD_FID, DirFid, AUD_STR, Name,
4548 AUD_FID, ExistingFid, AUD_END);
4555 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4556 * merged into it when possible.
4559 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4560 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4561 struct AFSFetchStatus *OutFidStatus,
4562 struct AFSFetchStatus *OutDirStatus,
4563 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4565 Vnode *parentptr = 0; /* vnode of input Directory */
4566 Vnode *targetptr = 0; /* vnode of the new file */
4567 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4568 Volume *volptr = 0; /* pointer to the volume header */
4569 int errorCode = 0; /* error code */
4570 struct acl_accessList *newACL; /* Access list */
4571 int newACLSize; /* Size of access list */
4572 DirHandle dir; /* Handle for dir package I/O */
4573 DirHandle parentdir; /* Handle for dir package I/O */
4574 struct client *client = 0; /* pointer to client structure */
4575 afs_int32 rights, anyrights; /* rights for this and any user */
4576 struct client *t_client; /* tmp ptr to client data */
4577 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4578 struct rx_connection *tcon = rx_ConnectionOf(acall);
4581 FidZero(&parentdir);
4583 /* Get ptr to client data for user Id for logging */
4584 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4585 logHostAddr.s_addr = rxr_HostOf(tcon);
4587 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4588 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4589 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4591 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4593 if (!FileNameOK(Name)) {
4599 * Get the vnode and volume for the parent dir along with the caller's
4603 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4604 &parentwhentargetnotdir, &client, WRITE_LOCK,
4605 &rights, &anyrights))) {
4609 /* set volume synchronization information */
4610 SetVolumeSync(Sync, volptr);
4612 /* Write access to the parent directory? */
4613 #ifdef DIRCREATE_NEED_WRITE
4615 * requires w access for the user to create a directory. this
4616 * closes a loophole in the current security arrangement, since a
4617 * user with i access only can create a directory and get the
4618 * implcit a access that goes with dir ownership, and proceed to
4619 * subvert quota in the volume.
4621 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4622 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4624 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4625 #endif /* DIRCREATE_NEED_WRITE */
4628 #define EMPTYDIRBLOCKS 2
4629 /* get a new vnode and set it up */
4631 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4632 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4636 /* Update the status for the parent dir */
4637 #if FS_STATS_DETAILED
4638 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4639 parentptr->disk.linkCount + 1,
4640 client->InSameNetwork);
4642 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4643 parentptr->disk.linkCount + 1);
4644 #endif /* FS_STATS_DETAILED */
4646 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4647 assert((SetAccessList
4648 (&targetptr, &volptr, &newACL, &newACLSize,
4649 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4650 assert(parentwhentargetnotdir == 0);
4651 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4653 /* update the status for the target vnode */
4654 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4655 parentptr, volptr, 0);
4657 /* Actually create the New directory in the directory package */
4658 SetDirHandle(&dir, targetptr);
4659 assert(!(MakeDir(&dir, OutFid, DirFid)));
4661 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4663 /* set up return status */
4664 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4665 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4667 /* convert the write lock to a read lock before breaking callbacks */
4668 VVnodeWriteToRead(&errorCode, parentptr);
4669 assert(!errorCode || errorCode == VSALVAGE);
4671 /* break call back on DirFid */
4672 BreakCallBack(client->host, DirFid, 0);
4674 /* Return a callback promise to caller */
4675 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4678 /* Write the all modified vnodes (parent, new files) and volume back */
4679 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4683 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4686 } /*SAFSS_MakeDir */
4690 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4691 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4692 struct AFSFetchStatus * OutFidStatus,
4693 struct AFSFetchStatus * OutDirStatus,
4694 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4697 struct rx_connection *tcon;
4698 struct client *t_client = NULL; /* tmp ptr to client data */
4699 #if FS_STATS_DETAILED
4700 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4701 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4702 struct timeval elapsedTime; /* Transfer time */
4705 * Set our stats pointer, remember when the RPC operation started, and
4706 * tally the operation.
4708 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
4712 TM_GetTimeOfDay(&opStartTime, 0);
4713 #endif /* FS_STATS_DETAILED */
4714 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4718 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4719 OutDirStatus, CallBack, Sync);
4722 code = CallPostamble(tcon, code);
4724 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4726 #if FS_STATS_DETAILED
4727 TM_GetTimeOfDay(&opStopTime, 0);
4730 (opP->numSuccesses)++;
4731 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4732 fs_stats_AddTo((opP->sumTime), elapsedTime);
4733 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4734 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4735 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4737 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4738 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4742 #endif /* FS_STATS_DETAILED */
4744 osi_auditU(acall, MakeDirEvent, code,
4745 AUD_ID, t_client ? t_client->ViceId : 0,
4746 AUD_FID, DirFid, AUD_STR, Name,
4747 AUD_FID, OutFid, AUD_END);
4750 } /*SRXAFS_MakeDir */
4754 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4755 * merged into it when possible.
4758 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4759 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4761 Vnode *parentptr = 0; /* vnode of input Directory */
4762 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4763 Vnode *targetptr = 0; /* file to be deleted */
4764 AFSFid fileFid; /* area for Fid from the directory */
4765 int errorCode = 0; /* error code */
4766 DirHandle dir; /* Handle for dir package I/O */
4767 Volume *volptr = 0; /* pointer to the volume header */
4768 struct client *client = 0; /* pointer to client structure */
4769 afs_int32 rights, anyrights; /* rights for this and any user */
4770 Vnode debugvnode1, debugvnode2;
4771 struct client *t_client; /* tmp ptr to client data */
4772 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4773 struct rx_connection *tcon = rx_ConnectionOf(acall);
4777 /* Get ptr to client data for user Id for logging */
4778 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4779 logHostAddr.s_addr = rxr_HostOf(tcon);
4781 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4782 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4783 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4785 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4788 * Get the vnode and volume for the parent dir along with the caller's
4792 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4793 &parentwhentargetnotdir, &client, WRITE_LOCK,
4794 &rights, &anyrights))) {
4797 debugvnode1 = *parentptr;
4799 /* set volume synchronization information */
4800 SetVolumeSync(Sync, volptr);
4802 /* Does the caller has delete (&write) access to the parent dir? */
4803 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
4807 debugvnode2 = *parentptr;
4808 /* Do the actual delete of the desired (empty) directory, Name */
4810 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
4815 /* Update the status for the parent dir; link count is also adjusted */
4816 #if FS_STATS_DETAILED
4817 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4818 parentptr->disk.linkCount - 1,
4819 client->InSameNetwork);
4821 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4822 parentptr->disk.linkCount - 1);
4823 #endif /* FS_STATS_DETAILED */
4825 /* Return to the caller the updated parent dir status */
4826 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4829 * Note: it is not necessary to break the callback on fileFid, since
4830 * refcount is now 0, so no one should be able to refer to the dir
4833 DeleteFileCallBacks(&fileFid);
4835 /* convert the write lock to a read lock before breaking callbacks */
4836 VVnodeWriteToRead(&errorCode, parentptr);
4837 assert(!errorCode || errorCode == VSALVAGE);
4839 /* break call back on DirFid and fileFid */
4840 BreakCallBack(client->host, DirFid, 0);
4843 /* Write the all modified vnodes (parent, new files) and volume back */
4844 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4847 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
4850 } /*SAFSS_RemoveDir */
4854 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4855 struct AFSFetchStatus * OutDirStatus,
4856 struct AFSVolSync * Sync)
4859 struct rx_connection *tcon;
4860 struct client *t_client = NULL; /* tmp ptr to client data */
4861 #if FS_STATS_DETAILED
4862 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4863 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4864 struct timeval elapsedTime; /* Transfer time */
4867 * Set our stats pointer, remember when the RPC operation started, and
4868 * tally the operation.
4870 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
4874 TM_GetTimeOfDay(&opStartTime, 0);
4875 #endif /* FS_STATS_DETAILED */
4877 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
4880 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
4883 code = CallPostamble(tcon, code);
4885 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4887 #if FS_STATS_DETAILED
4888 TM_GetTimeOfDay(&opStopTime, 0);
4891 (opP->numSuccesses)++;
4892 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4893 fs_stats_AddTo((opP->sumTime), elapsedTime);
4894 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4895 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4896 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4898 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4899 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4903 #endif /* FS_STATS_DETAILED */
4905 osi_auditU(acall, RemoveDirEvent, code,
4906 AUD_ID, t_client ? t_client->ViceId : 0,
4907 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
4910 } /*SRXAFS_RemoveDir */
4914 * This routine is called exclusively by SRXAFS_SetLock(), and should be
4915 * merged into it when possible.
4918 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
4919 struct AFSVolSync *Sync)
4921 Vnode *targetptr = 0; /* vnode of input file */
4922 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4923 int errorCode = 0; /* error code */
4924 Volume *volptr = 0; /* pointer to the volume header */
4925 struct client *client = 0; /* pointer to client structure */
4926 afs_int32 rights, anyrights; /* rights for this and any user */
4927 struct client *t_client; /* tmp ptr to client data */
4928 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4929 static char *locktype[2] = { "LockRead", "LockWrite" };
4930 struct rx_connection *tcon = rx_ConnectionOf(acall);
4932 if (type != LockRead && type != LockWrite) {
4936 /* Get ptr to client data for user Id for logging */
4937 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4938 logHostAddr.s_addr = rxr_HostOf(tcon);
4940 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4941 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
4942 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4944 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
4947 * Get the vnode and volume for the desired file along with the caller's
4951 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
4952 &parentwhentargetnotdir, &client, WRITE_LOCK,
4953 &rights, &anyrights))) {
4957 /* set volume synchronization information */
4958 SetVolumeSync(Sync, volptr);
4960 /* Handle the particular type of set locking, type */
4961 errorCode = HandleLocking(targetptr, rights, type);
4964 /* Write the all modified vnodes (parent, new files) and volume back */
4965 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
4968 if ((errorCode == VREADONLY) && (type == LockRead))
4969 errorCode = 0; /* allow read locks on RO volumes without saving state */
4971 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
4974 } /*SAFSS_SetLock */
4978 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
4979 ViceLockType type, struct AFSVolSync * Sync)
4981 return SRXAFS_SetLock(acall, Fid, type, Sync);
4982 } /*SRXAFS_OldSetLock */
4986 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
4987 struct AFSVolSync * Sync)
4990 struct rx_connection *tcon;
4991 struct client *t_client = NULL; /* tmp ptr to client data */
4992 #if FS_STATS_DETAILED
4993 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4994 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4995 struct timeval elapsedTime; /* Transfer time */
4998 * Set our stats pointer, remember when the RPC operation started, and
4999 * tally the operation.
5001 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5005 TM_GetTimeOfDay(&opStartTime, 0);
5006 #endif /* FS_STATS_DETAILED */
5008 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
5011 code = SAFSS_SetLock(acall, Fid, type, Sync);
5014 code = CallPostamble(tcon, code);
5016 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5018 #if FS_STATS_DETAILED
5019 TM_GetTimeOfDay(&opStopTime, 0);
5022 (opP->numSuccesses)++;
5023 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5024 fs_stats_AddTo((opP->sumTime), elapsedTime);
5025 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5026 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5027 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5029 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5030 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5034 #endif /* FS_STATS_DETAILED */
5036 osi_auditU(acall, SetLockEvent, code,
5037 AUD_ID, t_client ? t_client->ViceId : 0,
5038 AUD_FID, Fid, AUD_LONG, type, AUD_END);
5040 } /*SRXAFS_SetLock */
5044 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5045 * merged into it when possible.
5048 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5049 struct AFSVolSync *Sync)
5051 Vnode *targetptr = 0; /* vnode of input file */
5052 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5053 int errorCode = 0; /* error code */
5054 Volume *volptr = 0; /* pointer to the volume header */
5055 struct client *client = 0; /* pointer to client structure */
5056 afs_int32 rights, anyrights; /* rights for this and any user */
5057 struct client *t_client; /* tmp ptr to client data */
5058 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5059 struct rx_connection *tcon = rx_ConnectionOf(acall);
5061 /* Get ptr to client data for user Id for logging */
5062 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5063 logHostAddr.s_addr = rxr_HostOf(tcon);
5065 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5066 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5067 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5069 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5072 * Get the vnode and volume for the desired file along with the caller's
5076 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5077 &parentwhentargetnotdir, &client, WRITE_LOCK,
5078 &rights, &anyrights))) {
5079 goto Bad_ExtendLock;
5082 /* set volume synchronization information */
5083 SetVolumeSync(Sync, volptr);
5085 /* Handle the actual lock extension */
5086 errorCode = HandleLocking(targetptr, rights, LockExtend);
5089 /* Put back file's vnode and volume */
5090 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5093 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5094 errorCode = 0; /* under our generous policy re RO vols */
5096 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5099 } /*SAFSS_ExtendLock */
5103 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5104 struct AFSVolSync * Sync)
5106 return SRXAFS_ExtendLock(acall, Fid, Sync);
5107 } /*SRXAFS_OldExtendLock */
5111 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5112 struct AFSVolSync * Sync)
5115 struct rx_connection *tcon;
5116 struct client *t_client = NULL; /* tmp ptr to client data */
5117 #if FS_STATS_DETAILED
5118 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5119 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5120 struct timeval elapsedTime; /* Transfer time */
5123 * Set our stats pointer, remember when the RPC operation started, and
5124 * tally the operation.
5126 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5130 TM_GetTimeOfDay(&opStartTime, 0);
5131 #endif /* FS_STATS_DETAILED */
5133 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
5134 goto Bad_ExtendLock;
5136 code = SAFSS_ExtendLock(acall, Fid, Sync);
5139 code = CallPostamble(tcon, code);
5141 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5143 #if FS_STATS_DETAILED
5144 TM_GetTimeOfDay(&opStopTime, 0);
5147 (opP->numSuccesses)++;
5148 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5149 fs_stats_AddTo((opP->sumTime), elapsedTime);
5150 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5151 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5152 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5154 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5155 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5159 #endif /* FS_STATS_DETAILED */
5161 osi_auditU(acall, ExtendLockEvent, code,
5162 AUD_ID, t_client ? t_client->ViceId : 0,
5163 AUD_FID, Fid, AUD_END);
5166 } /*SRXAFS_ExtendLock */
5170 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5171 * merged into it when possible.
5174 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5175 struct AFSVolSync *Sync)
5177 Vnode *targetptr = 0; /* vnode of input file */
5178 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5179 int errorCode = 0; /* error code */
5180 Volume *volptr = 0; /* pointer to the volume header */
5181 struct client *client = 0; /* pointer to client structure */
5182 afs_int32 rights, anyrights; /* rights for this and any user */
5183 struct client *t_client; /* tmp ptr to client data */
5184 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5185 struct rx_connection *tcon = rx_ConnectionOf(acall);
5187 /* Get ptr to client data for user Id for logging */
5188 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5189 logHostAddr.s_addr = rxr_HostOf(tcon);
5191 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5192 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5193 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5195 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5198 * Get the vnode and volume for the desired file along with the caller's
5202 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5203 &parentwhentargetnotdir, &client, WRITE_LOCK,
5204 &rights, &anyrights))) {
5205 goto Bad_ReleaseLock;
5208 /* set volume synchronization information */
5209 SetVolumeSync(Sync, volptr);
5211 /* Handle the actual lock release */
5212 if ((errorCode = HandleLocking(targetptr, rights, LockRelease)))
5213 goto Bad_ReleaseLock;
5215 /* if no more locks left, a callback would be triggered here */
5216 if (targetptr->disk.lock.lockCount <= 0) {
5217 /* convert the write lock to a read lock before breaking callbacks */
5218 VVnodeWriteToRead(&errorCode, targetptr);
5219 assert(!errorCode || errorCode == VSALVAGE);
5220 BreakCallBack(client->host, Fid, 0);
5224 /* Put back file's vnode and volume */
5225 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5228 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5229 errorCode = 0; /* under our generous policy re RO vols */
5231 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5234 } /*SAFSS_ReleaseLock */
5238 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5239 struct AFSVolSync * Sync)
5241 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5242 } /*SRXAFS_OldReleaseLock */
5246 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5247 struct AFSVolSync * Sync)
5250 struct rx_connection *tcon;
5251 struct client *t_client = NULL; /* tmp ptr to client data */
5252 #if FS_STATS_DETAILED
5253 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5254 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5255 struct timeval elapsedTime; /* Transfer time */
5258 * Set our stats pointer, remember when the RPC operation started, and
5259 * tally the operation.
5261 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5265 TM_GetTimeOfDay(&opStartTime, 0);
5266 #endif /* FS_STATS_DETAILED */
5268 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
5269 goto Bad_ReleaseLock;
5271 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5274 code = CallPostamble(tcon, code);
5276 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5278 #if FS_STATS_DETAILED
5279 TM_GetTimeOfDay(&opStopTime, 0);
5282 (opP->numSuccesses)++;
5283 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5284 fs_stats_AddTo((opP->sumTime), elapsedTime);
5285 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5286 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5287 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5289 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5290 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5294 #endif /* FS_STATS_DETAILED */
5296 osi_auditU(acall, ReleaseLockEvent, code,
5297 AUD_ID, t_client ? t_client->ViceId : 0,
5298 AUD_FID, Fid, AUD_END);
5301 } /*SRXAFS_ReleaseLock */
5305 SetSystemStats(struct AFSStatistics *stats)
5307 /* Fix this sometime soon.. */
5308 /* Because hey, it's not like we have a network monitoring protocol... */
5309 struct timeval time;
5311 /* this works on all system types */
5312 TM_GetTimeOfDay(&time, 0);
5313 stats->CurrentTime = time.tv_sec;
5314 } /*SetSystemStats */
5317 SetAFSStats(struct AFSStatistics *stats)
5319 extern afs_int32 StartTime, CurrentConnections;
5323 stats->CurrentMsgNumber = 0;
5324 stats->OldestMsgNumber = 0;
5325 stats->StartTime = StartTime;
5326 stats->CurrentConnections = CurrentConnections;
5327 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5328 stats->TotalFetchs =
5329 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5330 AFSCallStats.FetchStatus;
5331 stats->FetchDatas = AFSCallStats.FetchData;
5332 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5333 seconds = AFSCallStats.AccumFetchTime / 1000;
5336 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5337 stats->TotalStores =
5338 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5339 AFSCallStats.StoreStatus;
5340 stats->StoreDatas = AFSCallStats.StoreData;
5341 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5342 seconds = AFSCallStats.AccumStoreTime / 1000;
5345 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5347 stats->ProcessSize = -1; /* TODO: */
5349 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5352 h_GetWorkStats((int *)&(stats->WorkStations),
5353 (int *)&(stats->ActiveWorkStations), (int *)0,
5354 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5358 /* Get disk related information from all AFS partitions. */
5361 SetVolumeStats(struct AFSStatistics *stats)
5363 struct DiskPartition *part;
5366 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5367 part = part->next) {
5368 stats->Disks[i].TotalBlocks = part->totalUsable;
5369 stats->Disks[i].BlocksAvailable = part->free;
5370 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5371 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5374 while (i < AFS_MSTATDISKS) {
5375 stats->Disks[i].TotalBlocks = -1;
5378 } /*SetVolumeStats */
5381 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5384 struct rx_connection *tcon = rx_ConnectionOf(acall);
5385 struct client *t_client = NULL; /* tmp ptr to client data */
5386 #if FS_STATS_DETAILED
5387 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5388 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5389 struct timeval elapsedTime; /* Transfer time */
5392 * Set our stats pointer, remember when the RPC operation started, and
5393 * tally the operation.
5395 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5399 TM_GetTimeOfDay(&opStartTime, 0);
5400 #endif /* FS_STATS_DETAILED */
5402 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon)))
5403 goto Bad_GetStatistics;
5405 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5407 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5409 memset(Statistics, 0, sizeof(*Statistics));
5410 SetAFSStats((struct AFSStatistics *)Statistics);
5411 SetVolumeStats((struct AFSStatistics *)Statistics);
5412 SetSystemStats((struct AFSStatistics *)Statistics);
5415 code = CallPostamble(tcon, code);
5417 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5419 #if FS_STATS_DETAILED
5420 TM_GetTimeOfDay(&opStopTime, 0);
5423 (opP->numSuccesses)++;
5424 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5425 fs_stats_AddTo((opP->sumTime), elapsedTime);
5426 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5427 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5428 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5430 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5431 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5435 #endif /* FS_STATS_DETAILED */
5437 osi_auditU(acall, GetStatisticsEvent, code,
5438 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5440 } /*SRXAFS_GetStatistics */
5443 /*------------------------------------------------------------------------
5444 * EXPORTED SRXAFS_XStatsVersion
5447 * Routine called by the server-side RPC interface to implement
5448 * pulling out the xstat version number for the File Server.
5451 * a_versionP : Ptr to the version number variable to set.
5457 * Nothing interesting.
5461 *------------------------------------------------------------------------*/
5464 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5465 { /*SRXAFS_XStatsVersion */
5467 struct client *t_client = NULL; /* tmp ptr to client data */
5468 struct rx_connection *tcon;
5469 #if FS_STATS_DETAILED
5470 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5471 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5472 struct timeval elapsedTime; /* Transfer time */
5475 * Set our stats pointer, remember when the RPC operation started, and
5476 * tally the operation.
5478 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5482 TM_GetTimeOfDay(&opStartTime, 0);
5483 #endif /* FS_STATS_DETAILED */
5485 *a_versionP = AFS_XSTAT_VERSION;
5487 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5489 #if FS_STATS_DETAILED
5490 TM_GetTimeOfDay(&opStopTime, 0);
5491 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5492 fs_stats_AddTo((opP->sumTime), elapsedTime);
5493 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5494 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5495 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5497 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5498 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5501 (opP->numSuccesses)++;
5503 #endif /* FS_STATS_DETAILED */
5505 osi_auditU(a_call, XStatsVersionEvent, 0,
5506 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5508 } /*SRXAFS_XStatsVersion */
5511 /*------------------------------------------------------------------------
5512 * PRIVATE FillPerfValues
5515 * Routine called to fill a regular performance data structure.
5518 * a_perfP : Ptr to perf structure to fill
5524 * Various collections need this info, so the guts were put in
5525 * this separate routine.
5529 *------------------------------------------------------------------------*/
5532 FillPerfValues(struct afs_PerfStats *a_perfP)
5533 { /*FillPerfValues */
5535 int dir_Buffers; /*# buffers in use by dir package */
5536 int dir_Calls; /*# read calls in dir package */
5537 int dir_IOs; /*# I/O ops in dir package */
5540 * Vnode cache section.
5542 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5543 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5544 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5545 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5546 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5547 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5548 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5549 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5550 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5551 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5552 a_perfP->vcache_H_Entries = VolumeCacheSize;
5553 a_perfP->vcache_H_Gets = VolumeGets;
5554 a_perfP->vcache_H_Replacements = VolumeReplacements;
5557 * Directory section.
5559 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5560 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5561 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5562 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5567 a_perfP->rx_packetRequests = (afs_int32) rx_stats.packetRequests;
5568 a_perfP->rx_noPackets_RcvClass =
5569 (afs_int32) rx_stats.receivePktAllocFailures;
5570 a_perfP->rx_noPackets_SendClass =
5571 (afs_int32) rx_stats.sendPktAllocFailures;
5572 a_perfP->rx_noPackets_SpecialClass =
5573 (afs_int32) rx_stats.specialPktAllocFailures;
5574 a_perfP->rx_socketGreedy = (afs_int32) rx_stats.socketGreedy;
5575 a_perfP->rx_bogusPacketOnRead = (afs_int32) rx_stats.bogusPacketOnRead;
5576 a_perfP->rx_bogusHost = (afs_int32) rx_stats.bogusHost;
5577 a_perfP->rx_noPacketOnRead = (afs_int32) rx_stats.noPacketOnRead;
5578 a_perfP->rx_noPacketBuffersOnRead =
5579 (afs_int32) rx_stats.noPacketBuffersOnRead;
5580 a_perfP->rx_selects = (afs_int32) rx_stats.selects;
5581 a_perfP->rx_sendSelects = (afs_int32) rx_stats.sendSelects;
5582 a_perfP->rx_packetsRead_RcvClass =
5583 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
5584 a_perfP->rx_packetsRead_SendClass =
5585 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
5586 a_perfP->rx_packetsRead_SpecialClass =
5587 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
5588 a_perfP->rx_dataPacketsRead = (afs_int32) rx_stats.dataPacketsRead;
5589 a_perfP->rx_ackPacketsRead = (afs_int32) rx_stats.ackPacketsRead;
5590 a_perfP->rx_dupPacketsRead = (afs_int32) rx_stats.dupPacketsRead;
5591 a_perfP->rx_spuriousPacketsRead =
5592 (afs_int32) rx_stats.spuriousPacketsRead;
5593 a_perfP->rx_packetsSent_RcvClass =
5594 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
5595 a_perfP->rx_packetsSent_SendClass =
5596 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
5597 a_perfP->rx_packetsSent_SpecialClass =
5598 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
5599 a_perfP->rx_ackPacketsSent = (afs_int32) rx_stats.ackPacketsSent;
5600 a_perfP->rx_pingPacketsSent = (afs_int32) rx_stats.pingPacketsSent;
5601 a_perfP->rx_abortPacketsSent = (afs_int32) rx_stats.abortPacketsSent;
5602 a_perfP->rx_busyPacketsSent = (afs_int32) rx_stats.busyPacketsSent;
5603 a_perfP->rx_dataPacketsSent = (afs_int32) rx_stats.dataPacketsSent;
5604 a_perfP->rx_dataPacketsReSent = (afs_int32) rx_stats.dataPacketsReSent;
5605 a_perfP->rx_dataPacketsPushed = (afs_int32) rx_stats.dataPacketsPushed;
5606 a_perfP->rx_ignoreAckedPacket = (afs_int32) rx_stats.ignoreAckedPacket;
5607 a_perfP->rx_totalRtt_Sec = (afs_int32) rx_stats.totalRtt.sec;
5608 a_perfP->rx_totalRtt_Usec = (afs_int32) rx_stats.totalRtt.usec;
5609 a_perfP->rx_minRtt_Sec = (afs_int32) rx_stats.minRtt.sec;
5610 a_perfP->rx_minRtt_Usec = (afs_int32) rx_stats.minRtt.usec;
5611 a_perfP->rx_maxRtt_Sec = (afs_int32) rx_stats.maxRtt.sec;
5612 a_perfP->rx_maxRtt_Usec = (afs_int32) rx_stats.maxRtt.usec;
5613 a_perfP->rx_nRttSamples = (afs_int32) rx_stats.nRttSamples;
5614 a_perfP->rx_nServerConns = (afs_int32) rx_stats.nServerConns;
5615 a_perfP->rx_nClientConns = (afs_int32) rx_stats.nClientConns;
5616 a_perfP->rx_nPeerStructs = (afs_int32) rx_stats.nPeerStructs;
5617 a_perfP->rx_nCallStructs = (afs_int32) rx_stats.nCallStructs;
5618 a_perfP->rx_nFreeCallStructs = (afs_int32) rx_stats.nFreeCallStructs;
5620 a_perfP->host_NumHostEntries = HTs;
5621 a_perfP->host_HostBlocks = HTBlocks;
5622 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5623 &(a_perfP->host_HostsInSameNetOrSubnet),
5624 &(a_perfP->host_HostsInDiffSubnet),
5625 &(a_perfP->host_HostsInDiffNetwork));
5626 a_perfP->host_NumClients = CEs;
5627 a_perfP->host_ClientBlocks = CEBlocks;
5629 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5630 a_perfP->rx_nBusies = (afs_int32) rx_stats.nBusies;
5631 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5632 } /*FillPerfValues */
5635 /*------------------------------------------------------------------------
5636 * EXPORTED SRXAFS_GetXStats
5639 * Routine called by the server-side callback RPC interface to
5640 * implement getting the given data collection from the extended
5641 * File Server statistics.
5644 * a_call : Ptr to Rx call on which this request came in.
5645 * a_clientVersionNum : Client version number.
5646 * a_opCode : Desired operation.
5647 * a_serverVersionNumP : Ptr to version number to set.
5648 * a_timeP : Ptr to time value (seconds) to set.
5649 * a_dataP : Ptr to variable array structure to return
5656 * Nothing interesting.
5660 *------------------------------------------------------------------------*/
5663 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5664 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5665 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5666 { /*SRXAFS_GetXStats */
5668 register int code; /*Return value */
5669 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5670 afs_int32 dataBytes; /*Bytes in data buffer */
5671 #if FS_STATS_DETAILED
5672 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5673 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5674 struct timeval elapsedTime; /* Transfer time */
5677 * Set our stats pointer, remember when the RPC operation started, and
5678 * tally the operation.
5680 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
5684 TM_GetTimeOfDay(&opStartTime, 0);
5685 #endif /* FS_STATS_DETAILED */
5688 * Record the time of day and the server version number.
5690 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5691 *a_timeP = FT_ApproxTime();
5694 * Stuff the appropriate data in there (assume victory)
5699 ("Received GetXStats call for collection %d\n",
5700 a_collectionNumber));
5704 * We're not keeping stats, so just return successfully with
5707 a_dataP->AFS_CollData_len = 0;
5708 a_dataP->AFS_CollData_val = NULL;
5711 switch (a_collectionNumber) {
5712 case AFS_XSTATSCOLL_CALL_INFO:
5714 * Pass back all the call-count-related data.
5716 * >>> We are forced to allocate a separate area in which to
5717 * >>> put this stuff in by the RPC stub generator, since it
5718 * >>> will be freed at the tail end of the server stub code.
5722 * I don't think call-level stats are being collected yet
5723 * for the File Server.
5725 dataBytes = sizeof(struct afs_Stats);
5726 dataBuffP = (afs_int32 *) malloc(dataBytes);
5727 memcpy(dataBuffP, &afs_cmstats, dataBytes);
5728 a_dataP->AFS_CollData_len = dataBytes >> 2;
5729 a_dataP->AFS_CollData_val = dataBuffP;
5731 a_dataP->AFS_CollData_len = 0;
5732 a_dataP->AFS_CollData_val = NULL;
5736 case AFS_XSTATSCOLL_PERF_INFO:
5738 * Pass back all the regular performance-related data.
5740 * >>> We are forced to allocate a separate area in which to
5741 * >>> put this stuff in by the RPC stub generator, since it
5742 * >>> will be freed at the tail end of the server stub code.
5745 afs_perfstats.numPerfCalls++;
5746 FillPerfValues(&afs_perfstats);
5749 * Don't overwrite the spares at the end.
5752 dataBytes = sizeof(struct afs_PerfStats);
5753 dataBuffP = (afs_int32 *) malloc(dataBytes);
5754 memcpy(dataBuffP, &afs_perfstats, dataBytes);
5755 a_dataP->AFS_CollData_len = dataBytes >> 2;
5756 a_dataP->AFS_CollData_val = dataBuffP;
5759 case AFS_XSTATSCOLL_FULL_PERF_INFO:
5761 * Pass back the full collection of performance-related data.
5762 * We have to stuff the basic, overall numbers in, but the
5763 * detailed numbers are kept in the structure already.
5765 * >>> We are forced to allocate a separate area in which to
5766 * >>> put this stuff in by the RPC stub generator, since it
5767 * >>> will be freed at the tail end of the server stub code.
5770 afs_perfstats.numPerfCalls++;
5771 #if FS_STATS_DETAILED
5772 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
5773 FillPerfValues(&afs_FullPerfStats.overall);
5776 * Don't overwrite the spares at the end.
5779 dataBytes = sizeof(struct fs_stats_FullPerfStats);
5780 dataBuffP = (afs_int32 *) malloc(dataBytes);
5781 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
5782 a_dataP->AFS_CollData_len = dataBytes >> 2;
5783 a_dataP->AFS_CollData_val = dataBuffP;
5789 * Illegal collection number.
5791 a_dataP->AFS_CollData_len = 0;
5792 a_dataP->AFS_CollData_val = NULL;
5794 } /*Switch on collection number */
5796 #if FS_STATS_DETAILED
5797 TM_GetTimeOfDay(&opStopTime, 0);
5800 (opP->numSuccesses)++;
5801 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5802 fs_stats_AddTo((opP->sumTime), elapsedTime);
5803 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5804 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5805 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5807 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5808 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5812 #endif /* FS_STATS_DETAILED */
5816 } /*SRXAFS_GetXStats */
5820 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
5821 struct AFSCBs *CallBackArray)
5823 afs_int32 errorCode = 0;
5825 struct client *client = 0;
5826 struct rx_connection *tcon;
5827 #if FS_STATS_DETAILED
5828 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5829 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5830 struct timeval elapsedTime; /* Transfer time */
5833 * Set our stats pointer, remember when the RPC operation started, and
5834 * tally the operation.
5837 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
5841 TM_GetTimeOfDay(&opStartTime, 0);
5842 #endif /* FS_STATS_DETAILED */
5846 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
5847 FidArray->AFSCBFids_len));
5850 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
5852 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
5853 goto Bad_GiveUpCallBacks;
5855 if (!FidArray && !CallBackArray) {
5857 ("SAFS_GiveUpAllCallBacks: host=%x\n",
5858 (tcon->peer ? tcon->peer->host : 0)));
5859 errorCode = GetClient(tcon, &client);
5861 DeleteAllCallBacks_r(client->host, 1);
5865 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
5867 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
5868 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
5869 (tcon->peer ? tcon->peer->host : 0)));
5871 goto Bad_GiveUpCallBacks;
5874 errorCode = GetClient(tcon, &client);
5876 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
5877 register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
5878 DeleteCallBack(client->host, fid);
5884 Bad_GiveUpCallBacks:
5885 errorCode = CallPostamble(tcon, errorCode);
5887 #if FS_STATS_DETAILED
5888 TM_GetTimeOfDay(&opStopTime, 0);
5889 if (errorCode == 0) {
5891 (opP->numSuccesses)++;
5892 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5893 fs_stats_AddTo((opP->sumTime), elapsedTime);
5894 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5895 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5896 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5898 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5899 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5903 #endif /* FS_STATS_DETAILED */
5906 } /*common_GiveUpCallBacks */
5910 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
5911 struct AFSCBs * CallBackArray)
5913 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
5914 } /*SRXAFS_GiveUpCallBacks */
5917 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
5919 return common_GiveUpCallBacks(acall, 0, 0);
5920 } /*SRXAFS_GiveUpAllCallBacks */
5924 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
5925 struct AFSVolumeInfo * avolinfo)
5927 return (VNOVOL); /* XXX Obsolete routine XXX */
5929 } /*SRXAFS_NGetVolumeInfo */
5933 * Dummy routine. Should never be called (the cache manager should only
5934 * invoke this interface when communicating with a AFS/DFS Protocol
5938 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
5939 char *afs_name_p, struct AFSFid * afs_fid_p,
5940 struct AFSFetchStatus * afs_status_p,
5941 struct AFSFetchStatus * afs_dir_status_p,
5942 struct AFSCallBack * afs_callback_p,
5943 struct AFSVolSync * afs_sync_p)
5950 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
5953 struct rx_connection *tcon;
5954 afs_int32 *dataBuffP;
5955 afs_int32 dataBytes;
5956 #if FS_STATS_DETAILED
5957 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5958 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5959 struct timeval elapsedTime; /* Transfer time */
5962 * Set our stats pointer, remember when the RPC operation started, and
5963 * tally the operation.
5965 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETCAPABILITIES]);
5969 TM_GetTimeOfDay(&opStartTime, 0);
5970 #endif /* FS_STATS_DETAILED */
5972 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon)))
5976 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
5978 dataBytes = 1 * sizeof(afs_int32);
5979 dataBuffP = (afs_int32 *) malloc(dataBytes);
5980 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS;
5981 #if defined(AFS_64BIT_ENV) && defined(AFS_LARGEFILE_ENV)
5982 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
5985 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
5986 capabilities->Capabilities_val = dataBuffP;
5988 ViceLog(2, ("SAFS_GetCapabilties\n"));
5991 code = CallPostamble(tcon, code);
5993 #if FS_STATS_DETAILED
5994 TM_GetTimeOfDay(&opStopTime, 0);
5995 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5998 (opP->numSuccesses)++;
5999 fs_stats_AddTo((opP->sumTime), elapsedTime);
6000 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6001 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6002 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6004 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6005 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6009 #endif /* FS_STATS_DETAILED */
6014 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
6015 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
6019 afs_int32 nids, naddrs;
6020 afs_int32 *vd, *addr;
6021 int errorCode = 0; /* return code to caller */
6022 struct client *client = 0;
6023 struct rx_connection *tcon = rx_ConnectionOf(acall);
6025 ViceLog(1, ("SRXAFS_FlushCPS\n"));
6027 AFSCallStats.TotalCalls++;
6029 nids = vids->ViceIds_len; /* # of users in here */
6030 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
6031 if (nids < 0 || naddrs < 0) {
6036 vd = vids->ViceIds_val;
6037 for (i = 0; i < nids; i++, vd++) {
6040 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
6044 client->prfail = 2; /* Means re-eval client's cps */
6047 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6050 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6051 free(client->CPS.prlist_val);
6052 client->CPS.prlist_val = NULL;
6053 client->CPS.prlist_len = 0;
6055 ReleaseWriteLock(&client->lock);
6059 addr = addrs->IPAddrs_val;
6060 for (i = 0; i < naddrs; i++, addr++) {
6062 h_flushhostcps(*addr, htons(7001));
6066 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6068 } /*SRXAFS_FlushCPS */
6070 /* worthless hack to let CS keep running ancient software */
6072 afs_vtoi(register char *aname)
6074 register afs_int32 temp;
6078 while ((tc = *aname++)) {
6079 if (tc > '9' || tc < '0')
6080 return 0; /* invalid name */
6088 * may get name or #, but must handle all weird cases (recognize readonly
6089 * or backup volumes by name or #
6092 CopyVolumeEntry(char *aname, register struct vldbentry *ave,
6093 register struct VolumeInfo *av)
6095 register int i, j, vol;
6096 afs_int32 mask, whichType;
6097 afs_uint32 *serverHost, *typePtr;
6099 /* figure out what type we want if by name */
6101 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6102 whichType = BACKVOL;
6103 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6108 vol = afs_vtoi(aname);
6110 vol = ave->volumeId[whichType];
6113 * Now vol has volume # we're interested in. Next, figure out the type
6114 * of the volume by looking finding it in the vldb entry
6116 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6119 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6122 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6123 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6124 whichType = BACKVOL;
6126 return EINVAL; /* error: can't find volume in vldb entry */
6128 typePtr = &av->Type0;
6129 serverHost = &av->Server0;
6131 av->Type = whichType;
6132 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6133 if (ave->flags & VLF_RWEXISTS)
6134 typePtr[RWVOL] = ave->volumeId[RWVOL];
6135 if (ave->flags & VLF_ROEXISTS)
6136 typePtr[ROVOL] = ave->volumeId[ROVOL];
6137 if (ave->flags & VLF_BACKEXISTS)
6138 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6140 for (i = 0, j = 0; i < ave->nServers; i++) {
6141 if ((ave->serverFlags[i] & mask) == 0)
6142 continue; /* wrong volume */
6143 serverHost[j] = ave->serverNumber[i];
6146 av->ServerCount = j;
6148 serverHost[j++] = 0; /* bogus 8, but compat only now */
6153 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6155 static struct rx_connection *vlConn = 0;
6156 static int down = 0;
6157 static afs_int32 lastDownTime = 0;
6158 struct vldbentry tve;
6159 struct rx_securityClass *vlSec;
6160 register afs_int32 code;
6163 vlSec = rxnull_NewClientSecurityObject();
6165 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6166 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6168 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6169 return 1; /* failure */
6172 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6174 down = 0; /* call worked */
6177 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6183 /* otherwise convert to old format vldb entry */
6184 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6194 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6195 struct VolumeInfo * avolinfo)
6198 struct rx_connection *tcon;
6199 #if FS_STATS_DETAILED
6200 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6201 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6202 struct timeval elapsedTime; /* Transfer time */
6205 * Set our stats pointer, remember when the RPC operation started, and
6206 * tally the operation.
6208 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6212 TM_GetTimeOfDay(&opStartTime, 0);
6213 #endif /* FS_STATS_DETAILED */
6214 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
6215 goto Bad_GetVolumeInfo;
6218 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6220 code = TryLocalVLServer(avolid, avolinfo);
6222 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6223 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6224 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6225 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6228 code = CallPostamble(tcon, code);
6230 #if FS_STATS_DETAILED
6231 TM_GetTimeOfDay(&opStopTime, 0);
6234 (opP->numSuccesses)++;
6235 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6236 fs_stats_AddTo((opP->sumTime), elapsedTime);
6237 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6238 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6239 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6241 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6242 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6246 #endif /* FS_STATS_DETAILED */
6250 } /*SRXAFS_GetVolumeInfo */
6254 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6255 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6256 char **OfflineMsg, char **Motd)
6258 Vnode *targetptr = 0; /* vnode of the new file */
6259 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6260 int errorCode = 0; /* error code */
6261 Volume *volptr = 0; /* pointer to the volume header */
6262 struct client *client = 0; /* pointer to client entry */
6263 afs_int32 rights, anyrights; /* rights for this and any user */
6265 struct rx_connection *tcon;
6266 struct client *t_client = NULL; /* tmp ptr to client data */
6267 #if FS_STATS_DETAILED
6268 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6269 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6270 struct timeval elapsedTime; /* Transfer time */
6273 * Set our stats pointer, remember when the RPC operation started, and
6274 * tally the operation.
6277 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6281 TM_GetTimeOfDay(&opStartTime, 0);
6282 #endif /* FS_STATS_DETAILED */
6284 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6285 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
6286 goto Bad_GetVolumeStatus;
6289 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6293 goto Bad_GetVolumeStatus;
6295 dummyFid.Volume = avolid, dummyFid.Vnode =
6296 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6299 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6300 &parentwhentargetnotdir, &client, READ_LOCK,
6301 &rights, &anyrights)))
6302 goto Bad_GetVolumeStatus;
6304 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6306 goto Bad_GetVolumeStatus;
6308 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6310 Bad_GetVolumeStatus:
6311 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6313 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6314 /* next is to guarantee out strings exist for stub */
6316 *Name = (char *)malloc(1);
6320 *Motd = (char *)malloc(1);
6323 if (*OfflineMsg == 0) {
6324 *OfflineMsg = (char *)malloc(1);
6327 errorCode = CallPostamble(tcon, errorCode);
6329 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6331 #if FS_STATS_DETAILED
6332 TM_GetTimeOfDay(&opStopTime, 0);
6333 if (errorCode == 0) {
6335 (opP->numSuccesses)++;
6336 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6337 fs_stats_AddTo((opP->sumTime), elapsedTime);
6338 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6339 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6340 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6342 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6343 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6347 #endif /* FS_STATS_DETAILED */
6349 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
6350 AUD_ID, t_client ? t_client->ViceId : 0,
6351 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
6354 } /*SRXAFS_GetVolumeStatus */
6358 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6359 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6360 char *OfflineMsg, char *Motd)
6362 Vnode *targetptr = 0; /* vnode of the new file */
6363 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6364 int errorCode = 0; /* error code */
6365 Volume *volptr = 0; /* pointer to the volume header */
6366 struct client *client = 0; /* pointer to client entry */
6367 afs_int32 rights, anyrights; /* rights for this and any user */
6369 struct rx_connection *tcon = rx_ConnectionOf(acall);
6370 struct client *t_client = NULL; /* tmp ptr to client data */
6371 #if FS_STATS_DETAILED
6372 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6373 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6374 struct timeval elapsedTime; /* Transfer time */
6377 * Set our stats pointer, remember when the RPC operation started, and
6378 * tally the operation.
6381 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6385 TM_GetTimeOfDay(&opStartTime, 0);
6386 #endif /* FS_STATS_DETAILED */
6388 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6389 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
6390 goto Bad_SetVolumeStatus;
6393 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6397 goto Bad_SetVolumeStatus;
6399 dummyFid.Volume = avolid, dummyFid.Vnode =
6400 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6403 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6404 &parentwhentargetnotdir, &client, READ_LOCK,
6405 &rights, &anyrights)))
6406 goto Bad_SetVolumeStatus;
6408 if (readonlyServer) {
6409 errorCode = VREADONLY;
6410 goto Bad_SetVolumeStatus;
6412 if (VanillaUser(client)) {
6414 goto Bad_SetVolumeStatus;
6418 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6420 Bad_SetVolumeStatus:
6421 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6423 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6424 errorCode = CallPostamble(tcon, errorCode);
6426 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6428 #if FS_STATS_DETAILED
6429 TM_GetTimeOfDay(&opStopTime, 0);
6430 if (errorCode == 0) {
6432 (opP->numSuccesses)++;
6433 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6434 fs_stats_AddTo((opP->sumTime), elapsedTime);
6435 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6436 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6437 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6439 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6440 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6444 #endif /* FS_STATS_DETAILED */
6446 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6447 AUD_ID, t_client ? t_client->ViceId : 0,
6448 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6450 } /*SRXAFS_SetVolumeStatus */
6452 #define DEFAULTVOLUME "root.afs"
6455 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6461 struct rx_connection *tcon;
6464 #if FS_STATS_DETAILED
6465 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6466 struct timeval opStartTime; /* Start time for RPC op */
6468 struct timeval opStopTime;
6469 struct timeval elapsedTime; /* Transfer time */
6473 * Set our stats pointer, remember when the RPC operation started, and
6474 * tally the operation.
6476 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6480 TM_GetTimeOfDay(&opStartTime, 0);
6481 #endif /* FS_STATS_DETAILED */
6483 return FSERR_EOPNOTSUPP;
6486 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
6487 goto Bad_GetRootVolume;
6489 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6492 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6494 strcpy(temp, DEFAULTVOLUME);
6496 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6497 lockf(fd, F_LOCK, 0);
6501 len = read(fd, temp, 256);
6502 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6503 lockf(fd, F_ULOCK, 0);
6508 if (temp[len - 1] == '\n')
6512 *VolumeName = temp; /* freed by rx server-side stub */
6515 errorCode = CallPostamble(tcon, errorCode);
6517 #if FS_STATS_DETAILED
6518 TM_GetTimeOfDay(&opStopTime, 0);
6519 if (errorCode == 0) {
6521 (opP->numSuccesses)++;
6522 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6523 fs_stats_AddTo((opP->sumTime), elapsedTime);
6524 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6525 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6526 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6528 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6529 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6533 #endif /* FS_STATS_DETAILED */
6538 } /*SRXAFS_GetRootVolume */
6541 /* still works because a struct CBS is the same as a struct AFSOpaque */
6543 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6544 struct AFSOpaque * Token)
6547 struct rx_connection *tcon;
6548 #if FS_STATS_DETAILED
6549 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6550 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6551 struct timeval elapsedTime; /* Transfer time */
6554 * Set our stats pointer, remember when the RPC operation started, and
6555 * tally the operation.
6557 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6561 TM_GetTimeOfDay(&opStartTime, 0);
6562 #endif /* FS_STATS_DETAILED */
6564 if ((code = CallPreamble(acall, ACTIVECALL, &tcon)))
6565 goto Bad_CheckToken;
6567 code = FSERR_ECONNREFUSED;
6570 code = CallPostamble(tcon, code);
6572 #if FS_STATS_DETAILED
6573 TM_GetTimeOfDay(&opStopTime, 0);
6576 (opP->numSuccesses)++;
6577 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6578 fs_stats_AddTo((opP->sumTime), elapsedTime);
6579 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6580 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6581 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6583 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6584 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6588 #endif /* FS_STATS_DETAILED */
6592 } /*SRXAFS_CheckToken */
6595 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6596 afs_uint32 * USeconds)
6599 struct rx_connection *tcon;
6601 #if FS_STATS_DETAILED
6602 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6603 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6604 struct timeval elapsedTime; /* Transfer time */
6607 * Set our stats pointer, remember when the RPC operation started, and
6608 * tally the operation.
6610 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
6614 TM_GetTimeOfDay(&opStartTime, 0);
6615 #endif /* FS_STATS_DETAILED */
6617 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon)))
6621 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6623 TM_GetTimeOfDay(&tpl, 0);
6624 *Seconds = tpl.tv_sec;
6625 *USeconds = tpl.tv_usec;
6627 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6630 code = CallPostamble(tcon, code);
6632 #if FS_STATS_DETAILED
6633 TM_GetTimeOfDay(&opStopTime, 0);
6634 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6637 (opP->numSuccesses)++;
6638 fs_stats_AddTo((opP->sumTime), elapsedTime);
6639 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6640 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6641 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6643 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6644 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6648 #endif /* FS_STATS_DETAILED */
6652 } /*SRXAFS_GetTime */
6659 * Implement a client's data fetch using Rx.
6662 * volptr : Ptr to the given volume's info.
6663 * targetptr : Pointer to the vnode involved.
6664 * Call : Ptr to the Rx call involved.
6665 * Pos : Offset within the file.
6666 * Len : Length in bytes to read; this value is bogus!
6667 * if FS_STATS_DETAILED
6668 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6670 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6676 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
6677 register struct rx_call * Call, afs_sfsize_t Pos,
6678 afs_sfsize_t Len, afs_int32 Int64Mode,
6679 #if FS_STATS_DETAILED
6680 afs_sfsize_t * a_bytesToFetchP,
6681 afs_sfsize_t * a_bytesFetchedP
6682 #endif /* FS_STATS_DETAILED */
6685 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6686 int errorCode = 0; /* Returned error code to caller */
6690 register char *tbuffer;
6691 #else /* AFS_NT40_ENV */
6692 struct iovec tiov[RX_MAXIOVECS];
6694 #endif /* AFS_NT40_ENV */
6698 #if FS_STATS_DETAILED
6700 * Initialize the byte count arguments.
6702 (*a_bytesToFetchP) = 0;
6703 (*a_bytesFetchedP) = 0;
6704 #endif /* FS_STATS_DETAILED */
6708 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
6709 (afs_uintmax_t) Len));
6711 if (!VN_GET_INO(targetptr)) {
6712 afs_int32 zero = htonl(0);
6714 * This is used for newly created files; we simply send 0 bytes
6715 * back to make the cache manager happy...
6718 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6719 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
6722 TM_GetTimeOfDay(&StartTime, 0);
6723 ihP = targetptr->handle;
6726 VTakeOffline(volptr);
6729 optSize = sendBufSize;
6730 tlen = FDH_SIZE(fdP);
6732 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
6735 VTakeOffline(volptr);
6742 if (Pos + Len > tlen)
6743 Len = tlen - Pos; /* get length we should send */
6744 (void)FDH_SEEK(fdP, Pos, 0);
6746 afs_int32 high, low;
6747 SplitOffsetOrSize(Len, high, low);
6748 assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
6751 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
6754 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
6756 #if FS_STATS_DETAILED
6757 (*a_bytesToFetchP) = Len;
6758 #endif /* FS_STATS_DETAILED */
6760 tbuffer = AllocSendBuffer();
6761 #endif /* AFS_NT40_ENV */
6769 errorCode = FDH_READ(fdP, tbuffer, wlen);
6770 if (errorCode != wlen) {
6772 FreeSendBuffer((struct afs_buffer *)tbuffer);
6773 VTakeOffline(volptr);
6776 errorCode = rx_Write(Call, tbuffer, wlen);
6777 #else /* AFS_NT40_ENV */
6778 errorCode = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
6779 if (errorCode <= 0) {
6781 VTakeOffline(volptr);
6785 errorCode = FDH_READV(fdP, tiov, tnio);
6786 if (errorCode != wlen) {
6788 VTakeOffline(volptr);
6791 errorCode = rx_Writev(Call, tiov, tnio, wlen);
6792 #endif /* AFS_NT40_ENV */
6793 #if FS_STATS_DETAILED
6795 * Bump the number of bytes actually sent by the number from this
6798 (*a_bytesFetchedP) += errorCode;
6799 #endif /* FS_STATS_DETAILED */
6800 if (errorCode != wlen) {
6803 FreeSendBuffer((struct afs_buffer *)tbuffer);
6804 #endif /* AFS_NT40_ENV */
6810 FreeSendBuffer((struct afs_buffer *)tbuffer);
6811 #endif /* AFS_NT40_ENV */
6813 TM_GetTimeOfDay(&StopTime, 0);
6815 /* Adjust all Fetch Data related stats */
6817 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
6818 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
6819 AFSCallStats.AccumFetchTime +=
6820 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
6821 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
6823 afs_fsize_t targLen;
6824 VN_GET_LEN(targLen, targetptr);
6825 AFSCallStats.TotalFetchedBytes += targLen;
6826 AFSCallStats.FetchSize1++;
6827 if (targLen < SIZE2)
6828 AFSCallStats.FetchSize2++;
6829 else if (targLen < SIZE3)
6830 AFSCallStats.FetchSize3++;
6831 else if (targLen < SIZE4)
6832 AFSCallStats.FetchSize4++;
6834 AFSCallStats.FetchSize5++;
6839 } /*FetchData_RXStyle */
6842 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
6843 afs_sfsize_t * size)
6845 #ifdef AFS_NAMEI_ENV
6847 lhp = IH_OPEN(V_linkHandle(vp));
6851 *lc = nt_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
6853 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
6858 *size = OS_SIZE(fdP->fd_fd);
6859 return (*size == -1) ? -1 : 0;
6861 struct afs_stat status;
6863 if (afs_fstat(fdP->fd_fd, &status) < 0) {
6867 *lc = GetLinkCount(vp, &status);
6868 *size = status.st_size;
6877 * Implement a client's data store using Rx.
6880 * volptr : Ptr to the given volume's info.
6881 * targetptr : Pointer to the vnode involved.
6882 * Call : Ptr to the Rx call involved.
6883 * Pos : Offset within the file.
6884 * Len : Length in bytes to store; this value is bogus!
6885 * if FS_STATS_DETAILED
6886 * a_bytesToStoreP : Set to the number of bytes to be stored to
6888 * a_bytesStoredP : Set to the actual number of bytes stored to
6893 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
6894 struct client * client, register struct rx_call * Call,
6895 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
6897 #if FS_STATS_DETAILED
6898 afs_sfsize_t * a_bytesToStoreP,
6899 afs_sfsize_t * a_bytesStoredP
6900 #endif /* FS_STATS_DETAILED */
6903 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
6904 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
6905 int errorCode = 0; /* Returned error code to caller */
6907 register char *tbuffer; /* data copying buffer */
6908 #else /* AFS_NT40_ENV */
6909 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
6910 int tnio; /* temp for iovec size */
6911 #endif /* AFS_NT40_ENV */
6912 afs_sfsize_t tlen; /* temp for xfr length */
6913 Inode tinode; /* inode for I/O */
6914 afs_int32 optSize; /* optimal transfer size */
6915 afs_sfsize_t DataLength; /* size of inode */
6916 afs_sfsize_t TruncatedLength; /* size after ftruncate */
6917 afs_fsize_t NewLength; /* size after this store completes */
6918 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
6919 int linkCount; /* link count on inode */
6921 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
6923 #if FS_STATS_DETAILED
6925 * Initialize the byte count arguments.
6927 (*a_bytesToStoreP) = 0;
6928 (*a_bytesStoredP) = 0;
6929 #endif /* FS_STATS_DETAILED */
6932 * We break the callbacks here so that the following signal will not
6935 BreakCallBack(client->host, Fid, 0);
6937 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
6938 /* the inode should have been created in Alloc_NewVnode */
6939 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
6941 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
6942 Fid->Volume, Fid->Vnode, Fid->Unique,
6943 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
6944 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
6945 return ENOENT; /* is this proper error code? */
6948 * See if the file has several links (from other volumes). If it
6949 * does, then we have to make a copy before changing it to avoid
6950 *changing read-only clones of this dude
6953 ("StoreData_RXStyle : Opening inode %s\n",
6954 PrintInode(NULL, VN_GET_INO(targetptr))));
6955 fdP = IH_OPEN(targetptr->handle);
6958 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
6960 VTakeOffline(volptr);
6964 if (linkCount != 1) {
6967 ("StoreData_RXStyle : inode %s has more than onelink\n",
6968 PrintInode(NULL, VN_GET_INO(targetptr))));
6969 /* other volumes share this data, better copy it first */
6971 /* Adjust the disk block count by the creation of the new inode.
6972 * We call the special VDiskUsage so we don't adjust the volume's
6973 * quota since we don't want to penalyze the user for afs's internal
6974 * mechanisms (i.e. copy on write overhead.) Also the right size
6975 * of the disk will be recorded...
6978 VN_GET_LEN(size, targetptr);
6979 volptr->partition->flags &= ~PART_DONTUPDATE;
6980 VSetPartitionDiskUsage(volptr->partition);
6981 volptr->partition->flags |= PART_DONTUPDATE;
6982 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
6983 volptr->partition->flags &= ~PART_DONTUPDATE;
6987 ViceLog(25, ("StoreData : calling CopyOnWrite on target dir\n"));
6988 if ((errorCode = CopyOnWrite(targetptr, volptr))) {
6989 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
6990 volptr->partition->flags &= ~PART_DONTUPDATE;
6993 volptr->partition->flags &= ~PART_DONTUPDATE;
6994 VSetPartitionDiskUsage(volptr->partition);
6995 fdP = IH_OPEN(targetptr->handle);
6998 ("StoreData : Reopen after CopyOnWrite failed\n"));
7002 tinode = VN_GET_INO(targetptr);
7004 assert(VALID_INO(tinode));
7006 /* compute new file length */
7007 NewLength = DataLength;
7008 if (FileLength < NewLength)
7009 /* simulate truncate */
7010 NewLength = FileLength;
7011 TruncatedLength = NewLength; /* remember length after possible ftruncate */
7012 if (Pos + Length > NewLength)
7013 NewLength = Pos + Length; /* and write */
7015 /* adjust the disk block count by the difference in the files */
7017 afs_fsize_t targSize;
7018 VN_GET_LEN(targSize, targetptr);
7019 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
7022 AdjustDiskUsage(volptr, adjustSize,
7023 adjustSize - SpareComp(volptr)))) {
7028 /* can signal cache manager to proceed from close now */
7029 /* this bit means that the locks are set and protections are OK */
7030 rx_SetLocalStatus(Call, 1);
7032 TM_GetTimeOfDay(&StartTime, 0);
7034 optSize = sendBufSize;
7036 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
7037 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
7038 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
7040 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
7041 if (FileLength < DataLength)
7042 FDH_TRUNC(fdP, FileLength);
7044 FDH_SEEK(fdP, Pos, 0);
7045 bytesTransfered = 0;
7047 tbuffer = AllocSendBuffer();
7048 #endif /* AFS_NT40_ENV */
7049 /* if length == 0, the loop below isn't going to do anything, including
7050 * extend the length of the inode, which it must do, since the file system
7051 * assumes that the inode length == vnode's file length. So, we extend
7052 * the file length manually if need be. Note that if file is bigger than
7053 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7054 * do what we're going to do below.
7056 if (Length == 0 && Pos > TruncatedLength) {
7057 /* Set the file's length; we've already done an lseek to the right
7060 errorCode = FDH_WRITE(fdP, &tlen, 1);
7063 errorCode = FDH_TRUNC(fdP, Pos);
7065 /* have some data to copy */
7066 #if FS_STATS_DETAILED
7067 (*a_bytesToStoreP) = Length;
7068 #endif /* FS_STATS_DETAILED */
7071 if (bytesTransfered >= Length) {
7075 tlen = Length - bytesTransfered; /* how much more to do */
7077 rlen = optSize; /* bound by buffer size */
7081 errorCode = rx_Read(Call, tbuffer, rlen);
7082 #else /* AFS_NT40_ENV */
7083 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7084 #endif /* AFS_NT40_ENV */
7085 #if FS_STATS_DETAILED
7086 (*a_bytesStoredP) += errorCode;
7087 #endif /* FS_STATS_DETAILED */
7088 if (errorCode <= 0) {
7094 errorCode = FDH_WRITE(fdP, tbuffer, rlen);
7095 #else /* AFS_NT40_ENV */
7096 errorCode = FDH_WRITEV(fdP, tiov, tnio);
7097 #endif /* AFS_NT40_ENV */
7098 if (errorCode != rlen) {
7099 errorCode = VDISKFULL;
7102 bytesTransfered += rlen;
7107 FreeSendBuffer((struct afs_buffer *)tbuffer);
7108 #endif /* AFS_NT40_ENV */
7113 afs_fsize_t nfSize = (afs_fsize_t) FDH_SIZE(fdP);
7114 /* something went wrong: adjust size and return */
7115 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7116 /* changed_newTime is tested in StoreData to detemine if we
7117 * need to update the target vnode.
7119 targetptr->changed_newTime = 1;
7121 /* set disk usage to be correct */
7122 VAdjustDiskUsage(&errorCode, volptr,
7123 (afs_sfsize_t) (nBlocks(nfSize) -
7124 nBlocks(NewLength)), 0);
7129 TM_GetTimeOfDay(&StopTime, 0);
7131 VN_SET_LEN(targetptr, NewLength);
7133 /* Update all StoreData related stats */
7135 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7136 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7137 AFSCallStats.StoreSize1++; /* Piggybacked data */
7139 afs_fsize_t targLen;
7140 VN_GET_LEN(targLen, targetptr);
7141 if (targLen < SIZE2)
7142 AFSCallStats.StoreSize2++;
7143 else if (targLen < SIZE3)
7144 AFSCallStats.StoreSize3++;
7145 else if (targLen < SIZE4)
7146 AFSCallStats.StoreSize4++;
7148 AFSCallStats.StoreSize5++;
7153 } /*StoreData_RXStyle */
7155 static int sys2et[512];
7158 init_sys_error_to_et(void)
7160 memset(&sys2et, 0, sizeof(sys2et));
7161 sys2et[EPERM] = UAEPERM;
7162 sys2et[ENOENT] = UAENOENT;
7163 sys2et[ESRCH] = UAESRCH;
7164 sys2et[EINTR] = UAEINTR;
7165 sys2et[EIO] = UAEIO;
7166 sys2et[ENXIO] = UAENXIO;
7167 sys2et[E2BIG] = UAE2BIG;
7168 sys2et[ENOEXEC] = UAENOEXEC;
7169 sys2et[EBADF] = UAEBADF;
7170 sys2et[ECHILD] = UAECHILD;
7171 sys2et[EAGAIN] = UAEAGAIN;
7172 sys2et[ENOMEM] = UAENOMEM;
7173 sys2et[EACCES] = UAEACCES;
7174 sys2et[EFAULT] = UAEFAULT;
7175 sys2et[ENOTBLK] = UAENOTBLK;
7176 sys2et[EBUSY] = UAEBUSY;
7177 sys2et[EEXIST] = UAEEXIST;
7178 sys2et[EXDEV] = UAEXDEV;
7179 sys2et[ENODEV] = UAENODEV;
7180 sys2et[ENOTDIR] = UAENOTDIR;
7181 sys2et[EISDIR] = UAEISDIR;
7182 sys2et[EINVAL] = UAEINVAL;
7183 sys2et[ENFILE] = UAENFILE;
7184 sys2et[EMFILE] = UAEMFILE;
7185 sys2et[ENOTTY] = UAENOTTY;
7186 sys2et[ETXTBSY] = UAETXTBSY;
7187 sys2et[EFBIG] = UAEFBIG;
7188 sys2et[ENOSPC] = UAENOSPC;
7189 sys2et[ESPIPE] = UAESPIPE;
7190 sys2et[EROFS] = UAEROFS;
7191 sys2et[EMLINK] = UAEMLINK;
7192 sys2et[EPIPE] = UAEPIPE;
7193 sys2et[EDOM] = UAEDOM;
7194 sys2et[ERANGE] = UAERANGE;
7195 sys2et[EDEADLK] = UAEDEADLK;
7196 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7197 sys2et[ENOLCK] = UAENOLCK;
7198 sys2et[ENOSYS] = UAENOSYS;
7199 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7200 sys2et[ELOOP] = UAELOOP;
7201 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7202 sys2et[ENOMSG] = UAENOMSG;
7203 sys2et[EIDRM] = UAEIDRM;
7204 sys2et[ECHRNG] = UAECHRNG;
7205 sys2et[EL2NSYNC] = UAEL2NSYNC;
7206 sys2et[EL3HLT] = UAEL3HLT;
7207 sys2et[EL3RST] = UAEL3RST;
7208 sys2et[ELNRNG] = UAELNRNG;
7209 sys2et[EUNATCH] = UAEUNATCH;
7210 sys2et[ENOCSI] = UAENOCSI;
7211 sys2et[EL2HLT] = UAEL2HLT;
7212 sys2et[EBADE] = UAEBADE;
7213 sys2et[EBADR] = UAEBADR;
7214 sys2et[EXFULL] = UAEXFULL;
7215 sys2et[ENOANO] = UAENOANO;
7216 sys2et[EBADRQC] = UAEBADRQC;
7217 sys2et[EBADSLT] = UAEBADSLT;
7218 sys2et[EDEADLK] = UAEDEADLK;
7219 sys2et[EBFONT] = UAEBFONT;
7220 sys2et[ENOSTR] = UAENOSTR;
7221 sys2et[ENODATA] = UAENODATA;
7222 sys2et[ETIME] = UAETIME;
7223 sys2et[ENOSR] = UAENOSR;
7224 sys2et[ENONET] = UAENONET;
7225 sys2et[ENOPKG] = UAENOPKG;
7226 sys2et[EREMOTE] = UAEREMOTE;
7227 sys2et[ENOLINK] = UAENOLINK;
7228 sys2et[EADV] = UAEADV;
7229 sys2et[ESRMNT] = UAESRMNT;
7230 sys2et[ECOMM] = UAECOMM;
7231 sys2et[EPROTO] = UAEPROTO;
7232 sys2et[EMULTIHOP] = UAEMULTIHOP;
7233 sys2et[EDOTDOT] = UAEDOTDOT;
7234 sys2et[EBADMSG] = UAEBADMSG;
7235 sys2et[EOVERFLOW] = UAEOVERFLOW;
7236 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7237 sys2et[EBADFD] = UAEBADFD;
7238 sys2et[EREMCHG] = UAEREMCHG;
7239 sys2et[ELIBACC] = UAELIBACC;
7240 sys2et[ELIBBAD] = UAELIBBAD;
7241 sys2et[ELIBSCN] = UAELIBSCN;
7242 sys2et[ELIBMAX] = UAELIBMAX;
7243 sys2et[ELIBEXEC] = UAELIBEXEC;
7244 sys2et[EILSEQ] = UAEILSEQ;
7245 sys2et[ERESTART] = UAERESTART;
7246 sys2et[ESTRPIPE] = UAESTRPIPE;
7247 sys2et[EUSERS] = UAEUSERS;
7248 sys2et[ENOTSOCK] = UAENOTSOCK;
7249 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7250 sys2et[EMSGSIZE] = UAEMSGSIZE;
7251 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7252 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7253 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7254 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7255 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7256 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7257 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7258 sys2et[EADDRINUSE] = UAEADDRINUSE;
7259 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7260 sys2et[ENETDOWN] = UAENETDOWN;
7261 sys2et[ENETUNREACH] = UAENETUNREACH;
7262 sys2et[ENETRESET] = UAENETRESET;
7263 sys2et[ECONNABORTED] = UAECONNABORTED;
7264 sys2et[ECONNRESET] = UAECONNRESET;
7265 sys2et[ENOBUFS] = UAENOBUFS;
7266 sys2et[EISCONN] = UAEISCONN;
7267 sys2et[ENOTCONN] = UAENOTCONN;
7268 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7269 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7270 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7271 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7272 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7273 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7274 sys2et[EALREADY] = UAEALREADY;
7275 sys2et[EINPROGRESS] = UAEINPROGRESS;
7276 sys2et[ESTALE] = UAESTALE;
7277 sys2et[EUCLEAN] = UAEUCLEAN;
7278 sys2et[ENOTNAM] = UAENOTNAM;
7279 sys2et[ENAVAIL] = UAENAVAIL;
7280 sys2et[EISNAM] = UAEISNAM;
7281 sys2et[EREMOTEIO] = UAEREMOTEIO;
7282 sys2et[EDQUOT] = UAEDQUOT;
7283 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7284 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7288 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7290 Error errorCode = 0;
7291 struct rx_connection *tcon;
7292 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7294 struct client *tclient;
7295 static struct rx_securityClass *sc = 0;
7297 struct rx_connection *conn;
7300 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon))
7301 goto Bad_CallBackRxConnAddr1;
7303 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7307 tclient = h_FindClient_r(tcon);
7308 thost = tclient->host;
7310 /* nothing more can be done */
7311 if ( !thost->interface )
7312 goto Bad_CallBackRxConnAddr;
7314 assert(thost->interface->numberOfInterfaces > 0 );
7316 /* the only address is the primary interface */
7317 /* can't change when there's only 1 address, anyway */
7318 if ( thost->interface->numberOfInterfaces == 1 )
7319 goto Bad_CallBackRxConnAddr;
7321 /* initialise a security object only once */
7323 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7325 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7327 if ( *addr == thost->interface->addr[i] ) {
7332 if ( *addr != thost->interface->addr[i] )
7333 goto Bad_CallBackRxConnAddr;
7335 conn = rx_NewConnection (thost->interface->addr[i],
7336 thost->port, 1, sc, 0);
7337 rx_SetConnDeadTime(conn, 2);
7338 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7340 errorCode = RXAFSCB_Probe(conn);
7343 if ( thost->callback_rxcon )
7344 rx_DestroyConnection(thost->callback_rxcon);
7345 thost->callback_rxcon = conn;
7347 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7348 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7349 h_ReleaseClient_r(tclient);
7350 /* The hold on thost will be released by CallPostamble */
7352 errorCode = CallPostamble(tcon, errorCode);
7355 rx_DestroyConnection(conn);
7357 Bad_CallBackRxConnAddr:
7358 h_ReleaseClient_r(tclient);
7359 /* The hold on thost will be released by CallPostamble */
7363 errorCode = CallPostamble(tcon, errorCode);
7364 Bad_CallBackRxConnAddr1:
7365 return errorCode; /* failure */
7369 sys_error_to_et(afs_int32 in)
7373 if (in < 0 || in > 511)
7375 if (in >= VICE_SPECIAL_ERRORS && in <= VIO || in == VRESTRICTED)
7377 if (sys2et[in] != 0)