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;
425 tclient = h_FindClient_r(aconn);
428 thost = tclient->host;
429 if (thost->hostFlags & HERRORTRANS)
431 h_ReleaseClient_r(tclient);
434 if (ahost != thost) {
435 /* host/client recycle */
436 char hoststr[16], hoststr2[16];
437 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
439 afs_inet_ntoa_r(ahost->host, hoststr),
442 afs_inet_ntoa_r(thost->host, hoststr2),
446 /* return the reference taken in CallPreamble */
450 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
451 afs_inet_ntoa_r(thost->host, hoststr),
456 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
457 * does not decrement refcount on client->host */
462 return (translate ? sys_error_to_et(ret) : ret);
466 * Returns the volume and vnode pointers associated with file Fid; the lock
467 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
468 * are incremented and they must be eventualy released.
471 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
474 Error local_errorCode, errorCode = -1;
475 static struct timeval restartedat = { 0, 0 };
477 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
479 if ((*volptr) == 0) {
484 #ifdef AFS_DEMAND_ATTACH_FS
492 *volptr = VGetVolume(&local_errorCode, &errorCode, (afs_int32) fid->Volume);
497 if ((errorCode == VOFFLINE) && (VInit < 2)) {
498 /* The volume we want may not be attached yet because
499 * the volume initialization is not yet complete.
500 * We can do several things:
501 * 1. return -1, which will cause users to see
502 * "connection timed out". This is more or
503 * less the same as always, except that the servers
504 * may appear to bounce up and down while they
505 * are actually restarting.
506 * 2. return VBUSY which will cause clients to
507 * sleep and retry for 6.5 - 15 minutes, depending
508 * on what version of the CM they are running. If
509 * the file server takes longer than that interval
510 * to attach the desired volume, then the application
511 * will see an ENODEV or EIO. This approach has
512 * the advantage that volumes which have been attached
513 * are immediately available, it keeps the server's
514 * immediate backlog low, and the call is interruptible
515 * by the user. Users see "waiting for busy volume."
516 * 3. sleep here and retry. Some people like this approach
517 * because there is no danger of seeing errors. However,
518 * this approach only works with a bounded number of
519 * clients, since the pending queues will grow without
520 * stopping. It might be better to find a way to take
521 * this call and stick it back on a queue in order to
522 * recycle this thread for a different request.
523 * 4. Return a new error code, which new cache managers will
524 * know enough to interpret as "sleep and retry", without
525 * the upper bound of 6-15 minutes that is imposed by the
526 * VBUSY handling. Users will see "waiting for
527 * busy volume," so they know that something is
528 * happening. Old cache managers must be able to do
529 * something reasonable with this, for instance, mark the
530 * server down. Fortunately, any error code < 0
531 * will elicit that behavior. See #1.
532 * 5. Some combination of the above. I like doing #2 for 10
533 * minutes, followed by #4. 3.1b and 3.2 cache managers
534 * will be fine as long as the restart period is
535 * not longer than 6.5 minutes, otherwise they may
536 * return ENODEV to users. 3.3 cache managers will be
537 * fine for 10 minutes, then will return
538 * ETIMEDOUT. 3.4 cache managers will just wait
539 * until the call works or fails definitively.
540 * NB. The problem with 2,3,4,5 is that old clients won't
541 * fail over to an alternate read-only replica while this
542 * server is restarting. 3.4 clients will fail over right away.
544 if (restartedat.tv_sec == 0) {
545 /* I'm not really worried about when we restarted, I'm */
546 /* just worried about when the first VBUSY was returned. */
547 FT_GetTimeOfDay(&restartedat, 0);
550 afs_perfstats.fs_nBusies++;
553 return (busyonrst ? VBUSY : restarting);
556 FT_GetTimeOfDay(&now, 0);
557 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
560 afs_perfstats.fs_nBusies++;
563 return (busyonrst ? VBUSY : restarting);
569 /* allow read operations on busy volume.
570 * must check local_errorCode because demand attach fs
571 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
572 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
573 #ifdef AFS_DEMAND_ATTACH_FS
574 /* DAFS case is complicated by the fact that local_errorCode can
575 * be VBUSY in cases where the volume is truly offline */
577 /* volume is in VOL_STATE_UNATTACHED */
580 #endif /* AFS_DEMAND_ATTACH_FS */
583 } else if (errorCode)
590 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
593 if ((*vptr)->disk.uniquifier != fid->Unique) {
594 VPutVnode(&fileCode, *vptr);
595 assert(fileCode == 0);
597 return (VNOVNODE); /* return the right error code, at least */
603 * This routine returns the ACL associated with the targetptr. If the
604 * targetptr isn't a directory, we access its parent dir and get the ACL
605 * thru the parent; in such case the parent's vnode is returned in
609 SetAccessList(Vnode ** targetptr, Volume ** volume,
610 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
611 AFSFid * Fid, int Lock)
613 if ((*targetptr)->disk.type == vDirectory) {
615 *ACL = VVnodeACL(*targetptr);
616 *ACLSize = VAclSize(*targetptr);
624 parentvnode = (*targetptr)->disk.parent;
625 VPutVnode(&errorCode, *targetptr);
629 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
632 *ACL = VVnodeACL(*parent);
633 *ACLSize = VAclSize(*parent);
634 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
636 if ((*targetptr)->disk.parent != parentvnode) {
637 VPutVnode(&errorCode, *parent);
648 /* Must not be called with H_LOCK held */
650 client_CheckRights(struct client *client, struct acl_accessList *ACL,
654 ObtainReadLock(&client->lock);
655 if (client->CPS.prlist_len > 0 && !client->deleted &&
656 client->host && !(client->host->hostFlags & HOSTDELETED))
657 acl_CheckRights(ACL, &client->CPS, rights);
658 ReleaseReadLock(&client->lock);
661 /* Must not be called with H_LOCK held */
663 client_HasAsMember(struct client *client, afs_int32 id)
667 ObtainReadLock(&client->lock);
668 if (client->CPS.prlist_len > 0 && !client->deleted &&
669 client->host && !(client->host->hostFlags & HOSTDELETED))
670 code = acl_IsAMember(id, &client->CPS);
671 ReleaseReadLock(&client->lock);
676 * Compare the directory's ACL with the user's access rights in the client
677 * connection and return the user's and everybody else's access permissions
678 * in rights and anyrights, respectively
681 GetRights(struct client *client, struct acl_accessList *ACL,
682 afs_int32 * rights, afs_int32 * anyrights)
684 extern prlist SystemAnyUserCPS;
685 afs_int32 hrights = 0;
686 #ifndef AFS_PTHREAD_ENV
690 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
691 ViceLog(0, ("CheckRights failed\n"));
696 client_CheckRights(client, ACL, rights);
698 /* wait if somebody else is already doing the getCPS call */
700 while (client->host->hostFlags & HCPS_INPROGRESS) {
701 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
702 #ifdef AFS_PTHREAD_ENV
703 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
704 #else /* AFS_PTHREAD_ENV */
706 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
707 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
708 #endif /* AFS_PTHREAD_ENV */
711 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
714 ("CheckRights: len=%u, for host=%s:%d\n",
715 client->host->hcps.prlist_len,
716 afs_inet_ntoa_r(client->host->host, hoststr),
717 ntohs(client->host->port)));
719 acl_CheckRights(ACL, &client->host->hcps, &hrights);
721 /* Allow system:admin the rights given with the -implicit option */
722 if (client_HasAsMember(client, SystemId))
723 *rights |= implicitAdminRights;
726 *anyrights |= hrights;
733 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
734 * a System:Administrator)
737 VanillaUser(struct client *client)
739 if (client_HasAsMember(client, SystemId))
740 return (0); /* not a system administrator, then you're "vanilla" */
747 * This unusual afs_int32-parameter routine encapsulates all volume package related
748 * operations together in a single function; it's called by almost all AFS
752 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
753 Vnode ** targetptr, int chkforDir, Vnode ** parent,
754 struct client **client, int locktype, afs_int32 * rights,
755 afs_int32 * anyrights)
757 struct acl_accessList *aCL; /* Internal access List */
758 int aCLSize; /* size of the access list */
759 Error errorCode = 0; /* return code to caller */
761 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
764 if (chkforDir == MustNOTBeDIR
765 && ((*targetptr)->disk.type == vDirectory))
767 else if (chkforDir == MustBeDIR
768 && ((*targetptr)->disk.type != vDirectory))
772 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
773 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
774 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
776 if (chkforDir == MustBeDIR)
777 assert((*parent) == 0);
779 if ((errorCode = GetClient(tcon, client)) != 0)
784 GetRights(*client, aCL, rights, anyrights);
785 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
786 if ((*targetptr)->disk.type != vDirectory) {
787 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
788 if ((*targetptr)->disk.owner == (*client)->ViceId)
789 (*rights) |= PRSFS_ADMINISTER;
791 (*rights) &= ~PRSFS_ADMINISTER;
793 #ifdef ADMIN_IMPLICIT_LOOKUP
794 /* admins get automatic lookup on everything */
795 if (!VanillaUser(*client))
796 (*rights) |= PRSFS_LOOKUP;
797 #endif /* ADMIN_IMPLICIT_LOOKUP */
800 } /*GetVolumePackage */
804 * This is the opposite of GetVolumePackage(), and is always used at the end of
805 * AFS calls to put back all used vnodes and the volume in the proper order!
808 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
809 Vnode * parentptr, Volume * volptr, struct client **client)
811 Error fileCode = 0; /* Error code returned by the volume package */
813 if (parentwhentargetnotdir) {
814 VPutVnode(&fileCode, parentwhentargetnotdir);
815 assert(!fileCode || (fileCode == VSALVAGE));
818 VPutVnode(&fileCode, targetptr);
819 assert(!fileCode || (fileCode == VSALVAGE));
822 VPutVnode(&fileCode, parentptr);
823 assert(!fileCode || (fileCode == VSALVAGE));
831 } /*PutVolumePackage */
834 VolumeOwner(register struct client *client, register Vnode * targetptr)
836 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
839 return (client->ViceId == owner);
842 * We don't have to check for host's cps since only regular
843 * viceid are volume owners.
845 return (client_HasAsMember(client, owner));
851 VolumeRootVnode(Vnode * targetptr)
853 return ((targetptr->vnodeNumber == ROOTVNODE)
854 && (targetptr->disk.uniquifier == 1));
856 } /*VolumeRootVnode */
859 * Check if target file has the proper access permissions for the Fetch
860 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
861 * StoreStatus) related calls
863 /* this code should probably just set a "priv" flag where all the audit events
864 * are now, and only generate the audit event once at the end of the routine,
865 * thus only generating the event if all the checks succeed, but only because
866 * of the privilege XXX
869 Check_PermissionRights(Vnode * targetptr, struct client *client,
870 afs_int32 rights, int CallingRoutine,
871 AFSStoreStatus * InStatus)
874 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
875 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
876 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
878 if (CallingRoutine & CHK_FETCH) {
879 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
880 if (targetptr->disk.type == vDirectory
881 || targetptr->disk.type == vSymlink) {
882 if (!(rights & PRSFS_LOOKUP)
883 #ifdef ADMIN_IMPLICIT_LOOKUP
884 /* grant admins fetch on all directories */
885 && VanillaUser(client)
886 #endif /* ADMIN_IMPLICIT_LOOKUP */
887 && !VolumeOwner(client, targetptr))
890 /* must have read access, or be owner and have insert access */
891 if (!(rights & PRSFS_READ)
892 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
895 if (CallingRoutine == CHK_FETCHDATA
896 && targetptr->disk.type == vFile)
897 #ifdef USE_GROUP_PERMS
898 if (!OWNSp(client, targetptr)
899 && !client_HasAsMember(client, targetptr->disk.owner)) {
901 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
905 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
910 * The check with the ownership below is a kludge to allow
911 * reading of files created with no read permission. The owner
912 * of the file is always allowed to read it.
914 if ((client->ViceId != targetptr->disk.owner)
915 && VanillaUser(client))
917 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
918 modeBits) ? 0 : EACCES);
920 } else { /* !VanillaUser(client) && !FetchData */
922 osi_audit(PrivilegeEvent, 0, AUD_ID,
923 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
926 } else { /* a store operation */
927 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
928 && (CallingRoutine != CHK_STOREACL)
929 && (targetptr->disk.type == vFile)) {
930 /* bypass protection checks on first store after a create
931 * for the creator; also prevent chowns during this time
932 * unless you are a system administrator */
933 /****** InStatus->Owner && UnixModeBits better be SET!! */
934 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
937 else if (VanillaUser(client))
938 return (EPERM); /* Was EACCES */
940 osi_audit(PrivilegeEvent, 0, AUD_ID,
941 (client ? client->ViceId : 0), AUD_INT,
942 CallingRoutine, AUD_END);
945 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
946 osi_audit(PrivilegeEvent, 0, AUD_ID,
947 (client ? client->ViceId : 0), AUD_INT,
948 CallingRoutine, AUD_END);
950 if (readonlyServer) {
953 if (CallingRoutine == CHK_STOREACL) {
954 if (!(rights & PRSFS_ADMINISTER)
955 && !VolumeOwner(client, targetptr))
957 } else { /* store data or status */
958 /* watch for chowns and chgrps */
959 if (CHOWN(InStatus, targetptr)
960 || CHGRP(InStatus, targetptr)) {
963 else if (VanillaUser(client))
964 return (EPERM); /* Was EACCES */
966 osi_audit(PrivilegeEvent, 0, AUD_ID,
967 (client ? client->ViceId : 0), AUD_INT,
968 CallingRoutine, AUD_END);
970 /* must be sysadmin to set suid/sgid bits */
971 if ((InStatus->Mask & AFS_SETMODE) &&
973 (InStatus->UnixModeBits & 0xc00) != 0) {
975 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
979 if (VanillaUser(client))
982 osi_audit(PrivSetID, 0, AUD_ID,
983 (client ? client->ViceId : 0), AUD_INT,
984 CallingRoutine, AUD_END);
986 if (CallingRoutine == CHK_STOREDATA) {
989 if (!(rights & PRSFS_WRITE))
991 /* Next thing is tricky. We want to prevent people
992 * from writing files sans 0200 bit, but we want
993 * creating new files with 0444 mode to work. We
994 * don't check the 0200 bit in the "you are the owner"
995 * path above, but here we check the bit. However, if
996 * you're a system administrator, we ignore the 0200
997 * bit anyway, since you may have fchowned the file,
999 #ifdef USE_GROUP_PERMS
1000 if ((targetptr->disk.type == vFile)
1001 && VanillaUser(client)) {
1002 if (!OWNSp(client, targetptr)
1003 && !client_HasAsMember(client, targetptr->disk.owner)) {
1005 ((GROUPWRITE & targetptr->disk.modeBits)
1009 ((OWNERWRITE & targetptr->disk.modeBits)
1014 if ((targetptr->disk.type != vDirectory)
1015 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1018 if (VanillaUser(client))
1021 osi_audit(PrivilegeEvent, 0, AUD_ID,
1022 (client ? client->ViceId : 0),
1023 AUD_INT, CallingRoutine, AUD_END);
1025 } else { /* a status store */
1028 if (targetptr->disk.type == vDirectory) {
1029 if (!(rights & PRSFS_DELETE)
1030 && !(rights & PRSFS_INSERT))
1032 } else { /* a file or symlink */
1033 if (!(rights & PRSFS_WRITE))
1043 } /*Check_PermissionRights */
1047 * The Access List information is converted from its internal form in the
1048 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1049 * external form and returned back to the caller, via the AccessList
1053 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1054 struct AFSOpaque *AccessList)
1056 char *eACL; /* External access list placeholder */
1058 if (acl_Externalize_pr
1059 (hpr_IdToName, (targetptr->disk.type ==
1060 vDirectory ? VVnodeACL(targetptr) :
1061 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1064 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1065 acl_FreeExternalACL(&eACL);
1068 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1069 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1071 acl_FreeExternalACL(&eACL);
1074 } /*RXFetch_AccessList */
1078 * The Access List information is converted from its external form in the
1079 * input AccessList structure to the internal representation and copied into
1080 * the target dir's vnode storage.
1083 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1085 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1087 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1090 if ((newACL->size + 4) > VAclSize(targetptr))
1092 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1093 acl_FreeACL(&newACL);
1096 } /*RXStore_AccessList */
1099 /* In our current implementation, each successive data store (new file
1100 * data version) creates a new inode. This function creates the new
1101 * inode, copies the old inode's contents to the new one, remove the old
1102 * inode (i.e. decrement inode count -- if it's currently used the delete
1103 * will be delayed), and modify some fields (i.e. vnode's
1104 * disk.inodeNumber and cloned)
1106 #define COPYBUFFSIZE 8192
1107 #define MAXFSIZE (~(afs_fsize_t) 0)
1109 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_fsize_t off, afs_fsize_t len)
1111 Inode ino, nearInode;
1114 register afs_fsize_t size;
1115 register int length;
1117 int rc; /* return code */
1118 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1119 FdHandle_t *targFdP; /* Source Inode file handle */
1120 FdHandle_t *newFdP; /* Dest Inode file handle */
1122 if (targetptr->disk.type == vDirectory)
1123 DFlush(); /* just in case? */
1125 VN_GET_LEN(size, targetptr);
1133 buff = (char *)malloc(COPYBUFFSIZE);
1138 ino = VN_GET_INO(targetptr);
1139 if (!VALID_INO(ino)) {
1141 VTakeOffline(volptr);
1142 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1146 targFdP = IH_OPEN(targetptr->handle);
1147 if (targFdP == NULL) {
1150 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1151 targetptr->vnodeNumber, V_id(volptr), rc));
1153 VTakeOffline(volptr);
1157 nearInode = VN_GET_INO(targetptr);
1159 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1160 VPartitionPath(V_partition(volptr)), nearInode,
1161 V_id(volptr), targetptr->vnodeNumber,
1162 targetptr->disk.uniquifier,
1163 (int)targetptr->disk.dataVersion);
1164 if (!VALID_INO(ino)) {
1166 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1167 volptr->partition->name, V_id(volptr), errno));
1172 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1173 newFdP = IH_OPEN(newH);
1174 assert(newFdP != NULL);
1176 FDH_SEEK(targFdP, off, SEEK_SET);
1177 FDH_SEEK(newFdP, off, SEEK_SET);
1179 if (size > COPYBUFFSIZE) { /* more than a buffer */
1180 length = COPYBUFFSIZE;
1181 size -= COPYBUFFSIZE;
1186 rdlen = FDH_READ(targFdP, buff, length);
1187 if (rdlen == length)
1188 wrlen = FDH_WRITE(newFdP, buff, length);
1191 /* Callers of this function are not prepared to recover
1192 * from error that put the filesystem in an inconsistent
1193 * state. Make sure that we force the volume off-line if
1194 * we some error other than ENOSPC - 4.29.99)
1196 * In case we are unable to write the required bytes, and the
1197 * error code indicates that the disk is full, we roll-back to
1198 * the initial state.
1200 if ((rdlen != length) || (wrlen != length)) {
1201 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1203 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1204 volptr->partition->name, V_id(volptr)));
1205 /* remove destination inode which was partially copied till now */
1206 FDH_REALLYCLOSE(newFdP);
1208 FDH_REALLYCLOSE(targFdP);
1209 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1212 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1213 rc, V_id(volptr), volptr->partition->name));
1214 VTakeOffline(volptr);
1220 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1221 V_id(volptr), volptr->partition->name, length, rdlen,
1223 #if defined(AFS_DEMAND_ATTACH_FS)
1224 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1226 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1228 /* Decrement this inode so salvager doesn't find it. */
1229 FDH_REALLYCLOSE(newFdP);
1231 FDH_REALLYCLOSE(targFdP);
1232 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1234 VTakeOffline(volptr);
1238 #ifndef AFS_PTHREAD_ENV
1240 #endif /* !AFS_PTHREAD_ENV */
1242 FDH_REALLYCLOSE(targFdP);
1243 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1244 V_parentId(volptr));
1246 IH_RELEASE(targetptr->handle);
1248 rc = FDH_SYNC(newFdP);
1251 targetptr->handle = newH;
1252 VN_SET_INO(targetptr, ino);
1253 targetptr->disk.cloned = 0;
1254 /* Internal change to vnode, no user level change to volume - def 5445 */
1255 targetptr->changed_oldTime = 1;
1257 return 0; /* success */
1261 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_fsize_t off, afs_fsize_t size) {
1262 char *buff = (char *)malloc(COPYBUFFSIZE);
1263 register int length;
1268 FDH_SEEK(targFdP, off, SEEK_SET);
1269 FDH_SEEK(newFdP, off, SEEK_SET);
1271 if (size > FDH_SIZE(targFdP) - off) size = FDH_SIZE(targFdP) - off;
1273 if (size > COPYBUFFSIZE) { /* more than a buffer */
1274 length = COPYBUFFSIZE;
1275 size -= COPYBUFFSIZE;
1280 rdlen = FDH_READ(targFdP, buff, length);
1281 if (rdlen == length)
1282 wrlen = FDH_WRITE(newFdP, buff, length);
1286 if ((rdlen != length) || (wrlen != length)) {
1287 /* no error recovery, at the worst we'll have a "hole" in the file */
1298 * Common code to handle with removing the Name (file when it's called from
1299 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1300 * given directory, parentptr.
1302 int DT1 = 0, DT0 = 0;
1304 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1305 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1307 DirHandle childdir; /* Handle for dir package I/O */
1308 Error errorCode = 0;
1311 /* watch for invalid names */
1312 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1314 if (parentptr->disk.cloned) {
1315 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1316 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1318 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1324 /* check that the file is in the directory */
1325 SetDirHandle(dir, parentptr);
1326 if (Lookup(dir, Name, fileFid))
1328 fileFid->Volume = V_id(volptr);
1330 /* just-in-case check for something causing deadlock */
1331 if (fileFid->Vnode == parentptr->vnodeNumber)
1334 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1338 if (ChkForDir == MustBeDIR) {
1339 if ((*targetptr)->disk.type != vDirectory)
1341 } else if ((*targetptr)->disk.type == vDirectory)
1344 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1346 * If the uniquifiers dont match then instead of asserting
1347 * take the volume offline and return VSALVAGE
1349 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1350 VTakeOffline(volptr);
1352 ("Volume %u now offline, must be salvaged.\n",
1354 errorCode = VSALVAGE;
1358 if (ChkForDir == MustBeDIR) {
1359 SetDirHandle(&childdir, *targetptr);
1360 if (IsEmpty(&childdir) != 0)
1362 DZap((afs_int32 *) &childdir);
1364 (*targetptr)->delete = 1;
1365 } else if ((--(*targetptr)->disk.linkCount) == 0)
1366 (*targetptr)->delete = 1;
1367 if ((*targetptr)->delete) {
1368 if (VN_GET_INO(*targetptr)) {
1370 IH_REALLYCLOSE((*targetptr)->handle);
1372 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1373 V_parentId(volptr));
1374 IH_RELEASE((*targetptr)->handle);
1375 if (errorCode == -1) {
1377 ("DT: inode=%s, name=%s, errno=%d\n",
1378 PrintInode(NULL, VN_GET_INO(*targetptr)), Name,
1380 if (errno != ENOENT)
1382 VTakeOffline(volptr);
1384 ("Volume %u now offline, must be salvaged.\n",
1392 VN_SET_INO(*targetptr, (Inode) 0);
1394 afs_fsize_t adjLength;
1395 VN_GET_LEN(adjLength, *targetptr);
1396 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1400 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1402 code = Delete(dir, (char *)Name);
1405 ("Error %d deleting %s\n", code,
1406 (((*targetptr)->disk.type ==
1407 Directory) ? "directory" : "file")));
1408 VTakeOffline(volptr);
1410 ("Volume %u now offline, must be salvaged.\n",
1423 * This routine updates the parent directory's status block after the
1424 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1425 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1429 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1430 int author, int linkcount,
1431 #if FS_STATS_DETAILED
1432 char a_inSameNetwork
1433 #endif /* FS_STATS_DETAILED */
1436 afs_fsize_t newlength; /* Holds new directory length */
1437 afs_fsize_t parentLength;
1439 #if FS_STATS_DETAILED
1440 Date currDate; /*Current date */
1441 int writeIdx; /*Write index to bump */
1442 int timeIdx; /*Authorship time index to bump */
1443 #endif /* FS_STATS_DETAILED */
1445 parentptr->disk.dataVersion++;
1446 newlength = (afs_fsize_t) Length(dir);
1448 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1449 * (create, symlink, link, makedir) so we need to check if we have enough space
1450 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1451 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1453 VN_GET_LEN(parentLength, parentptr);
1454 if (nBlocks(newlength) != nBlocks(parentLength)) {
1455 VAdjustDiskUsage(&errorCode, volptr,
1456 (nBlocks(newlength) - nBlocks(parentLength)),
1457 (nBlocks(newlength) - nBlocks(parentLength)));
1459 VN_SET_LEN(parentptr, newlength);
1461 #if FS_STATS_DETAILED
1463 * Update directory write stats for this volume. Note that the auth
1464 * counter is located immediately after its associated ``distance''
1467 if (a_inSameNetwork)
1468 writeIdx = VOL_STATS_SAME_NET;
1470 writeIdx = VOL_STATS_DIFF_NET;
1471 V_stat_writes(volptr, writeIdx)++;
1472 if (author != AnonymousID) {
1473 V_stat_writes(volptr, writeIdx + 1)++;
1477 * Update the volume's authorship information in response to this
1478 * directory operation. Get the current time, decide to which time
1479 * slot this operation belongs, and bump the appropriate slot.
1481 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1483 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1484 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1485 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1486 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1487 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1488 if (parentptr->disk.author == author) {
1489 V_stat_dirSameAuthor(volptr, timeIdx)++;
1491 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1493 #endif /* FS_STATS_DETAILED */
1495 parentptr->disk.author = author;
1496 parentptr->disk.linkCount = linkcount;
1497 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1498 parentptr->disk.serverModifyTime = FT_ApproxTime();
1499 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1504 * Update the target file's (or dir's) status block after the specified
1505 * operation is complete. Note that some other fields maybe updated by
1506 * the individual module.
1509 /* XXX INCOMPLETE - More attention is needed here! */
1511 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1512 struct client *client, AFSStoreStatus * InStatus,
1513 Vnode * parentptr, Volume * volptr,
1516 #if FS_STATS_DETAILED
1517 Date currDate; /*Current date */
1518 int writeIdx; /*Write index to bump */
1519 int timeIdx; /*Authorship time index to bump */
1520 #endif /* FS_STATS_DETAILED */
1522 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1523 targetptr->disk.parent = parentptr->vnodeNumber;
1524 VN_SET_LEN(targetptr, length);
1525 /* targetptr->disk.group = 0; save some cycles */
1526 targetptr->disk.modeBits = 0777;
1527 targetptr->disk.owner = client->ViceId;
1528 targetptr->disk.dataVersion = 0; /* consistent with the client */
1529 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1530 /* the inode was created in Alloc_NewVnode() */
1532 #if FS_STATS_DETAILED
1534 * Update file write stats for this volume. Note that the auth
1535 * counter is located immediately after its associated ``distance''
1538 if (client->InSameNetwork)
1539 writeIdx = VOL_STATS_SAME_NET;
1541 writeIdx = VOL_STATS_DIFF_NET;
1542 V_stat_writes(volptr, writeIdx)++;
1543 if (client->ViceId != AnonymousID) {
1544 V_stat_writes(volptr, writeIdx + 1)++;
1548 * We only count operations that DON'T involve creating new objects
1549 * (files, symlinks, directories) or simply setting status as
1550 * authorship-change operations.
1552 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1554 * Update the volume's authorship information in response to this
1555 * file operation. Get the current time, decide to which time
1556 * slot this operation belongs, and bump the appropriate slot.
1558 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1561 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1562 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1563 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1564 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1565 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1566 VOL_STATS_TIME_IDX_5);
1567 if (targetptr->disk.author == client->ViceId) {
1568 V_stat_fileSameAuthor(volptr, timeIdx)++;
1570 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1573 #endif /* FS_STATS_DETAILED */
1575 if (!(Caller & TVS_SSTATUS))
1576 targetptr->disk.author = client->ViceId;
1577 if (Caller & TVS_SDATA) {
1578 targetptr->disk.dataVersion++;
1579 if (VanillaUser(client)) {
1580 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1581 #ifdef CREATE_SGUID_ADMIN_ONLY
1582 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1586 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1587 /* store status, must explicitly request to change the date */
1588 if (InStatus->Mask & AFS_SETMODTIME)
1589 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1590 } else { /* other: date always changes, but perhaps to what is specified by caller */
1591 targetptr->disk.unixModifyTime =
1592 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1593 ClientModTime : FT_ApproxTime());
1595 if (InStatus->Mask & AFS_SETOWNER) {
1596 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1597 if (VanillaUser(client)) {
1598 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1599 #ifdef CREATE_SGUID_ADMIN_ONLY
1600 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1603 targetptr->disk.owner = InStatus->Owner;
1604 if (VolumeRootVnode(targetptr)) {
1605 Error errorCode = 0; /* what should be done with this? */
1607 V_owner(targetptr->volumePtr) = InStatus->Owner;
1608 VUpdateVolume(&errorCode, targetptr->volumePtr);
1611 if (InStatus->Mask & AFS_SETMODE) {
1612 int modebits = InStatus->UnixModeBits;
1613 #define CREATE_SGUID_ADMIN_ONLY 1
1614 #ifdef CREATE_SGUID_ADMIN_ONLY
1615 if (VanillaUser(client))
1616 modebits = modebits & 0777;
1618 if (VanillaUser(client)) {
1619 targetptr->disk.modeBits = modebits;
1621 targetptr->disk.modeBits = modebits;
1624 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1625 CHK_STOREDATA, AUD_END);
1629 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1630 CHK_STORESTATUS, AUD_END);
1637 targetptr->disk.serverModifyTime = FT_ApproxTime();
1638 if (InStatus->Mask & AFS_SETGROUP)
1639 targetptr->disk.group = InStatus->Group;
1640 /* vnode changed : to be written back by VPutVnode */
1641 targetptr->changed_newTime = 1;
1643 } /*Update_TargetVnodeStatus */
1647 * Fills the CallBack structure with the expiration time and type of callback
1648 * structure. Warning: this function is currently incomplete.
1651 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1653 /* CallBackTime could not be 0 */
1654 if (CallBackTime == 0) {
1655 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1656 CallBack->ExpirationTime = 0;
1658 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1659 CallBack->CallBackVersion = CALLBACK_VERSION;
1660 CallBack->CallBackType = CB_SHARED; /* The default for now */
1662 } /*SetCallBackStruct */
1666 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1667 * allocation; if some error occured (exceeded volume quota or partition
1668 * was full, or whatever), it frees the space back and returns the code.
1669 * We usually pre-adjust the volume space to make sure that there's
1670 * enough space before consuming some.
1673 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1674 afs_sfsize_t checkLength)
1679 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1681 VAdjustDiskUsage(&nc, volptr, -length, 0);
1682 if (rc == VOVERQUOTA) {
1684 ("Volume %u (%s) is full\n", V_id(volptr),
1688 if (rc == VDISKFULL) {
1690 ("Partition %s that contains volume %u is full\n",
1691 volptr->partition->name, V_id(volptr)));
1694 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1699 } /*AdjustDiskUsage */
1702 * Common code that handles the creation of a new file (SAFS_CreateFile and
1703 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1706 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1707 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1708 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1710 Error errorCode = 0; /* Error code returned back */
1713 Inode nearInode; /* hint for inode allocation in solaris */
1716 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1717 BlocksPreallocatedForVnode))) {
1719 ("Insufficient space to allocate %" AFS_INT64_FMT " blocks\n",
1720 (afs_intmax_t) BlocksPreallocatedForVnode));
1724 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1725 if (errorCode != 0) {
1726 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1729 OutFid->Volume = V_id(volptr);
1730 OutFid->Vnode = (*targetptr)->vnodeNumber;
1731 OutFid->Unique = (*targetptr)->disk.uniquifier;
1733 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1735 /* create the inode now itself */
1737 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1738 VPartitionPath(V_partition(volptr)), nearInode,
1739 V_id(volptr), (*targetptr)->vnodeNumber,
1740 (*targetptr)->disk.uniquifier, 1);
1742 /* error in creating inode */
1743 if (!VALID_INO(inode)) {
1745 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1746 (*targetptr)->volumePtr->header->diskstuff.id,
1747 (*targetptr)->vnodeNumber, errno));
1748 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1749 (*targetptr)->delete = 1; /* delete vnode */
1752 VN_SET_INO(*targetptr, inode);
1753 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1755 /* copy group from parent dir */
1756 (*targetptr)->disk.group = parentptr->disk.group;
1758 if (parentptr->disk.cloned) {
1759 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1760 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1761 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1762 /* delete the vnode previously allocated */
1763 (*targetptr)->delete = 1;
1764 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1765 IH_REALLYCLOSE((*targetptr)->handle);
1766 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1768 ("Alloc_NewVnode: partition %s idec %s failed\n",
1769 volptr->partition->name, PrintInode(NULL, inode)));
1770 IH_RELEASE((*targetptr)->handle);
1776 /* add the name to the directory */
1777 SetDirHandle(dir, parentptr);
1778 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1779 (*targetptr)->delete = 1;
1780 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1781 IH_REALLYCLOSE((*targetptr)->handle);
1782 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1784 ("Alloc_NewVnode: partition %s idec %s failed\n",
1785 volptr->partition->name, PrintInode(NULL, inode)));
1786 IH_RELEASE((*targetptr)->handle);
1792 } /*Alloc_NewVnode */
1796 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1800 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1802 int Time; /* Used for time */
1803 int writeVnode = targetptr->changed_oldTime; /* save original status */
1805 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1806 Time = FT_ApproxTime();
1807 switch (LockingType) {
1810 if (Time > targetptr->disk.lock.lockTime)
1811 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1813 Time += AFS_LOCKWAIT;
1814 if (LockingType == LockRead) {
1815 if ( !(rights & PRSFS_LOCK) &&
1816 !(rights & PRSFS_WRITE) &&
1817 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1820 if (targetptr->disk.lock.lockCount >= 0) {
1821 ++(targetptr->disk.lock.lockCount);
1822 targetptr->disk.lock.lockTime = Time;
1825 } else if (LockingType == LockWrite) {
1826 if ( !(rights & PRSFS_WRITE) &&
1827 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1830 if (targetptr->disk.lock.lockCount == 0) {
1831 targetptr->disk.lock.lockCount = -1;
1832 targetptr->disk.lock.lockTime = Time;
1838 Time += AFS_LOCKWAIT;
1839 if (targetptr->disk.lock.lockCount != 0)
1840 targetptr->disk.lock.lockTime = Time;
1845 if ((--targetptr->disk.lock.lockCount) <= 0)
1846 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1850 targetptr->changed_oldTime = writeVnode; /* restore old status */
1851 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1854 } /*HandleLocking */
1856 /* 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. */
1859 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1863 if (!(rights & Prfs_Mode))
1865 if ((targetptr->disk.type != vDirectory)
1866 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1872 * If some flags (i.e. min or max quota) are set, the volume's in disk
1873 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1874 * update, if applicable.
1877 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1878 char *Name, char *OfflineMsg, char *Motd)
1880 Error errorCode = 0;
1882 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1883 V_minquota(volptr) = StoreVolStatus->MinQuota;
1884 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1885 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1886 if (strlen(OfflineMsg) > 0) {
1887 strcpy(V_offlineMessage(volptr), OfflineMsg);
1889 if (strlen(Name) > 0) {
1890 strcpy(V_name(volptr), Name);
1892 #if OPENAFS_VOL_STATS
1894 * We don't overwrite the motd field, since it's now being used
1898 if (strlen(Motd) > 0) {
1899 strcpy(V_motd(volptr), Motd);
1901 #endif /* FS_STATS_DETAILED */
1902 VUpdateVolume(&errorCode, volptr);
1905 } /*RXUpdate_VolumeStatus */
1909 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1910 char **motd, Volume * volptr)
1914 status->Vid = V_id(volptr);
1915 status->ParentId = V_parentId(volptr);
1916 status->Online = V_inUse(volptr);
1917 status->InService = V_inService(volptr);
1918 status->Blessed = V_blessed(volptr);
1919 status->NeedsSalvage = V_needsSalvaged(volptr);
1920 if (VolumeWriteable(volptr))
1921 status->Type = ReadWrite;
1923 status->Type = ReadOnly;
1924 status->MinQuota = V_minquota(volptr);
1925 status->MaxQuota = V_maxquota(volptr);
1926 status->BlocksInUse = V_diskused(volptr);
1927 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
1928 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
1930 /* now allocate and copy these things; they're freed by the RXGEN stub */
1931 temp = strlen(V_name(volptr)) + 1;
1932 *name = malloc(temp);
1934 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1937 strcpy(*name, V_name(volptr));
1938 temp = strlen(V_offlineMessage(volptr)) + 1;
1939 *offMsg = malloc(temp);
1941 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1944 strcpy(*offMsg, V_offlineMessage(volptr));
1945 #if OPENAFS_VOL_STATS
1948 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1951 strcpy(*motd, nullString);
1953 temp = strlen(V_motd(volptr)) + 1;
1954 *motd = malloc(temp);
1956 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1959 strcpy(*motd, V_motd(volptr));
1960 #endif /* FS_STATS_DETAILED */
1962 } /*RXGetVolumeStatus */
1966 FileNameOK(register char *aname)
1968 register afs_int32 i, tc;
1971 /* watch for @sys on the right */
1972 if (strcmp(aname + i - 4, "@sys") == 0)
1975 while ((tc = *aname++)) {
1977 return 0; /* very bad character to encounter */
1979 return 1; /* file name is ok */
1985 * This variant of symlink is expressly to support the AFS/DFS translator
1986 * and is not supported by the AFS fileserver. We just return EINVAL.
1987 * The cache manager should not generate this call to an AFS cache manager.
1990 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
1991 char *LinkContents, struct AFSStoreStatus *InStatus,
1992 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
1993 struct AFSFetchStatus *OutDirStatus,
1994 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2000 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2001 struct FsCmdInputs * Inputs,
2002 struct FsCmdOutputs * Outputs)
2006 switch (Inputs->command) {
2010 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2011 Inputs->command, Outputs->code));
2016 static struct afs_buffer {
2017 struct afs_buffer *next;
2018 } *freeBufferList = 0;
2019 static int afs_buffersAlloced = 0;
2022 FreeSendBuffer(register struct afs_buffer *adata)
2025 afs_buffersAlloced--;
2026 adata->next = freeBufferList;
2027 freeBufferList = adata;
2031 } /*FreeSendBuffer */
2033 /* allocate space for sender */
2037 register struct afs_buffer *tp;
2040 afs_buffersAlloced++;
2041 if (!freeBufferList) {
2044 tmp = malloc(sendBufSize);
2046 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2051 tp = freeBufferList;
2052 freeBufferList = tp->next;
2056 } /*AllocSendBuffer */
2057 #endif /* AFS_NT40_ENV */
2060 * This routine returns the status info associated with the targetptr vnode
2061 * in the AFSFetchStatus structure. Some of the newer fields, such as
2062 * SegSize and Group are not yet implemented
2066 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2067 afs_int32 anyrights, Vnode * parentptr)
2069 /* initialize return status from a vnode */
2070 status->InterfaceVersion = 1;
2071 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2072 status->errorCode = 0;
2073 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2074 if (targetptr->disk.type == vFile)
2075 status->FileType = File;
2076 else if (targetptr->disk.type == vDirectory)
2077 status->FileType = Directory;
2078 else if (targetptr->disk.type == vSymlink)
2079 status->FileType = SymbolicLink;
2081 status->FileType = Invalid; /*invalid type field */
2082 status->LinkCount = targetptr->disk.linkCount;
2084 afs_fsize_t targetLen;
2085 VN_GET_LEN(targetLen, targetptr);
2086 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2088 status->DataVersion = targetptr->disk.dataVersion;
2089 status->Author = targetptr->disk.author;
2090 status->Owner = targetptr->disk.owner;
2091 status->CallerAccess = rights;
2092 status->AnonymousAccess = anyrights;
2093 status->UnixModeBits = targetptr->disk.modeBits;
2094 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2095 status->ParentVnode =
2096 (status->FileType ==
2097 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2098 status->ParentUnique =
2099 (status->FileType ==
2100 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2101 status->ServerModTime = targetptr->disk.serverModifyTime;
2102 status->Group = targetptr->disk.group;
2103 status->lockCount = targetptr->disk.lock.lockCount;
2104 status->errorCode = 0;
2110 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2111 afs_sfsize_t Pos, afs_sfsize_t Len,
2112 struct AFSFetchStatus *OutStatus,
2113 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2116 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2117 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2118 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2119 Error errorCode = 0; /* return code to caller */
2120 Error fileCode = 0; /* return code from vol package */
2121 Volume *volptr = 0; /* pointer to the volume */
2122 struct client *client = 0; /* pointer to the client data */
2123 struct rx_connection *tcon; /* the connection we're part of */
2125 afs_int32 rights, anyrights; /* rights for this and any user */
2126 struct client *t_client = NULL; /* tmp ptr to client data */
2127 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2128 #if FS_STATS_DETAILED
2129 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2130 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2131 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2132 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2133 struct timeval elapsedTime; /* Transfer time */
2134 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2135 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2136 int readIdx; /* Index of read stats array to bump */
2137 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2140 * Set our stats pointers, remember when the RPC operation started, and
2141 * tally the operation.
2143 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2144 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2148 FT_GetTimeOfDay(&opStartTime, 0);
2149 #endif /* FS_STATS_DETAILED */
2152 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2155 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2157 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2160 /* Get ptr to client data for user Id for logging */
2161 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2162 logHostAddr.s_addr = rxr_HostOf(tcon);
2164 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2165 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2166 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2168 * Get volume/vnode for the fetched file; caller's access rights to
2169 * it are also returned
2172 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2173 &parentwhentargetnotdir, &client, READ_LOCK,
2174 &rights, &anyrights)))
2177 SetVolumeSync(Sync, volptr);
2179 #if FS_STATS_DETAILED
2181 * Remember that another read operation was performed.
2184 if (client->InSameNetwork)
2185 readIdx = VOL_STATS_SAME_NET;
2187 readIdx = VOL_STATS_DIFF_NET;
2188 V_stat_reads(volptr, readIdx)++;
2189 if (client->ViceId != AnonymousID) {
2190 V_stat_reads(volptr, readIdx + 1)++;
2193 #endif /* FS_STATS_DETAILED */
2194 /* Check whether the caller has permission access to fetch the data */
2196 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2200 * Drop the read lock on the parent directory after saving the parent
2201 * vnode information we need to pass to GetStatus
2203 if (parentwhentargetnotdir != NULL) {
2204 tparentwhentargetnotdir = *parentwhentargetnotdir;
2205 VPutVnode(&fileCode, parentwhentargetnotdir);
2206 assert(!fileCode || (fileCode == VSALVAGE));
2207 parentwhentargetnotdir = NULL;
2209 #if FS_STATS_DETAILED
2211 * Remember when the data transfer started.
2213 FT_GetTimeOfDay(&xferStartTime, 0);
2214 #endif /* FS_STATS_DETAILED */
2216 /* actually do the data transfer */
2217 #if FS_STATS_DETAILED
2219 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2220 &bytesToXfer, &bytesXferred);
2223 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2225 #endif /* FS_STATS_DETAILED */
2227 #if FS_STATS_DETAILED
2229 * At this point, the data transfer is done, for good or ill. Remember
2230 * when the transfer ended, bump the number of successes/failures, and
2231 * integrate the transfer size and elapsed time into the stats. If the
2232 * operation failed, we jump to the appropriate point.
2234 FT_GetTimeOfDay(&xferStopTime, 0);
2236 (xferP->numXfers)++;
2238 (xferP->numSuccesses)++;
2241 * Bump the xfer sum by the number of bytes actually sent, NOT the
2244 tot_bytesXferred += bytesXferred;
2245 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2246 tot_bytesXferred &= 0x3FF;
2247 if (bytesXferred < xferP->minBytes)
2248 xferP->minBytes = bytesXferred;
2249 if (bytesXferred > xferP->maxBytes)
2250 xferP->maxBytes = bytesXferred;
2253 * Tally the size of the object. Note: we tally the actual size,
2254 * NOT the number of bytes that made it out over the wire.
2256 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2257 (xferP->count[0])++;
2258 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2259 (xferP->count[1])++;
2260 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2261 (xferP->count[2])++;
2262 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2263 (xferP->count[3])++;
2264 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2265 (xferP->count[4])++;
2266 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2267 (xferP->count[5])++;
2268 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2269 (xferP->count[6])++;
2270 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2271 (xferP->count[7])++;
2273 (xferP->count[8])++;
2275 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2276 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2277 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2278 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2279 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2281 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2282 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2287 * Finally, go off to tell our caller the bad news in case the
2292 #endif /* FS_STATS_DETAILED */
2294 /* write back the OutStatus from the target vnode */
2295 GetStatus(targetptr, OutStatus, rights, anyrights,
2296 &tparentwhentargetnotdir);
2298 /* if a r/w volume, promise a callback to the caller */
2299 if (VolumeWriteable(volptr))
2300 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2302 struct AFSFid myFid;
2303 memset(&myFid, 0, sizeof(struct AFSFid));
2304 myFid.Volume = Fid->Volume;
2305 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2309 /* Update and store volume/vnode and parent vnodes back */
2310 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2312 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2313 errorCode = CallPostamble(tcon, errorCode, thost);
2315 #if FS_STATS_DETAILED
2316 FT_GetTimeOfDay(&opStopTime, 0);
2317 if (errorCode == 0) {
2319 (opP->numSuccesses)++;
2320 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2321 fs_stats_AddTo((opP->sumTime), elapsedTime);
2322 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2323 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2324 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2326 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2327 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2331 #endif /* FS_STATS_DETAILED */
2333 osi_auditU(acall, FetchDataEvent, errorCode,
2334 AUD_ID, t_client ? t_client->ViceId : 0,
2335 AUD_FID, Fid, AUD_END);
2338 } /*SRXAFS_FetchData */
2341 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2342 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2343 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2345 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2350 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2351 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2352 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2355 afs_sfsize_t tPos, tLen;
2357 #ifdef AFS_64BIT_ENV
2358 tPos = (afs_sfsize_t) Pos;
2359 tLen = (afs_sfsize_t) Len;
2360 #else /* AFS_64BIT_ENV */
2361 if (Pos.high || Len.high)
2365 #endif /* AFS_64BIT_ENV */
2368 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2374 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2375 struct AFSOpaque * AccessList,
2376 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2378 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2379 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2380 Error errorCode = 0; /* return error code to caller */
2381 Volume *volptr = 0; /* pointer to the volume */
2382 struct client *client = 0; /* pointer to the client data */
2383 afs_int32 rights, anyrights; /* rights for this and any user */
2384 struct rx_connection *tcon = rx_ConnectionOf(acall);
2386 struct client *t_client = NULL; /* tmp ptr to client data */
2387 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2388 #if FS_STATS_DETAILED
2389 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2390 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2391 struct timeval elapsedTime; /* Transfer time */
2394 * Set our stats pointer, remember when the RPC operation started, and
2395 * tally the operation.
2397 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2401 FT_GetTimeOfDay(&opStartTime, 0);
2402 #endif /* FS_STATS_DETAILED */
2405 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2408 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2410 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2413 /* Get ptr to client data for user Id for logging */
2414 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2415 logHostAddr.s_addr = rxr_HostOf(tcon);
2417 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2418 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2419 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2421 AccessList->AFSOpaque_len = 0;
2422 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2423 if (!AccessList->AFSOpaque_val) {
2424 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2429 * Get volume/vnode for the fetched file; caller's access rights to it
2433 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2434 &parentwhentargetnotdir, &client, READ_LOCK,
2435 &rights, &anyrights)))
2438 SetVolumeSync(Sync, volptr);
2440 /* Check whether we have permission to fetch the ACL */
2442 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2445 /* Get the Access List from the dir's vnode */
2447 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2450 /* Get OutStatus back From the target Vnode */
2451 GetStatus(targetptr, OutStatus, rights, anyrights,
2452 parentwhentargetnotdir);
2455 /* Update and store volume/vnode and parent vnodes back */
2456 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2459 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2460 AccessList->AFSOpaque_val));
2461 errorCode = CallPostamble(tcon, errorCode, thost);
2463 #if FS_STATS_DETAILED
2464 FT_GetTimeOfDay(&opStopTime, 0);
2465 if (errorCode == 0) {
2467 (opP->numSuccesses)++;
2468 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2469 fs_stats_AddTo((opP->sumTime), elapsedTime);
2470 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2471 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2472 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2474 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2475 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2479 #endif /* FS_STATS_DETAILED */
2481 osi_auditU(acall, FetchACLEvent, errorCode,
2482 AUD_ID, t_client ? t_client->ViceId : 0,
2484 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2486 } /*SRXAFS_FetchACL */
2490 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2491 * merged into it when possible.
2495 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2496 struct AFSFetchStatus *OutStatus,
2497 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2499 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2500 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2501 Error errorCode = 0; /* return code to caller */
2502 Volume *volptr = 0; /* pointer to the volume */
2503 struct client *client = 0; /* pointer to the client data */
2504 afs_int32 rights, anyrights; /* rights for this and any user */
2505 struct client *t_client = NULL; /* tmp ptr to client data */
2506 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2507 struct rx_connection *tcon = rx_ConnectionOf(acall);
2509 /* Get ptr to client data for user Id for logging */
2510 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2511 logHostAddr.s_addr = rxr_HostOf(tcon);
2513 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2514 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2515 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2517 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2520 * Get volume/vnode for the fetched file; caller's rights to it are
2524 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2525 &parentwhentargetnotdir, &client, READ_LOCK,
2526 &rights, &anyrights)))
2527 goto Bad_FetchStatus;
2529 /* set volume synchronization information */
2530 SetVolumeSync(Sync, volptr);
2532 /* Are we allowed to fetch Fid's status? */
2533 if (targetptr->disk.type != vDirectory) {
2535 Check_PermissionRights(targetptr, client, rights,
2536 CHK_FETCHSTATUS, 0))) {
2537 if (rx_GetCallAbortCode(acall) == errorCode)
2538 rx_SetCallAbortCode(acall, 0);
2539 goto Bad_FetchStatus;
2543 /* set OutStatus From the Fid */
2544 GetStatus(targetptr, OutStatus, rights, anyrights,
2545 parentwhentargetnotdir);
2547 /* If a r/w volume, also set the CallBack state */
2548 if (VolumeWriteable(volptr))
2549 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2551 struct AFSFid myFid;
2552 memset(&myFid, 0, sizeof(struct AFSFid));
2553 myFid.Volume = Fid->Volume;
2554 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2558 /* Update and store volume/vnode and parent vnodes back */
2559 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2561 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2564 } /*SAFSS_FetchStatus */
2568 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2569 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2570 struct AFSVolSync * Sync)
2574 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2575 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2576 Error errorCode = 0; /* return code to caller */
2577 Volume *volptr = 0; /* pointer to the volume */
2578 struct client *client = 0; /* pointer to the client data */
2579 afs_int32 rights, anyrights; /* rights for this and any user */
2580 register struct AFSFid *tfid; /* file id we're dealing with now */
2581 struct rx_connection *tcon = rx_ConnectionOf(acall);
2583 struct client *t_client = NULL; /* tmp pointer to the client data */
2584 #if FS_STATS_DETAILED
2585 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2586 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2587 struct timeval elapsedTime; /* Transfer time */
2590 * Set our stats pointer, remember when the RPC operation started, and
2591 * tally the operation.
2593 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2597 FT_GetTimeOfDay(&opStartTime, 0);
2598 #endif /* FS_STATS_DETAILED */
2600 ViceLog(1, ("SAFS_BulkStatus\n"));
2602 AFSCallStats.TotalCalls++;
2604 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2605 if (nfiles <= 0) { /* Sanity check */
2607 goto Audit_and_Return;
2610 /* allocate space for return output parameters */
2611 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2612 malloc(nfiles * sizeof(struct AFSFetchStatus));
2613 if (!OutStats->AFSBulkStats_val) {
2614 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2617 OutStats->AFSBulkStats_len = nfiles;
2618 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2619 malloc(nfiles * sizeof(struct AFSCallBack));
2620 if (!CallBacks->AFSCBs_val) {
2621 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2624 CallBacks->AFSCBs_len = nfiles;
2626 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2627 goto Bad_BulkStatus;
2629 tfid = Fids->AFSCBFids_val;
2630 for (i = 0; i < nfiles; i++, tfid++) {
2632 * Get volume/vnode for the fetched file; caller's rights to it
2636 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2637 &parentwhentargetnotdir, &client, READ_LOCK,
2638 &rights, &anyrights)))
2639 goto Bad_BulkStatus;
2640 /* set volume synchronization information, but only once per call */
2642 SetVolumeSync(Sync, volptr);
2644 /* Are we allowed to fetch Fid's status? */
2645 if (targetptr->disk.type != vDirectory) {
2647 Check_PermissionRights(targetptr, client, rights,
2648 CHK_FETCHSTATUS, 0))) {
2649 if (rx_GetCallAbortCode(acall) == errorCode)
2650 rx_SetCallAbortCode(acall, 0);
2651 goto Bad_BulkStatus;
2655 /* set OutStatus From the Fid */
2656 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2657 anyrights, parentwhentargetnotdir);
2659 /* If a r/w volume, also set the CallBack state */
2660 if (VolumeWriteable(volptr))
2661 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2662 &CallBacks->AFSCBs_val[i]);
2664 struct AFSFid myFid;
2665 memset(&myFid, 0, sizeof(struct AFSFid));
2666 myFid.Volume = tfid->Volume;
2667 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2668 &CallBacks->AFSCBs_val[i]);
2671 /* put back the file ID and volume */
2672 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2674 parentwhentargetnotdir = (Vnode *) 0;
2675 targetptr = (Vnode *) 0;
2676 volptr = (Volume *) 0;
2677 client = (struct client *)0;
2681 /* Update and store volume/vnode and parent vnodes back */
2682 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2684 errorCode = CallPostamble(tcon, errorCode, thost);
2686 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2688 #if FS_STATS_DETAILED
2689 FT_GetTimeOfDay(&opStopTime, 0);
2690 if (errorCode == 0) {
2692 (opP->numSuccesses)++;
2693 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2694 fs_stats_AddTo((opP->sumTime), elapsedTime);
2695 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2696 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2697 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2699 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2700 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2704 #endif /* FS_STATS_DETAILED */
2707 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2708 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2709 AUD_ID, t_client ? t_client->ViceId : 0,
2710 AUD_FIDS, Fids, AUD_END);
2713 } /*SRXAFS_BulkStatus */
2717 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2718 struct AFSBulkStats * OutStats,
2719 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2723 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2724 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2725 Error errorCode = 0; /* return code to caller */
2726 Volume *volptr = 0; /* pointer to the volume */
2727 struct client *client = 0; /* pointer to the client data */
2728 afs_int32 rights, anyrights; /* rights for this and any user */
2729 register struct AFSFid *tfid; /* file id we're dealing with now */
2730 struct rx_connection *tcon;
2732 struct client *t_client = NULL; /* tmp ptr to client data */
2733 AFSFetchStatus *tstatus;
2734 #if FS_STATS_DETAILED
2735 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2736 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2737 struct timeval elapsedTime; /* Transfer time */
2740 * Set our stats pointer, remember when the RPC operation started, and
2741 * tally the operation.
2743 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2747 FT_GetTimeOfDay(&opStartTime, 0);
2748 #endif /* FS_STATS_DETAILED */
2750 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2752 AFSCallStats.TotalCalls++;
2754 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2755 if (nfiles <= 0) { /* Sanity check */
2757 goto Audit_and_Return;
2760 /* allocate space for return output parameters */
2761 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2762 malloc(nfiles * sizeof(struct AFSFetchStatus));
2763 if (!OutStats->AFSBulkStats_val) {
2764 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2767 OutStats->AFSBulkStats_len = nfiles;
2768 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2769 malloc(nfiles * sizeof(struct AFSCallBack));
2770 if (!CallBacks->AFSCBs_val) {
2771 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2774 CallBacks->AFSCBs_len = nfiles;
2776 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2777 goto Bad_InlineBulkStatus;
2780 tfid = Fids->AFSCBFids_val;
2781 for (i = 0; i < nfiles; i++, tfid++) {
2783 * Get volume/vnode for the fetched file; caller's rights to it
2787 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2788 &parentwhentargetnotdir, &client, READ_LOCK,
2789 &rights, &anyrights))) {
2790 tstatus = &OutStats->AFSBulkStats_val[i];
2791 tstatus->errorCode = errorCode;
2792 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2794 parentwhentargetnotdir = (Vnode *) 0;
2795 targetptr = (Vnode *) 0;
2796 volptr = (Volume *) 0;
2797 client = (struct client *)0;
2801 /* set volume synchronization information, but only once per call */
2803 SetVolumeSync(Sync, volptr);
2805 /* Are we allowed to fetch Fid's status? */
2806 if (targetptr->disk.type != vDirectory) {
2808 Check_PermissionRights(targetptr, client, rights,
2809 CHK_FETCHSTATUS, 0))) {
2810 tstatus = &OutStats->AFSBulkStats_val[i];
2811 tstatus->errorCode = errorCode;
2812 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2813 (Vnode *) 0, volptr, &client);
2814 parentwhentargetnotdir = (Vnode *) 0;
2815 targetptr = (Vnode *) 0;
2816 volptr = (Volume *) 0;
2817 client = (struct client *)0;
2822 /* set OutStatus From the Fid */
2823 GetStatus(targetptr,
2824 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2825 rights, anyrights, parentwhentargetnotdir);
2827 /* If a r/w volume, also set the CallBack state */
2828 if (VolumeWriteable(volptr))
2829 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2830 &CallBacks->AFSCBs_val[i]);
2832 struct AFSFid myFid;
2833 memset(&myFid, 0, sizeof(struct AFSFid));
2834 myFid.Volume = tfid->Volume;
2835 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2836 &CallBacks->AFSCBs_val[i]);
2839 /* put back the file ID and volume */
2840 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2842 parentwhentargetnotdir = (Vnode *) 0;
2843 targetptr = (Vnode *) 0;
2844 volptr = (Volume *) 0;
2845 client = (struct client *)0;
2848 Bad_InlineBulkStatus:
2849 /* Update and store volume/vnode and parent vnodes back */
2850 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2852 errorCode = CallPostamble(tcon, errorCode, thost);
2854 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2856 #if FS_STATS_DETAILED
2857 FT_GetTimeOfDay(&opStopTime, 0);
2858 if (errorCode == 0) {
2860 (opP->numSuccesses)++;
2861 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2862 fs_stats_AddTo((opP->sumTime), elapsedTime);
2863 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2864 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2865 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2867 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2868 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2872 #endif /* FS_STATS_DETAILED */
2875 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2876 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2877 AUD_ID, t_client ? t_client->ViceId : 0,
2878 AUD_FIDS, Fids, AUD_END);
2881 } /*SRXAFS_InlineBulkStatus */
2885 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2886 struct AFSFetchStatus * OutStatus,
2887 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2890 struct rx_connection *tcon;
2892 struct client *t_client = NULL; /* tmp ptr to client data */
2893 #if FS_STATS_DETAILED
2894 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2895 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2896 struct timeval elapsedTime; /* Transfer time */
2899 * Set our stats pointer, remember when the RPC operation started, and
2900 * tally the operation.
2902 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2906 FT_GetTimeOfDay(&opStartTime, 0);
2907 #endif /* FS_STATS_DETAILED */
2909 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2910 goto Bad_FetchStatus;
2912 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2915 code = CallPostamble(tcon, code, thost);
2917 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2919 #if FS_STATS_DETAILED
2920 FT_GetTimeOfDay(&opStopTime, 0);
2923 (opP->numSuccesses)++;
2924 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2925 fs_stats_AddTo((opP->sumTime), elapsedTime);
2926 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2927 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2928 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2930 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2931 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2935 #endif /* FS_STATS_DETAILED */
2937 osi_auditU(acall, FetchStatusEvent, code,
2938 AUD_ID, t_client ? t_client->ViceId : 0,
2939 AUD_FID, Fid, AUD_END);
2942 } /*SRXAFS_FetchStatus */
2946 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2947 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2948 afs_fsize_t Length, afs_fsize_t FileLength,
2949 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2951 Vnode *targetptr = 0; /* pointer to input fid */
2952 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2953 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2954 Error errorCode = 0; /* return code for caller */
2955 Error fileCode = 0; /* return code from vol package */
2956 Volume *volptr = 0; /* pointer to the volume header */
2957 struct client *client = 0; /* pointer to client structure */
2958 afs_int32 rights, anyrights; /* rights for this and any user */
2959 struct client *t_client = NULL; /* tmp ptr to client data */
2960 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2961 struct rx_connection *tcon;
2963 #if FS_STATS_DETAILED
2964 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2965 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2966 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2967 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2968 struct timeval elapsedTime; /* Transfer time */
2969 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2970 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2971 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2974 * Set our stats pointers, remember when the RPC operation started, and
2975 * tally the operation.
2977 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2978 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2983 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2985 FT_GetTimeOfDay(&opStartTime, 0);
2986 #endif /* FS_STATS_DETAILED */
2989 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
2991 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2994 /* Get ptr to client data for user Id for logging */
2995 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2996 logHostAddr.s_addr = rxr_HostOf(tcon);
2998 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2999 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3000 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3003 * Get associated volume/vnode for the stored file; caller's rights
3007 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
3008 &parentwhentargetnotdir, &client, WRITE_LOCK,
3009 &rights, &anyrights))) {
3013 /* set volume synchronization information */
3014 SetVolumeSync(Sync, volptr);
3016 if ((targetptr->disk.type == vSymlink)) {
3017 /* Should we return a better error code here??? */
3022 /* Check if we're allowed to store the data */
3024 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
3030 * Drop the read lock on the parent directory after saving the parent
3031 * vnode information we need to pass to GetStatus
3033 if (parentwhentargetnotdir != NULL) {
3034 tparentwhentargetnotdir = *parentwhentargetnotdir;
3035 VPutVnode(&fileCode, parentwhentargetnotdir);
3036 assert(!fileCode || (fileCode == VSALVAGE));
3037 parentwhentargetnotdir = NULL;
3039 #if FS_STATS_DETAILED
3041 * Remember when the data transfer started.
3043 FT_GetTimeOfDay(&xferStartTime, 0);
3044 #endif /* FS_STATS_DETAILED */
3046 /* Do the actual storing of the data */
3047 #if FS_STATS_DETAILED
3049 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3050 FileLength, (InStatus->Mask & AFS_FSYNC),
3051 &bytesToXfer, &bytesXferred);
3054 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3055 FileLength, (InStatus->Mask & AFS_FSYNC));
3056 if (errorCode && (!targetptr->changed_newTime))
3058 #endif /* FS_STATS_DETAILED */
3059 #if FS_STATS_DETAILED
3061 * At this point, the data transfer is done, for good or ill. Remember
3062 * when the transfer ended, bump the number of successes/failures, and
3063 * integrate the transfer size and elapsed time into the stats. If the
3064 * operation failed, we jump to the appropriate point.
3066 FT_GetTimeOfDay(&xferStopTime, 0);
3068 (xferP->numXfers)++;
3070 (xferP->numSuccesses)++;
3073 * Bump the xfer sum by the number of bytes actually sent, NOT the
3076 tot_bytesXferred += bytesXferred;
3077 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3078 tot_bytesXferred &= 0x3FF;
3079 if (bytesXferred < xferP->minBytes)
3080 xferP->minBytes = bytesXferred;
3081 if (bytesXferred > xferP->maxBytes)
3082 xferP->maxBytes = bytesXferred;
3085 * Tally the size of the object. Note: we tally the actual size,
3086 * NOT the number of bytes that made it out over the wire.
3088 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3089 (xferP->count[0])++;
3090 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3091 (xferP->count[1])++;
3092 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3093 (xferP->count[2])++;
3094 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3095 (xferP->count[3])++;
3096 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3097 (xferP->count[4])++;
3098 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3099 (xferP->count[5])++;
3100 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3101 (xferP->count[6])++;
3102 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3103 (xferP->count[7])++;
3105 (xferP->count[8])++;
3107 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3108 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3109 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3110 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3111 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3113 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3114 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3119 * Finally, go off to tell our caller the bad news in case the
3122 if (errorCode && (!targetptr->changed_newTime))
3124 #endif /* FS_STATS_DETAILED */
3126 /* Update the status of the target's vnode */
3127 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3128 targetptr, volptr, 0);
3130 /* Get the updated File's status back to the caller */
3131 GetStatus(targetptr, OutStatus, rights, anyrights,
3132 &tparentwhentargetnotdir);
3135 /* Update and store volume/vnode and parent vnodes back */
3136 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3138 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3140 errorCode = CallPostamble(tcon, errorCode, thost);
3142 #if FS_STATS_DETAILED
3143 FT_GetTimeOfDay(&opStopTime, 0);
3144 if (errorCode == 0) {
3146 (opP->numSuccesses)++;
3147 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3148 fs_stats_AddTo((opP->sumTime), elapsedTime);
3149 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3150 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3151 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3153 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3154 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3158 #endif /* FS_STATS_DETAILED */
3159 osi_auditU(acall, StoreDataEvent, errorCode,
3160 AUD_ID, t_client ? t_client->ViceId : 0,
3161 AUD_FID, Fid, AUD_END);
3163 } /*common_StoreData64 */
3166 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3167 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3168 afs_uint32 Length, afs_uint32 FileLength,
3169 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3171 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3172 (0x7fffffff - Pos) < Length)
3175 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3177 } /*SRXAFS_StoreData */
3180 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3181 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3182 afs_uint64 Length, afs_uint64 FileLength,
3183 struct AFSFetchStatus * OutStatus,
3184 struct AFSVolSync * Sync)
3188 afs_fsize_t tLength;
3189 afs_fsize_t tFileLength;
3191 #ifdef AFS_64BIT_ENV
3192 tPos = (afs_fsize_t) Pos;
3193 tLength = (afs_fsize_t) Length;
3194 tFileLength = (afs_fsize_t) FileLength;
3195 #else /* AFS_64BIT_ENV */
3196 if (FileLength.high)
3199 tLength = Length.low;
3200 tFileLength = FileLength.low;
3201 #endif /* AFS_64BIT_ENV */
3204 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3210 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3211 struct AFSOpaque * AccessList,
3212 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3214 Vnode *targetptr = 0; /* pointer to input fid */
3215 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3216 Error errorCode = 0; /* return code for caller */
3217 struct AFSStoreStatus InStatus; /* Input status for fid */
3218 Volume *volptr = 0; /* pointer to the volume header */
3219 struct client *client = 0; /* pointer to client structure */
3220 afs_int32 rights, anyrights; /* rights for this and any user */
3221 struct rx_connection *tcon;
3223 struct client *t_client = NULL; /* tmp ptr to client data */
3224 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3225 #if FS_STATS_DETAILED
3226 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3227 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3228 struct timeval elapsedTime; /* Transfer time */
3231 * Set our stats pointer, remember when the RPC operation started, and
3232 * tally the operation.
3234 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3238 FT_GetTimeOfDay(&opStartTime, 0);
3239 #endif /* FS_STATS_DETAILED */
3240 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3243 /* Get ptr to client data for user Id for logging */
3244 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3245 logHostAddr.s_addr = rxr_HostOf(tcon);
3247 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3248 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3249 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3251 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3253 InStatus.Mask = 0; /* not storing any status */
3256 * Get associated volume/vnode for the target dir; caller's rights
3257 * are also returned.
3260 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3261 &parentwhentargetnotdir, &client, WRITE_LOCK,
3262 &rights, &anyrights))) {
3266 /* set volume synchronization information */
3267 SetVolumeSync(Sync, volptr);
3269 /* Check if we have permission to change the dir's ACL */
3271 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3276 /* Build and store the new Access List for the dir */
3277 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3281 targetptr->changed_newTime = 1; /* status change of directory */
3283 /* convert the write lock to a read lock before breaking callbacks */
3284 VVnodeWriteToRead(&errorCode, targetptr);
3285 assert(!errorCode || errorCode == VSALVAGE);
3287 /* break call backs on the directory */
3288 BreakCallBack(client->host, Fid, 0);
3290 /* Get the updated dir's status back to the caller */
3291 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3294 /* Update and store volume/vnode and parent vnodes back */
3295 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3297 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3298 errorCode = CallPostamble(tcon, errorCode, thost);
3300 #if FS_STATS_DETAILED
3301 FT_GetTimeOfDay(&opStopTime, 0);
3302 if (errorCode == 0) {
3304 (opP->numSuccesses)++;
3305 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3306 fs_stats_AddTo((opP->sumTime), elapsedTime);
3307 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3308 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3309 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3311 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3312 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3316 #endif /* FS_STATS_DETAILED */
3318 osi_auditU(acall, StoreACLEvent, errorCode,
3319 AUD_ID, t_client ? t_client->ViceId : 0,
3320 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3323 } /*SRXAFS_StoreACL */
3327 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3328 * should be merged when possible.
3331 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3332 struct AFSStoreStatus *InStatus,
3333 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3335 Vnode *targetptr = 0; /* pointer to input fid */
3336 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3337 Error errorCode = 0; /* return code for caller */
3338 Volume *volptr = 0; /* pointer to the volume header */
3339 struct client *client = 0; /* pointer to client structure */
3340 afs_int32 rights, anyrights; /* rights for this and any user */
3341 struct client *t_client = NULL; /* tmp ptr to client data */
3342 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3343 struct rx_connection *tcon = rx_ConnectionOf(acall);
3345 /* Get ptr to client data for user Id for logging */
3346 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3347 logHostAddr.s_addr = rxr_HostOf(tcon);
3349 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3350 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3351 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3353 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3356 * Get volume/vnode for the target file; caller's rights to it are
3360 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3361 &parentwhentargetnotdir, &client, WRITE_LOCK,
3362 &rights, &anyrights))) {
3363 goto Bad_StoreStatus;
3366 /* set volume synchronization information */
3367 SetVolumeSync(Sync, volptr);
3369 /* Check if the caller has proper permissions to store status to Fid */
3371 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3373 goto Bad_StoreStatus;
3376 * Check for a symbolic link; we can't chmod these (otherwise could
3377 * change a symlink to a mt pt or vice versa)
3379 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3381 goto Bad_StoreStatus;
3384 /* Update the status of the target's vnode */
3385 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3386 (parentwhentargetnotdir ? parentwhentargetnotdir
3387 : targetptr), volptr, 0);
3389 /* convert the write lock to a read lock before breaking callbacks */
3390 VVnodeWriteToRead(&errorCode, targetptr);
3391 assert(!errorCode || errorCode == VSALVAGE);
3393 /* Break call backs on Fid */
3394 BreakCallBack(client->host, Fid, 0);
3396 /* Return the updated status back to caller */
3397 GetStatus(targetptr, OutStatus, rights, anyrights,
3398 parentwhentargetnotdir);
3401 /* Update and store volume/vnode and parent vnodes back */
3402 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3404 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3407 } /*SAFSS_StoreStatus */
3411 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3412 struct AFSStoreStatus * InStatus,
3413 struct AFSFetchStatus * OutStatus,
3414 struct AFSVolSync * Sync)
3417 struct rx_connection *tcon;
3419 struct client *t_client = NULL; /* tmp ptr to client data */
3420 #if FS_STATS_DETAILED
3421 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3422 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3423 struct timeval elapsedTime; /* Transfer time */
3426 * Set our stats pointer, remember when the RPC operation started, and
3427 * tally the operation.
3429 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3433 FT_GetTimeOfDay(&opStartTime, 0);
3434 #endif /* FS_STATS_DETAILED */
3436 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3437 goto Bad_StoreStatus;
3439 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3442 code = CallPostamble(tcon, code, thost);
3444 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3446 #if FS_STATS_DETAILED
3447 FT_GetTimeOfDay(&opStopTime, 0);
3450 (opP->numSuccesses)++;
3451 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3452 fs_stats_AddTo((opP->sumTime), elapsedTime);
3453 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3454 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3455 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3457 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3458 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3462 #endif /* FS_STATS_DETAILED */
3464 osi_auditU(acall, StoreStatusEvent, code,
3465 AUD_ID, t_client ? t_client->ViceId : 0,
3466 AUD_FID, Fid, AUD_END);
3469 } /*SRXAFS_StoreStatus */
3473 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3474 * merged in when possible.
3477 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3478 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3480 Vnode *parentptr = 0; /* vnode of input Directory */
3481 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3482 Vnode *targetptr = 0; /* file to be deleted */
3483 Volume *volptr = 0; /* pointer to the volume header */
3484 AFSFid fileFid; /* area for Fid from the directory */
3485 Error errorCode = 0; /* error code */
3486 DirHandle dir; /* Handle for dir package I/O */
3487 struct client *client = 0; /* pointer to client structure */
3488 afs_int32 rights, anyrights; /* rights for this and any user */
3489 struct client *t_client; /* tmp ptr to client data */
3490 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3491 struct rx_connection *tcon = rx_ConnectionOf(acall);
3494 /* Get ptr to client data for user Id for logging */
3495 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3496 logHostAddr.s_addr = rxr_HostOf(tcon);
3498 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3499 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3500 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3502 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3505 * Get volume/vnode for the parent dir; caller's access rights are
3509 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3510 &parentwhentargetnotdir, &client, WRITE_LOCK,
3511 &rights, &anyrights))) {
3512 goto Bad_RemoveFile;
3514 /* set volume synchronization information */
3515 SetVolumeSync(Sync, volptr);
3517 /* Does the caller has delete (& write) access to the parent directory? */
3518 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3519 goto Bad_RemoveFile;
3522 /* Actually delete the desired file */
3524 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3526 goto Bad_RemoveFile;
3529 /* Update the vnode status of the parent dir */
3530 #if FS_STATS_DETAILED
3531 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3532 parentptr->disk.linkCount,
3533 client->InSameNetwork);
3535 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3536 parentptr->disk.linkCount);
3537 #endif /* FS_STATS_DETAILED */
3539 /* Return the updated parent dir's status back to caller */
3540 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3542 /* Handle internal callback state for the parent and the deleted file */
3543 if (targetptr->disk.linkCount == 0) {
3544 /* no references left, discard entry */
3545 DeleteFileCallBacks(&fileFid);
3546 /* convert the parent lock to a read lock before breaking callbacks */
3547 VVnodeWriteToRead(&errorCode, parentptr);
3548 assert(!errorCode || errorCode == VSALVAGE);
3550 /* convert the parent lock to a read lock before breaking callbacks */
3551 VVnodeWriteToRead(&errorCode, parentptr);
3552 assert(!errorCode || errorCode == VSALVAGE);
3553 /* convert the target lock to a read lock before breaking callbacks */
3554 VVnodeWriteToRead(&errorCode, targetptr);
3555 assert(!errorCode || errorCode == VSALVAGE);
3556 /* tell all the file has changed */
3557 BreakCallBack(client->host, &fileFid, 1);
3560 /* break call back on the directory */
3561 BreakCallBack(client->host, DirFid, 0);
3564 /* Update and store volume/vnode and parent vnodes back */
3565 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3568 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3571 } /*SAFSS_RemoveFile */
3575 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3576 struct AFSFetchStatus * OutDirStatus,
3577 struct AFSVolSync * Sync)
3580 struct rx_connection *tcon;
3582 struct client *t_client = NULL; /* tmp ptr to client data */
3583 #if FS_STATS_DETAILED
3584 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3585 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3586 struct timeval elapsedTime; /* Transfer time */
3589 * Set our stats pointer, remember when the RPC operation started, and
3590 * tally the operation.
3592 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3596 FT_GetTimeOfDay(&opStartTime, 0);
3597 #endif /* FS_STATS_DETAILED */
3599 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3600 goto Bad_RemoveFile;
3602 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3605 code = CallPostamble(tcon, code, thost);
3607 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3609 #if FS_STATS_DETAILED
3610 FT_GetTimeOfDay(&opStopTime, 0);
3613 (opP->numSuccesses)++;
3614 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3615 fs_stats_AddTo((opP->sumTime), elapsedTime);
3616 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3617 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3618 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3620 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3621 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3625 #endif /* FS_STATS_DETAILED */
3627 osi_auditU(acall, RemoveFileEvent, code,
3628 AUD_ID, t_client ? t_client->ViceId : 0,
3629 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3632 } /*SRXAFS_RemoveFile */
3636 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3637 * be merged in when possible.
3640 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3641 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3642 struct AFSFetchStatus *OutFidStatus,
3643 struct AFSFetchStatus *OutDirStatus,
3644 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3646 Vnode *parentptr = 0; /* vnode of input Directory */
3647 Vnode *targetptr = 0; /* vnode of the new file */
3648 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3649 Volume *volptr = 0; /* pointer to the volume header */
3650 Error errorCode = 0; /* error code */
3651 DirHandle dir; /* Handle for dir package I/O */
3652 struct client *client = 0; /* pointer to client structure */
3653 afs_int32 rights, anyrights; /* rights for this and any user */
3654 struct client *t_client; /* tmp ptr to client data */
3655 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3656 struct rx_connection *tcon = rx_ConnectionOf(acall);
3660 /* Get ptr to client data for user Id for logging */
3661 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3662 logHostAddr.s_addr = rxr_HostOf(tcon);
3664 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3665 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3666 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3668 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3670 if (!FileNameOK(Name)) {
3672 goto Bad_CreateFile;
3676 * Get associated volume/vnode for the parent dir; caller long are
3680 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3681 &parentwhentargetnotdir, &client, WRITE_LOCK,
3682 &rights, &anyrights))) {
3683 goto Bad_CreateFile;
3686 /* set volume synchronization information */
3687 SetVolumeSync(Sync, volptr);
3689 /* Can we write (and insert) onto the parent directory? */
3690 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3691 goto Bad_CreateFile;
3693 /* get a new vnode for the file to be created and set it up */
3695 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3696 vFile, nBlocks(0)))) {
3697 goto Bad_CreateFile;
3700 /* update the status of the parent vnode */
3701 #if FS_STATS_DETAILED
3702 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3703 parentptr->disk.linkCount,
3704 client->InSameNetwork);
3706 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3707 parentptr->disk.linkCount);
3708 #endif /* FS_STATS_DETAILED */
3710 /* update the status of the new file's vnode */
3711 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3712 parentptr, volptr, 0);
3714 /* 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 */
3715 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3716 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3718 /* convert the write lock to a read lock before breaking callbacks */
3719 VVnodeWriteToRead(&errorCode, parentptr);
3720 assert(!errorCode || errorCode == VSALVAGE);
3722 /* break call back on parent dir */
3723 BreakCallBack(client->host, DirFid, 0);
3725 /* Return a callback promise for the newly created file to the caller */
3726 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3729 /* Update and store volume/vnode and parent vnodes back */
3730 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3733 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3736 } /*SAFSS_CreateFile */
3740 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3741 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3742 struct AFSFetchStatus * OutFidStatus,
3743 struct AFSFetchStatus * OutDirStatus,
3744 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3747 struct rx_connection *tcon;
3749 struct client *t_client = NULL; /* tmp ptr to client data */
3750 #if FS_STATS_DETAILED
3751 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3752 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3753 struct timeval elapsedTime; /* Transfer time */
3756 * Set our stats pointer, remember when the RPC operation started, and
3757 * tally the operation.
3759 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3763 FT_GetTimeOfDay(&opStartTime, 0);
3764 #endif /* FS_STATS_DETAILED */
3766 memset(OutFid, 0, sizeof(struct AFSFid));
3768 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3769 goto Bad_CreateFile;
3772 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3773 OutDirStatus, CallBack, Sync);
3776 code = CallPostamble(tcon, code, thost);
3778 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3780 #if FS_STATS_DETAILED
3781 FT_GetTimeOfDay(&opStopTime, 0);
3784 (opP->numSuccesses)++;
3785 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3786 fs_stats_AddTo((opP->sumTime), elapsedTime);
3787 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3788 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3789 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3791 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3792 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3796 #endif /* FS_STATS_DETAILED */
3798 osi_auditU(acall, CreateFileEvent, code,
3799 AUD_ID, t_client ? t_client->ViceId : 0,
3800 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3803 } /*SRXAFS_CreateFile */
3807 * This routine is called exclusively from SRXAFS_Rename(), and should be
3808 * merged in when possible.
3811 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3812 struct AFSFid *NewDirFid, char *NewName,
3813 struct AFSFetchStatus *OutOldDirStatus,
3814 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3816 Vnode *oldvptr = 0; /* vnode of the old Directory */
3817 Vnode *newvptr = 0; /* vnode of the new Directory */
3818 Vnode *fileptr = 0; /* vnode of the file to move */
3819 Vnode *newfileptr = 0; /* vnode of the file to delete */
3820 Vnode *testvptr = 0; /* used in directory tree walk */
3821 Vnode *parent = 0; /* parent for use in SetAccessList */
3822 Error errorCode = 0; /* error code */
3823 Error fileCode = 0; /* used when writing Vnodes */
3824 VnodeId testnode; /* used in directory tree walk */
3825 AFSFid fileFid; /* Fid of file to move */
3826 AFSFid newFileFid; /* Fid of new file */
3827 DirHandle olddir; /* Handle for dir package I/O */
3828 DirHandle newdir; /* Handle for dir package I/O */
3829 DirHandle filedir; /* Handle for dir package I/O */
3830 DirHandle newfiledir; /* Handle for dir package I/O */
3831 Volume *volptr = 0; /* pointer to the volume header */
3832 struct client *client = 0; /* pointer to client structure */
3833 afs_int32 rights, anyrights; /* rights for this and any user */
3834 afs_int32 newrights; /* rights for this user */
3835 afs_int32 newanyrights; /* rights for any user */
3836 int doDelete; /* deleted the rename target (ref count now 0) */
3838 struct client *t_client; /* tmp ptr to client data */
3839 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3840 struct rx_connection *tcon = rx_ConnectionOf(acall);
3845 FidZero(&newfiledir);
3847 /* Get ptr to client data for user Id for logging */
3848 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3849 logHostAddr.s_addr = rxr_HostOf(tcon);
3851 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3852 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3853 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3854 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3856 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3858 if (!FileNameOK(NewName)) {
3862 if (OldDirFid->Volume != NewDirFid->Volume) {
3867 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3868 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3869 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3875 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3877 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3878 &parent, &client, WRITE_LOCK, &rights,
3883 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3885 newrights = rights, newanyrights = anyrights;
3888 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3889 MustBeDIR, &parent, &client, WRITE_LOCK,
3890 &newrights, &newanyrights))) {
3896 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3897 &parent, &client, WRITE_LOCK, &newrights,
3903 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3904 &parent, &client, WRITE_LOCK, &rights,
3911 /* set volume synchronization information */
3912 SetVolumeSync(Sync, volptr);
3914 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3917 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3921 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3922 * call to CopyOnWrite returns error, it is not necessary to revert back
3923 * the effects of the first call because the contents of the volume is
3924 * not modified, it is only replicated.
3926 if (oldvptr->disk.cloned) {
3927 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3928 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
3931 SetDirHandle(&olddir, oldvptr);
3932 if (newvptr->disk.cloned) {
3933 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3934 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
3938 SetDirHandle(&newdir, newvptr);
3940 /* Lookup the file to delete its vnode */
3941 if (Lookup(&olddir, OldName, &fileFid)) {
3945 if (fileFid.Vnode == oldvptr->vnodeNumber
3946 || fileFid.Vnode == newvptr->vnodeNumber) {
3947 errorCode = FSERR_ELOOP;
3950 fileFid.Volume = V_id(volptr);
3951 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3952 if (errorCode != 0) {
3954 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3955 OldName, errorCode));
3956 VTakeOffline(volptr);
3959 if (fileptr->disk.uniquifier != fileFid.Unique) {
3961 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3963 VTakeOffline(volptr);
3968 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3969 && fileptr->disk.linkCount != 1) {
3971 * Hard links exist to this file - cannot move one of the links to
3972 * a new directory because of AFS restrictions (this is the same
3973 * reason that links cannot be made across directories, i.e.
3980 /* Lookup the new file */
3981 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3982 if (readonlyServer) {
3983 errorCode = VREADONLY;
3986 if (!(newrights & PRSFS_DELETE)) {
3990 if (newFileFid.Vnode == oldvptr->vnodeNumber
3991 || newFileFid.Vnode == newvptr->vnodeNumber
3992 || newFileFid.Vnode == fileFid.Vnode) {
3996 newFileFid.Volume = V_id(volptr);
3998 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
3999 if (errorCode != 0) {
4001 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
4002 NewName, errorCode));
4003 VTakeOffline(volptr);
4006 if (fileptr->disk.uniquifier != fileFid.Unique) {
4008 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
4010 VTakeOffline(volptr);
4014 SetDirHandle(&newfiledir, newfileptr);
4015 /* Now check that we're moving directories over directories properly, etc.
4016 * return proper POSIX error codes:
4017 * if fileptr is a file and new is a dir: EISDIR.
4018 * if fileptr is a dir and new is a file: ENOTDIR.
4019 * Also, dir to be removed must be empty, of course.
4021 if (newfileptr->disk.type == vDirectory) {
4022 if (fileptr->disk.type != vDirectory) {
4026 if ((IsEmpty(&newfiledir))) {
4031 if (fileptr->disk.type == vDirectory) {
4032 errorCode = ENOTDIR;
4039 * ok - now we check that the old name is not above new name in the
4040 * directory structure. This is to prevent removing a subtree alltogether
4042 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
4043 afs_int32 forpass = 0, vnum = 0, top = 0;
4044 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
4045 if (testnode > vnum) vnum = testnode;
4046 if (forpass > vnum) {
4047 errorCode = FSERR_ELOOP;
4050 if (testnode == oldvptr->vnodeNumber) {
4051 testnode = oldvptr->disk.parent;
4054 if ((testnode == fileptr->vnodeNumber)
4055 || (testnode == newvptr->vnodeNumber)) {
4056 errorCode = FSERR_ELOOP;
4059 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
4060 errorCode = FSERR_ELOOP;
4063 if (testnode == 1) top = 1;
4064 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
4065 assert(errorCode == 0);
4066 testnode = testvptr->disk.parent;
4067 VPutVnode(&errorCode, testvptr);
4068 if ((top == 1) && (testnode != 0)) {
4069 VTakeOffline(volptr);
4071 ("Volume %u now offline, must be salvaged.\n",
4076 assert(errorCode == 0);
4079 /* Do the CopyonWrite first before modifying anything else. Copying is
4080 * required because we may have to change entries for ..
4082 if ((fileptr->disk.type == vDirectory) && (fileptr->disk.cloned)) {
4083 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
4084 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
4088 /* If the new name exists already, delete it and the file it points to */
4091 /* Delete NewName from its directory */
4092 code = Delete(&newdir, NewName);
4095 /* Drop the link count */
4096 newfileptr->disk.linkCount--;
4097 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4098 afs_fsize_t newSize;
4099 VN_GET_LEN(newSize, newfileptr);
4100 VAdjustDiskUsage((Error *) & errorCode, volptr,
4101 (afs_sfsize_t) - nBlocks(newSize), 0);
4102 if (VN_GET_INO(newfileptr)) {
4103 IH_REALLYCLOSE(newfileptr->handle);
4105 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
4106 V_parentId(volptr));
4107 IH_RELEASE(newfileptr->handle);
4108 if (errorCode == -1) {
4110 ("Del: inode=%s, name=%s, errno=%d\n",
4111 PrintInode(NULL, VN_GET_INO(newfileptr)),
4113 if ((errno != ENOENT) && (errno != EIO)
4114 && (errno != ENXIO))
4115 ViceLog(0, ("Do we need to fsck?"));
4118 VN_SET_INO(newfileptr, (Inode) 0);
4119 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4122 /* Link count did not drop to zero.
4123 * Mark NewName vnode as changed - updates stime.
4125 newfileptr->changed_newTime = 1;
4130 * If the create below fails, and the delete above worked, we have
4131 * removed the new name and not replaced it. This is not very likely,
4132 * but possible. We could try to put the old file back, but it is
4133 * highly unlikely that it would work since it would involve issuing
4136 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4139 /* Delete the old name */
4140 assert(Delete(&olddir, (char *)OldName) == 0);
4142 /* if the directory length changes, reflect it in the statistics */
4143 #if FS_STATS_DETAILED
4144 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4145 oldvptr->disk.linkCount, client->InSameNetwork);
4146 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4147 newvptr->disk.linkCount, client->InSameNetwork);
4149 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4150 oldvptr->disk.linkCount);
4151 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4152 newvptr->disk.linkCount);
4153 #endif /* FS_STATS_DETAILED */
4155 if (oldvptr == newvptr)
4156 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4158 fileptr->disk.parent = newvptr->vnodeNumber;
4159 fileptr->changed_newTime = 1; /* status change of moved file */
4161 /* if we are dealing with a rename of a directory */
4162 if (fileptr->disk.type == vDirectory) {
4163 assert(!fileptr->disk.cloned);
4164 SetDirHandle(&filedir, fileptr);
4165 /* fix .. to point to the correct place */
4166 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4167 assert(Create(&filedir, "..", NewDirFid) == 0);
4168 fileptr->disk.dataVersion++;
4169 /* if the parent directories are different the link counts have to be */
4170 /* changed due to .. in the renamed directory */
4171 if (oldvptr != newvptr) {
4172 oldvptr->disk.linkCount--;
4173 newvptr->disk.linkCount++;
4177 /* set up return status */
4178 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4179 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4180 if (newfileptr && doDelete) {
4181 DeleteFileCallBacks(&newFileFid); /* no other references */
4186 /* convert the write locks to a read locks before breaking callbacks */
4187 VVnodeWriteToRead(&errorCode, newvptr);
4188 assert(!errorCode || errorCode == VSALVAGE);
4189 if (oldvptr != newvptr) {
4190 VVnodeWriteToRead(&errorCode, oldvptr);
4191 assert(!errorCode || errorCode == VSALVAGE);
4193 if (newfileptr && !doDelete) {
4194 /* convert the write lock to a read lock before breaking callbacks */
4195 VVnodeWriteToRead(&errorCode, newfileptr);
4196 assert(!errorCode || errorCode == VSALVAGE);
4199 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4200 BreakCallBack(client->host, NewDirFid, 0);
4201 if (oldvptr != newvptr) {
4202 BreakCallBack(client->host, OldDirFid, 0);
4203 if (fileptr->disk.type == vDirectory) /* if a dir moved, .. changed */
4204 BreakCallBack(client->host, &fileFid, 0);
4207 /* Note: it is not necessary to break the callback */
4209 DeleteFileCallBacks(&newFileFid); /* no other references */
4211 /* other's still exist (with wrong link count) */
4212 BreakCallBack(client->host, &newFileFid, 1);
4217 VPutVnode(&fileCode, newfileptr);
4218 assert(fileCode == 0);
4220 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
4221 newvptr : 0), oldvptr, volptr, &client);
4225 FidZap(&newfiledir);
4226 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4233 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4234 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4235 struct AFSFetchStatus * OutOldDirStatus,
4236 struct AFSFetchStatus * OutNewDirStatus,
4237 struct AFSVolSync * Sync)
4240 struct rx_connection *tcon;
4242 struct client *t_client = NULL; /* tmp ptr to client data */
4243 #if FS_STATS_DETAILED
4244 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4245 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4246 struct timeval elapsedTime; /* Transfer time */
4249 * Set our stats pointer, remember when the RPC operation started, and
4250 * tally the operation.
4252 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4256 FT_GetTimeOfDay(&opStartTime, 0);
4257 #endif /* FS_STATS_DETAILED */
4259 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4263 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4264 OutOldDirStatus, OutNewDirStatus, Sync);
4267 code = CallPostamble(tcon, code, thost);
4269 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4271 #if FS_STATS_DETAILED
4272 FT_GetTimeOfDay(&opStopTime, 0);
4275 (opP->numSuccesses)++;
4276 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4277 fs_stats_AddTo((opP->sumTime), elapsedTime);
4278 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4279 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4280 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4282 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4283 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4287 #endif /* FS_STATS_DETAILED */
4289 osi_auditU(acall, RenameFileEvent, code,
4290 AUD_ID, t_client ? t_client->ViceId : 0,
4291 AUD_FID, OldDirFid, AUD_STR, OldName,
4292 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4295 } /*SRXAFS_Rename */
4299 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4300 * merged into it when possible.
4303 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4304 char *LinkContents, struct AFSStoreStatus *InStatus,
4305 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4306 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4308 Vnode *parentptr = 0; /* vnode of input Directory */
4309 Vnode *targetptr = 0; /* vnode of the new link */
4310 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4311 Error errorCode = 0; /* error code */
4313 DirHandle dir; /* Handle for dir package I/O */
4314 Volume *volptr = 0; /* pointer to the volume header */
4315 struct client *client = 0; /* pointer to client structure */
4316 afs_int32 rights, anyrights; /* rights for this and any user */
4317 struct client *t_client; /* tmp ptr to client data */
4318 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4320 struct rx_connection *tcon = rx_ConnectionOf(acall);
4324 /* Get ptr to client data for user Id for logging */
4325 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4326 logHostAddr.s_addr = rxr_HostOf(tcon);
4328 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4329 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4330 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4332 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4334 if (!FileNameOK(Name)) {
4340 * Get the vnode and volume for the parent dir along with the caller's
4344 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4345 &parentwhentargetnotdir, &client, WRITE_LOCK,
4346 &rights, &anyrights))) {
4350 /* set volume synchronization information */
4351 SetVolumeSync(Sync, volptr);
4353 /* Does the caller has insert (and write) access to the parent directory? */
4354 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4359 * If we're creating a mount point (any x bits clear), we must have
4360 * administer access to the directory, too. Always allow sysadmins
4363 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4364 if (readonlyServer) {
4365 errorCode = VREADONLY;
4369 * We have a mountpoint, 'cause we're trying to set the Unix mode
4370 * bits to something with some x bits missing (default mode bits
4371 * if AFS_SETMODE is false is 0777)
4373 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4379 /* get a new vnode for the symlink and set it up */
4381 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4382 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4386 /* update the status of the parent vnode */
4387 #if FS_STATS_DETAILED
4388 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4389 parentptr->disk.linkCount,
4390 client->InSameNetwork);
4392 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4393 parentptr->disk.linkCount);
4394 #endif /* FS_STATS_DETAILED */
4396 /* update the status of the new symbolic link file vnode */
4397 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4398 parentptr, volptr, strlen((char *)LinkContents));
4400 /* Write the contents of the symbolic link name into the target inode */
4401 fdP = IH_OPEN(targetptr->handle);
4403 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4405 VTakeOffline(volptr);
4406 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
4410 len = strlen((char *) LinkContents);
4411 code = (len == FDH_WRITE(fdP, (char *) LinkContents, len)) ? 0 : VDISKFULL;
4413 ViceLog(0, ("SAFSS_Symlink FDH_WRITE failed for len=%d, Fid=%u.%d.%d\n", len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4416 * Set up and return modified status for the parent dir and new symlink
4419 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4420 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4422 /* convert the write lock to a read lock before breaking callbacks */
4423 VVnodeWriteToRead(&errorCode, parentptr);
4424 assert(!errorCode || errorCode == VSALVAGE);
4426 /* break call back on the parent dir */
4427 BreakCallBack(client->host, DirFid, 0);
4430 /* Write the all modified vnodes (parent, new files) and volume back */
4431 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4434 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4435 return ( errorCode ? errorCode : code );
4437 } /*SAFSS_Symlink */
4441 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4442 struct AFSFid *DirFid, /* Parent dir's fid */
4443 char *Name, /* File name to create */
4444 char *LinkContents, /* Contents of the new created file */
4445 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4446 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4447 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4448 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4449 struct AFSVolSync *Sync)
4452 struct rx_connection *tcon;
4454 struct client *t_client = NULL; /* tmp ptr to client data */
4455 #if FS_STATS_DETAILED
4456 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4457 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4458 struct timeval elapsedTime; /* Transfer time */
4461 * Set our stats pointer, remember when the RPC operation started, and
4462 * tally the operation.
4464 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4468 FT_GetTimeOfDay(&opStartTime, 0);
4469 #endif /* FS_STATS_DETAILED */
4471 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4475 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4476 OutFidStatus, OutDirStatus, Sync);
4479 code = CallPostamble(tcon, code, thost);
4481 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4483 #if FS_STATS_DETAILED
4484 FT_GetTimeOfDay(&opStopTime, 0);
4487 (opP->numSuccesses)++;
4488 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4489 fs_stats_AddTo((opP->sumTime), elapsedTime);
4490 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4491 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4492 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4494 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4495 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4499 #endif /* FS_STATS_DETAILED */
4501 osi_auditU(acall, SymlinkEvent, code,
4502 AUD_ID, t_client ? t_client->ViceId : 0,
4503 AUD_FID, DirFid, AUD_STR, Name,
4504 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4507 } /*SRXAFS_Symlink */
4511 * This routine is called exclusively by SRXAFS_Link(), and should be
4512 * merged into it when possible.
4515 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4516 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4517 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4519 Vnode *parentptr = 0; /* vnode of input Directory */
4520 Vnode *targetptr = 0; /* vnode of the new file */
4521 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4522 Volume *volptr = 0; /* pointer to the volume header */
4523 Error errorCode = 0; /* error code */
4524 DirHandle dir; /* Handle for dir package I/O */
4525 struct client *client = 0; /* pointer to client structure */
4526 afs_int32 rights, anyrights; /* rights for this and any user */
4527 struct client *t_client; /* tmp ptr to client data */
4528 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4529 struct rx_connection *tcon = rx_ConnectionOf(acall);
4533 /* Get ptr to client data for user Id for logging */
4534 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4535 logHostAddr.s_addr = rxr_HostOf(tcon);
4537 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4538 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4539 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4540 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4542 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4544 if (DirFid->Volume != ExistingFid->Volume) {
4548 if (!FileNameOK(Name)) {
4554 * Get the vnode and volume for the parent dir along with the caller's
4558 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4559 &parentwhentargetnotdir, &client, WRITE_LOCK,
4560 &rights, &anyrights))) {
4564 /* set volume synchronization information */
4565 SetVolumeSync(Sync, volptr);
4567 /* Can the caller insert into the parent directory? */
4568 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4572 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4573 /* AFS fileservers always have directory vnodes that are odd. */
4578 /* get the file vnode */
4580 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4583 if (targetptr->disk.type != vFile) {
4587 if (targetptr->disk.parent != DirFid->Vnode) {
4591 if (parentptr->disk.cloned) {
4592 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4593 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4594 goto Bad_Link; /* disk full error */
4597 /* add the name to the directory */
4598 SetDirHandle(&dir, parentptr);
4599 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4603 /* update the status in the parent vnode */
4604 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4605 #if FS_STATS_DETAILED
4606 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4607 parentptr->disk.linkCount,
4608 client->InSameNetwork);
4610 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4611 parentptr->disk.linkCount);
4612 #endif /* FS_STATS_DETAILED */
4614 targetptr->disk.linkCount++;
4615 targetptr->disk.author = client->ViceId;
4616 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4618 /* set up return status */
4619 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4620 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4622 /* convert the write locks to read locks before breaking callbacks */
4623 VVnodeWriteToRead(&errorCode, targetptr);
4624 assert(!errorCode || errorCode == VSALVAGE);
4625 VVnodeWriteToRead(&errorCode, parentptr);
4626 assert(!errorCode || errorCode == VSALVAGE);
4628 /* break call back on DirFid */
4629 BreakCallBack(client->host, DirFid, 0);
4631 * We also need to break the callback for the file that is hard-linked since part
4632 * of its status (like linkcount) is changed
4634 BreakCallBack(client->host, ExistingFid, 0);
4637 /* Write the all modified vnodes (parent, new files) and volume back */
4638 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4641 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4648 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4649 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4650 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4653 struct rx_connection *tcon;
4655 struct client *t_client = NULL; /* tmp ptr to client data */
4656 #if FS_STATS_DETAILED
4657 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4658 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4659 struct timeval elapsedTime; /* Transfer time */
4662 * Set our stats pointer, remember when the RPC operation started, and
4663 * tally the operation.
4665 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4669 FT_GetTimeOfDay(&opStartTime, 0);
4670 #endif /* FS_STATS_DETAILED */
4672 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4676 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4677 OutDirStatus, Sync);
4680 code = CallPostamble(tcon, code, thost);
4682 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4684 #if FS_STATS_DETAILED
4685 FT_GetTimeOfDay(&opStopTime, 0);
4688 (opP->numSuccesses)++;
4689 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4690 fs_stats_AddTo((opP->sumTime), elapsedTime);
4691 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4692 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4693 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4695 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4696 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4700 #endif /* FS_STATS_DETAILED */
4702 osi_auditU(acall, LinkEvent, code,
4703 AUD_ID, t_client ? t_client->ViceId : 0,
4704 AUD_FID, DirFid, AUD_STR, Name,
4705 AUD_FID, ExistingFid, AUD_END);
4712 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4713 * merged into it when possible.
4716 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4717 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4718 struct AFSFetchStatus *OutFidStatus,
4719 struct AFSFetchStatus *OutDirStatus,
4720 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4722 Vnode *parentptr = 0; /* vnode of input Directory */
4723 Vnode *targetptr = 0; /* vnode of the new file */
4724 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4725 Volume *volptr = 0; /* pointer to the volume header */
4726 Error errorCode = 0; /* error code */
4727 struct acl_accessList *newACL; /* Access list */
4728 int newACLSize; /* Size of access list */
4729 DirHandle dir; /* Handle for dir package I/O */
4730 DirHandle parentdir; /* Handle for dir package I/O */
4731 struct client *client = 0; /* pointer to client structure */
4732 afs_int32 rights, anyrights; /* rights for this and any user */
4733 struct client *t_client; /* tmp ptr to client data */
4734 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4735 struct rx_connection *tcon = rx_ConnectionOf(acall);
4738 FidZero(&parentdir);
4740 /* Get ptr to client data for user Id for logging */
4741 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4742 logHostAddr.s_addr = rxr_HostOf(tcon);
4744 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4745 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4746 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4748 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4750 if (!FileNameOK(Name)) {
4756 * Get the vnode and volume for the parent dir along with the caller's
4760 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4761 &parentwhentargetnotdir, &client, WRITE_LOCK,
4762 &rights, &anyrights))) {
4766 /* set volume synchronization information */
4767 SetVolumeSync(Sync, volptr);
4769 /* Write access to the parent directory? */
4770 #ifdef DIRCREATE_NEED_WRITE
4772 * requires w access for the user to create a directory. this
4773 * closes a loophole in the current security arrangement, since a
4774 * user with i access only can create a directory and get the
4775 * implcit a access that goes with dir ownership, and proceed to
4776 * subvert quota in the volume.
4778 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4779 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4781 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4782 #endif /* DIRCREATE_NEED_WRITE */
4785 #define EMPTYDIRBLOCKS 2
4786 /* get a new vnode and set it up */
4788 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4789 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4793 /* Update the status for the parent dir */
4794 #if FS_STATS_DETAILED
4795 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4796 parentptr->disk.linkCount + 1,
4797 client->InSameNetwork);
4799 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4800 parentptr->disk.linkCount + 1);
4801 #endif /* FS_STATS_DETAILED */
4803 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4804 assert((SetAccessList
4805 (&targetptr, &volptr, &newACL, &newACLSize,
4806 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4807 assert(parentwhentargetnotdir == 0);
4808 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4810 /* update the status for the target vnode */
4811 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4812 parentptr, volptr, 0);
4814 /* Actually create the New directory in the directory package */
4815 SetDirHandle(&dir, targetptr);
4816 assert(!(MakeDir(&dir, (afs_int32 *)OutFid, (afs_int32 *)DirFid)));
4818 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4820 /* set up return status */
4821 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4822 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4824 /* convert the write lock to a read lock before breaking callbacks */
4825 VVnodeWriteToRead(&errorCode, parentptr);
4826 assert(!errorCode || errorCode == VSALVAGE);
4828 /* break call back on DirFid */
4829 BreakCallBack(client->host, DirFid, 0);
4831 /* Return a callback promise to caller */
4832 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4835 /* Write the all modified vnodes (parent, new files) and volume back */
4836 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4840 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4843 } /*SAFSS_MakeDir */
4847 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4848 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4849 struct AFSFetchStatus * OutFidStatus,
4850 struct AFSFetchStatus * OutDirStatus,
4851 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4854 struct rx_connection *tcon;
4856 struct client *t_client = NULL; /* tmp ptr to client data */
4857 #if FS_STATS_DETAILED
4858 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4859 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4860 struct timeval elapsedTime; /* Transfer time */
4863 * Set our stats pointer, remember when the RPC operation started, and
4864 * tally the operation.
4866 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
4870 FT_GetTimeOfDay(&opStartTime, 0);
4871 #endif /* FS_STATS_DETAILED */
4872 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4876 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4877 OutDirStatus, CallBack, Sync);
4880 code = CallPostamble(tcon, code, thost);
4882 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4884 #if FS_STATS_DETAILED
4885 FT_GetTimeOfDay(&opStopTime, 0);
4888 (opP->numSuccesses)++;
4889 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4890 fs_stats_AddTo((opP->sumTime), elapsedTime);
4891 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4892 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4893 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4895 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4896 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4900 #endif /* FS_STATS_DETAILED */
4902 osi_auditU(acall, MakeDirEvent, code,
4903 AUD_ID, t_client ? t_client->ViceId : 0,
4904 AUD_FID, DirFid, AUD_STR, Name,
4905 AUD_FID, OutFid, AUD_END);
4908 } /*SRXAFS_MakeDir */
4912 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4913 * merged into it when possible.
4916 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4917 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4919 Vnode *parentptr = 0; /* vnode of input Directory */
4920 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4921 Vnode *targetptr = 0; /* file to be deleted */
4922 AFSFid fileFid; /* area for Fid from the directory */
4923 Error errorCode = 0; /* error code */
4924 DirHandle dir; /* Handle for dir package I/O */
4925 Volume *volptr = 0; /* pointer to the volume header */
4926 struct client *client = 0; /* pointer to client structure */
4927 afs_int32 rights, anyrights; /* rights for this and any user */
4928 Vnode debugvnode1, debugvnode2;
4929 struct client *t_client; /* tmp ptr to client data */
4930 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4931 struct rx_connection *tcon = rx_ConnectionOf(acall);
4935 /* Get ptr to client data for user Id for logging */
4936 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4937 logHostAddr.s_addr = rxr_HostOf(tcon);
4939 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4940 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4941 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4943 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4946 * Get the vnode and volume for the parent dir along with the caller's
4950 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4951 &parentwhentargetnotdir, &client, WRITE_LOCK,
4952 &rights, &anyrights))) {
4955 debugvnode1 = *parentptr;
4957 /* set volume synchronization information */
4958 SetVolumeSync(Sync, volptr);
4960 /* Does the caller has delete (&write) access to the parent dir? */
4961 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
4965 debugvnode2 = *parentptr;
4966 /* Do the actual delete of the desired (empty) directory, Name */
4968 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
4973 /* Update the status for the parent dir; link count is also adjusted */
4974 #if FS_STATS_DETAILED
4975 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4976 parentptr->disk.linkCount - 1,
4977 client->InSameNetwork);
4979 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4980 parentptr->disk.linkCount - 1);
4981 #endif /* FS_STATS_DETAILED */
4983 /* Return to the caller the updated parent dir status */
4984 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4987 * Note: it is not necessary to break the callback on fileFid, since
4988 * refcount is now 0, so no one should be able to refer to the dir
4991 DeleteFileCallBacks(&fileFid);
4993 /* convert the write lock to a read lock before breaking callbacks */
4994 VVnodeWriteToRead(&errorCode, parentptr);
4995 assert(!errorCode || errorCode == VSALVAGE);
4997 /* break call back on DirFid and fileFid */
4998 BreakCallBack(client->host, DirFid, 0);
5001 /* Write the all modified vnodes (parent, new files) and volume back */
5002 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
5005 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
5008 } /*SAFSS_RemoveDir */
5012 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
5013 struct AFSFetchStatus * OutDirStatus,
5014 struct AFSVolSync * Sync)
5017 struct rx_connection *tcon;
5019 struct client *t_client = NULL; /* tmp ptr to client data */
5020 #if FS_STATS_DETAILED
5021 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5022 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5023 struct timeval elapsedTime; /* Transfer time */
5026 * Set our stats pointer, remember when the RPC operation started, and
5027 * tally the operation.
5029 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
5033 FT_GetTimeOfDay(&opStartTime, 0);
5034 #endif /* FS_STATS_DETAILED */
5036 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5039 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
5042 code = CallPostamble(tcon, code, thost);
5044 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5046 #if FS_STATS_DETAILED
5047 FT_GetTimeOfDay(&opStopTime, 0);
5050 (opP->numSuccesses)++;
5051 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5052 fs_stats_AddTo((opP->sumTime), elapsedTime);
5053 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5054 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5055 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5057 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5058 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5062 #endif /* FS_STATS_DETAILED */
5064 osi_auditU(acall, RemoveDirEvent, code,
5065 AUD_ID, t_client ? t_client->ViceId : 0,
5066 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
5069 } /*SRXAFS_RemoveDir */
5073 * This routine is called exclusively by SRXAFS_SetLock(), and should be
5074 * merged into it when possible.
5077 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
5078 struct AFSVolSync *Sync)
5080 Vnode *targetptr = 0; /* vnode of input file */
5081 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5082 Error errorCode = 0; /* error code */
5083 Volume *volptr = 0; /* pointer to the volume header */
5084 struct client *client = 0; /* pointer to client structure */
5085 afs_int32 rights, anyrights; /* rights for this and any user */
5086 struct client *t_client; /* tmp ptr to client data */
5087 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5088 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
5089 struct rx_connection *tcon = rx_ConnectionOf(acall);
5091 if (type != LockRead && type != LockWrite) {
5095 /* Get ptr to client data for user Id for logging */
5096 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5097 logHostAddr.s_addr = rxr_HostOf(tcon);
5099 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
5100 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
5101 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5103 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
5106 * Get the vnode and volume for the desired file along with the caller's
5110 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5111 &parentwhentargetnotdir, &client, WRITE_LOCK,
5112 &rights, &anyrights))) {
5116 /* set volume synchronization information */
5117 SetVolumeSync(Sync, volptr);
5119 /* Handle the particular type of set locking, type */
5120 errorCode = HandleLocking(targetptr, client, rights, type);
5123 /* Write the all modified vnodes (parent, new files) and volume back */
5124 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5127 if ((errorCode == VREADONLY) && (type == LockRead))
5128 errorCode = 0; /* allow read locks on RO volumes without saving state */
5130 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
5133 } /*SAFSS_SetLock */
5137 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
5138 ViceLockType type, struct AFSVolSync * Sync)
5140 return SRXAFS_SetLock(acall, Fid, type, Sync);
5141 } /*SRXAFS_OldSetLock */
5145 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
5146 struct AFSVolSync * Sync)
5149 struct rx_connection *tcon;
5151 struct client *t_client = NULL; /* tmp ptr to client data */
5152 #if FS_STATS_DETAILED
5153 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5154 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5155 struct timeval elapsedTime; /* Transfer time */
5158 * Set our stats pointer, remember when the RPC operation started, and
5159 * tally the operation.
5161 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5165 FT_GetTimeOfDay(&opStartTime, 0);
5166 #endif /* FS_STATS_DETAILED */
5168 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5171 code = SAFSS_SetLock(acall, Fid, type, Sync);
5174 code = CallPostamble(tcon, code, thost);
5176 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5178 #if FS_STATS_DETAILED
5179 FT_GetTimeOfDay(&opStopTime, 0);
5182 (opP->numSuccesses)++;
5183 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5184 fs_stats_AddTo((opP->sumTime), elapsedTime);
5185 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5186 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5187 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5189 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5190 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5194 #endif /* FS_STATS_DETAILED */
5196 osi_auditU(acall, SetLockEvent, code,
5197 AUD_ID, t_client ? t_client->ViceId : 0,
5198 AUD_FID, Fid, AUD_LONG, type, AUD_END);
5200 } /*SRXAFS_SetLock */
5204 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5205 * merged into it when possible.
5208 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5209 struct AFSVolSync *Sync)
5211 Vnode *targetptr = 0; /* vnode of input file */
5212 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5213 Error errorCode = 0; /* error code */
5214 Volume *volptr = 0; /* pointer to the volume header */
5215 struct client *client = 0; /* pointer to client structure */
5216 afs_int32 rights, anyrights; /* rights for this and any user */
5217 struct client *t_client; /* tmp ptr to client data */
5218 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5219 struct rx_connection *tcon = rx_ConnectionOf(acall);
5221 /* Get ptr to client data for user Id for logging */
5222 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5223 logHostAddr.s_addr = rxr_HostOf(tcon);
5225 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5226 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5227 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5229 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5232 * Get the vnode and volume for the desired file along with the caller's
5236 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5237 &parentwhentargetnotdir, &client, WRITE_LOCK,
5238 &rights, &anyrights))) {
5239 goto Bad_ExtendLock;
5242 /* set volume synchronization information */
5243 SetVolumeSync(Sync, volptr);
5245 /* Handle the actual lock extension */
5246 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
5249 /* Put back file's vnode and volume */
5250 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5253 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5254 errorCode = 0; /* under our generous policy re RO vols */
5256 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5259 } /*SAFSS_ExtendLock */
5263 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5264 struct AFSVolSync * Sync)
5266 return SRXAFS_ExtendLock(acall, Fid, Sync);
5267 } /*SRXAFS_OldExtendLock */
5271 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5272 struct AFSVolSync * Sync)
5275 struct rx_connection *tcon;
5277 struct client *t_client = NULL; /* tmp ptr to client data */
5278 #if FS_STATS_DETAILED
5279 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5280 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5281 struct timeval elapsedTime; /* Transfer time */
5284 * Set our stats pointer, remember when the RPC operation started, and
5285 * tally the operation.
5287 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5291 FT_GetTimeOfDay(&opStartTime, 0);
5292 #endif /* FS_STATS_DETAILED */
5294 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5295 goto Bad_ExtendLock;
5297 code = SAFSS_ExtendLock(acall, Fid, Sync);
5300 code = CallPostamble(tcon, code, thost);
5302 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5304 #if FS_STATS_DETAILED
5305 FT_GetTimeOfDay(&opStopTime, 0);
5308 (opP->numSuccesses)++;
5309 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5310 fs_stats_AddTo((opP->sumTime), elapsedTime);
5311 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5312 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5313 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5315 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5316 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5320 #endif /* FS_STATS_DETAILED */
5322 osi_auditU(acall, ExtendLockEvent, code,
5323 AUD_ID, t_client ? t_client->ViceId : 0,
5324 AUD_FID, Fid, AUD_END);
5327 } /*SRXAFS_ExtendLock */
5331 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5332 * merged into it when possible.
5335 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5336 struct AFSVolSync *Sync)
5338 Vnode *targetptr = 0; /* vnode of input file */
5339 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5340 Error errorCode = 0; /* error code */
5341 Volume *volptr = 0; /* pointer to the volume header */
5342 struct client *client = 0; /* pointer to client structure */
5343 afs_int32 rights, anyrights; /* rights for this and any user */
5344 struct client *t_client; /* tmp ptr to client data */
5345 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5346 struct rx_connection *tcon = rx_ConnectionOf(acall);
5348 /* Get ptr to client data for user Id for logging */
5349 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5350 logHostAddr.s_addr = rxr_HostOf(tcon);
5352 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5353 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5354 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5356 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5359 * Get the vnode and volume for the desired file along with the caller's
5363 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5364 &parentwhentargetnotdir, &client, WRITE_LOCK,
5365 &rights, &anyrights))) {
5366 goto Bad_ReleaseLock;
5369 /* set volume synchronization information */
5370 SetVolumeSync(Sync, volptr);
5372 /* Handle the actual lock release */
5373 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
5374 goto Bad_ReleaseLock;
5376 /* if no more locks left, a callback would be triggered here */
5377 if (targetptr->disk.lock.lockCount <= 0) {
5378 /* convert the write lock to a read lock before breaking callbacks */
5379 VVnodeWriteToRead(&errorCode, targetptr);
5380 assert(!errorCode || errorCode == VSALVAGE);
5381 BreakCallBack(client->host, Fid, 0);
5385 /* Put back file's vnode and volume */
5386 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5389 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5390 errorCode = 0; /* under our generous policy re RO vols */
5392 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5395 } /*SAFSS_ReleaseLock */
5399 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5400 struct AFSVolSync * Sync)
5402 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5403 } /*SRXAFS_OldReleaseLock */
5407 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5408 struct AFSVolSync * Sync)
5411 struct rx_connection *tcon;
5413 struct client *t_client = NULL; /* tmp ptr to client data */
5414 #if FS_STATS_DETAILED
5415 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5416 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5417 struct timeval elapsedTime; /* Transfer time */
5420 * Set our stats pointer, remember when the RPC operation started, and
5421 * tally the operation.
5423 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5427 FT_GetTimeOfDay(&opStartTime, 0);
5428 #endif /* FS_STATS_DETAILED */
5430 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5431 goto Bad_ReleaseLock;
5433 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5436 code = CallPostamble(tcon, code, thost);
5438 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5440 #if FS_STATS_DETAILED
5441 FT_GetTimeOfDay(&opStopTime, 0);
5444 (opP->numSuccesses)++;
5445 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5446 fs_stats_AddTo((opP->sumTime), elapsedTime);
5447 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5448 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5449 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5451 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5452 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5456 #endif /* FS_STATS_DETAILED */
5458 osi_auditU(acall, ReleaseLockEvent, code,
5459 AUD_ID, t_client ? t_client->ViceId : 0,
5460 AUD_FID, Fid, AUD_END);
5463 } /*SRXAFS_ReleaseLock */
5467 SetSystemStats(struct AFSStatistics *stats)
5469 /* Fix this sometime soon.. */
5470 /* Because hey, it's not like we have a network monitoring protocol... */
5471 struct timeval time;
5473 /* this works on all system types */
5474 FT_GetTimeOfDay(&time, 0);
5475 stats->CurrentTime = time.tv_sec;
5476 } /*SetSystemStats */
5479 SetAFSStats(struct AFSStatistics *stats)
5481 extern afs_int32 StartTime, CurrentConnections;
5485 stats->CurrentMsgNumber = 0;
5486 stats->OldestMsgNumber = 0;
5487 stats->StartTime = StartTime;
5488 stats->CurrentConnections = CurrentConnections;
5489 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5490 stats->TotalFetchs =
5491 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5492 AFSCallStats.FetchStatus;
5493 stats->FetchDatas = AFSCallStats.FetchData;
5494 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5495 seconds = AFSCallStats.AccumFetchTime / 1000;
5498 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5499 stats->TotalStores =
5500 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5501 AFSCallStats.StoreStatus;
5502 stats->StoreDatas = AFSCallStats.StoreData;
5503 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5504 seconds = AFSCallStats.AccumStoreTime / 1000;
5507 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5509 stats->ProcessSize = -1; /* TODO: */
5511 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5514 h_GetWorkStats((int *)&(stats->WorkStations),
5515 (int *)&(stats->ActiveWorkStations), (int *)0,
5516 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5520 /* Get disk related information from all AFS partitions. */
5523 SetVolumeStats(struct AFSStatistics *stats)
5525 struct DiskPartition64 *part;
5528 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5529 part = part->next) {
5530 stats->Disks[i].TotalBlocks = RoundInt64ToInt32(part->totalUsable);
5531 stats->Disks[i].BlocksAvailable = RoundInt64ToInt32(part->free);
5532 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5533 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5536 while (i < AFS_MSTATDISKS) {
5537 stats->Disks[i].TotalBlocks = -1;
5540 } /*SetVolumeStats */
5543 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5546 struct rx_connection *tcon = rx_ConnectionOf(acall);
5548 struct client *t_client = NULL; /* tmp ptr to client data */
5549 #if FS_STATS_DETAILED
5550 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5551 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5552 struct timeval elapsedTime; /* Transfer time */
5555 * Set our stats pointer, remember when the RPC operation started, and
5556 * tally the operation.
5558 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5562 FT_GetTimeOfDay(&opStartTime, 0);
5563 #endif /* FS_STATS_DETAILED */
5565 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5566 goto Bad_GetStatistics;
5568 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5570 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5572 memset(Statistics, 0, sizeof(*Statistics));
5573 SetAFSStats((struct AFSStatistics *)Statistics);
5574 SetVolumeStats((struct AFSStatistics *)Statistics);
5575 SetSystemStats((struct AFSStatistics *)Statistics);
5578 code = CallPostamble(tcon, code, thost);
5580 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5582 #if FS_STATS_DETAILED
5583 FT_GetTimeOfDay(&opStopTime, 0);
5586 (opP->numSuccesses)++;
5587 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5588 fs_stats_AddTo((opP->sumTime), elapsedTime);
5589 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5590 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5591 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5593 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5594 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5598 #endif /* FS_STATS_DETAILED */
5600 osi_auditU(acall, GetStatisticsEvent, code,
5601 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5603 } /*SRXAFS_GetStatistics */
5607 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5609 extern afs_int32 StartTime, CurrentConnections;
5612 struct rx_connection *tcon = rx_ConnectionOf(acall);
5614 struct client *t_client = NULL; /* tmp ptr to client data */
5615 struct timeval time;
5616 #if FS_STATS_DETAILED
5617 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5618 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5619 struct timeval elapsedTime; /* Transfer time */
5622 * Set our stats pointer, remember when the RPC operation started, and
5623 * tally the operation.
5625 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5629 FT_GetTimeOfDay(&opStartTime, 0);
5630 #endif /* FS_STATS_DETAILED */
5632 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5633 goto Bad_GetStatistics64;
5635 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5636 Statistics->ViceStatistics64_val =
5637 malloc(statsVersion*sizeof(afs_int64));
5638 Statistics->ViceStatistics64_len = statsVersion;
5640 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5641 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5642 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5644 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5645 AFSCallStats.TotalCalls;
5646 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5647 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5648 AFSCallStats.FetchStatus;
5649 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5650 AFSCallStats.FetchData;
5651 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5652 AFSCallStats.TotalFetchedBytes;
5653 seconds = AFSCallStats.AccumFetchTime / 1000;
5656 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5657 AFSCallStats.TotalFetchedBytes / seconds;
5658 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5659 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5660 AFSCallStats.StoreStatus;
5661 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5662 AFSCallStats.StoreData;
5663 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5664 AFSCallStats.TotalStoredBytes;
5665 seconds = AFSCallStats.AccumStoreTime / 1000;
5668 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5669 AFSCallStats.TotalStoredBytes / seconds;
5671 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = -1;
5673 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] =
5674 (afs_int32) ((long)sbrk(0) >> 10);
5677 h_GetWorkStats((int *)&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5678 (int *)&(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5680 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5684 /* this works on all system types */
5685 FT_GetTimeOfDay(&time, 0);
5686 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
5688 Bad_GetStatistics64:
5689 code = CallPostamble(tcon, code, thost);
5691 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5693 #if FS_STATS_DETAILED
5694 FT_GetTimeOfDay(&opStopTime, 0);
5697 (opP->numSuccesses)++;
5698 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5699 fs_stats_AddTo((opP->sumTime), elapsedTime);
5700 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5701 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5702 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5704 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5705 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5709 #endif /* FS_STATS_DETAILED */
5711 osi_auditU(acall, GetStatisticsEvent, code,
5712 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5714 } /*SRXAFS_GetStatistics */
5717 /*------------------------------------------------------------------------
5718 * EXPORTED SRXAFS_XStatsVersion
5721 * Routine called by the server-side RPC interface to implement
5722 * pulling out the xstat version number for the File Server.
5725 * a_versionP : Ptr to the version number variable to set.
5731 * Nothing interesting.
5735 *------------------------------------------------------------------------*/
5738 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5739 { /*SRXAFS_XStatsVersion */
5741 struct client *t_client = NULL; /* tmp ptr to client data */
5742 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5743 #if FS_STATS_DETAILED
5744 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5745 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5746 struct timeval elapsedTime; /* Transfer time */
5749 * Set our stats pointer, remember when the RPC operation started, and
5750 * tally the operation.
5752 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5756 FT_GetTimeOfDay(&opStartTime, 0);
5757 #endif /* FS_STATS_DETAILED */
5759 *a_versionP = AFS_XSTAT_VERSION;
5761 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5763 #if FS_STATS_DETAILED
5764 FT_GetTimeOfDay(&opStopTime, 0);
5765 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5766 fs_stats_AddTo((opP->sumTime), elapsedTime);
5767 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5768 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5769 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5771 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5772 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5775 (opP->numSuccesses)++;
5777 #endif /* FS_STATS_DETAILED */
5779 osi_auditU(a_call, XStatsVersionEvent, 0,
5780 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5782 } /*SRXAFS_XStatsVersion */
5785 /*------------------------------------------------------------------------
5786 * PRIVATE FillPerfValues
5789 * Routine called to fill a regular performance data structure.
5792 * a_perfP : Ptr to perf structure to fill
5798 * Various collections need this info, so the guts were put in
5799 * this separate routine.
5803 *------------------------------------------------------------------------*/
5806 FillPerfValues(struct afs_PerfStats *a_perfP)
5807 { /*FillPerfValues */
5809 int dir_Buffers; /*# buffers in use by dir package */
5810 int dir_Calls; /*# read calls in dir package */
5811 int dir_IOs; /*# I/O ops in dir package */
5814 * Vnode cache section.
5816 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5817 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5818 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5819 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5820 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5821 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5822 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5823 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5824 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5825 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5826 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5827 SplitInt64(VStats.hdr_gets, hi, lo);
5828 a_perfP->vcache_H_Gets = lo;
5829 SplitInt64(VStats.hdr_loads, hi, lo);
5830 a_perfP->vcache_H_Replacements = lo;
5833 * Directory section.
5835 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5836 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5837 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5838 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5843 a_perfP->rx_packetRequests = (afs_int32) rx_stats.packetRequests;
5844 a_perfP->rx_noPackets_RcvClass =
5845 (afs_int32) rx_stats.receivePktAllocFailures;
5846 a_perfP->rx_noPackets_SendClass =
5847 (afs_int32) rx_stats.sendPktAllocFailures;
5848 a_perfP->rx_noPackets_SpecialClass =
5849 (afs_int32) rx_stats.specialPktAllocFailures;
5850 a_perfP->rx_socketGreedy = (afs_int32) rx_stats.socketGreedy;
5851 a_perfP->rx_bogusPacketOnRead = (afs_int32) rx_stats.bogusPacketOnRead;
5852 a_perfP->rx_bogusHost = (afs_int32) rx_stats.bogusHost;
5853 a_perfP->rx_noPacketOnRead = (afs_int32) rx_stats.noPacketOnRead;
5854 a_perfP->rx_noPacketBuffersOnRead =
5855 (afs_int32) rx_stats.noPacketBuffersOnRead;
5856 a_perfP->rx_selects = (afs_int32) rx_stats.selects;
5857 a_perfP->rx_sendSelects = (afs_int32) rx_stats.sendSelects;
5858 a_perfP->rx_packetsRead_RcvClass =
5859 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
5860 a_perfP->rx_packetsRead_SendClass =
5861 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
5862 a_perfP->rx_packetsRead_SpecialClass =
5863 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
5864 a_perfP->rx_dataPacketsRead = (afs_int32) rx_stats.dataPacketsRead;
5865 a_perfP->rx_ackPacketsRead = (afs_int32) rx_stats.ackPacketsRead;
5866 a_perfP->rx_dupPacketsRead = (afs_int32) rx_stats.dupPacketsRead;
5867 a_perfP->rx_spuriousPacketsRead =
5868 (afs_int32) rx_stats.spuriousPacketsRead;
5869 a_perfP->rx_packetsSent_RcvClass =
5870 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
5871 a_perfP->rx_packetsSent_SendClass =
5872 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
5873 a_perfP->rx_packetsSent_SpecialClass =
5874 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
5875 a_perfP->rx_ackPacketsSent = (afs_int32) rx_stats.ackPacketsSent;
5876 a_perfP->rx_pingPacketsSent = (afs_int32) rx_stats.pingPacketsSent;
5877 a_perfP->rx_abortPacketsSent = (afs_int32) rx_stats.abortPacketsSent;
5878 a_perfP->rx_busyPacketsSent = (afs_int32) rx_stats.busyPacketsSent;
5879 a_perfP->rx_dataPacketsSent = (afs_int32) rx_stats.dataPacketsSent;
5880 a_perfP->rx_dataPacketsReSent = (afs_int32) rx_stats.dataPacketsReSent;
5881 a_perfP->rx_dataPacketsPushed = (afs_int32) rx_stats.dataPacketsPushed;
5882 a_perfP->rx_ignoreAckedPacket = (afs_int32) rx_stats.ignoreAckedPacket;
5883 a_perfP->rx_totalRtt_Sec = (afs_int32) rx_stats.totalRtt.sec;
5884 a_perfP->rx_totalRtt_Usec = (afs_int32) rx_stats.totalRtt.usec;
5885 a_perfP->rx_minRtt_Sec = (afs_int32) rx_stats.minRtt.sec;
5886 a_perfP->rx_minRtt_Usec = (afs_int32) rx_stats.minRtt.usec;
5887 a_perfP->rx_maxRtt_Sec = (afs_int32) rx_stats.maxRtt.sec;
5888 a_perfP->rx_maxRtt_Usec = (afs_int32) rx_stats.maxRtt.usec;
5889 a_perfP->rx_nRttSamples = (afs_int32) rx_stats.nRttSamples;
5890 a_perfP->rx_nServerConns = (afs_int32) rx_stats.nServerConns;
5891 a_perfP->rx_nClientConns = (afs_int32) rx_stats.nClientConns;
5892 a_perfP->rx_nPeerStructs = (afs_int32) rx_stats.nPeerStructs;
5893 a_perfP->rx_nCallStructs = (afs_int32) rx_stats.nCallStructs;
5894 a_perfP->rx_nFreeCallStructs = (afs_int32) rx_stats.nFreeCallStructs;
5896 a_perfP->host_NumHostEntries = HTs;
5897 a_perfP->host_HostBlocks = HTBlocks;
5898 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5899 &(a_perfP->host_HostsInSameNetOrSubnet),
5900 &(a_perfP->host_HostsInDiffSubnet),
5901 &(a_perfP->host_HostsInDiffNetwork));
5902 a_perfP->host_NumClients = CEs;
5903 a_perfP->host_ClientBlocks = CEBlocks;
5905 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5906 a_perfP->rx_nBusies = (afs_int32) rx_stats.nBusies;
5907 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5908 } /*FillPerfValues */
5911 /*------------------------------------------------------------------------
5912 * EXPORTED SRXAFS_GetXStats
5915 * Routine called by the server-side callback RPC interface to
5916 * implement getting the given data collection from the extended
5917 * File Server statistics.
5920 * a_call : Ptr to Rx call on which this request came in.
5921 * a_clientVersionNum : Client version number.
5922 * a_opCode : Desired operation.
5923 * a_serverVersionNumP : Ptr to version number to set.
5924 * a_timeP : Ptr to time value (seconds) to set.
5925 * a_dataP : Ptr to variable array structure to return
5932 * Nothing interesting.
5936 *------------------------------------------------------------------------*/
5939 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5940 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5941 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5942 { /*SRXAFS_GetXStats */
5944 register int code; /*Return value */
5945 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5946 afs_int32 dataBytes; /*Bytes in data buffer */
5947 #if FS_STATS_DETAILED
5948 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5949 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5950 struct timeval elapsedTime; /* Transfer time */
5953 * Set our stats pointer, remember when the RPC operation started, and
5954 * tally the operation.
5956 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
5960 FT_GetTimeOfDay(&opStartTime, 0);
5961 #endif /* FS_STATS_DETAILED */
5964 * Record the time of day and the server version number.
5966 *a_srvVersionNumP = AFS_XSTAT_VERSION;
5967 *a_timeP = FT_ApproxTime();
5970 * Stuff the appropriate data in there (assume victory)
5975 ("Received GetXStats call for collection %d\n",
5976 a_collectionNumber));
5980 * We're not keeping stats, so just return successfully with
5983 a_dataP->AFS_CollData_len = 0;
5984 a_dataP->AFS_CollData_val = NULL;
5987 switch (a_collectionNumber) {
5988 case AFS_XSTATSCOLL_CALL_INFO:
5990 * Pass back all the call-count-related data.
5992 * >>> We are forced to allocate a separate area in which to
5993 * >>> put this stuff in by the RPC stub generator, since it
5994 * >>> will be freed at the tail end of the server stub code.
5998 * I don't think call-level stats are being collected yet
5999 * for the File Server.
6001 dataBytes = sizeof(struct afs_Stats);
6002 dataBuffP = (afs_int32 *) malloc(dataBytes);
6003 memcpy(dataBuffP, &afs_cmstats, dataBytes);
6004 a_dataP->AFS_CollData_len = dataBytes >> 2;
6005 a_dataP->AFS_CollData_val = dataBuffP;
6007 a_dataP->AFS_CollData_len = 0;
6008 a_dataP->AFS_CollData_val = NULL;
6012 case AFS_XSTATSCOLL_PERF_INFO:
6014 * Pass back all the regular performance-related data.
6016 * >>> We are forced to allocate a separate area in which to
6017 * >>> put this stuff in by the RPC stub generator, since it
6018 * >>> will be freed at the tail end of the server stub code.
6021 afs_perfstats.numPerfCalls++;
6022 FillPerfValues(&afs_perfstats);
6025 * Don't overwrite the spares at the end.
6028 dataBytes = sizeof(struct afs_PerfStats);
6029 dataBuffP = (afs_int32 *) malloc(dataBytes);
6030 memcpy(dataBuffP, &afs_perfstats, dataBytes);
6031 a_dataP->AFS_CollData_len = dataBytes >> 2;
6032 a_dataP->AFS_CollData_val = dataBuffP;
6035 case AFS_XSTATSCOLL_FULL_PERF_INFO:
6037 * Pass back the full collection of performance-related data.
6038 * We have to stuff the basic, overall numbers in, but the
6039 * detailed numbers are kept in the structure already.
6041 * >>> We are forced to allocate a separate area in which to
6042 * >>> put this stuff in by the RPC stub generator, since it
6043 * >>> will be freed at the tail end of the server stub code.
6046 afs_perfstats.numPerfCalls++;
6047 #if FS_STATS_DETAILED
6048 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
6049 FillPerfValues(&afs_FullPerfStats.overall);
6052 * Don't overwrite the spares at the end.
6055 dataBytes = sizeof(struct fs_stats_FullPerfStats);
6056 dataBuffP = (afs_int32 *) malloc(dataBytes);
6057 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
6058 a_dataP->AFS_CollData_len = dataBytes >> 2;
6059 a_dataP->AFS_CollData_val = dataBuffP;
6063 case AFS_XSTATSCOLL_CBSTATS:
6064 afs_perfstats.numPerfCalls++;
6066 dataBytes = sizeof(struct cbcounters);
6067 dataBuffP = (afs_int32 *) malloc(dataBytes);
6069 extern struct cbcounters cbstuff;
6070 dataBuffP[0]=cbstuff.DeleteFiles;
6071 dataBuffP[1]=cbstuff.DeleteCallBacks;
6072 dataBuffP[2]=cbstuff.BreakCallBacks;
6073 dataBuffP[3]=cbstuff.AddCallBacks;
6074 dataBuffP[4]=cbstuff.GotSomeSpaces;
6075 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
6076 dataBuffP[6]=cbstuff.nFEs;
6077 dataBuffP[7]=cbstuff.nCBs;
6078 dataBuffP[8]=cbstuff.nblks;
6079 dataBuffP[9]=cbstuff.CBsTimedOut;
6080 dataBuffP[10]=cbstuff.nbreakers;
6081 dataBuffP[11]=cbstuff.GSS1;
6082 dataBuffP[12]=cbstuff.GSS2;
6083 dataBuffP[13]=cbstuff.GSS3;
6084 dataBuffP[14]=cbstuff.GSS4;
6085 dataBuffP[15]=cbstuff.GSS5;
6088 a_dataP->AFS_CollData_len = dataBytes >> 2;
6089 a_dataP->AFS_CollData_val = dataBuffP;
6095 * Illegal collection number.
6097 a_dataP->AFS_CollData_len = 0;
6098 a_dataP->AFS_CollData_val = NULL;
6100 } /*Switch on collection number */
6102 #if FS_STATS_DETAILED
6103 FT_GetTimeOfDay(&opStopTime, 0);
6106 (opP->numSuccesses)++;
6107 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6108 fs_stats_AddTo((opP->sumTime), elapsedTime);
6109 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6110 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6111 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6113 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6114 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6118 #endif /* FS_STATS_DETAILED */
6122 } /*SRXAFS_GetXStats */
6126 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
6127 struct AFSCBs *CallBackArray)
6129 afs_int32 errorCode = 0;
6131 struct client *client = 0;
6132 struct rx_connection *tcon;
6134 #if FS_STATS_DETAILED
6135 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6136 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6137 struct timeval elapsedTime; /* Transfer time */
6140 * Set our stats pointer, remember when the RPC operation started, and
6141 * tally the operation.
6144 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
6148 FT_GetTimeOfDay(&opStartTime, 0);
6149 #endif /* FS_STATS_DETAILED */
6153 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
6154 FidArray->AFSCBFids_len));
6157 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
6159 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6160 goto Bad_GiveUpCallBacks;
6162 if (!FidArray && !CallBackArray) {
6164 ("SAFS_GiveUpAllCallBacks: host=%x\n",
6165 (tcon->peer ? tcon->peer->host : 0)));
6166 errorCode = GetClient(tcon, &client);
6169 DeleteAllCallBacks_r(client->host, 1);
6174 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
6176 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
6177 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
6178 (tcon->peer ? tcon->peer->host : 0)));
6180 goto Bad_GiveUpCallBacks;
6183 errorCode = GetClient(tcon, &client);
6185 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
6186 register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
6187 DeleteCallBack(client->host, fid);
6193 Bad_GiveUpCallBacks:
6194 errorCode = CallPostamble(tcon, errorCode, thost);
6196 #if FS_STATS_DETAILED
6197 FT_GetTimeOfDay(&opStopTime, 0);
6198 if (errorCode == 0) {
6200 (opP->numSuccesses)++;
6201 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6202 fs_stats_AddTo((opP->sumTime), elapsedTime);
6203 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6204 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6205 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6207 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6208 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6212 #endif /* FS_STATS_DETAILED */
6215 } /*common_GiveUpCallBacks */
6219 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
6220 struct AFSCBs * CallBackArray)
6222 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
6223 } /*SRXAFS_GiveUpCallBacks */
6226 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
6228 return common_GiveUpCallBacks(acall, 0, 0);
6229 } /*SRXAFS_GiveUpAllCallBacks */
6233 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
6234 struct AFSVolumeInfo * avolinfo)
6236 return (VNOVOL); /* XXX Obsolete routine XXX */
6238 } /*SRXAFS_NGetVolumeInfo */
6242 * Dummy routine. Should never be called (the cache manager should only
6243 * invoke this interface when communicating with a AFS/DFS Protocol
6247 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
6248 char *afs_name_p, struct AFSFid * afs_fid_p,
6249 struct AFSFetchStatus * afs_status_p,
6250 struct AFSFetchStatus * afs_dir_status_p,
6251 struct AFSCallBack * afs_callback_p,
6252 struct AFSVolSync * afs_sync_p)
6259 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
6262 struct rx_connection *tcon;
6264 afs_uint32 *dataBuffP;
6265 afs_int32 dataBytes;
6268 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
6269 afs_FullPerfStats.overall.fs_nGetCaps++;
6271 ViceLog(2, ("SAFS_GetCapabilties\n"));
6273 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6276 dataBytes = 1 * sizeof(afs_int32);
6277 dataBuffP = (afs_uint32 *) malloc(dataBytes);
6278 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
6279 #if defined(AFS_64BIT_ENV)
6280 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
6283 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
6285 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
6286 capabilities->Capabilities_val = dataBuffP;
6289 code = CallPostamble(tcon, code, thost);
6296 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
6297 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
6301 afs_int32 nids, naddrs;
6302 afs_int32 *vd, *addr;
6303 Error errorCode = 0; /* return code to caller */
6304 struct client *client = 0;
6306 ViceLog(1, ("SRXAFS_FlushCPS\n"));
6308 AFSCallStats.TotalCalls++;
6310 nids = vids->ViceIds_len; /* # of users in here */
6311 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
6312 if (nids < 0 || naddrs < 0) {
6317 vd = vids->ViceIds_val;
6318 for (i = 0; i < nids; i++, vd++) {
6321 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
6325 client->prfail = 2; /* Means re-eval client's cps */
6328 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6331 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6332 free(client->CPS.prlist_val);
6333 client->CPS.prlist_val = NULL;
6334 client->CPS.prlist_len = 0;
6336 ReleaseWriteLock(&client->lock);
6340 addr = addrs->IPAddrs_val;
6341 for (i = 0; i < naddrs; i++, addr++) {
6343 h_flushhostcps(*addr, htons(7001));
6347 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6349 } /*SRXAFS_FlushCPS */
6351 /* worthless hack to let CS keep running ancient software */
6353 afs_vtoi(register char *aname)
6355 register afs_int32 temp;
6359 while ((tc = *aname++)) {
6360 if (tc > '9' || tc < '0')
6361 return 0; /* invalid name */
6369 * may get name or #, but must handle all weird cases (recognize readonly
6370 * or backup volumes by name or #
6373 CopyVolumeEntry(char *aname, register struct vldbentry *ave,
6374 register struct VolumeInfo *av)
6376 register int i, j, vol;
6377 afs_int32 mask, whichType;
6378 afs_uint32 *serverHost, *typePtr;
6380 /* figure out what type we want if by name */
6382 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6383 whichType = BACKVOL;
6384 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6389 vol = afs_vtoi(aname);
6391 vol = ave->volumeId[whichType];
6394 * Now vol has volume # we're interested in. Next, figure out the type
6395 * of the volume by looking finding it in the vldb entry
6397 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6400 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6403 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6404 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6405 whichType = BACKVOL;
6407 return EINVAL; /* error: can't find volume in vldb entry */
6409 typePtr = &av->Type0;
6410 serverHost = &av->Server0;
6412 av->Type = whichType;
6413 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6414 if (ave->flags & VLF_RWEXISTS)
6415 typePtr[RWVOL] = ave->volumeId[RWVOL];
6416 if (ave->flags & VLF_ROEXISTS)
6417 typePtr[ROVOL] = ave->volumeId[ROVOL];
6418 if (ave->flags & VLF_BACKEXISTS)
6419 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6421 for (i = 0, j = 0; i < ave->nServers; i++) {
6422 if ((ave->serverFlags[i] & mask) == 0)
6423 continue; /* wrong volume */
6424 serverHost[j] = ave->serverNumber[i];
6427 av->ServerCount = j;
6429 serverHost[j++] = 0; /* bogus 8, but compat only now */
6434 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6436 static struct rx_connection *vlConn = 0;
6437 static int down = 0;
6438 static afs_int32 lastDownTime = 0;
6439 struct vldbentry tve;
6440 struct rx_securityClass *vlSec;
6441 register afs_int32 code;
6444 vlSec = rxnull_NewClientSecurityObject();
6446 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6447 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6449 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6450 return 1; /* failure */
6453 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6455 down = 0; /* call worked */
6458 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6464 /* otherwise convert to old format vldb entry */
6465 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6475 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6476 struct VolumeInfo * avolinfo)
6479 struct rx_connection *tcon;
6481 #if FS_STATS_DETAILED
6482 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6483 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6484 struct timeval elapsedTime; /* Transfer time */
6487 * Set our stats pointer, remember when the RPC operation started, and
6488 * tally the operation.
6490 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6494 FT_GetTimeOfDay(&opStartTime, 0);
6495 #endif /* FS_STATS_DETAILED */
6496 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6497 goto Bad_GetVolumeInfo;
6500 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6502 code = TryLocalVLServer(avolid, avolinfo);
6504 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6505 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6506 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6507 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6510 code = CallPostamble(tcon, code, thost);
6512 #if FS_STATS_DETAILED
6513 FT_GetTimeOfDay(&opStopTime, 0);
6516 (opP->numSuccesses)++;
6517 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6518 fs_stats_AddTo((opP->sumTime), elapsedTime);
6519 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6520 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6521 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6523 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6524 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6528 #endif /* FS_STATS_DETAILED */
6532 } /*SRXAFS_GetVolumeInfo */
6536 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6537 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6538 char **OfflineMsg, char **Motd)
6540 Vnode *targetptr = 0; /* vnode of the new file */
6541 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6542 Error errorCode = 0; /* error code */
6543 Volume *volptr = 0; /* pointer to the volume header */
6544 struct client *client = 0; /* pointer to client entry */
6545 afs_int32 rights, anyrights; /* rights for this and any user */
6547 struct rx_connection *tcon;
6549 struct client *t_client = NULL; /* tmp ptr to client data */
6550 #if FS_STATS_DETAILED
6551 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6552 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6553 struct timeval elapsedTime; /* Transfer time */
6556 * Set our stats pointer, remember when the RPC operation started, and
6557 * tally the operation.
6560 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6564 FT_GetTimeOfDay(&opStartTime, 0);
6565 #endif /* FS_STATS_DETAILED */
6567 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6568 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6569 goto Bad_GetVolumeStatus;
6572 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6576 goto Bad_GetVolumeStatus;
6578 dummyFid.Volume = avolid, dummyFid.Vnode =
6579 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6582 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6583 &parentwhentargetnotdir, &client, READ_LOCK,
6584 &rights, &anyrights)))
6585 goto Bad_GetVolumeStatus;
6587 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6589 goto Bad_GetVolumeStatus;
6591 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6593 Bad_GetVolumeStatus:
6594 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6596 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6597 /* next is to guarantee out strings exist for stub */
6599 *Name = (char *)malloc(1);
6603 *Motd = (char *)malloc(1);
6606 if (*OfflineMsg == 0) {
6607 *OfflineMsg = (char *)malloc(1);
6610 errorCode = CallPostamble(tcon, errorCode, thost);
6612 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6614 #if FS_STATS_DETAILED
6615 FT_GetTimeOfDay(&opStopTime, 0);
6616 if (errorCode == 0) {
6618 (opP->numSuccesses)++;
6619 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6620 fs_stats_AddTo((opP->sumTime), elapsedTime);
6621 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6622 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6623 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6625 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6626 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6630 #endif /* FS_STATS_DETAILED */
6632 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
6633 AUD_ID, t_client ? t_client->ViceId : 0,
6634 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
6637 } /*SRXAFS_GetVolumeStatus */
6641 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6642 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6643 char *OfflineMsg, char *Motd)
6645 Vnode *targetptr = 0; /* vnode of the new file */
6646 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6647 Error errorCode = 0; /* error code */
6648 Volume *volptr = 0; /* pointer to the volume header */
6649 struct client *client = 0; /* pointer to client entry */
6650 afs_int32 rights, anyrights; /* rights for this and any user */
6652 struct rx_connection *tcon = rx_ConnectionOf(acall);
6654 struct client *t_client = NULL; /* tmp ptr to client data */
6655 #if FS_STATS_DETAILED
6656 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6657 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6658 struct timeval elapsedTime; /* Transfer time */
6661 * Set our stats pointer, remember when the RPC operation started, and
6662 * tally the operation.
6665 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6669 FT_GetTimeOfDay(&opStartTime, 0);
6670 #endif /* FS_STATS_DETAILED */
6672 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6673 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6674 goto Bad_SetVolumeStatus;
6677 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6681 goto Bad_SetVolumeStatus;
6683 dummyFid.Volume = avolid, dummyFid.Vnode =
6684 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6687 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6688 &parentwhentargetnotdir, &client, READ_LOCK,
6689 &rights, &anyrights)))
6690 goto Bad_SetVolumeStatus;
6692 if (readonlyServer) {
6693 errorCode = VREADONLY;
6694 goto Bad_SetVolumeStatus;
6696 if (VanillaUser(client)) {
6698 goto Bad_SetVolumeStatus;
6702 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6704 Bad_SetVolumeStatus:
6705 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6707 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6708 errorCode = CallPostamble(tcon, errorCode, thost);
6710 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6712 #if FS_STATS_DETAILED
6713 FT_GetTimeOfDay(&opStopTime, 0);
6714 if (errorCode == 0) {
6716 (opP->numSuccesses)++;
6717 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6718 fs_stats_AddTo((opP->sumTime), elapsedTime);
6719 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6720 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6721 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6723 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6724 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6728 #endif /* FS_STATS_DETAILED */
6730 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6731 AUD_ID, t_client ? t_client->ViceId : 0,
6732 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6734 } /*SRXAFS_SetVolumeStatus */
6736 #define DEFAULTVOLUME "root.afs"
6739 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6745 struct rx_connection *tcon;
6747 Error errorCode = 0;
6749 #if FS_STATS_DETAILED
6750 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6751 struct timeval opStartTime; /* Start time for RPC op */
6753 struct timeval opStopTime;
6754 struct timeval elapsedTime; /* Transfer time */
6758 * Set our stats pointer, remember when the RPC operation started, and
6759 * tally the operation.
6761 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6765 FT_GetTimeOfDay(&opStartTime, 0);
6766 #endif /* FS_STATS_DETAILED */
6768 return FSERR_EOPNOTSUPP;
6771 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
6772 goto Bad_GetRootVolume;
6774 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6777 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6779 strcpy(temp, DEFAULTVOLUME);
6781 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6782 lockf(fd, F_LOCK, 0);
6786 len = read(fd, temp, 256);
6787 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6788 lockf(fd, F_ULOCK, 0);
6793 if (temp[len - 1] == '\n')
6797 *VolumeName = temp; /* freed by rx server-side stub */
6800 errorCode = CallPostamble(tcon, errorCode, thost);
6802 #if FS_STATS_DETAILED
6803 FT_GetTimeOfDay(&opStopTime, 0);
6804 if (errorCode == 0) {
6806 (opP->numSuccesses)++;
6807 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6808 fs_stats_AddTo((opP->sumTime), elapsedTime);
6809 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6810 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6811 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6813 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6814 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6818 #endif /* FS_STATS_DETAILED */
6823 } /*SRXAFS_GetRootVolume */
6826 /* still works because a struct CBS is the same as a struct AFSOpaque */
6828 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6829 struct AFSOpaque * Token)
6832 struct rx_connection *tcon;
6834 #if FS_STATS_DETAILED
6835 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6836 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6837 struct timeval elapsedTime; /* Transfer time */
6840 * Set our stats pointer, remember when the RPC operation started, and
6841 * tally the operation.
6843 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6847 FT_GetTimeOfDay(&opStartTime, 0);
6848 #endif /* FS_STATS_DETAILED */
6850 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6851 goto Bad_CheckToken;
6853 code = FSERR_ECONNREFUSED;
6856 code = CallPostamble(tcon, code, thost);
6858 #if FS_STATS_DETAILED
6859 FT_GetTimeOfDay(&opStopTime, 0);
6862 (opP->numSuccesses)++;
6863 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6864 fs_stats_AddTo((opP->sumTime), elapsedTime);
6865 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6866 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6867 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6869 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6870 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6874 #endif /* FS_STATS_DETAILED */
6878 } /*SRXAFS_CheckToken */
6881 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6882 afs_uint32 * USeconds)
6885 struct rx_connection *tcon;
6888 #if FS_STATS_DETAILED
6889 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6890 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6891 struct timeval elapsedTime; /* Transfer time */
6894 * Set our stats pointer, remember when the RPC operation started, and
6895 * tally the operation.
6897 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
6901 FT_GetTimeOfDay(&opStartTime, 0);
6902 #endif /* FS_STATS_DETAILED */
6904 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6908 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6910 FT_GetTimeOfDay(&tpl, 0);
6911 *Seconds = tpl.tv_sec;
6912 *USeconds = tpl.tv_usec;
6914 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6917 code = CallPostamble(tcon, code, thost);
6919 #if FS_STATS_DETAILED
6920 FT_GetTimeOfDay(&opStopTime, 0);
6921 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6924 (opP->numSuccesses)++;
6925 fs_stats_AddTo((opP->sumTime), elapsedTime);
6926 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6927 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6928 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6930 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6931 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6935 #endif /* FS_STATS_DETAILED */
6939 } /*SRXAFS_GetTime */
6946 * Implement a client's data fetch using Rx.
6949 * volptr : Ptr to the given volume's info.
6950 * targetptr : Pointer to the vnode involved.
6951 * Call : Ptr to the Rx call involved.
6952 * Pos : Offset within the file.
6953 * Len : Length in bytes to read; this value is bogus!
6954 * if FS_STATS_DETAILED
6955 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6957 * a_bytesFetchedP : Set to the actual number of bytes fetched from
6963 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
6964 register struct rx_call * Call, afs_sfsize_t Pos,
6965 afs_sfsize_t Len, afs_int32 Int64Mode,
6966 #if FS_STATS_DETAILED
6967 afs_sfsize_t * a_bytesToFetchP,
6968 afs_sfsize_t * a_bytesFetchedP
6969 #endif /* FS_STATS_DETAILED */
6972 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
6973 Error errorCode = 0; /* Returned error code to caller */
6977 register char *tbuffer;
6978 #else /* AFS_NT40_ENV */
6979 struct iovec tiov[RX_MAXIOVECS];
6981 #endif /* AFS_NT40_ENV */
6985 #if FS_STATS_DETAILED
6987 * Initialize the byte count arguments.
6989 (*a_bytesToFetchP) = 0;
6990 (*a_bytesFetchedP) = 0;
6991 #endif /* FS_STATS_DETAILED */
6995 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
6996 (afs_uintmax_t) Len));
6998 if (!VN_GET_INO(targetptr)) {
6999 afs_int32 zero = htonl(0);
7001 * This is used for newly created files; we simply send 0 bytes
7002 * back to make the cache manager happy...
7005 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7006 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7009 FT_GetTimeOfDay(&StartTime, 0);
7010 ihP = targetptr->handle;
7013 VTakeOffline(volptr);
7014 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7018 optSize = sendBufSize;
7019 tlen = FDH_SIZE(fdP);
7021 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
7024 VTakeOffline(volptr);
7025 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7033 if (Pos + Len > tlen) /* get length we should send */
7034 Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
7036 (void)FDH_SEEK(fdP, Pos, 0);
7038 afs_int32 high, low;
7039 SplitOffsetOrSize(Len, high, low);
7040 assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
7043 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
7046 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
7048 #if FS_STATS_DETAILED
7049 (*a_bytesToFetchP) = Len;
7050 #endif /* FS_STATS_DETAILED */
7052 tbuffer = AllocSendBuffer();
7053 #endif /* AFS_NT40_ENV */
7061 errorCode = FDH_READ(fdP, tbuffer, wlen);
7062 if (errorCode != wlen) {
7064 FreeSendBuffer((struct afs_buffer *)tbuffer);
7065 VTakeOffline(volptr);
7066 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7070 errorCode = rx_Write(Call, tbuffer, wlen);
7071 #else /* AFS_NT40_ENV */
7072 errorCode = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
7073 if (errorCode <= 0) {
7078 errorCode = FDH_READV(fdP, tiov, tnio);
7079 if (errorCode != wlen) {
7081 VTakeOffline(volptr);
7082 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7086 errorCode = rx_Writev(Call, tiov, tnio, wlen);
7087 #endif /* AFS_NT40_ENV */
7088 #if FS_STATS_DETAILED
7090 * Bump the number of bytes actually sent by the number from this
7093 (*a_bytesFetchedP) += errorCode;
7094 #endif /* FS_STATS_DETAILED */
7095 if (errorCode != wlen) {
7098 FreeSendBuffer((struct afs_buffer *)tbuffer);
7099 #endif /* AFS_NT40_ENV */
7105 FreeSendBuffer((struct afs_buffer *)tbuffer);
7106 #endif /* AFS_NT40_ENV */
7108 FT_GetTimeOfDay(&StopTime, 0);
7110 /* Adjust all Fetch Data related stats */
7112 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
7113 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
7114 AFSCallStats.AccumFetchTime +=
7115 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
7116 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
7118 afs_fsize_t targLen;
7119 VN_GET_LEN(targLen, targetptr);
7120 AFSCallStats.TotalFetchedBytes += targLen;
7121 AFSCallStats.FetchSize1++;
7122 if (targLen < SIZE2)
7123 AFSCallStats.FetchSize2++;
7124 else if (targLen < SIZE3)
7125 AFSCallStats.FetchSize3++;
7126 else if (targLen < SIZE4)
7127 AFSCallStats.FetchSize4++;
7129 AFSCallStats.FetchSize5++;
7134 } /*FetchData_RXStyle */
7137 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
7138 afs_sfsize_t * size)
7140 #ifdef AFS_NAMEI_ENV
7142 lhp = IH_OPEN(V_linkHandle(vp));
7146 *lc = nt_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
7148 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
7153 *size = OS_SIZE(fdP->fd_fd);
7154 return (*size == -1) ? -1 : 0;
7156 struct afs_stat status;
7158 if (afs_fstat(fdP->fd_fd, &status) < 0) {
7162 *lc = GetLinkCount(vp, &status);
7163 *size = status.st_size;
7172 * Implement a client's data store using Rx.
7175 * volptr : Ptr to the given volume's info.
7176 * targetptr : Pointer to the vnode involved.
7177 * Call : Ptr to the Rx call involved.
7178 * Pos : Offset within the file.
7179 * Len : Length in bytes to store; this value is bogus!
7180 * if FS_STATS_DETAILED
7181 * a_bytesToStoreP : Set to the number of bytes to be stored to
7183 * a_bytesStoredP : Set to the actual number of bytes stored to
7188 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
7189 struct client * client, register struct rx_call * Call,
7190 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
7192 #if FS_STATS_DETAILED
7193 afs_sfsize_t * a_bytesToStoreP,
7194 afs_sfsize_t * a_bytesStoredP
7195 #endif /* FS_STATS_DETAILED */
7198 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
7199 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
7200 Error errorCode = 0; /* Returned error code to caller */
7202 register char *tbuffer; /* data copying buffer */
7203 #else /* AFS_NT40_ENV */
7204 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
7205 int tnio; /* temp for iovec size */
7206 #endif /* AFS_NT40_ENV */
7207 afs_sfsize_t tlen; /* temp for xfr length */
7208 Inode tinode; /* inode for I/O */
7209 afs_int32 optSize; /* optimal transfer size */
7210 afs_sfsize_t DataLength = 0; /* size of inode */
7211 afs_sfsize_t TruncatedLength; /* size after ftruncate */
7212 afs_fsize_t NewLength; /* size after this store completes */
7213 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
7214 int linkCount = 0; /* link count on inode */
7215 afs_fsize_t CoW_off, CoW_len;
7216 FdHandle_t *fdP, *origfdP = NULL;
7217 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
7219 #if FS_STATS_DETAILED
7221 * Initialize the byte count arguments.
7223 (*a_bytesToStoreP) = 0;
7224 (*a_bytesStoredP) = 0;
7225 #endif /* FS_STATS_DETAILED */
7228 * We break the callbacks here so that the following signal will not
7231 BreakCallBack(client->host, Fid, 0);
7233 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
7234 /* the inode should have been created in Alloc_NewVnode */
7235 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
7237 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
7238 Fid->Volume, Fid->Vnode, Fid->Unique,
7239 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
7240 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
7241 return ENOENT; /* is this proper error code? */
7244 * See if the file has several links (from other volumes). If it
7245 * does, then we have to make a copy before changing it to avoid
7246 *changing read-only clones of this dude
7249 ("StoreData_RXStyle : Opening inode %s\n",
7250 PrintInode(NULL, VN_GET_INO(targetptr))));
7251 fdP = IH_OPEN(targetptr->handle);
7254 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
7256 VTakeOffline(volptr);
7257 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7262 if (linkCount != 1) {
7265 ("StoreData_RXStyle : inode %s has more than onelink\n",
7266 PrintInode(NULL, VN_GET_INO(targetptr))));
7267 /* other volumes share this data, better copy it first */
7269 /* Adjust the disk block count by the creation of the new inode.
7270 * We call the special VDiskUsage so we don't adjust the volume's
7271 * quota since we don't want to penalyze the user for afs's internal
7272 * mechanisms (i.e. copy on write overhead.) Also the right size
7273 * of the disk will be recorded...
7276 VN_GET_LEN(size, targetptr);
7277 volptr->partition->flags &= ~PART_DONTUPDATE;
7278 VSetPartitionDiskUsage(volptr->partition);
7279 volptr->partition->flags |= PART_DONTUPDATE;
7280 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
7281 volptr->partition->flags &= ~PART_DONTUPDATE;
7286 CoW_len = (FileLength >= (Length + Pos)) ? FileLength - Length : Pos;
7287 CopyOnWrite_calls++;
7288 if (CoW_len == 0) CopyOnWrite_size0++;
7289 if (Pos == 0) CopyOnWrite_off0++;
7290 if (CoW_len > CopyOnWrite_maxsize) CopyOnWrite_maxsize = CoW_len;
7292 ViceLog(1, ("StoreData : calling CopyOnWrite on vnode %u.%u (%s) "
7293 "off 0x0 size 0x%llx\n",
7294 afs_printable_VolumeId_u(V_id(volptr)),
7295 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7296 V_name(volptr), Pos));
7297 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, Pos))) {
7298 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
7299 volptr->partition->flags &= ~PART_DONTUPDATE;
7303 volptr->partition->flags &= ~PART_DONTUPDATE;
7304 VSetPartitionDiskUsage(volptr->partition);
7305 fdP = IH_OPEN(targetptr->handle);
7308 ("StoreData : Reopen after CopyOnWrite failed\n"));
7313 tinode = VN_GET_INO(targetptr);
7315 if (!VALID_INO(tinode)) {
7316 VTakeOffline(volptr);
7317 ViceLog(0,("Volume %u now offline, must be salvaged.\n",
7322 /* compute new file length */
7323 NewLength = DataLength;
7324 if (FileLength < NewLength)
7325 /* simulate truncate */
7326 NewLength = FileLength;
7327 TruncatedLength = NewLength; /* remember length after possible ftruncate */
7328 if (Pos + Length > NewLength)
7329 NewLength = Pos + Length; /* and write */
7331 /* adjust the disk block count by the difference in the files */
7333 afs_fsize_t targSize;
7334 VN_GET_LEN(targSize, targetptr);
7335 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
7338 AdjustDiskUsage(volptr, adjustSize,
7339 adjustSize - SpareComp(volptr)))) {
7341 if (origfdP) FDH_CLOSE(origfdP);
7345 /* can signal cache manager to proceed from close now */
7346 /* this bit means that the locks are set and protections are OK */
7347 rx_SetLocalStatus(Call, 1);
7349 FT_GetTimeOfDay(&StartTime, 0);
7351 optSize = sendBufSize;
7353 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
7354 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
7355 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
7357 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
7358 if (FileLength < DataLength)
7359 FDH_TRUNC(fdP, FileLength);
7361 FDH_SEEK(fdP, Pos, 0);
7362 bytesTransfered = 0;
7364 tbuffer = AllocSendBuffer();
7365 #endif /* AFS_NT40_ENV */
7366 /* if length == 0, the loop below isn't going to do anything, including
7367 * extend the length of the inode, which it must do, since the file system
7368 * assumes that the inode length == vnode's file length. So, we extend
7369 * the file length manually if need be. Note that if file is bigger than
7370 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7371 * do what we're going to do below.
7373 if (Length == 0 && Pos > TruncatedLength) {
7374 /* Set the file's length; we've already done an lseek to the right
7377 errorCode = FDH_WRITE(fdP, &tlen, 1);
7380 errorCode = FDH_TRUNC(fdP, Pos);
7382 /* have some data to copy */
7383 #if FS_STATS_DETAILED
7384 (*a_bytesToStoreP) = Length;
7385 #endif /* FS_STATS_DETAILED */
7388 if (bytesTransfered >= Length) {
7392 tlen = Length - bytesTransfered; /* how much more to do */
7394 rlen = optSize; /* bound by buffer size */
7398 errorCode = rx_Read(Call, tbuffer, rlen);
7399 #else /* AFS_NT40_ENV */
7400 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7401 #endif /* AFS_NT40_ENV */
7402 if (errorCode <= 0) {
7406 #if FS_STATS_DETAILED
7407 (*a_bytesStoredP) += errorCode;
7408 #endif /* FS_STATS_DETAILED */
7411 errorCode = FDH_WRITE(fdP, tbuffer, rlen);
7412 #else /* AFS_NT40_ENV */
7413 errorCode = FDH_WRITEV(fdP, tiov, tnio);
7414 #endif /* AFS_NT40_ENV */
7415 if (errorCode != rlen) {
7416 errorCode = VDISKFULL;
7419 bytesTransfered += rlen;
7424 FreeSendBuffer((struct afs_buffer *)tbuffer);
7425 #endif /* AFS_NT40_ENV */
7430 afs_fsize_t nfSize = (afs_fsize_t) FDH_SIZE(fdP);
7431 /* something went wrong: adjust size and return */
7432 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7433 /* changed_newTime is tested in StoreData to detemine if we
7434 * need to update the target vnode.
7436 targetptr->changed_newTime = 1;
7437 if (origfdP && (bytesTransfered < Length)) /* Need to "finish" CopyOnWrite still */
7438 CopyOnWrite2(origfdP, fdP, Pos + bytesTransfered, NewLength - Pos - bytesTransfered);
7439 if (origfdP) FDH_CLOSE(origfdP);
7441 /* set disk usage to be correct */
7442 VAdjustDiskUsage(&errorCode, volptr,
7443 (afs_sfsize_t) (nBlocks(nfSize) -
7444 nBlocks(NewLength)), 0);
7447 if (origfdP) { /* finish CopyOnWrite */
7448 if ( (CoW_off = Pos + Length) < NewLength) {
7449 errorCode = CopyOnWrite2(origfdP, fdP, CoW_off, CoW_len = NewLength - CoW_off);
7450 ViceLog(1, ("StoreData : CopyOnWrite2 on vnode %u.%u (%s) "
7451 "off 0x%llx size 0x%llx returns %d\n",
7452 afs_printable_VolumeId_u(V_id(volptr)),
7453 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7454 V_name(volptr), CoW_off, CoW_len, errorCode));
7460 FT_GetTimeOfDay(&StopTime, 0);
7462 VN_SET_LEN(targetptr, NewLength);
7464 /* Update all StoreData related stats */
7466 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7467 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7468 AFSCallStats.StoreSize1++; /* Piggybacked data */
7470 afs_fsize_t targLen;
7471 VN_GET_LEN(targLen, targetptr);
7472 if (targLen < SIZE2)
7473 AFSCallStats.StoreSize2++;
7474 else if (targLen < SIZE3)
7475 AFSCallStats.StoreSize3++;
7476 else if (targLen < SIZE4)
7477 AFSCallStats.StoreSize4++;
7479 AFSCallStats.StoreSize5++;
7484 } /*StoreData_RXStyle */
7486 static int sys2et[512];
7489 init_sys_error_to_et(void)
7491 memset(&sys2et, 0, sizeof(sys2et));
7492 sys2et[EPERM] = UAEPERM;
7493 sys2et[ENOENT] = UAENOENT;
7494 sys2et[ESRCH] = UAESRCH;
7495 sys2et[EINTR] = UAEINTR;
7496 sys2et[EIO] = UAEIO;
7497 sys2et[ENXIO] = UAENXIO;
7498 sys2et[E2BIG] = UAE2BIG;
7499 sys2et[ENOEXEC] = UAENOEXEC;
7500 sys2et[EBADF] = UAEBADF;
7501 sys2et[ECHILD] = UAECHILD;
7502 sys2et[EAGAIN] = UAEAGAIN;
7503 sys2et[ENOMEM] = UAENOMEM;
7504 sys2et[EACCES] = UAEACCES;
7505 sys2et[EFAULT] = UAEFAULT;
7506 sys2et[ENOTBLK] = UAENOTBLK;
7507 sys2et[EBUSY] = UAEBUSY;
7508 sys2et[EEXIST] = UAEEXIST;
7509 sys2et[EXDEV] = UAEXDEV;
7510 sys2et[ENODEV] = UAENODEV;
7511 sys2et[ENOTDIR] = UAENOTDIR;
7512 sys2et[EISDIR] = UAEISDIR;
7513 sys2et[EINVAL] = UAEINVAL;
7514 sys2et[ENFILE] = UAENFILE;
7515 sys2et[EMFILE] = UAEMFILE;
7516 sys2et[ENOTTY] = UAENOTTY;
7517 sys2et[ETXTBSY] = UAETXTBSY;
7518 sys2et[EFBIG] = UAEFBIG;
7519 sys2et[ENOSPC] = UAENOSPC;
7520 sys2et[ESPIPE] = UAESPIPE;
7521 sys2et[EROFS] = UAEROFS;
7522 sys2et[EMLINK] = UAEMLINK;
7523 sys2et[EPIPE] = UAEPIPE;
7524 sys2et[EDOM] = UAEDOM;
7525 sys2et[ERANGE] = UAERANGE;
7526 sys2et[EDEADLK] = UAEDEADLK;
7527 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7528 sys2et[ENOLCK] = UAENOLCK;
7529 sys2et[ENOSYS] = UAENOSYS;
7530 #if (ENOTEMPTY != EEXIST)
7531 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7533 sys2et[ELOOP] = UAELOOP;
7534 #if (EWOULDBLOCK != EAGAIN)
7535 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7537 sys2et[ENOMSG] = UAENOMSG;
7538 sys2et[EIDRM] = UAEIDRM;
7539 sys2et[ECHRNG] = UAECHRNG;
7540 sys2et[EL2NSYNC] = UAEL2NSYNC;
7541 sys2et[EL3HLT] = UAEL3HLT;
7542 sys2et[EL3RST] = UAEL3RST;
7543 sys2et[ELNRNG] = UAELNRNG;
7544 sys2et[EUNATCH] = UAEUNATCH;
7545 sys2et[ENOCSI] = UAENOCSI;
7546 sys2et[EL2HLT] = UAEL2HLT;
7547 sys2et[EBADE] = UAEBADE;
7548 sys2et[EBADR] = UAEBADR;
7549 sys2et[EXFULL] = UAEXFULL;
7550 sys2et[ENOANO] = UAENOANO;
7551 sys2et[EBADRQC] = UAEBADRQC;
7552 sys2et[EBADSLT] = UAEBADSLT;
7553 sys2et[EDEADLK] = UAEDEADLK;
7554 sys2et[EBFONT] = UAEBFONT;
7555 sys2et[ENOSTR] = UAENOSTR;
7556 sys2et[ENODATA] = UAENODATA;
7557 sys2et[ETIME] = UAETIME;
7558 sys2et[ENOSR] = UAENOSR;
7559 sys2et[ENONET] = UAENONET;
7560 sys2et[ENOPKG] = UAENOPKG;
7561 sys2et[EREMOTE] = UAEREMOTE;
7562 sys2et[ENOLINK] = UAENOLINK;
7563 sys2et[EADV] = UAEADV;
7564 sys2et[ESRMNT] = UAESRMNT;
7565 sys2et[ECOMM] = UAECOMM;
7566 sys2et[EPROTO] = UAEPROTO;
7567 sys2et[EMULTIHOP] = UAEMULTIHOP;
7568 sys2et[EDOTDOT] = UAEDOTDOT;
7569 sys2et[EBADMSG] = UAEBADMSG;
7570 sys2et[EOVERFLOW] = UAEOVERFLOW;
7571 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7572 sys2et[EBADFD] = UAEBADFD;
7573 sys2et[EREMCHG] = UAEREMCHG;
7574 sys2et[ELIBACC] = UAELIBACC;
7575 sys2et[ELIBBAD] = UAELIBBAD;
7576 sys2et[ELIBSCN] = UAELIBSCN;
7577 sys2et[ELIBMAX] = UAELIBMAX;
7578 sys2et[ELIBEXEC] = UAELIBEXEC;
7579 sys2et[EILSEQ] = UAEILSEQ;
7580 sys2et[ERESTART] = UAERESTART;
7581 sys2et[ESTRPIPE] = UAESTRPIPE;
7582 sys2et[EUSERS] = UAEUSERS;
7583 sys2et[ENOTSOCK] = UAENOTSOCK;
7584 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7585 sys2et[EMSGSIZE] = UAEMSGSIZE;
7586 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7587 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7588 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7589 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7590 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7591 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7592 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7593 sys2et[EADDRINUSE] = UAEADDRINUSE;
7594 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7595 sys2et[ENETDOWN] = UAENETDOWN;
7596 sys2et[ENETUNREACH] = UAENETUNREACH;
7597 sys2et[ENETRESET] = UAENETRESET;
7598 sys2et[ECONNABORTED] = UAECONNABORTED;
7599 sys2et[ECONNRESET] = UAECONNRESET;
7600 sys2et[ENOBUFS] = UAENOBUFS;
7601 sys2et[EISCONN] = UAEISCONN;
7602 sys2et[ENOTCONN] = UAENOTCONN;
7603 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7604 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7605 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7606 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7607 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7608 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7609 sys2et[EALREADY] = UAEALREADY;
7610 sys2et[EINPROGRESS] = UAEINPROGRESS;
7611 sys2et[ESTALE] = UAESTALE;
7612 sys2et[EUCLEAN] = UAEUCLEAN;
7613 sys2et[ENOTNAM] = UAENOTNAM;
7614 sys2et[ENAVAIL] = UAENAVAIL;
7615 sys2et[EISNAM] = UAEISNAM;
7616 sys2et[EREMOTEIO] = UAEREMOTEIO;
7617 sys2et[EDQUOT] = UAEDQUOT;
7618 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7619 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7621 sys2et[EIO] = UAEIO;
7625 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
7626 * - pass back the connection, client, and host from CallPreamble
7627 * - keep a ref on the client, which we don't now
7628 * - keep a hold on the host, which we already do
7629 * - pass the connection, client, and host down into SAFSS_*, and use
7630 * them instead of independently discovering them via rx_ConnectionOf
7631 * (safe) and rx_GetSpecific (not so safe)
7632 * The idea being that we decide what client and host we're going to use
7633 * when CallPreamble is called, and stay consistent throughout the call.
7634 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
7638 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7640 Error errorCode = 0;
7641 struct rx_connection *tcon;
7642 struct host *tcallhost;
7643 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7645 struct client *tclient;
7646 static struct rx_securityClass *sc = 0;
7648 struct rx_connection *conn;
7651 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost)))
7652 goto Bad_CallBackRxConnAddr1;
7654 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7658 tclient = h_FindClient_r(tcon);
7661 goto Bad_CallBackRxConnAddr;
7663 thost = tclient->host;
7665 /* nothing more can be done */
7666 if ( !thost->interface )
7667 goto Bad_CallBackRxConnAddr;
7669 /* the only address is the primary interface */
7670 /* can't change when there's only 1 address, anyway */
7671 if ( thost->interface->numberOfInterfaces <= 1 )
7672 goto Bad_CallBackRxConnAddr;
7674 /* initialise a security object only once */
7676 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7678 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7680 if ( *addr == thost->interface->addr[i] ) {
7685 if ( *addr != thost->interface->addr[i] )
7686 goto Bad_CallBackRxConnAddr;
7688 conn = rx_NewConnection (thost->interface->addr[i],
7689 thost->port, 1, sc, 0);
7690 rx_SetConnDeadTime(conn, 2);
7691 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7693 errorCode = RXAFSCB_Probe(conn);
7696 if ( thost->callback_rxcon )
7697 rx_DestroyConnection(thost->callback_rxcon);
7698 thost->callback_rxcon = conn;
7700 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7701 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7702 h_ReleaseClient_r(tclient);
7703 /* The hold on thost will be released by CallPostamble */
7705 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7708 rx_DestroyConnection(conn);
7710 Bad_CallBackRxConnAddr:
7711 h_ReleaseClient_r(tclient);
7712 /* The hold on thost will be released by CallPostamble */
7716 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7717 Bad_CallBackRxConnAddr1:
7718 return errorCode; /* failure */
7722 sys_error_to_et(afs_int32 in)
7726 if (in < 0 || in > 511)
7728 if ((in >= VICE_SPECIAL_ERRORS && in <= VIO) || in == VRESTRICTED)
7730 if (sys2et[in] != 0)