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/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;
1119 int rc; /* return code */
1120 IHandle_t *newH; /* Use until finished copying, then cp to vnode. */
1121 FdHandle_t *targFdP; /* Source Inode file handle */
1122 FdHandle_t *newFdP; /* Dest Inode file handle */
1124 if (targetptr->disk.type == vDirectory)
1125 DFlush(); /* just in case? */
1127 VN_GET_LEN(size, targetptr);
1135 buff = (char *)malloc(COPYBUFFSIZE);
1140 ino = VN_GET_INO(targetptr);
1141 if (!VALID_INO(ino)) {
1143 VTakeOffline(volptr);
1144 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
1148 targFdP = IH_OPEN(targetptr->handle);
1149 if (targFdP == NULL) {
1152 ("CopyOnWrite failed: Failed to open target vnode %u in volume %u (errno = %d)\n",
1153 targetptr->vnodeNumber, V_id(volptr), rc));
1155 VTakeOffline(volptr);
1159 nearInode = VN_GET_INO(targetptr);
1161 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1162 VPartitionPath(V_partition(volptr)), nearInode,
1163 V_id(volptr), targetptr->vnodeNumber,
1164 targetptr->disk.uniquifier,
1165 (int)targetptr->disk.dataVersion);
1166 if (!VALID_INO(ino)) {
1168 ("CopyOnWrite failed: Partition %s that contains volume %u may be out of free inodes(errno = %d)\n",
1169 volptr->partition->name, V_id(volptr), errno));
1174 IH_INIT(newH, V_device(volptr), V_id(volptr), ino);
1175 newFdP = IH_OPEN(newH);
1176 assert(newFdP != NULL);
1178 FDH_SEEK(targFdP, off, SEEK_SET);
1179 FDH_SEEK(newFdP, off, SEEK_SET);
1181 if (size > COPYBUFFSIZE) { /* more than a buffer */
1182 length = COPYBUFFSIZE;
1183 size -= COPYBUFFSIZE;
1188 rdlen = FDH_READ(targFdP, buff, length);
1189 if (rdlen == length)
1190 wrlen = FDH_WRITE(newFdP, buff, length);
1193 /* Callers of this function are not prepared to recover
1194 * from error that put the filesystem in an inconsistent
1195 * state. Make sure that we force the volume off-line if
1196 * we some error other than ENOSPC - 4.29.99)
1198 * In case we are unable to write the required bytes, and the
1199 * error code indicates that the disk is full, we roll-back to
1200 * the initial state.
1202 if ((rdlen != length) || (wrlen != length)) {
1203 if ((wrlen < 0) && (errno == ENOSPC)) { /* disk full */
1205 ("CopyOnWrite failed: Partition %s containing volume %u is full\n",
1206 volptr->partition->name, V_id(volptr)));
1207 /* remove destination inode which was partially copied till now */
1208 FDH_REALLYCLOSE(newFdP);
1210 FDH_REALLYCLOSE(targFdP);
1211 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1214 ("CopyOnWrite failed: error %u after i_dec on disk full, volume %u in partition %s needs salvage\n",
1215 rc, V_id(volptr), volptr->partition->name));
1216 VTakeOffline(volptr);
1221 /* length, rdlen, and wrlen may or may not be 64-bits wide;
1222 * since we never do any I/O anywhere near 2^32 bytes at a
1223 * time, just case to an unsigned int for printing */
1226 ("CopyOnWrite failed: volume %u in partition %s (tried reading %u, read %u, wrote %u, errno %u) volume needs salvage\n",
1227 V_id(volptr), volptr->partition->name, (unsigned)length, (unsigned)rdlen,
1228 (unsigned)wrlen, errno));
1229 #if defined(AFS_DEMAND_ATTACH_FS)
1230 ViceLog(0, ("CopyOnWrite failed: requesting salvage\n"));
1232 ViceLog(0, ("CopyOnWrite failed: taking volume offline\n"));
1234 /* Decrement this inode so salvager doesn't find it. */
1235 FDH_REALLYCLOSE(newFdP);
1237 FDH_REALLYCLOSE(targFdP);
1238 rc = IH_DEC(V_linkHandle(volptr), ino, V_parentId(volptr));
1240 VTakeOffline(volptr);
1244 #ifndef AFS_PTHREAD_ENV
1246 #endif /* !AFS_PTHREAD_ENV */
1248 FDH_REALLYCLOSE(targFdP);
1249 rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr),
1250 V_parentId(volptr));
1252 IH_RELEASE(targetptr->handle);
1254 rc = FDH_SYNC(newFdP);
1257 targetptr->handle = newH;
1258 VN_SET_INO(targetptr, ino);
1259 targetptr->disk.cloned = 0;
1260 /* Internal change to vnode, no user level change to volume - def 5445 */
1261 targetptr->changed_oldTime = 1;
1263 return 0; /* success */
1267 CopyOnWrite2(FdHandle_t *targFdP, FdHandle_t *newFdP, afs_foff_t off,
1270 char *buff = malloc(COPYBUFFSIZE);
1276 FDH_SEEK(targFdP, off, SEEK_SET);
1277 FDH_SEEK(newFdP, off, SEEK_SET);
1279 if (size > FDH_SIZE(targFdP) - off)
1280 size = FDH_SIZE(targFdP) - off;
1283 if (size > COPYBUFFSIZE) { /* more than a buffer */
1284 length = COPYBUFFSIZE;
1285 size -= COPYBUFFSIZE;
1290 rdlen = FDH_READ(targFdP, buff, length);
1291 if (rdlen == length)
1292 wrlen = FDH_WRITE(newFdP, buff, length);
1296 if ((rdlen != length) || (wrlen != length)) {
1297 /* no error recovery, at the worst we'll have a "hole"
1309 * Common code to handle with removing the Name (file when it's called from
1310 * SAFS_RemoveFile() or an empty dir when called from SAFS_rmdir()) from a
1311 * given directory, parentptr.
1313 int DT1 = 0, DT0 = 0;
1315 DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr,
1316 DirHandle * dir, AFSFid * fileFid, char *Name, int ChkForDir)
1318 DirHandle childdir; /* Handle for dir package I/O */
1319 Error errorCode = 0;
1322 /* watch for invalid names */
1323 if (!strcmp(Name, ".") || !strcmp(Name, ".."))
1325 if (parentptr->disk.cloned) {
1326 ViceLog(25, ("DeleteTarget : CopyOnWrite called\n"));
1327 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) {
1329 ("DeleteTarget %s: CopyOnWrite failed %d\n", Name,
1335 /* check that the file is in the directory */
1336 SetDirHandle(dir, parentptr);
1337 if (Lookup(dir, Name, fileFid))
1339 fileFid->Volume = V_id(volptr);
1341 /* just-in-case check for something causing deadlock */
1342 if (fileFid->Vnode == parentptr->vnodeNumber)
1345 *targetptr = VGetVnode(&errorCode, volptr, fileFid->Vnode, WRITE_LOCK);
1349 if (ChkForDir == MustBeDIR) {
1350 if ((*targetptr)->disk.type != vDirectory)
1352 } else if ((*targetptr)->disk.type == vDirectory)
1355 /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */
1357 * If the uniquifiers dont match then instead of asserting
1358 * take the volume offline and return VSALVAGE
1360 if ((*targetptr)->disk.uniquifier != fileFid->Unique) {
1361 VTakeOffline(volptr);
1363 ("Volume %u now offline, must be salvaged.\n",
1365 errorCode = VSALVAGE;
1369 if (ChkForDir == MustBeDIR) {
1370 SetDirHandle(&childdir, *targetptr);
1371 if (IsEmpty(&childdir) != 0)
1373 DZap((afs_int32 *) &childdir);
1375 (*targetptr)->delete = 1;
1376 } else if ((--(*targetptr)->disk.linkCount) == 0)
1377 (*targetptr)->delete = 1;
1378 if ((*targetptr)->delete) {
1379 if (VN_GET_INO(*targetptr)) {
1381 IH_REALLYCLOSE((*targetptr)->handle);
1383 IH_DEC(V_linkHandle(volptr), VN_GET_INO(*targetptr),
1384 V_parentId(volptr));
1385 IH_RELEASE((*targetptr)->handle);
1386 if (errorCode == -1) {
1388 ("DT: inode=%s, name=%s, errno=%d\n",
1389 PrintInode(NULL, VN_GET_INO(*targetptr)), Name,
1391 if (errno != ENOENT)
1393 VTakeOffline(volptr);
1395 ("Volume %u now offline, must be salvaged.\n",
1403 VN_SET_INO(*targetptr, (Inode) 0);
1405 afs_fsize_t adjLength;
1406 VN_GET_LEN(adjLength, *targetptr);
1407 VAdjustDiskUsage(&errorCode, volptr, -(int)nBlocks(adjLength), 0);
1411 (*targetptr)->changed_newTime = 1; /* Status change of deleted file/dir */
1413 code = Delete(dir, (char *)Name);
1416 ("Error %d deleting %s\n", code,
1417 (((*targetptr)->disk.type ==
1418 Directory) ? "directory" : "file")));
1419 VTakeOffline(volptr);
1421 ("Volume %u now offline, must be salvaged.\n",
1434 * This routine updates the parent directory's status block after the
1435 * specified operation (i.e. RemoveFile(), CreateFile(), Rename(),
1436 * SymLink(), Link(), MakeDir(), RemoveDir()) on one of its children has
1440 Update_ParentVnodeStatus(Vnode * parentptr, Volume * volptr, DirHandle * dir,
1441 int author, int linkcount,
1442 #if FS_STATS_DETAILED
1443 char a_inSameNetwork
1444 #endif /* FS_STATS_DETAILED */
1447 afs_fsize_t newlength; /* Holds new directory length */
1448 afs_fsize_t parentLength;
1450 #if FS_STATS_DETAILED
1451 Date currDate; /*Current date */
1452 int writeIdx; /*Write index to bump */
1453 int timeIdx; /*Authorship time index to bump */
1454 #endif /* FS_STATS_DETAILED */
1456 parentptr->disk.dataVersion++;
1457 newlength = (afs_fsize_t) Length(dir);
1459 * This is a called on both dir removals (i.e. remove, removedir, rename) but also in dir additions
1460 * (create, symlink, link, makedir) so we need to check if we have enough space
1461 * XXX But we still don't check the error since we're dealing with dirs here and really the increase
1462 * of a new entry would be too tiny to worry about failures (since we have all the existing cushion)
1464 VN_GET_LEN(parentLength, parentptr);
1465 if (nBlocks(newlength) != nBlocks(parentLength)) {
1466 VAdjustDiskUsage(&errorCode, volptr,
1467 (nBlocks(newlength) - nBlocks(parentLength)),
1468 (nBlocks(newlength) - nBlocks(parentLength)));
1470 VN_SET_LEN(parentptr, newlength);
1472 #if FS_STATS_DETAILED
1474 * Update directory write stats for this volume. Note that the auth
1475 * counter is located immediately after its associated ``distance''
1478 if (a_inSameNetwork)
1479 writeIdx = VOL_STATS_SAME_NET;
1481 writeIdx = VOL_STATS_DIFF_NET;
1482 V_stat_writes(volptr, writeIdx)++;
1483 if (author != AnonymousID) {
1484 V_stat_writes(volptr, writeIdx + 1)++;
1488 * Update the volume's authorship information in response to this
1489 * directory operation. Get the current time, decide to which time
1490 * slot this operation belongs, and bump the appropriate slot.
1492 currDate = (FT_ApproxTime() - parentptr->disk.unixModifyTime);
1494 (currDate < VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1495 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1496 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1497 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1498 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 : VOL_STATS_TIME_IDX_5);
1499 if (parentptr->disk.author == author) {
1500 V_stat_dirSameAuthor(volptr, timeIdx)++;
1502 V_stat_dirDiffAuthor(volptr, timeIdx)++;
1504 #endif /* FS_STATS_DETAILED */
1506 parentptr->disk.author = author;
1507 parentptr->disk.linkCount = linkcount;
1508 parentptr->disk.unixModifyTime = FT_ApproxTime(); /* This should be set from CLIENT!! */
1509 parentptr->disk.serverModifyTime = FT_ApproxTime();
1510 parentptr->changed_newTime = 1; /* vnode changed, write it back. */
1515 * Update the target file's (or dir's) status block after the specified
1516 * operation is complete. Note that some other fields maybe updated by
1517 * the individual module.
1520 /* XXX INCOMPLETE - More attention is needed here! */
1522 Update_TargetVnodeStatus(Vnode * targetptr, afs_uint32 Caller,
1523 struct client *client, AFSStoreStatus * InStatus,
1524 Vnode * parentptr, Volume * volptr,
1527 #if FS_STATS_DETAILED
1528 Date currDate; /*Current date */
1529 int writeIdx; /*Write index to bump */
1530 int timeIdx; /*Authorship time index to bump */
1531 #endif /* FS_STATS_DETAILED */
1533 if (Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR)) { /* initialize new file */
1534 targetptr->disk.parent = parentptr->vnodeNumber;
1535 VN_SET_LEN(targetptr, length);
1536 /* targetptr->disk.group = 0; save some cycles */
1537 targetptr->disk.modeBits = 0777;
1538 targetptr->disk.owner = client->ViceId;
1539 targetptr->disk.dataVersion = 0; /* consistent with the client */
1540 targetptr->disk.linkCount = (Caller & TVS_MKDIR ? 2 : 1);
1541 /* the inode was created in Alloc_NewVnode() */
1543 #if FS_STATS_DETAILED
1545 * Update file write stats for this volume. Note that the auth
1546 * counter is located immediately after its associated ``distance''
1549 if (client->InSameNetwork)
1550 writeIdx = VOL_STATS_SAME_NET;
1552 writeIdx = VOL_STATS_DIFF_NET;
1553 V_stat_writes(volptr, writeIdx)++;
1554 if (client->ViceId != AnonymousID) {
1555 V_stat_writes(volptr, writeIdx + 1)++;
1559 * We only count operations that DON'T involve creating new objects
1560 * (files, symlinks, directories) or simply setting status as
1561 * authorship-change operations.
1563 if (!(Caller & (TVS_CFILE | TVS_SLINK | TVS_MKDIR | TVS_SSTATUS))) {
1565 * Update the volume's authorship information in response to this
1566 * file operation. Get the current time, decide to which time
1567 * slot this operation belongs, and bump the appropriate slot.
1569 currDate = (FT_ApproxTime() - targetptr->disk.unixModifyTime);
1572 VOL_STATS_TIME_CAP_0 ? VOL_STATS_TIME_IDX_0 : currDate <
1573 VOL_STATS_TIME_CAP_1 ? VOL_STATS_TIME_IDX_1 : currDate <
1574 VOL_STATS_TIME_CAP_2 ? VOL_STATS_TIME_IDX_2 : currDate <
1575 VOL_STATS_TIME_CAP_3 ? VOL_STATS_TIME_IDX_3 : currDate <
1576 VOL_STATS_TIME_CAP_4 ? VOL_STATS_TIME_IDX_4 :
1577 VOL_STATS_TIME_IDX_5);
1578 if (targetptr->disk.author == client->ViceId) {
1579 V_stat_fileSameAuthor(volptr, timeIdx)++;
1581 V_stat_fileDiffAuthor(volptr, timeIdx)++;
1584 #endif /* FS_STATS_DETAILED */
1586 if (!(Caller & TVS_SSTATUS))
1587 targetptr->disk.author = client->ViceId;
1588 if (Caller & TVS_SDATA) {
1589 targetptr->disk.dataVersion++;
1590 if (VanillaUser(client)) {
1591 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1592 #ifdef CREATE_SGUID_ADMIN_ONLY
1593 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1597 if (Caller & TVS_SSTATUS) { /* update time on non-status change */
1598 /* store status, must explicitly request to change the date */
1599 if (InStatus->Mask & AFS_SETMODTIME)
1600 targetptr->disk.unixModifyTime = InStatus->ClientModTime;
1601 } else { /* other: date always changes, but perhaps to what is specified by caller */
1602 targetptr->disk.unixModifyTime =
1603 (InStatus->Mask & AFS_SETMODTIME ? InStatus->
1604 ClientModTime : FT_ApproxTime());
1606 if (InStatus->Mask & AFS_SETOWNER) {
1607 /* admin is allowed to do chmod, chown as well as chown, chmod. */
1608 if (VanillaUser(client)) {
1609 targetptr->disk.modeBits &= ~04000; /* turn off suid for file. */
1610 #ifdef CREATE_SGUID_ADMIN_ONLY
1611 targetptr->disk.modeBits &= ~02000; /* turn off sgid for file. */
1614 targetptr->disk.owner = InStatus->Owner;
1615 if (VolumeRootVnode(targetptr)) {
1616 Error errorCode = 0; /* what should be done with this? */
1618 V_owner(targetptr->volumePtr) = InStatus->Owner;
1619 VUpdateVolume(&errorCode, targetptr->volumePtr);
1622 if (InStatus->Mask & AFS_SETMODE) {
1623 int modebits = InStatus->UnixModeBits;
1624 #define CREATE_SGUID_ADMIN_ONLY 1
1625 #ifdef CREATE_SGUID_ADMIN_ONLY
1626 if (VanillaUser(client))
1627 modebits = modebits & 0777;
1629 if (VanillaUser(client)) {
1630 targetptr->disk.modeBits = modebits;
1632 targetptr->disk.modeBits = modebits;
1635 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1636 CHK_STOREDATA, AUD_END);
1640 osi_audit(PrivSetID, 0, AUD_ID, client->ViceId, AUD_INT,
1641 CHK_STORESTATUS, AUD_END);
1648 targetptr->disk.serverModifyTime = FT_ApproxTime();
1649 if (InStatus->Mask & AFS_SETGROUP)
1650 targetptr->disk.group = InStatus->Group;
1651 /* vnode changed : to be written back by VPutVnode */
1652 targetptr->changed_newTime = 1;
1654 } /*Update_TargetVnodeStatus */
1658 * Fills the CallBack structure with the expiration time and type of callback
1659 * structure. Warning: this function is currently incomplete.
1662 SetCallBackStruct(afs_uint32 CallBackTime, struct AFSCallBack *CallBack)
1664 /* CallBackTime could not be 0 */
1665 if (CallBackTime == 0) {
1666 ViceLog(0, ("WARNING: CallBackTime == 0!\n"));
1667 CallBack->ExpirationTime = 0;
1669 CallBack->ExpirationTime = CallBackTime - FT_ApproxTime();
1670 CallBack->CallBackVersion = CALLBACK_VERSION;
1671 CallBack->CallBackType = CB_SHARED; /* The default for now */
1673 } /*SetCallBackStruct */
1677 * Adjusts (Subtract) "length" number of blocks from the volume's disk
1678 * allocation; if some error occured (exceeded volume quota or partition
1679 * was full, or whatever), it frees the space back and returns the code.
1680 * We usually pre-adjust the volume space to make sure that there's
1681 * enough space before consuming some.
1684 AdjustDiskUsage(Volume * volptr, afs_sfsize_t length,
1685 afs_sfsize_t checkLength)
1690 VAdjustDiskUsage(&rc, volptr, length, checkLength);
1692 VAdjustDiskUsage(&nc, volptr, -length, 0);
1693 if (rc == VOVERQUOTA) {
1695 ("Volume %u (%s) is full\n", V_id(volptr),
1699 if (rc == VDISKFULL) {
1701 ("Partition %s that contains volume %u is full\n",
1702 volptr->partition->name, V_id(volptr)));
1705 ViceLog(0, ("Got error return %d from VAdjustDiskUsage\n", rc));
1710 } /*AdjustDiskUsage */
1713 * Common code that handles the creation of a new file (SAFS_CreateFile and
1714 * SAFS_Symlink) or a new dir (SAFS_MakeDir)
1717 Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr,
1718 Vnode ** targetptr, char *Name, struct AFSFid *OutFid,
1719 int FileType, afs_sfsize_t BlocksPreallocatedForVnode)
1721 Error errorCode = 0; /* Error code returned back */
1724 Inode nearInode; /* hint for inode allocation in solaris */
1727 AdjustDiskUsage(volptr, BlocksPreallocatedForVnode,
1728 BlocksPreallocatedForVnode))) {
1730 ("Insufficient space to allocate %" AFS_INT64_FMT " blocks\n",
1731 (afs_intmax_t) BlocksPreallocatedForVnode));
1735 *targetptr = VAllocVnode(&errorCode, volptr, FileType);
1736 if (errorCode != 0) {
1737 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1740 OutFid->Volume = V_id(volptr);
1741 OutFid->Vnode = (*targetptr)->vnodeNumber;
1742 OutFid->Unique = (*targetptr)->disk.uniquifier;
1744 nearInode = VN_GET_INO(parentptr); /* parent is also in same vol */
1746 /* create the inode now itself */
1748 IH_CREATE(V_linkHandle(volptr), V_device(volptr),
1749 VPartitionPath(V_partition(volptr)), nearInode,
1750 V_id(volptr), (*targetptr)->vnodeNumber,
1751 (*targetptr)->disk.uniquifier, 1);
1753 /* error in creating inode */
1754 if (!VALID_INO(inode)) {
1756 ("Volume : %u vnode = %u Failed to create inode: errno = %d\n",
1757 (*targetptr)->volumePtr->header->diskstuff.id,
1758 (*targetptr)->vnodeNumber, errno));
1759 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1760 (*targetptr)->delete = 1; /* delete vnode */
1763 VN_SET_INO(*targetptr, inode);
1764 IH_INIT(((*targetptr)->handle), V_device(volptr), V_id(volptr), inode);
1766 /* copy group from parent dir */
1767 (*targetptr)->disk.group = parentptr->disk.group;
1769 if (parentptr->disk.cloned) {
1770 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite called\n"));
1771 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE))) { /* disk full */
1772 ViceLog(25, ("Alloc_NewVnode : CopyOnWrite failed\n"));
1773 /* delete the vnode previously allocated */
1774 (*targetptr)->delete = 1;
1775 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1776 IH_REALLYCLOSE((*targetptr)->handle);
1777 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1779 ("Alloc_NewVnode: partition %s idec %s failed\n",
1780 volptr->partition->name, PrintInode(NULL, inode)));
1781 IH_RELEASE((*targetptr)->handle);
1787 /* add the name to the directory */
1788 SetDirHandle(dir, parentptr);
1789 if ((errorCode = Create(dir, (char *)Name, OutFid))) {
1790 (*targetptr)->delete = 1;
1791 VAdjustDiskUsage(&temp, volptr, -BlocksPreallocatedForVnode, 0);
1792 IH_REALLYCLOSE((*targetptr)->handle);
1793 if (IH_DEC(V_linkHandle(volptr), inode, V_parentId(volptr)))
1795 ("Alloc_NewVnode: partition %s idec %s failed\n",
1796 volptr->partition->name, PrintInode(NULL, inode)));
1797 IH_RELEASE((*targetptr)->handle);
1803 } /*Alloc_NewVnode */
1807 * Handle all the lock-related code (SAFS_SetLock, SAFS_ExtendLock and
1811 HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType)
1813 int Time; /* Used for time */
1814 int writeVnode = targetptr->changed_oldTime; /* save original status */
1816 targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */
1817 Time = FT_ApproxTime();
1818 switch (LockingType) {
1821 if (Time > targetptr->disk.lock.lockTime)
1822 targetptr->disk.lock.lockTime = targetptr->disk.lock.lockCount =
1824 Time += AFS_LOCKWAIT;
1825 if (LockingType == LockRead) {
1826 if ( !(rights & PRSFS_LOCK) &&
1827 !(rights & PRSFS_WRITE) &&
1828 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1831 if (targetptr->disk.lock.lockCount >= 0) {
1832 ++(targetptr->disk.lock.lockCount);
1833 targetptr->disk.lock.lockTime = Time;
1836 } else if (LockingType == LockWrite) {
1837 if ( !(rights & PRSFS_WRITE) &&
1838 !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) )
1841 if (targetptr->disk.lock.lockCount == 0) {
1842 targetptr->disk.lock.lockCount = -1;
1843 targetptr->disk.lock.lockTime = Time;
1849 Time += AFS_LOCKWAIT;
1850 if (targetptr->disk.lock.lockCount != 0)
1851 targetptr->disk.lock.lockTime = Time;
1856 if ((--targetptr->disk.lock.lockCount) <= 0)
1857 targetptr->disk.lock.lockCount = targetptr->disk.lock.lockTime =
1861 targetptr->changed_oldTime = writeVnode; /* restore old status */
1862 ViceLog(0, ("Illegal Locking type %d\n", LockingType));
1865 } /*HandleLocking */
1867 /* 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. */
1870 CheckWriteMode(Vnode * targetptr, afs_int32 rights, int Prfs_Mode)
1874 if (!(rights & Prfs_Mode))
1876 if ((targetptr->disk.type != vDirectory)
1877 && (!(targetptr->disk.modeBits & OWNERWRITE)))
1883 * If some flags (i.e. min or max quota) are set, the volume's in disk
1884 * label is updated; Name, OfflineMsg, and Motd are also reflected in the
1885 * update, if applicable.
1888 RXUpdate_VolumeStatus(Volume * volptr, AFSStoreVolumeStatus * StoreVolStatus,
1889 char *Name, char *OfflineMsg, char *Motd)
1891 Error errorCode = 0;
1893 if (StoreVolStatus->Mask & AFS_SETMINQUOTA)
1894 V_minquota(volptr) = StoreVolStatus->MinQuota;
1895 if (StoreVolStatus->Mask & AFS_SETMAXQUOTA)
1896 V_maxquota(volptr) = StoreVolStatus->MaxQuota;
1897 if (strlen(OfflineMsg) > 0) {
1898 strcpy(V_offlineMessage(volptr), OfflineMsg);
1900 if (strlen(Name) > 0) {
1901 strcpy(V_name(volptr), Name);
1903 #if OPENAFS_VOL_STATS
1905 * We don't overwrite the motd field, since it's now being used
1909 if (strlen(Motd) > 0) {
1910 strcpy(V_motd(volptr), Motd);
1912 #endif /* FS_STATS_DETAILED */
1913 VUpdateVolume(&errorCode, volptr);
1916 } /*RXUpdate_VolumeStatus */
1920 RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
1921 char **motd, Volume * volptr)
1925 status->Vid = V_id(volptr);
1926 status->ParentId = V_parentId(volptr);
1927 status->Online = V_inUse(volptr);
1928 status->InService = V_inService(volptr);
1929 status->Blessed = V_blessed(volptr);
1930 status->NeedsSalvage = V_needsSalvaged(volptr);
1931 if (VolumeWriteable(volptr))
1932 status->Type = ReadWrite;
1934 status->Type = ReadOnly;
1935 status->MinQuota = V_minquota(volptr);
1936 status->MaxQuota = V_maxquota(volptr);
1937 status->BlocksInUse = V_diskused(volptr);
1938 status->PartBlocksAvail = RoundInt64ToInt32(volptr->partition->free);
1939 status->PartMaxBlocks = RoundInt64ToInt32(volptr->partition->totalUsable);
1941 /* now allocate and copy these things; they're freed by the RXGEN stub */
1942 temp = strlen(V_name(volptr)) + 1;
1943 *name = malloc(temp);
1945 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1948 strcpy(*name, V_name(volptr));
1949 temp = strlen(V_offlineMessage(volptr)) + 1;
1950 *offMsg = malloc(temp);
1952 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1955 strcpy(*offMsg, V_offlineMessage(volptr));
1956 #if OPENAFS_VOL_STATS
1959 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1962 strcpy(*motd, nullString);
1964 temp = strlen(V_motd(volptr)) + 1;
1965 *motd = malloc(temp);
1967 ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
1970 strcpy(*motd, V_motd(volptr));
1971 #endif /* FS_STATS_DETAILED */
1973 } /*RXGetVolumeStatus */
1977 FileNameOK(char *aname)
1982 /* watch for @sys on the right */
1983 if (strcmp(aname + i - 4, "@sys") == 0)
1986 while ((tc = *aname++)) {
1988 return 0; /* very bad character to encounter */
1990 return 1; /* file name is ok */
1996 * This variant of symlink is expressly to support the AFS/DFS translator
1997 * and is not supported by the AFS fileserver. We just return EINVAL.
1998 * The cache manager should not generate this call to an AFS cache manager.
2001 SRXAFS_DFSSymlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
2002 char *LinkContents, struct AFSStoreStatus *InStatus,
2003 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
2004 struct AFSFetchStatus *OutDirStatus,
2005 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2011 SRXAFS_FsCmd(struct rx_call * acall, struct AFSFid * Fid,
2012 struct FsCmdInputs * Inputs,
2013 struct FsCmdOutputs * Outputs)
2017 switch (Inputs->command) {
2021 ViceLog(1,("FsCmd: cmd = %d, code=%d\n",
2022 Inputs->command, Outputs->code));
2027 static struct afs_buffer {
2028 struct afs_buffer *next;
2029 } *freeBufferList = 0;
2030 static int afs_buffersAlloced = 0;
2033 FreeSendBuffer(struct afs_buffer *adata)
2036 afs_buffersAlloced--;
2037 adata->next = freeBufferList;
2038 freeBufferList = adata;
2042 } /*FreeSendBuffer */
2044 /* allocate space for sender */
2048 struct afs_buffer *tp;
2051 afs_buffersAlloced++;
2052 if (!freeBufferList) {
2055 tmp = malloc(sendBufSize);
2057 ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
2062 tp = freeBufferList;
2063 freeBufferList = tp->next;
2067 } /*AllocSendBuffer */
2068 #endif /* AFS_NT40_ENV */
2071 * This routine returns the status info associated with the targetptr vnode
2072 * in the AFSFetchStatus structure. Some of the newer fields, such as
2073 * SegSize and Group are not yet implemented
2077 GetStatus(Vnode * targetptr, AFSFetchStatus * status, afs_int32 rights,
2078 afs_int32 anyrights, Vnode * parentptr)
2080 /* initialize return status from a vnode */
2081 status->InterfaceVersion = 1;
2082 status->SyncCounter = status->dataVersionHigh = status->lockCount =
2083 status->errorCode = 0;
2084 status->ResidencyMask = 1; /* means for MR-AFS: file in /vicepr-partition */
2085 if (targetptr->disk.type == vFile)
2086 status->FileType = File;
2087 else if (targetptr->disk.type == vDirectory)
2088 status->FileType = Directory;
2089 else if (targetptr->disk.type == vSymlink)
2090 status->FileType = SymbolicLink;
2092 status->FileType = Invalid; /*invalid type field */
2093 status->LinkCount = targetptr->disk.linkCount;
2095 afs_fsize_t targetLen;
2096 VN_GET_LEN(targetLen, targetptr);
2097 SplitOffsetOrSize(targetLen, status->Length_hi, status->Length);
2099 status->DataVersion = targetptr->disk.dataVersion;
2100 status->Author = targetptr->disk.author;
2101 status->Owner = targetptr->disk.owner;
2102 status->CallerAccess = rights;
2103 status->AnonymousAccess = anyrights;
2104 status->UnixModeBits = targetptr->disk.modeBits;
2105 status->ClientModTime = targetptr->disk.unixModifyTime; /* This might need rework */
2106 status->ParentVnode =
2107 (status->FileType ==
2108 Directory ? targetptr->vnodeNumber : parentptr->vnodeNumber);
2109 status->ParentUnique =
2110 (status->FileType ==
2111 Directory ? targetptr->disk.uniquifier : parentptr->disk.uniquifier);
2112 status->ServerModTime = targetptr->disk.serverModifyTime;
2113 status->Group = targetptr->disk.group;
2114 status->lockCount = targetptr->disk.lock.lockCount;
2115 status->errorCode = 0;
2121 common_FetchData64(struct rx_call *acall, struct AFSFid *Fid,
2122 afs_sfsize_t Pos, afs_sfsize_t Len,
2123 struct AFSFetchStatus *OutStatus,
2124 struct AFSCallBack *CallBack, struct AFSVolSync *Sync,
2127 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2128 Vnode *parentwhentargetnotdir = 0; /* parent vnode if vptr is a file */
2129 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2130 Error errorCode = 0; /* return code to caller */
2131 Error fileCode = 0; /* return code from vol package */
2132 Volume *volptr = 0; /* pointer to the volume */
2133 struct client *client = 0; /* pointer to the client data */
2134 struct rx_connection *tcon; /* the connection we're part of */
2136 afs_int32 rights, anyrights; /* rights for this and any user */
2137 struct client *t_client = NULL; /* tmp ptr to client data */
2138 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2139 #if FS_STATS_DETAILED
2140 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2141 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2142 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2143 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2144 struct timeval elapsedTime; /* Transfer time */
2145 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2146 afs_sfsize_t bytesXferred; /* # bytes actually xferred */
2147 int readIdx; /* Index of read stats array to bump */
2148 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2151 * Set our stats pointers, remember when the RPC operation started, and
2152 * tally the operation.
2154 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHDATA]);
2155 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_FETCHDATA]);
2159 FT_GetTimeOfDay(&opStartTime, 0);
2160 #endif /* FS_STATS_DETAILED */
2163 ("SRXAFS_FetchData, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2166 AFSCallStats.FetchData++, AFSCallStats.TotalCalls++;
2168 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2171 /* Get ptr to client data for user Id for logging */
2172 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2173 logHostAddr.s_addr = rxr_HostOf(tcon);
2175 ("SRXAFS_FetchData, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2176 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2177 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2179 * Get volume/vnode for the fetched file; caller's access rights to
2180 * it are also returned
2183 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2184 &parentwhentargetnotdir, &client, READ_LOCK,
2185 &rights, &anyrights)))
2188 SetVolumeSync(Sync, volptr);
2190 #if FS_STATS_DETAILED
2192 * Remember that another read operation was performed.
2195 if (client->InSameNetwork)
2196 readIdx = VOL_STATS_SAME_NET;
2198 readIdx = VOL_STATS_DIFF_NET;
2199 V_stat_reads(volptr, readIdx)++;
2200 if (client->ViceId != AnonymousID) {
2201 V_stat_reads(volptr, readIdx + 1)++;
2204 #endif /* FS_STATS_DETAILED */
2205 /* Check whether the caller has permission access to fetch the data */
2207 Check_PermissionRights(targetptr, client, rights, CHK_FETCHDATA, 0)))
2211 * Drop the read lock on the parent directory after saving the parent
2212 * vnode information we need to pass to GetStatus
2214 if (parentwhentargetnotdir != NULL) {
2215 tparentwhentargetnotdir = *parentwhentargetnotdir;
2216 VPutVnode(&fileCode, parentwhentargetnotdir);
2217 assert(!fileCode || (fileCode == VSALVAGE));
2218 parentwhentargetnotdir = NULL;
2220 #if FS_STATS_DETAILED
2222 * Remember when the data transfer started.
2224 FT_GetTimeOfDay(&xferStartTime, 0);
2225 #endif /* FS_STATS_DETAILED */
2227 /* actually do the data transfer */
2228 #if FS_STATS_DETAILED
2230 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type,
2231 &bytesToXfer, &bytesXferred);
2234 FetchData_RXStyle(volptr, targetptr, acall, Pos, Len, type)))
2236 #endif /* FS_STATS_DETAILED */
2238 #if FS_STATS_DETAILED
2240 * At this point, the data transfer is done, for good or ill. Remember
2241 * when the transfer ended, bump the number of successes/failures, and
2242 * integrate the transfer size and elapsed time into the stats. If the
2243 * operation failed, we jump to the appropriate point.
2245 FT_GetTimeOfDay(&xferStopTime, 0);
2247 (xferP->numXfers)++;
2249 (xferP->numSuccesses)++;
2252 * Bump the xfer sum by the number of bytes actually sent, NOT the
2255 tot_bytesXferred += bytesXferred;
2256 (xferP->sumBytes) += (tot_bytesXferred >> 10);
2257 tot_bytesXferred &= 0x3FF;
2258 if (bytesXferred < xferP->minBytes)
2259 xferP->minBytes = bytesXferred;
2260 if (bytesXferred > xferP->maxBytes)
2261 xferP->maxBytes = bytesXferred;
2264 * Tally the size of the object. Note: we tally the actual size,
2265 * NOT the number of bytes that made it out over the wire.
2267 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
2268 (xferP->count[0])++;
2269 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
2270 (xferP->count[1])++;
2271 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
2272 (xferP->count[2])++;
2273 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
2274 (xferP->count[3])++;
2275 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
2276 (xferP->count[4])++;
2277 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
2278 (xferP->count[5])++;
2279 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
2280 (xferP->count[6])++;
2281 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
2282 (xferP->count[7])++;
2284 (xferP->count[8])++;
2286 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
2287 fs_stats_AddTo((xferP->sumTime), elapsedTime);
2288 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
2289 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
2290 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
2292 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
2293 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
2298 * Finally, go off to tell our caller the bad news in case the
2303 #endif /* FS_STATS_DETAILED */
2305 /* write back the OutStatus from the target vnode */
2306 GetStatus(targetptr, OutStatus, rights, anyrights,
2307 &tparentwhentargetnotdir);
2309 /* if a r/w volume, promise a callback to the caller */
2310 if (VolumeWriteable(volptr))
2311 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2313 struct AFSFid myFid;
2314 memset(&myFid, 0, sizeof(struct AFSFid));
2315 myFid.Volume = Fid->Volume;
2316 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2320 /* Update and store volume/vnode and parent vnodes back */
2321 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2323 ViceLog(2, ("SRXAFS_FetchData returns %d\n", errorCode));
2324 errorCode = CallPostamble(tcon, errorCode, thost);
2326 #if FS_STATS_DETAILED
2327 FT_GetTimeOfDay(&opStopTime, 0);
2328 if (errorCode == 0) {
2330 (opP->numSuccesses)++;
2331 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2332 fs_stats_AddTo((opP->sumTime), elapsedTime);
2333 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2334 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2335 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2337 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2338 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2342 #endif /* FS_STATS_DETAILED */
2344 osi_auditU(acall, FetchDataEvent, errorCode,
2345 AUD_ID, t_client ? t_client->ViceId : 0,
2346 AUD_FID, Fid, AUD_END);
2349 } /*SRXAFS_FetchData */
2352 SRXAFS_FetchData(struct rx_call * acall, struct AFSFid * Fid, afs_int32 Pos,
2353 afs_int32 Len, struct AFSFetchStatus * OutStatus,
2354 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2356 return common_FetchData64(acall, Fid, Pos, Len, OutStatus, CallBack,
2361 SRXAFS_FetchData64(struct rx_call * acall, struct AFSFid * Fid, afs_int64 Pos,
2362 afs_int64 Len, struct AFSFetchStatus * OutStatus,
2363 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2366 afs_sfsize_t tPos, tLen;
2368 #ifdef AFS_64BIT_ENV
2369 tPos = (afs_sfsize_t) Pos;
2370 tLen = (afs_sfsize_t) Len;
2371 #else /* AFS_64BIT_ENV */
2372 if (Pos.high || Len.high)
2376 #endif /* AFS_64BIT_ENV */
2379 common_FetchData64(acall, Fid, tPos, tLen, OutStatus, CallBack, Sync,
2385 SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
2386 struct AFSOpaque * AccessList,
2387 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
2389 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2390 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2391 Error errorCode = 0; /* return error code to caller */
2392 Volume *volptr = 0; /* pointer to the volume */
2393 struct client *client = 0; /* pointer to the client data */
2394 afs_int32 rights, anyrights; /* rights for this and any user */
2395 struct rx_connection *tcon = rx_ConnectionOf(acall);
2397 struct client *t_client = NULL; /* tmp ptr to client data */
2398 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2399 #if FS_STATS_DETAILED
2400 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2401 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2402 struct timeval elapsedTime; /* Transfer time */
2405 * Set our stats pointer, remember when the RPC operation started, and
2406 * tally the operation.
2408 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHACL]);
2412 FT_GetTimeOfDay(&opStartTime, 0);
2413 #endif /* FS_STATS_DETAILED */
2416 ("SAFS_FetchACL, Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
2419 AFSCallStats.FetchACL++, AFSCallStats.TotalCalls++;
2421 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2424 /* Get ptr to client data for user Id for logging */
2425 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2426 logHostAddr.s_addr = rxr_HostOf(tcon);
2428 ("SAFS_FetchACL, Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
2429 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2430 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2432 AccessList->AFSOpaque_len = 0;
2433 AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
2434 if (!AccessList->AFSOpaque_val) {
2435 ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
2440 * Get volume/vnode for the fetched file; caller's access rights to it
2444 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2445 &parentwhentargetnotdir, &client, READ_LOCK,
2446 &rights, &anyrights)))
2449 SetVolumeSync(Sync, volptr);
2451 /* Check whether we have permission to fetch the ACL */
2453 Check_PermissionRights(targetptr, client, rights, CHK_FETCHACL, 0)))
2456 /* Get the Access List from the dir's vnode */
2458 RXFetch_AccessList(targetptr, parentwhentargetnotdir, AccessList)))
2461 /* Get OutStatus back From the target Vnode */
2462 GetStatus(targetptr, OutStatus, rights, anyrights,
2463 parentwhentargetnotdir);
2466 /* Update and store volume/vnode and parent vnodes back */
2467 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2470 ("SAFS_FetchACL returns %d (ACL=%s)\n", errorCode,
2471 AccessList->AFSOpaque_val));
2472 errorCode = CallPostamble(tcon, errorCode, thost);
2474 #if FS_STATS_DETAILED
2475 FT_GetTimeOfDay(&opStopTime, 0);
2476 if (errorCode == 0) {
2478 (opP->numSuccesses)++;
2479 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2480 fs_stats_AddTo((opP->sumTime), elapsedTime);
2481 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2482 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2483 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2485 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2486 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2490 #endif /* FS_STATS_DETAILED */
2492 osi_auditU(acall, FetchACLEvent, errorCode,
2493 AUD_ID, t_client ? t_client->ViceId : 0,
2495 AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
2497 } /*SRXAFS_FetchACL */
2501 * This routine is called exclusively by SRXAFS_FetchStatus(), and should be
2502 * merged into it when possible.
2506 SAFSS_FetchStatus(struct rx_call *acall, struct AFSFid *Fid,
2507 struct AFSFetchStatus *OutStatus,
2508 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
2510 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2511 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2512 Error errorCode = 0; /* return code to caller */
2513 Volume *volptr = 0; /* pointer to the volume */
2514 struct client *client = 0; /* pointer to the client data */
2515 afs_int32 rights, anyrights; /* rights for this and any user */
2516 struct client *t_client = NULL; /* tmp ptr to client data */
2517 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2518 struct rx_connection *tcon = rx_ConnectionOf(acall);
2520 /* Get ptr to client data for user Id for logging */
2521 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2522 logHostAddr.s_addr = rxr_HostOf(tcon);
2524 ("SAFS_FetchStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
2525 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
2526 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
2528 AFSCallStats.FetchStatus++, AFSCallStats.TotalCalls++;
2531 * Get volume/vnode for the fetched file; caller's rights to it are
2535 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
2536 &parentwhentargetnotdir, &client, READ_LOCK,
2537 &rights, &anyrights)))
2538 goto Bad_FetchStatus;
2540 /* set volume synchronization information */
2541 SetVolumeSync(Sync, volptr);
2543 /* Are we allowed to fetch Fid's status? */
2544 if (targetptr->disk.type != vDirectory) {
2546 Check_PermissionRights(targetptr, client, rights,
2547 CHK_FETCHSTATUS, 0))) {
2548 if (rx_GetCallAbortCode(acall) == errorCode)
2549 rx_SetCallAbortCode(acall, 0);
2550 goto Bad_FetchStatus;
2554 /* set OutStatus From the Fid */
2555 GetStatus(targetptr, OutStatus, rights, anyrights,
2556 parentwhentargetnotdir);
2558 /* If a r/w volume, also set the CallBack state */
2559 if (VolumeWriteable(volptr))
2560 SetCallBackStruct(AddCallBack(client->host, Fid), CallBack);
2562 struct AFSFid myFid;
2563 memset(&myFid, 0, sizeof(struct AFSFid));
2564 myFid.Volume = Fid->Volume;
2565 SetCallBackStruct(AddVolCallBack(client->host, &myFid), CallBack);
2569 /* Update and store volume/vnode and parent vnodes back */
2570 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2572 ViceLog(2, ("SAFS_FetchStatus returns %d\n", errorCode));
2575 } /*SAFSS_FetchStatus */
2579 SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2580 struct AFSBulkStats * OutStats, struct AFSCBs * CallBacks,
2581 struct AFSVolSync * Sync)
2585 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2586 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2587 Error errorCode = 0; /* return code to caller */
2588 Volume *volptr = 0; /* pointer to the volume */
2589 struct client *client = 0; /* pointer to the client data */
2590 afs_int32 rights, anyrights; /* rights for this and any user */
2591 struct AFSFid *tfid; /* file id we're dealing with now */
2592 struct rx_connection *tcon = rx_ConnectionOf(acall);
2594 struct client *t_client = NULL; /* tmp pointer to the client data */
2595 #if FS_STATS_DETAILED
2596 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2597 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2598 struct timeval elapsedTime; /* Transfer time */
2601 * Set our stats pointer, remember when the RPC operation started, and
2602 * tally the operation.
2604 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2608 FT_GetTimeOfDay(&opStartTime, 0);
2609 #endif /* FS_STATS_DETAILED */
2611 ViceLog(1, ("SAFS_BulkStatus\n"));
2613 AFSCallStats.TotalCalls++;
2615 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2616 if (nfiles <= 0) { /* Sanity check */
2618 goto Audit_and_Return;
2621 /* allocate space for return output parameters */
2622 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2623 malloc(nfiles * sizeof(struct AFSFetchStatus));
2624 if (!OutStats->AFSBulkStats_val) {
2625 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2628 OutStats->AFSBulkStats_len = nfiles;
2629 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2630 malloc(nfiles * sizeof(struct AFSCallBack));
2631 if (!CallBacks->AFSCBs_val) {
2632 ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
2635 CallBacks->AFSCBs_len = nfiles;
2637 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2638 goto Bad_BulkStatus;
2640 tfid = Fids->AFSCBFids_val;
2641 for (i = 0; i < nfiles; i++, tfid++) {
2643 * Get volume/vnode for the fetched file; caller's rights to it
2647 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2648 &parentwhentargetnotdir, &client, READ_LOCK,
2649 &rights, &anyrights)))
2650 goto Bad_BulkStatus;
2651 /* set volume synchronization information, but only once per call */
2653 SetVolumeSync(Sync, volptr);
2655 /* Are we allowed to fetch Fid's status? */
2656 if (targetptr->disk.type != vDirectory) {
2658 Check_PermissionRights(targetptr, client, rights,
2659 CHK_FETCHSTATUS, 0))) {
2660 if (rx_GetCallAbortCode(acall) == errorCode)
2661 rx_SetCallAbortCode(acall, 0);
2662 goto Bad_BulkStatus;
2666 /* set OutStatus From the Fid */
2667 GetStatus(targetptr, &OutStats->AFSBulkStats_val[i], rights,
2668 anyrights, parentwhentargetnotdir);
2670 /* If a r/w volume, also set the CallBack state */
2671 if (VolumeWriteable(volptr))
2672 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2673 &CallBacks->AFSCBs_val[i]);
2675 struct AFSFid myFid;
2676 memset(&myFid, 0, sizeof(struct AFSFid));
2677 myFid.Volume = tfid->Volume;
2678 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2679 &CallBacks->AFSCBs_val[i]);
2682 /* put back the file ID and volume */
2683 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2685 parentwhentargetnotdir = (Vnode *) 0;
2686 targetptr = (Vnode *) 0;
2687 volptr = (Volume *) 0;
2688 client = (struct client *)0;
2692 /* Update and store volume/vnode and parent vnodes back */
2693 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2695 errorCode = CallPostamble(tcon, errorCode, thost);
2697 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2699 #if FS_STATS_DETAILED
2700 FT_GetTimeOfDay(&opStopTime, 0);
2701 if (errorCode == 0) {
2703 (opP->numSuccesses)++;
2704 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2705 fs_stats_AddTo((opP->sumTime), elapsedTime);
2706 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2707 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2708 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2710 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2711 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2715 #endif /* FS_STATS_DETAILED */
2718 ViceLog(2, ("SAFS_BulkStatus returns %d\n", errorCode));
2719 osi_auditU(acall, BulkFetchStatusEvent, errorCode,
2720 AUD_ID, t_client ? t_client->ViceId : 0,
2721 AUD_FIDS, Fids, AUD_END);
2724 } /*SRXAFS_BulkStatus */
2728 SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
2729 struct AFSBulkStats * OutStats,
2730 struct AFSCBs * CallBacks, struct AFSVolSync * Sync)
2734 Vnode *targetptr = 0; /* pointer to vnode to fetch */
2735 Vnode *parentwhentargetnotdir = 0; /* parent vnode if targetptr is a file */
2736 Error errorCode = 0; /* return code to caller */
2737 Volume *volptr = 0; /* pointer to the volume */
2738 struct client *client = 0; /* pointer to the client data */
2739 afs_int32 rights, anyrights; /* rights for this and any user */
2740 struct AFSFid *tfid; /* file id we're dealing with now */
2741 struct rx_connection *tcon;
2743 struct client *t_client = NULL; /* tmp ptr to client data */
2744 AFSFetchStatus *tstatus;
2745 int VolSync_set = 0;
2746 #if FS_STATS_DETAILED
2747 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2748 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2749 struct timeval elapsedTime; /* Transfer time */
2752 * Set our stats pointer, remember when the RPC operation started, and
2753 * tally the operation.
2755 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_BULKSTATUS]);
2759 FT_GetTimeOfDay(&opStartTime, 0);
2760 #endif /* FS_STATS_DETAILED */
2762 ViceLog(1, ("SAFS_InlineBulkStatus\n"));
2764 AFSCallStats.TotalCalls++;
2766 nfiles = Fids->AFSCBFids_len; /* # of files in here */
2767 if (nfiles <= 0) { /* Sanity check */
2769 goto Audit_and_Return;
2772 /* allocate space for return output parameters */
2773 OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
2774 malloc(nfiles * sizeof(struct AFSFetchStatus));
2775 if (!OutStats->AFSBulkStats_val) {
2776 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2779 OutStats->AFSBulkStats_len = nfiles;
2780 CallBacks->AFSCBs_val = (struct AFSCallBack *)
2781 malloc(nfiles * sizeof(struct AFSCallBack));
2782 if (!CallBacks->AFSCBs_val) {
2783 ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
2786 CallBacks->AFSCBs_len = nfiles;
2788 /* Zero out return values to avoid leaking information on partial succes */
2789 memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
2790 memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
2791 memset(Sync, 0, sizeof(*Sync));
2793 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
2794 goto Bad_InlineBulkStatus;
2797 tfid = Fids->AFSCBFids_val;
2798 for (i = 0; i < nfiles; i++, tfid++) {
2800 * Get volume/vnode for the fetched file; caller's rights to it
2804 GetVolumePackage(tcon, tfid, &volptr, &targetptr, DONTCHECK,
2805 &parentwhentargetnotdir, &client, READ_LOCK,
2806 &rights, &anyrights))) {
2807 tstatus = &OutStats->AFSBulkStats_val[i];
2808 tstatus->errorCode = errorCode;
2809 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2811 parentwhentargetnotdir = (Vnode *) 0;
2812 targetptr = (Vnode *) 0;
2813 volptr = (Volume *) 0;
2814 client = (struct client *)0;
2818 /* set volume synchronization information, but only once per call */
2820 SetVolumeSync(Sync, volptr);
2824 /* Are we allowed to fetch Fid's status? */
2825 if (targetptr->disk.type != vDirectory) {
2827 Check_PermissionRights(targetptr, client, rights,
2828 CHK_FETCHSTATUS, 0))) {
2829 tstatus = &OutStats->AFSBulkStats_val[i];
2830 tstatus->errorCode = errorCode;
2831 (void)PutVolumePackage(parentwhentargetnotdir, targetptr,
2832 (Vnode *) 0, volptr, &client);
2833 parentwhentargetnotdir = (Vnode *) 0;
2834 targetptr = (Vnode *) 0;
2835 volptr = (Volume *) 0;
2836 client = (struct client *)0;
2841 /* set OutStatus From the Fid */
2842 GetStatus(targetptr,
2843 (struct AFSFetchStatus *)&OutStats->AFSBulkStats_val[i],
2844 rights, anyrights, parentwhentargetnotdir);
2846 /* If a r/w volume, also set the CallBack state */
2847 if (VolumeWriteable(volptr))
2848 SetCallBackStruct(AddBulkCallBack(client->host, tfid),
2849 &CallBacks->AFSCBs_val[i]);
2851 struct AFSFid myFid;
2852 memset(&myFid, 0, sizeof(struct AFSFid));
2853 myFid.Volume = tfid->Volume;
2854 SetCallBackStruct(AddVolCallBack(client->host, &myFid),
2855 &CallBacks->AFSCBs_val[i]);
2858 /* put back the file ID and volume */
2859 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2861 parentwhentargetnotdir = (Vnode *) 0;
2862 targetptr = (Vnode *) 0;
2863 volptr = (Volume *) 0;
2864 client = (struct client *)0;
2867 Bad_InlineBulkStatus:
2868 /* Update and store volume/vnode and parent vnodes back */
2869 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
2871 errorCode = CallPostamble(tcon, errorCode, thost);
2873 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2875 #if FS_STATS_DETAILED
2876 FT_GetTimeOfDay(&opStopTime, 0);
2877 if (errorCode == 0) {
2879 (opP->numSuccesses)++;
2880 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2881 fs_stats_AddTo((opP->sumTime), elapsedTime);
2882 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2883 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2884 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2886 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2887 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2891 #endif /* FS_STATS_DETAILED */
2894 ViceLog(2, ("SAFS_InlineBulkStatus returns %d\n", errorCode));
2895 osi_auditU(acall, InlineBulkFetchStatusEvent, errorCode,
2896 AUD_ID, t_client ? t_client->ViceId : 0,
2897 AUD_FIDS, Fids, AUD_END);
2900 } /*SRXAFS_InlineBulkStatus */
2904 SRXAFS_FetchStatus(struct rx_call * acall, struct AFSFid * Fid,
2905 struct AFSFetchStatus * OutStatus,
2906 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
2909 struct rx_connection *tcon;
2911 struct client *t_client = NULL; /* tmp ptr to client data */
2912 #if FS_STATS_DETAILED
2913 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2914 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2915 struct timeval elapsedTime; /* Transfer time */
2918 * Set our stats pointer, remember when the RPC operation started, and
2919 * tally the operation.
2921 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_FETCHSTATUS]);
2925 FT_GetTimeOfDay(&opStartTime, 0);
2926 #endif /* FS_STATS_DETAILED */
2928 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
2929 goto Bad_FetchStatus;
2931 code = SAFSS_FetchStatus(acall, Fid, OutStatus, CallBack, Sync);
2934 code = CallPostamble(tcon, code, thost);
2936 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
2938 #if FS_STATS_DETAILED
2939 FT_GetTimeOfDay(&opStopTime, 0);
2942 (opP->numSuccesses)++;
2943 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
2944 fs_stats_AddTo((opP->sumTime), elapsedTime);
2945 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
2946 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
2947 fs_stats_TimeAssign((opP->minTime), elapsedTime);
2949 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
2950 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
2954 #endif /* FS_STATS_DETAILED */
2956 osi_auditU(acall, FetchStatusEvent, code,
2957 AUD_ID, t_client ? t_client->ViceId : 0,
2958 AUD_FID, Fid, AUD_END);
2961 } /*SRXAFS_FetchStatus */
2965 common_StoreData64(struct rx_call *acall, struct AFSFid *Fid,
2966 struct AFSStoreStatus *InStatus, afs_fsize_t Pos,
2967 afs_fsize_t Length, afs_fsize_t FileLength,
2968 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
2970 Vnode *targetptr = 0; /* pointer to input fid */
2971 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
2972 Vnode tparentwhentargetnotdir; /* parent vnode for GetStatus */
2973 Error errorCode = 0; /* return code for caller */
2974 Error fileCode = 0; /* return code from vol package */
2975 Volume *volptr = 0; /* pointer to the volume header */
2976 struct client *client = 0; /* pointer to client structure */
2977 afs_int32 rights, anyrights; /* rights for this and any user */
2978 struct client *t_client = NULL; /* tmp ptr to client data */
2979 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
2980 struct rx_connection *tcon;
2982 #if FS_STATS_DETAILED
2983 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
2984 struct fs_stats_xferData *xferP; /* Ptr to this op's byte size struct */
2985 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
2986 struct timeval xferStartTime, xferStopTime; /* Start/stop times for xfer portion */
2987 struct timeval elapsedTime; /* Transfer time */
2988 afs_sfsize_t bytesToXfer; /* # bytes to xfer */
2989 afs_sfsize_t bytesXferred; /* # bytes actually xfer */
2990 static afs_int32 tot_bytesXferred; /* shared access protected by FS_LOCK */
2993 * Set our stats pointers, remember when the RPC operation started, and
2994 * tally the operation.
2996 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREDATA]);
2997 xferP = &(afs_FullPerfStats.det.xferOpTimes[FS_STATS_XFERIDX_STOREDATA]);
3002 ("StoreData: Fid = %u.%u.%u\n", Fid->Volume, Fid->Vnode,
3004 FT_GetTimeOfDay(&opStartTime, 0);
3005 #endif /* FS_STATS_DETAILED */
3008 AFSCallStats.StoreData++, AFSCallStats.TotalCalls++;
3010 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3013 /* Get ptr to client data for user Id for logging */
3014 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3015 logHostAddr.s_addr = rxr_HostOf(tcon);
3017 ("StoreData: Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
3018 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3019 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3022 * Get associated volume/vnode for the stored file; caller's rights
3026 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustNOTBeDIR,
3027 &parentwhentargetnotdir, &client, WRITE_LOCK,
3028 &rights, &anyrights))) {
3032 /* set volume synchronization information */
3033 SetVolumeSync(Sync, volptr);
3035 if ((targetptr->disk.type == vSymlink)) {
3036 /* Should we return a better error code here??? */
3041 /* Check if we're allowed to store the data */
3043 Check_PermissionRights(targetptr, client, rights, CHK_STOREDATA,
3049 * Drop the read lock on the parent directory after saving the parent
3050 * vnode information we need to pass to GetStatus
3052 if (parentwhentargetnotdir != NULL) {
3053 tparentwhentargetnotdir = *parentwhentargetnotdir;
3054 VPutVnode(&fileCode, parentwhentargetnotdir);
3055 assert(!fileCode || (fileCode == VSALVAGE));
3056 parentwhentargetnotdir = NULL;
3058 #if FS_STATS_DETAILED
3060 * Remember when the data transfer started.
3062 FT_GetTimeOfDay(&xferStartTime, 0);
3063 #endif /* FS_STATS_DETAILED */
3065 /* Do the actual storing of the data */
3066 #if FS_STATS_DETAILED
3068 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3069 FileLength, (InStatus->Mask & AFS_FSYNC),
3070 &bytesToXfer, &bytesXferred);
3073 StoreData_RXStyle(volptr, targetptr, Fid, client, acall, Pos, Length,
3074 FileLength, (InStatus->Mask & AFS_FSYNC));
3075 if (errorCode && (!targetptr->changed_newTime))
3077 #endif /* FS_STATS_DETAILED */
3078 #if FS_STATS_DETAILED
3080 * At this point, the data transfer is done, for good or ill. Remember
3081 * when the transfer ended, bump the number of successes/failures, and
3082 * integrate the transfer size and elapsed time into the stats. If the
3083 * operation failed, we jump to the appropriate point.
3085 FT_GetTimeOfDay(&xferStopTime, 0);
3087 (xferP->numXfers)++;
3089 (xferP->numSuccesses)++;
3092 * Bump the xfer sum by the number of bytes actually sent, NOT the
3095 tot_bytesXferred += bytesXferred;
3096 (xferP->sumBytes) += (tot_bytesXferred >> 10);
3097 tot_bytesXferred &= 0x3FF;
3098 if (bytesXferred < xferP->minBytes)
3099 xferP->minBytes = bytesXferred;
3100 if (bytesXferred > xferP->maxBytes)
3101 xferP->maxBytes = bytesXferred;
3104 * Tally the size of the object. Note: we tally the actual size,
3105 * NOT the number of bytes that made it out over the wire.
3107 if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET0)
3108 (xferP->count[0])++;
3109 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET1)
3110 (xferP->count[1])++;
3111 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET2)
3112 (xferP->count[2])++;
3113 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET3)
3114 (xferP->count[3])++;
3115 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET4)
3116 (xferP->count[4])++;
3117 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET5)
3118 (xferP->count[5])++;
3119 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET6)
3120 (xferP->count[6])++;
3121 else if (bytesToXfer <= FS_STATS_MAXBYTES_BUCKET7)
3122 (xferP->count[7])++;
3124 (xferP->count[8])++;
3126 fs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
3127 fs_stats_AddTo((xferP->sumTime), elapsedTime);
3128 fs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
3129 if (fs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
3130 fs_stats_TimeAssign((xferP->minTime), elapsedTime);
3132 if (fs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
3133 fs_stats_TimeAssign((xferP->maxTime), elapsedTime);
3138 * Finally, go off to tell our caller the bad news in case the
3141 if (errorCode && (!targetptr->changed_newTime))
3143 #endif /* FS_STATS_DETAILED */
3145 /* Update the status of the target's vnode */
3146 Update_TargetVnodeStatus(targetptr, TVS_SDATA, client, InStatus,
3147 targetptr, volptr, 0);
3149 /* Get the updated File's status back to the caller */
3150 GetStatus(targetptr, OutStatus, rights, anyrights,
3151 &tparentwhentargetnotdir);
3154 /* Update and store volume/vnode and parent vnodes back */
3155 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3157 ViceLog(2, ("SAFS_StoreData returns %d\n", errorCode));
3159 errorCode = CallPostamble(tcon, errorCode, thost);
3161 #if FS_STATS_DETAILED
3162 FT_GetTimeOfDay(&opStopTime, 0);
3163 if (errorCode == 0) {
3165 (opP->numSuccesses)++;
3166 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3167 fs_stats_AddTo((opP->sumTime), elapsedTime);
3168 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3169 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3170 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3172 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3173 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3177 #endif /* FS_STATS_DETAILED */
3178 osi_auditU(acall, StoreDataEvent, errorCode,
3179 AUD_ID, t_client ? t_client->ViceId : 0,
3180 AUD_FID, Fid, AUD_END);
3182 } /*common_StoreData64 */
3185 SRXAFS_StoreData(struct rx_call * acall, struct AFSFid * Fid,
3186 struct AFSStoreStatus * InStatus, afs_uint32 Pos,
3187 afs_uint32 Length, afs_uint32 FileLength,
3188 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3190 if (FileLength > 0x7fffffff || Pos > 0x7fffffff ||
3191 (0x7fffffff - Pos) < Length)
3194 return common_StoreData64(acall, Fid, InStatus, Pos, Length, FileLength,
3196 } /*SRXAFS_StoreData */
3199 SRXAFS_StoreData64(struct rx_call * acall, struct AFSFid * Fid,
3200 struct AFSStoreStatus * InStatus, afs_uint64 Pos,
3201 afs_uint64 Length, afs_uint64 FileLength,
3202 struct AFSFetchStatus * OutStatus,
3203 struct AFSVolSync * Sync)
3207 afs_fsize_t tLength;
3208 afs_fsize_t tFileLength;
3210 #ifdef AFS_64BIT_ENV
3211 tPos = (afs_fsize_t) Pos;
3212 tLength = (afs_fsize_t) Length;
3213 tFileLength = (afs_fsize_t) FileLength;
3214 #else /* AFS_64BIT_ENV */
3215 if (FileLength.high)
3218 tLength = Length.low;
3219 tFileLength = FileLength.low;
3220 #endif /* AFS_64BIT_ENV */
3223 common_StoreData64(acall, Fid, InStatus, tPos, tLength, tFileLength,
3229 SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid,
3230 struct AFSOpaque * AccessList,
3231 struct AFSFetchStatus * OutStatus, struct AFSVolSync * Sync)
3233 Vnode *targetptr = 0; /* pointer to input fid */
3234 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3235 Error errorCode = 0; /* return code for caller */
3236 struct AFSStoreStatus InStatus; /* Input status for fid */
3237 Volume *volptr = 0; /* pointer to the volume header */
3238 struct client *client = 0; /* pointer to client structure */
3239 afs_int32 rights, anyrights; /* rights for this and any user */
3240 struct rx_connection *tcon;
3242 struct client *t_client = NULL; /* tmp ptr to client data */
3243 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3244 #if FS_STATS_DETAILED
3245 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3246 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3247 struct timeval elapsedTime; /* Transfer time */
3250 * Set our stats pointer, remember when the RPC operation started, and
3251 * tally the operation.
3253 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STOREACL]);
3257 FT_GetTimeOfDay(&opStartTime, 0);
3258 #endif /* FS_STATS_DETAILED */
3259 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3262 /* Get ptr to client data for user Id for logging */
3263 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3264 logHostAddr.s_addr = rxr_HostOf(tcon);
3266 ("SAFS_StoreACL, Fid = %u.%u.%u, ACL=%s, Host %s:%d, Id %d\n",
3267 Fid->Volume, Fid->Vnode, Fid->Unique, AccessList->AFSOpaque_val,
3268 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3270 AFSCallStats.StoreACL++, AFSCallStats.TotalCalls++;
3272 InStatus.Mask = 0; /* not storing any status */
3275 * Get associated volume/vnode for the target dir; caller's rights
3276 * are also returned.
3279 GetVolumePackage(tcon, Fid, &volptr, &targetptr, MustBeDIR,
3280 &parentwhentargetnotdir, &client, WRITE_LOCK,
3281 &rights, &anyrights))) {
3285 /* set volume synchronization information */
3286 SetVolumeSync(Sync, volptr);
3288 /* Check if we have permission to change the dir's ACL */
3290 Check_PermissionRights(targetptr, client, rights, CHK_STOREACL,
3295 /* Build and store the new Access List for the dir */
3296 if ((errorCode = RXStore_AccessList(targetptr, AccessList))) {
3300 targetptr->changed_newTime = 1; /* status change of directory */
3302 /* convert the write lock to a read lock before breaking callbacks */
3303 VVnodeWriteToRead(&errorCode, targetptr);
3304 assert(!errorCode || errorCode == VSALVAGE);
3306 /* break call backs on the directory */
3307 BreakCallBack(client->host, Fid, 0);
3309 /* Get the updated dir's status back to the caller */
3310 GetStatus(targetptr, OutStatus, rights, anyrights, 0);
3313 /* Update and store volume/vnode and parent vnodes back */
3314 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3316 ViceLog(2, ("SAFS_StoreACL returns %d\n", errorCode));
3317 errorCode = CallPostamble(tcon, errorCode, thost);
3319 #if FS_STATS_DETAILED
3320 FT_GetTimeOfDay(&opStopTime, 0);
3321 if (errorCode == 0) {
3323 (opP->numSuccesses)++;
3324 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3325 fs_stats_AddTo((opP->sumTime), elapsedTime);
3326 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3327 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3328 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3330 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3331 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3335 #endif /* FS_STATS_DETAILED */
3337 osi_auditU(acall, StoreACLEvent, errorCode,
3338 AUD_ID, t_client ? t_client->ViceId : 0,
3339 AUD_FID, Fid, AUD_ACL, AccessList->AFSOpaque_val, AUD_END);
3342 } /*SRXAFS_StoreACL */
3346 * Note: This routine is called exclusively from SRXAFS_StoreStatus(), and
3347 * should be merged when possible.
3350 SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid,
3351 struct AFSStoreStatus *InStatus,
3352 struct AFSFetchStatus *OutStatus, struct AFSVolSync *Sync)
3354 Vnode *targetptr = 0; /* pointer to input fid */
3355 Vnode *parentwhentargetnotdir = 0; /* parent of Fid to get ACL */
3356 Error errorCode = 0; /* return code for caller */
3357 Volume *volptr = 0; /* pointer to the volume header */
3358 struct client *client = 0; /* pointer to client structure */
3359 afs_int32 rights, anyrights; /* rights for this and any user */
3360 struct client *t_client = NULL; /* tmp ptr to client data */
3361 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3362 struct rx_connection *tcon = rx_ConnectionOf(acall);
3364 /* Get ptr to client data for user Id for logging */
3365 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3366 logHostAddr.s_addr = rxr_HostOf(tcon);
3368 ("SAFS_StoreStatus, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
3369 Fid->Volume, Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
3370 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3372 AFSCallStats.StoreStatus++, AFSCallStats.TotalCalls++;
3375 * Get volume/vnode for the target file; caller's rights to it are
3379 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
3380 &parentwhentargetnotdir, &client, WRITE_LOCK,
3381 &rights, &anyrights))) {
3382 goto Bad_StoreStatus;
3385 /* set volume synchronization information */
3386 SetVolumeSync(Sync, volptr);
3388 /* Check if the caller has proper permissions to store status to Fid */
3390 Check_PermissionRights(targetptr, client, rights, CHK_STORESTATUS,
3392 goto Bad_StoreStatus;
3395 * Check for a symbolic link; we can't chmod these (otherwise could
3396 * change a symlink to a mt pt or vice versa)
3398 if (targetptr->disk.type == vSymlink && (InStatus->Mask & AFS_SETMODE)) {
3400 goto Bad_StoreStatus;
3403 /* Update the status of the target's vnode */
3404 Update_TargetVnodeStatus(targetptr, TVS_SSTATUS, client, InStatus,
3405 (parentwhentargetnotdir ? parentwhentargetnotdir
3406 : targetptr), volptr, 0);
3408 /* convert the write lock to a read lock before breaking callbacks */
3409 VVnodeWriteToRead(&errorCode, targetptr);
3410 assert(!errorCode || errorCode == VSALVAGE);
3412 /* Break call backs on Fid */
3413 BreakCallBack(client->host, Fid, 0);
3415 /* Return the updated status back to caller */
3416 GetStatus(targetptr, OutStatus, rights, anyrights,
3417 parentwhentargetnotdir);
3420 /* Update and store volume/vnode and parent vnodes back */
3421 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
3423 ViceLog(2, ("SAFS_StoreStatus returns %d\n", errorCode));
3426 } /*SAFSS_StoreStatus */
3430 SRXAFS_StoreStatus(struct rx_call * acall, struct AFSFid * Fid,
3431 struct AFSStoreStatus * InStatus,
3432 struct AFSFetchStatus * OutStatus,
3433 struct AFSVolSync * Sync)
3436 struct rx_connection *tcon;
3438 struct client *t_client = NULL; /* tmp ptr to client data */
3439 #if FS_STATS_DETAILED
3440 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3441 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3442 struct timeval elapsedTime; /* Transfer time */
3445 * Set our stats pointer, remember when the RPC operation started, and
3446 * tally the operation.
3448 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_STORESTATUS]);
3452 FT_GetTimeOfDay(&opStartTime, 0);
3453 #endif /* FS_STATS_DETAILED */
3455 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3456 goto Bad_StoreStatus;
3458 code = SAFSS_StoreStatus(acall, Fid, InStatus, OutStatus, Sync);
3461 code = CallPostamble(tcon, code, thost);
3463 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3465 #if FS_STATS_DETAILED
3466 FT_GetTimeOfDay(&opStopTime, 0);
3469 (opP->numSuccesses)++;
3470 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3471 fs_stats_AddTo((opP->sumTime), elapsedTime);
3472 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3473 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3474 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3476 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3477 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3481 #endif /* FS_STATS_DETAILED */
3483 osi_auditU(acall, StoreStatusEvent, code,
3484 AUD_ID, t_client ? t_client->ViceId : 0,
3485 AUD_FID, Fid, AUD_END);
3488 } /*SRXAFS_StoreStatus */
3492 * This routine is called exclusively by SRXAFS_RemoveFile(), and should be
3493 * merged in when possible.
3496 SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3497 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
3499 Vnode *parentptr = 0; /* vnode of input Directory */
3500 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3501 Vnode *targetptr = 0; /* file to be deleted */
3502 Volume *volptr = 0; /* pointer to the volume header */
3503 AFSFid fileFid; /* area for Fid from the directory */
3504 Error errorCode = 0; /* error code */
3505 DirHandle dir; /* Handle for dir package I/O */
3506 struct client *client = 0; /* pointer to client structure */
3507 afs_int32 rights, anyrights; /* rights for this and any user */
3508 struct client *t_client; /* tmp ptr to client data */
3509 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3510 struct rx_connection *tcon = rx_ConnectionOf(acall);
3513 /* Get ptr to client data for user Id for logging */
3514 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3515 logHostAddr.s_addr = rxr_HostOf(tcon);
3517 ("SAFS_RemoveFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3518 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3519 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3521 AFSCallStats.RemoveFile++, AFSCallStats.TotalCalls++;
3524 * Get volume/vnode for the parent dir; caller's access rights are
3528 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3529 &parentwhentargetnotdir, &client, WRITE_LOCK,
3530 &rights, &anyrights))) {
3531 goto Bad_RemoveFile;
3533 /* set volume synchronization information */
3534 SetVolumeSync(Sync, volptr);
3536 /* Does the caller has delete (& write) access to the parent directory? */
3537 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
3538 goto Bad_RemoveFile;
3541 /* Actually delete the desired file */
3543 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
3545 goto Bad_RemoveFile;
3548 /* Update the vnode status of the parent dir */
3549 #if FS_STATS_DETAILED
3550 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3551 parentptr->disk.linkCount,
3552 client->InSameNetwork);
3554 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3555 parentptr->disk.linkCount);
3556 #endif /* FS_STATS_DETAILED */
3558 /* Return the updated parent dir's status back to caller */
3559 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3561 /* Handle internal callback state for the parent and the deleted file */
3562 if (targetptr->disk.linkCount == 0) {
3563 /* no references left, discard entry */
3564 DeleteFileCallBacks(&fileFid);
3565 /* convert the parent lock to a read lock before breaking callbacks */
3566 VVnodeWriteToRead(&errorCode, parentptr);
3567 assert(!errorCode || errorCode == VSALVAGE);
3569 /* convert the parent lock to a read lock before breaking callbacks */
3570 VVnodeWriteToRead(&errorCode, parentptr);
3571 assert(!errorCode || errorCode == VSALVAGE);
3572 /* convert the target lock to a read lock before breaking callbacks */
3573 VVnodeWriteToRead(&errorCode, targetptr);
3574 assert(!errorCode || errorCode == VSALVAGE);
3575 /* tell all the file has changed */
3576 BreakCallBack(client->host, &fileFid, 1);
3579 /* break call back on the directory */
3580 BreakCallBack(client->host, DirFid, 0);
3583 /* Update and store volume/vnode and parent vnodes back */
3584 PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3587 ViceLog(2, ("SAFS_RemoveFile returns %d\n", errorCode));
3590 } /*SAFSS_RemoveFile */
3594 SRXAFS_RemoveFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3595 struct AFSFetchStatus * OutDirStatus,
3596 struct AFSVolSync * Sync)
3599 struct rx_connection *tcon;
3601 struct client *t_client = NULL; /* tmp ptr to client data */
3602 #if FS_STATS_DETAILED
3603 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3604 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3605 struct timeval elapsedTime; /* Transfer time */
3608 * Set our stats pointer, remember when the RPC operation started, and
3609 * tally the operation.
3611 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEFILE]);
3615 FT_GetTimeOfDay(&opStartTime, 0);
3616 #endif /* FS_STATS_DETAILED */
3618 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3619 goto Bad_RemoveFile;
3621 code = SAFSS_RemoveFile(acall, DirFid, Name, OutDirStatus, Sync);
3624 code = CallPostamble(tcon, code, thost);
3626 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3628 #if FS_STATS_DETAILED
3629 FT_GetTimeOfDay(&opStopTime, 0);
3632 (opP->numSuccesses)++;
3633 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3634 fs_stats_AddTo((opP->sumTime), elapsedTime);
3635 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3636 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3637 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3639 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3640 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3644 #endif /* FS_STATS_DETAILED */
3646 osi_auditU(acall, RemoveFileEvent, code,
3647 AUD_ID, t_client ? t_client->ViceId : 0,
3648 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
3651 } /*SRXAFS_RemoveFile */
3655 * This routine is called exclusively from SRXAFS_CreateFile(), and should
3656 * be merged in when possible.
3659 SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
3660 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
3661 struct AFSFetchStatus *OutFidStatus,
3662 struct AFSFetchStatus *OutDirStatus,
3663 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
3665 Vnode *parentptr = 0; /* vnode of input Directory */
3666 Vnode *targetptr = 0; /* vnode of the new file */
3667 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
3668 Volume *volptr = 0; /* pointer to the volume header */
3669 Error errorCode = 0; /* error code */
3670 DirHandle dir; /* Handle for dir package I/O */
3671 struct client *client = 0; /* pointer to client structure */
3672 afs_int32 rights, anyrights; /* rights for this and any user */
3673 struct client *t_client; /* tmp ptr to client data */
3674 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3675 struct rx_connection *tcon = rx_ConnectionOf(acall);
3679 /* Get ptr to client data for user Id for logging */
3680 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3681 logHostAddr.s_addr = rxr_HostOf(tcon);
3683 ("SAFS_CreateFile %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
3684 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
3685 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3687 AFSCallStats.CreateFile++, AFSCallStats.TotalCalls++;
3689 if (!FileNameOK(Name)) {
3691 goto Bad_CreateFile;
3695 * Get associated volume/vnode for the parent dir; caller long are
3699 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
3700 &parentwhentargetnotdir, &client, WRITE_LOCK,
3701 &rights, &anyrights))) {
3702 goto Bad_CreateFile;
3705 /* set volume synchronization information */
3706 SetVolumeSync(Sync, volptr);
3708 /* Can we write (and insert) onto the parent directory? */
3709 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
3710 goto Bad_CreateFile;
3712 /* get a new vnode for the file to be created and set it up */
3714 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
3715 vFile, nBlocks(0)))) {
3716 goto Bad_CreateFile;
3719 /* update the status of the parent vnode */
3720 #if FS_STATS_DETAILED
3721 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3722 parentptr->disk.linkCount,
3723 client->InSameNetwork);
3725 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
3726 parentptr->disk.linkCount);
3727 #endif /* FS_STATS_DETAILED */
3729 /* update the status of the new file's vnode */
3730 Update_TargetVnodeStatus(targetptr, TVS_CFILE, client, InStatus,
3731 parentptr, volptr, 0);
3733 /* 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 */
3734 GetStatus(targetptr, OutFidStatus, rights | PRSFS_ADMINISTER, anyrights, parentptr);
3735 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
3737 /* convert the write lock to a read lock before breaking callbacks */
3738 VVnodeWriteToRead(&errorCode, parentptr);
3739 assert(!errorCode || errorCode == VSALVAGE);
3741 /* break call back on parent dir */
3742 BreakCallBack(client->host, DirFid, 0);
3744 /* Return a callback promise for the newly created file to the caller */
3745 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
3748 /* Update and store volume/vnode and parent vnodes back */
3749 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
3752 ViceLog(2, ("SAFS_CreateFile returns %d\n", errorCode));
3755 } /*SAFSS_CreateFile */
3759 SRXAFS_CreateFile(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
3760 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
3761 struct AFSFetchStatus * OutFidStatus,
3762 struct AFSFetchStatus * OutDirStatus,
3763 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
3766 struct rx_connection *tcon;
3768 struct client *t_client = NULL; /* tmp ptr to client data */
3769 #if FS_STATS_DETAILED
3770 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
3771 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
3772 struct timeval elapsedTime; /* Transfer time */
3775 * Set our stats pointer, remember when the RPC operation started, and
3776 * tally the operation.
3778 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CREATEFILE]);
3782 FT_GetTimeOfDay(&opStartTime, 0);
3783 #endif /* FS_STATS_DETAILED */
3785 memset(OutFid, 0, sizeof(struct AFSFid));
3787 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
3788 goto Bad_CreateFile;
3791 SAFSS_CreateFile(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
3792 OutDirStatus, CallBack, Sync);
3795 code = CallPostamble(tcon, code, thost);
3797 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3799 #if FS_STATS_DETAILED
3800 FT_GetTimeOfDay(&opStopTime, 0);
3803 (opP->numSuccesses)++;
3804 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
3805 fs_stats_AddTo((opP->sumTime), elapsedTime);
3806 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
3807 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
3808 fs_stats_TimeAssign((opP->minTime), elapsedTime);
3810 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
3811 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
3815 #endif /* FS_STATS_DETAILED */
3817 osi_auditU(acall, CreateFileEvent, code,
3818 AUD_ID, t_client ? t_client->ViceId : 0,
3819 AUD_FID, DirFid, AUD_STR, Name, AUD_FID, OutFid, AUD_END);
3822 } /*SRXAFS_CreateFile */
3826 * This routine is called exclusively from SRXAFS_Rename(), and should be
3827 * merged in when possible.
3830 SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName,
3831 struct AFSFid *NewDirFid, char *NewName,
3832 struct AFSFetchStatus *OutOldDirStatus,
3833 struct AFSFetchStatus *OutNewDirStatus, struct AFSVolSync *Sync)
3835 Vnode *oldvptr = 0; /* vnode of the old Directory */
3836 Vnode *newvptr = 0; /* vnode of the new Directory */
3837 Vnode *fileptr = 0; /* vnode of the file to move */
3838 Vnode *newfileptr = 0; /* vnode of the file to delete */
3839 Vnode *testvptr = 0; /* used in directory tree walk */
3840 Vnode *parent = 0; /* parent for use in SetAccessList */
3841 Error errorCode = 0; /* error code */
3842 Error fileCode = 0; /* used when writing Vnodes */
3843 VnodeId testnode; /* used in directory tree walk */
3844 AFSFid fileFid; /* Fid of file to move */
3845 AFSFid newFileFid; /* Fid of new file */
3846 DirHandle olddir; /* Handle for dir package I/O */
3847 DirHandle newdir; /* Handle for dir package I/O */
3848 DirHandle filedir; /* Handle for dir package I/O */
3849 DirHandle newfiledir; /* Handle for dir package I/O */
3850 Volume *volptr = 0; /* pointer to the volume header */
3851 struct client *client = 0; /* pointer to client structure */
3852 afs_int32 rights, anyrights; /* rights for this and any user */
3853 afs_int32 newrights; /* rights for this user */
3854 afs_int32 newanyrights; /* rights for any user */
3855 int doDelete; /* deleted the rename target (ref count now 0) */
3857 int updatefile = 0; /* are we changing the renamed file? (we do this
3858 * if we need to update .. on a renamed dir) */
3859 struct client *t_client; /* tmp ptr to client data */
3860 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
3861 struct rx_connection *tcon = rx_ConnectionOf(acall);
3866 FidZero(&newfiledir);
3868 /* Get ptr to client data for user Id for logging */
3869 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
3870 logHostAddr.s_addr = rxr_HostOf(tcon);
3872 ("SAFS_Rename %s to %s, Fid = %u.%u.%u to %u.%u.%u, Host %s:%d, Id %d\n",
3873 OldName, NewName, OldDirFid->Volume, OldDirFid->Vnode,
3874 OldDirFid->Unique, NewDirFid->Volume, NewDirFid->Vnode,
3875 NewDirFid->Unique, inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
3877 AFSCallStats.Rename++, AFSCallStats.TotalCalls++;
3879 if (!FileNameOK(NewName)) {
3883 if (OldDirFid->Volume != NewDirFid->Volume) {
3888 if ((strcmp(OldName, ".") == 0) || (strcmp(OldName, "..") == 0)
3889 || (strcmp(NewName, ".") == 0) || (strcmp(NewName, "..") == 0)
3890 || (strlen(NewName) == 0) || (strlen(OldName) == 0)) {
3896 if (OldDirFid->Vnode <= NewDirFid->Vnode) {
3898 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3899 &parent, &client, WRITE_LOCK, &rights,
3904 if (OldDirFid->Vnode == NewDirFid->Vnode) {
3906 newrights = rights, newanyrights = anyrights;
3909 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr,
3910 MustBeDIR, &parent, &client, WRITE_LOCK,
3911 &newrights, &newanyrights))) {
3917 GetVolumePackage(tcon, NewDirFid, &volptr, &newvptr, MustBeDIR,
3918 &parent, &client, WRITE_LOCK, &newrights,
3924 GetVolumePackage(tcon, OldDirFid, &volptr, &oldvptr, MustBeDIR,
3925 &parent, &client, WRITE_LOCK, &rights,
3932 /* set volume synchronization information */
3933 SetVolumeSync(Sync, volptr);
3935 if ((errorCode = CheckWriteMode(oldvptr, rights, PRSFS_DELETE))) {
3938 if ((errorCode = CheckWriteMode(newvptr, newrights, PRSFS_INSERT))) {
3942 /* The CopyOnWrite might return ENOSPC ( disk full). Even if the second
3943 * call to CopyOnWrite returns error, it is not necessary to revert back
3944 * the effects of the first call because the contents of the volume is
3945 * not modified, it is only replicated.
3947 if (oldvptr->disk.cloned) {
3948 ViceLog(25, ("Rename : calling CopyOnWrite on old dir\n"));
3949 if ((errorCode = CopyOnWrite(oldvptr, volptr, 0, MAXFSIZE)))
3952 SetDirHandle(&olddir, oldvptr);
3953 if (newvptr->disk.cloned) {
3954 ViceLog(25, ("Rename : calling CopyOnWrite on new dir\n"));
3955 if ((errorCode = CopyOnWrite(newvptr, volptr, 0, MAXFSIZE)))
3959 SetDirHandle(&newdir, newvptr);
3961 /* Lookup the file to delete its vnode */
3962 if (Lookup(&olddir, OldName, &fileFid)) {
3966 if (fileFid.Vnode == oldvptr->vnodeNumber
3967 || fileFid.Vnode == newvptr->vnodeNumber) {
3968 errorCode = FSERR_ELOOP;
3971 fileFid.Volume = V_id(volptr);
3972 fileptr = VGetVnode(&errorCode, volptr, fileFid.Vnode, WRITE_LOCK);
3973 if (errorCode != 0) {
3975 ("SAFSS_Rename(): Error in VGetVnode() for old file %s, code %d\n",
3976 OldName, errorCode));
3977 VTakeOffline(volptr);
3980 if (fileptr->disk.uniquifier != fileFid.Unique) {
3982 ("SAFSS_Rename(): Old file %s uniquifier mismatch\n",
3984 VTakeOffline(volptr);
3989 if (fileptr->disk.type != vDirectory && oldvptr != newvptr
3990 && fileptr->disk.linkCount != 1) {
3992 * Hard links exist to this file - cannot move one of the links to
3993 * a new directory because of AFS restrictions (this is the same
3994 * reason that links cannot be made across directories, i.e.
4001 /* Lookup the new file */
4002 if (!(Lookup(&newdir, NewName, &newFileFid))) {
4003 if (readonlyServer) {
4004 errorCode = VREADONLY;
4007 if (!(newrights & PRSFS_DELETE)) {
4011 if (newFileFid.Vnode == oldvptr->vnodeNumber
4012 || newFileFid.Vnode == newvptr->vnodeNumber
4013 || newFileFid.Vnode == fileFid.Vnode) {
4017 newFileFid.Volume = V_id(volptr);
4019 VGetVnode(&errorCode, volptr, newFileFid.Vnode, WRITE_LOCK);
4020 if (errorCode != 0) {
4022 ("SAFSS_Rename(): Error in VGetVnode() for new file %s, code %d\n",
4023 NewName, errorCode));
4024 VTakeOffline(volptr);
4027 if (fileptr->disk.uniquifier != fileFid.Unique) {
4029 ("SAFSS_Rename(): New file %s uniquifier mismatch\n",
4031 VTakeOffline(volptr);
4035 SetDirHandle(&newfiledir, newfileptr);
4036 /* Now check that we're moving directories over directories properly, etc.
4037 * return proper POSIX error codes:
4038 * if fileptr is a file and new is a dir: EISDIR.
4039 * if fileptr is a dir and new is a file: ENOTDIR.
4040 * Also, dir to be removed must be empty, of course.
4042 if (newfileptr->disk.type == vDirectory) {
4043 if (fileptr->disk.type != vDirectory) {
4047 if ((IsEmpty(&newfiledir))) {
4052 if (fileptr->disk.type == vDirectory) {
4053 errorCode = ENOTDIR;
4060 * ok - now we check that the old name is not above new name in the
4061 * directory structure. This is to prevent removing a subtree alltogether
4063 if ((oldvptr != newvptr) && (fileptr->disk.type == vDirectory)) {
4064 afs_int32 forpass = 0, vnum = 0, top = 0;
4065 for (testnode = newvptr->disk.parent; testnode != 0; forpass++) {
4066 if (testnode > vnum) vnum = testnode;
4067 if (forpass > vnum) {
4068 errorCode = FSERR_ELOOP;
4071 if (testnode == oldvptr->vnodeNumber) {
4072 testnode = oldvptr->disk.parent;
4075 if ((testnode == fileptr->vnodeNumber)
4076 || (testnode == newvptr->vnodeNumber)) {
4077 errorCode = FSERR_ELOOP;
4080 if ((newfileptr) && (testnode == newfileptr->vnodeNumber)) {
4081 errorCode = FSERR_ELOOP;
4084 if (testnode == 1) top = 1;
4085 testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK);
4086 assert(errorCode == 0);
4087 testnode = testvptr->disk.parent;
4088 VPutVnode(&errorCode, testvptr);
4089 if ((top == 1) && (testnode != 0)) {
4090 VTakeOffline(volptr);
4092 ("Volume %u now offline, must be salvaged.\n",
4097 assert(errorCode == 0);
4101 if (fileptr->disk.type == vDirectory) {
4102 SetDirHandle(&filedir, fileptr);
4103 if (oldvptr != newvptr) {
4104 /* we always need to update .. if we've moving fileptr to a
4105 * different directory */
4108 struct AFSFid unused;
4110 code = Lookup(&filedir, "..", &unused);
4111 if (code == ENOENT) {
4112 /* only update .. if it doesn't already exist */
4118 /* Do the CopyonWrite first before modifying anything else. Copying is
4119 * required when we have to change entries for ..
4121 if (updatefile && (fileptr->disk.cloned)) {
4122 ViceLog(25, ("Rename : calling CopyOnWrite on target dir\n"));
4123 if ((errorCode = CopyOnWrite(fileptr, volptr, 0, MAXFSIZE)))
4127 /* If the new name exists already, delete it and the file it points to */
4130 /* Delete NewName from its directory */
4131 code = Delete(&newdir, NewName);
4134 /* Drop the link count */
4135 newfileptr->disk.linkCount--;
4136 if (newfileptr->disk.linkCount == 0) { /* Link count 0 - delete */
4137 afs_fsize_t newSize;
4138 VN_GET_LEN(newSize, newfileptr);
4139 VAdjustDiskUsage((Error *) & errorCode, volptr,
4140 (afs_sfsize_t) - nBlocks(newSize), 0);
4141 if (VN_GET_INO(newfileptr)) {
4142 IH_REALLYCLOSE(newfileptr->handle);
4144 IH_DEC(V_linkHandle(volptr), VN_GET_INO(newfileptr),
4145 V_parentId(volptr));
4146 IH_RELEASE(newfileptr->handle);
4147 if (errorCode == -1) {
4149 ("Del: inode=%s, name=%s, errno=%d\n",
4150 PrintInode(NULL, VN_GET_INO(newfileptr)),
4152 if ((errno != ENOENT) && (errno != EIO)
4153 && (errno != ENXIO))
4154 ViceLog(0, ("Do we need to fsck?"));
4157 VN_SET_INO(newfileptr, (Inode) 0);
4158 newfileptr->delete = 1; /* Mark NewName vnode to delete */
4161 /* Link count did not drop to zero.
4162 * Mark NewName vnode as changed - updates stime.
4164 newfileptr->changed_newTime = 1;
4169 * If the create below fails, and the delete above worked, we have
4170 * removed the new name and not replaced it. This is not very likely,
4171 * but possible. We could try to put the old file back, but it is
4172 * highly unlikely that it would work since it would involve issuing
4175 if ((errorCode = Create(&newdir, (char *)NewName, &fileFid)))
4178 /* Delete the old name */
4179 assert(Delete(&olddir, (char *)OldName) == 0);
4181 /* if the directory length changes, reflect it in the statistics */
4182 #if FS_STATS_DETAILED
4183 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4184 oldvptr->disk.linkCount, client->InSameNetwork);
4185 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4186 newvptr->disk.linkCount, client->InSameNetwork);
4188 Update_ParentVnodeStatus(oldvptr, volptr, &olddir, client->ViceId,
4189 oldvptr->disk.linkCount);
4190 Update_ParentVnodeStatus(newvptr, volptr, &newdir, client->ViceId,
4191 newvptr->disk.linkCount);
4192 #endif /* FS_STATS_DETAILED */
4194 if (oldvptr == newvptr)
4195 oldvptr->disk.dataVersion--; /* Since it was bumped by 2! */
4197 if (fileptr->disk.parent != newvptr->vnodeNumber) {
4198 fileptr->disk.parent = newvptr->vnodeNumber;
4199 fileptr->changed_newTime = 1;
4202 /* if we are dealing with a rename of a directory, and we need to
4203 * update the .. entry of that directory */
4205 assert(!fileptr->disk.cloned);
4207 fileptr->changed_newTime = 1; /* status change of moved file */
4209 /* fix .. to point to the correct place */
4210 Delete(&filedir, ".."); /* No assert--some directories may be bad */
4211 assert(Create(&filedir, "..", NewDirFid) == 0);
4212 fileptr->disk.dataVersion++;
4214 /* if the parent directories are different the link counts have to be */
4215 /* changed due to .. in the renamed directory */
4216 if (oldvptr != newvptr) {
4217 oldvptr->disk.linkCount--;
4218 newvptr->disk.linkCount++;
4222 /* set up return status */
4223 GetStatus(oldvptr, OutOldDirStatus, rights, anyrights, 0);
4224 GetStatus(newvptr, OutNewDirStatus, newrights, newanyrights, 0);
4225 if (newfileptr && doDelete) {
4226 DeleteFileCallBacks(&newFileFid); /* no other references */
4231 /* convert the write locks to a read locks before breaking callbacks */
4232 VVnodeWriteToRead(&errorCode, newvptr);
4233 assert(!errorCode || errorCode == VSALVAGE);
4234 if (oldvptr != newvptr) {
4235 VVnodeWriteToRead(&errorCode, oldvptr);
4236 assert(!errorCode || errorCode == VSALVAGE);
4238 if (newfileptr && !doDelete) {
4239 /* convert the write lock to a read lock before breaking callbacks */
4240 VVnodeWriteToRead(&errorCode, newfileptr);
4241 assert(!errorCode || errorCode == VSALVAGE);
4244 /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */
4245 BreakCallBack(client->host, NewDirFid, 0);
4246 if (oldvptr != newvptr) {
4247 BreakCallBack(client->host, OldDirFid, 0);
4250 /* if a dir moved, .. changed */
4251 /* we do not give an AFSFetchStatus structure back to the
4252 * originating client, and the file's status has changed, so be
4253 * sure to send a callback break. In theory the client knows
4254 * enough to know that the callback could be broken implicitly,
4255 * but that may not be clear, and some client implementations
4256 * may not know to. */
4257 BreakCallBack(client->host, &fileFid, 1);
4260 /* Note: it is not necessary to break the callback */
4262 DeleteFileCallBacks(&newFileFid); /* no other references */
4264 /* other's still exist (with wrong link count) */
4265 BreakCallBack(client->host, &newFileFid, 1);
4270 VPutVnode(&fileCode, newfileptr);
4271 assert(fileCode == 0);
4273 (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ?
4274 newvptr : 0), oldvptr, volptr, &client);
4278 FidZap(&newfiledir);
4279 ViceLog(2, ("SAFS_Rename returns %d\n", errorCode));
4286 SRXAFS_Rename(struct rx_call * acall, struct AFSFid * OldDirFid,
4287 char *OldName, struct AFSFid * NewDirFid, char *NewName,
4288 struct AFSFetchStatus * OutOldDirStatus,
4289 struct AFSFetchStatus * OutNewDirStatus,
4290 struct AFSVolSync * Sync)
4293 struct rx_connection *tcon;
4295 struct client *t_client = NULL; /* tmp ptr to client data */
4296 #if FS_STATS_DETAILED
4297 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4298 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4299 struct timeval elapsedTime; /* Transfer time */
4302 * Set our stats pointer, remember when the RPC operation started, and
4303 * tally the operation.
4305 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RENAME]);
4309 FT_GetTimeOfDay(&opStartTime, 0);
4310 #endif /* FS_STATS_DETAILED */
4312 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4316 SAFSS_Rename(acall, OldDirFid, OldName, NewDirFid, NewName,
4317 OutOldDirStatus, OutNewDirStatus, Sync);
4320 code = CallPostamble(tcon, code, thost);
4322 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4324 #if FS_STATS_DETAILED
4325 FT_GetTimeOfDay(&opStopTime, 0);
4328 (opP->numSuccesses)++;
4329 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4330 fs_stats_AddTo((opP->sumTime), elapsedTime);
4331 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4332 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4333 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4335 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4336 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4340 #endif /* FS_STATS_DETAILED */
4342 osi_auditU(acall, RenameFileEvent, code,
4343 AUD_ID, t_client ? t_client->ViceId : 0,
4344 AUD_FID, OldDirFid, AUD_STR, OldName,
4345 AUD_FID, NewDirFid, AUD_STR, NewName, AUD_END);
4348 } /*SRXAFS_Rename */
4352 * This routine is called exclusively by SRXAFS_Symlink(), and should be
4353 * merged into it when possible.
4356 SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4357 char *LinkContents, struct AFSStoreStatus *InStatus,
4358 struct AFSFid *OutFid, struct AFSFetchStatus *OutFidStatus,
4359 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4361 Vnode *parentptr = 0; /* vnode of input Directory */
4362 Vnode *targetptr = 0; /* vnode of the new link */
4363 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4364 Error errorCode = 0; /* error code */
4367 DirHandle dir; /* Handle for dir package I/O */
4368 Volume *volptr = 0; /* pointer to the volume header */
4369 struct client *client = 0; /* pointer to client structure */
4370 afs_int32 rights, anyrights; /* rights for this and any user */
4371 struct client *t_client; /* tmp ptr to client data */
4372 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4374 struct rx_connection *tcon = rx_ConnectionOf(acall);
4378 /* Get ptr to client data for user Id for logging */
4379 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4380 logHostAddr.s_addr = rxr_HostOf(tcon);
4382 ("SAFS_Symlink %s to %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4383 LinkContents, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4384 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4386 AFSCallStats.Symlink++, AFSCallStats.TotalCalls++;
4388 if (!FileNameOK(Name)) {
4394 * Get the vnode and volume for the parent dir along with the caller's
4398 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4399 &parentwhentargetnotdir, &client, WRITE_LOCK,
4400 &rights, &anyrights))) {
4404 /* set volume synchronization information */
4405 SetVolumeSync(Sync, volptr);
4407 /* Does the caller has insert (and write) access to the parent directory? */
4408 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4413 * If we're creating a mount point (any x bits clear), we must have
4414 * administer access to the directory, too. Always allow sysadmins
4417 if ((InStatus->Mask & AFS_SETMODE) && !(InStatus->UnixModeBits & 0111)) {
4418 if (readonlyServer) {
4419 errorCode = VREADONLY;
4423 * We have a mountpoint, 'cause we're trying to set the Unix mode
4424 * bits to something with some x bits missing (default mode bits
4425 * if AFS_SETMODE is false is 0777)
4427 if (VanillaUser(client) && !(rights & PRSFS_ADMINISTER)) {
4433 /* get a new vnode for the symlink and set it up */
4435 Alloc_NewVnode(parentptr, &dir, volptr, &targetptr, Name, OutFid,
4436 vSymlink, nBlocks(strlen((char *)LinkContents))))) {
4440 /* update the status of the parent vnode */
4441 #if FS_STATS_DETAILED
4442 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4443 parentptr->disk.linkCount,
4444 client->InSameNetwork);
4446 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4447 parentptr->disk.linkCount);
4448 #endif /* FS_STATS_DETAILED */
4450 /* update the status of the new symbolic link file vnode */
4451 Update_TargetVnodeStatus(targetptr, TVS_SLINK, client, InStatus,
4452 parentptr, volptr, strlen((char *)LinkContents));
4454 /* Write the contents of the symbolic link name into the target inode */
4455 fdP = IH_OPEN(targetptr->handle);
4457 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4459 VTakeOffline(volptr);
4460 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
4464 len = strlen((char *) LinkContents);
4465 code = (len == FDH_WRITE(fdP, (char *) LinkContents, len)) ? 0 : VDISKFULL;
4467 ViceLog(0, ("SAFSS_Symlink FDH_WRITE failed for len=%d, Fid=%u.%d.%d\n", (int)len, OutFid->Volume, OutFid->Vnode, OutFid->Unique));
4470 * Set up and return modified status for the parent dir and new symlink
4473 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4474 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4476 /* convert the write lock to a read lock before breaking callbacks */
4477 VVnodeWriteToRead(&errorCode, parentptr);
4478 assert(!errorCode || errorCode == VSALVAGE);
4480 /* break call back on the parent dir */
4481 BreakCallBack(client->host, DirFid, 0);
4484 /* Write the all modified vnodes (parent, new files) and volume back */
4485 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4488 ViceLog(2, ("SAFS_Symlink returns %d\n", errorCode));
4489 return ( errorCode ? errorCode : code );
4491 } /*SAFSS_Symlink */
4495 SRXAFS_Symlink(struct rx_call *acall, /* Rx call */
4496 struct AFSFid *DirFid, /* Parent dir's fid */
4497 char *Name, /* File name to create */
4498 char *LinkContents, /* Contents of the new created file */
4499 struct AFSStoreStatus *InStatus, /* Input status for the new symbolic link */
4500 struct AFSFid *OutFid, /* Fid for newly created symbolic link */
4501 struct AFSFetchStatus *OutFidStatus, /* Output status for new symbolic link */
4502 struct AFSFetchStatus *OutDirStatus, /* Output status for parent dir */
4503 struct AFSVolSync *Sync)
4506 struct rx_connection *tcon;
4508 struct client *t_client = NULL; /* tmp ptr to client data */
4509 #if FS_STATS_DETAILED
4510 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4511 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4512 struct timeval elapsedTime; /* Transfer time */
4515 * Set our stats pointer, remember when the RPC operation started, and
4516 * tally the operation.
4518 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SYMLINK]);
4522 FT_GetTimeOfDay(&opStartTime, 0);
4523 #endif /* FS_STATS_DETAILED */
4525 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4529 SAFSS_Symlink(acall, DirFid, Name, LinkContents, InStatus, OutFid,
4530 OutFidStatus, OutDirStatus, Sync);
4533 code = CallPostamble(tcon, code, thost);
4535 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4537 #if FS_STATS_DETAILED
4538 FT_GetTimeOfDay(&opStopTime, 0);
4541 (opP->numSuccesses)++;
4542 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4543 fs_stats_AddTo((opP->sumTime), elapsedTime);
4544 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4545 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4546 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4548 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4549 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4553 #endif /* FS_STATS_DETAILED */
4555 osi_auditU(acall, SymlinkEvent, code,
4556 AUD_ID, t_client ? t_client->ViceId : 0,
4557 AUD_FID, DirFid, AUD_STR, Name,
4558 AUD_FID, OutFid, AUD_STR, LinkContents, AUD_END);
4561 } /*SRXAFS_Symlink */
4565 * This routine is called exclusively by SRXAFS_Link(), and should be
4566 * merged into it when possible.
4569 SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4570 struct AFSFid *ExistingFid, struct AFSFetchStatus *OutFidStatus,
4571 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4573 Vnode *parentptr = 0; /* vnode of input Directory */
4574 Vnode *targetptr = 0; /* vnode of the new file */
4575 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4576 Volume *volptr = 0; /* pointer to the volume header */
4577 Error errorCode = 0; /* error code */
4578 DirHandle dir; /* Handle for dir package I/O */
4579 struct client *client = 0; /* pointer to client structure */
4580 afs_int32 rights, anyrights; /* rights for this and any user */
4581 struct client *t_client; /* tmp ptr to client data */
4582 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4583 struct rx_connection *tcon = rx_ConnectionOf(acall);
4587 /* Get ptr to client data for user Id for logging */
4588 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4589 logHostAddr.s_addr = rxr_HostOf(tcon);
4591 ("SAFS_Link %s, Did = %u.%u.%u, Fid = %u.%u.%u, Host %s:%d, Id %d\n",
4592 Name, DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4593 ExistingFid->Volume, ExistingFid->Vnode, ExistingFid->Unique,
4594 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4596 AFSCallStats.Link++, AFSCallStats.TotalCalls++;
4598 if (DirFid->Volume != ExistingFid->Volume) {
4602 if (!FileNameOK(Name)) {
4608 * Get the vnode and volume for the parent dir along with the caller's
4612 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4613 &parentwhentargetnotdir, &client, WRITE_LOCK,
4614 &rights, &anyrights))) {
4618 /* set volume synchronization information */
4619 SetVolumeSync(Sync, volptr);
4621 /* Can the caller insert into the parent directory? */
4622 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4626 if (((DirFid->Vnode & 1) && (ExistingFid->Vnode & 1)) || (DirFid->Vnode == ExistingFid->Vnode)) { /* at present, */
4627 /* AFS fileservers always have directory vnodes that are odd. */
4632 /* get the file vnode */
4634 CheckVnode(ExistingFid, &volptr, &targetptr, WRITE_LOCK))) {
4637 if (targetptr->disk.type != vFile) {
4641 if (targetptr->disk.parent != DirFid->Vnode) {
4645 if (parentptr->disk.cloned) {
4646 ViceLog(25, ("Link : calling CopyOnWrite on target dir\n"));
4647 if ((errorCode = CopyOnWrite(parentptr, volptr, 0, MAXFSIZE)))
4648 goto Bad_Link; /* disk full error */
4651 /* add the name to the directory */
4652 SetDirHandle(&dir, parentptr);
4653 if ((errorCode = Create(&dir, (char *)Name, ExistingFid)))
4657 /* update the status in the parent vnode */
4658 /**WARNING** --> disk.author SHOULDN'T be modified???? */
4659 #if FS_STATS_DETAILED
4660 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4661 parentptr->disk.linkCount,
4662 client->InSameNetwork);
4664 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
4665 parentptr->disk.linkCount);
4666 #endif /* FS_STATS_DETAILED */
4668 targetptr->disk.linkCount++;
4669 targetptr->disk.author = client->ViceId;
4670 targetptr->changed_newTime = 1; /* Status change of linked-to file */
4672 /* set up return status */
4673 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4674 GetStatus(parentptr, OutDirStatus, rights, anyrights, 0);
4676 /* convert the write locks to read locks before breaking callbacks */
4677 VVnodeWriteToRead(&errorCode, targetptr);
4678 assert(!errorCode || errorCode == VSALVAGE);
4679 VVnodeWriteToRead(&errorCode, parentptr);
4680 assert(!errorCode || errorCode == VSALVAGE);
4682 /* break call back on DirFid */
4683 BreakCallBack(client->host, DirFid, 0);
4685 * We also need to break the callback for the file that is hard-linked since part
4686 * of its status (like linkcount) is changed
4688 BreakCallBack(client->host, ExistingFid, 0);
4691 /* Write the all modified vnodes (parent, new files) and volume back */
4692 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4695 ViceLog(2, ("SAFS_Link returns %d\n", errorCode));
4702 SRXAFS_Link(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4703 struct AFSFid * ExistingFid, struct AFSFetchStatus * OutFidStatus,
4704 struct AFSFetchStatus * OutDirStatus, struct AFSVolSync * Sync)
4707 struct rx_connection *tcon;
4709 struct client *t_client = NULL; /* tmp ptr to client data */
4710 #if FS_STATS_DETAILED
4711 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4712 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4713 struct timeval elapsedTime; /* Transfer time */
4716 * Set our stats pointer, remember when the RPC operation started, and
4717 * tally the operation.
4719 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_LINK]);
4723 FT_GetTimeOfDay(&opStartTime, 0);
4724 #endif /* FS_STATS_DETAILED */
4726 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4730 SAFSS_Link(acall, DirFid, Name, ExistingFid, OutFidStatus,
4731 OutDirStatus, Sync);
4734 code = CallPostamble(tcon, code, thost);
4736 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4738 #if FS_STATS_DETAILED
4739 FT_GetTimeOfDay(&opStopTime, 0);
4742 (opP->numSuccesses)++;
4743 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4744 fs_stats_AddTo((opP->sumTime), elapsedTime);
4745 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4746 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4747 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4749 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4750 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4754 #endif /* FS_STATS_DETAILED */
4756 osi_auditU(acall, LinkEvent, code,
4757 AUD_ID, t_client ? t_client->ViceId : 0,
4758 AUD_FID, DirFid, AUD_STR, Name,
4759 AUD_FID, ExistingFid, AUD_END);
4766 * This routine is called exclusively by SRXAFS_MakeDir(), and should be
4767 * merged into it when possible.
4770 SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4771 struct AFSStoreStatus *InStatus, struct AFSFid *OutFid,
4772 struct AFSFetchStatus *OutFidStatus,
4773 struct AFSFetchStatus *OutDirStatus,
4774 struct AFSCallBack *CallBack, struct AFSVolSync *Sync)
4776 Vnode *parentptr = 0; /* vnode of input Directory */
4777 Vnode *targetptr = 0; /* vnode of the new file */
4778 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4779 Volume *volptr = 0; /* pointer to the volume header */
4780 Error errorCode = 0; /* error code */
4781 struct acl_accessList *newACL; /* Access list */
4782 int newACLSize; /* Size of access list */
4783 DirHandle dir; /* Handle for dir package I/O */
4784 DirHandle parentdir; /* Handle for dir package I/O */
4785 struct client *client = 0; /* pointer to client structure */
4786 afs_int32 rights, anyrights; /* rights for this and any user */
4787 struct client *t_client; /* tmp ptr to client data */
4788 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4789 struct rx_connection *tcon = rx_ConnectionOf(acall);
4792 FidZero(&parentdir);
4794 /* Get ptr to client data for user Id for logging */
4795 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4796 logHostAddr.s_addr = rxr_HostOf(tcon);
4798 ("SAFS_MakeDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4799 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4800 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4802 AFSCallStats.MakeDir++, AFSCallStats.TotalCalls++;
4804 if (!FileNameOK(Name)) {
4810 * Get the vnode and volume for the parent dir along with the caller's
4814 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
4815 &parentwhentargetnotdir, &client, WRITE_LOCK,
4816 &rights, &anyrights))) {
4820 /* set volume synchronization information */
4821 SetVolumeSync(Sync, volptr);
4823 /* Write access to the parent directory? */
4824 #ifdef DIRCREATE_NEED_WRITE
4826 * requires w access for the user to create a directory. this
4827 * closes a loophole in the current security arrangement, since a
4828 * user with i access only can create a directory and get the
4829 * implcit a access that goes with dir ownership, and proceed to
4830 * subvert quota in the volume.
4832 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))
4833 || (errorCode = CheckWriteMode(parentptr, rights, PRSFS_WRITE))) {
4835 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_INSERT))) {
4836 #endif /* DIRCREATE_NEED_WRITE */
4839 #define EMPTYDIRBLOCKS 2
4840 /* get a new vnode and set it up */
4842 Alloc_NewVnode(parentptr, &parentdir, volptr, &targetptr, Name,
4843 OutFid, vDirectory, EMPTYDIRBLOCKS))) {
4847 /* Update the status for the parent dir */
4848 #if FS_STATS_DETAILED
4849 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4850 parentptr->disk.linkCount + 1,
4851 client->InSameNetwork);
4853 Update_ParentVnodeStatus(parentptr, volptr, &parentdir, client->ViceId,
4854 parentptr->disk.linkCount + 1);
4855 #endif /* FS_STATS_DETAILED */
4857 /* Point to target's ACL buffer and copy the parent's ACL contents to it */
4858 assert((SetAccessList
4859 (&targetptr, &volptr, &newACL, &newACLSize,
4860 &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0);
4861 assert(parentwhentargetnotdir == 0);
4862 memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr));
4864 /* update the status for the target vnode */
4865 Update_TargetVnodeStatus(targetptr, TVS_MKDIR, client, InStatus,
4866 parentptr, volptr, 0);
4868 /* Actually create the New directory in the directory package */
4869 SetDirHandle(&dir, targetptr);
4870 assert(!(MakeDir(&dir, (afs_int32 *)OutFid, (afs_int32 *)DirFid)));
4872 VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir));
4874 /* set up return status */
4875 GetStatus(targetptr, OutFidStatus, rights, anyrights, parentptr);
4876 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
4878 /* convert the write lock to a read lock before breaking callbacks */
4879 VVnodeWriteToRead(&errorCode, parentptr);
4880 assert(!errorCode || errorCode == VSALVAGE);
4882 /* break call back on DirFid */
4883 BreakCallBack(client->host, DirFid, 0);
4885 /* Return a callback promise to caller */
4886 SetCallBackStruct(AddCallBack(client->host, OutFid), CallBack);
4889 /* Write the all modified vnodes (parent, new files) and volume back */
4890 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
4894 ViceLog(2, ("SAFS_MakeDir returns %d\n", errorCode));
4897 } /*SAFSS_MakeDir */
4901 SRXAFS_MakeDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
4902 struct AFSStoreStatus * InStatus, struct AFSFid * OutFid,
4903 struct AFSFetchStatus * OutFidStatus,
4904 struct AFSFetchStatus * OutDirStatus,
4905 struct AFSCallBack * CallBack, struct AFSVolSync * Sync)
4908 struct rx_connection *tcon;
4910 struct client *t_client = NULL; /* tmp ptr to client data */
4911 #if FS_STATS_DETAILED
4912 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
4913 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
4914 struct timeval elapsedTime; /* Transfer time */
4917 * Set our stats pointer, remember when the RPC operation started, and
4918 * tally the operation.
4920 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_MAKEDIR]);
4924 FT_GetTimeOfDay(&opStartTime, 0);
4925 #endif /* FS_STATS_DETAILED */
4926 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
4930 SAFSS_MakeDir(acall, DirFid, Name, InStatus, OutFid, OutFidStatus,
4931 OutDirStatus, CallBack, Sync);
4934 code = CallPostamble(tcon, code, thost);
4936 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4938 #if FS_STATS_DETAILED
4939 FT_GetTimeOfDay(&opStopTime, 0);
4942 (opP->numSuccesses)++;
4943 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
4944 fs_stats_AddTo((opP->sumTime), elapsedTime);
4945 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
4946 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
4947 fs_stats_TimeAssign((opP->minTime), elapsedTime);
4949 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
4950 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
4954 #endif /* FS_STATS_DETAILED */
4956 osi_auditU(acall, MakeDirEvent, code,
4957 AUD_ID, t_client ? t_client->ViceId : 0,
4958 AUD_FID, DirFid, AUD_STR, Name,
4959 AUD_FID, OutFid, AUD_END);
4962 } /*SRXAFS_MakeDir */
4966 * This routine is called exclusively by SRXAFS_RemoveDir(), and should be
4967 * merged into it when possible.
4970 SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name,
4971 struct AFSFetchStatus *OutDirStatus, struct AFSVolSync *Sync)
4973 Vnode *parentptr = 0; /* vnode of input Directory */
4974 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
4975 Vnode *targetptr = 0; /* file to be deleted */
4976 AFSFid fileFid; /* area for Fid from the directory */
4977 Error errorCode = 0; /* error code */
4978 DirHandle dir; /* Handle for dir package I/O */
4979 Volume *volptr = 0; /* pointer to the volume header */
4980 struct client *client = 0; /* pointer to client structure */
4981 afs_int32 rights, anyrights; /* rights for this and any user */
4982 Vnode debugvnode1, debugvnode2;
4983 struct client *t_client; /* tmp ptr to client data */
4984 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
4985 struct rx_connection *tcon = rx_ConnectionOf(acall);
4989 /* Get ptr to client data for user Id for logging */
4990 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
4991 logHostAddr.s_addr = rxr_HostOf(tcon);
4993 ("SAFS_RemoveDir %s, Did = %u.%u.%u, Host %s:%d, Id %d\n", Name,
4994 DirFid->Volume, DirFid->Vnode, DirFid->Unique,
4995 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
4997 AFSCallStats.RemoveDir++, AFSCallStats.TotalCalls++;
5000 * Get the vnode and volume for the parent dir along with the caller's
5004 GetVolumePackage(tcon, DirFid, &volptr, &parentptr, MustBeDIR,
5005 &parentwhentargetnotdir, &client, WRITE_LOCK,
5006 &rights, &anyrights))) {
5009 debugvnode1 = *parentptr;
5011 /* set volume synchronization information */
5012 SetVolumeSync(Sync, volptr);
5014 /* Does the caller has delete (&write) access to the parent dir? */
5015 if ((errorCode = CheckWriteMode(parentptr, rights, PRSFS_DELETE))) {
5019 debugvnode2 = *parentptr;
5020 /* Do the actual delete of the desired (empty) directory, Name */
5022 DeleteTarget(parentptr, volptr, &targetptr, &dir, &fileFid, Name,
5027 /* Update the status for the parent dir; link count is also adjusted */
5028 #if FS_STATS_DETAILED
5029 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
5030 parentptr->disk.linkCount - 1,
5031 client->InSameNetwork);
5033 Update_ParentVnodeStatus(parentptr, volptr, &dir, client->ViceId,
5034 parentptr->disk.linkCount - 1);
5035 #endif /* FS_STATS_DETAILED */
5037 /* Return to the caller the updated parent dir status */
5038 GetStatus(parentptr, OutDirStatus, rights, anyrights, NULL);
5041 * Note: it is not necessary to break the callback on fileFid, since
5042 * refcount is now 0, so no one should be able to refer to the dir
5045 DeleteFileCallBacks(&fileFid);
5047 /* convert the write lock to a read lock before breaking callbacks */
5048 VVnodeWriteToRead(&errorCode, parentptr);
5049 assert(!errorCode || errorCode == VSALVAGE);
5051 /* break call back on DirFid and fileFid */
5052 BreakCallBack(client->host, DirFid, 0);
5055 /* Write the all modified vnodes (parent, new files) and volume back */
5056 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, parentptr,
5059 ViceLog(2, ("SAFS_RemoveDir returns %d\n", errorCode));
5062 } /*SAFSS_RemoveDir */
5066 SRXAFS_RemoveDir(struct rx_call * acall, struct AFSFid * DirFid, char *Name,
5067 struct AFSFetchStatus * OutDirStatus,
5068 struct AFSVolSync * Sync)
5071 struct rx_connection *tcon;
5073 struct client *t_client = NULL; /* tmp ptr to client data */
5074 #if FS_STATS_DETAILED
5075 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5076 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5077 struct timeval elapsedTime; /* Transfer time */
5080 * Set our stats pointer, remember when the RPC operation started, and
5081 * tally the operation.
5083 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_REMOVEDIR]);
5087 FT_GetTimeOfDay(&opStartTime, 0);
5088 #endif /* FS_STATS_DETAILED */
5090 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5093 code = SAFSS_RemoveDir(acall, DirFid, Name, OutDirStatus, Sync);
5096 code = CallPostamble(tcon, code, thost);
5098 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5100 #if FS_STATS_DETAILED
5101 FT_GetTimeOfDay(&opStopTime, 0);
5104 (opP->numSuccesses)++;
5105 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5106 fs_stats_AddTo((opP->sumTime), elapsedTime);
5107 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5108 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5109 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5111 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5112 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5116 #endif /* FS_STATS_DETAILED */
5118 osi_auditU(acall, RemoveDirEvent, code,
5119 AUD_ID, t_client ? t_client->ViceId : 0,
5120 AUD_FID, DirFid, AUD_STR, Name, AUD_END);
5123 } /*SRXAFS_RemoveDir */
5127 * This routine is called exclusively by SRXAFS_SetLock(), and should be
5128 * merged into it when possible.
5131 SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type,
5132 struct AFSVolSync *Sync)
5134 Vnode *targetptr = 0; /* vnode of input file */
5135 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5136 Error errorCode = 0; /* error code */
5137 Volume *volptr = 0; /* pointer to the volume header */
5138 struct client *client = 0; /* pointer to client structure */
5139 afs_int32 rights, anyrights; /* rights for this and any user */
5140 struct client *t_client; /* tmp ptr to client data */
5141 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5142 static char *locktype[4] = { "LockRead", "LockWrite", "LockExtend", "LockRelease" };
5143 struct rx_connection *tcon = rx_ConnectionOf(acall);
5145 if (type != LockRead && type != LockWrite) {
5149 /* Get ptr to client data for user Id for logging */
5150 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5151 logHostAddr.s_addr = rxr_HostOf(tcon);
5153 ("SAFS_SetLock type = %s Fid = %u.%u.%u, Host %s:%d, Id %d\n",
5154 locktype[(int)type], Fid->Volume, Fid->Vnode, Fid->Unique,
5155 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5157 AFSCallStats.SetLock++, AFSCallStats.TotalCalls++;
5160 * Get the vnode and volume for the desired file along with the caller's
5164 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5165 &parentwhentargetnotdir, &client, WRITE_LOCK,
5166 &rights, &anyrights))) {
5170 /* set volume synchronization information */
5171 SetVolumeSync(Sync, volptr);
5173 /* Handle the particular type of set locking, type */
5174 errorCode = HandleLocking(targetptr, client, rights, type);
5177 /* Write the all modified vnodes (parent, new files) and volume back */
5178 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5181 if ((errorCode == VREADONLY) && (type == LockRead))
5182 errorCode = 0; /* allow read locks on RO volumes without saving state */
5184 ViceLog(2, ("SAFS_SetLock returns %d\n", errorCode));
5187 } /*SAFSS_SetLock */
5191 SRXAFS_OldSetLock(struct rx_call * acall, struct AFSFid * Fid,
5192 ViceLockType type, struct AFSVolSync * Sync)
5194 return SRXAFS_SetLock(acall, Fid, type, Sync);
5195 } /*SRXAFS_OldSetLock */
5199 SRXAFS_SetLock(struct rx_call * acall, struct AFSFid * Fid, ViceLockType type,
5200 struct AFSVolSync * Sync)
5203 struct rx_connection *tcon;
5205 struct client *t_client = NULL; /* tmp ptr to client data */
5206 #if FS_STATS_DETAILED
5207 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5208 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5209 struct timeval elapsedTime; /* Transfer time */
5212 * Set our stats pointer, remember when the RPC operation started, and
5213 * tally the operation.
5215 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETLOCK]);
5219 FT_GetTimeOfDay(&opStartTime, 0);
5220 #endif /* FS_STATS_DETAILED */
5222 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5225 code = SAFSS_SetLock(acall, Fid, type, Sync);
5228 code = CallPostamble(tcon, code, thost);
5230 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5232 #if FS_STATS_DETAILED
5233 FT_GetTimeOfDay(&opStopTime, 0);
5236 (opP->numSuccesses)++;
5237 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5238 fs_stats_AddTo((opP->sumTime), elapsedTime);
5239 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5240 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5241 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5243 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5244 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5248 #endif /* FS_STATS_DETAILED */
5250 osi_auditU(acall, SetLockEvent, code,
5251 AUD_ID, t_client ? t_client->ViceId : 0,
5252 AUD_FID, Fid, AUD_LONG, type, AUD_END);
5254 } /*SRXAFS_SetLock */
5258 * This routine is called exclusively by SRXAFS_ExtendLock(), and should be
5259 * merged into it when possible.
5262 SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid,
5263 struct AFSVolSync *Sync)
5265 Vnode *targetptr = 0; /* vnode of input file */
5266 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5267 Error errorCode = 0; /* error code */
5268 Volume *volptr = 0; /* pointer to the volume header */
5269 struct client *client = 0; /* pointer to client structure */
5270 afs_int32 rights, anyrights; /* rights for this and any user */
5271 struct client *t_client; /* tmp ptr to client data */
5272 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5273 struct rx_connection *tcon = rx_ConnectionOf(acall);
5275 /* Get ptr to client data for user Id for logging */
5276 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5277 logHostAddr.s_addr = rxr_HostOf(tcon);
5279 ("SAFS_ExtendLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5280 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5281 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5283 AFSCallStats.ExtendLock++, AFSCallStats.TotalCalls++;
5286 * Get the vnode and volume for the desired file along with the caller's
5290 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5291 &parentwhentargetnotdir, &client, WRITE_LOCK,
5292 &rights, &anyrights))) {
5293 goto Bad_ExtendLock;
5296 /* set volume synchronization information */
5297 SetVolumeSync(Sync, volptr);
5299 /* Handle the actual lock extension */
5300 errorCode = HandleLocking(targetptr, client, rights, LockExtend);
5303 /* Put back file's vnode and volume */
5304 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5307 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5308 errorCode = 0; /* under our generous policy re RO vols */
5310 ViceLog(2, ("SAFS_ExtendLock returns %d\n", errorCode));
5313 } /*SAFSS_ExtendLock */
5317 SRXAFS_OldExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5318 struct AFSVolSync * Sync)
5320 return SRXAFS_ExtendLock(acall, Fid, Sync);
5321 } /*SRXAFS_OldExtendLock */
5325 SRXAFS_ExtendLock(struct rx_call * acall, struct AFSFid * Fid,
5326 struct AFSVolSync * Sync)
5329 struct rx_connection *tcon;
5331 struct client *t_client = NULL; /* tmp ptr to client data */
5332 #if FS_STATS_DETAILED
5333 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5334 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5335 struct timeval elapsedTime; /* Transfer time */
5338 * Set our stats pointer, remember when the RPC operation started, and
5339 * tally the operation.
5341 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_EXTENDLOCK]);
5345 FT_GetTimeOfDay(&opStartTime, 0);
5346 #endif /* FS_STATS_DETAILED */
5348 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5349 goto Bad_ExtendLock;
5351 code = SAFSS_ExtendLock(acall, Fid, Sync);
5354 code = CallPostamble(tcon, code, thost);
5356 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5358 #if FS_STATS_DETAILED
5359 FT_GetTimeOfDay(&opStopTime, 0);
5362 (opP->numSuccesses)++;
5363 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5364 fs_stats_AddTo((opP->sumTime), elapsedTime);
5365 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5366 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5367 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5369 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5370 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5374 #endif /* FS_STATS_DETAILED */
5376 osi_auditU(acall, ExtendLockEvent, code,
5377 AUD_ID, t_client ? t_client->ViceId : 0,
5378 AUD_FID, Fid, AUD_END);
5381 } /*SRXAFS_ExtendLock */
5385 * This routine is called exclusively by SRXAFS_ReleaseLock(), and should be
5386 * merged into it when possible.
5389 SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid,
5390 struct AFSVolSync *Sync)
5392 Vnode *targetptr = 0; /* vnode of input file */
5393 Vnode *parentwhentargetnotdir = 0; /* parent for use in SetAccessList */
5394 Error errorCode = 0; /* error code */
5395 Volume *volptr = 0; /* pointer to the volume header */
5396 struct client *client = 0; /* pointer to client structure */
5397 afs_int32 rights, anyrights; /* rights for this and any user */
5398 struct client *t_client; /* tmp ptr to client data */
5399 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
5400 struct rx_connection *tcon = rx_ConnectionOf(acall);
5402 /* Get ptr to client data for user Id for logging */
5403 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5404 logHostAddr.s_addr = rxr_HostOf(tcon);
5406 ("SAFS_ReleaseLock Fid = %u.%u.%u, Host %s:%d, Id %d\n", Fid->Volume,
5407 Fid->Vnode, Fid->Unique, inet_ntoa(logHostAddr),
5408 ntohs(rxr_PortOf(tcon)), t_client->ViceId));
5410 AFSCallStats.ReleaseLock++, AFSCallStats.TotalCalls++;
5413 * Get the vnode and volume for the desired file along with the caller's
5417 GetVolumePackage(tcon, Fid, &volptr, &targetptr, DONTCHECK,
5418 &parentwhentargetnotdir, &client, WRITE_LOCK,
5419 &rights, &anyrights))) {
5420 goto Bad_ReleaseLock;
5423 /* set volume synchronization information */
5424 SetVolumeSync(Sync, volptr);
5426 /* Handle the actual lock release */
5427 if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease)))
5428 goto Bad_ReleaseLock;
5430 /* if no more locks left, a callback would be triggered here */
5431 if (targetptr->disk.lock.lockCount <= 0) {
5432 /* convert the write lock to a read lock before breaking callbacks */
5433 VVnodeWriteToRead(&errorCode, targetptr);
5434 assert(!errorCode || errorCode == VSALVAGE);
5435 BreakCallBack(client->host, Fid, 0);
5439 /* Put back file's vnode and volume */
5440 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
5443 if ((errorCode == VREADONLY)) /* presumably, we already granted this lock */
5444 errorCode = 0; /* under our generous policy re RO vols */
5446 ViceLog(2, ("SAFS_ReleaseLock returns %d\n", errorCode));
5449 } /*SAFSS_ReleaseLock */
5453 SRXAFS_OldReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5454 struct AFSVolSync * Sync)
5456 return SRXAFS_ReleaseLock(acall, Fid, Sync);
5457 } /*SRXAFS_OldReleaseLock */
5461 SRXAFS_ReleaseLock(struct rx_call * acall, struct AFSFid * Fid,
5462 struct AFSVolSync * Sync)
5465 struct rx_connection *tcon;
5467 struct client *t_client = NULL; /* tmp ptr to client data */
5468 #if FS_STATS_DETAILED
5469 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5470 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5471 struct timeval elapsedTime; /* Transfer time */
5474 * Set our stats pointer, remember when the RPC operation started, and
5475 * tally the operation.
5477 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_RELEASELOCK]);
5481 FT_GetTimeOfDay(&opStartTime, 0);
5482 #endif /* FS_STATS_DETAILED */
5484 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
5485 goto Bad_ReleaseLock;
5487 code = SAFSS_ReleaseLock(acall, Fid, Sync);
5490 code = CallPostamble(tcon, code, thost);
5492 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5494 #if FS_STATS_DETAILED
5495 FT_GetTimeOfDay(&opStopTime, 0);
5498 (opP->numSuccesses)++;
5499 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5500 fs_stats_AddTo((opP->sumTime), elapsedTime);
5501 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5502 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5503 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5505 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5506 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5510 #endif /* FS_STATS_DETAILED */
5512 osi_auditU(acall, ReleaseLockEvent, code,
5513 AUD_ID, t_client ? t_client->ViceId : 0,
5514 AUD_FID, Fid, AUD_END);
5517 } /*SRXAFS_ReleaseLock */
5521 SetSystemStats(struct AFSStatistics *stats)
5523 /* Fix this sometime soon.. */
5524 /* Because hey, it's not like we have a network monitoring protocol... */
5525 struct timeval time;
5527 /* this works on all system types */
5528 FT_GetTimeOfDay(&time, 0);
5529 stats->CurrentTime = time.tv_sec;
5530 } /*SetSystemStats */
5533 SetAFSStats(struct AFSStatistics *stats)
5535 extern afs_int32 StartTime, CurrentConnections;
5539 stats->CurrentMsgNumber = 0;
5540 stats->OldestMsgNumber = 0;
5541 stats->StartTime = StartTime;
5542 stats->CurrentConnections = CurrentConnections;
5543 stats->TotalAFSCalls = AFSCallStats.TotalCalls;
5544 stats->TotalFetchs =
5545 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5546 AFSCallStats.FetchStatus;
5547 stats->FetchDatas = AFSCallStats.FetchData;
5548 stats->FetchedBytes = AFSCallStats.TotalFetchedBytes;
5549 seconds = AFSCallStats.AccumFetchTime / 1000;
5552 stats->FetchDataRate = AFSCallStats.TotalFetchedBytes / seconds;
5553 stats->TotalStores =
5554 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5555 AFSCallStats.StoreStatus;
5556 stats->StoreDatas = AFSCallStats.StoreData;
5557 stats->StoredBytes = AFSCallStats.TotalStoredBytes;
5558 seconds = AFSCallStats.AccumStoreTime / 1000;
5561 stats->StoreDataRate = AFSCallStats.TotalStoredBytes / seconds;
5563 stats->ProcessSize = -1; /* TODO: */
5565 stats->ProcessSize = (afs_int32) ((long)sbrk(0) >> 10);
5568 h_GetWorkStats((int *)&(stats->WorkStations),
5569 (int *)&(stats->ActiveWorkStations), (int *)0,
5570 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5574 /* Get disk related information from all AFS partitions. */
5577 SetVolumeStats(struct AFSStatistics *stats)
5579 struct DiskPartition64 *part;
5582 for (part = DiskPartitionList; part && i < AFS_MSTATDISKS;
5583 part = part->next) {
5584 stats->Disks[i].TotalBlocks = RoundInt64ToInt32(part->totalUsable);
5585 stats->Disks[i].BlocksAvailable = RoundInt64ToInt32(part->free);
5586 memset(stats->Disks[i].Name, 0, AFS_DISKNAMESIZE);
5587 strncpy(stats->Disks[i].Name, part->name, AFS_DISKNAMESIZE);
5590 while (i < AFS_MSTATDISKS) {
5591 stats->Disks[i].TotalBlocks = -1;
5594 } /*SetVolumeStats */
5597 SRXAFS_GetStatistics(struct rx_call *acall, struct ViceStatistics *Statistics)
5600 struct rx_connection *tcon = rx_ConnectionOf(acall);
5602 struct client *t_client = NULL; /* tmp ptr to client data */
5603 #if FS_STATS_DETAILED
5604 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5605 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5606 struct timeval elapsedTime; /* Transfer time */
5609 * Set our stats pointer, remember when the RPC operation started, and
5610 * tally the operation.
5612 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5616 FT_GetTimeOfDay(&opStartTime, 0);
5617 #endif /* FS_STATS_DETAILED */
5619 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5620 goto Bad_GetStatistics;
5622 ViceLog(1, ("SAFS_GetStatistics Received\n"));
5624 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5626 memset(Statistics, 0, sizeof(*Statistics));
5627 SetAFSStats((struct AFSStatistics *)Statistics);
5628 SetVolumeStats((struct AFSStatistics *)Statistics);
5629 SetSystemStats((struct AFSStatistics *)Statistics);
5632 code = CallPostamble(tcon, code, thost);
5634 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5636 #if FS_STATS_DETAILED
5637 FT_GetTimeOfDay(&opStopTime, 0);
5640 (opP->numSuccesses)++;
5641 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5642 fs_stats_AddTo((opP->sumTime), elapsedTime);
5643 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5644 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5645 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5647 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5648 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5652 #endif /* FS_STATS_DETAILED */
5654 osi_auditU(acall, GetStatisticsEvent, code,
5655 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5657 } /*SRXAFS_GetStatistics */
5661 SRXAFS_GetStatistics64(struct rx_call *acall, afs_int32 statsVersion, ViceStatistics64 *Statistics)
5663 extern afs_int32 StartTime, CurrentConnections;
5666 struct rx_connection *tcon = rx_ConnectionOf(acall);
5668 struct client *t_client = NULL; /* tmp ptr to client data */
5669 struct timeval time;
5670 #if FS_STATS_DETAILED
5671 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5672 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5673 struct timeval elapsedTime; /* Transfer time */
5676 * Set our stats pointer, remember when the RPC operation started, and
5677 * tally the operation.
5679 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETSTATISTICS]);
5683 FT_GetTimeOfDay(&opStartTime, 0);
5684 #endif /* FS_STATS_DETAILED */
5686 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
5687 goto Bad_GetStatistics64;
5689 ViceLog(1, ("SAFS_GetStatistics64 Received\n"));
5690 Statistics->ViceStatistics64_val =
5691 malloc(statsVersion*sizeof(afs_int64));
5692 Statistics->ViceStatistics64_len = statsVersion;
5694 AFSCallStats.GetStatistics++, AFSCallStats.TotalCalls++;
5695 Statistics->ViceStatistics64_val[STATS64_STARTTIME] = StartTime;
5696 Statistics->ViceStatistics64_val[STATS64_CURRENTCONNECTIONS] =
5698 Statistics->ViceStatistics64_val[STATS64_TOTALVICECALLS] =
5699 AFSCallStats.TotalCalls;
5700 Statistics->ViceStatistics64_val[STATS64_TOTALFETCHES] =
5701 AFSCallStats.FetchData + AFSCallStats.FetchACL +
5702 AFSCallStats.FetchStatus;
5703 Statistics->ViceStatistics64_val[STATS64_FETCHDATAS] =
5704 AFSCallStats.FetchData;
5705 Statistics->ViceStatistics64_val[STATS64_FETCHEDBYTES] =
5706 AFSCallStats.TotalFetchedBytes;
5707 seconds = AFSCallStats.AccumFetchTime / 1000;
5710 Statistics->ViceStatistics64_val[STATS64_FETCHDATARATE] =
5711 AFSCallStats.TotalFetchedBytes / seconds;
5712 Statistics->ViceStatistics64_val[STATS64_TOTALSTORES] =
5713 AFSCallStats.StoreData + AFSCallStats.StoreACL +
5714 AFSCallStats.StoreStatus;
5715 Statistics->ViceStatistics64_val[STATS64_STOREDATAS] =
5716 AFSCallStats.StoreData;
5717 Statistics->ViceStatistics64_val[STATS64_STOREDBYTES] =
5718 AFSCallStats.TotalStoredBytes;
5719 seconds = AFSCallStats.AccumStoreTime / 1000;
5722 Statistics->ViceStatistics64_val[STATS64_STOREDATARATE] =
5723 AFSCallStats.TotalStoredBytes / seconds;
5725 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] = -1;
5727 Statistics->ViceStatistics64_val[STATS64_PROCESSSIZE] =
5728 (afs_int32) ((long)sbrk(0) >> 10);
5731 h_GetWorkStats((int *)&(Statistics->ViceStatistics64_val[STATS64_WORKSTATIONS]),
5732 (int *)&(Statistics->ViceStatistics64_val[STATS64_ACTIVEWORKSTATIONS]),
5734 (afs_int32) (FT_ApproxTime()) - (15 * 60));
5738 /* this works on all system types */
5739 FT_GetTimeOfDay(&time, 0);
5740 Statistics->ViceStatistics64_val[STATS64_CURRENTTIME] = time.tv_sec;
5742 Bad_GetStatistics64:
5743 code = CallPostamble(tcon, code, thost);
5745 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5747 #if FS_STATS_DETAILED
5748 FT_GetTimeOfDay(&opStopTime, 0);
5751 (opP->numSuccesses)++;
5752 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5753 fs_stats_AddTo((opP->sumTime), elapsedTime);
5754 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5755 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5756 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5758 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5759 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5763 #endif /* FS_STATS_DETAILED */
5765 osi_auditU(acall, GetStatisticsEvent, code,
5766 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5768 } /*SRXAFS_GetStatistics */
5771 /*------------------------------------------------------------------------
5772 * EXPORTED SRXAFS_XStatsVersion
5775 * Routine called by the server-side RPC interface to implement
5776 * pulling out the xstat version number for the File Server.
5779 * a_versionP : Ptr to the version number variable to set.
5785 * Nothing interesting.
5789 *------------------------------------------------------------------------*/
5792 SRXAFS_XStatsVersion(struct rx_call * a_call, afs_int32 * a_versionP)
5793 { /*SRXAFS_XStatsVersion */
5795 struct client *t_client = NULL; /* tmp ptr to client data */
5796 struct rx_connection *tcon = rx_ConnectionOf(a_call);
5797 #if FS_STATS_DETAILED
5798 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
5799 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
5800 struct timeval elapsedTime; /* Transfer time */
5803 * Set our stats pointer, remember when the RPC operation started, and
5804 * tally the operation.
5806 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_XSTATSVERSION]);
5810 FT_GetTimeOfDay(&opStartTime, 0);
5811 #endif /* FS_STATS_DETAILED */
5813 *a_versionP = AFS_XSTAT_VERSION;
5815 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
5817 #if FS_STATS_DETAILED
5818 FT_GetTimeOfDay(&opStopTime, 0);
5819 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
5820 fs_stats_AddTo((opP->sumTime), elapsedTime);
5821 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
5822 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
5823 fs_stats_TimeAssign((opP->minTime), elapsedTime);
5825 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
5826 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
5829 (opP->numSuccesses)++;
5831 #endif /* FS_STATS_DETAILED */
5833 osi_auditU(a_call, XStatsVersionEvent, 0,
5834 AUD_ID, t_client ? t_client->ViceId : 0, AUD_END);
5836 } /*SRXAFS_XStatsVersion */
5839 /*------------------------------------------------------------------------
5840 * PRIVATE FillPerfValues
5843 * Routine called to fill a regular performance data structure.
5846 * a_perfP : Ptr to perf structure to fill
5852 * Various collections need this info, so the guts were put in
5853 * this separate routine.
5857 *------------------------------------------------------------------------*/
5860 FillPerfValues(struct afs_PerfStats *a_perfP)
5861 { /*FillPerfValues */
5863 int dir_Buffers; /*# buffers in use by dir package */
5864 int dir_Calls; /*# read calls in dir package */
5865 int dir_IOs; /*# I/O ops in dir package */
5868 * Vnode cache section.
5870 a_perfP->vcache_L_Entries = VnodeClassInfo[vLarge].cacheSize;
5871 a_perfP->vcache_L_Allocs = VnodeClassInfo[vLarge].allocs;
5872 a_perfP->vcache_L_Gets = VnodeClassInfo[vLarge].gets;
5873 a_perfP->vcache_L_Reads = VnodeClassInfo[vLarge].reads;
5874 a_perfP->vcache_L_Writes = VnodeClassInfo[vLarge].writes;
5875 a_perfP->vcache_S_Entries = VnodeClassInfo[vSmall].cacheSize;
5876 a_perfP->vcache_S_Allocs = VnodeClassInfo[vSmall].allocs;
5877 a_perfP->vcache_S_Gets = VnodeClassInfo[vSmall].gets;
5878 a_perfP->vcache_S_Reads = VnodeClassInfo[vSmall].reads;
5879 a_perfP->vcache_S_Writes = VnodeClassInfo[vSmall].writes;
5880 a_perfP->vcache_H_Entries = VStats.hdr_cache_size;
5881 SplitInt64(VStats.hdr_gets, hi, lo);
5882 a_perfP->vcache_H_Gets = lo;
5883 SplitInt64(VStats.hdr_loads, hi, lo);
5884 a_perfP->vcache_H_Replacements = lo;
5887 * Directory section.
5889 DStat(&dir_Buffers, &dir_Calls, &dir_IOs);
5890 a_perfP->dir_Buffers = (afs_int32) dir_Buffers;
5891 a_perfP->dir_Calls = (afs_int32) dir_Calls;
5892 a_perfP->dir_IOs = (afs_int32) dir_IOs;
5897 a_perfP->rx_packetRequests = (afs_int32) rx_stats.packetRequests;
5898 a_perfP->rx_noPackets_RcvClass =
5899 (afs_int32) rx_stats.receivePktAllocFailures;
5900 a_perfP->rx_noPackets_SendClass =
5901 (afs_int32) rx_stats.sendPktAllocFailures;
5902 a_perfP->rx_noPackets_SpecialClass =
5903 (afs_int32) rx_stats.specialPktAllocFailures;
5904 a_perfP->rx_socketGreedy = (afs_int32) rx_stats.socketGreedy;
5905 a_perfP->rx_bogusPacketOnRead = (afs_int32) rx_stats.bogusPacketOnRead;
5906 a_perfP->rx_bogusHost = (afs_int32) rx_stats.bogusHost;
5907 a_perfP->rx_noPacketOnRead = (afs_int32) rx_stats.noPacketOnRead;
5908 a_perfP->rx_noPacketBuffersOnRead =
5909 (afs_int32) rx_stats.noPacketBuffersOnRead;
5910 a_perfP->rx_selects = (afs_int32) rx_stats.selects;
5911 a_perfP->rx_sendSelects = (afs_int32) rx_stats.sendSelects;
5912 a_perfP->rx_packetsRead_RcvClass =
5913 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_RECEIVE];
5914 a_perfP->rx_packetsRead_SendClass =
5915 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SEND];
5916 a_perfP->rx_packetsRead_SpecialClass =
5917 (afs_int32) rx_stats.packetsRead[RX_PACKET_CLASS_SPECIAL];
5918 a_perfP->rx_dataPacketsRead = (afs_int32) rx_stats.dataPacketsRead;
5919 a_perfP->rx_ackPacketsRead = (afs_int32) rx_stats.ackPacketsRead;
5920 a_perfP->rx_dupPacketsRead = (afs_int32) rx_stats.dupPacketsRead;
5921 a_perfP->rx_spuriousPacketsRead =
5922 (afs_int32) rx_stats.spuriousPacketsRead;
5923 a_perfP->rx_packetsSent_RcvClass =
5924 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_RECEIVE];
5925 a_perfP->rx_packetsSent_SendClass =
5926 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SEND];
5927 a_perfP->rx_packetsSent_SpecialClass =
5928 (afs_int32) rx_stats.packetsSent[RX_PACKET_CLASS_SPECIAL];
5929 a_perfP->rx_ackPacketsSent = (afs_int32) rx_stats.ackPacketsSent;
5930 a_perfP->rx_pingPacketsSent = (afs_int32) rx_stats.pingPacketsSent;
5931 a_perfP->rx_abortPacketsSent = (afs_int32) rx_stats.abortPacketsSent;
5932 a_perfP->rx_busyPacketsSent = (afs_int32) rx_stats.busyPacketsSent;
5933 a_perfP->rx_dataPacketsSent = (afs_int32) rx_stats.dataPacketsSent;
5934 a_perfP->rx_dataPacketsReSent = (afs_int32) rx_stats.dataPacketsReSent;
5935 a_perfP->rx_dataPacketsPushed = (afs_int32) rx_stats.dataPacketsPushed;
5936 a_perfP->rx_ignoreAckedPacket = (afs_int32) rx_stats.ignoreAckedPacket;
5937 a_perfP->rx_totalRtt_Sec = (afs_int32) rx_stats.totalRtt.sec;
5938 a_perfP->rx_totalRtt_Usec = (afs_int32) rx_stats.totalRtt.usec;
5939 a_perfP->rx_minRtt_Sec = (afs_int32) rx_stats.minRtt.sec;
5940 a_perfP->rx_minRtt_Usec = (afs_int32) rx_stats.minRtt.usec;
5941 a_perfP->rx_maxRtt_Sec = (afs_int32) rx_stats.maxRtt.sec;
5942 a_perfP->rx_maxRtt_Usec = (afs_int32) rx_stats.maxRtt.usec;
5943 a_perfP->rx_nRttSamples = (afs_int32) rx_stats.nRttSamples;
5944 a_perfP->rx_nServerConns = (afs_int32) rx_stats.nServerConns;
5945 a_perfP->rx_nClientConns = (afs_int32) rx_stats.nClientConns;
5946 a_perfP->rx_nPeerStructs = (afs_int32) rx_stats.nPeerStructs;
5947 a_perfP->rx_nCallStructs = (afs_int32) rx_stats.nCallStructs;
5948 a_perfP->rx_nFreeCallStructs = (afs_int32) rx_stats.nFreeCallStructs;
5950 a_perfP->host_NumHostEntries = HTs;
5951 a_perfP->host_HostBlocks = HTBlocks;
5952 h_GetHostNetStats(&(a_perfP->host_NonDeletedHosts),
5953 &(a_perfP->host_HostsInSameNetOrSubnet),
5954 &(a_perfP->host_HostsInDiffSubnet),
5955 &(a_perfP->host_HostsInDiffNetwork));
5956 a_perfP->host_NumClients = CEs;
5957 a_perfP->host_ClientBlocks = CEBlocks;
5959 a_perfP->sysname_ID = afs_perfstats.sysname_ID;
5960 a_perfP->rx_nBusies = (afs_int32) rx_stats.nBusies;
5961 a_perfP->fs_nBusies = afs_perfstats.fs_nBusies;
5962 } /*FillPerfValues */
5965 /*------------------------------------------------------------------------
5966 * EXPORTED SRXAFS_GetXStats
5969 * Routine called by the server-side callback RPC interface to
5970 * implement getting the given data collection from the extended
5971 * File Server statistics.
5974 * a_call : Ptr to Rx call on which this request came in.
5975 * a_clientVersionNum : Client version number.
5976 * a_opCode : Desired operation.
5977 * a_serverVersionNumP : Ptr to version number to set.
5978 * a_timeP : Ptr to time value (seconds) to set.
5979 * a_dataP : Ptr to variable array structure to return
5986 * Nothing interesting.
5990 *------------------------------------------------------------------------*/
5993 SRXAFS_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
5994 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
5995 afs_int32 * a_timeP, AFS_CollData * a_dataP)
5996 { /*SRXAFS_GetXStats */
5998 int code; /*Return value */
5999 afs_int32 *dataBuffP; /*Ptr to data to be returned */
6000 afs_int32 dataBytes; /*Bytes in data buffer */
6001 #if FS_STATS_DETAILED
6002 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6003 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6004 struct timeval elapsedTime; /* Transfer time */
6007 * Set our stats pointer, remember when the RPC operation started, and
6008 * tally the operation.
6010 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETXSTATS]);
6014 FT_GetTimeOfDay(&opStartTime, 0);
6015 #endif /* FS_STATS_DETAILED */
6018 * Record the time of day and the server version number.
6020 *a_srvVersionNumP = AFS_XSTAT_VERSION;
6021 *a_timeP = FT_ApproxTime();
6024 * Stuff the appropriate data in there (assume victory)
6029 ("Received GetXStats call for collection %d\n",
6030 a_collectionNumber));
6034 * We're not keeping stats, so just return successfully with
6037 a_dataP->AFS_CollData_len = 0;
6038 a_dataP->AFS_CollData_val = NULL;
6041 switch (a_collectionNumber) {
6042 case AFS_XSTATSCOLL_CALL_INFO:
6044 * Pass back all the call-count-related data.
6046 * >>> We are forced to allocate a separate area in which to
6047 * >>> put this stuff in by the RPC stub generator, since it
6048 * >>> will be freed at the tail end of the server stub code.
6052 * I don't think call-level stats are being collected yet
6053 * for the File Server.
6055 dataBytes = sizeof(struct afs_Stats);
6056 dataBuffP = (afs_int32 *) malloc(dataBytes);
6057 memcpy(dataBuffP, &afs_cmstats, dataBytes);
6058 a_dataP->AFS_CollData_len = dataBytes >> 2;
6059 a_dataP->AFS_CollData_val = dataBuffP;
6061 a_dataP->AFS_CollData_len = 0;
6062 a_dataP->AFS_CollData_val = NULL;
6066 case AFS_XSTATSCOLL_PERF_INFO:
6068 * Pass back all the regular performance-related data.
6070 * >>> We are forced to allocate a separate area in which to
6071 * >>> put this stuff in by the RPC stub generator, since it
6072 * >>> will be freed at the tail end of the server stub code.
6075 afs_perfstats.numPerfCalls++;
6076 FillPerfValues(&afs_perfstats);
6079 * Don't overwrite the spares at the end.
6082 dataBytes = sizeof(struct afs_PerfStats);
6083 dataBuffP = (afs_int32 *) malloc(dataBytes);
6084 memcpy(dataBuffP, &afs_perfstats, dataBytes);
6085 a_dataP->AFS_CollData_len = dataBytes >> 2;
6086 a_dataP->AFS_CollData_val = dataBuffP;
6089 case AFS_XSTATSCOLL_FULL_PERF_INFO:
6091 * Pass back the full collection of performance-related data.
6092 * We have to stuff the basic, overall numbers in, but the
6093 * detailed numbers are kept in the structure already.
6095 * >>> We are forced to allocate a separate area in which to
6096 * >>> put this stuff in by the RPC stub generator, since it
6097 * >>> will be freed at the tail end of the server stub code.
6100 afs_perfstats.numPerfCalls++;
6101 #if FS_STATS_DETAILED
6102 afs_FullPerfStats.overall.numPerfCalls = afs_perfstats.numPerfCalls;
6103 FillPerfValues(&afs_FullPerfStats.overall);
6106 * Don't overwrite the spares at the end.
6109 dataBytes = sizeof(struct fs_stats_FullPerfStats);
6110 dataBuffP = (afs_int32 *) malloc(dataBytes);
6111 memcpy(dataBuffP, &afs_FullPerfStats, dataBytes);
6112 a_dataP->AFS_CollData_len = dataBytes >> 2;
6113 a_dataP->AFS_CollData_val = dataBuffP;
6117 case AFS_XSTATSCOLL_CBSTATS:
6118 afs_perfstats.numPerfCalls++;
6120 dataBytes = sizeof(struct cbcounters);
6121 dataBuffP = (afs_int32 *) malloc(dataBytes);
6123 extern struct cbcounters cbstuff;
6124 dataBuffP[0]=cbstuff.DeleteFiles;
6125 dataBuffP[1]=cbstuff.DeleteCallBacks;
6126 dataBuffP[2]=cbstuff.BreakCallBacks;
6127 dataBuffP[3]=cbstuff.AddCallBacks;
6128 dataBuffP[4]=cbstuff.GotSomeSpaces;
6129 dataBuffP[5]=cbstuff.DeleteAllCallBacks;
6130 dataBuffP[6]=cbstuff.nFEs;
6131 dataBuffP[7]=cbstuff.nCBs;
6132 dataBuffP[8]=cbstuff.nblks;
6133 dataBuffP[9]=cbstuff.CBsTimedOut;
6134 dataBuffP[10]=cbstuff.nbreakers;
6135 dataBuffP[11]=cbstuff.GSS1;
6136 dataBuffP[12]=cbstuff.GSS2;
6137 dataBuffP[13]=cbstuff.GSS3;
6138 dataBuffP[14]=cbstuff.GSS4;
6139 dataBuffP[15]=cbstuff.GSS5;
6142 a_dataP->AFS_CollData_len = dataBytes >> 2;
6143 a_dataP->AFS_CollData_val = dataBuffP;
6149 * Illegal collection number.
6151 a_dataP->AFS_CollData_len = 0;
6152 a_dataP->AFS_CollData_val = NULL;
6154 } /*Switch on collection number */
6156 #if FS_STATS_DETAILED
6157 FT_GetTimeOfDay(&opStopTime, 0);
6160 (opP->numSuccesses)++;
6161 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6162 fs_stats_AddTo((opP->sumTime), elapsedTime);
6163 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6164 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6165 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6167 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6168 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6172 #endif /* FS_STATS_DETAILED */
6176 } /*SRXAFS_GetXStats */
6180 common_GiveUpCallBacks(struct rx_call *acall, struct AFSCBFids *FidArray,
6181 struct AFSCBs *CallBackArray)
6183 afs_int32 errorCode = 0;
6185 struct client *client = 0;
6186 struct rx_connection *tcon;
6188 #if FS_STATS_DETAILED
6189 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6190 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6191 struct timeval elapsedTime; /* Transfer time */
6194 * Set our stats pointer, remember when the RPC operation started, and
6195 * tally the operation.
6198 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GIVEUPCALLBACKS]);
6202 FT_GetTimeOfDay(&opStartTime, 0);
6203 #endif /* FS_STATS_DETAILED */
6207 ("SAFS_GiveUpCallBacks (Noffids=%d)\n",
6208 FidArray->AFSCBFids_len));
6211 AFSCallStats.GiveUpCallBacks++, AFSCallStats.TotalCalls++;
6213 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6214 goto Bad_GiveUpCallBacks;
6216 if (!FidArray && !CallBackArray) {
6218 ("SAFS_GiveUpAllCallBacks: host=%x\n",
6219 (tcon->peer ? tcon->peer->host : 0)));
6220 errorCode = GetClient(tcon, &client);
6223 DeleteAllCallBacks_r(client->host, 1);
6228 if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
6230 ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n",
6231 FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len,
6232 (tcon->peer ? tcon->peer->host : 0)));
6234 goto Bad_GiveUpCallBacks;
6237 errorCode = GetClient(tcon, &client);
6239 for (i = 0; i < FidArray->AFSCBFids_len; i++) {
6240 struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
6241 DeleteCallBack(client->host, fid);
6247 Bad_GiveUpCallBacks:
6248 errorCode = CallPostamble(tcon, errorCode, thost);
6250 #if FS_STATS_DETAILED
6251 FT_GetTimeOfDay(&opStopTime, 0);
6252 if (errorCode == 0) {
6254 (opP->numSuccesses)++;
6255 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6256 fs_stats_AddTo((opP->sumTime), elapsedTime);
6257 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6258 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6259 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6261 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6262 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6266 #endif /* FS_STATS_DETAILED */
6269 } /*common_GiveUpCallBacks */
6273 SRXAFS_GiveUpCallBacks(struct rx_call * acall, struct AFSCBFids * FidArray,
6274 struct AFSCBs * CallBackArray)
6276 return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
6277 } /*SRXAFS_GiveUpCallBacks */
6280 SRXAFS_GiveUpAllCallBacks(struct rx_call * acall)
6282 return common_GiveUpCallBacks(acall, 0, 0);
6283 } /*SRXAFS_GiveUpAllCallBacks */
6287 SRXAFS_NGetVolumeInfo(struct rx_call * acall, char *avolid,
6288 struct AFSVolumeInfo * avolinfo)
6290 return (VNOVOL); /* XXX Obsolete routine XXX */
6292 } /*SRXAFS_NGetVolumeInfo */
6296 * Dummy routine. Should never be called (the cache manager should only
6297 * invoke this interface when communicating with a AFS/DFS Protocol
6301 SRXAFS_Lookup(struct rx_call * call_p, struct AFSFid * afs_dfid_p,
6302 char *afs_name_p, struct AFSFid * afs_fid_p,
6303 struct AFSFetchStatus * afs_status_p,
6304 struct AFSFetchStatus * afs_dir_status_p,
6305 struct AFSCallBack * afs_callback_p,
6306 struct AFSVolSync * afs_sync_p)
6313 SRXAFS_GetCapabilities(struct rx_call * acall, Capabilities * capabilities)
6316 struct rx_connection *tcon;
6318 afs_uint32 *dataBuffP;
6319 afs_int32 dataBytes;
6322 AFSCallStats.GetCapabilities++, AFSCallStats.TotalCalls++;
6323 afs_FullPerfStats.overall.fs_nGetCaps++;
6325 ViceLog(2, ("SAFS_GetCapabilties\n"));
6327 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6330 dataBytes = 1 * sizeof(afs_int32);
6331 dataBuffP = (afs_uint32 *) malloc(dataBytes);
6332 dataBuffP[0] = VICED_CAPABILITY_ERRORTRANS | VICED_CAPABILITY_WRITELOCKACL;
6333 #if defined(AFS_64BIT_ENV)
6334 dataBuffP[0] |= VICED_CAPABILITY_64BITFILES;
6337 dataBuffP[0] |= VICED_CAPABILITY_SANEACLS;
6339 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
6340 capabilities->Capabilities_val = dataBuffP;
6343 code = CallPostamble(tcon, code, thost);
6350 SRXAFS_FlushCPS(struct rx_call * acall, struct ViceIds * vids,
6351 struct IPAddrs * addrs, afs_int32 spare1, afs_int32 * spare2,
6355 afs_int32 nids, naddrs;
6356 afs_int32 *vd, *addr;
6357 Error errorCode = 0; /* return code to caller */
6358 struct client *client = 0;
6360 ViceLog(1, ("SRXAFS_FlushCPS\n"));
6362 AFSCallStats.TotalCalls++;
6364 nids = vids->ViceIds_len; /* # of users in here */
6365 naddrs = addrs->IPAddrs_len; /* # of hosts in here */
6366 if (nids < 0 || naddrs < 0) {
6371 vd = vids->ViceIds_val;
6372 for (i = 0; i < nids; i++, vd++) {
6375 client = h_ID2Client(*vd); /* returns write locked and refCounted, or NULL */
6379 client->prfail = 2; /* Means re-eval client's cps */
6382 rx_SetRock(((struct rx_connection *)client->tcon), 0);
6385 if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
6386 free(client->CPS.prlist_val);
6387 client->CPS.prlist_val = NULL;
6388 client->CPS.prlist_len = 0;
6390 ReleaseWriteLock(&client->lock);
6394 addr = addrs->IPAddrs_val;
6395 for (i = 0; i < naddrs; i++, addr++) {
6397 h_flushhostcps(*addr, htons(7001));
6401 ViceLog(2, ("SAFS_FlushCPS returns %d\n", errorCode));
6403 } /*SRXAFS_FlushCPS */
6405 /* worthless hack to let CS keep running ancient software */
6407 afs_vtoi(char *aname)
6413 while ((tc = *aname++)) {
6414 if (tc > '9' || tc < '0')
6415 return 0; /* invalid name */
6423 * may get name or #, but must handle all weird cases (recognize readonly
6424 * or backup volumes by name or #
6427 CopyVolumeEntry(char *aname, struct vldbentry *ave,
6428 struct VolumeInfo *av)
6431 afs_int32 mask, whichType;
6432 afs_uint32 *serverHost, *typePtr;
6434 /* figure out what type we want if by name */
6436 if (i >= 8 && strcmp(aname + i - 7, ".backup") == 0)
6437 whichType = BACKVOL;
6438 else if (i >= 10 && strcmp(aname + i - 9, ".readonly") == 0)
6443 vol = afs_vtoi(aname);
6445 vol = ave->volumeId[whichType];
6448 * Now vol has volume # we're interested in. Next, figure out the type
6449 * of the volume by looking finding it in the vldb entry
6451 if ((ave->flags & VLF_RWEXISTS) && vol == ave->volumeId[RWVOL]) {
6454 } else if ((ave->flags & VLF_ROEXISTS) && vol == ave->volumeId[ROVOL]) {
6457 } else if ((ave->flags & VLF_BACKEXISTS) && vol == ave->volumeId[BACKVOL]) {
6458 mask = VLSF_RWVOL; /* backup always is on the same volume as parent */
6459 whichType = BACKVOL;
6461 return EINVAL; /* error: can't find volume in vldb entry */
6463 typePtr = &av->Type0;
6464 serverHost = &av->Server0;
6466 av->Type = whichType;
6467 av->Type0 = av->Type1 = av->Type2 = av->Type3 = av->Type4 = 0;
6468 if (ave->flags & VLF_RWEXISTS)
6469 typePtr[RWVOL] = ave->volumeId[RWVOL];
6470 if (ave->flags & VLF_ROEXISTS)
6471 typePtr[ROVOL] = ave->volumeId[ROVOL];
6472 if (ave->flags & VLF_BACKEXISTS)
6473 typePtr[BACKVOL] = ave->volumeId[BACKVOL];
6475 for (i = 0, j = 0; i < ave->nServers; i++) {
6476 if ((ave->serverFlags[i] & mask) == 0)
6477 continue; /* wrong volume */
6478 serverHost[j] = ave->serverNumber[i];
6481 av->ServerCount = j;
6483 serverHost[j++] = 0; /* bogus 8, but compat only now */
6488 TryLocalVLServer(char *avolid, struct VolumeInfo *avolinfo)
6490 static struct rx_connection *vlConn = 0;
6491 static int down = 0;
6492 static afs_int32 lastDownTime = 0;
6493 struct vldbentry tve;
6494 struct rx_securityClass *vlSec;
6498 vlSec = rxnull_NewClientSecurityObject();
6500 rx_NewConnection(htonl(0x7f000001), htons(7003), 52, vlSec, 0);
6501 rx_SetConnDeadTime(vlConn, 15); /* don't wait long */
6503 if (down && (FT_ApproxTime() < lastDownTime + 180)) {
6504 return 1; /* failure */
6507 code = VL_GetEntryByNameO(vlConn, avolid, &tve);
6509 down = 0; /* call worked */
6512 lastDownTime = FT_ApproxTime(); /* last time we tried an RPC */
6518 /* otherwise convert to old format vldb entry */
6519 code = CopyVolumeEntry(avolid, &tve, avolinfo);
6529 SRXAFS_GetVolumeInfo(struct rx_call * acall, char *avolid,
6530 struct VolumeInfo * avolinfo)
6533 struct rx_connection *tcon;
6535 #if FS_STATS_DETAILED
6536 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6537 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6538 struct timeval elapsedTime; /* Transfer time */
6541 * Set our stats pointer, remember when the RPC operation started, and
6542 * tally the operation.
6544 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMEINFO]);
6548 FT_GetTimeOfDay(&opStartTime, 0);
6549 #endif /* FS_STATS_DETAILED */
6550 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6551 goto Bad_GetVolumeInfo;
6554 AFSCallStats.GetVolumeInfo++, AFSCallStats.TotalCalls++;
6556 code = TryLocalVLServer(avolid, avolinfo);
6558 ("SAFS_GetVolumeInfo returns %d, Volume %u, type %x, servers %x %x %x %x...\n",
6559 code, avolinfo->Vid, avolinfo->Type, avolinfo->Server0,
6560 avolinfo->Server1, avolinfo->Server2, avolinfo->Server3));
6561 avolinfo->Type4 = 0xabcd9999; /* tell us to try new vldb */
6564 code = CallPostamble(tcon, code, thost);
6566 #if FS_STATS_DETAILED
6567 FT_GetTimeOfDay(&opStopTime, 0);
6570 (opP->numSuccesses)++;
6571 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6572 fs_stats_AddTo((opP->sumTime), elapsedTime);
6573 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6574 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6575 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6577 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6578 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6582 #endif /* FS_STATS_DETAILED */
6586 } /*SRXAFS_GetVolumeInfo */
6590 SRXAFS_GetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6591 AFSFetchVolumeStatus * FetchVolStatus, char **Name,
6592 char **OfflineMsg, char **Motd)
6594 Vnode *targetptr = 0; /* vnode of the new file */
6595 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6596 Error errorCode = 0; /* error code */
6597 Volume *volptr = 0; /* pointer to the volume header */
6598 struct client *client = 0; /* pointer to client entry */
6599 afs_int32 rights, anyrights; /* rights for this and any user */
6601 struct rx_connection *tcon;
6603 struct client *t_client = NULL; /* tmp ptr to client data */
6604 #if FS_STATS_DETAILED
6605 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6606 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6607 struct timeval elapsedTime; /* Transfer time */
6610 * Set our stats pointer, remember when the RPC operation started, and
6611 * tally the operation.
6614 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETVOLUMESTATUS]);
6618 FT_GetTimeOfDay(&opStartTime, 0);
6619 #endif /* FS_STATS_DETAILED */
6621 ViceLog(1, ("SAFS_GetVolumeStatus for volume %u\n", avolid));
6622 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6623 goto Bad_GetVolumeStatus;
6626 AFSCallStats.GetVolumeStatus++, AFSCallStats.TotalCalls++;
6630 goto Bad_GetVolumeStatus;
6632 dummyFid.Volume = avolid, dummyFid.Vnode =
6633 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6636 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6637 &parentwhentargetnotdir, &client, READ_LOCK,
6638 &rights, &anyrights)))
6639 goto Bad_GetVolumeStatus;
6641 if ((VanillaUser(client)) && (!(rights & PRSFS_READ))) {
6643 goto Bad_GetVolumeStatus;
6645 (void)RXGetVolumeStatus(FetchVolStatus, Name, OfflineMsg, Motd, volptr);
6647 Bad_GetVolumeStatus:
6648 (void)PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6650 ViceLog(2, ("SAFS_GetVolumeStatus returns %d\n", errorCode));
6651 /* next is to guarantee out strings exist for stub */
6653 *Name = (char *)malloc(1);
6657 *Motd = (char *)malloc(1);
6660 if (*OfflineMsg == 0) {
6661 *OfflineMsg = (char *)malloc(1);
6664 errorCode = CallPostamble(tcon, errorCode, thost);
6666 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6668 #if FS_STATS_DETAILED
6669 FT_GetTimeOfDay(&opStopTime, 0);
6670 if (errorCode == 0) {
6672 (opP->numSuccesses)++;
6673 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6674 fs_stats_AddTo((opP->sumTime), elapsedTime);
6675 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6676 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6677 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6679 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6680 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6684 #endif /* FS_STATS_DETAILED */
6686 osi_auditU(acall, GetVolumeStatusEvent, errorCode,
6687 AUD_ID, t_client ? t_client->ViceId : 0,
6688 AUD_LONG, avolid, AUD_STR, *Name, AUD_END);
6691 } /*SRXAFS_GetVolumeStatus */
6695 SRXAFS_SetVolumeStatus(struct rx_call * acall, afs_int32 avolid,
6696 AFSStoreVolumeStatus * StoreVolStatus, char *Name,
6697 char *OfflineMsg, char *Motd)
6699 Vnode *targetptr = 0; /* vnode of the new file */
6700 Vnode *parentwhentargetnotdir = 0; /* vnode of parent */
6701 Error errorCode = 0; /* error code */
6702 Volume *volptr = 0; /* pointer to the volume header */
6703 struct client *client = 0; /* pointer to client entry */
6704 afs_int32 rights, anyrights; /* rights for this and any user */
6706 struct rx_connection *tcon = rx_ConnectionOf(acall);
6708 struct client *t_client = NULL; /* tmp ptr to client data */
6709 #if FS_STATS_DETAILED
6710 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6711 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6712 struct timeval elapsedTime; /* Transfer time */
6715 * Set our stats pointer, remember when the RPC operation started, and
6716 * tally the operation.
6719 &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_SETVOLUMESTATUS]);
6723 FT_GetTimeOfDay(&opStartTime, 0);
6724 #endif /* FS_STATS_DETAILED */
6726 ViceLog(1, ("SAFS_SetVolumeStatus for volume %u\n", avolid));
6727 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6728 goto Bad_SetVolumeStatus;
6731 AFSCallStats.SetVolumeStatus++, AFSCallStats.TotalCalls++;
6735 goto Bad_SetVolumeStatus;
6737 dummyFid.Volume = avolid, dummyFid.Vnode =
6738 (afs_int32) ROOTVNODE, dummyFid.Unique = 1;
6741 GetVolumePackage(tcon, &dummyFid, &volptr, &targetptr, MustBeDIR,
6742 &parentwhentargetnotdir, &client, READ_LOCK,
6743 &rights, &anyrights)))
6744 goto Bad_SetVolumeStatus;
6746 if (readonlyServer) {
6747 errorCode = VREADONLY;
6748 goto Bad_SetVolumeStatus;
6750 if (VanillaUser(client)) {
6752 goto Bad_SetVolumeStatus;
6756 RXUpdate_VolumeStatus(volptr, StoreVolStatus, Name, OfflineMsg, Motd);
6758 Bad_SetVolumeStatus:
6759 PutVolumePackage(parentwhentargetnotdir, targetptr, (Vnode *) 0,
6761 ViceLog(2, ("SAFS_SetVolumeStatus returns %d\n", errorCode));
6762 errorCode = CallPostamble(tcon, errorCode, thost);
6764 t_client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
6766 #if FS_STATS_DETAILED
6767 FT_GetTimeOfDay(&opStopTime, 0);
6768 if (errorCode == 0) {
6770 (opP->numSuccesses)++;
6771 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6772 fs_stats_AddTo((opP->sumTime), elapsedTime);
6773 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6774 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6775 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6777 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6778 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6782 #endif /* FS_STATS_DETAILED */
6784 osi_auditU(acall, SetVolumeStatusEvent, errorCode,
6785 AUD_ID, t_client ? t_client->ViceId : 0,
6786 AUD_LONG, avolid, AUD_STR, Name, AUD_END);
6788 } /*SRXAFS_SetVolumeStatus */
6790 #define DEFAULTVOLUME "root.afs"
6793 SRXAFS_GetRootVolume(struct rx_call * acall, char **VolumeName)
6799 struct rx_connection *tcon;
6801 Error errorCode = 0;
6803 #if FS_STATS_DETAILED
6804 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6805 struct timeval opStartTime; /* Start time for RPC op */
6807 struct timeval opStopTime;
6808 struct timeval elapsedTime; /* Transfer time */
6812 * Set our stats pointer, remember when the RPC operation started, and
6813 * tally the operation.
6815 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETROOTVOLUME]);
6819 FT_GetTimeOfDay(&opStartTime, 0);
6820 #endif /* FS_STATS_DETAILED */
6822 return FSERR_EOPNOTSUPP;
6825 if (errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))
6826 goto Bad_GetRootVolume;
6828 AFSCallStats.GetRootVolume++, AFSCallStats.TotalCalls++;
6831 fd = afs_open(AFSDIR_SERVER_ROOTVOL_FILEPATH, O_RDONLY, 0666);
6833 strcpy(temp, DEFAULTVOLUME);
6835 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6836 lockf(fd, F_LOCK, 0);
6840 len = read(fd, temp, 256);
6841 #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV)
6842 lockf(fd, F_ULOCK, 0);
6847 if (temp[len - 1] == '\n')
6851 *VolumeName = temp; /* freed by rx server-side stub */
6854 errorCode = CallPostamble(tcon, errorCode, thost);
6856 #if FS_STATS_DETAILED
6857 FT_GetTimeOfDay(&opStopTime, 0);
6858 if (errorCode == 0) {
6860 (opP->numSuccesses)++;
6861 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6862 fs_stats_AddTo((opP->sumTime), elapsedTime);
6863 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6864 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6865 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6867 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6868 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6872 #endif /* FS_STATS_DETAILED */
6877 } /*SRXAFS_GetRootVolume */
6880 /* still works because a struct CBS is the same as a struct AFSOpaque */
6882 SRXAFS_CheckToken(struct rx_call * acall, afs_int32 AfsId,
6883 struct AFSOpaque * Token)
6886 struct rx_connection *tcon;
6888 #if FS_STATS_DETAILED
6889 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6890 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6891 struct timeval elapsedTime; /* Transfer time */
6894 * Set our stats pointer, remember when the RPC operation started, and
6895 * tally the operation.
6897 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_CHECKTOKEN]);
6901 FT_GetTimeOfDay(&opStartTime, 0);
6902 #endif /* FS_STATS_DETAILED */
6904 if ((code = CallPreamble(acall, ACTIVECALL, &tcon, &thost)))
6905 goto Bad_CheckToken;
6907 code = FSERR_ECONNREFUSED;
6910 code = CallPostamble(tcon, code, thost);
6912 #if FS_STATS_DETAILED
6913 FT_GetTimeOfDay(&opStopTime, 0);
6916 (opP->numSuccesses)++;
6917 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6918 fs_stats_AddTo((opP->sumTime), elapsedTime);
6919 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6920 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6921 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6923 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6924 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6928 #endif /* FS_STATS_DETAILED */
6932 } /*SRXAFS_CheckToken */
6935 SRXAFS_GetTime(struct rx_call * acall, afs_uint32 * Seconds,
6936 afs_uint32 * USeconds)
6939 struct rx_connection *tcon;
6942 #if FS_STATS_DETAILED
6943 struct fs_stats_opTimingData *opP; /* Ptr to this op's timing struct */
6944 struct timeval opStartTime, opStopTime; /* Start/stop times for RPC op */
6945 struct timeval elapsedTime; /* Transfer time */
6948 * Set our stats pointer, remember when the RPC operation started, and
6949 * tally the operation.
6951 opP = &(afs_FullPerfStats.det.rpcOpTimes[FS_STATS_RPCIDX_GETTIME]);
6955 FT_GetTimeOfDay(&opStartTime, 0);
6956 #endif /* FS_STATS_DETAILED */
6958 if ((code = CallPreamble(acall, NOTACTIVECALL, &tcon, &thost)))
6962 AFSCallStats.GetTime++, AFSCallStats.TotalCalls++;
6964 FT_GetTimeOfDay(&tpl, 0);
6965 *Seconds = tpl.tv_sec;
6966 *USeconds = tpl.tv_usec;
6968 ViceLog(2, ("SAFS_GetTime returns %u, %u\n", *Seconds, *USeconds));
6971 code = CallPostamble(tcon, code, thost);
6973 #if FS_STATS_DETAILED
6974 FT_GetTimeOfDay(&opStopTime, 0);
6975 fs_stats_GetDiff(elapsedTime, opStartTime, opStopTime);
6978 (opP->numSuccesses)++;
6979 fs_stats_AddTo((opP->sumTime), elapsedTime);
6980 fs_stats_SquareAddTo((opP->sqrTime), elapsedTime);
6981 if (fs_stats_TimeLessThan(elapsedTime, (opP->minTime))) {
6982 fs_stats_TimeAssign((opP->minTime), elapsedTime);
6984 if (fs_stats_TimeGreaterThan(elapsedTime, (opP->maxTime))) {
6985 fs_stats_TimeAssign((opP->maxTime), elapsedTime);
6989 #endif /* FS_STATS_DETAILED */
6993 } /*SRXAFS_GetTime */
7000 * Implement a client's data fetch using Rx.
7003 * volptr : Ptr to the given volume's info.
7004 * targetptr : Pointer to the vnode involved.
7005 * Call : Ptr to the Rx call involved.
7006 * Pos : Offset within the file.
7007 * Len : Length in bytes to read; this value is bogus!
7008 * if FS_STATS_DETAILED
7009 * a_bytesToFetchP : Set to the number of bytes to be fetched from
7011 * a_bytesFetchedP : Set to the actual number of bytes fetched from
7017 FetchData_RXStyle(Volume * volptr, Vnode * targetptr,
7018 struct rx_call * Call, afs_sfsize_t Pos,
7019 afs_sfsize_t Len, afs_int32 Int64Mode,
7020 #if FS_STATS_DETAILED
7021 afs_sfsize_t * a_bytesToFetchP,
7022 afs_sfsize_t * a_bytesFetchedP
7023 #endif /* FS_STATS_DETAILED */
7026 struct timeval StartTime, StopTime; /* used to calculate file transfer rates */
7031 #else /* AFS_NT40_ENV */
7032 struct iovec tiov[RX_MAXIOVECS];
7034 #endif /* AFS_NT40_ENV */
7038 #if FS_STATS_DETAILED
7040 * Initialize the byte count arguments.
7042 (*a_bytesToFetchP) = 0;
7043 (*a_bytesFetchedP) = 0;
7044 #endif /* FS_STATS_DETAILED */
7048 ("FetchData_RXStyle: Pos %llu, Len %llu\n", (afs_uintmax_t) Pos,
7049 (afs_uintmax_t) Len));
7051 if (!VN_GET_INO(targetptr)) {
7052 afs_int32 zero = htonl(0);
7054 * This is used for newly created files; we simply send 0 bytes
7055 * back to make the cache manager happy...
7058 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7059 rx_Write(Call, (char *)&zero, sizeof(afs_int32)); /* send 0-length */
7062 FT_GetTimeOfDay(&StartTime, 0);
7063 ihP = targetptr->handle;
7066 VTakeOffline(volptr);
7067 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7071 optSize = sendBufSize;
7072 tlen = FDH_SIZE(fdP);
7074 ("FetchData_RXStyle: file size %llu\n", (afs_uintmax_t) tlen));
7077 VTakeOffline(volptr);
7078 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7086 if (Pos + Len > tlen) /* get length we should send */
7087 Len = ((tlen - Pos) < 0) ? 0 : tlen - Pos;
7089 (void)FDH_SEEK(fdP, Pos, 0);
7091 afs_int32 high, low;
7092 SplitOffsetOrSize(Len, high, low);
7093 assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0);
7096 rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */
7099 rx_Write(Call, (char *)&low, sizeof(afs_int32)); /* send length on fetch */
7101 #if FS_STATS_DETAILED
7102 (*a_bytesToFetchP) = Len;
7103 #endif /* FS_STATS_DETAILED */
7105 tbuffer = AllocSendBuffer();
7106 #endif /* AFS_NT40_ENV */
7115 nBytes = FDH_READ(fdP, tbuffer, wlen);
7116 if (nBytes != wlen) {
7118 FreeSendBuffer((struct afs_buffer *)tbuffer);
7119 VTakeOffline(volptr);
7120 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7124 nBytes = rx_Write(Call, tbuffer, wlen);
7125 #else /* AFS_NT40_ENV */
7126 nBytes = rx_WritevAlloc(Call, tiov, &tnio, RX_MAXIOVECS, wlen);
7132 nBytes = FDH_READV(fdP, tiov, tnio);
7133 if (nBytes != wlen) {
7135 VTakeOffline(volptr);
7136 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7140 nBytes = rx_Writev(Call, tiov, tnio, wlen);
7141 #endif /* AFS_NT40_ENV */
7142 #if FS_STATS_DETAILED
7144 * Bump the number of bytes actually sent by the number from this
7147 (*a_bytesFetchedP) += nBytes;
7148 #endif /* FS_STATS_DETAILED */
7149 if (nBytes != wlen) {
7152 FreeSendBuffer((struct afs_buffer *)tbuffer);
7153 #endif /* AFS_NT40_ENV */
7159 FreeSendBuffer((struct afs_buffer *)tbuffer);
7160 #endif /* AFS_NT40_ENV */
7162 FT_GetTimeOfDay(&StopTime, 0);
7164 /* Adjust all Fetch Data related stats */
7166 if (AFSCallStats.TotalFetchedBytes > 2000000000) /* Reset if over 2 billion */
7167 AFSCallStats.TotalFetchedBytes = AFSCallStats.AccumFetchTime = 0;
7168 AFSCallStats.AccumFetchTime +=
7169 ((StopTime.tv_sec - StartTime.tv_sec) * 1000) +
7170 ((StopTime.tv_usec - StartTime.tv_usec) / 1000);
7172 afs_fsize_t targLen;
7173 VN_GET_LEN(targLen, targetptr);
7174 AFSCallStats.TotalFetchedBytes += targLen;
7175 AFSCallStats.FetchSize1++;
7176 if (targLen < SIZE2)
7177 AFSCallStats.FetchSize2++;
7178 else if (targLen < SIZE3)
7179 AFSCallStats.FetchSize3++;
7180 else if (targLen < SIZE4)
7181 AFSCallStats.FetchSize4++;
7183 AFSCallStats.FetchSize5++;
7188 } /*FetchData_RXStyle */
7191 GetLinkCountAndSize(Volume * vp, FdHandle_t * fdP, int *lc,
7192 afs_sfsize_t * size)
7194 #ifdef AFS_NAMEI_ENV
7196 lhp = IH_OPEN(V_linkHandle(vp));
7200 *lc = nt_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
7202 *lc = namei_GetLinkCount(lhp, fdP->fd_ih->ih_ino, 0);
7207 *size = OS_SIZE(fdP->fd_fd);
7208 return (*size == -1) ? -1 : 0;
7210 struct afs_stat status;
7212 if (afs_fstat(fdP->fd_fd, &status) < 0) {
7216 *lc = GetLinkCount(vp, &status);
7217 *size = status.st_size;
7226 * Implement a client's data store using Rx.
7229 * volptr : Ptr to the given volume's info.
7230 * targetptr : Pointer to the vnode involved.
7231 * Call : Ptr to the Rx call involved.
7232 * Pos : Offset within the file.
7233 * Len : Length in bytes to store; this value is bogus!
7234 * if FS_STATS_DETAILED
7235 * a_bytesToStoreP : Set to the number of bytes to be stored to
7237 * a_bytesStoredP : Set to the actual number of bytes stored to
7242 StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid,
7243 struct client * client, struct rx_call * Call,
7244 afs_fsize_t Pos, afs_fsize_t Length, afs_fsize_t FileLength,
7246 #if FS_STATS_DETAILED
7247 afs_sfsize_t * a_bytesToStoreP,
7248 afs_sfsize_t * a_bytesStoredP
7249 #endif /* FS_STATS_DETAILED */
7252 afs_sfsize_t bytesTransfered; /* number of bytes actually transfered */
7253 struct timeval StartTime, StopTime; /* Used to measure how long the store takes */
7254 Error errorCode = 0; /* Returned error code to caller */
7256 char *tbuffer; /* data copying buffer */
7257 #else /* AFS_NT40_ENV */
7258 struct iovec tiov[RX_MAXIOVECS]; /* no data copying with iovec */
7259 int tnio; /* temp for iovec size */
7260 #endif /* AFS_NT40_ENV */
7261 afs_sfsize_t tlen; /* temp for xfr length */
7262 Inode tinode; /* inode for I/O */
7263 afs_int32 optSize; /* optimal transfer size */
7264 afs_sfsize_t DataLength = 0; /* size of inode */
7265 afs_sfsize_t TruncatedLength; /* size after ftruncate */
7266 afs_fsize_t NewLength; /* size after this store completes */
7267 afs_sfsize_t adjustSize; /* bytes to call VAdjust... with */
7268 int linkCount = 0; /* link count on inode */
7269 afs_fsize_t CoW_off, CoW_len;
7271 FdHandle_t *fdP, *origfdP = NULL;
7272 struct in_addr logHostAddr; /* host ip holder for inet_ntoa */
7274 #if FS_STATS_DETAILED
7276 * Initialize the byte count arguments.
7278 (*a_bytesToStoreP) = 0;
7279 (*a_bytesStoredP) = 0;
7280 #endif /* FS_STATS_DETAILED */
7283 * We break the callbacks here so that the following signal will not
7286 BreakCallBack(client->host, Fid, 0);
7288 if (Pos == -1 || VN_GET_INO(targetptr) == 0) {
7289 /* the inode should have been created in Alloc_NewVnode */
7290 logHostAddr.s_addr = rxr_HostOf(rx_ConnectionOf(Call));
7292 ("StoreData_RXStyle : Inode non-existent Fid = %u.%u.%u, inode = %llu, Pos %llu Host %s:%d\n",
7293 Fid->Volume, Fid->Vnode, Fid->Unique,
7294 (afs_uintmax_t) VN_GET_INO(targetptr), (afs_uintmax_t) Pos,
7295 inet_ntoa(logHostAddr), ntohs(rxr_PortOf(rx_ConnectionOf(Call)))));
7296 return ENOENT; /* is this proper error code? */
7299 * See if the file has several links (from other volumes). If it
7300 * does, then we have to make a copy before changing it to avoid
7301 *changing read-only clones of this dude
7304 ("StoreData_RXStyle : Opening inode %s\n",
7305 PrintInode(NULL, VN_GET_INO(targetptr))));
7306 fdP = IH_OPEN(targetptr->handle);
7309 if (GetLinkCountAndSize(volptr, fdP, &linkCount, &DataLength) < 0) {
7311 VTakeOffline(volptr);
7312 ViceLog(0, ("Volume %u now offline, must be salvaged.\n",
7317 if (linkCount != 1) {
7320 ("StoreData_RXStyle : inode %s has more than onelink\n",
7321 PrintInode(NULL, VN_GET_INO(targetptr))));
7322 /* other volumes share this data, better copy it first */
7324 /* Adjust the disk block count by the creation of the new inode.
7325 * We call the special VDiskUsage so we don't adjust the volume's
7326 * quota since we don't want to penalyze the user for afs's internal
7327 * mechanisms (i.e. copy on write overhead.) Also the right size
7328 * of the disk will be recorded...
7331 VN_GET_LEN(size, targetptr);
7332 volptr->partition->flags &= ~PART_DONTUPDATE;
7333 VSetPartitionDiskUsage(volptr->partition);
7334 volptr->partition->flags |= PART_DONTUPDATE;
7335 if ((errorCode = VDiskUsage(volptr, nBlocks(size)))) {
7336 volptr->partition->flags &= ~PART_DONTUPDATE;
7341 CoW_len = (FileLength >= (Length + Pos)) ? FileLength - Length : Pos;
7342 CopyOnWrite_calls++;
7343 if (CoW_len == 0) CopyOnWrite_size0++;
7344 if (Pos == 0) CopyOnWrite_off0++;
7345 if (CoW_len > CopyOnWrite_maxsize) CopyOnWrite_maxsize = CoW_len;
7347 ViceLog(1, ("StoreData : calling CopyOnWrite on vnode %u.%u (%s) "
7348 "off 0x0 size 0x%llx\n",
7349 afs_printable_VolumeId_u(V_id(volptr)),
7350 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7351 V_name(volptr), Pos));
7352 if ((errorCode = CopyOnWrite(targetptr, volptr, 0, Pos))) {
7353 ViceLog(25, ("StoreData : CopyOnWrite failed\n"));
7354 volptr->partition->flags &= ~PART_DONTUPDATE;
7358 volptr->partition->flags &= ~PART_DONTUPDATE;
7359 VSetPartitionDiskUsage(volptr->partition);
7360 fdP = IH_OPEN(targetptr->handle);
7363 ("StoreData : Reopen after CopyOnWrite failed\n"));
7368 tinode = VN_GET_INO(targetptr);
7370 if (!VALID_INO(tinode)) {
7371 VTakeOffline(volptr);
7372 ViceLog(0,("Volume %u now offline, must be salvaged.\n",
7377 /* compute new file length */
7378 NewLength = DataLength;
7379 if (FileLength < NewLength)
7380 /* simulate truncate */
7381 NewLength = FileLength;
7382 TruncatedLength = NewLength; /* remember length after possible ftruncate */
7383 if (Pos + Length > NewLength)
7384 NewLength = Pos + Length; /* and write */
7386 /* adjust the disk block count by the difference in the files */
7388 afs_fsize_t targSize;
7389 VN_GET_LEN(targSize, targetptr);
7390 adjustSize = nBlocks(NewLength) - nBlocks(targSize);
7393 AdjustDiskUsage(volptr, adjustSize,
7394 adjustSize - SpareComp(volptr)))) {
7396 if (origfdP) FDH_CLOSE(origfdP);
7400 /* can signal cache manager to proceed from close now */
7401 /* this bit means that the locks are set and protections are OK */
7402 rx_SetLocalStatus(Call, 1);
7404 FT_GetTimeOfDay(&StartTime, 0);
7406 optSize = sendBufSize;
7408 ("StoreData_RXStyle: Pos %llu, DataLength %llu, FileLength %llu, Length %llu\n",
7409 (afs_uintmax_t) Pos, (afs_uintmax_t) DataLength,
7410 (afs_uintmax_t) FileLength, (afs_uintmax_t) Length));
7412 /* truncate the file iff it needs it (ftruncate is slow even when its a noop) */
7413 if (FileLength < DataLength)
7414 FDH_TRUNC(fdP, FileLength);
7416 FDH_SEEK(fdP, Pos, 0);
7417 bytesTransfered = 0;
7419 tbuffer = AllocSendBuffer();
7420 #endif /* AFS_NT40_ENV */
7421 /* if length == 0, the loop below isn't going to do anything, including
7422 * extend the length of the inode, which it must do, since the file system
7423 * assumes that the inode length == vnode's file length. So, we extend
7424 * the file length manually if need be. Note that if file is bigger than
7425 * Pos+(Length==0), we dont' have to do anything, and certainly shouldn't
7426 * do what we're going to do below.
7428 if (Length == 0 && Pos > TruncatedLength) {
7429 /* Set the file's length; we've already done an lseek to the right
7432 nBytes = FDH_WRITE(fdP, &tlen, 1);
7437 errorCode = FDH_TRUNC(fdP, Pos);
7439 /* have some data to copy */
7440 #if FS_STATS_DETAILED
7441 (*a_bytesToStoreP) = Length;
7442 #endif /* FS_STATS_DETAILED */
7445 if (bytesTransfered >= Length) {
7449 tlen = Length - bytesTransfered; /* how much more to do */
7451 rlen = optSize; /* bound by buffer size */
7455 errorCode = rx_Read(Call, tbuffer, rlen);
7456 #else /* AFS_NT40_ENV */
7457 errorCode = rx_Readv(Call, tiov, &tnio, RX_MAXIOVECS, rlen);
7458 #endif /* AFS_NT40_ENV */
7459 if (errorCode <= 0) {
7463 #if FS_STATS_DETAILED
7464 (*a_bytesStoredP) += errorCode;
7465 #endif /* FS_STATS_DETAILED */
7468 nBytes = FDH_WRITE(fdP, tbuffer, rlen);
7469 #else /* AFS_NT40_ENV */
7470 nBytes = FDH_WRITEV(fdP, tiov, tnio);
7471 #endif /* AFS_NT40_ENV */
7472 if (nBytes != rlen) {
7473 errorCode = VDISKFULL;
7476 bytesTransfered += rlen;
7481 FreeSendBuffer((struct afs_buffer *)tbuffer);
7482 #endif /* AFS_NT40_ENV */
7487 afs_sfsize_t nfSize = FDH_SIZE(fdP);
7488 assert(nfSize >= 0);
7489 /* something went wrong: adjust size and return */
7490 VN_SET_LEN(targetptr, nfSize); /* set new file size. */
7491 /* changed_newTime is tested in StoreData to detemine if we
7492 * need to update the target vnode.
7494 targetptr->changed_newTime = 1;
7495 if (origfdP && (bytesTransfered < Length)) /* Need to "finish" CopyOnWrite still */
7496 CopyOnWrite2(origfdP, fdP, Pos + bytesTransfered, NewLength - Pos - bytesTransfered);
7497 if (origfdP) FDH_CLOSE(origfdP);
7499 /* set disk usage to be correct */
7500 VAdjustDiskUsage(&errorCode, volptr,
7501 (afs_sfsize_t) (nBlocks(nfSize) -
7502 nBlocks(NewLength)), 0);
7505 if (origfdP) { /* finish CopyOnWrite */
7506 if ( (CoW_off = Pos + Length) < NewLength) {
7507 errorCode = CopyOnWrite2(origfdP, fdP, CoW_off, CoW_len = NewLength - CoW_off);
7508 ViceLog(1, ("StoreData : CopyOnWrite2 on vnode %u.%u (%s) "
7509 "off 0x%llx size 0x%llx returns %d\n",
7510 afs_printable_VolumeId_u(V_id(volptr)),
7511 afs_printable_VnodeId_u(targetptr->vnodeNumber),
7512 V_name(volptr), CoW_off, CoW_len, errorCode));
7518 FT_GetTimeOfDay(&StopTime, 0);
7520 VN_SET_LEN(targetptr, NewLength);
7522 /* Update all StoreData related stats */
7524 if (AFSCallStats.TotalStoredBytes > 2000000000) /* reset if over 2 billion */
7525 AFSCallStats.TotalStoredBytes = AFSCallStats.AccumStoreTime = 0;
7526 AFSCallStats.StoreSize1++; /* Piggybacked data */
7528 afs_fsize_t targLen;
7529 VN_GET_LEN(targLen, targetptr);
7530 if (targLen < SIZE2)
7531 AFSCallStats.StoreSize2++;
7532 else if (targLen < SIZE3)
7533 AFSCallStats.StoreSize3++;
7534 else if (targLen < SIZE4)
7535 AFSCallStats.StoreSize4++;
7537 AFSCallStats.StoreSize5++;
7542 } /*StoreData_RXStyle */
7544 static int sys2et[512];
7547 init_sys_error_to_et(void)
7549 memset(&sys2et, 0, sizeof(sys2et));
7550 sys2et[EPERM] = UAEPERM;
7551 sys2et[ENOENT] = UAENOENT;
7552 sys2et[ESRCH] = UAESRCH;
7553 sys2et[EINTR] = UAEINTR;
7554 sys2et[EIO] = UAEIO;
7555 sys2et[ENXIO] = UAENXIO;
7556 sys2et[E2BIG] = UAE2BIG;
7557 sys2et[ENOEXEC] = UAENOEXEC;
7558 sys2et[EBADF] = UAEBADF;
7559 sys2et[ECHILD] = UAECHILD;
7560 sys2et[EAGAIN] = UAEAGAIN;
7561 sys2et[ENOMEM] = UAENOMEM;
7562 sys2et[EACCES] = UAEACCES;
7563 sys2et[EFAULT] = UAEFAULT;
7564 sys2et[ENOTBLK] = UAENOTBLK;
7565 sys2et[EBUSY] = UAEBUSY;
7566 sys2et[EEXIST] = UAEEXIST;
7567 sys2et[EXDEV] = UAEXDEV;
7568 sys2et[ENODEV] = UAENODEV;
7569 sys2et[ENOTDIR] = UAENOTDIR;
7570 sys2et[EISDIR] = UAEISDIR;
7571 sys2et[EINVAL] = UAEINVAL;
7572 sys2et[ENFILE] = UAENFILE;
7573 sys2et[EMFILE] = UAEMFILE;
7574 sys2et[ENOTTY] = UAENOTTY;
7575 sys2et[ETXTBSY] = UAETXTBSY;
7576 sys2et[EFBIG] = UAEFBIG;
7577 sys2et[ENOSPC] = UAENOSPC;
7578 sys2et[ESPIPE] = UAESPIPE;
7579 sys2et[EROFS] = UAEROFS;
7580 sys2et[EMLINK] = UAEMLINK;
7581 sys2et[EPIPE] = UAEPIPE;
7582 sys2et[EDOM] = UAEDOM;
7583 sys2et[ERANGE] = UAERANGE;
7584 sys2et[EDEADLK] = UAEDEADLK;
7585 sys2et[ENAMETOOLONG] = UAENAMETOOLONG;
7586 sys2et[ENOLCK] = UAENOLCK;
7587 sys2et[ENOSYS] = UAENOSYS;
7588 #if (ENOTEMPTY != EEXIST)
7589 sys2et[ENOTEMPTY] = UAENOTEMPTY;
7591 sys2et[ELOOP] = UAELOOP;
7592 #if (EWOULDBLOCK != EAGAIN)
7593 sys2et[EWOULDBLOCK] = UAEWOULDBLOCK;
7595 sys2et[ENOMSG] = UAENOMSG;
7596 sys2et[EIDRM] = UAEIDRM;
7597 sys2et[ECHRNG] = UAECHRNG;
7598 sys2et[EL2NSYNC] = UAEL2NSYNC;
7599 sys2et[EL3HLT] = UAEL3HLT;
7600 sys2et[EL3RST] = UAEL3RST;
7601 sys2et[ELNRNG] = UAELNRNG;
7602 sys2et[EUNATCH] = UAEUNATCH;
7603 sys2et[ENOCSI] = UAENOCSI;
7604 sys2et[EL2HLT] = UAEL2HLT;
7605 sys2et[EBADE] = UAEBADE;
7606 sys2et[EBADR] = UAEBADR;
7607 sys2et[EXFULL] = UAEXFULL;
7608 sys2et[ENOANO] = UAENOANO;
7609 sys2et[EBADRQC] = UAEBADRQC;
7610 sys2et[EBADSLT] = UAEBADSLT;
7611 sys2et[EDEADLK] = UAEDEADLK;
7612 sys2et[EBFONT] = UAEBFONT;
7613 sys2et[ENOSTR] = UAENOSTR;
7614 sys2et[ENODATA] = UAENODATA;
7615 sys2et[ETIME] = UAETIME;
7616 sys2et[ENOSR] = UAENOSR;
7617 sys2et[ENONET] = UAENONET;
7618 sys2et[ENOPKG] = UAENOPKG;
7619 sys2et[EREMOTE] = UAEREMOTE;
7620 sys2et[ENOLINK] = UAENOLINK;
7621 sys2et[EADV] = UAEADV;
7622 sys2et[ESRMNT] = UAESRMNT;
7623 sys2et[ECOMM] = UAECOMM;
7624 sys2et[EPROTO] = UAEPROTO;
7625 sys2et[EMULTIHOP] = UAEMULTIHOP;
7626 sys2et[EDOTDOT] = UAEDOTDOT;
7627 sys2et[EBADMSG] = UAEBADMSG;
7628 sys2et[EOVERFLOW] = UAEOVERFLOW;
7629 sys2et[ENOTUNIQ] = UAENOTUNIQ;
7630 sys2et[EBADFD] = UAEBADFD;
7631 sys2et[EREMCHG] = UAEREMCHG;
7632 sys2et[ELIBACC] = UAELIBACC;
7633 sys2et[ELIBBAD] = UAELIBBAD;
7634 sys2et[ELIBSCN] = UAELIBSCN;
7635 sys2et[ELIBMAX] = UAELIBMAX;
7636 sys2et[ELIBEXEC] = UAELIBEXEC;
7637 sys2et[EILSEQ] = UAEILSEQ;
7638 sys2et[ERESTART] = UAERESTART;
7639 sys2et[ESTRPIPE] = UAESTRPIPE;
7640 sys2et[EUSERS] = UAEUSERS;
7641 sys2et[ENOTSOCK] = UAENOTSOCK;
7642 sys2et[EDESTADDRREQ] = UAEDESTADDRREQ;
7643 sys2et[EMSGSIZE] = UAEMSGSIZE;
7644 sys2et[EPROTOTYPE] = UAEPROTOTYPE;
7645 sys2et[ENOPROTOOPT] = UAENOPROTOOPT;
7646 sys2et[EPROTONOSUPPORT] = UAEPROTONOSUPPORT;
7647 sys2et[ESOCKTNOSUPPORT] = UAESOCKTNOSUPPORT;
7648 sys2et[EOPNOTSUPP] = UAEOPNOTSUPP;
7649 sys2et[EPFNOSUPPORT] = UAEPFNOSUPPORT;
7650 sys2et[EAFNOSUPPORT] = UAEAFNOSUPPORT;
7651 sys2et[EADDRINUSE] = UAEADDRINUSE;
7652 sys2et[EADDRNOTAVAIL] = UAEADDRNOTAVAIL;
7653 sys2et[ENETDOWN] = UAENETDOWN;
7654 sys2et[ENETUNREACH] = UAENETUNREACH;
7655 sys2et[ENETRESET] = UAENETRESET;
7656 sys2et[ECONNABORTED] = UAECONNABORTED;
7657 sys2et[ECONNRESET] = UAECONNRESET;
7658 sys2et[ENOBUFS] = UAENOBUFS;
7659 sys2et[EISCONN] = UAEISCONN;
7660 sys2et[ENOTCONN] = UAENOTCONN;
7661 sys2et[ESHUTDOWN] = UAESHUTDOWN;
7662 sys2et[ETOOMANYREFS] = UAETOOMANYREFS;
7663 sys2et[ETIMEDOUT] = UAETIMEDOUT;
7664 sys2et[ECONNREFUSED] = UAECONNREFUSED;
7665 sys2et[EHOSTDOWN] = UAEHOSTDOWN;
7666 sys2et[EHOSTUNREACH] = UAEHOSTUNREACH;
7667 sys2et[EALREADY] = UAEALREADY;
7668 sys2et[EINPROGRESS] = UAEINPROGRESS;
7669 sys2et[ESTALE] = UAESTALE;
7670 sys2et[EUCLEAN] = UAEUCLEAN;
7671 sys2et[ENOTNAM] = UAENOTNAM;
7672 sys2et[ENAVAIL] = UAENAVAIL;
7673 sys2et[EISNAM] = UAEISNAM;
7674 sys2et[EREMOTEIO] = UAEREMOTEIO;
7675 sys2et[EDQUOT] = UAEDQUOT;
7676 sys2et[ENOMEDIUM] = UAENOMEDIUM;
7677 sys2et[EMEDIUMTYPE] = UAEMEDIUMTYPE;
7679 sys2et[EIO] = UAEIO;
7683 * SRXAFS_CallBackRxConnAddr should be re-written as follows:
7684 * - pass back the connection, client, and host from CallPreamble
7685 * - keep a ref on the client, which we don't now
7686 * - keep a hold on the host, which we already do
7687 * - pass the connection, client, and host down into SAFSS_*, and use
7688 * them instead of independently discovering them via rx_ConnectionOf
7689 * (safe) and rx_GetSpecific (not so safe)
7690 * The idea being that we decide what client and host we're going to use
7691 * when CallPreamble is called, and stay consistent throughout the call.
7692 * This change is too invasive for 1.4.1 but should be made in 1.5.x.
7696 SRXAFS_CallBackRxConnAddr (struct rx_call * acall, afs_int32 *addr)
7698 Error errorCode = 0;
7699 struct rx_connection *tcon;
7700 struct host *tcallhost;
7701 #ifdef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7703 struct client *tclient;
7704 static struct rx_securityClass *sc = 0;
7706 struct rx_connection *conn;
7709 if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &tcallhost)))
7710 goto Bad_CallBackRxConnAddr1;
7712 #ifndef __EXPERIMENTAL_CALLBACK_CONN_MOVING
7716 tclient = h_FindClient_r(tcon);
7719 goto Bad_CallBackRxConnAddr;
7721 thost = tclient->host;
7723 /* nothing more can be done */
7724 if ( !thost->interface )
7725 goto Bad_CallBackRxConnAddr;
7727 /* the only address is the primary interface */
7728 /* can't change when there's only 1 address, anyway */
7729 if ( thost->interface->numberOfInterfaces <= 1 )
7730 goto Bad_CallBackRxConnAddr;
7732 /* initialise a security object only once */
7734 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
7736 for ( i=0; i < thost->interface->numberOfInterfaces; i++)
7738 if ( *addr == thost->interface->addr[i] ) {
7743 if ( *addr != thost->interface->addr[i] )
7744 goto Bad_CallBackRxConnAddr;
7746 conn = rx_NewConnection (thost->interface->addr[i],
7747 thost->port, 1, sc, 0);
7748 rx_SetConnDeadTime(conn, 2);
7749 rx_SetConnHardDeadTime(conn, AFS_HARDDEADTIME);
7751 errorCode = RXAFSCB_Probe(conn);
7754 if ( thost->callback_rxcon )
7755 rx_DestroyConnection(thost->callback_rxcon);
7756 thost->callback_rxcon = conn;
7758 rx_SetConnDeadTime(thost->callback_rxcon, 50);
7759 rx_SetConnHardDeadTime(thost->callback_rxcon, AFS_HARDDEADTIME);
7760 h_ReleaseClient_r(tclient);
7761 /* The hold on thost will be released by CallPostamble */
7763 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7766 rx_DestroyConnection(conn);
7768 Bad_CallBackRxConnAddr:
7769 h_ReleaseClient_r(tclient);
7770 /* The hold on thost will be released by CallPostamble */
7774 errorCode = CallPostamble(tcon, errorCode, tcallhost);
7775 Bad_CallBackRxConnAddr1:
7776 return errorCode; /* failure */
7780 sys_error_to_et(afs_int32 in)
7784 if (in < 0 || in > 511)
7786 if ((in >= VICE_SPECIAL_ERRORS && in <= VIO) || in == VRESTRICTED)
7788 if (sys2et[in] != 0)