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 #ifndef AFS_ARM_DARWIN_ENV
53 #include <netinet/if_ether.h>
58 /* included early because of name conflict on IOPEN */
59 #include <sys/inode.h>
63 #endif /* AFS_HPUX_ENV */
67 #include <afs/afs_assert.h>
70 #include <afs/afsint.h>
71 #include <afs/vldbint.h>
72 #include <afs/errors.h>
73 #include <afs/ihandle.h>
74 #include <afs/vnode.h>
75 #include <afs/volume.h>
76 #include <afs/ptclient.h>
77 #include <afs/ptuser.h>
78 #include <afs/prs_fs.h>
81 #include <rx/rx_globals.h>
83 #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)
86 #if !defined(AFS_NT40_ENV)
89 #if !defined(AFS_SGI_ENV) && !defined(AFS_NT40_ENV)
91 #include <sys/statfs.h>
92 #include <sys/lockf.h>
94 #if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
99 #include <afs/cellconfig.h>
100 #include <afs/keys.h>
103 #include <afs/partition.h>
104 #include "viced_prototypes.h"
107 #include "callback.h"
108 #include <afs/unified_afs.h>
109 #include <afs/audit.h>
110 #include <afs/afsutil.h>
113 extern void SetDirHandle(DirHandle * dir, Vnode * vnode);
114 extern void FidZap(DirHandle * file);
115 extern void FidZero(DirHandle * file);
117 #ifdef AFS_PTHREAD_ENV
118 pthread_mutex_t fileproc_glock_mutex;
119 #endif /* AFS_PTHREAD_ENV */
122 #define afs_stat stat64
123 #define afs_fstat fstat64
124 #define afs_open open64
125 #else /* !O_LARGEFILE */
126 #define afs_stat stat
127 #define afs_fstat fstat
128 #define afs_open open
129 #endif /* !O_LARGEFILE */
132 /* Useful local defines used by this module */
135 #define MustNOTBeDIR 1
139 #define TVS_SSTATUS 2
142 #define TVS_MKDIR 0x10
144 #define CHK_FETCH 0x10
145 #define CHK_FETCHDATA 0x10
146 #define CHK_FETCHACL 0x11
147 #define CHK_FETCHSTATUS 0x12
148 #define CHK_STOREDATA 0x00
149 #define CHK_STOREACL 0x01
150 #define CHK_STORESTATUS 0x02
152 #define OWNERREAD 0400
153 #define OWNERWRITE 0200
154 #define OWNEREXEC 0100
155 #ifdef USE_GROUP_PERMS
156 #define GROUPREAD 0040
157 #define GROUPWRITE 0020
158 #define GROUPREXEC 0010
161 /* The following errors were not defined in NT. They are given unique
162 * names here to avoid any potential collision.
164 #define FSERR_ELOOP 90
165 #define FSERR_EOPNOTSUPP 122
166 #define FSERR_ECONNREFUSED 130
168 #define NOTACTIVECALL 0
171 #define CREATE_SGUID_ADMIN_ONLY 1
173 extern struct afsconf_dir *confDir;
174 extern afs_int32 dataVersionHigh;
177 static struct AFSCallStatistics AFSCallStats;
178 #if FS_STATS_DETAILED
179 struct fs_stats_FullPerfStats afs_FullPerfStats;
180 extern int AnonymousID;
181 #endif /* FS_STATS_DETAILED */
182 #if OPENAFS_VOL_STATS
183 static const char nullString[] = "";
184 #endif /* OPENAFS_VOL_STATS */
187 afs_int32 NothingYet;
190 struct afs_FSStats afs_fsstats;
195 afs_int32 BlocksSpare = 1024; /* allow 1 MB overruns */
197 extern afs_int32 implicitAdminRights;
198 extern afs_int32 readonlyServer;
199 extern int CopyOnWrite_calls, CopyOnWrite_off0, CopyOnWrite_size0;
200 extern afs_fsize_t CopyOnWrite_maxsize;
203 * Externals used by the xstat code.
205 extern VolPkgStats VStats;
206 extern int CEs, CEBlocks;
208 extern int HTs, HTBlocks;
210 afs_int32 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
211 struct rx_call *Call, afs_sfsize_t Pos,
212 afs_sfsize_t Len, afs_int32 Int64Mode,
213 #if FS_STATS_DETAILED
214 afs_sfsize_t * a_bytesToFetchP,
215 afs_sfsize_t * a_bytesFetchedP
216 #endif /* FS_STATS_DETAILED */
219 afs_int32 StoreData_RXStyle(Volume * volptr, Vnode * targetptr,
220 struct AFSFid *Fid, struct client *client,
221 struct rx_call *Call, afs_fsize_t Pos,
222 afs_fsize_t Length, afs_fsize_t FileLength,
224 #if FS_STATS_DETAILED
225 afs_sfsize_t * a_bytesToStoreP,
226 afs_sfsize_t * a_bytesStoredP
227 #endif /* FS_STATS_DETAILED */
230 #ifdef AFS_SGI_XFS_IOPS_ENV
231 #include <afs/xfsattrs.h>
233 GetLinkCount(Volume * avp, struct stat *astat)
235 if (!strcmp("xfs", astat->st_fstype)) {
236 return (astat->st_mode & AFS_XFS_MODE_LINK_MASK);
238 return astat->st_nlink;
241 #define GetLinkCount(V, S) (S)->st_nlink
245 SpareComp(Volume * avolp)
251 temp = V_maxquota(avolp);
253 /* no matter; doesn't check in this case */
257 temp = (temp * PctSpare) / 100;
268 * Set the volume synchronization parameter for this volume. If it changes,
269 * the Cache Manager knows that the volume must be purged from the stat cache.
272 SetVolumeSync(struct AFSVolSync *async, Volume * avol)
275 /* date volume instance was created */
278 async->spare1 = avol->header->diskstuff.creationDate;
291 * Note that this function always returns a held host, so
292 * that CallPostamble can block without the host's disappearing.
293 * Call returns rx connection in passed in *tconn
296 CallPreamble(struct rx_call *acall, int activecall,
297 struct rx_connection **tconn, struct host **ahostp)
300 struct client *tclient;
303 char hoststr[16], hoststr2[16];
304 #ifdef AFS_PTHREAD_ENV
305 struct ubik_client *uclient;
310 ViceLog(0, ("CallPreamble: unexpected null tconn!\n"));
313 *tconn = rx_ConnectionOf(acall);
317 tclient = h_FindClient_r(*tconn);
319 ViceLog(0, ("CallPreamble: Couldn't get CPS. Too many lockers\n"));
323 thost = tclient->host;
324 if (tclient->prfail == 1) { /* couldn't get the CPS */
326 h_ReleaseClient_r(tclient);
328 ViceLog(0, ("CallPreamble: Couldn't get CPS. Fail\n"));
332 retry_flag = 0; /* Retry once */
334 /* Take down the old connection and re-read the key file */
336 ("CallPreamble: Couldn't get CPS. Reconnect to ptserver\n"));
337 #ifdef AFS_PTHREAD_ENV
338 uclient = (struct ubik_client *)pthread_getspecific(viced_uclient_key);
340 /* Is it still necessary to drop this? We hit the net, we should... */
346 code = hpr_Initialize(&uclient);
349 assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
352 code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
355 h_ReleaseClient_r(tclient);
358 ViceLog(0, ("CallPreamble: couldn't reconnect to ptserver\n"));
362 tclient->prfail = 2; /* Means re-eval client's cps */
363 h_ReleaseClient_r(tclient);
368 tclient->LastCall = thost->LastCall = FT_ApproxTime();
369 if (activecall) /* For all but "GetTime", "GetStats", and "GetCaps" calls */
370 thost->ActiveCall = thost->LastCall;
373 if (thost->hostFlags & HOSTDELETED) {
375 ("Discarded a packet for deleted host %s:%d\n",
376 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port)));
377 code = VBUSY; /* raced, so retry */
378 } else if ((thost->hostFlags & VENUSDOWN)
379 || (thost->hostFlags & HFE_LATER)) {
380 if (BreakDelayedCallBacks_r(thost)) {
382 ("BreakDelayedCallbacks FAILED for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
383 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
384 ntohs(rxr_PortOf(*tconn))));
385 if (MultiProbeAlternateAddress_r(thost)) {
387 ("MultiProbe failed to find new address for host %s:%d\n",
388 afs_inet_ntoa_r(thost->host, hoststr),
389 ntohs(thost->port)));
393 ("MultiProbe found new address for host %s:%d\n",
394 afs_inet_ntoa_r(thost->host, hoststr),
395 ntohs(thost->port)));
396 if (BreakDelayedCallBacks_r(thost)) {
398 ("BreakDelayedCallbacks FAILED AGAIN for host %s:%d which IS UP. Connection from %s:%d. Possible network or routing failure.\n",
399 afs_inet_ntoa_r(thost->host, hoststr), ntohs(thost->port), afs_inet_ntoa_r(rxr_HostOf(*tconn), hoststr2),
400 ntohs(rxr_PortOf(*tconn))));
409 h_ReleaseClient_r(tclient);
419 CallPostamble(struct rx_connection *aconn, afs_int32 ret,
423 struct client *tclient;
427 tclient = h_FindClient_r(aconn);
430 thost = tclient->host;
431 if (thost->hostFlags & HERRORTRANS)
433 h_ReleaseClient_r(tclient);
436 if (ahost != thost) {
437 /* host/client recycle */
438 char hoststr[16], hoststr2[16];
439 ViceLog(0, ("CallPostamble: ahost %s:%d (%p) != thost "
441 afs_inet_ntoa_r(ahost->host, hoststr),
444 afs_inet_ntoa_r(thost->host, hoststr2),
448 /* return the reference taken in CallPreamble */
452 ViceLog(0, ("CallPostamble: null ahost for thost %s:%d (%p)\n",
453 afs_inet_ntoa_r(thost->host, hoststr),
458 /* return the reference taken in local h_FindClient_r--h_ReleaseClient_r
459 * does not decrement refcount on client->host */
464 return (translate ? sys_error_to_et(ret) : ret);
468 * Returns the volume and vnode pointers associated with file Fid; the lock
469 * type on the vnode is set to lock. Note that both volume/vnode's ref counts
470 * are incremented and they must be eventualy released.
473 CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock)
476 Error local_errorCode, errorCode = -1;
477 static struct timeval restartedat = { 0, 0 };
479 if (fid->Volume == 0 || fid->Vnode == 0) /* not: || fid->Unique == 0) */
481 if ((*volptr) == 0) {
486 #ifdef AFS_DEMAND_ATTACH_FS
494 *volptr = VGetVolumeNoWait(&local_errorCode, &errorCode, (afs_int32) fid->Volume);
499 if ((errorCode == VOFFLINE) && (VInit < 2)) {
500 /* The volume we want may not be attached yet because
501 * the volume initialization is not yet complete.
502 * We can do several things:
503 * 1. return -1, which will cause users to see
504 * "connection timed out". This is more or
505 * less the same as always, except that the servers
506 * may appear to bounce up and down while they
507 * are actually restarting.
508 * 2. return VBUSY which will cause clients to
509 * sleep and retry for 6.5 - 15 minutes, depending
510 * on what version of the CM they are running. If
511 * the file server takes longer than that interval
512 * to attach the desired volume, then the application
513 * will see an ENODEV or EIO. This approach has
514 * the advantage that volumes which have been attached
515 * are immediately available, it keeps the server's
516 * immediate backlog low, and the call is interruptible
517 * by the user. Users see "waiting for busy volume."
518 * 3. sleep here and retry. Some people like this approach
519 * because there is no danger of seeing errors. However,
520 * this approach only works with a bounded number of
521 * clients, since the pending queues will grow without
522 * stopping. It might be better to find a way to take
523 * this call and stick it back on a queue in order to
524 * recycle this thread for a different request.
525 * 4. Return a new error code, which new cache managers will
526 * know enough to interpret as "sleep and retry", without
527 * the upper bound of 6-15 minutes that is imposed by the
528 * VBUSY handling. Users will see "waiting for
529 * busy volume," so they know that something is
530 * happening. Old cache managers must be able to do
531 * something reasonable with this, for instance, mark the
532 * server down. Fortunately, any error code < 0
533 * will elicit that behavior. See #1.
534 * 5. Some combination of the above. I like doing #2 for 10
535 * minutes, followed by #4. 3.1b and 3.2 cache managers
536 * will be fine as long as the restart period is
537 * not longer than 6.5 minutes, otherwise they may
538 * return ENODEV to users. 3.3 cache managers will be
539 * fine for 10 minutes, then will return
540 * ETIMEDOUT. 3.4 cache managers will just wait
541 * until the call works or fails definitively.
542 * NB. The problem with 2,3,4,5 is that old clients won't
543 * fail over to an alternate read-only replica while this
544 * server is restarting. 3.4 clients will fail over right away.
546 if (restartedat.tv_sec == 0) {
547 /* I'm not really worried about when we restarted, I'm */
548 /* just worried about when the first VBUSY was returned. */
549 FT_GetTimeOfDay(&restartedat, 0);
552 afs_perfstats.fs_nBusies++;
555 return (busyonrst ? VBUSY : restarting);
558 FT_GetTimeOfDay(&now, 0);
559 if ((now.tv_sec - restartedat.tv_sec) < (11 * 60)) {
562 afs_perfstats.fs_nBusies++;
565 return (busyonrst ? VBUSY : restarting);
571 /* allow read operations on busy volume.
572 * must check local_errorCode because demand attach fs
573 * can have local_errorCode == VSALVAGING, errorCode == VBUSY */
574 else if (local_errorCode == VBUSY && lock == READ_LOCK) {
575 #ifdef AFS_DEMAND_ATTACH_FS
576 /* DAFS case is complicated by the fact that local_errorCode can
577 * be VBUSY in cases where the volume is truly offline */
579 /* volume is in VOL_STATE_UNATTACHED */
582 #endif /* AFS_DEMAND_ATTACH_FS */
585 } else if (errorCode)
592 *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock);
595 if ((*vptr)->disk.uniquifier != fid->Unique) {
596 VPutVnode(&fileCode, *vptr);
597 assert(fileCode == 0);
599 return (VNOVNODE); /* return the right error code, at least */
605 * This routine returns the ACL associated with the targetptr. If the
606 * targetptr isn't a directory, we access its parent dir and get the ACL
607 * thru the parent; in such case the parent's vnode is returned in
611 SetAccessList(Vnode ** targetptr, Volume ** volume,
612 struct acl_accessList **ACL, int *ACLSize, Vnode ** parent,
613 AFSFid * Fid, int Lock)
615 if ((*targetptr)->disk.type == vDirectory) {
617 *ACL = VVnodeACL(*targetptr);
618 *ACLSize = VAclSize(*targetptr);
626 parentvnode = (*targetptr)->disk.parent;
627 VPutVnode(&errorCode, *targetptr);
631 *parent = VGetVnode(&errorCode, *volume, parentvnode, READ_LOCK);
634 *ACL = VVnodeACL(*parent);
635 *ACLSize = VAclSize(*parent);
636 if ((errorCode = CheckVnode(Fid, volume, targetptr, Lock)) != 0)
638 if ((*targetptr)->disk.parent != parentvnode) {
639 VPutVnode(&errorCode, *parent);
650 /* Must not be called with H_LOCK held */
652 client_CheckRights(struct client *client, struct acl_accessList *ACL,
656 ObtainReadLock(&client->lock);
657 if (client->CPS.prlist_len > 0 && !client->deleted &&
658 client->host && !(client->host->hostFlags & HOSTDELETED))
659 acl_CheckRights(ACL, &client->CPS, rights);
660 ReleaseReadLock(&client->lock);
663 /* Must not be called with H_LOCK held */
665 client_HasAsMember(struct client *client, afs_int32 id)
669 ObtainReadLock(&client->lock);
670 if (client->CPS.prlist_len > 0 && !client->deleted &&
671 client->host && !(client->host->hostFlags & HOSTDELETED))
672 code = acl_IsAMember(id, &client->CPS);
673 ReleaseReadLock(&client->lock);
678 * Compare the directory's ACL with the user's access rights in the client
679 * connection and return the user's and everybody else's access permissions
680 * in rights and anyrights, respectively
683 GetRights(struct client *client, struct acl_accessList *ACL,
684 afs_int32 * rights, afs_int32 * anyrights)
686 extern prlist SystemAnyUserCPS;
687 afs_int32 hrights = 0;
688 #ifndef AFS_PTHREAD_ENV
692 if (acl_CheckRights(ACL, &SystemAnyUserCPS, anyrights) != 0) {
693 ViceLog(0, ("CheckRights failed\n"));
698 client_CheckRights(client, ACL, rights);
700 /* wait if somebody else is already doing the getCPS call */
702 while (client->host->hostFlags & HCPS_INPROGRESS) {
703 client->host->hostFlags |= HCPS_WAITING; /* I am waiting */
704 #ifdef AFS_PTHREAD_ENV
705 pthread_cond_wait(&client->host->cond, &host_glock_mutex);
706 #else /* AFS_PTHREAD_ENV */
708 LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS)
709 ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
710 #endif /* AFS_PTHREAD_ENV */
713 if (!client->host->hcps.prlist_len || !client->host->hcps.prlist_val) {
716 ("CheckRights: len=%u, for host=%s:%d\n",
717 client->host->hcps.prlist_len,
718 afs_inet_ntoa_r(client->host->host, hoststr),
719 ntohs(client->host->port)));
721 acl_CheckRights(ACL, &client->host->hcps, &hrights);
723 /* Allow system:admin the rights given with the -implicit option */
724 if (client_HasAsMember(client, SystemId))
725 *rights |= implicitAdminRights;
728 *anyrights |= hrights;
735 * VanillaUser returns 1 (true) if the user is a vanilla user (i.e., not
736 * a System:Administrator)
739 VanillaUser(struct client *client)
741 if (client_HasAsMember(client, SystemId))
742 return (0); /* not a system administrator, then you're "vanilla" */
749 * This unusual afs_int32-parameter routine encapsulates all volume package related
750 * operations together in a single function; it's called by almost all AFS
754 GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr,
755 Vnode ** targetptr, int chkforDir, Vnode ** parent,
756 struct client **client, int locktype, afs_int32 * rights,
757 afs_int32 * anyrights)
759 struct acl_accessList *aCL; /* Internal access List */
760 int aCLSize; /* size of the access list */
761 Error errorCode = 0; /* return code to caller */
763 if ((errorCode = CheckVnode(Fid, volptr, targetptr, locktype)))
766 if (chkforDir == MustNOTBeDIR
767 && ((*targetptr)->disk.type == vDirectory))
769 else if (chkforDir == MustBeDIR
770 && ((*targetptr)->disk.type != vDirectory))
774 SetAccessList(targetptr, volptr, &aCL, &aCLSize, parent,
775 (chkforDir == MustBeDIR ? (AFSFid *) 0 : Fid),
776 (chkforDir == MustBeDIR ? 0 : locktype))) != 0)
778 if (chkforDir == MustBeDIR)
779 assert((*parent) == 0);
781 if ((errorCode = GetClient(tcon, client)) != 0)
786 GetRights(*client, aCL, rights, anyrights);
787 /* ok, if this is not a dir, set the PRSFS_ADMINISTER bit iff we're the owner */
788 if ((*targetptr)->disk.type != vDirectory) {
789 /* anyuser can't be owner, so only have to worry about rights, not anyrights */
790 if ((*targetptr)->disk.owner == (*client)->ViceId)
791 (*rights) |= PRSFS_ADMINISTER;
793 (*rights) &= ~PRSFS_ADMINISTER;
795 #ifdef ADMIN_IMPLICIT_LOOKUP
796 /* admins get automatic lookup on everything */
797 if (!VanillaUser(*client))
798 (*rights) |= PRSFS_LOOKUP;
799 #endif /* ADMIN_IMPLICIT_LOOKUP */
802 } /*GetVolumePackage */
806 * This is the opposite of GetVolumePackage(), and is always used at the end of
807 * AFS calls to put back all used vnodes and the volume in the proper order!
810 PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr,
811 Vnode * parentptr, Volume * volptr, struct client **client)
813 Error fileCode = 0; /* Error code returned by the volume package */
815 if (parentwhentargetnotdir) {
816 VPutVnode(&fileCode, parentwhentargetnotdir);
817 assert(!fileCode || (fileCode == VSALVAGE));
820 VPutVnode(&fileCode, targetptr);
821 assert(!fileCode || (fileCode == VSALVAGE));
824 VPutVnode(&fileCode, parentptr);
825 assert(!fileCode || (fileCode == VSALVAGE));
833 } /*PutVolumePackage */
836 VolumeOwner(struct client *client, Vnode * targetptr)
838 afs_int32 owner = V_owner(targetptr->volumePtr); /* get volume owner */
841 return (client->ViceId == owner);
844 * We don't have to check for host's cps since only regular
845 * viceid are volume owners.
847 return (client_HasAsMember(client, owner));
853 VolumeRootVnode(Vnode * targetptr)
855 return ((targetptr->vnodeNumber == ROOTVNODE)
856 && (targetptr->disk.uniquifier == 1));
858 } /*VolumeRootVnode */
861 * Check if target file has the proper access permissions for the Fetch
862 * (FetchData, FetchACL, FetchStatus) and Store (StoreData, StoreACL,
863 * StoreStatus) related calls
865 /* this code should probably just set a "priv" flag where all the audit events
866 * are now, and only generate the audit event once at the end of the routine,
867 * thus only generating the event if all the checks succeed, but only because
868 * of the privilege XXX
871 Check_PermissionRights(Vnode * targetptr, struct client *client,
872 afs_int32 rights, int CallingRoutine,
873 AFSStoreStatus * InStatus)
876 #define OWNSp(client, target) ((client)->ViceId == (target)->disk.owner)
877 #define CHOWN(i,t) (((i)->Mask & AFS_SETOWNER) &&((i)->Owner != (t)->disk.owner))
878 #define CHGRP(i,t) (((i)->Mask & AFS_SETGROUP) &&((i)->Group != (t)->disk.group))
880 if (CallingRoutine & CHK_FETCH) {
881 if (CallingRoutine == CHK_FETCHDATA || VanillaUser(client)) {
882 if (targetptr->disk.type == vDirectory
883 || targetptr->disk.type == vSymlink) {
884 if (!(rights & PRSFS_LOOKUP)
885 #ifdef ADMIN_IMPLICIT_LOOKUP
886 /* grant admins fetch on all directories */
887 && VanillaUser(client)
888 #endif /* ADMIN_IMPLICIT_LOOKUP */
889 && !VolumeOwner(client, targetptr))
892 /* must have read access, or be owner and have insert access */
893 if (!(rights & PRSFS_READ)
894 && !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)))
897 if (CallingRoutine == CHK_FETCHDATA
898 && targetptr->disk.type == vFile)
899 #ifdef USE_GROUP_PERMS
900 if (!OWNSp(client, targetptr)
901 && !client_HasAsMember(client, targetptr->disk.owner)) {
903 (((GROUPREAD | GROUPEXEC) & targetptr->disk.modeBits)
907 (((OWNERREAD | OWNEREXEC) & targetptr->disk.modeBits)
912 * The check with the ownership below is a kludge to allow
913 * reading of files created with no read permission. The owner
914 * of the file is always allowed to read it.
916 if ((client->ViceId != targetptr->disk.owner)
917 && VanillaUser(client))
919 (((OWNERREAD | OWNEREXEC) & targetptr->disk.
920 modeBits) ? 0 : EACCES);
922 } else { /* !VanillaUser(client) && !FetchData */
924 osi_audit(PrivilegeEvent, 0, AUD_ID,
925 (client ? client->ViceId : 0), AUD_INT, CallingRoutine,
928 } else { /* a store operation */
929 if ((rights & PRSFS_INSERT) && OWNSp(client, targetptr)
930 && (CallingRoutine != CHK_STOREACL)
931 && (targetptr->disk.type == vFile)) {
932 /* bypass protection checks on first store after a create
933 * for the creator; also prevent chowns during this time
934 * unless you are a system administrator */
935 /****** InStatus->Owner && UnixModeBits better be SET!! */
936 if (CHOWN(InStatus, targetptr) || CHGRP(InStatus, targetptr)) {
939 else if (VanillaUser(client))
940 return (EPERM); /* Was EACCES */
942 osi_audit(PrivilegeEvent, 0, AUD_ID,
943 (client ? client->ViceId : 0), AUD_INT,
944 CallingRoutine, AUD_END);
947 if (CallingRoutine != CHK_STOREDATA && !VanillaUser(client)) {
948 osi_audit(PrivilegeEvent, 0, AUD_ID,
949 (client ? client->ViceId : 0), AUD_INT,
950 CallingRoutine, AUD_END);
952 if (readonlyServer) {
955 if (CallingRoutine == CHK_STOREACL) {
956 if (!(rights & PRSFS_ADMINISTER)
957 && !VolumeOwner(client, targetptr))
959 } else { /* store data or status */
960 /* watch for chowns and chgrps */
961 if (CHOWN(InStatus, targetptr)
962 || CHGRP(InStatus, targetptr)) {
965 else if (VanillaUser(client))
966 return (EPERM); /* Was EACCES */
968 osi_audit(PrivilegeEvent, 0, AUD_ID,
969 (client ? client->ViceId : 0), AUD_INT,
970 CallingRoutine, AUD_END);
972 /* must be sysadmin to set suid/sgid bits */
973 if ((InStatus->Mask & AFS_SETMODE) &&
975 (InStatus->UnixModeBits & 0xc00) != 0) {
977 (InStatus->UnixModeBits & (S_ISUID | S_ISGID)) != 0) {
981 if (VanillaUser(client))
984 osi_audit(PrivSetID, 0, AUD_ID,
985 (client ? client->ViceId : 0), AUD_INT,
986 CallingRoutine, AUD_END);
988 if (CallingRoutine == CHK_STOREDATA) {
991 if (!(rights & PRSFS_WRITE))
993 /* Next thing is tricky. We want to prevent people
994 * from writing files sans 0200 bit, but we want
995 * creating new files with 0444 mode to work. We
996 * don't check the 0200 bit in the "you are the owner"
997 * path above, but here we check the bit. However, if
998 * you're a system administrator, we ignore the 0200
999 * bit anyway, since you may have fchowned the file,
1001 #ifdef USE_GROUP_PERMS
1002 if ((targetptr->disk.type == vFile)
1003 && VanillaUser(client)) {
1004 if (!OWNSp(client, targetptr)
1005 && !client_HasAsMember(client, targetptr->disk.owner)) {
1007 ((GROUPWRITE & targetptr->disk.modeBits)
1011 ((OWNERWRITE & targetptr->disk.modeBits)
1016 if ((targetptr->disk.type != vDirectory)
1017 && (!(targetptr->disk.modeBits & OWNERWRITE))) {
1020 if (VanillaUser(client))
1023 osi_audit(PrivilegeEvent, 0, AUD_ID,
1024 (client ? client->ViceId : 0),
1025 AUD_INT, CallingRoutine, AUD_END);
1027 } else { /* a status store */
1030 if (targetptr->disk.type == vDirectory) {
1031 if (!(rights & PRSFS_DELETE)
1032 && !(rights & PRSFS_INSERT))
1034 } else { /* a file or symlink */
1035 if (!(rights & PRSFS_WRITE))
1045 } /*Check_PermissionRights */
1049 * The Access List information is converted from its internal form in the
1050 * target's vnode buffer (or its parent vnode buffer if not a dir), to an
1051 * external form and returned back to the caller, via the AccessList
1055 RXFetch_AccessList(Vnode * targetptr, Vnode * parentwhentargetnotdir,
1056 struct AFSOpaque *AccessList)
1058 char *eACL; /* External access list placeholder */
1060 if (acl_Externalize_pr
1061 (hpr_IdToName, (targetptr->disk.type ==
1062 vDirectory ? VVnodeACL(targetptr) :
1063 VVnodeACL(parentwhentargetnotdir)), &eACL) != 0) {
1066 if ((strlen(eACL) + 1) > AFSOPAQUEMAX) {
1067 acl_FreeExternalACL(&eACL);
1070 strcpy((char *)(AccessList->AFSOpaque_val), (char *)eACL);
1071 AccessList->AFSOpaque_len = strlen(eACL) + 1;
1073 acl_FreeExternalACL(&eACL);
1076 } /*RXFetch_AccessList */
1080 * The Access List information is converted from its external form in the
1081 * input AccessList structure to the internal representation and copied into
1082 * the target dir's vnode storage.
1085 RXStore_AccessList(Vnode * targetptr, struct AFSOpaque *AccessList)
1087 struct acl_accessList *newACL; /* PlaceHolder for new access list */
1089 if (acl_Internalize_pr(hpr_NameToId, AccessList->AFSOpaque_val, &newACL)
1092 if ((newACL->size + 4) > VAclSize(targetptr))
1094 memcpy((char *)VVnodeACL(targetptr), (char *)newACL, (int)(newACL->size));
1095 acl_FreeACL(&newACL);
1098 } /*RXStore_AccessList */
1101 /* In our current implementation, each successive data store (new file
1102 * data version) creates a new inode. This function creates the new
1103 * inode, copies the old inode's contents to the new one, remove the old
1104 * inode (i.e. decrement inode count -- if it's currently used the delete
1105 * will be delayed), and modify some fields (i.e. vnode's
1106 * disk.inodeNumber and cloned)
1108 #define COPYBUFFSIZE 8192
1109 #define MAXFSIZE (~(afs_fsize_t) 0)
1111 CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len)
1113 Inode ino, nearInode;
1120 int rc; /* return code */
1121 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1122 FdHandle_t *targFdP; /* Source Inode file handle */
1123 FdHandle_t *newFdP; /* Dest Inode file handle */
1125 if (targetptr->disk.type == vDirectory)
1126 DFlush(); /* just in case? */
1128 VN_GET_LEN(size, targetptr);
1136 buff = (char *)malloc(COPYBUFFSIZE);
1141 ino = VN_GET_INO(targetptr);
1142 if (!VALID_INO(ino)) {
1144 VTakeOffline(volptr);
1145 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1149 targFdP = IH_OPEN(targetptr->handle);
1150 if (targFdP == NULL) {
1153 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1154 targetptr->vnodeNumber, V_id(volptr), rc));
1156 VTakeOffline(volptr);
1160 nearInode = VN_GET_INO(targetptr);
1162 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1163 VPartitionPath(V_partition(volptr)), nearInode,
1164 V_id(volptr), targetptr->vnodeNumber,
1165 targetptr->disk.uniquifier,
1166 (int)targetptr->disk.dataVersion);
1167 if (!VALID_INO(ino)) {
1169 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1170 volptr->partition->name, V_id(volptr), errno));
1175 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1176 newFdP = IH_OPEN(newH);
1177 assert(newFdP != NULL);
1181 if (size > COPYBUFFSIZE) { /* more than a buffer */
1182 length = COPYBUFFSIZE;
1183 size -= COPYBUFFSIZE;
1188 rdlen = FDH_PREAD(targFdP, buff, length, done);
1189 if (rdlen == length) {
1190 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1194 /* Callers of this function are not prepared to recover
1195 * from error that put the filesystem in an inconsistent
1196 * state. Make sure that we force the volume off-line if
1197 * we some error other than ENOSPC - 4.29.99)
1199 * In case we are unable to write the required bytes, and the
1200 * error code indicates that the disk is full, we roll-back to
1201 * the initial state.
1203 if ((rdlen != length) || (wrlen != length)) {
1204 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1206 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1207 volptr->partition->name, V_id(volptr)));
1208 /* remove destination inode which was partially copied till now */
1209 FDH_REALLYCLOSE(newFdP);
1211 FDH_REALLYCLOSE(targFdP);
1212 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1215 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1216 rc, V_id(volptr), volptr->partition->name));
1217 VTakeOffline(volptr);
1222 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1223 * since we never do any I/O anywhere near 2^32 bytes at a
1224 * time, just case to an unsigned int for printing */
1227 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1228 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1229 (unsigned)wrlen, errno));
1230 #if defined(AFS_DEMAND_ATTACH_FS)
1231 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1233 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1235 /* Decrement this inode so salvager doesn't find it. */
1236 FDH_REALLYCLOSE(newFdP);
1238 FDH_REALLYCLOSE(targFdP);
1239 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1241 VTakeOffline(volptr);
1245 #ifndef AFS_PTHREAD_ENV
1247 #endif /* !AFS_PTHREAD_ENV */
1249 FDH_REALLYCLOSE(targFdP);
1250 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1251 V_parentId(volptr));
1253 IH_RELEASE(targetptr->handle);
1255 rc = FDH_SYNC(newFdP);
1258 targetptr->handle = newH;
1259 VN_SET_INO(targetptr, ino);
1260 targetptr->disk.cloned = 0;
1261 /* Internal change to vnode, no user level change to volume - def 5445 */
1262 targetptr->changed_oldTime = 1;
1264 return 0; /* success */
1268 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_foff_t off,
1271 char *buff = malloc(COPYBUFFSIZE);
1276 afs_foff_t done = off;
1278 if (size > FDH_SIZE(targFdP) - off)
1279 size = FDH_SIZE(targFdP) - off;
1282 if (size > COPYBUFFSIZE) { /* more than a buffer */
1283 length = COPYBUFFSIZE;
1284 size -= COPYBUFFSIZE;
1289 rdlen = FDH_PREAD(targFdP, buff, length, done);
1290 if (rdlen == length) {
1291 wrlen = FDH_PWRITE(newFdP, buff, length, done);
1297 if ((rdlen != length) || (wrlen != length)) {
1298 /* no error recovery, at the worst we'll have a "hole"
1310 * Common code to handle with removing the Name (file when it's called from
1311 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1312 * given directory, parentptr.
1314 int DT1 = 0, DT0 = 0;
1316 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1317 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1319 DirHandle childdir; /* Handle for dir package I/O */
1320 Error errorCode = 0;
1324 /* watch for invalid names */
1325 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1327 if (parentptr->disk.cloned) {
1328 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1329 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1331 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1337 /* check that the file is in the directory */
1338 SetDirHandle(dir, parentptr);
1339 if (Lookup(dir, Name, fileFid))
1341 fileFid->Volume = V_id(volptr);
1343 /* just-in-case check for something causing deadlock */
1344 if (fileFid->Vnode == parentptr->vnodeNumber)
1347 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1351 if (ChkForDir == MustBeDIR) {
1352 if ((*targetptr)->disk.type != vDirectory)
1354 } else if ((*targetptr)->disk.type == vDirectory)
1357 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1359 * If the uniquifiers dont match then instead of asserting
1360 * take the volume offline and return VSALVAGE
1362 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1363 VTakeOffline(volptr);
1365 ("Volume %u now offline, must be salvaged.\n",
1367 errorCode = VSALVAGE;
1371 if (ChkForDir == MustBeDIR) {
1372 SetDirHandle(&childdir, *targetptr);
1373 if (IsEmpty(&childdir) != 0)
1375 DZap((afs_int32 *) &childdir);
1377 (*targetptr)->delete = 1;
1378 } else if ((--(*targetptr)->disk.linkCount) == 0)
1379 (*targetptr)->delete = 1;
1380 if ((*targetptr)->delete) {
1381 if (VN_GET_INO(*targetptr)) {
1383 IH_REALLYCLOSE((*targetptr)->handle);
1385 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1386 V_parentId(volptr));
1387 IH_RELEASE((*targetptr)->handle);
1388 if (errorCode == -1) {
1390 ("DT: inode=%s, name=%s, errno=%d\n",
1391 PrintInode(stmp, VN_GET_INO(*targetptr)), Name,
1393 if (errno != ENOENT)
1395 VTakeOffline(volptr);
1397 ("Volume %u now offline, must be salvaged.\n",
1405 VN_SET_INO(*targetptr, (Inode) 0);
1407 afs_fsize_t adjLength;
1408 VN_GET_LEN(adjLength, *targetptr);
1409 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1413 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1415 code = Delete(dir, (char *)Name);
1418 ("Error %d deleting %s\n", code,
1419 (((*targetptr)->disk.type ==
1420 Directory) ? "directory" : "file")));
1421 VTakeOffline(volptr);
1423 ("Volume %u now offline, must be salvaged.\n",
1436 * This routine updates the parent directory's status block after the
1437 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1438 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1442 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1443 int author, int linkcount,
1444 #if FS_STATS_DETAILED
1445 char a_inSameNetwork
1446 #endif /* FS_STATS_DETAILED */
1449 afs_fsize_t newlength; /* Holds new directory length */
1450 afs_fsize_t parentLength;
1452 #if FS_STATS_DETAILED
1453 Date currDate; /*Current date */
1454 int writeIdx; /*Write index to bump */
1455 int timeIdx; /*Authorship time index to bump */
1456 #endif /* FS_STATS_DETAILED */
1458 parentptr->disk.dataVersion++;
1459 newlength = (afs_fsize_t) Length(dir);
1461 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1462 * (create, symlink, link, makedir) so we need to check if we have enough space
1463 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1464 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1466 VN_GET_LEN(parentLength, parentptr);
1467 if (nBlocks(newlength) != nBlocks(parentLength)) {
1468 VAdjustDiskUsage(&errorCode, volptr,
1469 (nBlocks(newlength) - nBlocks(parentLength)),
1470 (nBlocks(newlength) - nBlocks(parentLength)));
1472 VN_SET_LEN(parentptr, newlength);
1474 #if FS_STATS_DETAILED
1476 * Update directory write stats for this volume. Note that the auth
1477 * counter is located immediately after its associated ``distance''
1480 if (a_inSameNetwork)
1481 writeIdx = VOL_STATS_SAME_NET;
1483 writeIdx = VOL_STATS_DIFF_NET;
1484 V_stat_writes(volptr, writeIdx)++;
1485 if (author != AnonymousID) {
1486 V_stat_writes(volptr, writeIdx + 1)++;
1490 * Update the volume's authorship information in response to this
1491 * directory operation. Get the current time, decide to which time
1492 * slot this operation belongs, and bump the appropriate slot.
1494 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1496 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1497 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1498 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1499 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1500 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1501 if (parentptr->disk.author == author) {
1502 V_stat_dirSameAuthor(volptr, timeIdx)++;
1504 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1506 #endif /* FS_STATS_DETAILED */
1508 parentptr->disk.author = author;
1509 parentptr->disk.linkCount = linkcount;
1510 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1511 parentptr->disk.serverModifyTime = FT_ApproxTime();
1512 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1517 * Update the target file's (or dir's) status block after the specified
1518 * operation is complete. Note that some other fields maybe updated by
1519 * the individual module.
1522 /* XXX INCOMPLETE - More attention is needed here! */
1524 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1525 struct client *client, AFSStoreStatus * InStatus,
1526 Vnode * parentptr, Volume * volptr,
1529 #if FS_STATS_DETAILED
1530 Date currDate; /*Current date */
1531 int writeIdx; /*Write index to bump */
1532 int timeIdx; /*Authorship time index to bump */
1533 #endif /* FS_STATS_DETAILED */
1535 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1536 targetptr->disk.parent = parentptr->vnodeNumber;
1537 VN_SET_LEN(targetptr, length);
1538 /* targetptr->disk.group = 0; save some cycles */
1539 targetptr->disk.modeBits = 0777;
1540 targetptr->disk.owner = client->ViceId;
1541 targetptr->disk.dataVersion = 0; /* consistent with the client */
1542 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1543 /* the inode was created in Alloc_NewVnode() */
1545 #if FS_STATS_DETAILED
1547 * Update file write stats for this volume. Note that the auth
1548 * counter is located immediately after its associated ``distance''
1551 if (client->InSameNetwork)
1552 writeIdx = VOL_STATS_SAME_NET;
1554 writeIdx = VOL_STATS_DIFF_NET;
1555 V_stat_writes(volptr, writeIdx)++;
1556 if (client->ViceId != AnonymousID) {
1557 V_stat_writes(volptr, writeIdx + 1)++;
1561 * We only count operations that DON'T involve creating new objects
1562 * (files, symlinks, directories) or simply setting status as
1563 * authorship-change operations.
1565 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1567 * Update the volume's authorship information in response to this
1568 * file operation. Get the current time, decide to which time
1569 * slot this operation belongs, and bump the appropriate slot.
1571 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1574 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1575 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1576 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1577 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1578 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1579 VOL_STATS_TIME_IDX_5);
1580 if (targetptr->disk.author == client->ViceId) {
1581 V_stat_fileSameAuthor(volptr, timeIdx)++;
1583 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1586 #endif /* FS_STATS_DETAILED */
1588 if (!(Caller & TVS_SSTATUS))
1589 targetptr->disk.author = client->ViceId;
1590 if (Caller & TVS_SDATA) {
1591 targetptr->disk.dataVersion++;
1592 if (VanillaUser(client)) {
1593 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1594 #ifdef CREATE_SGUID_ADMIN_ONLY
1595 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1599 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1600 /* store status, must explicitly request to change the date */
1601 if (InStatus->Mask & AFS_SETMODTIME)
1602 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1603 } else { /* other: date always changes, but perhaps to what is specified by caller */
1604 targetptr->disk.unixModifyTime =
1605 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1606 ClientModTime : FT_ApproxTime());
1608 if (InStatus->Mask & AFS_SETOWNER) {
1609 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1610 if (VanillaUser(client)) {
1611 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1612 #ifdef CREATE_SGUID_ADMIN_ONLY
1613 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1616 targetptr->disk.owner = InStatus->Owner;
1617 if (VolumeRootVnode(targetptr)) {
1618 Error errorCode = 0; /* what should be done with this? */
1620 V_owner(targetptr->volumePtr) = InStatus->Owner;
1621 VUpdateVolume(&errorCode, targetptr->volumePtr);
1624 if (InStatus->Mask & AFS_SETMODE) {
1625 int modebits = InStatus->UnixModeBits;
1626 #define CREATE_SGUID_ADMIN_ONLY 1
1627 #ifdef CREATE_SGUID_ADMIN_ONLY
1628 if (VanillaUser(client))
1629 modebits = modebits & 0777;
1631 if (VanillaUser(client)) {
1632 targetptr->disk.modeBits = modebits;
1634 targetptr->disk.modeBits = modebits;
1637 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1638 CHK_STOREDATA, AUD_END);
1642 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1643 CHK_STORESTATUS, AUD_END);
1650 targetptr->disk.serverModifyTime = FT_ApproxTime();
1651 if (InStatus->Mask & AFS_SETGROUP)
1652 targetptr->disk.group = InStatus->Group;
1653 /* vnode changed : to be written back by VPutVnode */
1654 targetptr->changed_newTime = 1;
1656 } /*Update_TargetVnodeStatus */
1660 * Fills the CallBack structure with the expiration time and type of callback
1661 * structure. Warning: this function is currently incomplete.
1664 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1666 /* CallBackTime could not be 0 */
1667 if (CallBackTime == 0) {
1668 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1669 CallBack->ExpirationTime = 0;
1671 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1672 CallBack->CallBackVersion = CALLBACK_VERSION;
1673 CallBack->CallBackType = CB_SHARED; /* The default for now */
1675 } /*SetCallBackStruct */
1679 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1680 * allocation; if some error occured (exceeded volume quota or partition
1681 * was full, or whatever), it frees the space back and returns the code.
1682 * We usually pre-adjust the volume space to make sure that there's
1683 * enough space before consuming some.
1686 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1687 afs_sfsize_t checkLength)
1692 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1694 VAdjustDiskUsage(&nc, volptr, -length, 0);
1695 if (rc == VOVERQUOTA) {
1697 ("Volume %u (%s) is full\n", V_id(volptr),
1701 if (rc == VDISKFULL) {
1703 ("Partition %s that contains volume %u is full\n",
1704 volptr->partition->name, V_id(volptr)));
1707 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1712 } /*AdjustDiskUsage */
1715 * Common code that handles the creation of a new file (SAFS_CreateFile and
1716 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1719 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1720 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1721 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1723 Error errorCode = 0; /* Error code returned back */
1726 Inode nearInode; /* hint for inode allocation in solaris */
1730 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1731 BlocksPreallocatedForVnode))) {
1733 ("Insufficient space to allocate %" AFS_INT64_FMT " blocks\n",
1734 (afs_intmax_t) BlocksPreallocatedForVnode));
1738 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1739 if (errorCode != 0) {
1740 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1743 OutFid->Volume = V_id(volptr);
1744 OutFid->Vnode = (*targetptr)->vnodeNumber;
1745 OutFid->Unique = (*targetptr)->disk.uniquifier;
1747 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1749 /* create the inode now itself */
1751 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1752 VPartitionPath(V_partition(volptr)), nearInode,
1753 V_id(volptr), (*targetptr)->vnodeNumber,
1754 (*targetptr)->disk.uniquifier, 1);
1756 /* error in creating inode */
1757 if (!VALID_INO(inode)) {
1759 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1760 (*targetptr)->volumePtr->header->diskstuff.id,
1761 (*targetptr)->vnodeNumber, errno));
1762 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1763 (*targetptr)->delete = 1; /* delete vnode */
1766 VN_SET_INO(*targetptr, inode);
1767 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1769 /* copy group from parent dir */
1770 (*targetptr)->disk.group = parentptr->disk.group;
1772 if (parentptr->disk.cloned) {
1773 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1774 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1775 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1776 /* delete the vnode previously allocated */
1777 (*targetptr)->delete = 1;
1778 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1779 IH_REALLYCLOSE((*targetptr)->handle);
1780 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1782 ("Alloc_NewVnode: partition %s idec %s failed\n",
1783 volptr->partition->name, PrintInode(stmp, inode)));
1784 IH_RELEASE((*targetptr)->handle);
1790 /* add the name to the directory */
1791 SetDirHandle(dir, parentptr);
1792 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1793 (*targetptr)->delete = 1;
1794 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1795 IH_REALLYCLOSE((*targetptr)->handle);
1796 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1798 ("Alloc_NewVnode: partition %s idec %s failed\n",
1799 volptr->partition->name, PrintInode(stmp, inode)));
1800 IH_RELEASE((*targetptr)->handle);
1806 } /*Alloc_NewVnode */
1810 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1814 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1816 int Time; /* Used for time */
1817 int writeVnode = targetptr->changed_oldTime; /* save original status */
1819 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1820 Time = FT_ApproxTime();
1821 switch (LockingType) {
1824 if (Time > targetptr->disk.lock.lockTime)
1825 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1827 Time += AFS_LOCKWAIT;
1828 if (LockingType == LockRead) {
1829 if ( !(rights & PRSFS_LOCK) &&
1830 !(rights & PRSFS_WRITE) &&
1831 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1834 if (targetptr->disk.lock.lockCount >= 0) {
1835 ++(targetptr->disk.lock.lockCount);
1836 targetptr->disk.lock.lockTime = Time;
1839 } else if (LockingType == LockWrite) {
1840 if ( !(rights & PRSFS_WRITE) &&
1841 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1844 if (targetptr->disk.lock.lockCount == 0) {
1845 targetptr->disk.lock.lockCount = -1;
1846 targetptr->disk.lock.lockTime = Time;
1852 Time += AFS_LOCKWAIT;
1853 if (targetptr->disk.lock.lockCount != 0)
1854 targetptr->disk.lock.lockTime = Time;
1859 if ((--targetptr->disk.lock.lockCount) <= 0)
1860 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1864 targetptr->changed_oldTime = writeVnode; /* restore old status */
1865 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1868 } /*HandleLocking */
1870 /* 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. */
1873 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1877 if (!(rights & Prfs_Mode))
1879 if ((targetptr->disk.type != vDirectory)
1880 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1886 * If some flags (i.e. min or max quota) are set, the volume's in disk
1887 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1888 * update, if applicable.
1891 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1892 char *Name, char *OfflineMsg, char *Motd)
1894 Error errorCode = 0;
1896 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1897 V_minquota(volptr) = StoreVolStatus->MinQuota;
1898 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1899 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1900 if (strlen(OfflineMsg) > 0) {
1901 strcpy(V_offlineMessage(volptr), OfflineMsg);
1903 if (strlen(Name) > 0) {
1904 strcpy(V_name(volptr), Name);
1906 #if OPENAFS_VOL_STATS
1908 * We don't overwrite the motd field, since it's now being used
1912 if (strlen(Motd) > 0) {
1913 strcpy(V_motd(volptr), Motd);
1915 #endif /* FS_STATS_DETAILED */
1916 VUpdateVolume(&errorCode, volptr);
1919 } /*RXUpdate_VolumeStatus */
1923 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1924 char **motd, Volume * volptr)
1928 status->Vid = V_id(volptr);
1929 status->ParentId = V_parentId(volptr);
1930 status->Online = V_inUse(volptr);
1931 status->InService = V_inService(volptr);
1932 status->Blessed = V_blessed(volptr);
1933 status->NeedsSalvage = V_needsSalvaged(volptr);
1934 if (VolumeWriteable(volptr))
1935 status->Type = ReadWrite;
1937 status->Type = ReadOnly;
1938 status->MinQuota = V_minquota(volptr);
1939 status->MaxQuota = V_maxquota(volptr);
1940 status->BlocksInUse = V_diskused(volptr);
1941 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
1942 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
1944 /* now allocate and copy these things; they're freed by the RXGEN stub */
1945 temp = strlen(V_name(volptr)) + 1;
1946 *name = malloc(temp);
1948 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1951 strcpy(*name, V_name(volptr));
1952 temp = strlen(V_offlineMessage(volptr)) + 1;
1953 *offMsg = malloc(temp);
1955 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1958 strcpy(*offMsg, V_offlineMessage(volptr));
1959 #if OPENAFS_VOL_STATS
1962 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1965 strcpy(*motd, nullString);
1967 temp = strlen(V_motd(volptr)) + 1;
1968 *motd = malloc(temp);
1970 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1973 strcpy(*motd, V_motd(volptr));
1974 #endif /* FS_STATS_DETAILED */
1976 } /*RXGetVolumeStatus */
1980 FileNameOK(char *aname)
1985 /* watch for @sys on the right */
1986 if (strcmp(aname + i - 4, "@sys") == 0)
1989 while ((tc = *aname++)) {
1991 return 0; /* very bad character to encounter */
1993 return 1; /* file name is ok */
1999 * This variant of symlink is expressly to support the AFS/DFS translator
2000 * and is not supported by the AFS fileserver. We just return EINVAL.
2001 * The cache manager should not generate this call to an AFS cache manager.
2004 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2005 char *LinkContents, struct AFSStoreStatus *InStatus,
2006 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2007 struct AFSFetchStatus *OutDirStatus,
2008 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2014 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2015 struct FsCmdInputs * Inputs,
2016 struct FsCmdOutputs * Outputs)
2020 switch (Inputs->command) {
2024 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2025 Inputs->command, Outputs->code));
2030 static struct afs_buffer {
2031 struct afs_buffer *next;
2032 } *freeBufferList = 0;
2033 static int afs_buffersAlloced = 0;
2036 FreeSendBuffer(struct afs_buffer *adata)
2039 afs_buffersAlloced--;
2040 adata->next = freeBufferList;
2041 freeBufferList = adata;
2045 } /*FreeSendBuffer */
2047 /* allocate space for sender */
2049 AllocSendBuffer(void)
2051 struct afs_buffer *tp;
2054 afs_buffersAlloced++;
2055 if (!freeBufferList) {
2058 tmp = malloc(sendBufSize);
2060 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2065 tp = freeBufferList;
2066 freeBufferList = tp->next;
2070 } /*AllocSendBuffer */
2071 #endif /* HAVE_PIOV */
2074 * This routine returns the status info associated with the targetptr vnode
2075 * in the AFSFetchStatus structure. Some of the newer fields, such as
2076 * SegSize and Group are not yet implemented
2080 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2081 afs_int32 anyrights, Vnode * parentptr)
2083 /* initialize return status from a vnode */
2084 status->InterfaceVersion = 1;
2085 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2086 status->errorCode = 0;
2087 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2088 if (targetptr->disk.type == vFile)
2089 status->FileType = File;
2090 else if (targetptr->disk.type == vDirectory)
2091 status->FileType = Directory;
2092 else if (targetptr->disk.type == vSymlink)
2093 status->FileType = SymbolicLink;
2095 status->FileType = Invalid; /*invalid type field */
2096 status->LinkCount = targetptr->disk.linkCount;
2098 afs_fsize_t targetLen;
2099 VN_GET_LEN(targetLen, targetptr);
2100 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2102 status->DataVersion = targetptr->disk.dataVersion;
2103 status->Author = targetptr->disk.author;
2104 status->Owner = targetptr->disk.owner;
2105 status->CallerAccess = rights;
2106 status->AnonymousAccess = anyrights;
2107 status->UnixModeBits = targetptr->disk.modeBits;
2108 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2109 status->ParentVnode =
2110 (status->FileType ==
2111 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2112 status->ParentUnique =
2113 (status->FileType ==
2114 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2115 status->ServerModTime = targetptr->disk.serverModifyTime;
2116 status->Group = targetptr->disk.group;
2117 status->lockCount = targetptr->disk.lock.lockCount;
2118 status->errorCode = 0;
2124 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2125 afs_sfsize_t Pos, afs_sfsize_t Len,
2126 struct AFSFetchStatus *OutStatus,
2127 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2130 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2131 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2132 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2133 Error errorCode = 0; /* return code to caller */
2134 Error fileCode = 0; /* return code from vol package */
2135 Volume *volptr = 0; /* pointer to the volume */
2136 struct client *client = 0; /* pointer to the client data */
2137 struct rx_connection *tcon; /* the connection we're part of */
2139 afs_int32 rights, anyrights; /* rights for this and any user */
2140 struct client *t_client = NULL; /* tmp ptr to client data */
2141 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2142 #if FS_STATS_DETAILED
2143 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2144 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2145 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2146 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2147 struct timeval elapsedTime; /* Transfer time */
2148 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2149 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2150 int readIdx; /* Index of read stats array to bump */
2151 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2154 * Set our stats pointers, remember when the RPC operation started, and
2155 * tally the operation.
2157 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2158 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2162 FT_GetTimeOfDay(&opStartTime, 0);
2163 #endif /* FS_STATS_DETAILED */
2166 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2169 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2171 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2174 /* Get ptr to client data for user Id for logging */
2175 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2176 logHostAddr.s_addr = rxr_HostOf(tcon);
2178 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2179 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2180 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2182 * Get volume/vnode for the fetched file; caller's access rights to
2183 * it are also returned
2186 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2187 &parentwhentargetnotdir, &client, READ_LOCK,
2188 &rights, &anyrights)))
2191 SetVolumeSync(Sync, volptr);
2193 #if FS_STATS_DETAILED
2195 * Remember that another read operation was performed.
2198 if (client->InSameNetwork)
2199 readIdx = VOL_STATS_SAME_NET;
2201 readIdx = VOL_STATS_DIFF_NET;
2202 V_stat_reads(volptr, readIdx)++;
2203 if (client->ViceId != AnonymousID) {
2204 V_stat_reads(volptr, readIdx + 1)++;
2207 #endif /* FS_STATS_DETAILED */
2208 /* Check whether the caller has permission access to fetch the data */
2210 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2214 * Drop the read lock on the parent directory after saving the parent
2215 * vnode information we need to pass to GetStatus
2217 if (parentwhentargetnotdir != NULL) {
2218 tparentwhentargetnotdir = *parentwhentargetnotdir;
2219 VPutVnode(&fileCode, parentwhentargetnotdir);
2220 assert(!fileCode || (fileCode == VSALVAGE));
2221 parentwhentargetnotdir = NULL;
2223 #if FS_STATS_DETAILED
2225 * Remember when the data transfer started.
2227 FT_GetTimeOfDay(&xferStartTime, 0);
2228 #endif /* FS_STATS_DETAILED */
2230 /* actually do the data transfer */
2231 #if FS_STATS_DETAILED
2233 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2234 &bytesToXfer, &bytesXferred);
2237 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2239 #endif /* FS_STATS_DETAILED */
2241 #if FS_STATS_DETAILED
2243 * At this point, the data transfer is done, for good or ill. Remember
2244 * when the transfer ended, bump the number of successes/failures, and
2245 * integrate the transfer size and elapsed time into the stats. If the
2246 * operation failed, we jump to the appropriate point.
2248 FT_GetTimeOfDay(&xferStopTime, 0);
2250 (xferP->numXfers)++;
2252 (xferP->numSuccesses)++;
2255 * Bump the xfer sum by the number of bytes actually sent, NOT the
2258 tot_bytesXferred += bytesXferred;
2259 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2260 tot_bytesXferred &= 0x3FF;
2261 if (bytesXferred < xferP->minBytes)
2262 xferP->minBytes = bytesXferred;
2263 if (bytesXferred > xferP->maxBytes)
2264 xferP->maxBytes = bytesXferred;
2267 * Tally the size of the object. Note: we tally the actual size,
2268 * NOT the number of bytes that made it out over the wire.
2270 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2271 (xferP->count[0])++;
2272 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2273 (xferP->count[1])++;
2274 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2275 (xferP->count[2])++;
2276 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2277 (xferP->count[3])++;
2278 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2279 (xferP->count[4])++;
2280 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2281 (xferP->count[5])++;
2282 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2283 (xferP->count[6])++;
2284 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2285 (xferP->count[7])++;
2287 (xferP->count[8])++;
2289 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2290 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2291 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2292 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2293 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2295 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2296 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2301 * Finally, go off to tell our caller the bad news in case the
2306 #endif /* FS_STATS_DETAILED */
2308 /* write back the OutStatus from the target vnode */
2309 GetStatus(targetptr, OutStatus, rights, anyrights,
2310 &tparentwhentargetnotdir);
2312 /* if a r/w volume, promise a callback to the caller */
2313 if (VolumeWriteable(volptr))
2314 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2316 struct AFSFid myFid;
2317 memset(&myFid, 0, sizeof(struct AFSFid));
2318 myFid.Volume = Fid->Volume;
2319 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2323 /* Update and store volume/vnode and parent vnodes back */
2324 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2326 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2327 errorCode = CallPostamble(tcon, errorCode, thost);
2329 #if FS_STATS_DETAILED
2330 FT_GetTimeOfDay(&opStopTime, 0);
2331 if (errorCode == 0) {
2333 (opP->numSuccesses)++;
2334 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2335 fs_stats_AddTo((opP->sumTime), elapsedTime);
2336 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2337 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2338 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2340 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2341 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2345 #endif /* FS_STATS_DETAILED */
2347 osi_auditU(acall, FetchDataEvent, errorCode,
2348 AUD_ID, t_client ? t_client->ViceId : 0,
2349 AUD_FID, Fid, AUD_END);
2352 } /*SRXAFS_FetchData */
2355 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2356 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2357 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2359 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2364 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2365 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2366 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2369 afs_sfsize_t tPos, tLen;
2371 tPos = (afs_sfsize_t) Pos;
2372 tLen = (afs_sfsize_t) Len;
2375 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2381 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2382 struct AFSOpaque * AccessList,
2383 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2385 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2386 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2387 Error errorCode = 0; /* return error code to caller */
2388 Volume *volptr = 0; /* pointer to the volume */
2389 struct client *client = 0; /* pointer to the client data */
2390 afs_int32 rights, anyrights; /* rights for this and any user */
2391 struct rx_connection *tcon = rx_ConnectionOf(acall);
2393 struct client *t_client = NULL; /* tmp ptr to client data */
2394 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2395 #if FS_STATS_DETAILED
2396 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2397 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2398 struct timeval elapsedTime; /* Transfer time */
2401 * Set our stats pointer, remember when the RPC operation started, and
2402 * tally the operation.
2404 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2408 FT_GetTimeOfDay(&opStartTime, 0);
2409 #endif /* FS_STATS_DETAILED */
2412 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2415 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2417 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2420 /* Get ptr to client data for user Id for logging */
2421 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2422 logHostAddr.s_addr = rxr_HostOf(tcon);
2424 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2425 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2426 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2428 AccessList->AFSOpaque_len = 0;
2429 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2430 if (!AccessList->AFSOpaque_val) {
2431 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2436 * Get volume/vnode for the fetched file; caller's access rights to it
2440 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2441 &parentwhentargetnotdir, &client, READ_LOCK,
2442 &rights, &anyrights)))
2445 SetVolumeSync(Sync, volptr);
2447 /* Check whether we have permission to fetch the ACL */
2449 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2452 /* Get the Access List from the dir's vnode */
2454 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2457 /* Get OutStatus back From the target Vnode */
2458 GetStatus(targetptr, OutStatus, rights, anyrights,
2459 parentwhentargetnotdir);
2462 /* Update and store volume/vnode and parent vnodes back */
2463 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2466 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2467 AccessList->AFSOpaque_val));
2468 errorCode = CallPostamble(tcon, errorCode, thost);
2470 #if FS_STATS_DETAILED
2471 FT_GetTimeOfDay(&opStopTime, 0);
2472 if (errorCode == 0) {
2474 (opP->numSuccesses)++;
2475 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2476 fs_stats_AddTo((opP->sumTime), elapsedTime);
2477 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2478 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2479 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2481 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2482 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2486 #endif /* FS_STATS_DETAILED */
2488 osi_auditU(acall, FetchACLEvent, errorCode,
2489 AUD_ID, t_client ? t_client->ViceId : 0,
2491 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2493 } /*SRXAFS_FetchACL */
2497 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2498 * merged into it when possible.
2502 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2503 struct AFSFetchStatus *OutStatus,
2504 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2506 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2507 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2508 Error errorCode = 0; /* return code to caller */
2509 Volume *volptr = 0; /* pointer to the volume */
2510 struct client *client = 0; /* pointer to the client data */
2511 afs_int32 rights, anyrights; /* rights for this and any user */
2512 struct client *t_client = NULL; /* tmp ptr to client data */
2513 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2514 struct rx_connection *tcon = rx_ConnectionOf(acall);
2516 /* Get ptr to client data for user Id for logging */
2517 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2518 logHostAddr.s_addr = rxr_HostOf(tcon);
2520 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2521 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2522 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2524 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2527 * Get volume/vnode for the fetched file; caller's rights to it are
2531 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2532 &parentwhentargetnotdir, &client, READ_LOCK,
2533 &rights, &anyrights)))
2534 goto Bad_FetchStatus;
2536 /* set volume synchronization information */
2537 SetVolumeSync(Sync, volptr);
2539 /* Are we allowed to fetch Fid's status? */
2540 if (targetptr->disk.type != vDirectory) {
2542 Check_PermissionRights(targetptr, client, rights,
2543 CHK_FETCHSTATUS, 0))) {
2544 if (rx_GetCallAbortCode(acall) == errorCode)
2545 rx_SetCallAbortCode(acall, 0);
2546 goto Bad_FetchStatus;
2550 /* set OutStatus From the Fid */
2551 GetStatus(targetptr, OutStatus, rights, anyrights,
2552 parentwhentargetnotdir);
2554 /* If a r/w volume, also set the CallBack state */
2555 if (VolumeWriteable(volptr))
2556 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2558 struct AFSFid myFid;
2559 memset(&myFid, 0, sizeof(struct AFSFid));
2560 myFid.Volume = Fid->Volume;
2561 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2565 /* Update and store volume/vnode and parent vnodes back */
2566 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2568 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2571 } /*SAFSS_FetchStatus */
2575 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2576 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2577 struct AFSVolSync * Sync)
2581 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2582 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2583 Error errorCode = 0; /* return code to caller */
2584 Volume *volptr = 0; /* pointer to the volume */
2585 struct client *client = 0; /* pointer to the client data */
2586 afs_int32 rights, anyrights; /* rights for this and any user */
2587 struct AFSFid *tfid; /* file id we're dealing with now */
2588 struct rx_connection *tcon = rx_ConnectionOf(acall);
2590 struct client *t_client = NULL; /* tmp pointer to the client data */
2591 #if FS_STATS_DETAILED
2592 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2593 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2594 struct timeval elapsedTime; /* Transfer time */
2597 * Set our stats pointer, remember when the RPC operation started, and
2598 * tally the operation.
2600 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2604 FT_GetTimeOfDay(&opStartTime, 0);
2605 #endif /* FS_STATS_DETAILED */
2607 ViceLog(1, ("SAFS_BulkStatus\n"));
2609 AFSCallStats.TotalCalls++;
2611 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2612 if (nfiles <= 0) { /* Sanity check */
2614 goto Audit_and_Return;
2617 /* allocate space for return output parameters */
2618 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2619 malloc(nfiles * sizeof(struct AFSFetchStatus));
2620 if (!OutStats->AFSBulkStats_val) {
2621 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2624 OutStats->AFSBulkStats_len = nfiles;
2625 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2626 malloc(nfiles * sizeof(struct AFSCallBack));
2627 if (!CallBacks->AFSCBs_val) {
2628 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2631 CallBacks->AFSCBs_len = nfiles;
2633 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2634 goto Bad_BulkStatus;
2636 tfid = Fids->AFSCBFids_val;
2637 for (i = 0; i < nfiles; i++, tfid++) {
2639 * Get volume/vnode for the fetched file; caller's rights to it
2643 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2644 &parentwhentargetnotdir, &client, READ_LOCK,
2645 &rights, &anyrights)))
2646 goto Bad_BulkStatus;
2647 /* set volume synchronization information, but only once per call */
2649 SetVolumeSync(Sync, volptr);
2651 /* Are we allowed to fetch Fid's status? */
2652 if (targetptr->disk.type != vDirectory) {
2654 Check_PermissionRights(targetptr, client, rights,
2655 CHK_FETCHSTATUS, 0))) {
2656 if (rx_GetCallAbortCode(acall) == errorCode)
2657 rx_SetCallAbortCode(acall, 0);
2658 goto Bad_BulkStatus;
2662 /* set OutStatus From the Fid */
2663 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2664 anyrights, parentwhentargetnotdir);
2666 /* If a r/w volume, also set the CallBack state */
2667 if (VolumeWriteable(volptr))
2668 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2669 &CallBacks->AFSCBs_val[i]);
2671 struct AFSFid myFid;
2672 memset(&myFid, 0, sizeof(struct AFSFid));
2673 myFid.Volume = tfid->Volume;
2674 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2675 &CallBacks->AFSCBs_val[i]);
2678 /* put back the file ID and volume */
2679 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2681 parentwhentargetnotdir = (Vnode *) 0;
2682 targetptr = (Vnode *) 0;
2683 volptr = (Volume *) 0;
2684 client = (struct client *)0;
2688 /* Update and store volume/vnode and parent vnodes back */
2689 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2691 errorCode = CallPostamble(tcon, errorCode, thost);
2693 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2695 #if FS_STATS_DETAILED
2696 FT_GetTimeOfDay(&opStopTime, 0);
2697 if (errorCode == 0) {
2699 (opP->numSuccesses)++;
2700 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2701 fs_stats_AddTo((opP->sumTime), elapsedTime);
2702 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2703 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2704 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2706 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2707 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2711 #endif /* FS_STATS_DETAILED */
2714 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2715 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2716 AUD_ID, t_client ? t_client->ViceId : 0,
2717 AUD_FIDS, Fids, AUD_END);
2720 } /*SRXAFS_BulkStatus */
2724 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2725 struct AFSBulkStats * OutStats,
2726 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2730 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2731 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2732 Error errorCode = 0; /* return code to caller */
2733 Volume *volptr = 0; /* pointer to the volume */
2734 struct client *client = 0; /* pointer to the client data */
2735 afs_int32 rights, anyrights; /* rights for this and any user */
2736 struct AFSFid *tfid; /* file id we're dealing with now */
2737 struct rx_connection *tcon;
2739 struct client *t_client = NULL; /* tmp ptr to client data */
2740 AFSFetchStatus *tstatus;
2741 int VolSync_set = 0;
2742 #if FS_STATS_DETAILED
2743 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2744 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2745 struct timeval elapsedTime; /* Transfer time */
2748 * Set our stats pointer, remember when the RPC operation started, and
2749 * tally the operation.
2751 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2755 FT_GetTimeOfDay(&opStartTime, 0);
2756 #endif /* FS_STATS_DETAILED */
2758 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2760 AFSCallStats.TotalCalls++;
2762 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2763 if (nfiles <= 0) { /* Sanity check */
2765 goto Audit_and_Return;
2768 /* allocate space for return output parameters */
2769 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2770 malloc(nfiles * sizeof(struct AFSFetchStatus));
2771 if (!OutStats->AFSBulkStats_val) {
2772 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2775 OutStats->AFSBulkStats_len = nfiles;
2776 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2777 malloc(nfiles * sizeof(struct AFSCallBack));
2778 if (!CallBacks->AFSCBs_val) {
2779 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2782 CallBacks->AFSCBs_len = nfiles;
2784 /* Zero out return values to avoid leaking information on partial succes */
2785 memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
2786 memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
2787 memset(Sync, 0, sizeof(*Sync));
2789 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2790 goto Bad_InlineBulkStatus;
2793 tfid = Fids->AFSCBFids_val;
2794 for (i = 0; i < nfiles; i++, tfid++) {
2796 * Get volume/vnode for the fetched file; caller's rights to it
2800 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2801 &parentwhentargetnotdir, &client, READ_LOCK,
2802 &rights, &anyrights))) {
2803 tstatus = &OutStats->AFSBulkStats_val[i];
2804 tstatus->errorCode = errorCode;
2805 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2807 parentwhentargetnotdir = (Vnode *) 0;
2808 targetptr = (Vnode *) 0;
2809 volptr = (Volume *) 0;
2810 client = (struct client *)0;
2814 /* set volume synchronization information, but only once per call */
2816 SetVolumeSync(Sync, volptr);
2820 /* Are we allowed to fetch Fid's status? */
2821 if (targetptr->disk.type != vDirectory) {
2823 Check_PermissionRights(targetptr, client, rights,
2824 CHK_FETCHSTATUS, 0))) {
2825 tstatus = &OutStats->AFSBulkStats_val[i];
2826 tstatus->errorCode = errorCode;
2827 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2828 (Vnode *) 0, volptr, &client);
2829 parentwhentargetnotdir = (Vnode *) 0;
2830 targetptr = (Vnode *) 0;
2831 volptr = (Volume *) 0;
2832 client = (struct client *)0;
2837 /* set OutStatus From the Fid */
2838 GetStatus(targetptr,
2839 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2840 rights, anyrights, parentwhentargetnotdir);
2842 /* If a r/w volume, also set the CallBack state */
2843 if (VolumeWriteable(volptr))
2844 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2845 &CallBacks->AFSCBs_val[i]);
2847 struct AFSFid myFid;
2848 memset(&myFid, 0, sizeof(struct AFSFid));
2849 myFid.Volume = tfid->Volume;
2850 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2851 &CallBacks->AFSCBs_val[i]);
2854 /* put back the file ID and volume */
2855 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2857 parentwhentargetnotdir = (Vnode *) 0;
2858 targetptr = (Vnode *) 0;
2859 volptr = (Volume *) 0;
2860 client = (struct client *)0;
2863 Bad_InlineBulkStatus:
2864 /* Update and store volume/vnode and parent vnodes back */
2865 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2867 errorCode = CallPostamble(tcon, errorCode, thost);
2869 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2871 #if FS_STATS_DETAILED
2872 FT_GetTimeOfDay(&opStopTime, 0);
2873 if (errorCode == 0) {
2875 (opP->numSuccesses)++;
2876 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2877 fs_stats_AddTo((opP->sumTime), elapsedTime);
2878 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2879 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2880 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2882 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2883 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2887 #endif /* FS_STATS_DETAILED */
2890 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2891 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2892 AUD_ID, t_client ? t_client->ViceId : 0,
2893 AUD_FIDS, Fids, AUD_END);
2896 } /*SRXAFS_InlineBulkStatus */
2900 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2901 struct AFSFetchStatus * OutStatus,
2902 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2905 struct rx_connection *tcon;
2907 struct client *t_client = NULL; /* tmp ptr to client data */
2908 #if FS_STATS_DETAILED
2909 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2910 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2911 struct timeval elapsedTime; /* Transfer time */
2914 * Set our stats pointer, remember when the RPC operation started, and
2915 * tally the operation.
2917 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2921 FT_GetTimeOfDay(&opStartTime, 0);
2922 #endif /* FS_STATS_DETAILED */
2924 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2925 goto Bad_FetchStatus;
2927 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2930 code = CallPostamble(tcon, code, thost);
2932 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2934 #if FS_STATS_DETAILED
2935 FT_GetTimeOfDay(&opStopTime, 0);
2938 (opP->numSuccesses)++;
2939 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2940 fs_stats_AddTo((opP->sumTime), elapsedTime);
2941 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2942 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2943 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2945 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2946 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2950 #endif /* FS_STATS_DETAILED */
2952 osi_auditU(acall, FetchStatusEvent, code,
2953 AUD_ID, t_client ? t_client->ViceId : 0,
2954 AUD_FID, Fid, AUD_END);
2957 } /*SRXAFS_FetchStatus */
2961 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2962 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2963 afs_fsize_t Length, afs_fsize_t FileLength,
2964 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2966 Vnode *targetptr = 0; /* pointer to input fid */
2967 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2968 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2969 Error errorCode = 0; /* return code for caller */
2970 Error fileCode = 0; /* return code from vol package */
2971 Volume *volptr = 0; /* pointer to the volume header */
2972 struct client *client = 0; /* pointer to client structure */
2973 afs_int32 rights, anyrights; /* rights for this and any user */
2974 struct client *t_client = NULL; /* tmp ptr to client data */
2975 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2976 struct rx_connection *tcon;
2978 #if FS_STATS_DETAILED
2979 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2980 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2981 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2982 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2983 struct timeval elapsedTime; /* Transfer time */
2984 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2985 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2986 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2989 * Set our stats pointers, remember when the RPC operation started, and
2990 * tally the operation.
2992 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2993 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
2998 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
3000 FT_GetTimeOfDay(&opStartTime, 0);
3001 #endif /* FS_STATS_DETAILED */
3004 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
3006 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3009 /* Get ptr to client data for user Id for logging */
3010 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3011 logHostAddr.s_addr = rxr_HostOf(tcon);
3013 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
3014 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3015 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3018 * Get associated volume/vnode for the stored file; caller's rights
3022 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
3023 &parentwhentargetnotdir, &client, WRITE_LOCK,
3024 &rights, &anyrights))) {
3028 /* set volume synchronization information */
3029 SetVolumeSync(Sync, volptr);
3031 if ((targetptr->disk.type == vSymlink)) {
3032 /* Should we return a better error code here??? */
3037 /* Check if we're allowed to store the data */
3039 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
3045 * Drop the read lock on the parent directory after saving the parent
3046 * vnode information we need to pass to GetStatus
3048 if (parentwhentargetnotdir != NULL) {
3049 tparentwhentargetnotdir = *parentwhentargetnotdir;
3050 VPutVnode(&fileCode, parentwhentargetnotdir);
3051 assert(!fileCode || (fileCode == VSALVAGE));
3052 parentwhentargetnotdir = NULL;
3054 #if FS_STATS_DETAILED
3056 * Remember when the data transfer started.
3058 FT_GetTimeOfDay(&xferStartTime, 0);
3059 #endif /* FS_STATS_DETAILED */
3061 /* Do the actual storing of the data */
3062 #if FS_STATS_DETAILED
3064 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3065 FileLength, (InStatus->Mask & AFS_FSYNC),
3066 &bytesToXfer, &bytesXferred);
3069 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3070 FileLength, (InStatus->Mask & AFS_FSYNC));
3071 if (errorCode && (!targetptr->changed_newTime))
3073 #endif /* FS_STATS_DETAILED */
3074 #if FS_STATS_DETAILED
3076 * At this point, the data transfer is done, for good or ill. Remember
3077 * when the transfer ended, bump the number of successes/failures, and
3078 * integrate the transfer size and elapsed time into the stats. If the
3079 * operation failed, we jump to the appropriate point.
3081 FT_GetTimeOfDay(&xferStopTime, 0);
3083 (xferP->numXfers)++;
3085 (xferP->numSuccesses)++;
3088 * Bump the xfer sum by the number of bytes actually sent, NOT the
3091 tot_bytesXferred += bytesXferred;
3092 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3093 tot_bytesXferred &= 0x3FF;
3094 if (bytesXferred < xferP->minBytes)
3095 xferP->minBytes = bytesXferred;
3096 if (bytesXferred > xferP->maxBytes)
3097 xferP->maxBytes = bytesXferred;
3100 * Tally the size of the object. Note: we tally the actual size,
3101 * NOT the number of bytes that made it out over the wire.
3103 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3104 (xferP->count[0])++;
3105 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3106 (xferP->count[1])++;
3107 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3108 (xferP->count[2])++;
3109 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3110 (xferP->count[3])++;
3111 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3112 (xferP->count[4])++;
3113 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3114 (xferP->count[5])++;
3115 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3116 (xferP->count[6])++;
3117 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3118 (xferP->count[7])++;
3120 (xferP->count[8])++;
3122 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3123 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3124 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3125 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3126 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3128 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3129 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3134 * Finally, go off to tell our caller the bad news in case the
3137 if (errorCode && (!targetptr->changed_newTime))
3139 #endif /* FS_STATS_DETAILED */
3141 /* Update the status of the target's vnode */
3142 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3143 targetptr, volptr, 0);
3145 /* Get the updated File's status back to the caller */
3146 GetStatus(targetptr, OutStatus, rights, anyrights,
3147 &tparentwhentargetnotdir);
3150 /* Update and store volume/vnode and parent vnodes back */
3151 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3153 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3155 errorCode = CallPostamble(tcon, errorCode, thost);
3157 #if FS_STATS_DETAILED
3158 FT_GetTimeOfDay(&opStopTime, 0);
3159 if (errorCode == 0) {
3161 (opP->numSuccesses)++;
3162 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3163 fs_stats_AddTo((opP->sumTime), elapsedTime);
3164 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3165 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3166 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3168 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3169 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3173 #endif /* FS_STATS_DETAILED */
3174 osi_auditU(acall, StoreDataEvent, errorCode,
3175 AUD_ID, t_client ? t_client->ViceId : 0,
3176 AUD_FID, Fid, AUD_END);
3178 } /*common_StoreData64 */
3181 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3182 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3183 afs_uint32 Length, afs_uint32 FileLength,
3184 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3186 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3187 (0x7fffffff - Pos) < Length)
3190 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3192 } /*SRXAFS_StoreData */
3195 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3196 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3197 afs_uint64 Length, afs_uint64 FileLength,
3198 struct AFSFetchStatus * OutStatus,
3199 struct AFSVolSync * Sync)
3203 afs_fsize_t tLength;
3204 afs_fsize_t tFileLength;
3206 tPos = (afs_fsize_t) Pos;
3207 tLength = (afs_fsize_t) Length;
3208 tFileLength = (afs_fsize_t) FileLength;
3211 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3217 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3218 struct AFSOpaque * AccessList,
3219 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3221 Vnode *targetptr = 0; /* pointer to input fid */
3222 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3223 Error errorCode = 0; /* return code for caller */
3224 struct AFSStoreStatus InStatus; /* Input status for fid */
3225 Volume *volptr = 0; /* pointer to the volume header */
3226 struct client *client = 0; /* pointer to client structure */
3227 afs_int32 rights, anyrights; /* rights for this and any user */
3228 struct rx_connection *tcon;
3230 struct client *t_client = NULL; /* tmp ptr to client data */
3231 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3232 #if FS_STATS_DETAILED
3233 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3234 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3235 struct timeval elapsedTime; /* Transfer time */
3238 * Set our stats pointer, remember when the RPC operation started, and
3239 * tally the operation.
3241 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3245 FT_GetTimeOfDay(&opStartTime, 0);
3246 #endif /* FS_STATS_DETAILED */
3247 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3250 /* Get ptr to client data for user Id for logging */
3251 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3252 logHostAddr.s_addr = rxr_HostOf(tcon);
3254 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3255 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3256 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3258 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3260 InStatus.Mask = 0; /* not storing any status */
3263 * Get associated volume/vnode for the target dir; caller's rights
3264 * are also returned.
3267 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3268 &parentwhentargetnotdir, &client, WRITE_LOCK,
3269 &rights, &anyrights))) {
3273 /* set volume synchronization information */
3274 SetVolumeSync(Sync, volptr);
3276 /* Check if we have permission to change the dir's ACL */
3278 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3283 /* Build and store the new Access List for the dir */
3284 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3288 targetptr->changed_newTime = 1; /* status change of directory */
3290 /* convert the write lock to a read lock before breaking callbacks */
3291 VVnodeWriteToRead(&errorCode, targetptr);
3292 assert(!errorCode || errorCode == VSALVAGE);
3294 /* break call backs on the directory */
3295 BreakCallBack(client->host, Fid, 0);
3297 /* Get the updated dir's status back to the caller */
3298 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3301 /* Update and store volume/vnode and parent vnodes back */
3302 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3304 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3305 errorCode = CallPostamble(tcon, errorCode, thost);
3307 #if FS_STATS_DETAILED
3308 FT_GetTimeOfDay(&opStopTime, 0);
3309 if (errorCode == 0) {
3311 (opP->numSuccesses)++;
3312 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3313 fs_stats_AddTo((opP->sumTime), elapsedTime);
3314 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3315 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3316 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3318 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3319 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3323 #endif /* FS_STATS_DETAILED */
3325 osi_auditU(acall, StoreACLEvent, errorCode,
3326 AUD_ID, t_client ? t_client->ViceId : 0,
3327 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3330 } /*SRXAFS_StoreACL */
3334 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3335 * should be merged when possible.
3338 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3339 struct AFSStoreStatus *InStatus,
3340 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3342 Vnode *targetptr = 0; /* pointer to input fid */
3343 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3344 Error errorCode = 0; /* return code for caller */
3345 Volume *volptr = 0; /* pointer to the volume header */
3346 struct client *client = 0; /* pointer to client structure */
3347 afs_int32 rights, anyrights; /* rights for this and any user */
3348 struct client *t_client = NULL; /* tmp ptr to client data */
3349 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3350 struct rx_connection *tcon = rx_ConnectionOf(acall);
3352 /* Get ptr to client data for user Id for logging */
3353 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3354 logHostAddr.s_addr = rxr_HostOf(tcon);
3356 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3357 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3358 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3360 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3363 * Get volume/vnode for the target file; caller's rights to it are
3367 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3368 &parentwhentargetnotdir, &client, WRITE_LOCK,
3369 &rights, &anyrights))) {
3370 goto Bad_StoreStatus;
3373 /* set volume synchronization information */
3374 SetVolumeSync(Sync, volptr);
3376 /* Check if the caller has proper permissions to store status to Fid */
3378 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3380 goto Bad_StoreStatus;
3383 * Check for a symbolic link; we can't chmod these (otherwise could
3384 * change a symlink to a mt pt or vice versa)
3386 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3388 goto Bad_StoreStatus;
3391 /* Update the status of the target's vnode */
3392 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3393 (parentwhentargetnotdir ? parentwhentargetnotdir
3394 : targetptr), volptr, 0);
3396 /* convert the write lock to a read lock before breaking callbacks */
3397 VVnodeWriteToRead(&errorCode, targetptr);
3398 assert(!errorCode || errorCode == VSALVAGE);
3400 /* Break call backs on Fid */
3401 BreakCallBack(client->host, Fid, 0);
3403 /* Return the updated status back to caller */
3404 GetStatus(targetptr, OutStatus, rights, anyrights,
3405 parentwhentargetnotdir);
3408 /* Update and store volume/vnode and parent vnodes back */
3409 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3411 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3414 } /*SAFSS_StoreStatus */
3418 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3419 struct AFSStoreStatus * InStatus,
3420 struct AFSFetchStatus * OutStatus,
3421 struct AFSVolSync * Sync)
3424 struct rx_connection *tcon;
3426 struct client *t_client = NULL; /* tmp ptr to client data */
3427 #if FS_STATS_DETAILED
3428 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3429 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3430 struct timeval elapsedTime; /* Transfer time */
3433 * Set our stats pointer, remember when the RPC operation started, and
3434 * tally the operation.
3436 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3440 FT_GetTimeOfDay(&opStartTime, 0);
3441 #endif /* FS_STATS_DETAILED */
3443 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3444 goto Bad_StoreStatus;
3446 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3449 code = CallPostamble(tcon, code, thost);
3451 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3453 #if FS_STATS_DETAILED
3454 FT_GetTimeOfDay(&opStopTime, 0);
3457 (opP->numSuccesses)++;
3458 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3459 fs_stats_AddTo((opP->sumTime), elapsedTime);
3460 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3461 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3462 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3464 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3465 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3469 #endif /* FS_STATS_DETAILED */
3471 osi_auditU(acall, StoreStatusEvent, code,
3472 AUD_ID, t_client ? t_client->ViceId : 0,
3473 AUD_FID, Fid, AUD_END);
3476 } /*SRXAFS_StoreStatus */
3480 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3481 * merged in when possible.
3484 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3485 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3487 Vnode *parentptr = 0; /* vnode of input Directory */
3488 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3489 Vnode *targetptr = 0; /* file to be deleted */
3490 Volume *volptr = 0; /* pointer to the volume header */
3491 AFSFid fileFid; /* area for Fid from the directory */
3492 Error errorCode = 0; /* error code */
3493 DirHandle dir; /* Handle for dir package I/O */
3494 struct client *client = 0; /* pointer to client structure */
3495 afs_int32 rights, anyrights; /* rights for this and any user */
3496 struct client *t_client; /* tmp ptr to client data */
3497 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3498 struct rx_connection *tcon = rx_ConnectionOf(acall);
3501 /* Get ptr to client data for user Id for logging */
3502 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3503 logHostAddr.s_addr = rxr_HostOf(tcon);
3505 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3506 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3507 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3509 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3512 * Get volume/vnode for the parent dir; caller's access rights are
3516 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3517 &parentwhentargetnotdir, &client, WRITE_LOCK,
3518 &rights, &anyrights))) {
3519 goto Bad_RemoveFile;
3521 /* set volume synchronization information */
3522 SetVolumeSync(Sync, volptr);
3524 /* Does the caller has delete (& write) access to the parent directory? */
3525 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3526 goto Bad_RemoveFile;
3529 /* Actually delete the desired file */
3531 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3533 goto Bad_RemoveFile;
3536 /* Update the vnode status of the parent dir */
3537 #if FS_STATS_DETAILED
3538 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3539 parentptr->disk.linkCount,
3540 client->InSameNetwork);
3542 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3543 parentptr->disk.linkCount);
3544 #endif /* FS_STATS_DETAILED */
3546 /* Return the updated parent dir's status back to caller */
3547 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3549 /* Handle internal callback state for the parent and the deleted file */
3550 if (targetptr->disk.linkCount == 0) {
3551 /* no references left, discard entry */
3552 DeleteFileCallBacks(&fileFid);
3553 /* convert the parent lock to a read lock before breaking callbacks */
3554 VVnodeWriteToRead(&errorCode, parentptr);
3555 assert(!errorCode || errorCode == VSALVAGE);
3557 /* convert the parent lock to a read lock before breaking callbacks */
3558 VVnodeWriteToRead(&errorCode, parentptr);
3559 assert(!errorCode || errorCode == VSALVAGE);
3560 /* convert the target lock to a read lock before breaking callbacks */
3561 VVnodeWriteToRead(&errorCode, targetptr);
3562 assert(!errorCode || errorCode == VSALVAGE);
3563 /* tell all the file has changed */
3564 BreakCallBack(client->host, &fileFid, 1);
3567 /* break call back on the directory */
3568 BreakCallBack(client->host, DirFid, 0);
3571 /* Update and store volume/vnode and parent vnodes back */
3572 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3575 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3578 } /*SAFSS_RemoveFile */
3582 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3583 struct AFSFetchStatus * OutDirStatus,
3584 struct AFSVolSync * Sync)
3587 struct rx_connection *tcon;
3589 struct client *t_client = NULL; /* tmp ptr to client data */
3590 #if FS_STATS_DETAILED
3591 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3592 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3593 struct timeval elapsedTime; /* Transfer time */
3596 * Set our stats pointer, remember when the RPC operation started, and
3597 * tally the operation.
3599 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3603 FT_GetTimeOfDay(&opStartTime, 0);
3604 #endif /* FS_STATS_DETAILED */
3606 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3607 goto Bad_RemoveFile;
3609 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3612 code = CallPostamble(tcon, code, thost);
3614 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3616 #if FS_STATS_DETAILED
3617 FT_GetTimeOfDay(&opStopTime, 0);
3620 (opP->numSuccesses)++;
3621 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3622 fs_stats_AddTo((opP->sumTime), elapsedTime);
3623 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3624 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3625 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3627 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3628 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3632 #endif /* FS_STATS_DETAILED */
3634 osi_auditU(acall, RemoveFileEvent, code,
3635 AUD_ID, t_client ? t_client->ViceId : 0,
3636 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3639 } /*SRXAFS_RemoveFile */
3643 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3644 * be merged in when possible.
3647 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3648 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3649 struct AFSFetchStatus *OutFidStatus,
3650 struct AFSFetchStatus *OutDirStatus,
3651 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3653 Vnode *parentptr = 0; /* vnode of input Directory */
3654 Vnode *targetptr = 0; /* vnode of the new file */
3655 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3656 Volume *volptr = 0; /* pointer to the volume header */
3657 Error errorCode = 0; /* error code */
3658 DirHandle dir; /* Handle for dir package I/O */
3659 struct client *client = 0; /* pointer to client structure */
3660 afs_int32 rights, anyrights; /* rights for this and any user */
3661 struct client *t_client; /* tmp ptr to client data */
3662 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3663 struct rx_connection *tcon = rx_ConnectionOf(acall);
3667 /* Get ptr to client data for user Id for logging */
3668 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3669 logHostAddr.s_addr = rxr_HostOf(tcon);
3671 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3672 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3673 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3675 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3677 if (!FileNameOK(Name)) {
3679 goto Bad_CreateFile;
3683 * Get associated volume/vnode for the parent dir; caller long are
3687 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3688 &parentwhentargetnotdir, &client, WRITE_LOCK,
3689 &rights, &anyrights))) {
3690 goto Bad_CreateFile;
3693 /* set volume synchronization information */
3694 SetVolumeSync(Sync, volptr);
3696 /* Can we write (and insert) onto the parent directory? */
3697 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3698 goto Bad_CreateFile;
3700 /* get a new vnode for the file to be created and set it up */
3702 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3703 vFile, nBlocks(0)))) {
3704 goto Bad_CreateFile;
3707 /* update the status of the parent vnode */
3708 #if FS_STATS_DETAILED
3709 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3710 parentptr->disk.linkCount,
3711 client->InSameNetwork);
3713 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3714 parentptr->disk.linkCount);
3715 #endif /* FS_STATS_DETAILED */
3717 /* update the status of the new file's vnode */
3718 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3719 parentptr, volptr, 0);
3721 /* 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 */
3722 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3723 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3725 /* convert the write lock to a read lock before breaking callbacks */
3726 VVnodeWriteToRead(&errorCode, parentptr);
3727 assert(!errorCode || errorCode == VSALVAGE);
3729 /* break call back on parent dir */
3730 BreakCallBack(client->host, DirFid, 0);
3732 /* Return a callback promise for the newly created file to the caller */
3733 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3736 /* Update and store volume/vnode and parent vnodes back */
3737 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3740 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3743 } /*SAFSS_CreateFile */
3747 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3748 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3749 struct AFSFetchStatus * OutFidStatus,
3750 struct AFSFetchStatus * OutDirStatus,
3751 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3754 struct rx_connection *tcon;
3756 struct client *t_client = NULL; /* tmp ptr to client data */
3757 #if FS_STATS_DETAILED
3758 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3759 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3760 struct timeval elapsedTime; /* Transfer time */
3763 * Set our stats pointer, remember when the RPC operation started, and
3764 * tally the operation.
3766 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3770 FT_GetTimeOfDay(&opStartTime, 0);
3771 #endif /* FS_STATS_DETAILED */
3773 memset(OutFid, 0, sizeof(struct AFSFid));
3775 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3776 goto Bad_CreateFile;
3779 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3780 OutDirStatus, CallBack, Sync);
3783 code = CallPostamble(tcon, code, thost);
3785 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3787 #if FS_STATS_DETAILED
3788 FT_GetTimeOfDay(&opStopTime, 0);
3791 (opP->numSuccesses)++;
3792 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3793 fs_stats_AddTo((opP->sumTime), elapsedTime);
3794 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3795 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3796 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3798 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3799 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3803 #endif /* FS_STATS_DETAILED */
3805 osi_auditU(acall, CreateFileEvent, code,
3806 AUD_ID, t_client ? t_client->ViceId : 0,
3807 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3810 } /*SRXAFS_CreateFile */
3814 * This routine is called exclusively from SRXAFS_Rename(), and should be
3815 * merged in when possible.
3818 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3819 struct AFSFid *NewDirFid, char *NewName,
3820 struct AFSFetchStatus *OutOldDirStatus,
3821 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3823 Vnode *oldvptr = 0; /* vnode of the old Directory */
3824 Vnode *newvptr = 0; /* vnode of the new Directory */
3825 Vnode *fileptr = 0; /* vnode of the file to move */
3826 Vnode *newfileptr = 0; /* vnode of the file to delete */
3827 Vnode *testvptr = 0; /* used in directory tree walk */
3828 Vnode *parent = 0; /* parent for use in SetAccessList */
3829 Error errorCode = 0; /* error code */
3830 Error fileCode = 0; /* used when writing Vnodes */
3831 VnodeId testnode; /* used in directory tree walk */
3832 AFSFid fileFid; /* Fid of file to move */
3833 AFSFid newFileFid; /* Fid of new file */
3834 DirHandle olddir; /* Handle for dir package I/O */
3835 DirHandle newdir; /* Handle for dir package I/O */
3836 DirHandle filedir; /* Handle for dir package I/O */
3837 DirHandle newfiledir; /* Handle for dir package I/O */
3838 Volume *volptr = 0; /* pointer to the volume header */
3839 struct client *client = 0; /* pointer to client structure */
3840 afs_int32 rights, anyrights; /* rights for this and any user */
3841 afs_int32 newrights; /* rights for this user */
3842 afs_int32 newanyrights; /* rights for any user */
3843 int doDelete; /* deleted the rename target (ref count now 0) */
3845 int updatefile = 0; /* are we changing the renamed file? (we do this
3846 * if we need to update .. on a renamed dir) */
3847 struct client *t_client; /* tmp ptr to client data */
3848 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3849 struct rx_connection *tcon = rx_ConnectionOf(acall);
3855 FidZero(&newfiledir);
3857 /* Get ptr to client data for user Id for logging */
3858 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3859 logHostAddr.s_addr = rxr_HostOf(tcon);
3861 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3862 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3863 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3864 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3866 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3868 if (!FileNameOK(NewName)) {
3872 if (OldDirFid->Volume != NewDirFid->Volume) {
3877 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3878 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3879 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3885 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3887 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3888 &parent, &client, WRITE_LOCK, &rights,
3893 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3895 newrights = rights, newanyrights = anyrights;
3898 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3899 MustBeDIR, &parent, &client, WRITE_LOCK,
3900 &newrights, &newanyrights))) {
3906 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3907 &parent, &client, WRITE_LOCK, &newrights,
3913 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3914 &parent, &client, WRITE_LOCK, &rights,
3921 /* set volume synchronization information */
3922 SetVolumeSync(Sync, volptr);
3924 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3927 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3931 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3932 * call to CopyOnWrite returns error, it is not necessary to revert back
3933 * the effects of the first call because the contents of the volume is
3934 * not modified, it is only replicated.
3936 if (oldvptr->disk.cloned) {
3937 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3938 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
3941 SetDirHandle(&olddir, oldvptr);
3942 if (newvptr->disk.cloned) {
3943 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3944 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
3948 SetDirHandle(&newdir, newvptr);
3950 /* Lookup the file to delete its vnode */
3951 if (Lookup(&olddir, OldName, &fileFid)) {
3955 if (fileFid.Vnode == oldvptr->vnodeNumber
3956 || fileFid.Vnode == newvptr->vnodeNumber) {
3957 errorCode = FSERR_ELOOP;
3960 fileFid.Volume = V_id(volptr);
3961 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3962 if (errorCode != 0) {
3964 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3965 OldName, errorCode));
3966 VTakeOffline(volptr);
3969 if (fileptr->disk.uniquifier != fileFid.Unique) {
3971 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3973 VTakeOffline(volptr);
3978 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3979 && fileptr->disk.linkCount != 1) {
3981 * Hard links exist to this file - cannot move one of the links to
3982 * a new directory because of AFS restrictions (this is the same
3983 * reason that links cannot be made across directories, i.e.
3990 /* Lookup the new file */
3991 if (!(Lookup(&newdir, NewName, &newFileFid))) {
3992 if (readonlyServer) {
3993 errorCode = VREADONLY;
3996 if (!(newrights & PRSFS_DELETE)) {
4000 if (newFileFid.Vnode == oldvptr->vnodeNumber
4001 || newFileFid.Vnode == newvptr->vnodeNumber
4002 || newFileFid.Vnode == fileFid.Vnode) {
4006 newFileFid.Volume = V_id(volptr);
4008 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
4009 if (errorCode != 0) {
4011 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
4012 NewName, errorCode));
4013 VTakeOffline(volptr);
4016 if (fileptr->disk.uniquifier != fileFid.Unique) {
4018 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
4020 VTakeOffline(volptr);
4024 SetDirHandle(&newfiledir, newfileptr);
4025 /* Now check that we're moving directories over directories properly, etc.
4026 * return proper POSIX error codes:
4027 * if fileptr is a file and new is a dir: EISDIR.
4028 * if fileptr is a dir and new is a file: ENOTDIR.
4029 * Also, dir to be removed must be empty, of course.
4031 if (newfileptr->disk.type == vDirectory) {
4032 if (fileptr->disk.type != vDirectory) {
4036 if ((IsEmpty(&newfiledir))) {
4041 if (fileptr->disk.type == vDirectory) {
4042 errorCode = ENOTDIR;
4049 * ok - now we check that the old name is not above new name in the
4050 * directory structure. This is to prevent removing a subtree alltogether
4052 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
4053 afs_int32 forpass = 0, vnum = 0, top = 0;
4054 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
4055 if (testnode > vnum) vnum = testnode;
4056 if (forpass > vnum) {
4057 errorCode = FSERR_ELOOP;
4060 if (testnode == oldvptr->vnodeNumber) {
4061 testnode = oldvptr->disk.parent;
4064 if ((testnode == fileptr->vnodeNumber)
4065 || (testnode == newvptr->vnodeNumber)) {
4066 errorCode = FSERR_ELOOP;
4069 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
4070 errorCode = FSERR_ELOOP;
4073 if (testnode == 1) top = 1;
4074 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
4075 assert(errorCode == 0);
4076 testnode = testvptr->disk.parent;
4077 VPutVnode(&errorCode, testvptr);
4078 if ((top == 1) && (testnode != 0)) {
4079 VTakeOffline(volptr);
4081 ("Volume %u now offline, must be salvaged.\n",
4086 assert(errorCode == 0);
4090 if (fileptr->disk.type == vDirectory) {
4091 SetDirHandle(&filedir, fileptr);
4092 if (oldvptr != newvptr) {
4093 /* we always need to update .. if we've moving fileptr to a
4094 * different directory */
4097 struct AFSFid unused;
4099 code = Lookup(&filedir, "..", &unused);
4100 if (code == ENOENT) {
4101 /* only update .. if it doesn't already exist */
4107 /* Do the CopyonWrite first before modifying anything else. Copying is
4108 * required when we have to change entries for ..
4110 if (updatefile && (fileptr->disk.cloned)) {
4111 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
4112 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
4116 /* If the new name exists already, delete it and the file it points to */
4119 /* Delete NewName from its directory */
4120 code = Delete(&newdir, NewName);
4123 /* Drop the link count */
4124 newfileptr->disk.linkCount--;
4125 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4126 afs_fsize_t newSize;
4127 VN_GET_LEN(newSize, newfileptr);
4128 VAdjustDiskUsage((Error *) & errorCode, volptr,
4129 (afs_sfsize_t) - nBlocks(newSize), 0);
4130 if (VN_GET_INO(newfileptr)) {
4131 IH_REALLYCLOSE(newfileptr->handle);
4133 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
4134 V_parentId(volptr));
4135 IH_RELEASE(newfileptr->handle);
4136 if (errorCode == -1) {
4138 ("Del: inode=%s, name=%s, errno=%d\n",
4139 PrintInode(stmp, VN_GET_INO(newfileptr)),
4141 if ((errno != ENOENT) && (errno != EIO)
4142 && (errno != ENXIO))
4143 ViceLog(0, ("Do we need to fsck?"));
4146 VN_SET_INO(newfileptr, (Inode) 0);
4147 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4150 /* Link count did not drop to zero.
4151 * Mark NewName vnode as changed - updates stime.
4153 newfileptr->changed_newTime = 1;
4158 * If the create below fails, and the delete above worked, we have
4159 * removed the new name and not replaced it. This is not very likely,
4160 * but possible. We could try to put the old file back, but it is
4161 * highly unlikely that it would work since it would involve issuing
4164 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4167 /* Delete the old name */
4168 assert(Delete(&olddir, (char *)OldName) == 0);
4170 /* if the directory length changes, reflect it in the statistics */
4171 #if FS_STATS_DETAILED
4172 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4173 oldvptr->disk.linkCount, client->InSameNetwork);
4174 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4175 newvptr->disk.linkCount, client->InSameNetwork);
4177 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4178 oldvptr->disk.linkCount);
4179 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4180 newvptr->disk.linkCount);
4181 #endif /* FS_STATS_DETAILED */
4183 if (oldvptr == newvptr)
4184 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4186 if (fileptr->disk.parent != newvptr->vnodeNumber) {
4187 fileptr->disk.parent = newvptr->vnodeNumber;
4188 fileptr->changed_newTime = 1;
4191 /* if we are dealing with a rename of a directory, and we need to
4192 * update the .. entry of that directory */
4194 assert(!fileptr->disk.cloned);
4196 fileptr->changed_newTime = 1; /* status change of moved file */
4198 /* fix .. to point to the correct place */
4199 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4200 assert(Create(&filedir, "..", NewDirFid) == 0);
4201 fileptr->disk.dataVersion++;
4203 /* if the parent directories are different the link counts have to be */
4204 /* changed due to .. in the renamed directory */
4205 if (oldvptr != newvptr) {
4206 oldvptr->disk.linkCount--;
4207 newvptr->disk.linkCount++;
4211 /* set up return status */
4212 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4213 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4214 if (newfileptr && doDelete) {
4215 DeleteFileCallBacks(&newFileFid); /* no other references */
4220 /* convert the write locks to a read locks before breaking callbacks */
4221 VVnodeWriteToRead(&errorCode, newvptr);
4222 assert(!errorCode || errorCode == VSALVAGE);
4223 if (oldvptr != newvptr) {
4224 VVnodeWriteToRead(&errorCode, oldvptr);
4225 assert(!errorCode || errorCode == VSALVAGE);
4227 if (newfileptr && !doDelete) {
4228 /* convert the write lock to a read lock before breaking callbacks */
4229 VVnodeWriteToRead(&errorCode, newfileptr);
4230 assert(!errorCode || errorCode == VSALVAGE);
4233 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4234 BreakCallBack(client->host, NewDirFid, 0);
4235 if (oldvptr != newvptr) {
4236 BreakCallBack(client->host, OldDirFid, 0);
4239 /* if a dir moved, .. changed */
4240 /* we do not give an AFSFetchStatus structure back to the
4241 * originating client, and the file's status has changed, so be
4242 * sure to send a callback break. In theory the client knows
4243 * enough to know that the callback could be broken implicitly,
4244 * but that may not be clear, and some client implementations
4245 * may not know to. */
4246 BreakCallBack(client->host, &fileFid, 1);
4249 /* Note: it is not necessary to break the callback */
4251 DeleteFileCallBacks(&newFileFid); /* no other references */
4253 /* other's still exist (with wrong link count) */
4254 BreakCallBack(client->host, &newFileFid, 1);
4259 VPutVnode(&fileCode, newfileptr);
4260 assert(fileCode == 0);
4262 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
4263 newvptr : 0), oldvptr, volptr, &client);
4267 FidZap(&newfiledir);
4268 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4275 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4276 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4277 struct AFSFetchStatus * OutOldDirStatus,
4278 struct AFSFetchStatus * OutNewDirStatus,
4279 struct AFSVolSync * Sync)
4282 struct rx_connection *tcon;
4284 struct client *t_client = NULL; /* tmp ptr to client data */
4285 #if FS_STATS_DETAILED
4286 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4287 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4288 struct timeval elapsedTime; /* Transfer time */
4291 * Set our stats pointer, remember when the RPC operation started, and
4292 * tally the operation.
4294 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4298 FT_GetTimeOfDay(&opStartTime, 0);
4299 #endif /* FS_STATS_DETAILED */
4301 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4305 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4306 OutOldDirStatus, OutNewDirStatus, Sync);
4309 code = CallPostamble(tcon, code, thost);
4311 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4313 #if FS_STATS_DETAILED
4314 FT_GetTimeOfDay(&opStopTime, 0);
4317 (opP->numSuccesses)++;
4318 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4319 fs_stats_AddTo((opP->sumTime), elapsedTime);
4320 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4321 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4322 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4324 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4325 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4329 #endif /* FS_STATS_DETAILED */
4331 osi_auditU(acall, RenameFileEvent, code,
4332 AUD_ID, t_client ? t_client->ViceId : 0,
4333 AUD_FID, OldDirFid, AUD_STR, OldName,
4334 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4337 } /*SRXAFS_Rename */
4341 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4342 * merged into it when possible.
4345 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4346 char *LinkContents, struct AFSStoreStatus *InStatus,
4347 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4348 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4350 Vnode *parentptr = 0; /* vnode of input Directory */
4351 Vnode *targetptr = 0; /* vnode of the new link */
4352 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4353 Error errorCode = 0; /* error code */
4356 DirHandle dir; /* Handle for dir package I/O */
4357 Volume *volptr = 0; /* pointer to the volume header */
4358 struct client *client = 0; /* pointer to client structure */
4359 afs_int32 rights, anyrights; /* rights for this and any user */
4360 struct client *t_client; /* tmp ptr to client data */
4361 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4363 struct rx_connection *tcon = rx_ConnectionOf(acall);
4367 /* Get ptr to client data for user Id for logging */
4368 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4369 logHostAddr.s_addr = rxr_HostOf(tcon);
4371 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4372 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4373 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4375 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4377 if (!FileNameOK(Name)) {
4383 * Get the vnode and volume for the parent dir along with the caller's
4387 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4388 &parentwhentargetnotdir, &client, WRITE_LOCK,
4389 &rights, &anyrights))) {
4393 /* set volume synchronization information */
4394 SetVolumeSync(Sync, volptr);
4396 /* Does the caller has insert (and write) access to the parent directory? */
4397 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4402 * If we're creating a mount point (any x bits clear), we must have
4403 * administer access to the directory, too. Always allow sysadmins
4406 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4407 if (readonlyServer) {
4408 errorCode = VREADONLY;
4412 * We have a mountpoint, 'cause we're trying to set the Unix mode
4413 * bits to something with some x bits missing (default mode bits
4414 * if AFS_SETMODE is false is 0777)
4416 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4422 /* get a new vnode for the symlink and set it up */
4424 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4425 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4429 /* update the status of the parent vnode */
4430 #if FS_STATS_DETAILED
4431 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4432 parentptr->disk.linkCount,
4433 client->InSameNetwork);
4435 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4436 parentptr->disk.linkCount);
4437 #endif /* FS_STATS_DETAILED */
4439 /* update the status of the new symbolic link file vnode */
4440 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4441 parentptr, volptr, strlen((char *)LinkContents));
4443 /* Write the contents of the symbolic link name into the target inode */
4444 fdP = IH_OPEN(targetptr->handle);
4446 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4448 VTakeOffline(volptr);
4449 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
4453 len = strlen((char *) LinkContents);
4454 code = (len == FDH_PWRITE(fdP, (char *) LinkContents, len, 0)) ? 0 : VDISKFULL;
4456 ViceLog(0, ("SAFSS_Symlink FDH_PWRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4459 * Set up and return modified status for the parent dir and new symlink
4462 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4463 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4465 /* convert the write lock to a read lock before breaking callbacks */
4466 VVnodeWriteToRead(&errorCode, parentptr);
4467 assert(!errorCode || errorCode == VSALVAGE);
4469 /* break call back on the parent dir */
4470 BreakCallBack(client->host, DirFid, 0);
4473 /* Write the all modified vnodes (parent, new files) and volume back */
4474 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4477 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4478 return ( errorCode ? errorCode : code );
4480 } /*SAFSS_Symlink */
4484 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4485 struct AFSFid *DirFid, /* Parent dir's fid */
4486 char *Name, /* File name to create */
4487 char *LinkContents, /* Contents of the new created file */
4488 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4489 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4490 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4491 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4492 struct AFSVolSync *Sync)
4495 struct rx_connection *tcon;
4497 struct client *t_client = NULL; /* tmp ptr to client data */
4498 #if FS_STATS_DETAILED
4499 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4500 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4501 struct timeval elapsedTime; /* Transfer time */
4504 * Set our stats pointer, remember when the RPC operation started, and
4505 * tally the operation.
4507 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4511 FT_GetTimeOfDay(&opStartTime, 0);
4512 #endif /* FS_STATS_DETAILED */
4514 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4518 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4519 OutFidStatus, OutDirStatus, Sync);
4522 code = CallPostamble(tcon, code, thost);
4524 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4526 #if FS_STATS_DETAILED
4527 FT_GetTimeOfDay(&opStopTime, 0);
4530 (opP->numSuccesses)++;
4531 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4532 fs_stats_AddTo((opP->sumTime), elapsedTime);
4533 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4534 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4535 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4537 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4538 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4542 #endif /* FS_STATS_DETAILED */
4544 osi_auditU(acall, SymlinkEvent, code,
4545 AUD_ID, t_client ? t_client->ViceId : 0,
4546 AUD_FID, DirFid, AUD_STR, Name,
4547 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4550 } /*SRXAFS_Symlink */
4554 * This routine is called exclusively by SRXAFS_Link(), and should be
4555 * merged into it when possible.
4558 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4559 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4560 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4562 Vnode *parentptr = 0; /* vnode of input Directory */
4563 Vnode *targetptr = 0; /* vnode of the new file */
4564 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4565 Volume *volptr = 0; /* pointer to the volume header */
4566 Error errorCode = 0; /* error code */
4567 DirHandle dir; /* Handle for dir package I/O */
4568 struct client *client = 0; /* pointer to client structure */
4569 afs_int32 rights, anyrights; /* rights for this and any user */
4570 struct client *t_client; /* tmp ptr to client data */
4571 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4572 struct rx_connection *tcon = rx_ConnectionOf(acall);
4576 /* Get ptr to client data for user Id for logging */
4577 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4578 logHostAddr.s_addr = rxr_HostOf(tcon);
4580 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4581 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4582 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4583 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4585 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4587 if (DirFid->Volume != ExistingFid->Volume) {
4591 if (!FileNameOK(Name)) {
4597 * Get the vnode and volume for the parent dir along with the caller's
4601 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4602 &parentwhentargetnotdir, &client, WRITE_LOCK,
4603 &rights, &anyrights))) {
4607 /* set volume synchronization information */
4608 SetVolumeSync(Sync, volptr);
4610 /* Can the caller insert into the parent directory? */
4611 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4615 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4616 /* AFS fileservers always have directory vnodes that are odd. */
4621 /* get the file vnode */
4623 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4626 if (targetptr->disk.type != vFile) {
4630 if (targetptr->disk.parent != DirFid->Vnode) {
4634 if (parentptr->disk.cloned) {
4635 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4636 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4637 goto Bad_Link; /* disk full error */
4640 /* add the name to the directory */
4641 SetDirHandle(&dir, parentptr);
4642 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4646 /* update the status in the parent vnode */
4647 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4648 #if FS_STATS_DETAILED
4649 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4650 parentptr->disk.linkCount,
4651 client->InSameNetwork);
4653 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4654 parentptr->disk.linkCount);
4655 #endif /* FS_STATS_DETAILED */
4657 targetptr->disk.linkCount++;
4658 targetptr->disk.author = client->ViceId;
4659 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4661 /* set up return status */
4662 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4663 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4665 /* convert the write locks to read locks before breaking callbacks */
4666 VVnodeWriteToRead(&errorCode, targetptr);
4667 assert(!errorCode || errorCode == VSALVAGE);
4668 VVnodeWriteToRead(&errorCode, parentptr);
4669 assert(!errorCode || errorCode == VSALVAGE);
4671 /* break call back on DirFid */
4672 BreakCallBack(client->host, DirFid, 0);
4674 * We also need to break the callback for the file that is hard-linked since part
4675 * of its status (like linkcount) is changed
4677 BreakCallBack(client->host, ExistingFid, 0);
4680 /* Write the all modified vnodes (parent, new files) and volume back */
4681 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4684 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4691 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4692 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4693 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4696 struct rx_connection *tcon;
4698 struct client *t_client = NULL; /* tmp ptr to client data */
4699 #if FS_STATS_DETAILED
4700 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4701 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4702 struct timeval elapsedTime; /* Transfer time */
4705 * Set our stats pointer, remember when the RPC operation started, and
4706 * tally the operation.
4708 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4712 FT_GetTimeOfDay(&opStartTime, 0);
4713 #endif /* FS_STATS_DETAILED */
4715 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4719 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4720 OutDirStatus, Sync);
4723 code = CallPostamble(tcon, code, thost);
4725 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4727 #if FS_STATS_DETAILED
4728 FT_GetTimeOfDay(&opStopTime, 0);
4731 (opP->numSuccesses)++;
4732 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4733 fs_stats_AddTo((opP->sumTime), elapsedTime);
4734 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4735 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4736 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4738 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4739 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4743 #endif /* FS_STATS_DETAILED */
4745 osi_auditU(acall, LinkEvent, code,
4746 AUD_ID, t_client ? t_client->ViceId : 0,
4747 AUD_FID, DirFid, AUD_STR, Name,
4748 AUD_FID, ExistingFid, AUD_END);
4755 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4756 * merged into it when possible.
4759 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4760 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4761 struct AFSFetchStatus *OutFidStatus,
4762 struct AFSFetchStatus *OutDirStatus,
4763 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4765 Vnode *parentptr = 0; /* vnode of input Directory */
4766 Vnode *targetptr = 0; /* vnode of the new file */
4767 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4768 Volume *volptr = 0; /* pointer to the volume header */
4769 Error errorCode = 0; /* error code */
4770 struct acl_accessList *newACL; /* Access list */
4771 int newACLSize; /* Size of access list */
4772 DirHandle dir; /* Handle for dir package I/O */
4773 DirHandle parentdir; /* Handle for dir package I/O */
4774 struct client *client = 0; /* pointer to client structure */
4775 afs_int32 rights, anyrights; /* rights for this and any user */
4776 struct client *t_client; /* tmp ptr to client data */
4777 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4778 struct rx_connection *tcon = rx_ConnectionOf(acall);
4781 FidZero(&parentdir);
4783 /* Get ptr to client data for user Id for logging */
4784 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4785 logHostAddr.s_addr = rxr_HostOf(tcon);
4787 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4788 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4789 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4791 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4793 if (!FileNameOK(Name)) {
4799 * Get the vnode and volume for the parent dir along with the caller's
4803 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4804 &parentwhentargetnotdir, &client, WRITE_LOCK,
4805 &rights, &anyrights))) {
4809 /* set volume synchronization information */
4810 SetVolumeSync(Sync, volptr);
4812 /* Write access to the parent directory? */
4813 #ifdef DIRCREATE_NEED_WRITE
4815 * requires w access for the user to create a directory. this
4816 * closes a loophole in the current security arrangement, since a
4817 * user with i access only can create a directory and get the
4818 * implcit a access that goes with dir ownership, and proceed to
4819 * subvert quota in the volume.
4821 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4822 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4824 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4825 #endif /* DIRCREATE_NEED_WRITE */
4828 #define EMPTYDIRBLOCKS 2
4829 /* get a new vnode and set it up */
4831 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4832 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4836 /* Update the status for the parent dir */
4837 #if FS_STATS_DETAILED
4838 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4839 parentptr->disk.linkCount + 1,
4840 client->InSameNetwork);
4842 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4843 parentptr->disk.linkCount + 1);
4844 #endif /* FS_STATS_DETAILED */
4846 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4847 assert((SetAccessList
4848 (&targetptr, &volptr, &newACL, &newACLSize,
4849 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4850 assert(parentwhentargetnotdir == 0);
4851 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4853 /* update the status for the target vnode */
4854 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4855 parentptr, volptr, 0);
4857 /* Actually create the New directory in the directory package */
4858 SetDirHandle(&dir, targetptr);
4859 assert(!(MakeDir(&dir, (afs_int32 *)OutFid, (afs_int32 *)DirFid)));
4861 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4863 /* set up return status */
4864 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4865 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4867 /* convert the write lock to a read lock before breaking callbacks */
4868 VVnodeWriteToRead(&errorCode, parentptr);
4869 assert(!errorCode || errorCode == VSALVAGE);
4871 /* break call back on DirFid */
4872 BreakCallBack(client->host, DirFid, 0);
4874 /* Return a callback promise to caller */
4875 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4878 /* Write the all modified vnodes (parent, new files) and volume back */
4879 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4883 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4886 } /*SAFSS_MakeDir */
4890 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4891 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4892 struct AFSFetchStatus * OutFidStatus,
4893 struct AFSFetchStatus * OutDirStatus,
4894 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4897 struct rx_connection *tcon;
4899 struct client *t_client = NULL; /* tmp ptr to client data */
4900 #if FS_STATS_DETAILED
4901 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4902 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4903 struct timeval elapsedTime; /* Transfer time */
4906 * Set our stats pointer, remember when the RPC operation started, and
4907 * tally the operation.
4909 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
4913 FT_GetTimeOfDay(&opStartTime, 0);
4914 #endif /* FS_STATS_DETAILED */
4915 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4919 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4920 OutDirStatus, CallBack, Sync);
4923 code = CallPostamble(tcon, code, thost);
4925 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4927 #if FS_STATS_DETAILED
4928 FT_GetTimeOfDay(&opStopTime, 0);
4931 (opP->numSuccesses)++;
4932 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4933 fs_stats_AddTo((opP->sumTime), elapsedTime);
4934 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4935 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4936 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4938 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4939 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4943 #endif /* FS_STATS_DETAILED */
4945 osi_auditU(acall, MakeDirEvent, code,
4946 AUD_ID, t_client ? t_client->ViceId : 0,
4947 AUD_FID, DirFid, AUD_STR, Name,
4948 AUD_FID, OutFid, AUD_END);
4951 } /*SRXAFS_MakeDir */
4955 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4956 * merged into it when possible.
4959 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4960 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4962 Vnode *parentptr = 0; /* vnode of input Directory */
4963 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4964 Vnode *targetptr = 0; /* file to be deleted */
4965 AFSFid fileFid; /* area for Fid from the directory */
4966 Error errorCode = 0; /* error code */
4967 DirHandle dir; /* Handle for dir package I/O */
4968 Volume *volptr = 0; /* pointer to the volume header */
4969 struct client *client = 0; /* pointer to client structure */
4970 afs_int32 rights, anyrights; /* rights for this and any user */
4971 struct client *t_client; /* tmp ptr to client data */
4972 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4973 struct rx_connection *tcon = rx_ConnectionOf(acall);
4977 /* Get ptr to client data for user Id for logging */
4978 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4979 logHostAddr.s_addr = rxr_HostOf(tcon);
4981 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4982 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4983 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4985 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
4988 * Get the vnode and volume for the parent dir along with the caller's
4992 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4993 &parentwhentargetnotdir, &client, WRITE_LOCK,
4994 &rights, &anyrights))) {
4998 /* set volume synchronization information */
4999 SetVolumeSync(Sync, volptr);
5001 /* Does the caller has delete (&write) access to the parent dir? */
5002 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
5006 /* Do the actual delete of the desired (empty) directory, Name */
5008 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
5013 /* Update the status for the parent dir; link count is also adjusted */
5014 #if FS_STATS_DETAILED
5015 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
5016 parentptr->disk.linkCount - 1,
5017 client->InSameNetwork);
5019 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
5020 parentptr->disk.linkCount - 1);
5021 #endif /* FS_STATS_DETAILED */
5023 /* Return to the caller the updated parent dir status */
5024 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
5027 * Note: it is not necessary to break the callback on fileFid, since
5028 * refcount is now 0, so no one should be able to refer to the dir
5031 DeleteFileCallBacks(&fileFid);
5033 /* convert the write lock to a read lock before breaking callbacks */
5034 VVnodeWriteToRead(&errorCode, parentptr);
5035 assert(!errorCode || errorCode == VSALVAGE);
5037 /* break call back on DirFid and fileFid */
5038 BreakCallBack(client->host, DirFid, 0);
5041 /* Write the all modified vnodes (parent, new files) and volume back */
5042 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
5045 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
5048 } /*SAFSS_RemoveDir */
5052 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
5053 struct AFSFetchStatus * OutDirStatus,
5054 struct AFSVolSync * Sync)
5057 struct rx_connection *tcon;
5059 struct client *t_client = NULL; /* tmp ptr to client data */
5060 #if FS_STATS_DETAILED
5061 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5062 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5063 struct timeval elapsedTime; /* Transfer time */
5066 * Set our stats pointer, remember when the RPC operation started, and
5067 * tally the operation.
5069 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
5073 FT_GetTimeOfDay(&opStartTime, 0);
5074 #endif /* FS_STATS_DETAILED */
5076 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5079 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
5082 code = CallPostamble(tcon, code, thost);
5084 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5086 #if FS_STATS_DETAILED
5087 FT_GetTimeOfDay(&opStopTime, 0);
5090 (opP->numSuccesses)++;
5091 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5092 fs_stats_AddTo((opP->sumTime), elapsedTime);
5093 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5094 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5095 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5097 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5098 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5102 #endif /* FS_STATS_DETAILED */
5104 osi_auditU(acall, RemoveDirEvent, code,
5105 AUD_ID, t_client ? t_client->ViceId : 0,
5106 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
5109 } /*SRXAFS_RemoveDir */
5113 * This routine is called exclusively by SRXAFS_SetLock(), and should be
5114 * merged into it when possible.
5117 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
5118 struct AFSVolSync *Sync)
5120 Vnode *targetptr = 0; /* vnode of input file */
5121 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5122 Error errorCode = 0; /* error code */
5123 Volume *volptr = 0; /* pointer to the volume header */
5124 struct client *client = 0; /* pointer to client structure */
5125 afs_int32 rights, anyrights; /* rights for this and any user */
5126 struct client *t_client; /* tmp ptr to client data */
5127 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5128 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
5129 struct rx_connection *tcon = rx_ConnectionOf(acall);
5131 if (type != LockRead && type != LockWrite) {
5135 /* Get ptr to client data for user Id for logging */
5136 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5137 logHostAddr.s_addr = rxr_HostOf(tcon);
5139 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
5140 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
5141 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5143 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
5146 * Get the vnode and volume for the desired file along with the caller's
5150 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5151 &parentwhentargetnotdir, &client, WRITE_LOCK,
5152 &rights, &anyrights))) {
5156 /* set volume synchronization information */
5157 SetVolumeSync(Sync, volptr);
5159 /* Handle the particular type of set locking, type */
5160 errorCode = HandleLocking(targetptr, client, rights, type);
5163 /* Write the all modified vnodes (parent, new files) and volume back */
5164 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5167 if ((errorCode == VREADONLY) && (type == LockRead))
5168 errorCode = 0; /* allow read locks on RO volumes without saving state */
5170 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
5173 } /*SAFSS_SetLock */
5177 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
5178 ViceLockType type, struct AFSVolSync * Sync)
5180 return SRXAFS_SetLock(acall, Fid, type, Sync);
5181 } /*SRXAFS_OldSetLock */
5185 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
5186 struct AFSVolSync * Sync)
5189 struct rx_connection *tcon;
5191 struct client *t_client = NULL; /* tmp ptr to client data */
5192 #if FS_STATS_DETAILED
5193 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5194 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5195 struct timeval elapsedTime; /* Transfer time */
5198 * Set our stats pointer, remember when the RPC operation started, and
5199 * tally the operation.
5201 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5205 FT_GetTimeOfDay(&opStartTime, 0);
5206 #endif /* FS_STATS_DETAILED */
5208 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5211 code = SAFSS_SetLock(acall, Fid, type, Sync);
5214 code = CallPostamble(tcon, code, thost);
5216 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5218 #if FS_STATS_DETAILED
5219 FT_GetTimeOfDay(&opStopTime, 0);
5222 (opP->numSuccesses)++;
5223 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5224 fs_stats_AddTo((opP->sumTime), elapsedTime);
5225 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5226 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5227 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5229 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5230 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5234 #endif /* FS_STATS_DETAILED */
5236 osi_auditU(acall, SetLockEvent, code,
5237 AUD_ID, t_client ? t_client->ViceId : 0,
5238 AUD_FID, Fid, AUD_LONG, type, AUD_END);
5240 } /*SRXAFS_SetLock */
5244 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5245 * merged into it when possible.
5248 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5249 struct AFSVolSync *Sync)
5251 Vnode *targetptr = 0; /* vnode of input file */
5252 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5253 Error errorCode = 0; /* error code */
5254 Volume *volptr = 0; /* pointer to the volume header */
5255 struct client *client = 0; /* pointer to client structure */
5256 afs_int32 rights, anyrights; /* rights for this and any user */
5257 struct client *t_client; /* tmp ptr to client data */
5258 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5259 struct rx_connection *tcon = rx_ConnectionOf(acall);
5261 /* Get ptr to client data for user Id for logging */
5262 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5263 logHostAddr.s_addr = rxr_HostOf(tcon);
5265 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5266 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5267 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5269 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5272 * Get the vnode and volume for the desired file along with the caller's
5276 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5277 &parentwhentargetnotdir, &client, WRITE_LOCK,
5278 &rights, &anyrights))) {
5279 goto Bad_ExtendLock;
5282 /* set volume synchronization information */
5283 SetVolumeSync(Sync, volptr);
5285 /* Handle the actual lock extension */
5286 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
5289 /* Put back file's vnode and volume */
5290 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5293 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5294 errorCode = 0; /* under our generous policy re RO vols */
5296 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5299 } /*SAFSS_ExtendLock */
5303 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5304 struct AFSVolSync * Sync)
5306 return SRXAFS_ExtendLock(acall, Fid, Sync);
5307 } /*SRXAFS_OldExtendLock */
5311 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5312 struct AFSVolSync * Sync)
5315 struct rx_connection *tcon;
5317 struct client *t_client = NULL; /* tmp ptr to client data */
5318 #if FS_STATS_DETAILED
5319 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5320 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5321 struct timeval elapsedTime; /* Transfer time */
5324 * Set our stats pointer, remember when the RPC operation started, and
5325 * tally the operation.
5327 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5331 FT_GetTimeOfDay(&opStartTime, 0);
5332 #endif /* FS_STATS_DETAILED */
5334 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5335 goto Bad_ExtendLock;
5337 code = SAFSS_ExtendLock(acall, Fid, Sync);
5340 code = CallPostamble(tcon, code, thost);
5342 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5344 #if FS_STATS_DETAILED
5345 FT_GetTimeOfDay(&opStopTime, 0);
5348 (opP->numSuccesses)++;
5349 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5350 fs_stats_AddTo((opP->sumTime), elapsedTime);
5351 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5352 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5353 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5355 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5356 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5360 #endif /* FS_STATS_DETAILED */
5362 osi_auditU(acall, ExtendLockEvent, code,
5363 AUD_ID, t_client ? t_client->ViceId : 0,
5364 AUD_FID, Fid, AUD_END);
5367 } /*SRXAFS_ExtendLock */
5371 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5372 * merged into it when possible.
5375 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5376 struct AFSVolSync *Sync)
5378 Vnode *targetptr = 0; /* vnode of input file */
5379 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5380 Error errorCode = 0; /* error code */
5381 Volume *volptr = 0; /* pointer to the volume header */
5382 struct client *client = 0; /* pointer to client structure */
5383 afs_int32 rights, anyrights; /* rights for this and any user */
5384 struct client *t_client; /* tmp ptr to client data */
5385 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5386 struct rx_connection *tcon = rx_ConnectionOf(acall);
5388 /* Get ptr to client data for user Id for logging */
5389 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5390 logHostAddr.s_addr = rxr_HostOf(tcon);
5392 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5393 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5394 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5396 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5399 * Get the vnode and volume for the desired file along with the caller's
5403 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5404 &parentwhentargetnotdir, &client, WRITE_LOCK,
5405 &rights, &anyrights))) {
5406 goto Bad_ReleaseLock;
5409 /* set volume synchronization information */
5410 SetVolumeSync(Sync, volptr);
5412 /* Handle the actual lock release */
5413 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
5414 goto Bad_ReleaseLock;
5416 /* if no more locks left, a callback would be triggered here */
5417 if (targetptr->disk.lock.lockCount <= 0) {
5418 /* convert the write lock to a read lock before breaking callbacks */
5419 VVnodeWriteToRead(&errorCode, targetptr);
5420 assert(!errorCode || errorCode == VSALVAGE);
5421 BreakCallBack(client->host, Fid, 0);
5425 /* Put back file's vnode and volume */
5426 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5429 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5430 errorCode = 0; /* under our generous policy re RO vols */
5432 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5435 } /*SAFSS_ReleaseLock */
5439 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5440 struct AFSVolSync * Sync)
5442 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5443 } /*SRXAFS_OldReleaseLock */
5447 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5448 struct AFSVolSync * Sync)
5451 struct rx_connection *tcon;
5453 struct client *t_client = NULL; /* tmp ptr to client data */
5454 #if FS_STATS_DETAILED
5455 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5456 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5457 struct timeval elapsedTime; /* Transfer time */
5460 * Set our stats pointer, remember when the RPC operation started, and
5461 * tally the operation.
5463 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5467 FT_GetTimeOfDay(&opStartTime, 0);
5468 #endif /* FS_STATS_DETAILED */
5470 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5471 goto Bad_ReleaseLock;
5473 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5476 code = CallPostamble(tcon, code, thost);
5478 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5480 #if FS_STATS_DETAILED
5481 FT_GetTimeOfDay(&opStopTime, 0);
5484 (opP->numSuccesses)++;
5485 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5486 fs_stats_AddTo((opP->sumTime), elapsedTime);
5487 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5488 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5489 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5491 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5492 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5496 #endif /* FS_STATS_DETAILED */
5498 osi_auditU(acall, ReleaseLockEvent, code,
5499 AUD_ID, t_client ? t_client->ViceId : 0,
5500 AUD_FID, Fid, AUD_END);
5503 } /*SRXAFS_ReleaseLock */
5507 SetSystemStats(struct AFSStatistics *stats)
5509 /* Fix this sometime soon.. */
5510 /* Because hey, it's not like we have a network monitoring protocol... */
5511 struct timeval time;
5513 /* this works on all system types */
5514 FT_GetTimeOfDay(&time, 0);
5515 stats->CurrentTime = time.tv_sec;
5516 } /*SetSystemStats */
5519 SetAFSStats(struct AFSStatistics *stats)
5521 extern afs_int32 StartTime, CurrentConnections;
5525 stats->CurrentMsgNumber = 0;
5526 stats->OldestMsgNumber = 0;
5527 stats->StartTime = StartTime;
5528 stats->CurrentConnections = CurrentConnections;
5529 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5530 stats->TotalFetchs =
5531 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5532 AFSCallStats.FetchStatus;
5533 stats->FetchDatas = AFSCallStats.FetchData;
5534 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5535 seconds = AFSCallStats.AccumFetchTime / 1000;
5538 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5539 stats->TotalStores =
5540 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5541 AFSCallStats.StoreStatus;
5542 stats->StoreDatas = AFSCallStats.StoreData;
5543 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5544 seconds = AFSCallStats.AccumStoreTime / 1000;
5547 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5549 stats->ProcessSize = -1; /* TODO: */
5551 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5554 h_GetWorkStats((int *)&(stats->WorkStations),
5555 (int *)&(stats->ActiveWorkStations), (int *)0,
5556 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5560 /* Get disk related information from all AFS partitions. */
5563 SetVolumeStats(struct AFSStatistics *stats)
5565 struct DiskPartition64 *part;
5568 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5569 part = part->next) {
5570 stats->Disks[i].TotalBlocks = RoundInt64ToInt32(part->totalUsable);
5571 stats->Disks[i].BlocksAvailable = RoundInt64ToInt32(part->free);
5572 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5573 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5576 while (i < AFS_MSTATDISKS) {
5577 stats->Disks[i].TotalBlocks = -1;
5580 } /*SetVolumeStats */
5583 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5586 struct rx_connection *tcon = rx_ConnectionOf(acall);
5588 struct client *t_client = NULL; /* tmp ptr to client data */
5589 #if FS_STATS_DETAILED
5590 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5591 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5592 struct timeval elapsedTime; /* Transfer time */
5595 * Set our stats pointer, remember when the RPC operation started, and
5596 * tally the operation.
5598 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5602 FT_GetTimeOfDay(&opStartTime, 0);
5603 #endif /* FS_STATS_DETAILED */
5605 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5606 goto Bad_GetStatistics;
5608 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5610 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5612 memset(Statistics, 0, sizeof(*Statistics));
5613 SetAFSStats((struct AFSStatistics *)Statistics);
5614 SetVolumeStats((struct AFSStatistics *)Statistics);
5615 SetSystemStats((struct AFSStatistics *)Statistics);
5618 code = CallPostamble(tcon, code, thost);
5620 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5622 #if FS_STATS_DETAILED
5623 FT_GetTimeOfDay(&opStopTime, 0);
5626 (opP->numSuccesses)++;
5627 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5628 fs_stats_AddTo((opP->sumTime), elapsedTime);
5629 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5630 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5631 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5633 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5634 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5638 #endif /* FS_STATS_DETAILED */
5640 osi_auditU(acall, GetStatisticsEvent, code,
5641 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5643 } /*SRXAFS_GetStatistics */
5647 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5649 extern afs_int32 StartTime, CurrentConnections;
5652 struct rx_connection *tcon = rx_ConnectionOf(acall);
5654 struct client *t_client = NULL; /* tmp ptr to client data */
5655 struct timeval time;
5656 #if FS_STATS_DETAILED
5657 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5658 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5659 struct timeval elapsedTime; /* Transfer time */
5662 * Set our stats pointer, remember when the RPC operation started, and
5663 * tally the operation.
5665 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5669 FT_GetTimeOfDay(&opStartTime, 0);
5670 #endif /* FS_STATS_DETAILED */
5672 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5673 goto Bad_GetStatistics64;
5675 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5676 Statistics->ViceStatistics64_val =
5677 malloc(statsVersion*sizeof(afs_int64));
5678 Statistics->ViceStatistics64_len = statsVersion;
5680 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5681 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5682 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5684 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5685 AFSCallStats.TotalCalls;
5686 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5687 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5688 AFSCallStats.FetchStatus;
5689 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5690 AFSCallStats.FetchData;
5691 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5692 AFSCallStats.TotalFetchedBytes;
5693 seconds = AFSCallStats.AccumFetchTime / 1000;
5696 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5697 AFSCallStats.TotalFetchedBytes / seconds;
5698 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5699 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5700 AFSCallStats.StoreStatus;
5701 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5702 AFSCallStats.StoreData;
5703 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5704 AFSCallStats.TotalStoredBytes;
5705 seconds = AFSCallStats.AccumStoreTime / 1000;
5708 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5709 AFSCallStats.TotalStoredBytes / seconds;
5711 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = -1;
5713 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] =
5714 (afs_int32) ((long)sbrk(0) >> 10);
5717 h_GetWorkStats64(&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5718 &(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5720 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5724 /* this works on all system types */
5725 FT_GetTimeOfDay(&time, 0);
5726 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
5728 Bad_GetStatistics64:
5729 code = CallPostamble(tcon, code, thost);
5731 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5733 #if FS_STATS_DETAILED
5734 FT_GetTimeOfDay(&opStopTime, 0);
5737 (opP->numSuccesses)++;
5738 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5739 fs_stats_AddTo((opP->sumTime), elapsedTime);
5740 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5741 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5742 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5744 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5745 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5749 #endif /* FS_STATS_DETAILED */
5751 osi_auditU(acall, GetStatisticsEvent, code,
5752 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5754 } /*SRXAFS_GetStatistics */
5757 /*------------------------------------------------------------------------
5758 * EXPORTED SRXAFS_XStatsVersion
5761 * Routine called by the server-side RPC interface to implement
5762 * pulling out the xstat version number for the File Server.
5765 * a_versionP : Ptr to the version number variable to set.
5771 * Nothing interesting.
5775 *------------------------------------------------------------------------*/
5778 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5779 { /*SRXAFS_XStatsVersion */
5781 struct client *t_client = NULL; /* tmp ptr to client data */
5782 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5783 #if FS_STATS_DETAILED
5784 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5785 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5786 struct timeval elapsedTime; /* Transfer time */
5789 * Set our stats pointer, remember when the RPC operation started, and
5790 * tally the operation.
5792 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5796 FT_GetTimeOfDay(&opStartTime, 0);
5797 #endif /* FS_STATS_DETAILED */
5799 *a_versionP = AFS_XSTAT_VERSION;
5801 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5803 #if FS_STATS_DETAILED
5804 FT_GetTimeOfDay(&opStopTime, 0);
5805 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5806 fs_stats_AddTo((opP->sumTime), elapsedTime);
5807 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5808 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5809 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5811 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5812 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5815 (opP->numSuccesses)++;
5817 #endif /* FS_STATS_DETAILED */
5819 osi_auditU(a_call, XStatsVersionEvent, 0,
5820 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5822 } /*SRXAFS_XStatsVersion */
5825 /*------------------------------------------------------------------------
5826 * PRIVATE FillPerfValues
5829 * Routine called to fill a regular performance data structure.
5832 * a_perfP : Ptr to perf structure to fill
5838 * Various collections need this info, so the guts were put in
5839 * this separate routine.
5843 *------------------------------------------------------------------------*/
5846 FillPerfValues(struct afs_PerfStats *a_perfP)
5847 { /*FillPerfValues */
5849 int dir_Buffers; /*# buffers in use by dir package */
5850 int dir_Calls; /*# read calls in dir package */
5851 int dir_IOs; /*# I/O ops in dir package */
5852 struct rx_statistics *stats;
5855 * Vnode cache section.
5857 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5858 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5859 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5860 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5861 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5862 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5863 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5864 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5865 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5866 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5867 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5868 SplitInt64(VStats.hdr_gets, hi, lo);
5869 a_perfP->vcache_H_Gets = lo;
5870 SplitInt64(VStats.hdr_loads, hi, lo);
5871 a_perfP->vcache_H_Replacements = lo;
5874 * Directory section.
5876 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5877 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5878 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5879 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5884 stats = rx_GetStatistics();
5886 a_perfP->rx_packetRequests = (afs_int32) stats->packetRequests;
5887 a_perfP->rx_noPackets_RcvClass =
5888 (afs_int32) stats->receivePktAllocFailures;
5889 a_perfP->rx_noPackets_SendClass =
5890 (afs_int32) stats->sendPktAllocFailures;
5891 a_perfP->rx_noPackets_SpecialClass =
5892 (afs_int32) stats->specialPktAllocFailures;
5893 a_perfP->rx_socketGreedy = (afs_int32) stats->socketGreedy;
5894 a_perfP->rx_bogusPacketOnRead = (afs_int32) stats->bogusPacketOnRead;
5895 a_perfP->rx_bogusHost = (afs_int32) stats->bogusHost;
5896 a_perfP->rx_noPacketOnRead = (afs_int32) stats->noPacketOnRead;
5897 a_perfP->rx_noPacketBuffersOnRead =
5898 (afs_int32) stats->noPacketBuffersOnRead;
5899 a_perfP->rx_selects = (afs_int32) stats->selects;
5900 a_perfP->rx_sendSelects = (afs_int32) stats->sendSelects;
5901 a_perfP->rx_packetsRead_RcvClass =
5902 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_RECEIVE];
5903 a_perfP->rx_packetsRead_SendClass =
5904 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SEND];
5905 a_perfP->rx_packetsRead_SpecialClass =
5906 (afs_int32) stats->packetsRead[RX_PACKET_CLASS_SPECIAL];
5907 a_perfP->rx_dataPacketsRead = (afs_int32) stats->dataPacketsRead;
5908 a_perfP->rx_ackPacketsRead = (afs_int32) stats->ackPacketsRead;
5909 a_perfP->rx_dupPacketsRead = (afs_int32) stats->dupPacketsRead;
5910 a_perfP->rx_spuriousPacketsRead =
5911 (afs_int32) stats->spuriousPacketsRead;
5912 a_perfP->rx_packetsSent_RcvClass =
5913 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_RECEIVE];
5914 a_perfP->rx_packetsSent_SendClass =
5915 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SEND];
5916 a_perfP->rx_packetsSent_SpecialClass =
5917 (afs_int32) stats->packetsSent[RX_PACKET_CLASS_SPECIAL];
5918 a_perfP->rx_ackPacketsSent = (afs_int32) stats->ackPacketsSent;
5919 a_perfP->rx_pingPacketsSent = (afs_int32) stats->pingPacketsSent;
5920 a_perfP->rx_abortPacketsSent = (afs_int32) stats->abortPacketsSent;
5921 a_perfP->rx_busyPacketsSent = (afs_int32) stats->busyPacketsSent;
5922 a_perfP->rx_dataPacketsSent = (afs_int32) stats->dataPacketsSent;
5923 a_perfP->rx_dataPacketsReSent = (afs_int32) stats->dataPacketsReSent;
5924 a_perfP->rx_dataPacketsPushed = (afs_int32) stats->dataPacketsPushed;
5925 a_perfP->rx_ignoreAckedPacket = (afs_int32) stats->ignoreAckedPacket;
5926 a_perfP->rx_totalRtt_Sec = (afs_int32) stats->totalRtt.sec;
5927 a_perfP->rx_totalRtt_Usec = (afs_int32) stats->totalRtt.usec;
5928 a_perfP->rx_minRtt_Sec = (afs_int32) stats->minRtt.sec;
5929 a_perfP->rx_minRtt_Usec = (afs_int32) stats->minRtt.usec;
5930 a_perfP->rx_maxRtt_Sec = (afs_int32) stats->maxRtt.sec;
5931 a_perfP->rx_maxRtt_Usec = (afs_int32) stats->maxRtt.usec;
5932 a_perfP->rx_nRttSamples = (afs_int32) stats->nRttSamples;
5933 a_perfP->rx_nServerConns = (afs_int32) stats->nServerConns;
5934 a_perfP->rx_nClientConns = (afs_int32) stats->nClientConns;
5935 a_perfP->rx_nPeerStructs = (afs_int32) stats->nPeerStructs;
5936 a_perfP->rx_nCallStructs = (afs_int32) stats->nCallStructs;
5937 a_perfP->rx_nFreeCallStructs = (afs_int32) stats->nFreeCallStructs;
5939 a_perfP->host_NumHostEntries = HTs;
5940 a_perfP->host_HostBlocks = HTBlocks;
5941 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5942 &(a_perfP->host_HostsInSameNetOrSubnet),
5943 &(a_perfP->host_HostsInDiffSubnet),
5944 &(a_perfP->host_HostsInDiffNetwork));
5945 a_perfP->host_NumClients = CEs;
5946 a_perfP->host_ClientBlocks = CEBlocks;
5948 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5949 a_perfP->rx_nBusies = (afs_int32) stats->nBusies;
5950 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5951 rx_FreeStatistics(&stats);
5952 } /*FillPerfValues */
5955 /*------------------------------------------------------------------------
5956 * EXPORTED SRXAFS_GetXStats
5959 * Routine called by the server-side callback RPC interface to
5960 * implement getting the given data collection from the extended
5961 * File Server statistics.
5964 * a_call : Ptr to Rx call on which this request came in.
5965 * a_clientVersionNum : Client version number.
5966 * a_opCode : Desired operation.
5967 * a_serverVersionNumP : Ptr to version number to set.
5968 * a_timeP : Ptr to time value (seconds) to set.
5969 * a_dataP : Ptr to variable array structure to return
5976 * Nothing interesting.
5980 *------------------------------------------------------------------------*/
5983 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5984 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5985 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5986 { /*SRXAFS_GetXStats */
5988 int code; /*Return value */
5989 afs_int32 *dataBuffP; /*Ptr to data to be returned */
5990 afs_int32 dataBytes; /*Bytes in data buffer */
5991 #if FS_STATS_DETAILED
5992 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5993 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5994 struct timeval elapsedTime; /* Transfer time */
5997 * Set our stats pointer, remember when the RPC operation started, and
5998 * tally the operation.
6000 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
6004 FT_GetTimeOfDay(&opStartTime, 0);
6005 #endif /* FS_STATS_DETAILED */
6008 * Record the time of day and the server version number.
6010 *a_srvVersionNumP = AFS_XSTAT_VERSION;
6011 *a_timeP = FT_ApproxTime();
6014 * Stuff the appropriate data in there (assume victory)
6019 ("Received GetXStats call for collection %d\n",
6020 a_collectionNumber));
6024 * We're not keeping stats, so just return successfully with
6027 a_dataP->AFS_CollData_len = 0;
6028 a_dataP->AFS_CollData_val = NULL;
6031 switch (a_collectionNumber) {
6032 case AFS_XSTATSCOLL_CALL_INFO:
6034 * Pass back all the call-count-related data.
6036 * >>> We are forced to allocate a separate area in which to
6037 * >>> put this stuff in by the RPC stub generator, since it
6038 * >>> will be freed at the tail end of the server stub code.
6042 * I don't think call-level stats are being collected yet
6043 * for the File Server.
6045 dataBytes = sizeof(struct afs_Stats);
6046 dataBuffP = (afs_int32 *) malloc(dataBytes);
6047 memcpy(dataBuffP, &afs_cmstats, dataBytes);
6048 a_dataP->AFS_CollData_len = dataBytes >> 2;
6049 a_dataP->AFS_CollData_val = dataBuffP;
6051 a_dataP->AFS_CollData_len = 0;
6052 a_dataP->AFS_CollData_val = NULL;
6056 case AFS_XSTATSCOLL_PERF_INFO:
6058 * Pass back all the regular performance-related data.
6060 * >>> We are forced to allocate a separate area in which to
6061 * >>> put this stuff in by the RPC stub generator, since it
6062 * >>> will be freed at the tail end of the server stub code.
6065 afs_perfstats.numPerfCalls++;
6066 FillPerfValues(&afs_perfstats);
6069 * Don't overwrite the spares at the end.
6072 dataBytes = sizeof(struct afs_PerfStats);
6073 dataBuffP = (afs_int32 *) malloc(dataBytes);
6074 memcpy(dataBuffP, &afs_perfstats, dataBytes);
6075 a_dataP->AFS_CollData_len = dataBytes >> 2;
6076 a_dataP->AFS_CollData_val = dataBuffP;
6079 case AFS_XSTATSCOLL_FULL_PERF_INFO:
6081 * Pass back the full collection of performance-related data.
6082 * We have to stuff the basic, overall numbers in, but the
6083 * detailed numbers are kept in the structure already.
6085 * >>> We are forced to allocate a separate area in which to
6086 * >>> put this stuff in by the RPC stub generator, since it
6087 * >>> will be freed at the tail end of the server stub code.
6090 afs_perfstats.numPerfCalls++;
6091 #if FS_STATS_DETAILED
6092 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
6093 FillPerfValues(&afs_FullPerfStats.overall);
6096 * Don't overwrite the spares at the end.
6099 dataBytes = sizeof(struct fs_stats_FullPerfStats);
6100 dataBuffP = (afs_int32 *) malloc(dataBytes);
6101 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
6102 a_dataP->AFS_CollData_len = dataBytes >> 2;
6103 a_dataP->AFS_CollData_val = dataBuffP;
6107 case AFS_XSTATSCOLL_CBSTATS:
6108 afs_perfstats.numPerfCalls++;
6110 dataBytes = sizeof(struct cbcounters);
6111 dataBuffP = (afs_int32 *) malloc(dataBytes);
6113 extern struct cbcounters cbstuff;
6114 dataBuffP[0]=cbstuff.DeleteFiles;
6115 dataBuffP[1]=cbstuff.DeleteCallBacks;
6116 dataBuffP[2]=cbstuff.BreakCallBacks;
6117 dataBuffP[3]=cbstuff.AddCallBacks;
6118 dataBuffP[4]=cbstuff.GotSomeSpaces;
6119 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
6120 dataBuffP[6]=cbstuff.nFEs;
6121 dataBuffP[7]=cbstuff.nCBs;
6122 dataBuffP[8]=cbstuff.nblks;
6123 dataBuffP[9]=cbstuff.CBsTimedOut;
6124 dataBuffP[10]=cbstuff.nbreakers;
6125 dataBuffP[11]=cbstuff.GSS1;
6126 dataBuffP[12]=cbstuff.GSS2;
6127 dataBuffP[13]=cbstuff.GSS3;
6128 dataBuffP[14]=cbstuff.GSS4;
6129 dataBuffP[15]=cbstuff.GSS5;
6132 a_dataP->AFS_CollData_len = dataBytes >> 2;
6133 a_dataP->AFS_CollData_val = dataBuffP;
6139 * Illegal collection number.
6141 a_dataP->AFS_CollData_len = 0;
6142 a_dataP->AFS_CollData_val = NULL;
6144 } /*Switch on collection number */
6146 #if FS_STATS_DETAILED
6147 FT_GetTimeOfDay(&opStopTime, 0);
6150 (opP->numSuccesses)++;
6151 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6152 fs_stats_AddTo((opP->sumTime), elapsedTime);
6153 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6154 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6155 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6157 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6158 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6162 #endif /* FS_STATS_DETAILED */
6166 } /*SRXAFS_GetXStats */
6170 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
6171 struct AFSCBs *CallBackArray)
6173 afs_int32 errorCode = 0;
6175 struct client *client = 0;
6176 struct rx_connection *tcon;
6178 #if FS_STATS_DETAILED
6179 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6180 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6181 struct timeval elapsedTime; /* Transfer time */
6184 * Set our stats pointer, remember when the RPC operation started, and
6185 * tally the operation.
6188 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
6192 FT_GetTimeOfDay(&opStartTime, 0);
6193 #endif /* FS_STATS_DETAILED */
6197 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
6198 FidArray->AFSCBFids_len));
6201 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
6203 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6204 goto Bad_GiveUpCallBacks;
6206 if (!FidArray && !CallBackArray) {
6208 ("SAFS_GiveUpAllCallBacks: host=%x\n",
6209 (tcon->peer ? tcon->peer->host : 0)));
6210 errorCode = GetClient(tcon, &client);
6213 DeleteAllCallBacks_r(client->host, 1);
6218 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
6220 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
6221 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
6222 (tcon->peer ? tcon->peer->host : 0)));
6224 goto Bad_GiveUpCallBacks;
6227 errorCode = GetClient(tcon, &client);
6229 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
6230 struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
6231 DeleteCallBack(client->host, fid);
6237 Bad_GiveUpCallBacks:
6238 errorCode = CallPostamble(tcon, errorCode, thost);
6240 #if FS_STATS_DETAILED
6241 FT_GetTimeOfDay(&opStopTime, 0);
6242 if (errorCode == 0) {
6244 (opP->numSuccesses)++;
6245 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6246 fs_stats_AddTo((opP->sumTime), elapsedTime);
6247 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6248 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6249 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6251 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6252 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6256 #endif /* FS_STATS_DETAILED */
6259 } /*common_GiveUpCallBacks */
6263 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
6264 struct AFSCBs * CallBackArray)
6266 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
6267 } /*SRXAFS_GiveUpCallBacks */
6270 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
6272 return common_GiveUpCallBacks(acall, 0, 0);
6273 } /*SRXAFS_GiveUpAllCallBacks */
6277 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
6278 struct AFSVolumeInfo * avolinfo)
6280 return (VNOVOL); /* XXX Obsolete routine XXX */
6282 } /*SRXAFS_NGetVolumeInfo */
6286 * Dummy routine. Should never be called (the cache manager should only
6287 * invoke this interface when communicating with a AFS/DFS Protocol
6291 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
6292 char *afs_name_p, struct AFSFid * afs_fid_p,
6293 struct AFSFetchStatus * afs_status_p,
6294 struct AFSFetchStatus * afs_dir_status_p,
6295 struct AFSCallBack * afs_callback_p,
6296 struct AFSVolSync * afs_sync_p)
6303 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
6306 struct rx_connection *tcon;
6308 afs_uint32 *dataBuffP;
6309 afs_int32 dataBytes;
6312 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
6313 afs_FullPerfStats.overall.fs_nGetCaps++;
6315 ViceLog(2, ("SAFS_GetCapabilties\n"));
6317 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6320 dataBytes = 1 * sizeof(afs_int32);
6321 dataBuffP = (afs_uint32 *) malloc(dataBytes);
6322 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
6323 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
6325 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
6327 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
6328 capabilities->Capabilities_val = dataBuffP;
6331 code = CallPostamble(tcon, code, thost);
6338 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
6339 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
6343 afs_int32 nids, naddrs;
6344 afs_int32 *vd, *addr;
6345 Error errorCode = 0; /* return code to caller */
6346 struct client *client = 0;
6348 ViceLog(1, ("SRXAFS_FlushCPS\n"));
6350 AFSCallStats.TotalCalls++;
6352 nids = vids->ViceIds_len; /* # of users in here */
6353 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
6354 if (nids < 0 || naddrs < 0) {
6359 vd = vids->ViceIds_val;
6360 for (i = 0; i < nids; i++, vd++) {
6363 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
6367 client->prfail = 2; /* Means re-eval client's cps */
6370 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6373 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6374 free(client->CPS.prlist_val);
6375 client->CPS.prlist_val = NULL;
6376 client->CPS.prlist_len = 0;
6378 ReleaseWriteLock(&client->lock);
6382 addr = addrs->IPAddrs_val;
6383 for (i = 0; i < naddrs; i++, addr++) {
6385 h_flushhostcps(*addr, htons(7001));
6389 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6391 } /*SRXAFS_FlushCPS */
6393 /* worthless hack to let CS keep running ancient software */
6395 afs_vtoi(char *aname)
6401 while ((tc = *aname++)) {
6402 if (tc > '9' || tc < '0')
6403 return 0; /* invalid name */
6411 * may get name or #, but must handle all weird cases (recognize readonly
6412 * or backup volumes by name or #
6415 CopyVolumeEntry(char *aname, struct vldbentry *ave,
6416 struct VolumeInfo *av)
6419 afs_int32 mask, whichType;
6420 afs_uint32 *serverHost, *typePtr;
6422 /* figure out what type we want if by name */
6424 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6425 whichType = BACKVOL;
6426 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6431 vol = afs_vtoi(aname);
6433 vol = ave->volumeId[whichType];
6436 * Now vol has volume # we're interested in. Next, figure out the type
6437 * of the volume by looking finding it in the vldb entry
6439 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6442 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6445 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6446 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6447 whichType = BACKVOL;
6449 return EINVAL; /* error: can't find volume in vldb entry */
6451 typePtr = &av->Type0;
6452 serverHost = &av->Server0;
6454 av->Type = whichType;
6455 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6456 if (ave->flags & VLF_RWEXISTS)
6457 typePtr[RWVOL] = ave->volumeId[RWVOL];
6458 if (ave->flags & VLF_ROEXISTS)
6459 typePtr[ROVOL] = ave->volumeId[ROVOL];
6460 if (ave->flags & VLF_BACKEXISTS)
6461 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6463 for (i = 0, j = 0; i < ave->nServers; i++) {
6464 if ((ave->serverFlags[i] & mask) == 0)
6465 continue; /* wrong volume */
6466 serverHost[j] = ave->serverNumber[i];
6469 av->ServerCount = j;
6471 serverHost[j++] = 0; /* bogus 8, but compat only now */
6476 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6478 static struct rx_connection *vlConn = 0;
6479 static int down = 0;
6480 static afs_int32 lastDownTime = 0;
6481 struct vldbentry tve;
6482 struct rx_securityClass *vlSec;
6486 vlSec = rxnull_NewClientSecurityObject();
6488 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6489 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6491 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6492 return 1; /* failure */
6495 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6497 down = 0; /* call worked */
6500 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6506 /* otherwise convert to old format vldb entry */
6507 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6517 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6518 struct VolumeInfo * avolinfo)
6521 struct rx_connection *tcon;
6523 #if FS_STATS_DETAILED
6524 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6525 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6526 struct timeval elapsedTime; /* Transfer time */
6529 * Set our stats pointer, remember when the RPC operation started, and
6530 * tally the operation.
6532 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6536 FT_GetTimeOfDay(&opStartTime, 0);
6537 #endif /* FS_STATS_DETAILED */
6538 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6539 goto Bad_GetVolumeInfo;
6542 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6544 code = TryLocalVLServer(avolid, avolinfo);
6546 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6547 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6548 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6549 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6552 code = CallPostamble(tcon, code, thost);
6554 #if FS_STATS_DETAILED
6555 FT_GetTimeOfDay(&opStopTime, 0);
6558 (opP->numSuccesses)++;
6559 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6560 fs_stats_AddTo((opP->sumTime), elapsedTime);
6561 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6562 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6563 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6565 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6566 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6570 #endif /* FS_STATS_DETAILED */
6574 } /*SRXAFS_GetVolumeInfo */
6578 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6579 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6580 char **OfflineMsg, char **Motd)
6582 Vnode *targetptr = 0; /* vnode of the new file */
6583 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6584 Error errorCode = 0; /* error code */
6585 Volume *volptr = 0; /* pointer to the volume header */
6586 struct client *client = 0; /* pointer to client entry */
6587 afs_int32 rights, anyrights; /* rights for this and any user */
6589 struct rx_connection *tcon;
6591 struct client *t_client = NULL; /* tmp ptr to client data */
6592 #if FS_STATS_DETAILED
6593 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6594 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6595 struct timeval elapsedTime; /* Transfer time */
6598 * Set our stats pointer, remember when the RPC operation started, and
6599 * tally the operation.
6602 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6606 FT_GetTimeOfDay(&opStartTime, 0);
6607 #endif /* FS_STATS_DETAILED */
6609 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6610 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6611 goto Bad_GetVolumeStatus;
6614 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6618 goto Bad_GetVolumeStatus;
6620 dummyFid.Volume = avolid, dummyFid.Vnode =
6621 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6624 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6625 &parentwhentargetnotdir, &client, READ_LOCK,
6626 &rights, &anyrights)))
6627 goto Bad_GetVolumeStatus;
6629 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6631 goto Bad_GetVolumeStatus;
6633 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6635 Bad_GetVolumeStatus:
6636 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6638 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6639 /* next is to guarantee out strings exist for stub */
6641 *Name = (char *)malloc(1);
6645 *Motd = (char *)malloc(1);
6648 if (*OfflineMsg == 0) {
6649 *OfflineMsg = (char *)malloc(1);
6652 errorCode = CallPostamble(tcon, errorCode, thost);
6654 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6656 #if FS_STATS_DETAILED
6657 FT_GetTimeOfDay(&opStopTime, 0);
6658 if (errorCode == 0) {
6660 (opP->numSuccesses)++;
6661 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6662 fs_stats_AddTo((opP->sumTime), elapsedTime);
6663 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6664 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6665 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6667 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6668 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6672 #endif /* FS_STATS_DETAILED */
6674 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
6675 AUD_ID, t_client ? t_client->ViceId : 0,
6676 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
6679 } /*SRXAFS_GetVolumeStatus */
6683 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6684 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6685 char *OfflineMsg, char *Motd)
6687 Vnode *targetptr = 0; /* vnode of the new file */
6688 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6689 Error errorCode = 0; /* error code */
6690 Volume *volptr = 0; /* pointer to the volume header */
6691 struct client *client = 0; /* pointer to client entry */
6692 afs_int32 rights, anyrights; /* rights for this and any user */
6694 struct rx_connection *tcon = rx_ConnectionOf(acall);
6696 struct client *t_client = NULL; /* tmp ptr to client data */
6697 #if FS_STATS_DETAILED
6698 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6699 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6700 struct timeval elapsedTime; /* Transfer time */
6703 * Set our stats pointer, remember when the RPC operation started, and
6704 * tally the operation.
6707 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6711 FT_GetTimeOfDay(&opStartTime, 0);
6712 #endif /* FS_STATS_DETAILED */
6714 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6715 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6716 goto Bad_SetVolumeStatus;
6719 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6723 goto Bad_SetVolumeStatus;
6725 dummyFid.Volume = avolid, dummyFid.Vnode =
6726 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6729 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6730 &parentwhentargetnotdir, &client, READ_LOCK,
6731 &rights, &anyrights)))
6732 goto Bad_SetVolumeStatus;
6734 if (readonlyServer) {
6735 errorCode = VREADONLY;
6736 goto Bad_SetVolumeStatus;
6738 if (VanillaUser(client)) {
6740 goto Bad_SetVolumeStatus;
6744 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6746 Bad_SetVolumeStatus:
6747 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6749 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6750 errorCode = CallPostamble(tcon, errorCode, thost);
6752 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6754 #if FS_STATS_DETAILED
6755 FT_GetTimeOfDay(&opStopTime, 0);
6756 if (errorCode == 0) {
6758 (opP->numSuccesses)++;
6759 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6760 fs_stats_AddTo((opP->sumTime), elapsedTime);
6761 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6762 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6763 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6765 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6766 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6770 #endif /* FS_STATS_DETAILED */
6772 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6773 AUD_ID, t_client ? t_client->ViceId : 0,
6774 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6776 } /*SRXAFS_SetVolumeStatus */
6778 #define DEFAULTVOLUME "root.afs"
6781 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6787 struct rx_connection *tcon;
6789 Error errorCode = 0;
6791 #if FS_STATS_DETAILED
6792 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6793 struct timeval opStartTime; /* Start time for RPC op */
6795 struct timeval opStopTime;
6796 struct timeval elapsedTime; /* Transfer time */
6800 * Set our stats pointer, remember when the RPC operation started, and
6801 * tally the operation.
6803 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6807 FT_GetTimeOfDay(&opStartTime, 0);
6808 #endif /* FS_STATS_DETAILED */
6810 return FSERR_EOPNOTSUPP;
6813 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
6814 goto Bad_GetRootVolume;
6816 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6819 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6821 strcpy(temp, DEFAULTVOLUME);
6823 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6824 lockf(fd, F_LOCK, 0);
6828 len = read(fd, temp, 256);
6829 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6830 lockf(fd, F_ULOCK, 0);
6835 if (temp[len - 1] == '\n')
6839 *VolumeName = temp; /* freed by rx server-side stub */
6842 errorCode = CallPostamble(tcon, errorCode, thost);
6844 #if FS_STATS_DETAILED
6845 FT_GetTimeOfDay(&opStopTime, 0);
6846 if (errorCode == 0) {
6848 (opP->numSuccesses)++;
6849 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6850 fs_stats_AddTo((opP->sumTime), elapsedTime);
6851 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6852 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6853 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6855 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6856 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6860 #endif /* FS_STATS_DETAILED */
6865 } /*SRXAFS_GetRootVolume */
6868 /* still works because a struct CBS is the same as a struct AFSOpaque */
6870 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6871 struct AFSOpaque * Token)
6874 struct rx_connection *tcon;
6876 #if FS_STATS_DETAILED
6877 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6878 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6879 struct timeval elapsedTime; /* Transfer time */
6882 * Set our stats pointer, remember when the RPC operation started, and
6883 * tally the operation.
6885 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6889 FT_GetTimeOfDay(&opStartTime, 0);
6890 #endif /* FS_STATS_DETAILED */
6892 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6893 goto Bad_CheckToken;
6895 code = FSERR_ECONNREFUSED;
6898 code = CallPostamble(tcon, code, thost);
6900 #if FS_STATS_DETAILED
6901 FT_GetTimeOfDay(&opStopTime, 0);
6904 (opP->numSuccesses)++;
6905 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6906 fs_stats_AddTo((opP->sumTime), elapsedTime);
6907 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6908 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6909 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6911 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6912 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6916 #endif /* FS_STATS_DETAILED */
6920 } /*SRXAFS_CheckToken */
6923 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6924 afs_uint32 * USeconds)
6927 struct rx_connection *tcon;
6930 #if FS_STATS_DETAILED
6931 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6932 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6933 struct timeval elapsedTime; /* Transfer time */
6936 * Set our stats pointer, remember when the RPC operation started, and
6937 * tally the operation.
6939 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
6943 FT_GetTimeOfDay(&opStartTime, 0);
6944 #endif /* FS_STATS_DETAILED */
6946 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6950 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6952 FT_GetTimeOfDay(&tpl, 0);
6953 *Seconds = tpl.tv_sec;
6954 *USeconds = tpl.tv_usec;
6956 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6959 code = CallPostamble(tcon, code, thost);
6961 #if FS_STATS_DETAILED
6962 FT_GetTimeOfDay(&opStopTime, 0);
6963 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6966 (opP->numSuccesses)++;
6967 fs_stats_AddTo((opP->sumTime), elapsedTime);
6968 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6969 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6970 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6972 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6973 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6977 #endif /* FS_STATS_DETAILED */
6981 } /*SRXAFS_GetTime */
6988 * Implement a client's data fetch using Rx.
6991 * volptr : Ptr to the given volume's info.
6992 * targetptr : Pointer to the vnode involved.
6993 * Call : Ptr to the Rx call involved.
6994 * Pos : Offset within the file.
6995 * Len : Length in bytes to read; this value is bogus!
6996 * if FS_STATS_DETAILED
6997 * a_bytesToFetchP : Set to the number of bytes to be fetched from
6999 * a_bytesFetchedP : Set to the actual number of bytes fetched from
7005 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
7006 struct rx_call * Call, afs_sfsize_t Pos,
7007 afs_sfsize_t Len, afs_int32 Int64Mode,
7008 #if FS_STATS_DETAILED
7009 afs_sfsize_t * a_bytesToFetchP,
7010 afs_sfsize_t * a_bytesFetchedP
7011 #endif /* FS_STATS_DETAILED */
7014 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
7019 #else /* HAVE_PIOV */
7020 struct iovec tiov[RX_MAXIOVECS];
7022 #endif /* HAVE_PIOV */
7026 #if FS_STATS_DETAILED
7028 * Initialize the byte count arguments.
7030 (*a_bytesToFetchP) = 0;
7031 (*a_bytesFetchedP) = 0;
7032 #endif /* FS_STATS_DETAILED */
7036 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
7037 (afs_uintmax_t) Len));
7039 if (!VN_GET_INO(targetptr)) {
7040 afs_int32 zero = htonl(0);
7042 * This is used for newly created files; we simply send 0 bytes
7043 * back to make the cache manager happy...
7046 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7047 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7050 FT_GetTimeOfDay(&StartTime, 0);
7051 ihP = targetptr->handle;
7054 VTakeOffline(volptr);
7055 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7059 optSize = sendBufSize;
7060 tlen = FDH_SIZE(fdP);
7062 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
7065 VTakeOffline(volptr);
7066 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7074 if (Pos + Len > tlen) /* get length we should send */
7075 Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
7078 afs_int32 high, low;
7079 SplitOffsetOrSize(Len, high, low);
7080 assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
7083 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
7086 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
7088 #if FS_STATS_DETAILED
7089 (*a_bytesToFetchP) = Len;
7090 #endif /* FS_STATS_DETAILED */
7092 tbuffer = AllocSendBuffer();
7093 #endif /* HAVE_PIOV */
7102 nBytes = FDH_PREAD(fdP, tbuffer, wlen, Pos);
7103 if (nBytes != wlen) {
7105 FreeSendBuffer((struct afs_buffer *)tbuffer);
7106 VTakeOffline(volptr);
7107 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7111 nBytes = rx_Write(Call, tbuffer, wlen);
7112 #else /* HAVE_PIOV */
7113 nBytes = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
7119 nBytes = FDH_PREADV(fdP, tiov, tnio, Pos);
7120 if (nBytes != wlen) {
7122 VTakeOffline(volptr);
7123 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7127 nBytes = rx_Writev(Call, tiov, tnio, wlen);
7128 #endif /* HAVE_PIOV */
7130 #if FS_STATS_DETAILED
7132 * Bump the number of bytes actually sent by the number from this
7135 (*a_bytesFetchedP) += nBytes;
7136 #endif /* FS_STATS_DETAILED */
7137 if (nBytes != wlen) {
7140 FreeSendBuffer((struct afs_buffer *)tbuffer);
7141 #endif /* HAVE_PIOV */
7147 FreeSendBuffer((struct afs_buffer *)tbuffer);
7148 #endif /* HAVE_PIOV */
7150 FT_GetTimeOfDay(&StopTime, 0);
7152 /* Adjust all Fetch Data related stats */
7154 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
7155 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
7156 AFSCallStats.AccumFetchTime +=
7157 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
7158 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
7160 afs_fsize_t targLen;
7161 VN_GET_LEN(targLen, targetptr);
7162 AFSCallStats.TotalFetchedBytes += targLen;
7163 AFSCallStats.FetchSize1++;
7164 if (targLen < SIZE2)
7165 AFSCallStats.FetchSize2++;
7166 else if (targLen < SIZE3)
7167 AFSCallStats.FetchSize3++;
7168 else if (targLen < SIZE4)
7169 AFSCallStats.FetchSize4++;
7171 AFSCallStats.FetchSize5++;
7176 } /*FetchData_RXStyle */
7179 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
7180 afs_sfsize_t * size)
7182 #ifdef AFS_NAMEI_ENV
7184 lhp = IH_OPEN(V_linkHandle(vp));
7188 *lc = nt_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
7190 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
7195 *size = OS_SIZE(fdP->fd_fd);
7196 return (*size == -1) ? -1 : 0;
7198 struct afs_stat status;
7200 if (afs_fstat(fdP->fd_fd, &status) < 0) {
7204 *lc = GetLinkCount(vp, &status);
7205 *size = status.st_size;
7214 * Implement a client's data store using Rx.
7217 * volptr : Ptr to the given volume's info.
7218 * targetptr : Pointer to the vnode involved.
7219 * Call : Ptr to the Rx call involved.
7220 * Pos : Offset within the file.
7221 * Len : Length in bytes to store; this value is bogus!
7222 * if FS_STATS_DETAILED
7223 * a_bytesToStoreP : Set to the number of bytes to be stored to
7225 * a_bytesStoredP : Set to the actual number of bytes stored to
7230 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
7231 struct client * client, struct rx_call * Call,
7232 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
7234 #if FS_STATS_DETAILED
7235 afs_sfsize_t * a_bytesToStoreP,
7236 afs_sfsize_t * a_bytesStoredP
7237 #endif /* FS_STATS_DETAILED */
7240 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
7241 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
7242 Error errorCode = 0; /* Returned error code to caller */
7244 char *tbuffer; /* data copying buffer */
7245 #else /* HAVE_PIOV */
7246 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
7247 int tnio; /* temp for iovec size */
7248 #endif /* HAVE_PIOV */
7249 afs_sfsize_t tlen; /* temp for xfr length */
7250 Inode tinode; /* inode for I/O */
7251 afs_int32 optSize; /* optimal transfer size */
7252 afs_sfsize_t DataLength = 0; /* size of inode */
7253 afs_sfsize_t TruncatedLength; /* size after ftruncate */
7254 afs_fsize_t NewLength; /* size after this store completes */
7255 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
7256 int linkCount = 0; /* link count on inode */
7257 afs_fsize_t CoW_off, CoW_len;
7259 FdHandle_t *fdP, *origfdP = NULL;
7260 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
7263 #if FS_STATS_DETAILED
7265 * Initialize the byte count arguments.
7267 (*a_bytesToStoreP) = 0;
7268 (*a_bytesStoredP) = 0;
7269 #endif /* FS_STATS_DETAILED */
7272 * We break the callbacks here so that the following signal will not
7275 BreakCallBack(client->host, Fid, 0);
7277 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
7278 /* the inode should have been created in Alloc_NewVnode */
7279 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
7281 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
7282 Fid->Volume, Fid->Vnode, Fid->Unique,
7283 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
7284 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
7285 return ENOENT; /* is this proper error code? */
7288 * See if the file has several links (from other volumes). If it
7289 * does, then we have to make a copy before changing it to avoid
7290 *changing read-only clones of this dude
7293 ("StoreData_RXStyle : Opening inode %s\n",
7294 PrintInode(stmp, VN_GET_INO(targetptr))));
7295 fdP = IH_OPEN(targetptr->handle);
7298 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
7300 VTakeOffline(volptr);
7301 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7306 if (linkCount != 1) {
7309 ("StoreData_RXStyle : inode %s has more than onelink\n",
7310 PrintInode(stmp, VN_GET_INO(targetptr))));
7311 /* other volumes share this data, better copy it first */
7313 /* Adjust the disk block count by the creation of the new inode.
7314 * We call the special VDiskUsage so we don't adjust the volume's
7315 * quota since we don't want to penalyze the user for afs's internal
7316 * mechanisms (i.e. copy on write overhead.) Also the right size
7317 * of the disk will be recorded...
7320 VN_GET_LEN(size, targetptr);
7321 volptr->partition->flags &= ~PART_DONTUPDATE;
7322 VSetPartitionDiskUsage(volptr->partition);
7323 volptr->partition->flags |= PART_DONTUPDATE;
7324 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
7325 volptr->partition->flags &= ~PART_DONTUPDATE;
7330 CoW_len = (FileLength >= (Length + Pos)) ? FileLength - Length : Pos;
7331 CopyOnWrite_calls++;
7332 if (CoW_len == 0) CopyOnWrite_size0++;
7333 if (Pos == 0) CopyOnWrite_off0++;
7334 if (CoW_len > CopyOnWrite_maxsize) CopyOnWrite_maxsize = CoW_len;
7336 ViceLog(1, ("StoreData : calling CopyOnWrite on vnode %u.%u (%s) "
7337 "off 0x0 size 0x%llx\n",
7338 afs_printable_VolumeId_u(V_id(volptr)),
7339 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7340 V_name(volptr), Pos));
7341 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, Pos))) {
7342 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
7343 volptr->partition->flags &= ~PART_DONTUPDATE;
7347 volptr->partition->flags &= ~PART_DONTUPDATE;
7348 VSetPartitionDiskUsage(volptr->partition);
7349 fdP = IH_OPEN(targetptr->handle);
7352 ("StoreData : Reopen after CopyOnWrite failed\n"));
7357 tinode = VN_GET_INO(targetptr);
7359 if (!VALID_INO(tinode)) {
7360 VTakeOffline(volptr);
7361 ViceLog(0,("Volume %u now offline, must be salvaged.\n",
7366 /* compute new file length */
7367 NewLength = DataLength;
7368 if (FileLength < NewLength)
7369 /* simulate truncate */
7370 NewLength = FileLength;
7371 TruncatedLength = NewLength; /* remember length after possible ftruncate */
7372 if (Pos + Length > NewLength)
7373 NewLength = Pos + Length; /* and write */
7375 /* adjust the disk block count by the difference in the files */
7377 afs_fsize_t targSize;
7378 VN_GET_LEN(targSize, targetptr);
7379 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
7382 AdjustDiskUsage(volptr, adjustSize,
7383 adjustSize - SpareComp(volptr)))) {
7385 if (origfdP) FDH_CLOSE(origfdP);
7389 /* can signal cache manager to proceed from close now */
7390 /* this bit means that the locks are set and protections are OK */
7391 rx_SetLocalStatus(Call, 1);
7393 FT_GetTimeOfDay(&StartTime, 0);
7395 optSize = sendBufSize;
7397 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
7398 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
7399 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
7401 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
7402 if (FileLength < DataLength)
7403 FDH_TRUNC(fdP, FileLength);
7404 bytesTransfered = 0;
7406 tbuffer = AllocSendBuffer();
7407 #endif /* HAVE_PIOV */
7408 /* if length == 0, the loop below isn't going to do anything, including
7409 * extend the length of the inode, which it must do, since the file system
7410 * assumes that the inode length == vnode's file length. So, we extend
7411 * the file length manually if need be. Note that if file is bigger than
7412 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7413 * do what we're going to do below.
7415 if (Length == 0 && Pos > TruncatedLength) {
7416 /* Set the file's length; we've already done an lseek to the right
7419 nBytes = FDH_PWRITE(fdP, &tlen, 1, Pos);
7424 errorCode = FDH_TRUNC(fdP, Pos);
7426 /* have some data to copy */
7427 #if FS_STATS_DETAILED
7428 (*a_bytesToStoreP) = Length;
7429 #endif /* FS_STATS_DETAILED */
7432 if (bytesTransfered >= Length) {
7436 tlen = Length - bytesTransfered; /* how much more to do */
7438 rlen = optSize; /* bound by buffer size */
7442 errorCode = rx_Read(Call, tbuffer, rlen);
7443 #else /* HAVE_PIOV */
7444 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7445 #endif /* HAVE_PIOV */
7446 if (errorCode <= 0) {
7450 #if FS_STATS_DETAILED
7451 (*a_bytesStoredP) += errorCode;
7452 #endif /* FS_STATS_DETAILED */
7455 nBytes = FDH_PWRITE(fdP, tbuffer, rlen, Pos);
7456 #else /* HAVE_PIOV */
7457 nBytes = FDH_PWRITEV(fdP, tiov, tnio, Pos);
7458 #endif /* HAVE_PIOV */
7459 if (nBytes != rlen) {
7460 errorCode = VDISKFULL;
7463 bytesTransfered += rlen;
7469 FreeSendBuffer((struct afs_buffer *)tbuffer);
7470 #endif /* HAVE_PIOV */
7475 afs_sfsize_t nfSize = FDH_SIZE(fdP);
7476 assert(nfSize >= 0);
7477 /* something went wrong: adjust size and return */
7478 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7479 /* changed_newTime is tested in StoreData to detemine if we
7480 * need to update the target vnode.
7482 targetptr->changed_newTime = 1;
7483 if (origfdP && (bytesTransfered < Length)) /* Need to "finish" CopyOnWrite still */
7484 CopyOnWrite2(origfdP, fdP, Pos + bytesTransfered, NewLength - Pos - bytesTransfered);
7485 if (origfdP) FDH_CLOSE(origfdP);
7487 /* set disk usage to be correct */
7488 VAdjustDiskUsage(&errorCode, volptr,
7489 (afs_sfsize_t) (nBlocks(nfSize) -
7490 nBlocks(NewLength)), 0);
7493 if (origfdP) { /* finish CopyOnWrite */
7494 if ( (CoW_off = Pos + Length) < NewLength) {
7495 errorCode = CopyOnWrite2(origfdP, fdP, CoW_off, CoW_len = NewLength - CoW_off);
7496 ViceLog(1, ("StoreData : CopyOnWrite2 on vnode %u.%u (%s) "
7497 "off 0x%llx size 0x%llx returns %d\n",
7498 afs_printable_VolumeId_u(V_id(volptr)),
7499 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7500 V_name(volptr), CoW_off, CoW_len, errorCode));
7506 FT_GetTimeOfDay(&StopTime, 0);
7508 VN_SET_LEN(targetptr, NewLength);
7510 /* Update all StoreData related stats */
7512 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7513 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7514 AFSCallStats.StoreSize1++; /* Piggybacked data */
7516 afs_fsize_t targLen;
7517 VN_GET_LEN(targLen, targetptr);
7518 if (targLen < SIZE2)
7519 AFSCallStats.StoreSize2++;
7520 else if (targLen < SIZE3)
7521 AFSCallStats.StoreSize3++;
7522 else if (targLen < SIZE4)
7523 AFSCallStats.StoreSize4++;
7525 AFSCallStats.StoreSize5++;
7530 } /*StoreData_RXStyle */
7532 static int sys2et[512];
7535 init_sys_error_to_et(void)
7537 memset(&sys2et, 0, sizeof(sys2et));
7538 sys2et[EPERM] = UAEPERM;
7539 sys2et[ENOENT] = UAENOENT;
7540 sys2et[ESRCH] = UAESRCH;
7541 sys2et[EINTR] = UAEINTR;
7542 sys2et[EIO] = UAEIO;
7543 sys2et[ENXIO] = UAENXIO;
7544 sys2et[E2BIG] = UAE2BIG;
7545 sys2et[ENOEXEC] = UAENOEXEC;
7546 sys2et[EBADF] = UAEBADF;
7547 sys2et[ECHILD] = UAECHILD;
7548 sys2et[EAGAIN] = UAEAGAIN;
7549 sys2et[ENOMEM] = UAENOMEM;
7550 sys2et[EACCES] = UAEACCES;
7551 sys2et[EFAULT] = UAEFAULT;
7552 sys2et[ENOTBLK] = UAENOTBLK;
7553 sys2et[EBUSY] = UAEBUSY;
7554 sys2et[EEXIST] = UAEEXIST;
7555 sys2et[EXDEV] = UAEXDEV;
7556 sys2et[ENODEV] = UAENODEV;
7557 sys2et[ENOTDIR] = UAENOTDIR;
7558 sys2et[EISDIR] = UAEISDIR;
7559 sys2et[EINVAL] = UAEINVAL;
7560 sys2et[ENFILE] = UAENFILE;
7561 sys2et[EMFILE] = UAEMFILE;
7562 sys2et[ENOTTY] = UAENOTTY;
7563 sys2et[ETXTBSY] = UAETXTBSY;
7564 sys2et[EFBIG] = UAEFBIG;
7565 sys2et[ENOSPC] = UAENOSPC;
7566 sys2et[ESPIPE] = UAESPIPE;
7567 sys2et[EROFS] = UAEROFS;
7568 sys2et[EMLINK] = UAEMLINK;
7569 sys2et[EPIPE] = UAEPIPE;
7570 sys2et[EDOM] = UAEDOM;
7571 sys2et[ERANGE] = UAERANGE;
7572 sys2et[EDEADLK] = UAEDEADLK;
7573 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7574 sys2et[ENOLCK] = UAENOLCK;
7575 sys2et[ENOSYS] = UAENOSYS;
7576 #if (ENOTEMPTY != EEXIST)
7577 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7579 sys2et[ELOOP] = UAELOOP;
7580 #if (EWOULDBLOCK != EAGAIN)
7581 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7583 sys2et[ENOMSG] = UAENOMSG;
7584 sys2et[EIDRM] = UAEIDRM;
7585 sys2et[ECHRNG] = UAECHRNG;
7586 sys2et[EL2NSYNC] = UAEL2NSYNC;
7587 sys2et[EL3HLT] = UAEL3HLT;
7588 sys2et[EL3RST] = UAEL3RST;
7589 sys2et[ELNRNG] = UAELNRNG;
7590 sys2et[EUNATCH] = UAEUNATCH;
7591 sys2et[ENOCSI] = UAENOCSI;
7592 sys2et[EL2HLT] = UAEL2HLT;
7593 sys2et[EBADE] = UAEBADE;
7594 sys2et[EBADR] = UAEBADR;
7595 sys2et[EXFULL] = UAEXFULL;
7596 sys2et[ENOANO] = UAENOANO;
7597 sys2et[EBADRQC] = UAEBADRQC;
7598 sys2et[EBADSLT] = UAEBADSLT;
7599 sys2et[EDEADLK] = UAEDEADLK;
7600 sys2et[EBFONT] = UAEBFONT;
7601 sys2et[ENOSTR] = UAENOSTR;
7602 sys2et[ENODATA] = UAENODATA;
7603 sys2et[ETIME] = UAETIME;
7604 sys2et[ENOSR] = UAENOSR;
7605 sys2et[ENONET] = UAENONET;
7606 sys2et[ENOPKG] = UAENOPKG;
7607 sys2et[EREMOTE] = UAEREMOTE;
7608 sys2et[ENOLINK] = UAENOLINK;
7609 sys2et[EADV] = UAEADV;
7610 sys2et[ESRMNT] = UAESRMNT;
7611 sys2et[ECOMM] = UAECOMM;
7612 sys2et[EPROTO] = UAEPROTO;
7613 sys2et[EMULTIHOP] = UAEMULTIHOP;
7614 sys2et[EDOTDOT] = UAEDOTDOT;
7615 sys2et[EBADMSG] = UAEBADMSG;
7616 sys2et[EOVERFLOW] = UAEOVERFLOW;
7617 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7618 sys2et[EBADFD] = UAEBADFD;
7619 sys2et[EREMCHG] = UAEREMCHG;
7620 sys2et[ELIBACC] = UAELIBACC;
7621 sys2et[ELIBBAD] = UAELIBBAD;
7622 sys2et[ELIBSCN] = UAELIBSCN;
7623 sys2et[ELIBMAX] = UAELIBMAX;
7624 sys2et[ELIBEXEC] = UAELIBEXEC;
7625 sys2et[EILSEQ] = UAEILSEQ;
7626 sys2et[ERESTART] = UAERESTART;
7627 sys2et[ESTRPIPE] = UAESTRPIPE;
7628 sys2et[EUSERS] = UAEUSERS;
7629 sys2et[ENOTSOCK] = UAENOTSOCK;
7630 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7631 sys2et[EMSGSIZE] = UAEMSGSIZE;
7632 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7633 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7634 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7635 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7636 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7637 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7638 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7639 sys2et[EADDRINUSE] = UAEADDRINUSE;
7640 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7641 sys2et[ENETDOWN] = UAENETDOWN;
7642 sys2et[ENETUNREACH] = UAENETUNREACH;
7643 sys2et[ENETRESET] = UAENETRESET;
7644 sys2et[ECONNABORTED] = UAECONNABORTED;
7645 sys2et[ECONNRESET] = UAECONNRESET;
7646 sys2et[ENOBUFS] = UAENOBUFS;
7647 sys2et[EISCONN] = UAEISCONN;
7648 sys2et[ENOTCONN] = UAENOTCONN;
7649 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7650 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7651 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7652 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7653 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7654 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7655 sys2et[EALREADY] = UAEALREADY;
7656 sys2et[EINPROGRESS] = UAEINPROGRESS;
7657 sys2et[ESTALE] = UAESTALE;
7658 sys2et[EUCLEAN] = UAEUCLEAN;
7659 sys2et[ENOTNAM] = UAENOTNAM;
7660 sys2et[ENAVAIL] = UAENAVAIL;
7661 sys2et[EISNAM] = UAEISNAM;
7662 sys2et[EREMOTEIO] = UAEREMOTEIO;
7663 sys2et[EDQUOT] = UAEDQUOT;
7664 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7665 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7667 sys2et[EIO] = UAEIO;
7671 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
7672 * - pass back the connection, client, and host from CallPreamble
7673 * - keep a ref on the client, which we don't now
7674 * - keep a hold on the host, which we already do
7675 * - pass the connection, client, and host down into SAFSS_*, and use
7676 * them instead of independently discovering them via rx_ConnectionOf
7677 * (safe) and rx_GetSpecific (not so safe)
7678 * The idea being that we decide what client and host we're going to use
7679 * when CallPreamble is called, and stay consistent throughout the call.
7680 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
7684 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7686 Error errorCode = 0;
7687 struct rx_connection *tcon;
7688 struct host *tcallhost;
7689 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7691 struct client *tclient;
7692 static struct rx_securityClass *sc = 0;
7694 struct rx_connection *conn;
7697 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost)))
7698 goto Bad_CallBackRxConnAddr1;
7700 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7704 tclient = h_FindClient_r(tcon);
7707 goto Bad_CallBackRxConnAddr;
7709 thost = tclient->host;
7711 /* nothing more can be done */
7712 if ( !thost->interface )
7713 goto Bad_CallBackRxConnAddr;
7715 /* the only address is the primary interface */
7716 /* can't change when there's only 1 address, anyway */
7717 if ( thost->interface->numberOfInterfaces <= 1 )
7718 goto Bad_CallBackRxConnAddr;
7720 /* initialise a security object only once */
7722 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7724 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7726 if ( *addr == thost->interface->addr[i] ) {
7731 if ( *addr != thost->interface->addr[i] )
7732 goto Bad_CallBackRxConnAddr;
7734 conn = rx_NewConnection (thost->interface->addr[i],
7735 thost->port, 1, sc, 0);
7736 rx_SetConnDeadTime(conn, 2);
7737 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7739 errorCode = RXAFSCB_Probe(conn);
7742 if ( thost->callback_rxcon )
7743 rx_DestroyConnection(thost->callback_rxcon);
7744 thost->callback_rxcon = conn;
7746 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7747 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7748 h_ReleaseClient_r(tclient);
7749 /* The hold on thost will be released by CallPostamble */
7751 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7754 rx_DestroyConnection(conn);
7756 Bad_CallBackRxConnAddr:
7757 h_ReleaseClient_r(tclient);
7758 /* The hold on thost will be released by CallPostamble */
7762 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7763 Bad_CallBackRxConnAddr1:
7764 return errorCode; /* failure */
7768 sys_error_to_et(afs_int32 in)
7772 if (in < 0 || in > 511)
7774 if ((in >= VICE_SPECIAL_ERRORS && in <= VIO) || in == VRESTRICTED)
7776 if (sys2et[in] != 0)