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>
36 #undef SHARED /* XXX */
41 #include <sys/param.h>
43 #include <sys/ioctl.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
50 #ifndef AFS_LINUX20_ENV
52 #include <netinet/if_ether.h>
56 /* included early because of name conflict on IOPEN */
57 #include <sys/inode.h>
61 #endif /* AFS_HPUX_ENV */
65 #include <afs/assert.h>
68 #include <afs/afsint.h>
69 #include <afs/vldbint.h>
70 #include <afs/errors.h>
71 #include <afs/ihandle.h>
72 #include <afs/vnode.h>
73 #include <afs/volume.h>
74 #include <afs/ptclient.h>
75 #include <afs/ptuser.h>
76 #include <afs/prs_fs.h>
79 #include <rx/rx_globals.h>
81 #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)
84 #if !defined(AFS_NT40_ENV)
87 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
89 #include <sys/statfs.h>
90 #include <sys/lockf.h>
92 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
97 #include <afs/cellconfig.h>
101 #include <afs/partition.h>
102 #include "viced_prototypes.h"
105 #include "callback.h"
106 #include <afs/unified_afs.h>
107 #include <afs/audit.h>
108 #include <afs/afsutil.h>
111 extern void SetDirHandle(register DirHandle * dir, register Vnode * vnode);
112 extern void FidZap(DirHandle * file);
113 extern void FidZero(DirHandle * file);
115 #ifdef AFS_PTHREAD_ENV
116 pthread_mutex_t fileproc_glock_mutex;
117 #endif /* AFS_PTHREAD_ENV */
120 #define afs_stat stat64
121 #define afs_fstat fstat64
122 #define afs_open open64
123 #else /* !O_LARGEFILE */
124 #define afs_stat stat
125 #define afs_fstat fstat
126 #define afs_open open
127 #endif /* !O_LARGEFILE */
130 /* Useful local defines used by this module */
133 #define MustNOTBeDIR 1
137 #define TVS_SSTATUS 2
140 #define TVS_MKDIR 0x10
142 #define CHK_FETCH 0x10
143 #define CHK_FETCHDATA 0x10
144 #define CHK_FETCHACL 0x11
145 #define CHK_FETCHSTATUS 0x12
146 #define CHK_STOREDATA 0x00
147 #define CHK_STOREACL 0x01
148 #define CHK_STORESTATUS 0x02
150 #define OWNERREAD 0400
151 #define OWNERWRITE 0200
152 #define OWNEREXEC 0100
153 #ifdef USE_GROUP_PERMS
154 #define GROUPREAD 0040
155 #define GROUPWRITE 0020
156 #define GROUPREXEC 0010
159 /* The following errors were not defined in NT. They are given unique
160 * names here to avoid any potential collision.
162 #define FSERR_ELOOP 90
163 #define FSERR_EOPNOTSUPP 122
164 #define FSERR_ECONNREFUSED 130
166 #define NOTACTIVECALL 0
169 #define CREATE_SGUID_ADMIN_ONLY 1
171 extern struct afsconf_dir *confDir;
172 extern afs_int32 dataVersionHigh;
175 static struct AFSCallStatistics AFSCallStats;
176 #if FS_STATS_DETAILED
177 struct fs_stats_FullPerfStats afs_FullPerfStats;
178 extern int AnonymousID;
179 #endif /* FS_STATS_DETAILED */
180 #if OPENAFS_VOL_STATS
181 static const char nullString[] = "";
182 #endif /* OPENAFS_VOL_STATS */
185 afs_int32 NothingYet;
188 struct afs_FSStats afs_fsstats;
193 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
195 extern afs_int32 implicitAdminRights;
196 extern afs_int32 readonlyServer;
197 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
198 extern afs_fsize_t CopyOnWrite_maxsize;
201 * Externals used by the xstat code.
203 extern VolPkgStats VStats;
204 extern int CEs, CEBlocks;
206 extern int HTs, HTBlocks;
208 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
209 register struct rx_call *Call, afs_sfsize_t Pos,
210 afs_sfsize_t Len, afs_int32 Int64Mode,
211 #if FS_STATS_DETAILED
212 afs_sfsize_t * a_bytesToFetchP,
213 afs_sfsize_t * a_bytesFetchedP
214 #endif /* FS_STATS_DETAILED */
217 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
218 struct AFSFid *Fid, struct client *client,
219 register struct rx_call *Call, afs_fsize_t Pos,
220 afs_fsize_t Length, afs_fsize_t FileLength,
222 #if FS_STATS_DETAILED
223 afs_sfsize_t * a_bytesToStoreP,
224 afs_sfsize_t * a_bytesStoredP
225 #endif /* FS_STATS_DETAILED */
228 #ifdef AFS_SGI_XFS_IOPS_ENV
229 #include <afs/xfsattrs.h>
231 GetLinkCount(Volume * avp, struct stat *astat)
233 if (!strcmp("xfs", astat->st_fstype)) {
234 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
236 return astat->st_nlink;
239 #define GetLinkCount(V, S) (S)->st_nlink
243 SpareComp(Volume * avolp)
245 register afs_int32 temp;
249 temp = V_maxquota(avolp);
251 /* no matter; doesn't check in this case */
255 temp = (temp * PctSpare) / 100;
266 * Set the volume synchronization parameter for this volume. If it changes,
267 * the Cache Manager knows that the volume must be purged from the stat cache.
270 SetVolumeSync(register struct AFSVolSync *async, register Volume * avol)
273 /* date volume instance was created */
276 async->spare1 = avol->header->diskstuff.creationDate;
289 * Note that this function always returns a held host, so
290 * that CallPostamble can block without the host's disappearing.
291 * Call returns rx connection in passed in *tconn
294 CallPreamble(register struct rx_call *acall, int activecall,
295 struct rx_connection **tconn, struct host **ahostp)
298 struct client *tclient;
301 char hoststr[16], hoststr2[16];
302 #ifdef AFS_PTHREAD_ENV
303 struct ubik_client *uclient;
308 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
311 *tconn = rx_ConnectionOf(acall);
315 tclient = h_FindClient_r(*tconn);
317 ViceLog(0, ("CallPreamble: Couldn't get CPS. Too many lockers\n"));
321 thost = tclient->host;
322 if (tclient->prfail == 1) { /* couldn't get the CPS */
324 h_ReleaseClient_r(tclient);
326 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
330 retry_flag = 0; /* Retry once */
332 /* Take down the old connection and re-read the key file */
334 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
335 #ifdef AFS_PTHREAD_ENV
336 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
338 /* Is it still necessary to drop this? We hit the net, we should... */
344 code = hpr_Initialize(&uclient);
347 assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
350 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
353 h_ReleaseClient_r(tclient);
356 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
360 tclient->prfail = 2; /* Means re-eval client's cps */
361 h_ReleaseClient_r(tclient);
366 tclient->LastCall = thost->LastCall = FT_ApproxTime();
367 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
368 thost->ActiveCall = thost->LastCall;
371 if (thost->hostFlags & HOSTDELETED) {
373 ("Discarded a packet for deleted host %s:%d\n",
374 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
375 code = VBUSY; /* raced, so retry */
376 } else if ((thost->hostFlags & VENUSDOWN)
377 || (thost->hostFlags & HFE_LATER)) {
378 if (BreakDelayedCallBacks_r(thost)) {
380 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
381 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
382 ntohs(rxr_PortOf(*tconn))));
383 if (MultiProbeAlternateAddress_r(thost)) {
385 ("MultiProbe failed to find new address for host %s:%d\n",
386 afs_inet_ntoa_r(thost->host, hoststr),
387 ntohs(thost->port)));
391 ("MultiProbe found new address for host %s:%d\n",
392 afs_inet_ntoa_r(thost->host, hoststr),
393 ntohs(thost->port)));
394 if (BreakDelayedCallBacks_r(thost)) {
396 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
397 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
398 ntohs(rxr_PortOf(*tconn))));
407 h_ReleaseClient_r(tclient);
417 CallPostamble(register struct rx_connection *aconn, afs_int32 ret,
421 struct client *tclient;
426 tclient = h_FindClient_r(aconn);
429 thost = tclient->host;
430 if (thost->hostFlags & HERRORTRANS)
432 h_ReleaseClient_r(tclient);
433 held = h_Held_r(thost);
436 if (ahost && ahost != thost) {
437 char hoststr[16], hoststr2[16];
438 ViceLog(0, ("CallPostamble: ahost %s:%d (%x) != thost %s:%d (%x)\n",
439 afs_inet_ntoa_r(ahost->host, hoststr), ntohs(ahost->port),
441 afs_inet_ntoa_r(thost->host, hoststr2), ntohs(thost->port),
446 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%x)\n",
447 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port),
452 return (translate ? sys_error_to_et(ret) : ret);
456 * Returns the volume and vnode pointers associated with file Fid; the lock
457 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
458 * are incremented and they must be eventualy released.
461 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
464 Error local_errorCode, errorCode = -1;
465 static struct timeval restartedat = { 0, 0 };
467 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
469 if ((*volptr) == 0) {
474 #ifdef AFS_DEMAND_ATTACH_FS
482 *volptr = VGetVolume(&local_errorCode, &errorCode, (afs_int32) fid->Volume);
487 if ((errorCode == VOFFLINE) && (VInit < 2)) {
488 /* The volume we want may not be attached yet because
489 * the volume initialization is not yet complete.
490 * We can do several things:
491 * 1. return -1, which will cause users to see
492 * "connection timed out". This is more or
493 * less the same as always, except that the servers
494 * may appear to bounce up and down while they
495 * are actually restarting.
496 * 2. return VBUSY which will cause clients to
497 * sleep and retry for 6.5 - 15 minutes, depending
498 * on what version of the CM they are running. If
499 * the file server takes longer than that interval
500 * to attach the desired volume, then the application
501 * will see an ENODEV or EIO. This approach has
502 * the advantage that volumes which have been attached
503 * are immediately available, it keeps the server's
504 * immediate backlog low, and the call is interruptible
505 * by the user. Users see "waiting for busy volume."
506 * 3. sleep here and retry. Some people like this approach
507 * because there is no danger of seeing errors. However,
508 * this approach only works with a bounded number of
509 * clients, since the pending queues will grow without
510 * stopping. It might be better to find a way to take
511 * this call and stick it back on a queue in order to
512 * recycle this thread for a different request.
513 * 4. Return a new error code, which new cache managers will
514 * know enough to interpret as "sleep and retry", without
515 * the upper bound of 6-15 minutes that is imposed by the
516 * VBUSY handling. Users will see "waiting for
517 * busy volume," so they know that something is
518 * happening. Old cache managers must be able to do
519 * something reasonable with this, for instance, mark the
520 * server down. Fortunately, any error code < 0
521 * will elicit that behavior. See #1.
522 * 5. Some combination of the above. I like doing #2 for 10
523 * minutes, followed by #4. 3.1b and 3.2 cache managers
524 * will be fine as long as the restart period is
525 * not longer than 6.5 minutes, otherwise they may
526 * return ENODEV to users. 3.3 cache managers will be
527 * fine for 10 minutes, then will return
528 * ETIMEDOUT. 3.4 cache managers will just wait
529 * until the call works or fails definitively.
530 * NB. The problem with 2,3,4,5 is that old clients won't
531 * fail over to an alternate read-only replica while this
532 * server is restarting. 3.4 clients will fail over right away.
534 if (restartedat.tv_sec == 0) {
535 /* I'm not really worried about when we restarted, I'm */
536 /* just worried about when the first VBUSY was returned. */
537 FT_GetTimeOfDay(&restartedat, 0);
540 afs_perfstats.fs_nBusies++;
543 return (busyonrst ? VBUSY : restarting);
546 FT_GetTimeOfDay(&now, 0);
547 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
550 afs_perfstats.fs_nBusies++;
553 return (busyonrst ? VBUSY : restarting);
559 /* allow read operations on busy volume.
560 * must check local_errorCode because demand attach fs
561 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
562 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
563 #ifdef AFS_DEMAND_ATTACH_FS
564 /* DAFS case is complicated by the fact that local_errorCode can
565 * be VBUSY in cases where the volume is truly offline */
567 /* volume is in VOL_STATE_UNATTACHED */
570 #endif /* AFS_DEMAND_ATTACH_FS */
573 } else if (errorCode)
580 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
583 if ((*vptr)->disk.uniquifier != fid->Unique) {
584 VPutVnode(&fileCode, *vptr);
585 assert(fileCode == 0);
587 return (VNOVNODE); /* return the right error code, at least */
593 * This routine returns the ACL associated with the targetptr. If the
594 * targetptr isn't a directory, we access its parent dir and get the ACL
595 * thru the parent; in such case the parent's vnode is returned in
599 SetAccessList(Vnode ** targetptr, Volume ** volume,
600 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
601 AFSFid * Fid, int Lock)
603 if ((*targetptr)->disk.type == vDirectory) {
605 *ACL = VVnodeACL(*targetptr);
606 *ACLSize = VAclSize(*targetptr);
614 parentvnode = (*targetptr)->disk.parent;
615 VPutVnode(&errorCode, *targetptr);
619 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
622 *ACL = VVnodeACL(*parent);
623 *ACLSize = VAclSize(*parent);
624 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
626 if ((*targetptr)->disk.parent != parentvnode) {
627 VPutVnode(&errorCode, *parent);
638 /* Must not be called with H_LOCK held */
640 client_CheckRights(struct client *client, struct acl_accessList *ACL,
644 ObtainReadLock(&client->lock);
645 if (client->CPS.prlist_len > 0 && !client->deleted &&
646 client->host && !(client->host->hostFlags & HOSTDELETED))
647 acl_CheckRights(ACL, &client->CPS, rights);
648 ReleaseReadLock(&client->lock);
651 /* Must not be called with H_LOCK held */
653 client_HasAsMember(struct client *client, afs_int32 id)
657 ObtainReadLock(&client->lock);
658 if (client->CPS.prlist_len > 0 && !client->deleted &&
659 client->host && !(client->host->hostFlags & HOSTDELETED))
660 code = acl_IsAMember(id, &client->CPS);
661 ReleaseReadLock(&client->lock);
666 * Compare the directory's ACL with the user's access rights in the client
667 * connection and return the user's and everybody else's access permissions
668 * in rights and anyrights, respectively
671 GetRights(struct client *client, struct acl_accessList *ACL,
672 afs_int32 * rights, afs_int32 * anyrights)
674 extern prlist SystemAnyUserCPS;
675 afs_int32 hrights = 0;
676 #ifndef AFS_PTHREAD_ENV
680 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
681 ViceLog(0, ("CheckRights failed\n"));
686 client_CheckRights(client, ACL, rights);
688 /* wait if somebody else is already doing the getCPS call */
690 while (client->host->hostFlags & HCPS_INPROGRESS) {
691 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
692 #ifdef AFS_PTHREAD_ENV
693 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
694 #else /* AFS_PTHREAD_ENV */
696 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
697 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
698 #endif /* AFS_PTHREAD_ENV */
701 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
704 ("CheckRights: len=%u, for host=%s:%d\n",
705 client->host->hcps.prlist_len,
706 afs_inet_ntoa_r(client->host->host, hoststr),
707 ntohs(client->host->port)));
709 acl_CheckRights(ACL, &client->host->hcps, &hrights);
711 /* Allow system:admin the rights given with the -implicit option */
712 if (client_HasAsMember(client, SystemId))
713 *rights |= implicitAdminRights;
716 *anyrights |= hrights;
723 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
724 * a System:Administrator)
727 VanillaUser(struct client *client)
729 if (client_HasAsMember(client, SystemId))
730 return (0); /* not a system administrator, then you're "vanilla" */
737 * This unusual afs_int32-parameter routine encapsulates all volume package related
738 * operations together in a single function; it's called by almost all AFS
742 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
743 Vnode ** targetptr, int chkforDir, Vnode ** parent,
744 struct client **client, int locktype, afs_int32 * rights,
745 afs_int32 * anyrights)
747 struct acl_accessList *aCL; /* Internal access List */
748 int aCLSize; /* size of the access list */
749 Error errorCode = 0; /* return code to caller */
751 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
754 if (chkforDir == MustNOTBeDIR
755 && ((*targetptr)->disk.type == vDirectory))
757 else if (chkforDir == MustBeDIR
758 && ((*targetptr)->disk.type != vDirectory))
762 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
763 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
764 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
766 if (chkforDir == MustBeDIR)
767 assert((*parent) == 0);
769 if ((errorCode = GetClient(tcon, client)) != 0)
774 GetRights(*client, aCL, rights, anyrights);
775 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
776 if ((*targetptr)->disk.type != vDirectory) {
777 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
778 if ((*targetptr)->disk.owner == (*client)->ViceId)
779 (*rights) |= PRSFS_ADMINISTER;
781 (*rights) &= ~PRSFS_ADMINISTER;
783 #ifdef ADMIN_IMPLICIT_LOOKUP
784 /* admins get automatic lookup on everything */
785 if (!VanillaUser(*client))
786 (*rights) |= PRSFS_LOOKUP;
787 #endif /* ADMIN_IMPLICIT_LOOKUP */
790 } /*GetVolumePackage */
794 * This is the opposite of GetVolumePackage(), and is always used at the end of
795 * AFS calls to put back all used vnodes and the volume in the proper order!
798 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
799 Vnode * parentptr, Volume * volptr, struct client **client)
801 Error fileCode = 0; /* Error code returned by the volume package */
803 if (parentwhentargetnotdir) {
804 VPutVnode(&fileCode, parentwhentargetnotdir);
805 assert(!fileCode || (fileCode == VSALVAGE));
808 VPutVnode(&fileCode, targetptr);
809 assert(!fileCode || (fileCode == VSALVAGE));
812 VPutVnode(&fileCode, parentptr);
813 assert(!fileCode || (fileCode == VSALVAGE));
821 } /*PutVolumePackage */
824 VolumeOwner(register struct client *client, register Vnode * targetptr)
826 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
829 return (client->ViceId == owner);
832 * We don't have to check for host's cps since only regular
833 * viceid are volume owners.
835 return (client_HasAsMember(client, owner));
841 VolumeRootVnode(Vnode * targetptr)
843 return ((targetptr->vnodeNumber == ROOTVNODE)
844 && (targetptr->disk.uniquifier == 1));
846 } /*VolumeRootVnode */
849 * Check if target file has the proper access permissions for the Fetch
850 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
851 * StoreStatus) related calls
853 /* this code should probably just set a "priv" flag where all the audit events
854 * are now, and only generate the audit event once at the end of the routine,
855 * thus only generating the event if all the checks succeed, but only because
856 * of the privilege XXX
859 Check_PermissionRights(Vnode * targetptr, struct client *client,
860 afs_int32 rights, int CallingRoutine,
861 AFSStoreStatus * InStatus)
864 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
865 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
866 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
868 if (CallingRoutine & CHK_FETCH) {
869 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
870 if (targetptr->disk.type == vDirectory
871 || targetptr->disk.type == vSymlink) {
872 if (!(rights & PRSFS_LOOKUP)
873 #ifdef ADMIN_IMPLICIT_LOOKUP
874 /* grant admins fetch on all directories */
875 && VanillaUser(client)
876 #endif /* ADMIN_IMPLICIT_LOOKUP */
877 && !VolumeOwner(client, targetptr))
880 /* must have read access, or be owner and have insert access */
881 if (!(rights & PRSFS_READ)
882 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
885 if (CallingRoutine == CHK_FETCHDATA
886 && targetptr->disk.type == vFile)
887 #ifdef USE_GROUP_PERMS
888 if (!OWNSp(client, targetptr)
889 && !client_HasAsMember(client, targetptr->disk.owner)) {
891 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
895 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
900 * The check with the ownership below is a kludge to allow
901 * reading of files created with no read permission. The owner
902 * of the file is always allowed to read it.
904 if ((client->ViceId != targetptr->disk.owner)
905 && VanillaUser(client))
907 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
908 modeBits) ? 0 : EACCES);
910 } else { /* !VanillaUser(client) && !FetchData */
912 osi_audit(PrivilegeEvent, 0, AUD_ID,
913 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
916 } else { /* a store operation */
917 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
918 && (CallingRoutine != CHK_STOREACL)
919 && (targetptr->disk.type == vFile)) {
920 /* bypass protection checks on first store after a create
921 * for the creator; also prevent chowns during this time
922 * unless you are a system administrator */
923 /****** InStatus->Owner && UnixModeBits better be SET!! */
924 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
927 else if (VanillaUser(client))
928 return (EPERM); /* Was EACCES */
930 osi_audit(PrivilegeEvent, 0, AUD_ID,
931 (client ? client->ViceId : 0), AUD_INT,
932 CallingRoutine, AUD_END);
935 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
936 osi_audit(PrivilegeEvent, 0, AUD_ID,
937 (client ? client->ViceId : 0), AUD_INT,
938 CallingRoutine, AUD_END);
940 if (readonlyServer) {
943 if (CallingRoutine == CHK_STOREACL) {
944 if (!(rights & PRSFS_ADMINISTER)
945 && !VolumeOwner(client, targetptr))
947 } else { /* store data or status */
948 /* watch for chowns and chgrps */
949 if (CHOWN(InStatus, targetptr)
950 || CHGRP(InStatus, targetptr)) {
953 else if (VanillaUser(client))
954 return (EPERM); /* Was EACCES */
956 osi_audit(PrivilegeEvent, 0, AUD_ID,
957 (client ? client->ViceId : 0), AUD_INT,
958 CallingRoutine, AUD_END);
960 /* must be sysadmin to set suid/sgid bits */
961 if ((InStatus->Mask & AFS_SETMODE) &&
963 (InStatus->UnixModeBits & 0xc00) != 0) {
965 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
969 if (VanillaUser(client))
972 osi_audit(PrivSetID, 0, AUD_ID,
973 (client ? client->ViceId : 0), AUD_INT,
974 CallingRoutine, AUD_END);
976 if (CallingRoutine == CHK_STOREDATA) {
979 if (!(rights & PRSFS_WRITE))
981 /* Next thing is tricky. We want to prevent people
982 * from writing files sans 0200 bit, but we want
983 * creating new files with 0444 mode to work. We
984 * don't check the 0200 bit in the "you are the owner"
985 * path above, but here we check the bit. However, if
986 * you're a system administrator, we ignore the 0200
987 * bit anyway, since you may have fchowned the file,
989 #ifdef USE_GROUP_PERMS
990 if ((targetptr->disk.type == vFile)
991 && VanillaUser(client)) {
992 if (!OWNSp(client, targetptr)
993 && !client_HasAsMember(client, targetptr->disk.owner)) {
995 ((GROUPWRITE & targetptr->disk.modeBits)
999 ((OWNERWRITE & targetptr->disk.modeBits)
1004 if ((targetptr->disk.type != vDirectory)
1005 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1008 if (VanillaUser(client))
1011 osi_audit(PrivilegeEvent, 0, AUD_ID,
1012 (client ? client->ViceId : 0),
1013 AUD_INT, CallingRoutine, AUD_END);
1015 } else { /* a status store */
1018 if (targetptr->disk.type == vDirectory) {
1019 if (!(rights & PRSFS_DELETE)
1020 && !(rights & PRSFS_INSERT))
1022 } else { /* a file or symlink */
1023 if (!(rights & PRSFS_WRITE))
1033 } /*Check_PermissionRights */
1037 * The Access List information is converted from its internal form in the
1038 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1039 * external form and returned back to the caller, via the AccessList
1043 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1044 struct AFSOpaque *AccessList)
1046 char *eACL; /* External access list placeholder */
1049 ((targetptr->disk.type ==
1050 vDirectory ? VVnodeACL(targetptr) :
1051 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1054 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1055 acl_FreeExternalACL(&eACL);
1058 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1059 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1061 acl_FreeExternalACL(&eACL);
1064 } /*RXFetch_AccessList */
1068 * The Access List information is converted from its external form in the
1069 * input AccessList structure to the internal representation and copied into
1070 * the target dir's vnode storage.
1073 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1075 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1077 if (acl_Internalize(AccessList->AFSOpaque_val, &newACL) != 0)
1079 if ((newACL->size + 4) > VAclSize(targetptr))
1081 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1082 acl_FreeACL(&newACL);
1085 } /*RXStore_AccessList */
1088 /* In our current implementation, each successive data store (new file
1089 * data version) creates a new inode. This function creates the new
1090 * inode, copies the old inode's contents to the new one, remove the old
1091 * inode (i.e. decrement inode count -- if it's currently used the delete
1092 * will be delayed), and modify some fields (i.e. vnode's
1093 * disk.inodeNumber and cloned)
1095 #define COPYBUFFSIZE 8192
1096 #define MAXFSIZE (~(afs_fsize_t) 0)
1098 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_fsize_t off, afs_fsize_t len)
1100 Inode ino, nearInode;
1103 register afs_fsize_t size;
1104 register int length;
1106 int rc; /* return code */
1107 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1108 FdHandle_t *targFdP; /* Source Inode file handle */
1109 FdHandle_t *newFdP; /* Dest Inode file handle */
1111 if (targetptr->disk.type == vDirectory)
1112 DFlush(); /* just in case? */
1114 VN_GET_LEN(size, targetptr);
1122 buff = (char *)malloc(COPYBUFFSIZE);
1127 ino = VN_GET_INO(targetptr);
1128 if (!VALID_INO(ino)) {
1130 VTakeOffline(volptr);
1131 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1135 targFdP = IH_OPEN(targetptr->handle);
1136 if (targFdP == NULL) {
1139 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1140 targetptr->vnodeNumber, V_id(volptr), rc));
1142 VTakeOffline(volptr);
1146 nearInode = VN_GET_INO(targetptr);
1148 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1149 VPartitionPath(V_partition(volptr)), nearInode,
1150 V_id(volptr), targetptr->vnodeNumber,
1151 targetptr->disk.uniquifier,
1152 (int)targetptr->disk.dataVersion);
1153 if (!VALID_INO(ino)) {
1155 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1156 volptr->partition->name, V_id(volptr), errno));
1161 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1162 newFdP = IH_OPEN(newH);
1163 assert(newFdP != NULL);
1165 FDH_SEEK(targFdP, off, SEEK_SET);
1166 FDH_SEEK(newFdP, off, SEEK_SET);
1168 if (size > COPYBUFFSIZE) { /* more than a buffer */
1169 length = COPYBUFFSIZE;
1170 size -= COPYBUFFSIZE;
1175 rdlen = FDH_READ(targFdP, buff, length);
1176 if (rdlen == length)
1177 wrlen = FDH_WRITE(newFdP, buff, length);
1180 /* Callers of this function are not prepared to recover
1181 * from error that put the filesystem in an inconsistent
1182 * state. Make sure that we force the volume off-line if
1183 * we some error other than ENOSPC - 4.29.99)
1185 * In case we are unable to write the required bytes, and the
1186 * error code indicates that the disk is full, we roll-back to
1187 * the initial state.
1189 if ((rdlen != length) || (wrlen != length)) {
1190 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1192 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1193 volptr->partition->name, V_id(volptr)));
1194 /* remove destination inode which was partially copied till now */
1195 FDH_REALLYCLOSE(newFdP);
1197 FDH_REALLYCLOSE(targFdP);
1198 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1201 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1202 rc, V_id(volptr), volptr->partition->name));
1203 VTakeOffline(volptr);
1209 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1210 V_id(volptr), volptr->partition->name, length, rdlen,
1212 #if defined(AFS_DEMAND_ATTACH_FS)
1213 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1215 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1217 /* Decrement this inode so salvager doesn't find it. */
1218 FDH_REALLYCLOSE(newFdP);
1220 FDH_REALLYCLOSE(targFdP);
1221 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1223 VTakeOffline(volptr);
1227 #ifndef AFS_PTHREAD_ENV
1229 #endif /* !AFS_PTHREAD_ENV */
1231 FDH_REALLYCLOSE(targFdP);
1232 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1233 V_parentId(volptr));
1235 IH_RELEASE(targetptr->handle);
1237 rc = FDH_SYNC(newFdP);
1240 targetptr->handle = newH;
1241 VN_SET_INO(targetptr, ino);
1242 targetptr->disk.cloned = 0;
1243 /* Internal change to vnode, no user level change to volume - def 5445 */
1244 targetptr->changed_oldTime = 1;
1246 return 0; /* success */
1250 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_fsize_t off, afs_fsize_t size) {
1251 char *buff = (char *)malloc(COPYBUFFSIZE);
1252 register int length;
1257 FDH_SEEK(targFdP, off, SEEK_SET);
1258 FDH_SEEK(newFdP, off, SEEK_SET);
1260 if (size > FDH_SIZE(targFdP) - off) size = FDH_SIZE(targFdP) - off;
1262 if (size > COPYBUFFSIZE) { /* more than a buffer */
1263 length = COPYBUFFSIZE;
1264 size -= COPYBUFFSIZE;
1269 rdlen = FDH_READ(targFdP, buff, length);
1270 if (rdlen == length)
1271 wrlen = FDH_WRITE(newFdP, buff, length);
1275 if ((rdlen != length) || (wrlen != length)) {
1276 /* no error recovery, at the worst we'll have a "hole" in the file */
1287 * Common code to handle with removing the Name (file when it's called from
1288 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1289 * given directory, parentptr.
1291 int DT1 = 0, DT0 = 0;
1293 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1294 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1296 DirHandle childdir; /* Handle for dir package I/O */
1297 Error errorCode = 0;
1300 /* watch for invalid names */
1301 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1303 if (parentptr->disk.cloned) {
1304 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1305 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1307 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1313 /* check that the file is in the directory */
1314 SetDirHandle(dir, parentptr);
1315 if (Lookup(dir, Name, fileFid))
1317 fileFid->Volume = V_id(volptr);
1319 /* just-in-case check for something causing deadlock */
1320 if (fileFid->Vnode == parentptr->vnodeNumber)
1323 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1327 if (ChkForDir == MustBeDIR) {
1328 if ((*targetptr)->disk.type != vDirectory)
1330 } else if ((*targetptr)->disk.type == vDirectory)
1333 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1335 * If the uniquifiers dont match then instead of asserting
1336 * take the volume offline and return VSALVAGE
1338 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1339 VTakeOffline(volptr);
1341 ("Volume %u now offline, must be salvaged.\n",
1343 errorCode = VSALVAGE;
1347 if (ChkForDir == MustBeDIR) {
1348 SetDirHandle(&childdir, *targetptr);
1349 if (IsEmpty(&childdir) != 0)
1353 (*targetptr)->delete = 1;
1354 } else if ((--(*targetptr)->disk.linkCount) == 0)
1355 (*targetptr)->delete = 1;
1356 if ((*targetptr)->delete) {
1357 if (VN_GET_INO(*targetptr)) {
1359 IH_REALLYCLOSE((*targetptr)->handle);
1361 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1362 V_parentId(volptr));
1363 IH_RELEASE((*targetptr)->handle);
1364 if (errorCode == -1) {
1366 ("DT: inode=%s, name=%s, errno=%d\n",
1367 PrintInode(NULL, VN_GET_INO(*targetptr)), Name,
1369 if (errno != ENOENT)
1371 VTakeOffline(volptr);
1373 ("Volume %u now offline, must be salvaged.\n",
1381 VN_SET_INO(*targetptr, (Inode) 0);
1383 afs_fsize_t adjLength;
1384 VN_GET_LEN(adjLength, *targetptr);
1385 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1389 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1391 code = Delete(dir, (char *)Name);
1394 ("Error %d deleting %s\n", code,
1395 (((*targetptr)->disk.type ==
1396 Directory) ? "directory" : "file")));
1397 VTakeOffline(volptr);
1399 ("Volume %u now offline, must be salvaged.\n",
1412 * This routine updates the parent directory's status block after the
1413 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1414 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1418 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1419 int author, int linkcount,
1420 #if FS_STATS_DETAILED
1421 char a_inSameNetwork
1422 #endif /* FS_STATS_DETAILED */
1425 afs_fsize_t newlength; /* Holds new directory length */
1426 afs_fsize_t parentLength;
1428 #if FS_STATS_DETAILED
1429 Date currDate; /*Current date */
1430 int writeIdx; /*Write index to bump */
1431 int timeIdx; /*Authorship time index to bump */
1432 #endif /* FS_STATS_DETAILED */
1434 parentptr->disk.dataVersion++;
1435 newlength = (afs_fsize_t) Length(dir);
1437 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1438 * (create, symlink, link, makedir) so we need to check if we have enough space
1439 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1440 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1442 VN_GET_LEN(parentLength, parentptr);
1443 if (nBlocks(newlength) != nBlocks(parentLength)) {
1444 VAdjustDiskUsage(&errorCode, volptr,
1445 (nBlocks(newlength) - nBlocks(parentLength)),
1446 (nBlocks(newlength) - nBlocks(parentLength)));
1448 VN_SET_LEN(parentptr, newlength);
1450 #if FS_STATS_DETAILED
1452 * Update directory write stats for this volume. Note that the auth
1453 * counter is located immediately after its associated ``distance''
1456 if (a_inSameNetwork)
1457 writeIdx = VOL_STATS_SAME_NET;
1459 writeIdx = VOL_STATS_DIFF_NET;
1460 V_stat_writes(volptr, writeIdx)++;
1461 if (author != AnonymousID) {
1462 V_stat_writes(volptr, writeIdx + 1)++;
1466 * Update the volume's authorship information in response to this
1467 * directory operation. Get the current time, decide to which time
1468 * slot this operation belongs, and bump the appropriate slot.
1470 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1472 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1473 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1474 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1475 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1476 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1477 if (parentptr->disk.author == author) {
1478 V_stat_dirSameAuthor(volptr, timeIdx)++;
1480 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1482 #endif /* FS_STATS_DETAILED */
1484 parentptr->disk.author = author;
1485 parentptr->disk.linkCount = linkcount;
1486 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1487 parentptr->disk.serverModifyTime = FT_ApproxTime();
1488 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1493 * Update the target file's (or dir's) status block after the specified
1494 * operation is complete. Note that some other fields maybe updated by
1495 * the individual module.
1498 /* XXX INCOMPLETE - More attention is needed here! */
1500 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1501 struct client *client, AFSStoreStatus * InStatus,
1502 Vnode * parentptr, Volume * volptr,
1505 #if FS_STATS_DETAILED
1506 Date currDate; /*Current date */
1507 int writeIdx; /*Write index to bump */
1508 int timeIdx; /*Authorship time index to bump */
1509 #endif /* FS_STATS_DETAILED */
1511 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1512 targetptr->disk.parent = parentptr->vnodeNumber;
1513 VN_SET_LEN(targetptr, length);
1514 /* targetptr->disk.group = 0; save some cycles */
1515 targetptr->disk.modeBits = 0777;
1516 targetptr->disk.owner = client->ViceId;
1517 targetptr->disk.dataVersion = 0; /* consistent with the client */
1518 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1519 /* the inode was created in Alloc_NewVnode() */
1521 #if FS_STATS_DETAILED
1523 * Update file write stats for this volume. Note that the auth
1524 * counter is located immediately after its associated ``distance''
1527 if (client->InSameNetwork)
1528 writeIdx = VOL_STATS_SAME_NET;
1530 writeIdx = VOL_STATS_DIFF_NET;
1531 V_stat_writes(volptr, writeIdx)++;
1532 if (client->ViceId != AnonymousID) {
1533 V_stat_writes(volptr, writeIdx + 1)++;
1537 * We only count operations that DON'T involve creating new objects
1538 * (files, symlinks, directories) or simply setting status as
1539 * authorship-change operations.
1541 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1543 * Update the volume's authorship information in response to this
1544 * file operation. Get the current time, decide to which time
1545 * slot this operation belongs, and bump the appropriate slot.
1547 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1550 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1551 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1552 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1553 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1554 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1555 VOL_STATS_TIME_IDX_5);
1556 if (targetptr->disk.author == client->ViceId) {
1557 V_stat_fileSameAuthor(volptr, timeIdx)++;
1559 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1562 #endif /* FS_STATS_DETAILED */
1564 if (!(Caller & TVS_SSTATUS))
1565 targetptr->disk.author = client->ViceId;
1566 if (Caller & TVS_SDATA) {
1567 targetptr->disk.dataVersion++;
1568 if (VanillaUser(client)) {
1569 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1570 #ifdef CREATE_SGUID_ADMIN_ONLY
1571 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1575 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1576 /* store status, must explicitly request to change the date */
1577 if (InStatus->Mask & AFS_SETMODTIME)
1578 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1579 } else { /* other: date always changes, but perhaps to what is specified by caller */
1580 targetptr->disk.unixModifyTime =
1581 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1582 ClientModTime : FT_ApproxTime());
1584 if (InStatus->Mask & AFS_SETOWNER) {
1585 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1586 if (VanillaUser(client)) {
1587 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1588 #ifdef CREATE_SGUID_ADMIN_ONLY
1589 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1592 targetptr->disk.owner = InStatus->Owner;
1593 if (VolumeRootVnode(targetptr)) {
1594 Error errorCode = 0; /* what should be done with this? */
1596 V_owner(targetptr->volumePtr) = InStatus->Owner;
1597 VUpdateVolume(&errorCode, targetptr->volumePtr);
1600 if (InStatus->Mask & AFS_SETMODE) {
1601 int modebits = InStatus->UnixModeBits;
1602 #define CREATE_SGUID_ADMIN_ONLY 1
1603 #ifdef CREATE_SGUID_ADMIN_ONLY
1604 if (VanillaUser(client))
1605 modebits = modebits & 0777;
1607 if (VanillaUser(client)) {
1608 targetptr->disk.modeBits = modebits;
1610 targetptr->disk.modeBits = modebits;
1613 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1614 CHK_STOREDATA, AUD_END);
1618 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1619 CHK_STORESTATUS, AUD_END);
1626 targetptr->disk.serverModifyTime = FT_ApproxTime();
1627 if (InStatus->Mask & AFS_SETGROUP)
1628 targetptr->disk.group = InStatus->Group;
1629 /* vnode changed : to be written back by VPutVnode */
1630 targetptr->changed_newTime = 1;
1632 } /*Update_TargetVnodeStatus */
1636 * Fills the CallBack structure with the expiration time and type of callback
1637 * structure. Warning: this function is currently incomplete.
1640 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1642 /* CallBackTime could not be 0 */
1643 if (CallBackTime == 0) {
1644 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1645 CallBack->ExpirationTime = 0;
1647 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1648 CallBack->CallBackVersion = CALLBACK_VERSION;
1649 CallBack->CallBackType = CB_SHARED; /* The default for now */
1651 } /*SetCallBackStruct */
1655 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1656 * allocation; if some error occured (exceeded volume quota or partition
1657 * was full, or whatever), it frees the space back and returns the code.
1658 * We usually pre-adjust the volume space to make sure that there's
1659 * enough space before consuming some.
1662 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1663 afs_sfsize_t checkLength)
1668 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1670 VAdjustDiskUsage(&nc, volptr, -length, 0);
1671 if (rc == VOVERQUOTA) {
1673 ("Volume %u (%s) is full\n", V_id(volptr),
1677 if (rc == VDISKFULL) {
1679 ("Partition %s that contains volume %u is full\n",
1680 volptr->partition->name, V_id(volptr)));
1683 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1688 } /*AdjustDiskUsage */
1691 * Common code that handles the creation of a new file (SAFS_CreateFile and
1692 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1695 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1696 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1697 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1699 Error errorCode = 0; /* Error code returned back */
1702 Inode nearInode; /* hint for inode allocation in solaris */
1705 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1706 BlocksPreallocatedForVnode))) {
1708 ("Insufficient space to allocate %" AFS_INT64_FMT " blocks\n",
1709 (afs_intmax_t) BlocksPreallocatedForVnode));
1713 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1714 if (errorCode != 0) {
1715 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1718 OutFid->Volume = V_id(volptr);
1719 OutFid->Vnode = (*targetptr)->vnodeNumber;
1720 OutFid->Unique = (*targetptr)->disk.uniquifier;
1722 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1724 /* create the inode now itself */
1726 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1727 VPartitionPath(V_partition(volptr)), nearInode,
1728 V_id(volptr), (*targetptr)->vnodeNumber,
1729 (*targetptr)->disk.uniquifier, 1);
1731 /* error in creating inode */
1732 if (!VALID_INO(inode)) {
1734 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1735 (*targetptr)->volumePtr->header->diskstuff.id,
1736 (*targetptr)->vnodeNumber, errno));
1737 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1738 (*targetptr)->delete = 1; /* delete vnode */
1741 VN_SET_INO(*targetptr, inode);
1742 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1744 /* copy group from parent dir */
1745 (*targetptr)->disk.group = parentptr->disk.group;
1747 if (parentptr->disk.cloned) {
1748 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1749 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1750 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1751 /* delete the vnode previously allocated */
1752 (*targetptr)->delete = 1;
1753 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1754 IH_REALLYCLOSE((*targetptr)->handle);
1755 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1757 ("Alloc_NewVnode: partition %s idec %s failed\n",
1758 volptr->partition->name, PrintInode(NULL, inode)));
1759 IH_RELEASE((*targetptr)->handle);
1765 /* add the name to the directory */
1766 SetDirHandle(dir, parentptr);
1767 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1768 (*targetptr)->delete = 1;
1769 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1770 IH_REALLYCLOSE((*targetptr)->handle);
1771 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1773 ("Alloc_NewVnode: partition %s idec %s failed\n",
1774 volptr->partition->name, PrintInode(NULL, inode)));
1775 IH_RELEASE((*targetptr)->handle);
1781 } /*Alloc_NewVnode */
1785 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1789 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1791 int Time; /* Used for time */
1792 int writeVnode = targetptr->changed_oldTime; /* save original status */
1794 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1795 Time = FT_ApproxTime();
1796 switch (LockingType) {
1799 if (Time > targetptr->disk.lock.lockTime)
1800 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1802 Time += AFS_LOCKWAIT;
1803 if (LockingType == LockRead) {
1804 if ( !(rights & PRSFS_LOCK) &&
1805 !(rights & PRSFS_WRITE) &&
1806 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1809 if (targetptr->disk.lock.lockCount >= 0) {
1810 ++(targetptr->disk.lock.lockCount);
1811 targetptr->disk.lock.lockTime = Time;
1814 } else if (LockingType == LockWrite) {
1815 if ( !(rights & PRSFS_WRITE) &&
1816 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1819 if (targetptr->disk.lock.lockCount == 0) {
1820 targetptr->disk.lock.lockCount = -1;
1821 targetptr->disk.lock.lockTime = Time;
1827 Time += AFS_LOCKWAIT;
1828 if (targetptr->disk.lock.lockCount != 0)
1829 targetptr->disk.lock.lockTime = Time;
1834 if ((--targetptr->disk.lock.lockCount) <= 0)
1835 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1839 targetptr->changed_oldTime = writeVnode; /* restore old status */
1840 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1843 } /*HandleLocking */
1845 /* 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. */
1848 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1852 if (!(rights & Prfs_Mode))
1854 if ((targetptr->disk.type != vDirectory)
1855 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1861 * If some flags (i.e. min or max quota) are set, the volume's in disk
1862 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1863 * update, if applicable.
1866 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1867 char *Name, char *OfflineMsg, char *Motd)
1869 Error errorCode = 0;
1871 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1872 V_minquota(volptr) = StoreVolStatus->MinQuota;
1873 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1874 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1875 if (strlen(OfflineMsg) > 0) {
1876 strcpy(V_offlineMessage(volptr), OfflineMsg);
1878 if (strlen(Name) > 0) {
1879 strcpy(V_name(volptr), Name);
1881 #if OPENAFS_VOL_STATS
1883 * We don't overwrite the motd field, since it's now being used
1887 if (strlen(Motd) > 0) {
1888 strcpy(V_motd(volptr), Motd);
1890 #endif /* FS_STATS_DETAILED */
1891 VUpdateVolume(&errorCode, volptr);
1894 } /*RXUpdate_VolumeStatus */
1898 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1899 char **motd, Volume * volptr)
1903 status->Vid = V_id(volptr);
1904 status->ParentId = V_parentId(volptr);
1905 status->Online = V_inUse(volptr);
1906 status->InService = V_inService(volptr);
1907 status->Blessed = V_blessed(volptr);
1908 status->NeedsSalvage = V_needsSalvaged(volptr);
1909 if (VolumeWriteable(volptr))
1910 status->Type = ReadWrite;
1912 status->Type = ReadOnly;
1913 status->MinQuota = V_minquota(volptr);
1914 status->MaxQuota = V_maxquota(volptr);
1915 status->BlocksInUse = V_diskused(volptr);
1916 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
1917 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
1919 /* now allocate and copy these things; they're freed by the RXGEN stub */
1920 temp = strlen(V_name(volptr)) + 1;
1921 *name = malloc(temp);
1923 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1926 strcpy(*name, V_name(volptr));
1927 temp = strlen(V_offlineMessage(volptr)) + 1;
1928 *offMsg = malloc(temp);
1930 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1933 strcpy(*offMsg, V_offlineMessage(volptr));
1934 #if OPENAFS_VOL_STATS
1937 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1940 strcpy(*motd, nullString);
1942 temp = strlen(V_motd(volptr)) + 1;
1943 *motd = malloc(temp);
1945 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1948 strcpy(*motd, V_motd(volptr));
1949 #endif /* FS_STATS_DETAILED */
1951 } /*RXGetVolumeStatus */
1955 FileNameOK(register char *aname)
1957 register afs_int32 i, tc;
1960 /* watch for @sys on the right */
1961 if (strcmp(aname + i - 4, "@sys") == 0)
1964 while ((tc = *aname++)) {
1966 return 0; /* very bad character to encounter */
1968 return 1; /* file name is ok */
1974 * This variant of symlink is expressly to support the AFS/DFS translator
1975 * and is not supported by the AFS fileserver. We just return EINVAL.
1976 * The cache manager should not generate this call to an AFS cache manager.
1979 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
1980 char *LinkContents, struct AFSStoreStatus *InStatus,
1981 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
1982 struct AFSFetchStatus *OutDirStatus,
1983 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
1989 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
1990 struct FsCmdInputs * Inputs,
1991 struct FsCmdOutputs * Outputs)
1995 switch (Inputs->command) {
1999 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2000 Inputs->command, Outputs->code));
2005 static struct afs_buffer {
2006 struct afs_buffer *next;
2007 } *freeBufferList = 0;
2008 static int afs_buffersAlloced = 0;
2011 FreeSendBuffer(register struct afs_buffer *adata)
2014 afs_buffersAlloced--;
2015 adata->next = freeBufferList;
2016 freeBufferList = adata;
2020 } /*FreeSendBuffer */
2022 /* allocate space for sender */
2026 register struct afs_buffer *tp;
2029 afs_buffersAlloced++;
2030 if (!freeBufferList) {
2033 tmp = malloc(sendBufSize);
2035 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2040 tp = freeBufferList;
2041 freeBufferList = tp->next;
2045 } /*AllocSendBuffer */
2046 #endif /* AFS_NT40_ENV */
2049 * This routine returns the status info associated with the targetptr vnode
2050 * in the AFSFetchStatus structure. Some of the newer fields, such as
2051 * SegSize and Group are not yet implemented
2055 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2056 afs_int32 anyrights, Vnode * parentptr)
2058 /* initialize return status from a vnode */
2059 status->InterfaceVersion = 1;
2060 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2061 status->errorCode = 0;
2062 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2063 if (targetptr->disk.type == vFile)
2064 status->FileType = File;
2065 else if (targetptr->disk.type == vDirectory)
2066 status->FileType = Directory;
2067 else if (targetptr->disk.type == vSymlink)
2068 status->FileType = SymbolicLink;
2070 status->FileType = Invalid; /*invalid type field */
2071 status->LinkCount = targetptr->disk.linkCount;
2073 afs_fsize_t targetLen;
2074 VN_GET_LEN(targetLen, targetptr);
2075 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2077 status->DataVersion = targetptr->disk.dataVersion;
2078 status->Author = targetptr->disk.author;
2079 status->Owner = targetptr->disk.owner;
2080 status->CallerAccess = rights;
2081 status->AnonymousAccess = anyrights;
2082 status->UnixModeBits = targetptr->disk.modeBits;
2083 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2084 status->ParentVnode =
2085 (status->FileType ==
2086 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2087 status->ParentUnique =
2088 (status->FileType ==
2089 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2090 status->ServerModTime = targetptr->disk.serverModifyTime;
2091 status->Group = targetptr->disk.group;
2092 status->lockCount = targetptr->disk.lock.lockCount;
2093 status->errorCode = 0;
2099 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2100 afs_sfsize_t Pos, afs_sfsize_t Len,
2101 struct AFSFetchStatus *OutStatus,
2102 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2105 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2106 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2107 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2108 Error errorCode = 0; /* return code to caller */
2109 Error fileCode = 0; /* return code from vol package */
2110 Volume *volptr = 0; /* pointer to the volume */
2111 struct client *client = 0; /* pointer to the client data */
2112 struct rx_connection *tcon; /* the connection we're part of */
2114 afs_int32 rights, anyrights; /* rights for this and any user */
2115 struct client *t_client = NULL; /* tmp ptr to client data */
2116 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2117 #if FS_STATS_DETAILED
2118 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2119 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2120 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2121 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2122 struct timeval elapsedTime; /* Transfer time */
2123 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2124 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2125 int readIdx; /* Index of read stats array to bump */
2126 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2129 * Set our stats pointers, remember when the RPC operation started, and
2130 * tally the operation.
2132 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2133 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2137 FT_GetTimeOfDay(&opStartTime, 0);
2138 #endif /* FS_STATS_DETAILED */
2141 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2144 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2146 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2149 /* Get ptr to client data for user Id for logging */
2150 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2151 logHostAddr.s_addr = rxr_HostOf(tcon);
2153 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2154 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2155 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2157 * Get volume/vnode for the fetched file; caller's access rights to
2158 * it are also returned
2161 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2162 &parentwhentargetnotdir, &client, READ_LOCK,
2163 &rights, &anyrights)))
2166 SetVolumeSync(Sync, volptr);
2168 #if FS_STATS_DETAILED
2170 * Remember that another read operation was performed.
2173 if (client->InSameNetwork)
2174 readIdx = VOL_STATS_SAME_NET;
2176 readIdx = VOL_STATS_DIFF_NET;
2177 V_stat_reads(volptr, readIdx)++;
2178 if (client->ViceId != AnonymousID) {
2179 V_stat_reads(volptr, readIdx + 1)++;
2182 #endif /* FS_STATS_DETAILED */
2183 /* Check whether the caller has permission access to fetch the data */
2185 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2189 * Drop the read lock on the parent directory after saving the parent
2190 * vnode information we need to pass to GetStatus
2192 if (parentwhentargetnotdir != NULL) {
2193 tparentwhentargetnotdir = *parentwhentargetnotdir;
2194 VPutVnode(&fileCode, parentwhentargetnotdir);
2195 assert(!fileCode || (fileCode == VSALVAGE));
2196 parentwhentargetnotdir = NULL;
2198 #if FS_STATS_DETAILED
2200 * Remember when the data transfer started.
2202 FT_GetTimeOfDay(&xferStartTime, 0);
2203 #endif /* FS_STATS_DETAILED */
2205 /* actually do the data transfer */
2206 #if FS_STATS_DETAILED
2208 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2209 &bytesToXfer, &bytesXferred);
2212 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2214 #endif /* FS_STATS_DETAILED */
2216 #if FS_STATS_DETAILED
2218 * At this point, the data transfer is done, for good or ill. Remember
2219 * when the transfer ended, bump the number of successes/failures, and
2220 * integrate the transfer size and elapsed time into the stats. If the
2221 * operation failed, we jump to the appropriate point.
2223 FT_GetTimeOfDay(&xferStopTime, 0);
2225 (xferP->numXfers)++;
2227 (xferP->numSuccesses)++;
2230 * Bump the xfer sum by the number of bytes actually sent, NOT the
2233 tot_bytesXferred += bytesXferred;
2234 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2235 tot_bytesXferred &= 0x3FF;
2236 if (bytesXferred < xferP->minBytes)
2237 xferP->minBytes = bytesXferred;
2238 if (bytesXferred > xferP->maxBytes)
2239 xferP->maxBytes = bytesXferred;
2242 * Tally the size of the object. Note: we tally the actual size,
2243 * NOT the number of bytes that made it out over the wire.
2245 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2246 (xferP->count[0])++;
2247 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2248 (xferP->count[1])++;
2249 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2250 (xferP->count[2])++;
2251 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2252 (xferP->count[3])++;
2253 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2254 (xferP->count[4])++;
2255 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2256 (xferP->count[5])++;
2257 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2258 (xferP->count[6])++;
2259 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2260 (xferP->count[7])++;
2262 (xferP->count[8])++;
2264 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2265 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2266 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2267 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2268 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2270 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2271 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2276 * Finally, go off to tell our caller the bad news in case the
2281 #endif /* FS_STATS_DETAILED */
2283 /* write back the OutStatus from the target vnode */
2284 GetStatus(targetptr, OutStatus, rights, anyrights,
2285 &tparentwhentargetnotdir);
2287 /* if a r/w volume, promise a callback to the caller */
2288 if (VolumeWriteable(volptr))
2289 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2291 struct AFSFid myFid;
2292 memset(&myFid, 0, sizeof(struct AFSFid));
2293 myFid.Volume = Fid->Volume;
2294 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2298 /* Update and store volume/vnode and parent vnodes back */
2299 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2301 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2302 errorCode = CallPostamble(tcon, errorCode, thost);
2304 #if FS_STATS_DETAILED
2305 FT_GetTimeOfDay(&opStopTime, 0);
2306 if (errorCode == 0) {
2308 (opP->numSuccesses)++;
2309 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2310 fs_stats_AddTo((opP->sumTime), elapsedTime);
2311 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2312 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2313 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2315 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2316 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2320 #endif /* FS_STATS_DETAILED */
2322 osi_auditU(acall, FetchDataEvent, errorCode,
2323 AUD_ID, t_client ? t_client->ViceId : 0,
2324 AUD_FID, Fid, AUD_END);
2327 } /*SRXAFS_FetchData */
2330 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2331 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2332 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2334 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2339 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2340 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2341 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2344 afs_sfsize_t tPos, tLen;
2346 #ifdef AFS_64BIT_ENV
2347 #ifndef AFS_LARGEFILE_ENV
2348 if (Pos + Len > 0x7fffffff)
2350 #endif /* !AFS_LARGEFILE_ENV */
2351 tPos = (afs_sfsize_t) Pos;
2352 tLen = (afs_sfsize_t) Len;
2353 #else /* AFS_64BIT_ENV */
2354 if (Pos.high || Len.high)
2358 #endif /* AFS_64BIT_ENV */
2361 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2367 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2368 struct AFSOpaque * AccessList,
2369 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2371 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2372 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2373 Error errorCode = 0; /* return error code to caller */
2374 Volume *volptr = 0; /* pointer to the volume */
2375 struct client *client = 0; /* pointer to the client data */
2376 afs_int32 rights, anyrights; /* rights for this and any user */
2377 struct rx_connection *tcon = rx_ConnectionOf(acall);
2379 struct client *t_client = NULL; /* tmp ptr to client data */
2380 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2381 #if FS_STATS_DETAILED
2382 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2383 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2384 struct timeval elapsedTime; /* Transfer time */
2387 * Set our stats pointer, remember when the RPC operation started, and
2388 * tally the operation.
2390 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2394 FT_GetTimeOfDay(&opStartTime, 0);
2395 #endif /* FS_STATS_DETAILED */
2398 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2401 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2403 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2406 /* Get ptr to client data for user Id for logging */
2407 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2408 logHostAddr.s_addr = rxr_HostOf(tcon);
2410 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2411 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2412 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2414 AccessList->AFSOpaque_len = 0;
2415 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2416 if (!AccessList->AFSOpaque_val) {
2417 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2422 * Get volume/vnode for the fetched file; caller's access rights to it
2426 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2427 &parentwhentargetnotdir, &client, READ_LOCK,
2428 &rights, &anyrights)))
2431 SetVolumeSync(Sync, volptr);
2433 /* Check whether we have permission to fetch the ACL */
2435 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2438 /* Get the Access List from the dir's vnode */
2440 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2443 /* Get OutStatus back From the target Vnode */
2444 GetStatus(targetptr, OutStatus, rights, anyrights,
2445 parentwhentargetnotdir);
2448 /* Update and store volume/vnode and parent vnodes back */
2449 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2452 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2453 AccessList->AFSOpaque_val));
2454 errorCode = CallPostamble(tcon, errorCode, thost);
2456 #if FS_STATS_DETAILED
2457 FT_GetTimeOfDay(&opStopTime, 0);
2458 if (errorCode == 0) {
2460 (opP->numSuccesses)++;
2461 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2462 fs_stats_AddTo((opP->sumTime), elapsedTime);
2463 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2464 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2465 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2467 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2468 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2472 #endif /* FS_STATS_DETAILED */
2474 osi_auditU(acall, FetchACLEvent, errorCode,
2475 AUD_ID, t_client ? t_client->ViceId : 0,
2477 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2479 } /*SRXAFS_FetchACL */
2483 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2484 * merged into it when possible.
2488 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2489 struct AFSFetchStatus *OutStatus,
2490 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2492 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2493 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2494 Error errorCode = 0; /* return code to caller */
2495 Volume *volptr = 0; /* pointer to the volume */
2496 struct client *client = 0; /* pointer to the client data */
2497 afs_int32 rights, anyrights; /* rights for this and any user */
2498 struct client *t_client = NULL; /* tmp ptr to client data */
2499 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2500 struct rx_connection *tcon = rx_ConnectionOf(acall);
2502 /* Get ptr to client data for user Id for logging */
2503 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2504 logHostAddr.s_addr = rxr_HostOf(tcon);
2506 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2507 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2508 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2510 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2513 * Get volume/vnode for the fetched file; caller's rights to it are
2517 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2518 &parentwhentargetnotdir, &client, READ_LOCK,
2519 &rights, &anyrights)))
2520 goto Bad_FetchStatus;
2522 /* set volume synchronization information */
2523 SetVolumeSync(Sync, volptr);
2525 /* Are we allowed to fetch Fid's status? */
2526 if (targetptr->disk.type != vDirectory) {
2528 Check_PermissionRights(targetptr, client, rights,
2529 CHK_FETCHSTATUS, 0))) {
2530 if (rx_GetCallAbortCode(acall) == errorCode)
2531 rx_SetCallAbortCode(acall, 0);
2532 goto Bad_FetchStatus;
2536 /* set OutStatus From the Fid */
2537 GetStatus(targetptr, OutStatus, rights, anyrights,
2538 parentwhentargetnotdir);
2540 /* If a r/w volume, also set the CallBack state */
2541 if (VolumeWriteable(volptr))
2542 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2544 struct AFSFid myFid;
2545 memset(&myFid, 0, sizeof(struct AFSFid));
2546 myFid.Volume = Fid->Volume;
2547 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2551 /* Update and store volume/vnode and parent vnodes back */
2552 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2554 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2557 } /*SAFSS_FetchStatus */
2561 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2562 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2563 struct AFSVolSync * Sync)
2567 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2568 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2569 Error errorCode = 0; /* return code to caller */
2570 Volume *volptr = 0; /* pointer to the volume */
2571 struct client *client = 0; /* pointer to the client data */
2572 afs_int32 rights, anyrights; /* rights for this and any user */
2573 register struct AFSFid *tfid; /* file id we're dealing with now */
2574 struct rx_connection *tcon = rx_ConnectionOf(acall);
2576 struct client *t_client = NULL; /* tmp pointer to the client data */
2577 #if FS_STATS_DETAILED
2578 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2579 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2580 struct timeval elapsedTime; /* Transfer time */
2583 * Set our stats pointer, remember when the RPC operation started, and
2584 * tally the operation.
2586 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2590 FT_GetTimeOfDay(&opStartTime, 0);
2591 #endif /* FS_STATS_DETAILED */
2593 ViceLog(1, ("SAFS_BulkStatus\n"));
2595 AFSCallStats.TotalCalls++;
2597 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2598 if (nfiles <= 0) { /* Sanity check */
2600 goto Audit_and_Return;
2603 /* allocate space for return output parameters */
2604 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2605 malloc(nfiles * sizeof(struct AFSFetchStatus));
2606 if (!OutStats->AFSBulkStats_val) {
2607 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2610 OutStats->AFSBulkStats_len = nfiles;
2611 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2612 malloc(nfiles * sizeof(struct AFSCallBack));
2613 if (!CallBacks->AFSCBs_val) {
2614 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2617 CallBacks->AFSCBs_len = nfiles;
2619 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2620 goto Bad_BulkStatus;
2622 tfid = Fids->AFSCBFids_val;
2623 for (i = 0; i < nfiles; i++, tfid++) {
2625 * Get volume/vnode for the fetched file; caller's rights to it
2629 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2630 &parentwhentargetnotdir, &client, READ_LOCK,
2631 &rights, &anyrights)))
2632 goto Bad_BulkStatus;
2633 /* set volume synchronization information, but only once per call */
2635 SetVolumeSync(Sync, volptr);
2637 /* Are we allowed to fetch Fid's status? */
2638 if (targetptr->disk.type != vDirectory) {
2640 Check_PermissionRights(targetptr, client, rights,
2641 CHK_FETCHSTATUS, 0))) {
2642 if (rx_GetCallAbortCode(acall) == errorCode)
2643 rx_SetCallAbortCode(acall, 0);
2644 goto Bad_BulkStatus;
2648 /* set OutStatus From the Fid */
2649 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2650 anyrights, parentwhentargetnotdir);
2652 /* If a r/w volume, also set the CallBack state */
2653 if (VolumeWriteable(volptr))
2654 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2655 &CallBacks->AFSCBs_val[i]);
2657 struct AFSFid myFid;
2658 memset(&myFid, 0, sizeof(struct AFSFid));
2659 myFid.Volume = tfid->Volume;
2660 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2661 &CallBacks->AFSCBs_val[i]);
2664 /* put back the file ID and volume */
2665 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2667 parentwhentargetnotdir = (Vnode *) 0;
2668 targetptr = (Vnode *) 0;
2669 volptr = (Volume *) 0;
2670 client = (struct client *)0;
2674 /* Update and store volume/vnode and parent vnodes back */
2675 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2677 errorCode = CallPostamble(tcon, errorCode, thost);
2679 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2681 #if FS_STATS_DETAILED
2682 FT_GetTimeOfDay(&opStopTime, 0);
2683 if (errorCode == 0) {
2685 (opP->numSuccesses)++;
2686 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2687 fs_stats_AddTo((opP->sumTime), elapsedTime);
2688 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2689 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2690 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2692 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2693 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2697 #endif /* FS_STATS_DETAILED */
2700 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2701 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2702 AUD_ID, t_client ? t_client->ViceId : 0,
2703 AUD_FIDS, Fids, AUD_END);
2706 } /*SRXAFS_BulkStatus */
2710 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2711 struct AFSBulkStats * OutStats,
2712 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2716 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2717 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2718 Error errorCode = 0; /* return code to caller */
2719 Volume *volptr = 0; /* pointer to the volume */
2720 struct client *client = 0; /* pointer to the client data */
2721 afs_int32 rights, anyrights; /* rights for this and any user */
2722 register struct AFSFid *tfid; /* file id we're dealing with now */
2723 struct rx_connection *tcon;
2725 struct client *t_client = NULL; /* tmp ptr to client data */
2726 AFSFetchStatus *tstatus;
2727 #if FS_STATS_DETAILED
2728 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2729 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2730 struct timeval elapsedTime; /* Transfer time */
2733 * Set our stats pointer, remember when the RPC operation started, and
2734 * tally the operation.
2736 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2740 FT_GetTimeOfDay(&opStartTime, 0);
2741 #endif /* FS_STATS_DETAILED */
2743 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2745 AFSCallStats.TotalCalls++;
2747 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2748 if (nfiles <= 0) { /* Sanity check */
2750 goto Audit_and_Return;
2753 /* allocate space for return output parameters */
2754 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2755 malloc(nfiles * sizeof(struct AFSFetchStatus));
2756 if (!OutStats->AFSBulkStats_val) {
2757 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2760 OutStats->AFSBulkStats_len = nfiles;
2761 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2762 malloc(nfiles * sizeof(struct AFSCallBack));
2763 if (!CallBacks->AFSCBs_val) {
2764 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2767 CallBacks->AFSCBs_len = nfiles;
2769 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2770 goto Bad_InlineBulkStatus;
2773 tfid = Fids->AFSCBFids_val;
2774 for (i = 0; i < nfiles; i++, tfid++) {
2776 * Get volume/vnode for the fetched file; caller's rights to it
2780 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2781 &parentwhentargetnotdir, &client, READ_LOCK,
2782 &rights, &anyrights))) {
2783 tstatus = &OutStats->AFSBulkStats_val[i];
2784 tstatus->errorCode = errorCode;
2785 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2787 parentwhentargetnotdir = (Vnode *) 0;
2788 targetptr = (Vnode *) 0;
2789 volptr = (Volume *) 0;
2790 client = (struct client *)0;
2794 /* set volume synchronization information, but only once per call */
2796 SetVolumeSync(Sync, volptr);
2798 /* Are we allowed to fetch Fid's status? */
2799 if (targetptr->disk.type != vDirectory) {
2801 Check_PermissionRights(targetptr, client, rights,
2802 CHK_FETCHSTATUS, 0))) {
2803 tstatus = &OutStats->AFSBulkStats_val[i];
2804 tstatus->errorCode = errorCode;
2805 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2806 (Vnode *) 0, volptr, &client);
2807 parentwhentargetnotdir = (Vnode *) 0;
2808 targetptr = (Vnode *) 0;
2809 volptr = (Volume *) 0;
2810 client = (struct client *)0;
2815 /* set OutStatus From the Fid */
2816 GetStatus(targetptr,
2817 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2818 rights, anyrights, parentwhentargetnotdir);
2820 /* If a r/w volume, also set the CallBack state */
2821 if (VolumeWriteable(volptr))
2822 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2823 &CallBacks->AFSCBs_val[i]);
2825 struct AFSFid myFid;
2826 memset(&myFid, 0, sizeof(struct AFSFid));
2827 myFid.Volume = tfid->Volume;
2828 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2829 &CallBacks->AFSCBs_val[i]);
2832 /* put back the file ID and volume */
2833 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2835 parentwhentargetnotdir = (Vnode *) 0;
2836 targetptr = (Vnode *) 0;
2837 volptr = (Volume *) 0;
2838 client = (struct client *)0;
2841 Bad_InlineBulkStatus:
2842 /* Update and store volume/vnode and parent vnodes back */
2843 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2845 errorCode = CallPostamble(tcon, errorCode, thost);
2847 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2849 #if FS_STATS_DETAILED
2850 FT_GetTimeOfDay(&opStopTime, 0);
2851 if (errorCode == 0) {
2853 (opP->numSuccesses)++;
2854 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2855 fs_stats_AddTo((opP->sumTime), elapsedTime);
2856 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2857 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2858 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2860 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2861 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2865 #endif /* FS_STATS_DETAILED */
2868 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2869 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2870 AUD_ID, t_client ? t_client->ViceId : 0,
2871 AUD_FIDS, Fids, AUD_END);
2874 } /*SRXAFS_InlineBulkStatus */
2878 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2879 struct AFSFetchStatus * OutStatus,
2880 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2883 struct rx_connection *tcon;
2885 struct client *t_client = NULL; /* tmp ptr to client data */
2886 #if FS_STATS_DETAILED
2887 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2888 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2889 struct timeval elapsedTime; /* Transfer time */
2892 * Set our stats pointer, remember when the RPC operation started, and
2893 * tally the operation.
2895 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2899 FT_GetTimeOfDay(&opStartTime, 0);
2900 #endif /* FS_STATS_DETAILED */
2902 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2903 goto Bad_FetchStatus;
2905 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2908 code = CallPostamble(tcon, code, thost);
2910 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2912 #if FS_STATS_DETAILED
2913 FT_GetTimeOfDay(&opStopTime, 0);
2916 (opP->numSuccesses)++;
2917 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2918 fs_stats_AddTo((opP->sumTime), elapsedTime);
2919 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2920 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2921 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2923 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2924 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2928 #endif /* FS_STATS_DETAILED */
2930 osi_auditU(acall, FetchStatusEvent, code,
2931 AUD_ID, t_client ? t_client->ViceId : 0,
2932 AUD_FID, Fid, AUD_END);
2935 } /*SRXAFS_FetchStatus */
2939 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2940 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2941 afs_fsize_t Length, afs_fsize_t FileLength,
2942 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2944 Vnode *targetptr = 0; /* pointer to input fid */
2945 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2946 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2947 Error errorCode = 0; /* return code for caller */
2948 Error fileCode = 0; /* return code from vol package */
2949 Volume *volptr = 0; /* pointer to the volume header */
2950 struct client *client = 0; /* pointer to client structure */
2951 afs_int32 rights, anyrights; /* rights for this and any user */
2952 struct client *t_client = NULL; /* tmp ptr to client data */
2953 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2954 struct rx_connection *tcon;
2956 #if FS_STATS_DETAILED
2957 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2958 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2959 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2960 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2961 struct timeval elapsedTime; /* Transfer time */
2962 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2963 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2964 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2967 * Set our stats pointers, remember when the RPC operation started, and
2968 * tally the operation.
2970 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2971 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2976 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2978 FT_GetTimeOfDay(&opStartTime, 0);
2979 #endif /* FS_STATS_DETAILED */
2982 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2984 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2987 /* Get ptr to client data for user Id for logging */
2988 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2989 logHostAddr.s_addr = rxr_HostOf(tcon);
2991 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2992 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2993 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2996 * Get associated volume/vnode for the stored file; caller's rights
3000 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
3001 &parentwhentargetnotdir, &client, WRITE_LOCK,
3002 &rights, &anyrights))) {
3006 /* set volume synchronization information */
3007 SetVolumeSync(Sync, volptr);
3009 if ((targetptr->disk.type == vSymlink)) {
3010 /* Should we return a better error code here??? */
3015 /* Check if we're allowed to store the data */
3017 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
3023 * Drop the read lock on the parent directory after saving the parent
3024 * vnode information we need to pass to GetStatus
3026 if (parentwhentargetnotdir != NULL) {
3027 tparentwhentargetnotdir = *parentwhentargetnotdir;
3028 VPutVnode(&fileCode, parentwhentargetnotdir);
3029 assert(!fileCode || (fileCode == VSALVAGE));
3030 parentwhentargetnotdir = NULL;
3032 #if FS_STATS_DETAILED
3034 * Remember when the data transfer started.
3036 FT_GetTimeOfDay(&xferStartTime, 0);
3037 #endif /* FS_STATS_DETAILED */
3039 /* Do the actual storing of the data */
3040 #if FS_STATS_DETAILED
3042 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3043 FileLength, (InStatus->Mask & AFS_FSYNC),
3044 &bytesToXfer, &bytesXferred);
3047 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3048 FileLength, (InStatus->Mask & AFS_FSYNC));
3049 if (errorCode && (!targetptr->changed_newTime))
3051 #endif /* FS_STATS_DETAILED */
3052 #if FS_STATS_DETAILED
3054 * At this point, the data transfer is done, for good or ill. Remember
3055 * when the transfer ended, bump the number of successes/failures, and
3056 * integrate the transfer size and elapsed time into the stats. If the
3057 * operation failed, we jump to the appropriate point.
3059 FT_GetTimeOfDay(&xferStopTime, 0);
3061 (xferP->numXfers)++;
3063 (xferP->numSuccesses)++;
3066 * Bump the xfer sum by the number of bytes actually sent, NOT the
3069 tot_bytesXferred += bytesXferred;
3070 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3071 tot_bytesXferred &= 0x3FF;
3072 if (bytesXferred < xferP->minBytes)
3073 xferP->minBytes = bytesXferred;
3074 if (bytesXferred > xferP->maxBytes)
3075 xferP->maxBytes = bytesXferred;
3078 * Tally the size of the object. Note: we tally the actual size,
3079 * NOT the number of bytes that made it out over the wire.
3081 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3082 (xferP->count[0])++;
3083 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3084 (xferP->count[1])++;
3085 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3086 (xferP->count[2])++;
3087 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3088 (xferP->count[3])++;
3089 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3090 (xferP->count[4])++;
3091 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3092 (xferP->count[5])++;
3093 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3094 (xferP->count[6])++;
3095 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3096 (xferP->count[7])++;
3098 (xferP->count[8])++;
3100 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3101 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3102 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3103 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3104 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3106 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3107 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3112 * Finally, go off to tell our caller the bad news in case the
3115 if (errorCode && (!targetptr->changed_newTime))
3117 #endif /* FS_STATS_DETAILED */
3119 /* Update the status of the target's vnode */
3120 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3121 targetptr, volptr, 0);
3123 /* Get the updated File's status back to the caller */
3124 GetStatus(targetptr, OutStatus, rights, anyrights,
3125 &tparentwhentargetnotdir);
3128 /* Update and store volume/vnode and parent vnodes back */
3129 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3131 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3133 errorCode = CallPostamble(tcon, errorCode, thost);
3135 #if FS_STATS_DETAILED
3136 FT_GetTimeOfDay(&opStopTime, 0);
3137 if (errorCode == 0) {
3139 (opP->numSuccesses)++;
3140 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3141 fs_stats_AddTo((opP->sumTime), elapsedTime);
3142 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3143 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3144 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3146 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3147 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3151 #endif /* FS_STATS_DETAILED */
3152 osi_auditU(acall, StoreDataEvent, errorCode,
3153 AUD_ID, t_client ? t_client->ViceId : 0,
3154 AUD_FID, Fid, AUD_END);
3156 } /*common_StoreData64 */
3159 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3160 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3161 afs_uint32 Length, afs_uint32 FileLength,
3162 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3164 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3165 (0x7fffffff - Pos) < Length)
3168 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3170 } /*SRXAFS_StoreData */
3173 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3174 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3175 afs_uint64 Length, afs_uint64 FileLength,
3176 struct AFSFetchStatus * OutStatus,
3177 struct AFSVolSync * Sync)
3181 afs_fsize_t tLength;
3182 afs_fsize_t tFileLength;
3184 #ifdef AFS_64BIT_ENV
3185 #ifndef AFS_LARGEFILE_ENV
3186 if (FileLength > 0x7fffffff)
3188 #endif /* !AFS_LARGEFILE_ENV */
3189 tPos = (afs_fsize_t) Pos;
3190 tLength = (afs_fsize_t) Length;
3191 tFileLength = (afs_fsize_t) FileLength;
3192 #else /* AFS_64BIT_ENV */
3193 if (FileLength.high)
3196 tLength = Length.low;
3197 tFileLength = FileLength.low;
3198 #endif /* AFS_64BIT_ENV */
3201 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3207 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3208 struct AFSOpaque * AccessList,
3209 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3211 Vnode *targetptr = 0; /* pointer to input fid */
3212 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3213 Error errorCode = 0; /* return code for caller */
3214 struct AFSStoreStatus InStatus; /* Input status for fid */
3215 Volume *volptr = 0; /* pointer to the volume header */
3216 struct client *client = 0; /* pointer to client structure */
3217 afs_int32 rights, anyrights; /* rights for this and any user */
3218 struct rx_connection *tcon;
3220 struct client *t_client = NULL; /* tmp ptr to client data */
3221 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3222 #if FS_STATS_DETAILED
3223 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3224 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3225 struct timeval elapsedTime; /* Transfer time */
3228 * Set our stats pointer, remember when the RPC operation started, and
3229 * tally the operation.
3231 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3235 FT_GetTimeOfDay(&opStartTime, 0);
3236 #endif /* FS_STATS_DETAILED */
3237 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3240 /* Get ptr to client data for user Id for logging */
3241 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3242 logHostAddr.s_addr = rxr_HostOf(tcon);
3244 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3245 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3246 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3248 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3250 InStatus.Mask = 0; /* not storing any status */
3253 * Get associated volume/vnode for the target dir; caller's rights
3254 * are also returned.
3257 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3258 &parentwhentargetnotdir, &client, WRITE_LOCK,
3259 &rights, &anyrights))) {
3263 /* set volume synchronization information */
3264 SetVolumeSync(Sync, volptr);
3266 /* Check if we have permission to change the dir's ACL */
3268 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3273 /* Build and store the new Access List for the dir */
3274 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3278 targetptr->changed_newTime = 1; /* status change of directory */
3280 /* convert the write lock to a read lock before breaking callbacks */
3281 VVnodeWriteToRead(&errorCode, targetptr);
3282 assert(!errorCode || errorCode == VSALVAGE);
3284 /* break call backs on the directory */
3285 BreakCallBack(client->host, Fid, 0);
3287 /* Get the updated dir's status back to the caller */
3288 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3291 /* Update and store volume/vnode and parent vnodes back */
3292 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3294 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3295 errorCode = CallPostamble(tcon, errorCode, thost);
3297 #if FS_STATS_DETAILED
3298 FT_GetTimeOfDay(&opStopTime, 0);
3299 if (errorCode == 0) {
3301 (opP->numSuccesses)++;
3302 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3303 fs_stats_AddTo((opP->sumTime), elapsedTime);
3304 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3305 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3306 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3308 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3309 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3313 #endif /* FS_STATS_DETAILED */
3315 osi_auditU(acall, StoreACLEvent, errorCode,
3316 AUD_ID, t_client ? t_client->ViceId : 0,
3317 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3320 } /*SRXAFS_StoreACL */
3324 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3325 * should be merged when possible.
3328 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3329 struct AFSStoreStatus *InStatus,
3330 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3332 Vnode *targetptr = 0; /* pointer to input fid */
3333 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3334 Error errorCode = 0; /* return code for caller */
3335 Volume *volptr = 0; /* pointer to the volume header */
3336 struct client *client = 0; /* pointer to client structure */
3337 afs_int32 rights, anyrights; /* rights for this and any user */
3338 struct client *t_client = NULL; /* tmp ptr to client data */
3339 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3340 struct rx_connection *tcon = rx_ConnectionOf(acall);
3342 /* Get ptr to client data for user Id for logging */
3343 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3344 logHostAddr.s_addr = rxr_HostOf(tcon);
3346 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3347 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3348 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3350 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3353 * Get volume/vnode for the target file; caller's rights to it are
3357 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3358 &parentwhentargetnotdir, &client, WRITE_LOCK,
3359 &rights, &anyrights))) {
3360 goto Bad_StoreStatus;
3363 /* set volume synchronization information */
3364 SetVolumeSync(Sync, volptr);
3366 /* Check if the caller has proper permissions to store status to Fid */
3368 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3370 goto Bad_StoreStatus;
3373 * Check for a symbolic link; we can't chmod these (otherwise could
3374 * change a symlink to a mt pt or vice versa)
3376 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3378 goto Bad_StoreStatus;
3381 /* Update the status of the target's vnode */
3382 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3383 (parentwhentargetnotdir ? parentwhentargetnotdir
3384 : targetptr), volptr, 0);
3386 /* convert the write lock to a read lock before breaking callbacks */
3387 VVnodeWriteToRead(&errorCode, targetptr);
3388 assert(!errorCode || errorCode == VSALVAGE);
3390 /* Break call backs on Fid */
3391 BreakCallBack(client->host, Fid, 0);
3393 /* Return the updated status back to caller */
3394 GetStatus(targetptr, OutStatus, rights, anyrights,
3395 parentwhentargetnotdir);
3398 /* Update and store volume/vnode and parent vnodes back */
3399 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3401 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3404 } /*SAFSS_StoreStatus */
3408 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3409 struct AFSStoreStatus * InStatus,
3410 struct AFSFetchStatus * OutStatus,
3411 struct AFSVolSync * Sync)
3414 struct rx_connection *tcon;
3416 struct client *t_client = NULL; /* tmp ptr to client data */
3417 #if FS_STATS_DETAILED
3418 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3419 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3420 struct timeval elapsedTime; /* Transfer time */
3423 * Set our stats pointer, remember when the RPC operation started, and
3424 * tally the operation.
3426 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3430 FT_GetTimeOfDay(&opStartTime, 0);
3431 #endif /* FS_STATS_DETAILED */
3433 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3434 goto Bad_StoreStatus;
3436 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3439 code = CallPostamble(tcon, code, thost);
3441 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3443 #if FS_STATS_DETAILED
3444 FT_GetTimeOfDay(&opStopTime, 0);
3447 (opP->numSuccesses)++;
3448 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3449 fs_stats_AddTo((opP->sumTime), elapsedTime);
3450 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3451 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3452 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3454 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3455 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3459 #endif /* FS_STATS_DETAILED */
3461 osi_auditU(acall, StoreStatusEvent, code,
3462 AUD_ID, t_client ? t_client->ViceId : 0,
3463 AUD_FID, Fid, AUD_END);
3466 } /*SRXAFS_StoreStatus */
3470 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3471 * merged in when possible.
3474 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3475 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3477 Vnode *parentptr = 0; /* vnode of input Directory */
3478 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3479 Vnode *targetptr = 0; /* file to be deleted */
3480 Volume *volptr = 0; /* pointer to the volume header */
3481 AFSFid fileFid; /* area for Fid from the directory */
3482 Error errorCode = 0; /* error code */
3483 DirHandle dir; /* Handle for dir package I/O */
3484 struct client *client = 0; /* pointer to client structure */
3485 afs_int32 rights, anyrights; /* rights for this and any user */
3486 struct client *t_client; /* tmp ptr to client data */
3487 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3488 struct rx_connection *tcon = rx_ConnectionOf(acall);
3491 /* Get ptr to client data for user Id for logging */
3492 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3493 logHostAddr.s_addr = rxr_HostOf(tcon);
3495 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3496 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3497 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3499 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3502 * Get volume/vnode for the parent dir; caller's access rights are
3506 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3507 &parentwhentargetnotdir, &client, WRITE_LOCK,
3508 &rights, &anyrights))) {
3509 goto Bad_RemoveFile;
3511 /* set volume synchronization information */
3512 SetVolumeSync(Sync, volptr);
3514 /* Does the caller has delete (& write) access to the parent directory? */
3515 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3516 goto Bad_RemoveFile;
3519 /* Actually delete the desired file */
3521 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3523 goto Bad_RemoveFile;
3526 /* Update the vnode status of the parent dir */
3527 #if FS_STATS_DETAILED
3528 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3529 parentptr->disk.linkCount,
3530 client->InSameNetwork);
3532 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3533 parentptr->disk.linkCount);
3534 #endif /* FS_STATS_DETAILED */
3536 /* Return the updated parent dir's status back to caller */
3537 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3539 /* Handle internal callback state for the parent and the deleted file */
3540 if (targetptr->disk.linkCount == 0) {
3541 /* no references left, discard entry */
3542 DeleteFileCallBacks(&fileFid);
3543 /* convert the parent lock to a read lock before breaking callbacks */
3544 VVnodeWriteToRead(&errorCode, parentptr);
3545 assert(!errorCode || errorCode == VSALVAGE);
3547 /* convert the parent lock to a read lock before breaking callbacks */
3548 VVnodeWriteToRead(&errorCode, parentptr);
3549 assert(!errorCode || errorCode == VSALVAGE);
3550 /* convert the target lock to a read lock before breaking callbacks */
3551 VVnodeWriteToRead(&errorCode, targetptr);
3552 assert(!errorCode || errorCode == VSALVAGE);
3553 /* tell all the file has changed */
3554 BreakCallBack(client->host, &fileFid, 1);
3557 /* break call back on the directory */
3558 BreakCallBack(client->host, DirFid, 0);
3561 /* Update and store volume/vnode and parent vnodes back */
3562 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3565 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3568 } /*SAFSS_RemoveFile */
3572 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3573 struct AFSFetchStatus * OutDirStatus,
3574 struct AFSVolSync * Sync)
3577 struct rx_connection *tcon;
3579 struct client *t_client = NULL; /* tmp ptr to client data */
3580 #if FS_STATS_DETAILED
3581 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3582 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3583 struct timeval elapsedTime; /* Transfer time */
3586 * Set our stats pointer, remember when the RPC operation started, and
3587 * tally the operation.
3589 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3593 FT_GetTimeOfDay(&opStartTime, 0);
3594 #endif /* FS_STATS_DETAILED */
3596 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3597 goto Bad_RemoveFile;
3599 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3602 code = CallPostamble(tcon, code, thost);
3604 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3606 #if FS_STATS_DETAILED
3607 FT_GetTimeOfDay(&opStopTime, 0);
3610 (opP->numSuccesses)++;
3611 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3612 fs_stats_AddTo((opP->sumTime), elapsedTime);
3613 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3614 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3615 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3617 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3618 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3622 #endif /* FS_STATS_DETAILED */
3624 osi_auditU(acall, RemoveFileEvent, code,
3625 AUD_ID, t_client ? t_client->ViceId : 0,
3626 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3629 } /*SRXAFS_RemoveFile */
3633 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3634 * be merged in when possible.
3637 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3638 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3639 struct AFSFetchStatus *OutFidStatus,
3640 struct AFSFetchStatus *OutDirStatus,
3641 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3643 Vnode *parentptr = 0; /* vnode of input Directory */
3644 Vnode *targetptr = 0; /* vnode of the new file */
3645 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3646 Volume *volptr = 0; /* pointer to the volume header */
3647 Error errorCode = 0; /* error code */
3648 DirHandle dir; /* Handle for dir package I/O */
3649 struct client *client = 0; /* pointer to client structure */
3650 afs_int32 rights, anyrights; /* rights for this and any user */
3651 struct client *t_client; /* tmp ptr to client data */
3652 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3653 struct rx_connection *tcon = rx_ConnectionOf(acall);
3657 /* Get ptr to client data for user Id for logging */
3658 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3659 logHostAddr.s_addr = rxr_HostOf(tcon);
3661 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3662 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3663 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3665 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3667 if (!FileNameOK(Name)) {
3669 goto Bad_CreateFile;
3673 * Get associated volume/vnode for the parent dir; caller long are
3677 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3678 &parentwhentargetnotdir, &client, WRITE_LOCK,
3679 &rights, &anyrights))) {
3680 goto Bad_CreateFile;
3683 /* set volume synchronization information */
3684 SetVolumeSync(Sync, volptr);
3686 /* Can we write (and insert) onto the parent directory? */
3687 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3688 goto Bad_CreateFile;
3690 /* get a new vnode for the file to be created and set it up */
3692 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3693 vFile, nBlocks(0)))) {
3694 goto Bad_CreateFile;
3697 /* update the status of the parent vnode */
3698 #if FS_STATS_DETAILED
3699 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3700 parentptr->disk.linkCount,
3701 client->InSameNetwork);
3703 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3704 parentptr->disk.linkCount);
3705 #endif /* FS_STATS_DETAILED */
3707 /* update the status of the new file's vnode */
3708 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3709 parentptr, volptr, 0);
3711 /* 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 */
3712 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3713 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3715 /* convert the write lock to a read lock before breaking callbacks */
3716 VVnodeWriteToRead(&errorCode, parentptr);
3717 assert(!errorCode || errorCode == VSALVAGE);
3719 /* break call back on parent dir */
3720 BreakCallBack(client->host, DirFid, 0);
3722 /* Return a callback promise for the newly created file to the caller */
3723 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3726 /* Update and store volume/vnode and parent vnodes back */
3727 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3730 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3733 } /*SAFSS_CreateFile */
3737 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3738 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3739 struct AFSFetchStatus * OutFidStatus,
3740 struct AFSFetchStatus * OutDirStatus,
3741 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3744 struct rx_connection *tcon;
3746 struct client *t_client = NULL; /* tmp ptr to client data */
3747 #if FS_STATS_DETAILED
3748 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3749 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3750 struct timeval elapsedTime; /* Transfer time */
3753 * Set our stats pointer, remember when the RPC operation started, and
3754 * tally the operation.
3756 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3760 FT_GetTimeOfDay(&opStartTime, 0);
3761 #endif /* FS_STATS_DETAILED */
3763 memset(OutFid, 0, sizeof(struct AFSFid));
3765 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3766 goto Bad_CreateFile;
3769 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3770 OutDirStatus, CallBack, Sync);
3773 code = CallPostamble(tcon, code, thost);
3775 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3777 #if FS_STATS_DETAILED
3778 FT_GetTimeOfDay(&opStopTime, 0);
3781 (opP->numSuccesses)++;
3782 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3783 fs_stats_AddTo((opP->sumTime), elapsedTime);
3784 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3785 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3786 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3788 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3789 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3793 #endif /* FS_STATS_DETAILED */
3795 osi_auditU(acall, CreateFileEvent, code,
3796 AUD_ID, t_client ? t_client->ViceId : 0,
3797 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3800 } /*SRXAFS_CreateFile */
3804 * This routine is called exclusively from SRXAFS_Rename(), and should be
3805 * merged in when possible.
3808 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3809 struct AFSFid *NewDirFid, char *NewName,
3810 struct AFSFetchStatus *OutOldDirStatus,
3811 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3813 Vnode *oldvptr = 0; /* vnode of the old Directory */
3814 Vnode *newvptr = 0; /* vnode of the new Directory */
3815 Vnode *fileptr = 0; /* vnode of the file to move */
3816 Vnode *newfileptr = 0; /* vnode of the file to delete */
3817 Vnode *testvptr = 0; /* used in directory tree walk */
3818 Vnode *parent = 0; /* parent for use in SetAccessList */
3819 Error errorCode = 0; /* error code */
3820 Error fileCode = 0; /* used when writing Vnodes */
3821 VnodeId testnode; /* used in directory tree walk */
3822 AFSFid fileFid; /* Fid of file to move */
3823 AFSFid newFileFid; /* Fid of new file */
3824 DirHandle olddir; /* Handle for dir package I/O */
3825 DirHandle newdir; /* Handle for dir package I/O */
3826 DirHandle filedir; /* Handle for dir package I/O */
3827 DirHandle newfiledir; /* Handle for dir package I/O */
3828 Volume *volptr = 0; /* pointer to the volume header */
3829 struct client *client = 0; /* pointer to client structure */
3830 afs_int32 rights, anyrights; /* rights for this and any user */
3831 afs_int32 newrights; /* rights for this user */
3832 afs_int32 newanyrights; /* rights for any user */
3833 int doDelete; /* deleted the rename target (ref count now 0) */
3835 struct client *t_client; /* tmp ptr to client data */
3836 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3837 struct rx_connection *tcon = rx_ConnectionOf(acall);
3842 FidZero(&newfiledir);
3844 /* Get ptr to client data for user Id for logging */
3845 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3846 logHostAddr.s_addr = rxr_HostOf(tcon);
3848 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3849 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3850 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3851 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3853 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3855 if (!FileNameOK(NewName)) {
3859 if (OldDirFid->Volume != NewDirFid->Volume) {
3864 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3865 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3866 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3872 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3874 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3875 &parent, &client, WRITE_LOCK, &rights,
3880 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3882 newrights = rights, newanyrights = anyrights;
3885 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3886 MustBeDIR, &parent, &client, WRITE_LOCK,
3887 &newrights, &newanyrights))) {
3893 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3894 &parent, &client, WRITE_LOCK, &newrights,
3900 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3901 &parent, &client, WRITE_LOCK, &rights,
3908 /* set volume synchronization information */
3909 SetVolumeSync(Sync, volptr);
3911 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3914 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3918 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3919 * call to CopyOnWrite returns error, it is not necessary to revert back
3920 * the effects of the first call because the contents of the volume is
3921 * not modified, it is only replicated.
3923 if (oldvptr->disk.cloned) {
3924 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3925 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
3928 SetDirHandle(&olddir, oldvptr);
3929 if (newvptr->disk.cloned) {
3930 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3931 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
3935 SetDirHandle(&newdir, newvptr);
3937 /* Lookup the file to delete its vnode */
3938 if (Lookup(&olddir, OldName, &fileFid)) {
3942 if (fileFid.Vnode == oldvptr->vnodeNumber
3943 || fileFid.Vnode == newvptr->vnodeNumber) {
3944 errorCode = FSERR_ELOOP;
3947 fileFid.Volume = V_id(volptr);
3948 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3949 if (errorCode != 0) {
3951 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3952 OldName, errorCode));
3953 VTakeOffline(volptr);
3956 if (fileptr->disk.uniquifier != fileFid.Unique) {
3958 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3960 VTakeOffline(volptr);
3965 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3966 && fileptr->disk.linkCount != 1) {
3968 * Hard links exist to this file - cannot move one of the links to
3969 * a new directory because of AFS restrictions (this is the same
3970 * reason that links cannot be made across directories, i.e.
3977 /* Lookup the new file */
3978 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3979 if (readonlyServer) {
3980 errorCode = VREADONLY;
3983 if (!(newrights & PRSFS_DELETE)) {
3987 if (newFileFid.Vnode == oldvptr->vnodeNumber
3988 || newFileFid.Vnode == newvptr->vnodeNumber
3989 || newFileFid.Vnode == fileFid.Vnode) {
3993 newFileFid.Volume = V_id(volptr);
3995 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3996 if (errorCode != 0) {
3998 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
3999 NewName, errorCode));
4000 VTakeOffline(volptr);
4003 if (fileptr->disk.uniquifier != fileFid.Unique) {
4005 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
4007 VTakeOffline(volptr);
4011 SetDirHandle(&newfiledir, newfileptr);
4012 /* Now check that we're moving directories over directories properly, etc.
4013 * return proper POSIX error codes:
4014 * if fileptr is a file and new is a dir: EISDIR.
4015 * if fileptr is a dir and new is a file: ENOTDIR.
4016 * Also, dir to be removed must be empty, of course.
4018 if (newfileptr->disk.type == vDirectory) {
4019 if (fileptr->disk.type != vDirectory) {
4023 if ((IsEmpty(&newfiledir))) {
4028 if (fileptr->disk.type == vDirectory) {
4029 errorCode = ENOTDIR;
4036 * ok - now we check that the old name is not above new name in the
4037 * directory structure. This is to prevent removing a subtree alltogether
4039 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
4040 afs_int32 forpass = 0, vnum = 0, top = 0;
4041 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
4042 if (testnode > vnum) vnum = testnode;
4043 if (forpass > vnum) {
4044 errorCode = FSERR_ELOOP;
4047 if (testnode == oldvptr->vnodeNumber) {
4048 testnode = oldvptr->disk.parent;
4051 if ((testnode == fileptr->vnodeNumber)
4052 || (testnode == newvptr->vnodeNumber)) {
4053 errorCode = FSERR_ELOOP;
4056 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
4057 errorCode = FSERR_ELOOP;
4060 if (testnode == 1) top = 1;
4061 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
4062 assert(errorCode == 0);
4063 testnode = testvptr->disk.parent;
4064 VPutVnode(&errorCode, testvptr);
4065 if ((top == 1) && (testnode != 0)) {
4066 VTakeOffline(volptr);
4068 ("Volume %u now offline, must be salvaged.\n",
4073 assert(errorCode == 0);
4076 /* Do the CopyonWrite first before modifying anything else. Copying is
4077 * required because we may have to change entries for ..
4079 if ((fileptr->disk.type == vDirectory) && (fileptr->disk.cloned)) {
4080 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
4081 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
4085 /* If the new name exists already, delete it and the file it points to */
4088 /* Delete NewName from its directory */
4089 code = Delete(&newdir, NewName);
4092 /* Drop the link count */
4093 newfileptr->disk.linkCount--;
4094 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4095 afs_fsize_t newSize;
4096 VN_GET_LEN(newSize, newfileptr);
4097 VAdjustDiskUsage((Error *) & errorCode, volptr,
4098 (afs_sfsize_t) - nBlocks(newSize), 0);
4099 if (VN_GET_INO(newfileptr)) {
4100 IH_REALLYCLOSE(newfileptr->handle);
4102 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
4103 V_parentId(volptr));
4104 IH_RELEASE(newfileptr->handle);
4105 if (errorCode == -1) {
4107 ("Del: inode=%s, name=%s, errno=%d\n",
4108 PrintInode(NULL, VN_GET_INO(newfileptr)),
4110 if ((errno != ENOENT) && (errno != EIO)
4111 && (errno != ENXIO))
4112 ViceLog(0, ("Do we need to fsck?"));
4115 VN_SET_INO(newfileptr, (Inode) 0);
4116 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4119 /* Link count did not drop to zero.
4120 * Mark NewName vnode as changed - updates stime.
4122 newfileptr->changed_newTime = 1;
4127 * If the create below fails, and the delete above worked, we have
4128 * removed the new name and not replaced it. This is not very likely,
4129 * but possible. We could try to put the old file back, but it is
4130 * highly unlikely that it would work since it would involve issuing
4133 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4136 /* Delete the old name */
4137 assert(Delete(&olddir, (char *)OldName) == 0);
4139 /* if the directory length changes, reflect it in the statistics */
4140 #if FS_STATS_DETAILED
4141 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4142 oldvptr->disk.linkCount, client->InSameNetwork);
4143 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4144 newvptr->disk.linkCount, client->InSameNetwork);
4146 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4147 oldvptr->disk.linkCount);
4148 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4149 newvptr->disk.linkCount);
4150 #endif /* FS_STATS_DETAILED */
4152 if (oldvptr == newvptr)
4153 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4155 fileptr->disk.parent = newvptr->vnodeNumber;
4156 fileptr->changed_newTime = 1; /* status change of moved file */
4158 /* if we are dealing with a rename of a directory */
4159 if (fileptr->disk.type == vDirectory) {
4160 assert(!fileptr->disk.cloned);
4161 SetDirHandle(&filedir, fileptr);
4162 /* fix .. to point to the correct place */
4163 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4164 assert(Create(&filedir, "..", NewDirFid) == 0);
4165 fileptr->disk.dataVersion++;
4166 /* if the parent directories are different the link counts have to be */
4167 /* changed due to .. in the renamed directory */
4168 if (oldvptr != newvptr) {
4169 oldvptr->disk.linkCount--;
4170 newvptr->disk.linkCount++;
4174 /* set up return status */
4175 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4176 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4177 if (newfileptr && doDelete) {
4178 DeleteFileCallBacks(&newFileFid); /* no other references */
4183 /* convert the write locks to a read locks before breaking callbacks */
4184 VVnodeWriteToRead(&errorCode, newvptr);
4185 assert(!errorCode || errorCode == VSALVAGE);
4186 if (oldvptr != newvptr) {
4187 VVnodeWriteToRead(&errorCode, oldvptr);
4188 assert(!errorCode || errorCode == VSALVAGE);
4190 if (newfileptr && !doDelete) {
4191 /* convert the write lock to a read lock before breaking callbacks */
4192 VVnodeWriteToRead(&errorCode, newfileptr);
4193 assert(!errorCode || errorCode == VSALVAGE);
4196 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4197 BreakCallBack(client->host, NewDirFid, 0);
4198 if (oldvptr != newvptr) {
4199 BreakCallBack(client->host, OldDirFid, 0);
4200 if (fileptr->disk.type == vDirectory) /* if a dir moved, .. changed */
4201 BreakCallBack(client->host, &fileFid, 0);
4204 /* Note: it is not necessary to break the callback */
4206 DeleteFileCallBacks(&newFileFid); /* no other references */
4208 /* other's still exist (with wrong link count) */
4209 BreakCallBack(client->host, &newFileFid, 1);
4214 VPutVnode(&fileCode, newfileptr);
4215 assert(fileCode == 0);
4217 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
4218 newvptr : 0), oldvptr, volptr, &client);
4222 FidZap(&newfiledir);
4223 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4230 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4231 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4232 struct AFSFetchStatus * OutOldDirStatus,
4233 struct AFSFetchStatus * OutNewDirStatus,
4234 struct AFSVolSync * Sync)
4237 struct rx_connection *tcon;
4239 struct client *t_client = NULL; /* tmp ptr to client data */
4240 #if FS_STATS_DETAILED
4241 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4242 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4243 struct timeval elapsedTime; /* Transfer time */
4246 * Set our stats pointer, remember when the RPC operation started, and
4247 * tally the operation.
4249 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4253 FT_GetTimeOfDay(&opStartTime, 0);
4254 #endif /* FS_STATS_DETAILED */
4256 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4260 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4261 OutOldDirStatus, OutNewDirStatus, Sync);
4264 code = CallPostamble(tcon, code, thost);
4266 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4268 #if FS_STATS_DETAILED
4269 FT_GetTimeOfDay(&opStopTime, 0);
4272 (opP->numSuccesses)++;
4273 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4274 fs_stats_AddTo((opP->sumTime), elapsedTime);
4275 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4276 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4277 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4279 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4280 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4284 #endif /* FS_STATS_DETAILED */
4286 osi_auditU(acall, RenameFileEvent, code,
4287 AUD_ID, t_client ? t_client->ViceId : 0,
4288 AUD_FID, OldDirFid, AUD_STR, OldName,
4289 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4292 } /*SRXAFS_Rename */
4296 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4297 * merged into it when possible.
4300 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4301 char *LinkContents, struct AFSStoreStatus *InStatus,
4302 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4303 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4305 Vnode *parentptr = 0; /* vnode of input Directory */
4306 Vnode *targetptr = 0; /* vnode of the new link */
4307 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4308 Error errorCode = 0; /* error code */
4310 DirHandle dir; /* Handle for dir package I/O */
4311 Volume *volptr = 0; /* pointer to the volume header */
4312 struct client *client = 0; /* pointer to client structure */
4313 afs_int32 rights, anyrights; /* rights for this and any user */
4314 struct client *t_client; /* tmp ptr to client data */
4315 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4317 struct rx_connection *tcon = rx_ConnectionOf(acall);
4321 /* Get ptr to client data for user Id for logging */
4322 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4323 logHostAddr.s_addr = rxr_HostOf(tcon);
4325 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4326 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4327 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4329 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4331 if (!FileNameOK(Name)) {
4337 * Get the vnode and volume for the parent dir along with the caller's
4341 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4342 &parentwhentargetnotdir, &client, WRITE_LOCK,
4343 &rights, &anyrights))) {
4347 /* set volume synchronization information */
4348 SetVolumeSync(Sync, volptr);
4350 /* Does the caller has insert (and write) access to the parent directory? */
4351 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4356 * If we're creating a mount point (any x bits clear), we must have
4357 * administer access to the directory, too. Always allow sysadmins
4360 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4361 if (readonlyServer) {
4362 errorCode = VREADONLY;
4366 * We have a mountpoint, 'cause we're trying to set the Unix mode
4367 * bits to something with some x bits missing (default mode bits
4368 * if AFS_SETMODE is false is 0777)
4370 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4376 /* get a new vnode for the symlink and set it up */
4378 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4379 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4383 /* update the status of the parent vnode */
4384 #if FS_STATS_DETAILED
4385 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4386 parentptr->disk.linkCount,
4387 client->InSameNetwork);
4389 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4390 parentptr->disk.linkCount);
4391 #endif /* FS_STATS_DETAILED */
4393 /* update the status of the new symbolic link file vnode */
4394 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4395 parentptr, volptr, strlen((char *)LinkContents));
4397 /* Write the contents of the symbolic link name into the target inode */
4398 fdP = IH_OPEN(targetptr->handle);
4400 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4402 VTakeOffline(volptr);
4403 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
4407 len = strlen((char *) LinkContents);
4408 code = (len == FDH_WRITE(fdP, (char *) LinkContents, len)) ? 0 : VDISKFULL;
4410 ViceLog(0, ("SAFSS_Symlink FDH_WRITE failed for len=%d, Fid=%u.%d.%d\n", len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4413 * Set up and return modified status for the parent dir and new symlink
4416 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4417 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4419 /* convert the write lock to a read lock before breaking callbacks */
4420 VVnodeWriteToRead(&errorCode, parentptr);
4421 assert(!errorCode || errorCode == VSALVAGE);
4423 /* break call back on the parent dir */
4424 BreakCallBack(client->host, DirFid, 0);
4427 /* Write the all modified vnodes (parent, new files) and volume back */
4428 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4431 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4432 return ( errorCode ? errorCode : code );
4434 } /*SAFSS_Symlink */
4438 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4439 struct AFSFid *DirFid, /* Parent dir's fid */
4440 char *Name, /* File name to create */
4441 char *LinkContents, /* Contents of the new created file */
4442 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4443 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4444 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4445 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4446 struct AFSVolSync *Sync)
4449 struct rx_connection *tcon;
4451 struct client *t_client = NULL; /* tmp ptr to client data */
4452 #if FS_STATS_DETAILED
4453 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4454 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4455 struct timeval elapsedTime; /* Transfer time */
4458 * Set our stats pointer, remember when the RPC operation started, and
4459 * tally the operation.
4461 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4465 FT_GetTimeOfDay(&opStartTime, 0);
4466 #endif /* FS_STATS_DETAILED */
4468 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4472 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4473 OutFidStatus, OutDirStatus, Sync);
4476 code = CallPostamble(tcon, code, thost);
4478 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4480 #if FS_STATS_DETAILED
4481 FT_GetTimeOfDay(&opStopTime, 0);
4484 (opP->numSuccesses)++;
4485 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4486 fs_stats_AddTo((opP->sumTime), elapsedTime);
4487 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4488 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4489 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4491 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4492 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4496 #endif /* FS_STATS_DETAILED */
4498 osi_auditU(acall, SymlinkEvent, code,
4499 AUD_ID, t_client ? t_client->ViceId : 0,
4500 AUD_FID, DirFid, AUD_STR, Name,
4501 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4504 } /*SRXAFS_Symlink */
4508 * This routine is called exclusively by SRXAFS_Link(), and should be
4509 * merged into it when possible.
4512 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4513 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4514 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4516 Vnode *parentptr = 0; /* vnode of input Directory */
4517 Vnode *targetptr = 0; /* vnode of the new file */
4518 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4519 Volume *volptr = 0; /* pointer to the volume header */
4520 Error errorCode = 0; /* error code */
4521 DirHandle dir; /* Handle for dir package I/O */
4522 struct client *client = 0; /* pointer to client structure */
4523 afs_int32 rights, anyrights; /* rights for this and any user */
4524 struct client *t_client; /* tmp ptr to client data */
4525 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4526 struct rx_connection *tcon = rx_ConnectionOf(acall);
4530 /* Get ptr to client data for user Id for logging */
4531 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4532 logHostAddr.s_addr = rxr_HostOf(tcon);
4534 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4535 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4536 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4537 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4539 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4541 if (DirFid->Volume != ExistingFid->Volume) {
4545 if (!FileNameOK(Name)) {
4551 * Get the vnode and volume for the parent dir along with the caller's
4555 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4556 &parentwhentargetnotdir, &client, WRITE_LOCK,
4557 &rights, &anyrights))) {
4561 /* set volume synchronization information */
4562 SetVolumeSync(Sync, volptr);
4564 /* Can the caller insert into the parent directory? */
4565 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4569 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4570 /* AFS fileservers always have directory vnodes that are odd. */
4575 /* get the file vnode */
4577 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4580 if (targetptr->disk.type != vFile) {
4584 if (targetptr->disk.parent != DirFid->Vnode) {
4588 if (parentptr->disk.cloned) {
4589 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4590 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4591 goto Bad_Link; /* disk full error */
4594 /* add the name to the directory */
4595 SetDirHandle(&dir, parentptr);
4596 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4600 /* update the status in the parent vnode */
4601 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4602 #if FS_STATS_DETAILED
4603 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4604 parentptr->disk.linkCount,
4605 client->InSameNetwork);
4607 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4608 parentptr->disk.linkCount);
4609 #endif /* FS_STATS_DETAILED */
4611 targetptr->disk.linkCount++;
4612 targetptr->disk.author = client->ViceId;
4613 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4615 /* set up return status */
4616 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4617 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4619 /* convert the write locks to read locks before breaking callbacks */
4620 VVnodeWriteToRead(&errorCode, targetptr);
4621 assert(!errorCode || errorCode == VSALVAGE);
4622 VVnodeWriteToRead(&errorCode, parentptr);
4623 assert(!errorCode || errorCode == VSALVAGE);
4625 /* break call back on DirFid */
4626 BreakCallBack(client->host, DirFid, 0);
4628 * We also need to break the callback for the file that is hard-linked since part
4629 * of its status (like linkcount) is changed
4631 BreakCallBack(client->host, ExistingFid, 0);
4634 /* Write the all modified vnodes (parent, new files) and volume back */
4635 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4638 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4645 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4646 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4647 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4650 struct rx_connection *tcon;
4652 struct client *t_client = NULL; /* tmp ptr to client data */
4653 #if FS_STATS_DETAILED
4654 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4655 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4656 struct timeval elapsedTime; /* Transfer time */
4659 * Set our stats pointer, remember when the RPC operation started, and
4660 * tally the operation.
4662 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4666 FT_GetTimeOfDay(&opStartTime, 0);
4667 #endif /* FS_STATS_DETAILED */
4669 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4673 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4674 OutDirStatus, Sync);
4677 code = CallPostamble(tcon, code, thost);
4679 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4681 #if FS_STATS_DETAILED
4682 FT_GetTimeOfDay(&opStopTime, 0);
4685 (opP->numSuccesses)++;
4686 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4687 fs_stats_AddTo((opP->sumTime), elapsedTime);
4688 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4689 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4690 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4692 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4693 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4697 #endif /* FS_STATS_DETAILED */
4699 osi_auditU(acall, LinkEvent, code,
4700 AUD_ID, t_client ? t_client->ViceId : 0,
4701 AUD_FID, DirFid, AUD_STR, Name,
4702 AUD_FID, ExistingFid, AUD_END);
4709 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4710 * merged into it when possible.
4713 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4714 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4715 struct AFSFetchStatus *OutFidStatus,
4716 struct AFSFetchStatus *OutDirStatus,
4717 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4719 Vnode *parentptr = 0; /* vnode of input Directory */
4720 Vnode *targetptr = 0; /* vnode of the new file */
4721 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4722 Volume *volptr = 0; /* pointer to the volume header */
4723 Error errorCode = 0; /* error code */
4724 struct acl_accessList *newACL; /* Access list */
4725 int newACLSize; /* Size of access list */
4726 DirHandle dir; /* Handle for dir package I/O */
4727 DirHandle parentdir; /* Handle for dir package I/O */
4728 struct client *client = 0; /* pointer to client structure */
4729 afs_int32 rights, anyrights; /* rights for this and any user */
4730 struct client *t_client; /* tmp ptr to client data */
4731 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4732 struct rx_connection *tcon = rx_ConnectionOf(acall);
4735 FidZero(&parentdir);
4737 /* Get ptr to client data for user Id for logging */
4738 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4739 logHostAddr.s_addr = rxr_HostOf(tcon);
4741 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4742 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4743 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4745 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4747 if (!FileNameOK(Name)) {
4753 * Get the vnode and volume for the parent dir along with the caller's
4757 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4758 &parentwhentargetnotdir, &client, WRITE_LOCK,
4759 &rights, &anyrights))) {
4763 /* set volume synchronization information */
4764 SetVolumeSync(Sync, volptr);
4766 /* Write access to the parent directory? */
4767 #ifdef DIRCREATE_NEED_WRITE
4769 * requires w access for the user to create a directory. this
4770 * closes a loophole in the current security arrangement, since a
4771 * user with i access only can create a directory and get the
4772 * implcit a access that goes with dir ownership, and proceed to
4773 * subvert quota in the volume.
4775 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4776 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4778 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4779 #endif /* DIRCREATE_NEED_WRITE */
4782 #define EMPTYDIRBLOCKS 2
4783 /* get a new vnode and set it up */
4785 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4786 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4790 /* Update the status for the parent dir */
4791 #if FS_STATS_DETAILED
4792 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4793 parentptr->disk.linkCount + 1,
4794 client->InSameNetwork);
4796 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4797 parentptr->disk.linkCount + 1);
4798 #endif /* FS_STATS_DETAILED */
4800 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4801 assert((SetAccessList
4802 (&targetptr, &volptr, &newACL, &newACLSize,
4803 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4804 assert(parentwhentargetnotdir == 0);
4805 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4807 /* update the status for the target vnode */
4808 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4809 parentptr, volptr, 0);
4811 /* Actually create the New directory in the directory package */
4812 SetDirHandle(&dir, targetptr);
4813 assert(!(MakeDir(&dir, OutFid, DirFid)));
4815 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4817 /* set up return status */
4818 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4819 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4821 /* convert the write lock to a read lock before breaking callbacks */
4822 VVnodeWriteToRead(&errorCode, parentptr);
4823 assert(!errorCode || errorCode == VSALVAGE);
4825 /* break call back on DirFid */
4826 BreakCallBack(client->host, DirFid, 0);
4828 /* Return a callback promise to caller */
4829 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4832 /* Write the all modified vnodes (parent, new files) and volume back */
4833 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4837 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4840 } /*SAFSS_MakeDir */
4844 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4845 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4846 struct AFSFetchStatus * OutFidStatus,
4847 struct AFSFetchStatus * OutDirStatus,
4848 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4851 struct rx_connection *tcon;
4853 struct client *t_client = NULL; /* tmp ptr to client data */
4854 #if FS_STATS_DETAILED
4855 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4856 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4857 struct timeval elapsedTime; /* Transfer time */
4860 * Set our stats pointer, remember when the RPC operation started, and
4861 * tally the operation.
4863 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
4867 FT_GetTimeOfDay(&opStartTime, 0);
4868 #endif /* FS_STATS_DETAILED */
4869 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4873 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4874 OutDirStatus, CallBack, Sync);
4877 code = CallPostamble(tcon, code, thost);
4879 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4881 #if FS_STATS_DETAILED
4882 FT_GetTimeOfDay(&opStopTime, 0);
4885 (opP->numSuccesses)++;
4886 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4887 fs_stats_AddTo((opP->sumTime), elapsedTime);
4888 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4889 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4890 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4892 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4893 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4897 #endif /* FS_STATS_DETAILED */
4899 osi_auditU(acall, MakeDirEvent, code,
4900 AUD_ID, t_client ? t_client->ViceId : 0,
4901 AUD_FID, DirFid, AUD_STR, Name,
4902 AUD_FID, OutFid, AUD_END);
4905 } /*SRXAFS_MakeDir */
4909 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4910 * merged into it when possible.
4913 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4914 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4916 Vnode *parentptr = 0; /* vnode of input Directory */
4917 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4918 Vnode *targetptr = 0; /* file to be deleted */
4919 AFSFid fileFid; /* area for Fid from the directory */
4920 Error errorCode = 0; /* error code */
4921 DirHandle dir; /* Handle for dir package I/O */
4922 Volume *volptr = 0; /* pointer to the volume header */
4923 struct client *client = 0; /* pointer to client structure */
4924 afs_int32 rights, anyrights; /* rights for this and any user */
4925 Vnode debugvnode1, debugvnode2;
4926 struct client *t_client; /* tmp ptr to client data */
4927 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4928 struct rx_connection *tcon = rx_ConnectionOf(acall);
4932 /* Get ptr to client data for user Id for logging */
4933 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4934 logHostAddr.s_addr = rxr_HostOf(tcon);
4936 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4937 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4938 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4940 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4943 * Get the vnode and volume for the parent dir along with the caller's
4947 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4948 &parentwhentargetnotdir, &client, WRITE_LOCK,
4949 &rights, &anyrights))) {
4952 debugvnode1 = *parentptr;
4954 /* set volume synchronization information */
4955 SetVolumeSync(Sync, volptr);
4957 /* Does the caller has delete (&write) access to the parent dir? */
4958 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
4962 debugvnode2 = *parentptr;
4963 /* Do the actual delete of the desired (empty) directory, Name */
4965 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
4970 /* Update the status for the parent dir; link count is also adjusted */
4971 #if FS_STATS_DETAILED
4972 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4973 parentptr->disk.linkCount - 1,
4974 client->InSameNetwork);
4976 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4977 parentptr->disk.linkCount - 1);
4978 #endif /* FS_STATS_DETAILED */
4980 /* Return to the caller the updated parent dir status */
4981 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4984 * Note: it is not necessary to break the callback on fileFid, since
4985 * refcount is now 0, so no one should be able to refer to the dir
4988 DeleteFileCallBacks(&fileFid);
4990 /* convert the write lock to a read lock before breaking callbacks */
4991 VVnodeWriteToRead(&errorCode, parentptr);
4992 assert(!errorCode || errorCode == VSALVAGE);
4994 /* break call back on DirFid and fileFid */
4995 BreakCallBack(client->host, DirFid, 0);
4998 /* Write the all modified vnodes (parent, new files) and volume back */
4999 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
5002 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
5005 } /*SAFSS_RemoveDir */
5009 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
5010 struct AFSFetchStatus * OutDirStatus,
5011 struct AFSVolSync * Sync)
5014 struct rx_connection *tcon;
5016 struct client *t_client = NULL; /* tmp ptr to client data */
5017 #if FS_STATS_DETAILED
5018 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5019 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5020 struct timeval elapsedTime; /* Transfer time */
5023 * Set our stats pointer, remember when the RPC operation started, and
5024 * tally the operation.
5026 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
5030 FT_GetTimeOfDay(&opStartTime, 0);
5031 #endif /* FS_STATS_DETAILED */
5033 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5036 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
5039 code = CallPostamble(tcon, code, thost);
5041 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5043 #if FS_STATS_DETAILED
5044 FT_GetTimeOfDay(&opStopTime, 0);
5047 (opP->numSuccesses)++;
5048 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5049 fs_stats_AddTo((opP->sumTime), elapsedTime);
5050 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5051 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5052 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5054 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5055 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5059 #endif /* FS_STATS_DETAILED */
5061 osi_auditU(acall, RemoveDirEvent, code,
5062 AUD_ID, t_client ? t_client->ViceId : 0,
5063 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
5066 } /*SRXAFS_RemoveDir */
5070 * This routine is called exclusively by SRXAFS_SetLock(), and should be
5071 * merged into it when possible.
5074 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
5075 struct AFSVolSync *Sync)
5077 Vnode *targetptr = 0; /* vnode of input file */
5078 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5079 Error errorCode = 0; /* error code */
5080 Volume *volptr = 0; /* pointer to the volume header */
5081 struct client *client = 0; /* pointer to client structure */
5082 afs_int32 rights, anyrights; /* rights for this and any user */
5083 struct client *t_client; /* tmp ptr to client data */
5084 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5085 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
5086 struct rx_connection *tcon = rx_ConnectionOf(acall);
5088 if (type != LockRead && type != LockWrite) {
5092 /* Get ptr to client data for user Id for logging */
5093 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5094 logHostAddr.s_addr = rxr_HostOf(tcon);
5096 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
5097 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
5098 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5100 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
5103 * Get the vnode and volume for the desired file along with the caller's
5107 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5108 &parentwhentargetnotdir, &client, WRITE_LOCK,
5109 &rights, &anyrights))) {
5113 /* set volume synchronization information */
5114 SetVolumeSync(Sync, volptr);
5116 /* Handle the particular type of set locking, type */
5117 errorCode = HandleLocking(targetptr, client, rights, type);
5120 /* Write the all modified vnodes (parent, new files) and volume back */
5121 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5124 if ((errorCode == VREADONLY) && (type == LockRead))
5125 errorCode = 0; /* allow read locks on RO volumes without saving state */
5127 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
5130 } /*SAFSS_SetLock */
5134 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
5135 ViceLockType type, struct AFSVolSync * Sync)
5137 return SRXAFS_SetLock(acall, Fid, type, Sync);
5138 } /*SRXAFS_OldSetLock */
5142 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
5143 struct AFSVolSync * Sync)
5146 struct rx_connection *tcon;
5148 struct client *t_client = NULL; /* tmp ptr to client data */
5149 #if FS_STATS_DETAILED
5150 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5151 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5152 struct timeval elapsedTime; /* Transfer time */
5155 * Set our stats pointer, remember when the RPC operation started, and
5156 * tally the operation.
5158 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5162 FT_GetTimeOfDay(&opStartTime, 0);
5163 #endif /* FS_STATS_DETAILED */
5165 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5168 code = SAFSS_SetLock(acall, Fid, type, Sync);
5171 code = CallPostamble(tcon, code, thost);
5173 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5175 #if FS_STATS_DETAILED
5176 FT_GetTimeOfDay(&opStopTime, 0);
5179 (opP->numSuccesses)++;
5180 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5181 fs_stats_AddTo((opP->sumTime), elapsedTime);
5182 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5183 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5184 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5186 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5187 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5191 #endif /* FS_STATS_DETAILED */
5193 osi_auditU(acall, SetLockEvent, code,
5194 AUD_ID, t_client ? t_client->ViceId : 0,
5195 AUD_FID, Fid, AUD_LONG, type, AUD_END);
5197 } /*SRXAFS_SetLock */
5201 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5202 * merged into it when possible.
5205 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5206 struct AFSVolSync *Sync)
5208 Vnode *targetptr = 0; /* vnode of input file */
5209 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5210 Error errorCode = 0; /* error code */
5211 Volume *volptr = 0; /* pointer to the volume header */
5212 struct client *client = 0; /* pointer to client structure */
5213 afs_int32 rights, anyrights; /* rights for this and any user */
5214 struct client *t_client; /* tmp ptr to client data */
5215 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5216 struct rx_connection *tcon = rx_ConnectionOf(acall);
5218 /* Get ptr to client data for user Id for logging */
5219 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5220 logHostAddr.s_addr = rxr_HostOf(tcon);
5222 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5223 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5224 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5226 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5229 * Get the vnode and volume for the desired file along with the caller's
5233 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5234 &parentwhentargetnotdir, &client, WRITE_LOCK,
5235 &rights, &anyrights))) {
5236 goto Bad_ExtendLock;
5239 /* set volume synchronization information */
5240 SetVolumeSync(Sync, volptr);
5242 /* Handle the actual lock extension */
5243 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
5246 /* Put back file's vnode and volume */
5247 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5250 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5251 errorCode = 0; /* under our generous policy re RO vols */
5253 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5256 } /*SAFSS_ExtendLock */
5260 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5261 struct AFSVolSync * Sync)
5263 return SRXAFS_ExtendLock(acall, Fid, Sync);
5264 } /*SRXAFS_OldExtendLock */
5268 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5269 struct AFSVolSync * Sync)
5272 struct rx_connection *tcon;
5274 struct client *t_client = NULL; /* tmp ptr to client data */
5275 #if FS_STATS_DETAILED
5276 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5277 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5278 struct timeval elapsedTime; /* Transfer time */
5281 * Set our stats pointer, remember when the RPC operation started, and
5282 * tally the operation.
5284 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5288 FT_GetTimeOfDay(&opStartTime, 0);
5289 #endif /* FS_STATS_DETAILED */
5291 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5292 goto Bad_ExtendLock;
5294 code = SAFSS_ExtendLock(acall, Fid, Sync);
5297 code = CallPostamble(tcon, code, thost);
5299 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5301 #if FS_STATS_DETAILED
5302 FT_GetTimeOfDay(&opStopTime, 0);
5305 (opP->numSuccesses)++;
5306 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5307 fs_stats_AddTo((opP->sumTime), elapsedTime);
5308 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5309 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5310 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5312 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5313 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5317 #endif /* FS_STATS_DETAILED */
5319 osi_auditU(acall, ExtendLockEvent, code,
5320 AUD_ID, t_client ? t_client->ViceId : 0,
5321 AUD_FID, Fid, AUD_END);
5324 } /*SRXAFS_ExtendLock */
5328 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5329 * merged into it when possible.
5332 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5333 struct AFSVolSync *Sync)
5335 Vnode *targetptr = 0; /* vnode of input file */
5336 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5337 Error errorCode = 0; /* error code */
5338 Volume *volptr = 0; /* pointer to the volume header */
5339 struct client *client = 0; /* pointer to client structure */
5340 afs_int32 rights, anyrights; /* rights for this and any user */
5341 struct client *t_client; /* tmp ptr to client data */
5342 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5343 struct rx_connection *tcon = rx_ConnectionOf(acall);
5345 /* Get ptr to client data for user Id for logging */
5346 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5347 logHostAddr.s_addr = rxr_HostOf(tcon);
5349 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5350 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5351 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5353 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5356 * Get the vnode and volume for the desired file along with the caller's
5360 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5361 &parentwhentargetnotdir, &client, WRITE_LOCK,
5362 &rights, &anyrights))) {
5363 goto Bad_ReleaseLock;
5366 /* set volume synchronization information */
5367 SetVolumeSync(Sync, volptr);
5369 /* Handle the actual lock release */
5370 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
5371 goto Bad_ReleaseLock;
5373 /* if no more locks left, a callback would be triggered here */
5374 if (targetptr->disk.lock.lockCount <= 0) {
5375 /* convert the write lock to a read lock before breaking callbacks */
5376 VVnodeWriteToRead(&errorCode, targetptr);
5377 assert(!errorCode || errorCode == VSALVAGE);
5378 BreakCallBack(client->host, Fid, 0);
5382 /* Put back file's vnode and volume */
5383 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5386 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5387 errorCode = 0; /* under our generous policy re RO vols */
5389 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5392 } /*SAFSS_ReleaseLock */
5396 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5397 struct AFSVolSync * Sync)
5399 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5400 } /*SRXAFS_OldReleaseLock */
5404 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5405 struct AFSVolSync * Sync)
5408 struct rx_connection *tcon;
5410 struct client *t_client = NULL; /* tmp ptr to client data */
5411 #if FS_STATS_DETAILED
5412 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5413 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5414 struct timeval elapsedTime; /* Transfer time */
5417 * Set our stats pointer, remember when the RPC operation started, and
5418 * tally the operation.
5420 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5424 FT_GetTimeOfDay(&opStartTime, 0);
5425 #endif /* FS_STATS_DETAILED */
5427 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5428 goto Bad_ReleaseLock;
5430 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5433 code = CallPostamble(tcon, code, thost);
5435 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5437 #if FS_STATS_DETAILED
5438 FT_GetTimeOfDay(&opStopTime, 0);
5441 (opP->numSuccesses)++;
5442 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5443 fs_stats_AddTo((opP->sumTime), elapsedTime);
5444 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5445 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5446 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5448 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5449 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5453 #endif /* FS_STATS_DETAILED */
5455 osi_auditU(acall, ReleaseLockEvent, code,
5456 AUD_ID, t_client ? t_client->ViceId : 0,
5457 AUD_FID, Fid, AUD_END);
5460 } /*SRXAFS_ReleaseLock */
5464 SetSystemStats(struct AFSStatistics *stats)
5466 /* Fix this sometime soon.. */
5467 /* Because hey, it's not like we have a network monitoring protocol... */
5468 struct timeval time;
5470 /* this works on all system types */
5471 FT_GetTimeOfDay(&time, 0);
5472 stats->CurrentTime = time.tv_sec;
5473 } /*SetSystemStats */
5476 SetAFSStats(struct AFSStatistics *stats)
5478 extern afs_int32 StartTime, CurrentConnections;
5482 stats->CurrentMsgNumber = 0;
5483 stats->OldestMsgNumber = 0;
5484 stats->StartTime = StartTime;
5485 stats->CurrentConnections = CurrentConnections;
5486 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5487 stats->TotalFetchs =
5488 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5489 AFSCallStats.FetchStatus;
5490 stats->FetchDatas = AFSCallStats.FetchData;
5491 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5492 seconds = AFSCallStats.AccumFetchTime / 1000;
5495 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5496 stats->TotalStores =
5497 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5498 AFSCallStats.StoreStatus;
5499 stats->StoreDatas = AFSCallStats.StoreData;
5500 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5501 seconds = AFSCallStats.AccumStoreTime / 1000;
5504 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5506 stats->ProcessSize = -1; /* TODO: */
5508 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5511 h_GetWorkStats((int *)&(stats->WorkStations),
5512 (int *)&(stats->ActiveWorkStations), (int *)0,
5513 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5517 /* Get disk related information from all AFS partitions. */
5520 SetVolumeStats(struct AFSStatistics *stats)
5522 struct DiskPartition64 *part;
5525 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5526 part = part->next) {
5527 stats->Disks[i].TotalBlocks = RoundInt64ToInt32(part->totalUsable);
5528 stats->Disks[i].BlocksAvailable = RoundInt64ToInt32(part->free);
5529 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5530 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5533 while (i < AFS_MSTATDISKS) {
5534 stats->Disks[i].TotalBlocks = -1;
5537 } /*SetVolumeStats */
5540 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5543 struct rx_connection *tcon = rx_ConnectionOf(acall);
5545 struct client *t_client = NULL; /* tmp ptr to client data */
5546 #if FS_STATS_DETAILED
5547 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5548 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5549 struct timeval elapsedTime; /* Transfer time */
5552 * Set our stats pointer, remember when the RPC operation started, and
5553 * tally the operation.
5555 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5559 FT_GetTimeOfDay(&opStartTime, 0);
5560 #endif /* FS_STATS_DETAILED */
5562 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5563 goto Bad_GetStatistics;
5565 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5567 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5569 memset(Statistics, 0, sizeof(*Statistics));
5570 SetAFSStats((struct AFSStatistics *)Statistics);
5571 SetVolumeStats((struct AFSStatistics *)Statistics);
5572 SetSystemStats((struct AFSStatistics *)Statistics);
5575 code = CallPostamble(tcon, code, thost);
5577 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5579 #if FS_STATS_DETAILED
5580 FT_GetTimeOfDay(&opStopTime, 0);
5583 (opP->numSuccesses)++;
5584 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5585 fs_stats_AddTo((opP->sumTime), elapsedTime);
5586 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5587 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5588 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5590 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5591 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5595 #endif /* FS_STATS_DETAILED */
5597 osi_auditU(acall, GetStatisticsEvent, code,
5598 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5600 } /*SRXAFS_GetStatistics */
5604 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5606 extern afs_int32 StartTime, CurrentConnections;
5609 struct rx_connection *tcon = rx_ConnectionOf(acall);
5611 struct client *t_client = NULL; /* tmp ptr to client data */
5612 struct timeval time;
5613 #if FS_STATS_DETAILED
5614 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5615 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5616 struct timeval elapsedTime; /* Transfer time */
5619 * Set our stats pointer, remember when the RPC operation started, and
5620 * tally the operation.
5622 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5626 FT_GetTimeOfDay(&opStartTime, 0);
5627 #endif /* FS_STATS_DETAILED */
5629 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5630 goto Bad_GetStatistics64;
5632 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5633 Statistics->ViceStatistics64_val =
5634 malloc(statsVersion*sizeof(afs_int64));
5635 Statistics->ViceStatistics64_len = statsVersion;
5637 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5638 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5639 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5641 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5642 AFSCallStats.TotalCalls;
5643 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5644 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5645 AFSCallStats.FetchStatus;
5646 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5647 AFSCallStats.FetchData;
5648 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5649 AFSCallStats.TotalFetchedBytes;
5650 seconds = AFSCallStats.AccumFetchTime / 1000;
5653 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5654 AFSCallStats.TotalFetchedBytes / seconds;
5655 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5656 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5657 AFSCallStats.StoreStatus;
5658 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5659 AFSCallStats.StoreData;
5660 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5661 AFSCallStats.TotalStoredBytes;
5662 seconds = AFSCallStats.AccumStoreTime / 1000;
5665 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5666 AFSCallStats.TotalStoredBytes / seconds;
5668 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = -1;
5670 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] =
5671 (afs_int32) ((long)sbrk(0) >> 10);
5674 h_GetWorkStats((int *)&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5675 (int *)&(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5677 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5681 /* this works on all system types */
5682 FT_GetTimeOfDay(&time, 0);
5683 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
5685 Bad_GetStatistics64:
5686 code = CallPostamble(tcon, code, thost);
5688 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5690 #if FS_STATS_DETAILED
5691 FT_GetTimeOfDay(&opStopTime, 0);
5694 (opP->numSuccesses)++;
5695 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5696 fs_stats_AddTo((opP->sumTime), elapsedTime);
5697 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5698 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5699 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5701 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5702 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5706 #endif /* FS_STATS_DETAILED */
5708 osi_auditU(acall, GetStatisticsEvent, code,
5709 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5711 } /*SRXAFS_GetStatistics */
5714 /*------------------------------------------------------------------------
5715 * EXPORTED SRXAFS_XStatsVersion
5718 * Routine called by the server-side RPC interface to implement
5719 * pulling out the xstat version number for the File Server.
5722 * a_versionP : Ptr to the version number variable to set.
5728 * Nothing interesting.
5732 *------------------------------------------------------------------------*/
5735 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5736 { /*SRXAFS_XStatsVersion */
5738 struct client *t_client = NULL; /* tmp ptr to client data */
5739 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5740 #if FS_STATS_DETAILED
5741 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5742 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5743 struct timeval elapsedTime; /* Transfer time */
5746 * Set our stats pointer, remember when the RPC operation started, and
5747 * tally the operation.
5749 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5753 FT_GetTimeOfDay(&opStartTime, 0);
5754 #endif /* FS_STATS_DETAILED */
5756 *a_versionP = AFS_XSTAT_VERSION;
5758 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5760 #if FS_STATS_DETAILED
5761 FT_GetTimeOfDay(&opStopTime, 0);
5762 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5763 fs_stats_AddTo((opP->sumTime), elapsedTime);
5764 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5765 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5766 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5768 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5769 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5772 (opP->numSuccesses)++;
5774 #endif /* FS_STATS_DETAILED */
5776 osi_auditU(a_call, XStatsVersionEvent, 0,
5777 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5779 } /*SRXAFS_XStatsVersion */
5782 /*------------------------------------------------------------------------
5783 * PRIVATE FillPerfValues
5786 * Routine called to fill a regular performance data structure.
5789 * a_perfP : Ptr to perf structure to fill
5795 * Various collections need this info, so the guts were put in
5796 * this separate routine.
5800 *------------------------------------------------------------------------*/
5803 FillPerfValues(struct afs_PerfStats *a_perfP)
5804 { /*FillPerfValues */
5806 int dir_Buffers; /*# buffers in use by dir package */
5807 int dir_Calls; /*# read calls in dir package */
5808 int dir_IOs; /*# I/O ops in dir package */
5811 * Vnode cache section.
5813 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5814 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5815 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5816 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5817 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5818 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5819 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5820 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5821 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5822 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5823 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5824 SplitInt64(VStats.hdr_gets, hi, lo);
5825 a_perfP->vcache_H_Gets = lo;
5826 SplitInt64(VStats.hdr_loads, hi, lo);
5827 a_perfP->vcache_H_Replacements = lo;
5830 * Directory section.
5832 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5833 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5834 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5835 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5840 a_perfP->rx_packetRequests = (afs_int32) rx_stats.packetRequests;
5841 a_perfP->rx_noPackets_RcvClass =
5842 (afs_int32) rx_stats.receivePktAllocFailures;
5843 a_perfP->rx_noPackets_SendClass =
5844 (afs_int32) rx_stats.sendPktAllocFailures;
5845 a_perfP->rx_noPackets_SpecialClass =
5846 (afs_int32) rx_stats.specialPktAllocFailures;
5847 a_perfP->rx_socketGreedy = (afs_int32) rx_stats.socketGreedy;
5848 a_perfP->rx_bogusPacketOnRead = (afs_int32) rx_stats.bogusPacketOnRead;
5849 a_perfP->rx_bogusHost = (afs_int32) rx_stats.bogusHost;
5850 a_perfP->rx_noPacketOnRead = (afs_int32) rx_stats.noPacketOnRead;
5851 a_perfP->rx_noPacketBuffersOnRead =
5852 (afs_int32) rx_stats.noPacketBuffersOnRead;
5853 a_perfP->rx_selects = (afs_int32) rx_stats.selects;
5854 a_perfP->rx_sendSelects = (afs_int32) rx_stats.sendSelects;
5855 a_perfP->rx_packetsRead_RcvClass =
5856 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
5857 a_perfP->rx_packetsRead_SendClass =
5858 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
5859 a_perfP->rx_packetsRead_SpecialClass =
5860 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
5861 a_perfP->rx_dataPacketsRead = (afs_int32) rx_stats.dataPacketsRead;
5862 a_perfP->rx_ackPacketsRead = (afs_int32) rx_stats.ackPacketsRead;
5863 a_perfP->rx_dupPacketsRead = (afs_int32) rx_stats.dupPacketsRead;
5864 a_perfP->rx_spuriousPacketsRead =
5865 (afs_int32) rx_stats.spuriousPacketsRead;
5866 a_perfP->rx_packetsSent_RcvClass =
5867 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
5868 a_perfP->rx_packetsSent_SendClass =
5869 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
5870 a_perfP->rx_packetsSent_SpecialClass =
5871 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
5872 a_perfP->rx_ackPacketsSent = (afs_int32) rx_stats.ackPacketsSent;
5873 a_perfP->rx_pingPacketsSent = (afs_int32) rx_stats.pingPacketsSent;
5874 a_perfP->rx_abortPacketsSent = (afs_int32) rx_stats.abortPacketsSent;
5875 a_perfP->rx_busyPacketsSent = (afs_int32) rx_stats.busyPacketsSent;
5876 a_perfP->rx_dataPacketsSent = (afs_int32) rx_stats.dataPacketsSent;
5877 a_perfP->rx_dataPacketsReSent = (afs_int32) rx_stats.dataPacketsReSent;
5878 a_perfP->rx_dataPacketsPushed = (afs_int32) rx_stats.dataPacketsPushed;
5879 a_perfP->rx_ignoreAckedPacket = (afs_int32) rx_stats.ignoreAckedPacket;
5880 a_perfP->rx_totalRtt_Sec = (afs_int32) rx_stats.totalRtt.sec;
5881 a_perfP->rx_totalRtt_Usec = (afs_int32) rx_stats.totalRtt.usec;
5882 a_perfP->rx_minRtt_Sec = (afs_int32) rx_stats.minRtt.sec;
5883 a_perfP->rx_minRtt_Usec = (afs_int32) rx_stats.minRtt.usec;
5884 a_perfP->rx_maxRtt_Sec = (afs_int32) rx_stats.maxRtt.sec;
5885 a_perfP->rx_maxRtt_Usec = (afs_int32) rx_stats.maxRtt.usec;
5886 a_perfP->rx_nRttSamples = (afs_int32) rx_stats.nRttSamples;
5887 a_perfP->rx_nServerConns = (afs_int32) rx_stats.nServerConns;
5888 a_perfP->rx_nClientConns = (afs_int32) rx_stats.nClientConns;
5889 a_perfP->rx_nPeerStructs = (afs_int32) rx_stats.nPeerStructs;
5890 a_perfP->rx_nCallStructs = (afs_int32) rx_stats.nCallStructs;
5891 a_perfP->rx_nFreeCallStructs = (afs_int32) rx_stats.nFreeCallStructs;
5893 a_perfP->host_NumHostEntries = HTs;
5894 a_perfP->host_HostBlocks = HTBlocks;
5895 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5896 &(a_perfP->host_HostsInSameNetOrSubnet),
5897 &(a_perfP->host_HostsInDiffSubnet),
5898 &(a_perfP->host_HostsInDiffNetwork));
5899 a_perfP->host_NumClients = CEs;
5900 a_perfP->host_ClientBlocks = CEBlocks;
5902 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5903 a_perfP->rx_nBusies = (afs_int32) rx_stats.nBusies;
5904 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5905 } /*FillPerfValues */
5908 /*------------------------------------------------------------------------
5909 * EXPORTED SRXAFS_GetXStats
5912 * Routine called by the server-side callback RPC interface to
5913 * implement getting the given data collection from the extended
5914 * File Server statistics.
5917 * a_call : Ptr to Rx call on which this request came in.
5918 * a_clientVersionNum : Client version number.
5919 * a_opCode : Desired operation.
5920 * a_serverVersionNumP : Ptr to version number to set.
5921 * a_timeP : Ptr to time value (seconds) to set.
5922 * a_dataP : Ptr to variable array structure to return
5929 * Nothing interesting.
5933 *------------------------------------------------------------------------*/
5936 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5937 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5938 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5939 { /*SRXAFS_GetXStats */
5941 register int code; /*Return value */
5942 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5943 afs_int32 dataBytes; /*Bytes in data buffer */
5944 #if FS_STATS_DETAILED
5945 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5946 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5947 struct timeval elapsedTime; /* Transfer time */
5950 * Set our stats pointer, remember when the RPC operation started, and
5951 * tally the operation.
5953 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
5957 FT_GetTimeOfDay(&opStartTime, 0);
5958 #endif /* FS_STATS_DETAILED */
5961 * Record the time of day and the server version number.
5963 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5964 *a_timeP = FT_ApproxTime();
5967 * Stuff the appropriate data in there (assume victory)
5972 ("Received GetXStats call for collection %d\n",
5973 a_collectionNumber));
5977 * We're not keeping stats, so just return successfully with
5980 a_dataP->AFS_CollData_len = 0;
5981 a_dataP->AFS_CollData_val = NULL;
5984 switch (a_collectionNumber) {
5985 case AFS_XSTATSCOLL_CALL_INFO:
5987 * Pass back all the call-count-related data.
5989 * >>> We are forced to allocate a separate area in which to
5990 * >>> put this stuff in by the RPC stub generator, since it
5991 * >>> will be freed at the tail end of the server stub code.
5995 * I don't think call-level stats are being collected yet
5996 * for the File Server.
5998 dataBytes = sizeof(struct afs_Stats);
5999 dataBuffP = (afs_int32 *) malloc(dataBytes);
6000 memcpy(dataBuffP, &afs_cmstats, dataBytes);
6001 a_dataP->AFS_CollData_len = dataBytes >> 2;
6002 a_dataP->AFS_CollData_val = dataBuffP;
6004 a_dataP->AFS_CollData_len = 0;
6005 a_dataP->AFS_CollData_val = NULL;
6009 case AFS_XSTATSCOLL_PERF_INFO:
6011 * Pass back all the regular performance-related data.
6013 * >>> We are forced to allocate a separate area in which to
6014 * >>> put this stuff in by the RPC stub generator, since it
6015 * >>> will be freed at the tail end of the server stub code.
6018 afs_perfstats.numPerfCalls++;
6019 FillPerfValues(&afs_perfstats);
6022 * Don't overwrite the spares at the end.
6025 dataBytes = sizeof(struct afs_PerfStats);
6026 dataBuffP = (afs_int32 *) malloc(dataBytes);
6027 memcpy(dataBuffP, &afs_perfstats, dataBytes);
6028 a_dataP->AFS_CollData_len = dataBytes >> 2;
6029 a_dataP->AFS_CollData_val = dataBuffP;
6032 case AFS_XSTATSCOLL_FULL_PERF_INFO:
6034 * Pass back the full collection of performance-related data.
6035 * We have to stuff the basic, overall numbers in, but the
6036 * detailed numbers are kept in the structure already.
6038 * >>> We are forced to allocate a separate area in which to
6039 * >>> put this stuff in by the RPC stub generator, since it
6040 * >>> will be freed at the tail end of the server stub code.
6043 afs_perfstats.numPerfCalls++;
6044 #if FS_STATS_DETAILED
6045 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
6046 FillPerfValues(&afs_FullPerfStats.overall);
6049 * Don't overwrite the spares at the end.
6052 dataBytes = sizeof(struct fs_stats_FullPerfStats);
6053 dataBuffP = (afs_int32 *) malloc(dataBytes);
6054 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
6055 a_dataP->AFS_CollData_len = dataBytes >> 2;
6056 a_dataP->AFS_CollData_val = dataBuffP;
6060 case AFS_XSTATSCOLL_CBSTATS:
6061 afs_perfstats.numPerfCalls++;
6063 dataBytes = sizeof(struct cbcounters);
6064 dataBuffP = (afs_int32 *) malloc(dataBytes);
6066 extern struct cbcounters cbstuff;
6067 dataBuffP[0]=cbstuff.DeleteFiles;
6068 dataBuffP[1]=cbstuff.DeleteCallBacks;
6069 dataBuffP[2]=cbstuff.BreakCallBacks;
6070 dataBuffP[3]=cbstuff.AddCallBacks;
6071 dataBuffP[4]=cbstuff.GotSomeSpaces;
6072 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
6073 dataBuffP[6]=cbstuff.nFEs;
6074 dataBuffP[7]=cbstuff.nCBs;
6075 dataBuffP[8]=cbstuff.nblks;
6076 dataBuffP[9]=cbstuff.CBsTimedOut;
6077 dataBuffP[10]=cbstuff.nbreakers;
6078 dataBuffP[11]=cbstuff.GSS1;
6079 dataBuffP[12]=cbstuff.GSS2;
6080 dataBuffP[13]=cbstuff.GSS3;
6081 dataBuffP[14]=cbstuff.GSS4;
6082 dataBuffP[15]=cbstuff.GSS5;
6085 a_dataP->AFS_CollData_len = dataBytes >> 2;
6086 a_dataP->AFS_CollData_val = dataBuffP;
6092 * Illegal collection number.
6094 a_dataP->AFS_CollData_len = 0;
6095 a_dataP->AFS_CollData_val = NULL;
6097 } /*Switch on collection number */
6099 #if FS_STATS_DETAILED
6100 FT_GetTimeOfDay(&opStopTime, 0);
6103 (opP->numSuccesses)++;
6104 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6105 fs_stats_AddTo((opP->sumTime), elapsedTime);
6106 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6107 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6108 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6110 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6111 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6115 #endif /* FS_STATS_DETAILED */
6119 } /*SRXAFS_GetXStats */
6123 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
6124 struct AFSCBs *CallBackArray)
6126 afs_int32 errorCode = 0;
6128 struct client *client = 0;
6129 struct rx_connection *tcon;
6131 #if FS_STATS_DETAILED
6132 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6133 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6134 struct timeval elapsedTime; /* Transfer time */
6137 * Set our stats pointer, remember when the RPC operation started, and
6138 * tally the operation.
6141 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
6145 FT_GetTimeOfDay(&opStartTime, 0);
6146 #endif /* FS_STATS_DETAILED */
6150 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
6151 FidArray->AFSCBFids_len));
6154 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
6156 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6157 goto Bad_GiveUpCallBacks;
6159 if (!FidArray && !CallBackArray) {
6161 ("SAFS_GiveUpAllCallBacks: host=%x\n",
6162 (tcon->peer ? tcon->peer->host : 0)));
6163 errorCode = GetClient(tcon, &client);
6166 DeleteAllCallBacks_r(client->host, 1);
6171 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
6173 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
6174 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
6175 (tcon->peer ? tcon->peer->host : 0)));
6177 goto Bad_GiveUpCallBacks;
6180 errorCode = GetClient(tcon, &client);
6182 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
6183 register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
6184 DeleteCallBack(client->host, fid);
6190 Bad_GiveUpCallBacks:
6191 errorCode = CallPostamble(tcon, errorCode, thost);
6193 #if FS_STATS_DETAILED
6194 FT_GetTimeOfDay(&opStopTime, 0);
6195 if (errorCode == 0) {
6197 (opP->numSuccesses)++;
6198 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6199 fs_stats_AddTo((opP->sumTime), elapsedTime);
6200 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6201 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6202 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6204 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6205 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6209 #endif /* FS_STATS_DETAILED */
6212 } /*common_GiveUpCallBacks */
6216 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
6217 struct AFSCBs * CallBackArray)
6219 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
6220 } /*SRXAFS_GiveUpCallBacks */
6223 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
6225 return common_GiveUpCallBacks(acall, 0, 0);
6226 } /*SRXAFS_GiveUpAllCallBacks */
6230 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
6231 struct AFSVolumeInfo * avolinfo)
6233 return (VNOVOL); /* XXX Obsolete routine XXX */
6235 } /*SRXAFS_NGetVolumeInfo */
6239 * Dummy routine. Should never be called (the cache manager should only
6240 * invoke this interface when communicating with a AFS/DFS Protocol
6244 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
6245 char *afs_name_p, struct AFSFid * afs_fid_p,
6246 struct AFSFetchStatus * afs_status_p,
6247 struct AFSFetchStatus * afs_dir_status_p,
6248 struct AFSCallBack * afs_callback_p,
6249 struct AFSVolSync * afs_sync_p)
6256 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
6259 struct rx_connection *tcon;
6261 afs_uint32 *dataBuffP;
6262 afs_int32 dataBytes;
6265 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
6266 afs_FullPerfStats.overall.fs_nGetCaps++;
6268 ViceLog(2, ("SAFS_GetCapabilties\n"));
6270 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6273 dataBytes = 1 * sizeof(afs_int32);
6274 dataBuffP = (afs_uint32 *) malloc(dataBytes);
6275 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
6276 #if defined(AFS_64BIT_ENV) && defined(AFS_LARGEFILE_ENV)
6277 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
6280 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
6282 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
6283 capabilities->Capabilities_val = dataBuffP;
6286 code = CallPostamble(tcon, code, thost);
6293 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
6294 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
6298 afs_int32 nids, naddrs;
6299 afs_int32 *vd, *addr;
6300 Error errorCode = 0; /* return code to caller */
6301 struct client *client = 0;
6303 ViceLog(1, ("SRXAFS_FlushCPS\n"));
6305 AFSCallStats.TotalCalls++;
6307 nids = vids->ViceIds_len; /* # of users in here */
6308 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
6309 if (nids < 0 || naddrs < 0) {
6314 vd = vids->ViceIds_val;
6315 for (i = 0; i < nids; i++, vd++) {
6318 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
6322 client->prfail = 2; /* Means re-eval client's cps */
6325 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6328 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6329 free(client->CPS.prlist_val);
6330 client->CPS.prlist_val = NULL;
6331 client->CPS.prlist_len = 0;
6333 ReleaseWriteLock(&client->lock);
6337 addr = addrs->IPAddrs_val;
6338 for (i = 0; i < naddrs; i++, addr++) {
6340 h_flushhostcps(*addr, htons(7001));
6344 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6346 } /*SRXAFS_FlushCPS */
6348 /* worthless hack to let CS keep running ancient software */
6350 afs_vtoi(register char *aname)
6352 register afs_int32 temp;
6356 while ((tc = *aname++)) {
6357 if (tc > '9' || tc < '0')
6358 return 0; /* invalid name */
6366 * may get name or #, but must handle all weird cases (recognize readonly
6367 * or backup volumes by name or #
6370 CopyVolumeEntry(char *aname, register struct vldbentry *ave,
6371 register struct VolumeInfo *av)
6373 register int i, j, vol;
6374 afs_int32 mask, whichType;
6375 afs_uint32 *serverHost, *typePtr;
6377 /* figure out what type we want if by name */
6379 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6380 whichType = BACKVOL;
6381 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6386 vol = afs_vtoi(aname);
6388 vol = ave->volumeId[whichType];
6391 * Now vol has volume # we're interested in. Next, figure out the type
6392 * of the volume by looking finding it in the vldb entry
6394 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6397 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6400 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6401 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6402 whichType = BACKVOL;
6404 return EINVAL; /* error: can't find volume in vldb entry */
6406 typePtr = &av->Type0;
6407 serverHost = &av->Server0;
6409 av->Type = whichType;
6410 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6411 if (ave->flags & VLF_RWEXISTS)
6412 typePtr[RWVOL] = ave->volumeId[RWVOL];
6413 if (ave->flags & VLF_ROEXISTS)
6414 typePtr[ROVOL] = ave->volumeId[ROVOL];
6415 if (ave->flags & VLF_BACKEXISTS)
6416 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6418 for (i = 0, j = 0; i < ave->nServers; i++) {
6419 if ((ave->serverFlags[i] & mask) == 0)
6420 continue; /* wrong volume */
6421 serverHost[j] = ave->serverNumber[i];
6424 av->ServerCount = j;
6426 serverHost[j++] = 0; /* bogus 8, but compat only now */
6431 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6433 static struct rx_connection *vlConn = 0;
6434 static int down = 0;
6435 static afs_int32 lastDownTime = 0;
6436 struct vldbentry tve;
6437 struct rx_securityClass *vlSec;
6438 register afs_int32 code;
6441 vlSec = rxnull_NewClientSecurityObject();
6443 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6444 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6446 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6447 return 1; /* failure */
6450 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6452 down = 0; /* call worked */
6455 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6461 /* otherwise convert to old format vldb entry */
6462 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6472 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6473 struct VolumeInfo * avolinfo)
6476 struct rx_connection *tcon;
6478 #if FS_STATS_DETAILED
6479 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6480 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6481 struct timeval elapsedTime; /* Transfer time */
6484 * Set our stats pointer, remember when the RPC operation started, and
6485 * tally the operation.
6487 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6491 FT_GetTimeOfDay(&opStartTime, 0);
6492 #endif /* FS_STATS_DETAILED */
6493 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6494 goto Bad_GetVolumeInfo;
6497 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6499 code = TryLocalVLServer(avolid, avolinfo);
6501 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6502 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6503 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6504 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6507 code = CallPostamble(tcon, code, thost);
6509 #if FS_STATS_DETAILED
6510 FT_GetTimeOfDay(&opStopTime, 0);
6513 (opP->numSuccesses)++;
6514 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6515 fs_stats_AddTo((opP->sumTime), elapsedTime);
6516 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6517 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6518 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6520 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6521 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6525 #endif /* FS_STATS_DETAILED */
6529 } /*SRXAFS_GetVolumeInfo */
6533 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6534 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6535 char **OfflineMsg, char **Motd)
6537 Vnode *targetptr = 0; /* vnode of the new file */
6538 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6539 Error errorCode = 0; /* error code */
6540 Volume *volptr = 0; /* pointer to the volume header */
6541 struct client *client = 0; /* pointer to client entry */
6542 afs_int32 rights, anyrights; /* rights for this and any user */
6544 struct rx_connection *tcon;
6546 struct client *t_client = NULL; /* tmp ptr to client data */
6547 #if FS_STATS_DETAILED
6548 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6549 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6550 struct timeval elapsedTime; /* Transfer time */
6553 * Set our stats pointer, remember when the RPC operation started, and
6554 * tally the operation.
6557 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6561 FT_GetTimeOfDay(&opStartTime, 0);
6562 #endif /* FS_STATS_DETAILED */
6564 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6565 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6566 goto Bad_GetVolumeStatus;
6569 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6573 goto Bad_GetVolumeStatus;
6575 dummyFid.Volume = avolid, dummyFid.Vnode =
6576 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6579 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6580 &parentwhentargetnotdir, &client, READ_LOCK,
6581 &rights, &anyrights)))
6582 goto Bad_GetVolumeStatus;
6584 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6586 goto Bad_GetVolumeStatus;
6588 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6590 Bad_GetVolumeStatus:
6591 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6593 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6594 /* next is to guarantee out strings exist for stub */
6596 *Name = (char *)malloc(1);
6600 *Motd = (char *)malloc(1);
6603 if (*OfflineMsg == 0) {
6604 *OfflineMsg = (char *)malloc(1);
6607 errorCode = CallPostamble(tcon, errorCode, thost);
6609 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6611 #if FS_STATS_DETAILED
6612 FT_GetTimeOfDay(&opStopTime, 0);
6613 if (errorCode == 0) {
6615 (opP->numSuccesses)++;
6616 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6617 fs_stats_AddTo((opP->sumTime), elapsedTime);
6618 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6619 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6620 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6622 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6623 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6627 #endif /* FS_STATS_DETAILED */
6629 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
6630 AUD_ID, t_client ? t_client->ViceId : 0,
6631 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
6634 } /*SRXAFS_GetVolumeStatus */
6638 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6639 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6640 char *OfflineMsg, char *Motd)
6642 Vnode *targetptr = 0; /* vnode of the new file */
6643 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6644 Error errorCode = 0; /* error code */
6645 Volume *volptr = 0; /* pointer to the volume header */
6646 struct client *client = 0; /* pointer to client entry */
6647 afs_int32 rights, anyrights; /* rights for this and any user */
6649 struct rx_connection *tcon = rx_ConnectionOf(acall);
6651 struct client *t_client = NULL; /* tmp ptr to client data */
6652 #if FS_STATS_DETAILED
6653 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6654 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6655 struct timeval elapsedTime; /* Transfer time */
6658 * Set our stats pointer, remember when the RPC operation started, and
6659 * tally the operation.
6662 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6666 FT_GetTimeOfDay(&opStartTime, 0);
6667 #endif /* FS_STATS_DETAILED */
6669 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6670 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6671 goto Bad_SetVolumeStatus;
6674 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6678 goto Bad_SetVolumeStatus;
6680 dummyFid.Volume = avolid, dummyFid.Vnode =
6681 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6684 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6685 &parentwhentargetnotdir, &client, READ_LOCK,
6686 &rights, &anyrights)))
6687 goto Bad_SetVolumeStatus;
6689 if (readonlyServer) {
6690 errorCode = VREADONLY;
6691 goto Bad_SetVolumeStatus;
6693 if (VanillaUser(client)) {
6695 goto Bad_SetVolumeStatus;
6699 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6701 Bad_SetVolumeStatus:
6702 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6704 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6705 errorCode = CallPostamble(tcon, errorCode, thost);
6707 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6709 #if FS_STATS_DETAILED
6710 FT_GetTimeOfDay(&opStopTime, 0);
6711 if (errorCode == 0) {
6713 (opP->numSuccesses)++;
6714 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6715 fs_stats_AddTo((opP->sumTime), elapsedTime);
6716 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6717 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6718 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6720 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6721 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6725 #endif /* FS_STATS_DETAILED */
6727 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6728 AUD_ID, t_client ? t_client->ViceId : 0,
6729 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6731 } /*SRXAFS_SetVolumeStatus */
6733 #define DEFAULTVOLUME "root.afs"
6736 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6742 struct rx_connection *tcon;
6744 Error errorCode = 0;
6746 #if FS_STATS_DETAILED
6747 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6748 struct timeval opStartTime; /* Start time for RPC op */
6750 struct timeval opStopTime;
6751 struct timeval elapsedTime; /* Transfer time */
6755 * Set our stats pointer, remember when the RPC operation started, and
6756 * tally the operation.
6758 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6762 FT_GetTimeOfDay(&opStartTime, 0);
6763 #endif /* FS_STATS_DETAILED */
6765 return FSERR_EOPNOTSUPP;
6768 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
6769 goto Bad_GetRootVolume;
6771 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6774 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6776 strcpy(temp, DEFAULTVOLUME);
6778 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6779 lockf(fd, F_LOCK, 0);
6783 len = read(fd, temp, 256);
6784 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6785 lockf(fd, F_ULOCK, 0);
6790 if (temp[len - 1] == '\n')
6794 *VolumeName = temp; /* freed by rx server-side stub */
6797 errorCode = CallPostamble(tcon, errorCode, thost);
6799 #if FS_STATS_DETAILED
6800 FT_GetTimeOfDay(&opStopTime, 0);
6801 if (errorCode == 0) {
6803 (opP->numSuccesses)++;
6804 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6805 fs_stats_AddTo((opP->sumTime), elapsedTime);
6806 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6807 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6808 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6810 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6811 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6815 #endif /* FS_STATS_DETAILED */
6820 } /*SRXAFS_GetRootVolume */
6823 /* still works because a struct CBS is the same as a struct AFSOpaque */
6825 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6826 struct AFSOpaque * Token)
6829 struct rx_connection *tcon;
6831 #if FS_STATS_DETAILED
6832 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6833 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6834 struct timeval elapsedTime; /* Transfer time */
6837 * Set our stats pointer, remember when the RPC operation started, and
6838 * tally the operation.
6840 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6844 FT_GetTimeOfDay(&opStartTime, 0);
6845 #endif /* FS_STATS_DETAILED */
6847 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6848 goto Bad_CheckToken;
6850 code = FSERR_ECONNREFUSED;
6853 code = CallPostamble(tcon, code, thost);
6855 #if FS_STATS_DETAILED
6856 FT_GetTimeOfDay(&opStopTime, 0);
6859 (opP->numSuccesses)++;
6860 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6861 fs_stats_AddTo((opP->sumTime), elapsedTime);
6862 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6863 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6864 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6866 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6867 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6871 #endif /* FS_STATS_DETAILED */
6875 } /*SRXAFS_CheckToken */
6878 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6879 afs_uint32 * USeconds)
6882 struct rx_connection *tcon;
6885 #if FS_STATS_DETAILED
6886 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6887 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6888 struct timeval elapsedTime; /* Transfer time */
6891 * Set our stats pointer, remember when the RPC operation started, and
6892 * tally the operation.
6894 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
6898 FT_GetTimeOfDay(&opStartTime, 0);
6899 #endif /* FS_STATS_DETAILED */
6901 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6905 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6907 FT_GetTimeOfDay(&tpl, 0);
6908 *Seconds = tpl.tv_sec;
6909 *USeconds = tpl.tv_usec;
6911 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6914 code = CallPostamble(tcon, code, thost);
6916 #if FS_STATS_DETAILED
6917 FT_GetTimeOfDay(&opStopTime, 0);
6918 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6921 (opP->numSuccesses)++;
6922 fs_stats_AddTo((opP->sumTime), elapsedTime);
6923 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6924 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6925 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6927 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6928 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6932 #endif /* FS_STATS_DETAILED */
6936 } /*SRXAFS_GetTime */
6943 * Implement a client's data fetch using Rx.
6946 * volptr : Ptr to the given volume's info.
6947 * targetptr : Pointer to the vnode involved.
6948 * Call : Ptr to the Rx call involved.
6949 * Pos : Offset within the file.
6950 * Len : Length in bytes to read; this value is bogus!
6951 * if FS_STATS_DETAILED
6952 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6954 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6960 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
6961 register struct rx_call * Call, afs_sfsize_t Pos,
6962 afs_sfsize_t Len, afs_int32 Int64Mode,
6963 #if FS_STATS_DETAILED
6964 afs_sfsize_t * a_bytesToFetchP,
6965 afs_sfsize_t * a_bytesFetchedP
6966 #endif /* FS_STATS_DETAILED */
6969 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6970 Error errorCode = 0; /* Returned error code to caller */
6974 register char *tbuffer;
6975 #else /* AFS_NT40_ENV */
6976 struct iovec tiov[RX_MAXIOVECS];
6978 #endif /* AFS_NT40_ENV */
6982 #if FS_STATS_DETAILED
6984 * Initialize the byte count arguments.
6986 (*a_bytesToFetchP) = 0;
6987 (*a_bytesFetchedP) = 0;
6988 #endif /* FS_STATS_DETAILED */
6992 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
6993 (afs_uintmax_t) Len));
6995 if (!VN_GET_INO(targetptr)) {
6996 afs_int32 zero = htonl(0);
6998 * This is used for newly created files; we simply send 0 bytes
6999 * back to make the cache manager happy...
7002 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7003 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7006 FT_GetTimeOfDay(&StartTime, 0);
7007 ihP = targetptr->handle;
7010 VTakeOffline(volptr);
7011 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7015 optSize = sendBufSize;
7016 tlen = FDH_SIZE(fdP);
7018 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
7021 VTakeOffline(volptr);
7022 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7030 if (Pos + Len > tlen)
7031 Len = tlen - Pos; /* get length we should send */
7032 (void)FDH_SEEK(fdP, Pos, 0);
7034 afs_int32 high, low;
7035 SplitOffsetOrSize(Len, high, low);
7036 assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
7039 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
7042 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
7044 #if FS_STATS_DETAILED
7045 (*a_bytesToFetchP) = Len;
7046 #endif /* FS_STATS_DETAILED */
7048 tbuffer = AllocSendBuffer();
7049 #endif /* AFS_NT40_ENV */
7057 errorCode = FDH_READ(fdP, tbuffer, wlen);
7058 if (errorCode != wlen) {
7060 FreeSendBuffer((struct afs_buffer *)tbuffer);
7061 VTakeOffline(volptr);
7062 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7066 errorCode = rx_Write(Call, tbuffer, wlen);
7067 #else /* AFS_NT40_ENV */
7068 errorCode = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
7069 if (errorCode <= 0) {
7074 errorCode = FDH_READV(fdP, tiov, tnio);
7075 if (errorCode != wlen) {
7077 VTakeOffline(volptr);
7078 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7082 errorCode = rx_Writev(Call, tiov, tnio, wlen);
7083 #endif /* AFS_NT40_ENV */
7084 #if FS_STATS_DETAILED
7086 * Bump the number of bytes actually sent by the number from this
7089 (*a_bytesFetchedP) += errorCode;
7090 #endif /* FS_STATS_DETAILED */
7091 if (errorCode != wlen) {
7094 FreeSendBuffer((struct afs_buffer *)tbuffer);
7095 #endif /* AFS_NT40_ENV */
7101 FreeSendBuffer((struct afs_buffer *)tbuffer);
7102 #endif /* AFS_NT40_ENV */
7104 FT_GetTimeOfDay(&StopTime, 0);
7106 /* Adjust all Fetch Data related stats */
7108 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
7109 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
7110 AFSCallStats.AccumFetchTime +=
7111 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
7112 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
7114 afs_fsize_t targLen;
7115 VN_GET_LEN(targLen, targetptr);
7116 AFSCallStats.TotalFetchedBytes += targLen;
7117 AFSCallStats.FetchSize1++;
7118 if (targLen < SIZE2)
7119 AFSCallStats.FetchSize2++;
7120 else if (targLen < SIZE3)
7121 AFSCallStats.FetchSize3++;
7122 else if (targLen < SIZE4)
7123 AFSCallStats.FetchSize4++;
7125 AFSCallStats.FetchSize5++;
7130 } /*FetchData_RXStyle */
7133 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
7134 afs_sfsize_t * size)
7136 #ifdef AFS_NAMEI_ENV
7138 lhp = IH_OPEN(V_linkHandle(vp));
7142 *lc = nt_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
7144 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
7149 *size = OS_SIZE(fdP->fd_fd);
7150 return (*size == -1) ? -1 : 0;
7152 struct afs_stat status;
7154 if (afs_fstat(fdP->fd_fd, &status) < 0) {
7158 *lc = GetLinkCount(vp, &status);
7159 *size = status.st_size;
7168 * Implement a client's data store using Rx.
7171 * volptr : Ptr to the given volume's info.
7172 * targetptr : Pointer to the vnode involved.
7173 * Call : Ptr to the Rx call involved.
7174 * Pos : Offset within the file.
7175 * Len : Length in bytes to store; this value is bogus!
7176 * if FS_STATS_DETAILED
7177 * a_bytesToStoreP : Set to the number of bytes to be stored to
7179 * a_bytesStoredP : Set to the actual number of bytes stored to
7184 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
7185 struct client * client, register struct rx_call * Call,
7186 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
7188 #if FS_STATS_DETAILED
7189 afs_sfsize_t * a_bytesToStoreP,
7190 afs_sfsize_t * a_bytesStoredP
7191 #endif /* FS_STATS_DETAILED */
7194 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
7195 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
7196 Error errorCode = 0; /* Returned error code to caller */
7198 register char *tbuffer; /* data copying buffer */
7199 #else /* AFS_NT40_ENV */
7200 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
7201 int tnio; /* temp for iovec size */
7202 #endif /* AFS_NT40_ENV */
7203 afs_sfsize_t tlen; /* temp for xfr length */
7204 Inode tinode; /* inode for I/O */
7205 afs_int32 optSize; /* optimal transfer size */
7206 afs_sfsize_t DataLength = 0; /* size of inode */
7207 afs_sfsize_t TruncatedLength; /* size after ftruncate */
7208 afs_fsize_t NewLength; /* size after this store completes */
7209 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
7210 int linkCount = 0; /* link count on inode */
7211 afs_fsize_t CoW_off, CoW_len;
7212 FdHandle_t *fdP, *origfdP = NULL;
7213 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
7215 #if FS_STATS_DETAILED
7217 * Initialize the byte count arguments.
7219 (*a_bytesToStoreP) = 0;
7220 (*a_bytesStoredP) = 0;
7221 #endif /* FS_STATS_DETAILED */
7224 * We break the callbacks here so that the following signal will not
7227 BreakCallBack(client->host, Fid, 0);
7229 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
7230 /* the inode should have been created in Alloc_NewVnode */
7231 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
7233 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
7234 Fid->Volume, Fid->Vnode, Fid->Unique,
7235 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
7236 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
7237 return ENOENT; /* is this proper error code? */
7240 * See if the file has several links (from other volumes). If it
7241 * does, then we have to make a copy before changing it to avoid
7242 *changing read-only clones of this dude
7245 ("StoreData_RXStyle : Opening inode %s\n",
7246 PrintInode(NULL, VN_GET_INO(targetptr))));
7247 fdP = IH_OPEN(targetptr->handle);
7250 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
7252 VTakeOffline(volptr);
7253 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7258 if (linkCount != 1) {
7261 ("StoreData_RXStyle : inode %s has more than onelink\n",
7262 PrintInode(NULL, VN_GET_INO(targetptr))));
7263 /* other volumes share this data, better copy it first */
7265 /* Adjust the disk block count by the creation of the new inode.
7266 * We call the special VDiskUsage so we don't adjust the volume's
7267 * quota since we don't want to penalyze the user for afs's internal
7268 * mechanisms (i.e. copy on write overhead.) Also the right size
7269 * of the disk will be recorded...
7272 VN_GET_LEN(size, targetptr);
7273 volptr->partition->flags &= ~PART_DONTUPDATE;
7274 VSetPartitionDiskUsage(volptr->partition);
7275 volptr->partition->flags |= PART_DONTUPDATE;
7276 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
7277 volptr->partition->flags &= ~PART_DONTUPDATE;
7282 CoW_len = (FileLength >= (Length + Pos)) ? FileLength - Length : Pos;
7283 CopyOnWrite_calls++;
7284 if (CoW_len == 0) CopyOnWrite_size0++;
7285 if (Pos == 0) CopyOnWrite_off0++;
7286 if (CoW_len > CopyOnWrite_maxsize) CopyOnWrite_maxsize = CoW_len;
7288 ViceLog(1, ("StoreData : calling CopyOnWrite on vnode %lu.%lu (%s) off 0x%llx size 0x%llx\n",
7289 V_id(volptr), targetptr->vnodeNumber, V_name(volptr), 0, Pos));
7290 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, Pos))) {
7291 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
7292 volptr->partition->flags &= ~PART_DONTUPDATE;
7296 volptr->partition->flags &= ~PART_DONTUPDATE;
7297 VSetPartitionDiskUsage(volptr->partition);
7298 fdP = IH_OPEN(targetptr->handle);
7301 ("StoreData : Reopen after CopyOnWrite failed\n"));
7306 tinode = VN_GET_INO(targetptr);
7308 if (!VALID_INO(tinode)) {
7309 VTakeOffline(volptr);
7310 ViceLog(0,("Volume %u now offline, must be salvaged.\n",
7315 /* compute new file length */
7316 NewLength = DataLength;
7317 if (FileLength < NewLength)
7318 /* simulate truncate */
7319 NewLength = FileLength;
7320 TruncatedLength = NewLength; /* remember length after possible ftruncate */
7321 if (Pos + Length > NewLength)
7322 NewLength = Pos + Length; /* and write */
7324 /* adjust the disk block count by the difference in the files */
7326 afs_fsize_t targSize;
7327 VN_GET_LEN(targSize, targetptr);
7328 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
7331 AdjustDiskUsage(volptr, adjustSize,
7332 adjustSize - SpareComp(volptr)))) {
7334 if (origfdP) FDH_CLOSE(origfdP);
7338 /* can signal cache manager to proceed from close now */
7339 /* this bit means that the locks are set and protections are OK */
7340 rx_SetLocalStatus(Call, 1);
7342 FT_GetTimeOfDay(&StartTime, 0);
7344 optSize = sendBufSize;
7346 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
7347 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
7348 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
7350 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
7351 if (FileLength < DataLength)
7352 FDH_TRUNC(fdP, FileLength);
7354 FDH_SEEK(fdP, Pos, 0);
7355 bytesTransfered = 0;
7357 tbuffer = AllocSendBuffer();
7358 #endif /* AFS_NT40_ENV */
7359 /* if length == 0, the loop below isn't going to do anything, including
7360 * extend the length of the inode, which it must do, since the file system
7361 * assumes that the inode length == vnode's file length. So, we extend
7362 * the file length manually if need be. Note that if file is bigger than
7363 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7364 * do what we're going to do below.
7366 if (Length == 0 && Pos > TruncatedLength) {
7367 /* Set the file's length; we've already done an lseek to the right
7370 errorCode = FDH_WRITE(fdP, &tlen, 1);
7373 errorCode = FDH_TRUNC(fdP, Pos);
7375 /* have some data to copy */
7376 #if FS_STATS_DETAILED
7377 (*a_bytesToStoreP) = Length;
7378 #endif /* FS_STATS_DETAILED */
7381 if (bytesTransfered >= Length) {
7385 tlen = Length - bytesTransfered; /* how much more to do */
7387 rlen = optSize; /* bound by buffer size */
7391 errorCode = rx_Read(Call, tbuffer, rlen);
7392 #else /* AFS_NT40_ENV */
7393 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7394 #endif /* AFS_NT40_ENV */
7395 #if FS_STATS_DETAILED
7396 (*a_bytesStoredP) += errorCode;
7397 #endif /* FS_STATS_DETAILED */
7398 if (errorCode <= 0) {
7404 errorCode = FDH_WRITE(fdP, tbuffer, rlen);
7405 #else /* AFS_NT40_ENV */
7406 errorCode = FDH_WRITEV(fdP, tiov, tnio);
7407 #endif /* AFS_NT40_ENV */
7408 if (errorCode != rlen) {
7409 errorCode = VDISKFULL;
7412 bytesTransfered += rlen;
7417 FreeSendBuffer((struct afs_buffer *)tbuffer);
7418 #endif /* AFS_NT40_ENV */
7423 afs_fsize_t nfSize = (afs_fsize_t) FDH_SIZE(fdP);
7424 /* something went wrong: adjust size and return */
7425 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7426 /* changed_newTime is tested in StoreData to detemine if we
7427 * need to update the target vnode.
7429 targetptr->changed_newTime = 1;
7430 if (origfdP && (bytesTransfered < Length)) /* Need to "finish" CopyOnWrite still */
7431 CopyOnWrite2(origfdP, fdP, Pos + bytesTransfered, NewLength - Pos - bytesTransfered);
7432 if (origfdP) FDH_CLOSE(origfdP);
7434 /* set disk usage to be correct */
7435 VAdjustDiskUsage(&errorCode, volptr,
7436 (afs_sfsize_t) (nBlocks(nfSize) -
7437 nBlocks(NewLength)), 0);
7440 if (origfdP) { /* finish CopyOnWrite */
7441 if ( (CoW_off = Pos + Length) < NewLength) {
7442 errorCode = CopyOnWrite2(origfdP, fdP, CoW_off, CoW_len = NewLength - CoW_off);
7443 ViceLog(1, ("StoreData : CopyOnWrite2 on vnode %lu.%lu (%s) off 0x%llx size 0x%llx returns %d\n",
7444 V_id(volptr), targetptr->vnodeNumber, V_name(volptr), CoW_off, CoW_len, errorCode));
7450 FT_GetTimeOfDay(&StopTime, 0);
7452 VN_SET_LEN(targetptr, NewLength);
7454 /* Update all StoreData related stats */
7456 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7457 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7458 AFSCallStats.StoreSize1++; /* Piggybacked data */
7460 afs_fsize_t targLen;
7461 VN_GET_LEN(targLen, targetptr);
7462 if (targLen < SIZE2)
7463 AFSCallStats.StoreSize2++;
7464 else if (targLen < SIZE3)
7465 AFSCallStats.StoreSize3++;
7466 else if (targLen < SIZE4)
7467 AFSCallStats.StoreSize4++;
7469 AFSCallStats.StoreSize5++;
7474 } /*StoreData_RXStyle */
7476 static int sys2et[512];
7479 init_sys_error_to_et(void)
7481 memset(&sys2et, 0, sizeof(sys2et));
7482 sys2et[EPERM] = UAEPERM;
7483 sys2et[ENOENT] = UAENOENT;
7484 sys2et[ESRCH] = UAESRCH;
7485 sys2et[EINTR] = UAEINTR;
7486 sys2et[EIO] = UAEIO;
7487 sys2et[ENXIO] = UAENXIO;
7488 sys2et[E2BIG] = UAE2BIG;
7489 sys2et[ENOEXEC] = UAENOEXEC;
7490 sys2et[EBADF] = UAEBADF;
7491 sys2et[ECHILD] = UAECHILD;
7492 sys2et[EAGAIN] = UAEAGAIN;
7493 sys2et[ENOMEM] = UAENOMEM;
7494 sys2et[EACCES] = UAEACCES;
7495 sys2et[EFAULT] = UAEFAULT;
7496 sys2et[ENOTBLK] = UAENOTBLK;
7497 sys2et[EBUSY] = UAEBUSY;
7498 sys2et[EEXIST] = UAEEXIST;
7499 sys2et[EXDEV] = UAEXDEV;
7500 sys2et[ENODEV] = UAENODEV;
7501 sys2et[ENOTDIR] = UAENOTDIR;
7502 sys2et[EISDIR] = UAEISDIR;
7503 sys2et[EINVAL] = UAEINVAL;
7504 sys2et[ENFILE] = UAENFILE;
7505 sys2et[EMFILE] = UAEMFILE;
7506 sys2et[ENOTTY] = UAENOTTY;
7507 sys2et[ETXTBSY] = UAETXTBSY;
7508 sys2et[EFBIG] = UAEFBIG;
7509 sys2et[ENOSPC] = UAENOSPC;
7510 sys2et[ESPIPE] = UAESPIPE;
7511 sys2et[EROFS] = UAEROFS;
7512 sys2et[EMLINK] = UAEMLINK;
7513 sys2et[EPIPE] = UAEPIPE;
7514 sys2et[EDOM] = UAEDOM;
7515 sys2et[ERANGE] = UAERANGE;
7516 sys2et[EDEADLK] = UAEDEADLK;
7517 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7518 sys2et[ENOLCK] = UAENOLCK;
7519 sys2et[ENOSYS] = UAENOSYS;
7520 #if (ENOTEMPTY != EEXIST)
7521 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7523 sys2et[ELOOP] = UAELOOP;
7524 #if (EWOULDBLOCK != EAGAIN)
7525 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7527 sys2et[ENOMSG] = UAENOMSG;
7528 sys2et[EIDRM] = UAEIDRM;
7529 sys2et[ECHRNG] = UAECHRNG;
7530 sys2et[EL2NSYNC] = UAEL2NSYNC;
7531 sys2et[EL3HLT] = UAEL3HLT;
7532 sys2et[EL3RST] = UAEL3RST;
7533 sys2et[ELNRNG] = UAELNRNG;
7534 sys2et[EUNATCH] = UAEUNATCH;
7535 sys2et[ENOCSI] = UAENOCSI;
7536 sys2et[EL2HLT] = UAEL2HLT;
7537 sys2et[EBADE] = UAEBADE;
7538 sys2et[EBADR] = UAEBADR;
7539 sys2et[EXFULL] = UAEXFULL;
7540 sys2et[ENOANO] = UAENOANO;
7541 sys2et[EBADRQC] = UAEBADRQC;
7542 sys2et[EBADSLT] = UAEBADSLT;
7543 sys2et[EDEADLK] = UAEDEADLK;
7544 sys2et[EBFONT] = UAEBFONT;
7545 sys2et[ENOSTR] = UAENOSTR;
7546 sys2et[ENODATA] = UAENODATA;
7547 sys2et[ETIME] = UAETIME;
7548 sys2et[ENOSR] = UAENOSR;
7549 sys2et[ENONET] = UAENONET;
7550 sys2et[ENOPKG] = UAENOPKG;
7551 sys2et[EREMOTE] = UAEREMOTE;
7552 sys2et[ENOLINK] = UAENOLINK;
7553 sys2et[EADV] = UAEADV;
7554 sys2et[ESRMNT] = UAESRMNT;
7555 sys2et[ECOMM] = UAECOMM;
7556 sys2et[EPROTO] = UAEPROTO;
7557 sys2et[EMULTIHOP] = UAEMULTIHOP;
7558 sys2et[EDOTDOT] = UAEDOTDOT;
7559 sys2et[EBADMSG] = UAEBADMSG;
7560 sys2et[EOVERFLOW] = UAEOVERFLOW;
7561 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7562 sys2et[EBADFD] = UAEBADFD;
7563 sys2et[EREMCHG] = UAEREMCHG;
7564 sys2et[ELIBACC] = UAELIBACC;
7565 sys2et[ELIBBAD] = UAELIBBAD;
7566 sys2et[ELIBSCN] = UAELIBSCN;
7567 sys2et[ELIBMAX] = UAELIBMAX;
7568 sys2et[ELIBEXEC] = UAELIBEXEC;
7569 sys2et[EILSEQ] = UAEILSEQ;
7570 sys2et[ERESTART] = UAERESTART;
7571 sys2et[ESTRPIPE] = UAESTRPIPE;
7572 sys2et[EUSERS] = UAEUSERS;
7573 sys2et[ENOTSOCK] = UAENOTSOCK;
7574 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7575 sys2et[EMSGSIZE] = UAEMSGSIZE;
7576 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7577 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7578 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7579 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7580 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7581 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7582 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7583 sys2et[EADDRINUSE] = UAEADDRINUSE;
7584 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7585 sys2et[ENETDOWN] = UAENETDOWN;
7586 sys2et[ENETUNREACH] = UAENETUNREACH;
7587 sys2et[ENETRESET] = UAENETRESET;
7588 sys2et[ECONNABORTED] = UAECONNABORTED;
7589 sys2et[ECONNRESET] = UAECONNRESET;
7590 sys2et[ENOBUFS] = UAENOBUFS;
7591 sys2et[EISCONN] = UAEISCONN;
7592 sys2et[ENOTCONN] = UAENOTCONN;
7593 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7594 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7595 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7596 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7597 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7598 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7599 sys2et[EALREADY] = UAEALREADY;
7600 sys2et[EINPROGRESS] = UAEINPROGRESS;
7601 sys2et[ESTALE] = UAESTALE;
7602 sys2et[EUCLEAN] = UAEUCLEAN;
7603 sys2et[ENOTNAM] = UAENOTNAM;
7604 sys2et[ENAVAIL] = UAENAVAIL;
7605 sys2et[EISNAM] = UAEISNAM;
7606 sys2et[EREMOTEIO] = UAEREMOTEIO;
7607 sys2et[EDQUOT] = UAEDQUOT;
7608 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7609 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7611 sys2et[EIO] = UAEIO;
7615 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
7616 * - pass back the connection, client, and host from CallPreamble
7617 * - keep a ref on the client, which we don't now
7618 * - keep a hold on the host, which we already do
7619 * - pass the connection, client, and host down into SAFSS_*, and use
7620 * them instead of independently discovering them via rx_ConnectionOf
7621 * (safe) and rx_GetSpecific (not so safe)
7622 * The idea being that we decide what client and host we're going to use
7623 * when CallPreamble is called, and stay consistent throughout the call.
7624 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
7628 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7630 Error errorCode = 0;
7631 struct rx_connection *tcon;
7632 struct host *tcallhost;
7633 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7635 struct client *tclient;
7636 static struct rx_securityClass *sc = 0;
7638 struct rx_connection *conn;
7641 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost)))
7642 goto Bad_CallBackRxConnAddr1;
7644 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7648 tclient = h_FindClient_r(tcon);
7651 goto Bad_CallBackRxConnAddr;
7653 thost = tclient->host;
7655 /* nothing more can be done */
7656 if ( !thost->interface )
7657 goto Bad_CallBackRxConnAddr;
7659 /* the only address is the primary interface */
7660 /* can't change when there's only 1 address, anyway */
7661 if ( thost->interface->numberOfInterfaces <= 1 )
7662 goto Bad_CallBackRxConnAddr;
7664 /* initialise a security object only once */
7666 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7668 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7670 if ( *addr == thost->interface->addr[i] ) {
7675 if ( *addr != thost->interface->addr[i] )
7676 goto Bad_CallBackRxConnAddr;
7678 conn = rx_NewConnection (thost->interface->addr[i],
7679 thost->port, 1, sc, 0);
7680 rx_SetConnDeadTime(conn, 2);
7681 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7683 errorCode = RXAFSCB_Probe(conn);
7686 if ( thost->callback_rxcon )
7687 rx_DestroyConnection(thost->callback_rxcon);
7688 thost->callback_rxcon = conn;
7690 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7691 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7692 h_ReleaseClient_r(tclient);
7693 /* The hold on thost will be released by CallPostamble */
7695 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7698 rx_DestroyConnection(conn);
7700 Bad_CallBackRxConnAddr:
7701 h_ReleaseClient_r(tclient);
7702 /* The hold on thost will be released by CallPostamble */
7706 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7707 Bad_CallBackRxConnAddr1:
7708 return errorCode; /* failure */
7712 sys_error_to_et(afs_int32 in)
7716 if (in < 0 || in > 511)
7718 if (in >= VICE_SPECIAL_ERRORS && in <= VIO || in == VRESTRICTED)
7720 if (sys2et[in] != 0)